Ignore:
Timestamp:
2022-12-07T12:07:30+13:00 (18 months ago)
Author:
kjdon
Message:

made service names public so we can use them from other classes rather than hard coding the names in those classes. added ValidateDocumentId service - basically shecks whether the supplied id or list of ids is/are valid

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java

    r30056 r36977  
    2727import org.greenstone.gsdl3.util.BasicDocument;
    2828import org.greenstone.gsdl3.util.GSXML;
     29import org.greenstone.gsdl3.util.GSParams;
    2930import org.greenstone.gsdl3.util.GSPath;
    3031import org.greenstone.gsdl3.util.MacroResolver;
     
    4243// General Java classes
    4344import java.io.File;
     45import java.io.Serializable;
    4446import java.util.StringTokenizer;
    4547import java.util.Set;
    4648import java.util.Iterator;
    4749import java.util.ArrayList;
     50import java.util.HashMap;
    4851
    4952import org.apache.log4j.*;
     
    5861
    5962    // the services on offer
    60     protected static final String DOCUMENT_STRUCTURE_RETRIEVE_SERVICE = "DocumentStructureRetrieve";
    61     protected static final String DOCUMENT_METADATA_RETRIEVE_SERVICE = "DocumentMetadataRetrieve";
    62     protected static final String DOCUMENT_CONTENT_RETRIEVE_SERVICE = "DocumentContentRetrieve";
    63 
     63    public static final String DOCUMENT_STRUCTURE_RETRIEVE_SERVICE = "DocumentStructureRetrieve";
     64    public static final String DOCUMENT_METADATA_RETRIEVE_SERVICE = "DocumentMetadataRetrieve";
     65    public static final String DOCUMENT_CONTENT_RETRIEVE_SERVICE = "DocumentContentRetrieve";
     66        public static final String VALIDATE_DOCUMENT_ID_SERVICE = "ValidateDocumentId";
    6467    protected static final String STRUCT_PARAM = "structure";
    6568    protected static final String INFO_PARAM = "info";
     
    105108        this.config_info = info;
    106109
     110                Element vdi_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
     111                vdi_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
     112                vdi_service.setAttribute(GSXML.NAME_ATT, VALIDATE_DOCUMENT_ID_SERVICE);
     113                this.short_service_info.appendChild(vdi_service);
     114       
     115
    107116        // set up short_service_info_ - for now just has name and type
    108117        if (does_structure)
     
    190199    }
    191200
     201  /** this request needs to come with a documentNodeList, or a d paramter
     202   *  it returns a documentNodeList, with all document nodes marked with valid=true/false
     203  */
     204 
     205  protected Element processValidateDocumentId(Element request) {
     206    Document result_doc = XMLConverter.newDOM();
     207    Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
     208    String lang = request.getAttribute(GSXML.LANG_ATT);
     209    result.setAttribute(GSXML.FROM_ATT, VALIDATE_DOCUMENT_ID_SERVICE);
     210    result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
     211
     212    // Get the documents
     213    boolean has_doc_info = false;
     214    Element request_node_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     215    if (request_node_list == null)
     216    {
     217      // maybe we have a document param
     218      Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     219      if (param_list != null) {
     220        HashMap<String, Serializable> params = GSXML.extractParams(param_list, false, GSParams.DOCUMENT);
     221        String doc_id = (String)params.get(GSParams.DOCUMENT);
     222        if (doc_id!=null && !doc_id.equals("")) {
     223          // generate a doc node list
     224          request_node_list = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     225          Element current_doc = result_doc.createElement(GSXML.DOC_NODE_ELEM);
     226          current_doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
     227          request_node_list.appendChild(current_doc);
     228          has_doc_info = true;
     229        }
     230      }
     231    } else {
     232      has_doc_info = true;
     233    }
     234    if (has_doc_info == false) {
     235        GSXML.addError(result, VALIDATE_DOCUMENT_ID_SERVICE + ": missing doc id info.  Request must contain either " + GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER+" or "+GSParams.DOCUMENT+" parameter.", GSXML.ERROR_TYPE_SYNTAX);
     236      return result;
     237    }
     238    // copy the request doc node list to the response
     239    Element response_node_list = (Element) result_doc.importNode(request_node_list, true);
     240    result.appendChild(response_node_list);
     241
     242    NodeList doc_nodes = GSXML.getChildrenByTagName(response_node_list, GSXML.DOC_NODE_ELEM);
     243    if (doc_nodes.getLength() == 0)
     244    {
     245      GSXML.addError(result, VALIDATE_DOCUMENT_ID_SERVICE+": no " + GSXML.DOC_NODE_ELEM + " found in the " + GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX);
     246      return result;
     247    }
     248
     249    // Whew, now we have checked (almost) all the syntax of the request, now we can process it.
     250    for (int i = 0; i < doc_nodes.getLength(); i++)
     251    {
     252      Element doc_node = (Element) doc_nodes.item(i);
     253      String node_id = doc_node.getAttribute(GSXML.NODE_ID_ATT);
     254      if (this.gs_doc.isValidOID(node_id)) {
     255        doc_node.setAttribute("valid", "true");
     256      }
     257      else {
     258        doc_node.setAttribute("valid", "false");
     259      }
     260    }
     261    return result;
     262
     263  }
    192264    protected Element processDocumentMetadataRetrieve(Element request)
    193265    {
Note: See TracChangeset for help on using the changeset viewer.