Ignore:
Timestamp:
2023-01-21T20:34:59+13:00 (17 months ago)
Author:
davidb
Message:

Introduction of new optional parameter docVersion. If null (or equal to the empty string), then code works as before. Designed to work with the file-level document-version history mechanism, if non-empty, then this value is used to change where doc.xml on the file system is read from

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java

    r36978 r37177  
    5757    public static final String REALISTIC_BOOK_ARG = "book";
    5858        public static final String NO_TEXT_ARG = "noText";
    59         public static final String DOC_EDIT_ARG = "docEdit";
    60  
     59        public static final String DOC_EDIT_ARG    = "docEdit";
     60        public static final String DOC_VERSION_ARG = "dv";
     61   
    6162    /**
    6263     * if this is set to true, when a document is displayed, any annotation type
     
    205206        // are we editing mode? just get the archive document, convert to our internal doc format, and return it
    206207        if (editing_document) {
    207           return getFormattedArchiveDoc(doc, collection, document_id, document_type, result, page_response, userContext);
     208            String opt_document_version = (String) params.get(DOC_VERSION_ARG);
     209            return getFormattedArchiveDoc(doc, collection, document_id, opt_document_version, document_type, result, page_response, userContext);
    208210        }
    209211       
     
    825827  }
    826828
    827   protected Element getFormattedArchiveDoc(Document doc, String collection, String document_id, String document_type, Element result, Element page_response, UserContext userContext ) {
     829    protected Element getFormattedArchiveDoc(Document doc, String collection, String document_id, String opt_document_version, String document_type,
     830                         Element result, Element page_response, UserContext userContext ) {
    828831    // call get archive doc
    829832    Element dx_message = doc.createElement(GSXML.MESSAGE_ELEM);
     
    834837    dx_section.setAttribute(GSXML.NODE_ID_ATT, document_id);
    835838    dx_section.setAttribute(GSXML.COLLECTION_ATT, collection);
     839    dx_section.setAttribute(GSXML.DOC_VERSION_ATT, opt_document_version);
    836840    dx_request.appendChild(dx_section);
    837841
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/ArchiveIO.java

    r28966 r37177  
    124124        HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
    125125
    126         String oid = (String) params.get(GSXML.NODE_ID_ATT);
    127         String collection = (String) params.get(GSXML.COLLECTION_ATT);
    128 
    129         String filePath = _GSDM.archiveGetDocumentFilePath(oid, collection, userContext);
     126        String oid           = (String) params.get(GSXML.NODE_ID_ATT);
     127        String optDocVersion = (String) params.get(GSXML.DOC_VERSION_ATT);
     128        String collection    = (String) params.get(GSXML.COLLECTION_ATT);
     129       
     130        String filePath = _GSDM.archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext);
    130131       
    131132        Element metadataList = result_doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
     
    139140    {
    140141        //Create a new (empty) result message
    141       Document result_doc = XMLConverter.newDOM();
     142        Document result_doc = XMLConverter.newDOM();
    142143        Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
    143144        result.setAttribute(GSXML.FROM_ATT, ARCHIVE_GET_SOURCE_FILE_OID);
     
    190191        HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
    191192
    192         String oid = (String) params.get(GSXML.NODE_ID_ATT);
    193         String collection = (String) params.get(GSXML.COLLECTION_ATT);
    194        
    195         boolean exists = _GSDM.archiveCheckDocumentOrSectionExists(oid, collection, userContext);
     193        String oid           = (String) params.get(GSXML.NODE_ID_ATT);
     194        String optDocVersion = (String) params.get(GSXML.DOC_VERSION_ATT);
     195        String collection    = (String) params.get(GSXML.COLLECTION_ATT);
     196       
     197        boolean exists = _GSDM.archiveCheckDocumentOrSectionExists(oid, optDocVersion, collection, userContext);
    196198        if(_GSDM.checkError(result, ARCHIVE_CHECK_DOCUMENT_OR_SECTION_EXISTS))
    197199        {
     
    212214        result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    213215
     216       
    214217        UserContext userContext = new UserContext(request);
    215218
     
    225228        String collection = null;
    226229        String oid = null;
    227 
     230        //String optDocVersion = null;
     231       
    228232        NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
    229233        for (int i = 0; i < params.getLength(); i++)
     
    256260                    oid = value;
    257261                }
     262                /*else if (name.equals(GSXML.DOC_VERSION_ATT))
     263                {
     264                    optDocVersion = value;
     265                    }*/
    258266            }
    259267        }
     
    285293        String collection = null;
    286294        String oid = null;
    287 
     295        // String optDocVersion = null;
     296       
    288297        NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
    289298        for (int i = 0; i < params.getLength(); i++)
     
    301310                oid = value;
    302311            }
     312            /*else if (name.equals(GSXML.DOC_VERSION_ATT))
     313            {
     314                optDocVersion = value;
     315                }*/
    303316        }
    304317       
     
    328341        HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
    329342
    330         String oid = (String) params.get(GSXML.NODE_ID_ATT);
    331         String collection = (String) params.get(GSXML.COLLECTION_ATT);
    332 
     343        String oid           = (String) params.get(GSXML.NODE_ID_ATT);
     344        //String optDocVersion = (String) params.get(GSXML.DOC_VERSION_ATT);
     345        String collection    = (String) params.get(GSXML.COLLECTION_ATT);
     346       
    333347        ArrayList<String> assocFiles = _GSDM.archiveGetAssociatedImportFiles(oid, collection, userContext);
    334348        if(_GSDM.checkError(result, ARCHIVE_GET_ASSOCIATED_IMPORT_FILES))
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocXMLUtil.java

    r36975 r37177  
    132132        {
    133133            Element currentDoc = (Element) docList.item(i);
    134             String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
     134            String oid        = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    135135            String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    136 
    137             _GSDM.documentXMLCreateDocXML(oid, collection, userContext);
     136            //String optDocVersion = (String) currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);
     137       
     138            _GSDM.documentXMLCreateNewImportDocXML(oid, collection, userContext);
    138139            if(_GSDM.checkError(result, DOC_XML_CREATE_EMPTY_FILE_SERVICE))
    139140            {
     
    146147    protected Element processDocXMLGetMetadata(Element request)
    147148    {
    148       Document result_doc = XMLConverter.newDOM();
     149        Document result_doc = XMLConverter.newDOM();
    149150        Element result = GSXML.createBasicResponse(result_doc, DOC_XML_GET_METADATA_SERVICE);
    150151
     
    162163        {
    163164            Element currentMetadata = (Element) metadataList.item(i);
    164             String oid = currentMetadata.getAttribute(GSXML.NODE_ID_ATT);
    165             String collection = currentMetadata.getAttribute(GSXML.COLLECTION_ATT);
    166             String metadataName = currentMetadata.getAttribute(GSXML.NAME_ATT);
    167 
    168             ArrayList<Element> metadataValues = _GSDM.documentXMLGetMetadata(oid, collection, metadataName, userContext);
     165            String oid           = currentMetadata.getAttribute(GSXML.NODE_ID_ATT);
     166            String optDocVersion = currentMetadata.getAttribute(GSXML.DOC_VERSION_ATT);
     167            String collection    = currentMetadata.getAttribute(GSXML.COLLECTION_ATT);
     168            String metadataName  = currentMetadata.getAttribute(GSXML.NAME_ATT);
     169
     170            ArrayList<Element> metadataValues = _GSDM.documentXMLGetMetadata(oid, optDocVersion, collection, metadataName, userContext);
    169171            if(_GSDM.checkError(result, DOC_XML_GET_METADATA_SERVICE))
    170172            {
     
    202204        {
    203205            Element currentMetadata = (Element) metadataList.item(i);
    204             String oid = currentMetadata.getAttribute(GSXML.NODE_ID_ATT);
    205             String collection = currentMetadata.getAttribute(GSXML.COLLECTION_ATT);
    206             String metadataName = currentMetadata.getAttribute(GSXML.NAME_ATT);
     206            String oid           = currentMetadata.getAttribute(GSXML.NODE_ID_ATT);
     207            String optDocVersion = currentMetadata.getAttribute(GSXML.DOC_VERSION_ATT);
     208            String collection    = currentMetadata.getAttribute(GSXML.COLLECTION_ATT);
     209            String metadataName     = currentMetadata.getAttribute(GSXML.NAME_ATT);
    207210            String newMetadataValue = currentMetadata.getAttribute(GSXML.VALUE_ATT);
    208211           
     
    239242                    return result;
    240243                }
    241                 _GSDM.documentXMLSetMetadata(oid, collection, metadataName, newMetadataValue, pos, op, userContext);
     244                _GSDM.documentXMLSetMetadata(oid, optDocVersion, collection, metadataName, newMetadataValue, pos, op, userContext);
    242245                if(_GSDM.checkError(result, DOC_XML_SET_METADATA_SERVICE))
    243246                {
     
    248251            else if (oldMetadataValue != null && !oldMetadataValue.equals(""))
    249252            {
    250                 _GSDM.documentXMLReplaceMetadata(oid, collection, metadataName, oldMetadataValue, newMetadataValue, userContext);
     253                _GSDM.documentXMLReplaceMetadata(oid, optDocVersion, collection, metadataName, oldMetadataValue, newMetadataValue, userContext);
    251254                if(_GSDM.checkError(result, DOC_XML_SET_METADATA_SERVICE))
    252255                {
     
    282285        {
    283286            Element currentSection = (Element) sectionList.item(i);
    284             String oid = currentSection.getAttribute(GSXML.NODE_ID_ATT);
    285             String collection = currentSection.getAttribute(GSXML.COLLECTION_ATT);
    286 
    287             _GSDM.documentXMLCreateSection(oid, collection, userContext);
     287            String oid           = currentSection.getAttribute(GSXML.NODE_ID_ATT);
     288            String optDocVersion = currentSection.getAttribute(GSXML.DOC_VERSION_ATT);
     289            String collection    = currentSection.getAttribute(GSXML.COLLECTION_ATT);
     290           
     291            _GSDM.documentXMLCreateSection(oid, optDocVersion, collection, userContext);
    288292            if(_GSDM.checkError(result, DOC_XML_CREATE_SECTION_SERVICE))
    289293            {
     
    312316        {
    313317            Element currentSection = (Element) sectionList.item(i);
    314             String oid = currentSection.getAttribute(GSXML.NODE_ID_ATT);
    315             String collection = currentSection.getAttribute(GSXML.COLLECTION_ATT);
    316 
    317             _GSDM.documentXMLDeleteSection(oid, collection, userContext);
     318            String oid           = currentSection.getAttribute(GSXML.NODE_ID_ATT);
     319            String optDocVersion = currentSection.getAttribute(GSXML.DOC_VERSION_ATT);
     320            String collection    = currentSection.getAttribute(GSXML.COLLECTION_ATT);
     321           
     322            _GSDM.documentXMLDeleteSection(oid, optDocVersion, collection, userContext);
    318323            if(_GSDM.checkError(result, DOC_XML_DELETE_SECTION_SERVICE))
    319324            {
     
    342347        {
    343348            Element currentSection = (Element) sectionList.item(i);
    344             String oid = currentSection.getAttribute(GSXML.NODE_ID_ATT);
    345             String collection = currentSection.getAttribute(GSXML.COLLECTION_ATT);
    346 
    347             Element section = _GSDM.documentXMLGetSection(oid, collection, userContext);
     349            String oid           = currentSection.getAttribute(GSXML.NODE_ID_ATT);
     350            String optDocVersion = currentSection.getAttribute(GSXML.DOC_VERSION_ATT);
     351            String collection    = currentSection.getAttribute(GSXML.COLLECTION_ATT);
     352
     353            Element section = _GSDM.documentXMLGetSection(oid, optDocVersion, collection, userContext);
    348354            if(_GSDM.checkError(result, DOC_XML_GET_SECTION_SERVICE))
    349355            {
    350               logger.error("there was an error getting the archive section for " +oid);
    351                 return result;
     356                logger.error("there was an error getting the archive section for " +oid);
     357                return result;
    352358            }
    353359            result.appendChild(result_doc.importNode(section,true));
     
    374380        {
    375381            Element currentSection = (Element) sectionList.item(i);
    376             String oid = currentSection.getAttribute(GSXML.NODE_ID_ATT);
    377             String collection = currentSection.getAttribute(GSXML.COLLECTION_ATT);
     382            String oid           = currentSection.getAttribute(GSXML.NODE_ID_ATT);
     383            String optDocVersion = currentSection.getAttribute(GSXML.DOC_VERSION_ATT);
     384            String collection    = currentSection.getAttribute(GSXML.COLLECTION_ATT);
     385           
    378386            String operation = currentSection.getAttribute("operation");
    379387           
     
    392400            }
    393401           
    394             _GSDM.documentXMLSetSection(oid, collection, currentSection, op, userContext);
     402            _GSDM.documentXMLSetSection(oid, optDocVersion, collection, currentSection, op, userContext);
    395403            if(_GSDM.checkError(result, DOC_XML_SET_SECTION_SERVICE))
    396404            {
     
    420428        {
    421429            Element currentContent = (Element) contentList.item(i);
    422             String oid = currentContent.getAttribute(GSXML.NODE_ID_ATT);
    423             String collection = currentContent.getAttribute(GSXML.COLLECTION_ATT);
    424 
    425             String content = _GSDM.documentXMLGetText(oid, collection, userContext);
     430            String oid           = currentContent.getAttribute(GSXML.NODE_ID_ATT);
     431            String optDocVersion = currentContent.getAttribute(GSXML.DOC_VERSION_ATT);
     432            String collection    = currentContent.getAttribute(GSXML.COLLECTION_ATT);
     433           
     434            String content = _GSDM.documentXMLGetText(oid, optDocVersion, collection, userContext);
    426435            if(_GSDM.checkError(result, DOC_XML_GET_TEXT_SERVICE))
    427436            {
     
    463472        {
    464473            Element currentContent = (Element) contentList.item(i);
    465             String oid = currentContent.getAttribute(GSXML.NODE_ID_ATT);
    466             String collection = currentContent.getAttribute(GSXML.COLLECTION_ATT);
    467 
    468             _GSDM.documentXMLSetText(oid, collection, currentContent, userContext);
     474            String oid           = currentContent.getAttribute(GSXML.NODE_ID_ATT);
     475            String optDocVersion = currentContent.getAttribute(GSXML.DOC_VERSION_ATT);
     476            String collection    = currentContent.getAttribute(GSXML.COLLECTION_ATT);
     477           
     478            _GSDM.documentXMLSetText(oid, optDocVersion, collection, currentContent, userContext);
    469479            if(_GSDM.checkError(result, DOC_XML_SET_TEXT_SERVICE))
    470480            {
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocumentMaker.java

    r30731 r37177  
    142142            //Get information about the current new document
    143143            Element currentDoc = (Element) documents.item(i);
    144             String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    145             String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    146 
    147             _GSDM.documentCreate(oid, collection, userContext);
     144            String oid           = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
     145            String optDocVersion = currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);
     146            String collection    = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
     147
     148            _GSDM.documentCreate(oid, optDocVersion, collection, userContext);
    148149            if (_GSDM.checkError(result, DOCUMENT_CREATE))
    149150            {
     
    173174        {
    174175            Element currentDoc = (Element) documents.item(i);
    175             String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    176             String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    177 
    178             _GSDM.documentDelete(oid, collection, userContext);
     176            String oid           = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
     177            String optDocVersion = currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);
     178            String collection    = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
     179
     180            _GSDM.documentDelete(oid, optDocVersion, collection, userContext);
    179181            if (_GSDM.checkError(result, DOCUMENT_DELETE))
    180182            {
     
    204206        {
    205207            Element currentDoc = (Element) documents.item(i);
    206             String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    207             String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    208             String newOID = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT);
    209             String newCollection = currentDoc.getAttribute("new" + GSXML.COLLECTION_ATT);
     208            String oid           = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
     209            String optDocVersion = currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);
     210            String collection    = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
     211            String newOID           = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT);
     212            String optNewDocVersion = currentDoc.getAttribute("new" + GSXML.DOC_VERSION_ATT);
     213            String newCollection    = currentDoc.getAttribute("new" + GSXML.COLLECTION_ATT);
    210214            String operation = currentDoc.getAttribute("operation");
    211215
    212             _GSDM.documentMoveOrDuplicate(oid, collection, newOID, newCollection, _GSDM.operationStringToInt(operation), false, userContext);
     216            _GSDM.documentMoveOrDuplicate(oid, optDocVersion, collection,
     217                              newOID, optNewDocVersion, newCollection,
     218                              _GSDM.operationStringToInt(operation), false, userContext);
    213219            if (_GSDM.checkError(result, DOCUMENT_DUPLICATE))
    214220            {
     
    238244        {
    239245            Element currentDoc = (Element) documents.item(i);
    240             String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    241             String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
     246            String oid           = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
     247            String optDocVersion = currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);
     248            String collection    = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    242249
    243250            NodeList requestedInfoList = currentDoc.getElementsByTagName("info"); //TODO: Replace info with a constant
     
    249256            }
    250257
    251             _GSDM.documentGetInformation(oid, collection, requestedInfo, userContext);
     258            _GSDM.documentGetInformation(oid, optDocVersion, collection, requestedInfo, userContext);
    252259            if (_GSDM.checkError(result, DOCUMENT_GET_INFORMATION))
    253260            {
     
    277284        {
    278285            Element currentDoc = (Element) documents.item(i);
     286            String oid           = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
     287            String optDocVersion = currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);
     288            String collection    = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
     289            String newOID           = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT);
     290            String optNewDocVersion = currentDoc.getAttribute("new" + GSXML.DOC_VERSION_ATT);
     291            String newCollection    = currentDoc.getAttribute("new" + GSXML.COLLECTION_ATT);
     292            String operation = currentDoc.getAttribute("operation");
     293
     294            _GSDM.documentMoveOrDuplicate(oid, optDocVersion, collection,
     295                              newOID, optNewDocVersion, newCollection,
     296                              _GSDM.operationStringToInt(operation), true, userContext);
     297            if (_GSDM.checkError(result, DOCUMENT_MOVE))
     298            {
     299                return result;
     300            }
     301        }
     302        return result;
     303    }
     304
     305    protected Element processDocumentMerge(Element request)
     306    {
     307      Document result_doc = XMLConverter.newDOM();
     308        Element result = GSXML.createBasicResponse(result_doc, DOCUMENT_MERGE);
     309
     310        if (request == null)
     311        {
     312            GSXML.addError(result, DOCUMENT_MERGE + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
     313            return result;
     314        }
     315
     316        UserContext userContext = new UserContext(request);
     317
     318        //Get the list of documents to duplicate
     319        NodeList documents = request.getElementsByTagName(GSXML.DOCUMENT_ELEM);
     320        for (int i = 0; i < documents.getLength(); i++)
     321        {
     322            Element currentDoc = (Element) documents.item(i);
    279323            String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    280             String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    281             String newOID = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT);
    282             String newCollection = currentDoc.getAttribute("new" + GSXML.COLLECTION_ATT);
    283             String operation = currentDoc.getAttribute("operation");
    284 
    285             _GSDM.documentMoveOrDuplicate(oid, collection, newOID, newCollection, _GSDM.operationStringToInt(operation), true, userContext);
    286             if (_GSDM.checkError(result, DOCUMENT_MOVE))
    287             {
    288                 return result;
    289             }
    290         }
    291         return result;
    292     }
    293 
    294     protected Element processDocumentMerge(Element request)
    295     {
    296       Document result_doc = XMLConverter.newDOM();
    297         Element result = GSXML.createBasicResponse(result_doc, DOCUMENT_MERGE);
    298 
    299         if (request == null)
    300         {
    301             GSXML.addError(result, DOCUMENT_MERGE + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
     324            String collection    = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
     325            String optDocVersion = currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);         
     326            String mergeOID      = currentDoc.getAttribute("merge" + GSXML.NODE_ID_ATT);
     327
     328            _GSDM.documentMerge(oid, optDocVersion, collection, mergeOID, userContext);
     329            if (_GSDM.checkError(result, DOCUMENT_MERGE))
     330            {
     331                return result;
     332            }
     333        }
     334
     335        return result;
     336    }
     337
     338    protected Element processDocumentSplit(Element request)
     339    {
     340      Document result_doc = XMLConverter.newDOM();
     341        Element result = GSXML.createBasicResponse(result_doc, DOCUMENT_SPLIT);
     342
     343        if (request == null)
     344        {
     345            GSXML.addError(result, DOCUMENT_SPLIT + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
    302346            return result;
    303347        }
     
    310354        {
    311355            Element currentDoc = (Element) documents.item(i);
    312             String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    313             String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    314             String mergeOID = currentDoc.getAttribute("merge" + GSXML.NODE_ID_ATT);
    315 
    316             _GSDM.documentMerge(oid, collection, mergeOID, userContext);
    317             if (_GSDM.checkError(result, DOCUMENT_MERGE))
    318             {
    319                 return result;
    320             }
    321         }
    322 
    323         return result;
    324     }
    325 
    326     protected Element processDocumentSplit(Element request)
    327     {
    328       Document result_doc = XMLConverter.newDOM();
    329         Element result = GSXML.createBasicResponse(result_doc, DOCUMENT_SPLIT);
    330 
    331         if (request == null)
    332         {
    333             GSXML.addError(result, DOCUMENT_SPLIT + ": Request is null", GSXML.ERROR_TYPE_SYNTAX);
    334             return result;
    335         }
    336 
    337         UserContext userContext = new UserContext(request);
    338 
    339         //Get the list of documents to duplicate
    340         NodeList documents = request.getElementsByTagName(GSXML.DOCUMENT_ELEM);
    341         for (int i = 0; i < documents.getLength(); i++)
    342         {
    343             Element currentDoc = (Element) documents.item(i);
    344             String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
    345             String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
     356            String oid           = currentDoc.getAttribute(GSXML.NODE_ID_ATT);
     357            String optDocVersion = currentDoc.getAttribute(GSXML.DOC_VERSION_ATT);         
     358            String collection    = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    346359            String splitPoint = currentDoc.getAttribute("splitpoint");
    347360
     
    357370            }
    358371
    359             _GSDM.documentSplit(oid, collection, split, userContext);
     372            _GSDM.documentSplit(oid, optDocVersion, collection, split, userContext);
    360373            if (_GSDM.checkError(result, DOCUMENT_SPLIT))
    361374            {
     
    413426                if (operation.equals("move") || operation.equals("duplicate"))
    414427                {
    415                     String origCollection = (String) keyValueMap.get("collection");
    416                     String origOID = (String) keyValueMap.get("oid");
    417                     String newCollection = (String) keyValueMap.get("newCollection");
    418                     String newOID = (String) keyValueMap.get("newOID");
     428                    String origOID            = (String) keyValueMap.get("oid");
     429                    String optOrigDocVersion  = (String) keyValueMap.get("optDocVersion");
     430                    String origCollection     = (String) keyValueMap.get("collection");
     431                    String newOID            = (String) keyValueMap.get("newOID");
     432                    String optNewDocVersion  = (String) keyValueMap.get("optNewDocVersion");
     433                    String newCollection     = (String) keyValueMap.get("newCollection");
    419434                    String subOperation = (String) keyValueMap.get("subOperation");
    420435
    421                     _GSDM.documentMoveOrDuplicate(origOID, origCollection, newOID, newCollection, _GSDM.operationStringToInt(subOperation), operation.equals("move"), userContext);
     436                    _GSDM.documentMoveOrDuplicate(origOID, optOrigDocVersion, origCollection,
     437                                      newOID, optNewDocVersion, newCollection,
     438                                      _GSDM.operationStringToInt(subOperation), operation.equals("move"), userContext);
    422439                }
    423440                else if (operation.equals("createDocument"))
    424441                {
    425                     String oid = (String) keyValueMap.get("oid");
    426                     String collection = (String) keyValueMap.get("collection");
    427 
    428                     _GSDM.documentCreate(oid, collection, userContext);
     442                    String oid            = (String) keyValueMap.get("oid");
     443                    String optDocVersion  = (String) keyValueMap.get("optDocVersion");
     444                    String collection     = (String) keyValueMap.get("collection");
     445
     446                    _GSDM.documentCreate(oid, optDocVersion, collection, userContext);
    429447                }
    430448                else if (operation.equals("create"))
    431449                {
    432                     String oid = (String) keyValueMap.get("oid");
    433                     String collection = (String) keyValueMap.get("collection");
     450                    String oid            = (String) keyValueMap.get("oid");
     451                    String optDocVersion  = (String) keyValueMap.get("optDocVersion");
     452                    String collection     = (String) keyValueMap.get("collection");
    434453                    String subOperation = (String) keyValueMap.get("subOperation");
    435454
    436                     //_GSDM.documentCreate(oid, collection, userContext); <--- Maybe go back to this
    437                     _GSDM.documentXMLSetSection(oid, collection, result_doc.createElement(GSXML.DOCXML_SECTION_ELEM), _GSDM.operationStringToInt(subOperation), userContext);
     455                    //_GSDM.documentCreate(oid, optDocVersion, collection, userContext); <--- Maybe go back to this
     456                    _GSDM.documentXMLSetSection(oid, optDocVersion, collection, result_doc.createElement(GSXML.DOCXML_SECTION_ELEM), _GSDM.operationStringToInt(subOperation), userContext);
    438457                }
    439458                else if (operation.equals("delete"))
    440459                {
    441                     String oid = (String) keyValueMap.get("oid");
    442                     String collection = (String) keyValueMap.get("collection");
    443 
    444                     _GSDM.documentDelete(oid, collection, userContext);
     460                    String oid            = (String) keyValueMap.get("oid");
     461                    String optDocVersion  = (String) keyValueMap.get("optDocVersion");
     462                    String collection     = (String) keyValueMap.get("collection");
     463
     464                    _GSDM.documentDelete(oid, optDocVersion, collection, userContext);
    445465                }
    446466                else if (operation.equals("setText"))
    447467                {
    448                     String oid = (String) keyValueMap.get("oid");
    449                     String collection = (String) keyValueMap.get("collection");
     468                    String oid            = (String) keyValueMap.get("oid");
     469                    String optDocVersion  = (String) keyValueMap.get("optDocVersion");
     470                    String collection     = (String) keyValueMap.get("collection");
    450471                    String newContent = (String) keyValueMap.get("text");
    451472                   
    452                     _GSDM.documentXMLSetText(oid, collection, newContent, userContext);
     473                    _GSDM.documentXMLSetText(oid, optDocVersion, collection, newContent, userContext);
    453474                    // make sure NoText metadata is not set (in case we have added text where there was none before)
    454                     _GSDM.documentXMLDeleteMetadata(oid, collection, "NoText", userContext);
     475                    _GSDM.documentXMLDeleteMetadata(oid, optDocVersion, collection, "NoText", userContext);
    455476                    // only top level doc ids are in database
    456477                    markDocumentInFlatDatabase("R", collection, OID.getTop(oid));
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSDocumentModel.java

    r36107 r37177  
    3131{
    3232  //static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GSDocumentModel.class.getName());
    33     //The two archive databases
     33
     34    //The folder name used inside an archive's document to store older versions
     35    //(file-level document-version history)
     36    public static final String ARCHIVES_DOCVERSION_DIR = "_fldv_history";
     37
     38        //The two archive databases
    3439    protected static final String ARCHIVEINFSRC = "archiveinf-src";
    3540    protected static final String ARCHIVEINFDOC = "archiveinf-doc";
    3641
     42       
    3743    //Set operations
    3844    public static final int OPERATION_REPLACE = 1;
     
    121127     * @param oid
    122128     *            is the identifier of the document/section to create.
     129     * @param optDocVersion
     130     *            is the (optional) document version of the specified oid.
    123131     * @param collection
    124132     *            is the collection we want to create the document/section in.
    125133     */
    126     public void documentCreate(String oid, String collection, UserContext userContext)
     134        public void documentCreate(String oid, String optDocVersion, String collection, UserContext userContext)
    127135    {
    128136        _errorStatus = NO_ERROR;
     
    141149        }
    142150
    143         if (archiveCheckDocumentOrSectionExists(oid, collection, userContext))
     151        if (archiveCheckDocumentOrSectionExists(oid, optDocVersion, collection, userContext))
    144152        {
    145153            _errorStatus = ERROR_DESTINATION_DOCUMENT_OR_SECTION_ALREADY_EXISTS;
     
    157165        {
    158166            //Create a basic doc.xml file to go in the new folder
    159             documentXMLCreateDocXML(oid, collection, userContext);
     167                documentXMLCreateNewImportDocXML(oid, collection, userContext); // created in the import area, so optDocVersion not relevant
    160168        }
    161169        else
    162170        {
    163             documentXMLCreateSection(oid, collection, userContext);
     171                documentXMLCreateSection(oid, optDocVersion, collection, userContext);
    164172        }
    165173    }
     
    170178     * @param oid
    171179     *            is the identifier of the document/section to delete.
     180     * @param optDocVersion
     181     *            is the (optional) document version of the specified oid.
    172182     * @param collection
    173183     *            is the collection to delete the document/section from.
    174184     */
    175     public void documentDelete(String oid, String collection, UserContext userContext)
     185    public void documentDelete(String oid, String optDocVersion, String collection, UserContext userContext)
    176186    {
    177187        _errorStatus = NO_ERROR;
     
    187197        }
    188198
    189         if (!archiveCheckDocumentOrSectionExists(oid, collection, userContext))
     199        if (!archiveCheckDocumentOrSectionExists(oid, optDocVersion, collection, userContext))
    190200        {
    191201            _errorStatus = ERROR_SOURCE_DOCUMENT_OR_SECTION_DOES_NOT_EXIST;
     
    202212        if (!section)
    203213        {
    204             String archivesFile = archiveGetDocumentFilePath(oid, collection, userContext);
     214                String archivesFile = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext);
    205215            String archivesFolder = archivesFile.substring(0, archivesFile.lastIndexOf(File.separator));
    206216            File dirToDelete = new File(archivesFolder);
     
    212222            }
    213223
    214             //Remove the entry from the archive database
    215             archiveRemoveEntryFromDatabase(oid, collection, userContext);
     224            if (optDocVersion == null || optDocVersion.equals("")) {
     225                // Have deleted the 'top-level' (i.e. live) version
     226                // => Remove the entry from the archive database
     227                archiveRemoveEntryFromDatabase(oid, collection, userContext);
     228            }
    216229        }
    217230        else
    218231        {
    219             documentXMLDeleteSection(oid, collection, userContext);
     232                documentXMLDeleteSection(oid, optDocVersion, collection, userContext);
    220233        }
    221234    }
     
    225238     *
    226239     * @param oid
    227      *            is the identifier of the document/section that is to be
    228      *            copied.
     240     *            is the identifier of the document/section that is to be copied.
     241     * @param optDocVersion
     242     *            is the (optional) document version of the specified oid.
    229243     * @param collection
    230244     *            is the collection the source document resides in.
     
    232246     *            is the new identifier for the document/section (it cannot
    233247     *            already exist).
     248     * @param optNewDocVersion
     249     *            is the (optional) document version of the specified newOID.
    234250     * @param newCollection
    235251     *            is the collection the new document/section will be copied to.
     
    237253     *            instead.
    238254     */
    239     public void documentMoveOrDuplicate(String oid, String collection, String newOID, String newCollection, int operation, boolean move, UserContext userContext)
    240     {
    241         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
     255    public void documentMoveOrDuplicate(String oid, String optDocVersion, String collection,
     256                        String newOID, String optNewDocVersion, String newCollection,
     257                        int operation, boolean move, UserContext userContext)
     258    {
     259            if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
    242260        {
    243261            return;
     
    263281        case OPERATION_TYPE_DOC_TO_DOC:
    264282        {
    265             String archiveDir = archiveGetDocumentFilePath(oid, collection, userContext);
     283                if (optNewDocVersion != null) {
     284                // While for other operation types is can make sense to have a document
     285                // version for the new document, for a DOC_TO_DOC, the doc being
     286                // created in archives is 'freshly minted', and so is not able
     287                // to take a doc version as part of that
     288                //
     289                // => set error and return
     290                _errorStatus = ERROR_COULD_NOT_DUPLICATE;
     291                return;
     292            }
     293           
     294                String archiveDir = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext);
    266295            if (_errorStatus != NO_ERROR)
    267296            {
     
    293322            {
    294323                deleteDirectory(dirToDuplicate);
     324
     325                if (optDocVersion == null || optDocVersion.equals("")) {
     326                    // Have deleted the 'top-level' (i.e. live) version
     327                    // => Remove the entry from the archive database
     328                    archiveRemoveEntryFromDatabase(oid, collection, userContext);
     329                }               
    295330            }
    296331
     
    300335        case OPERATION_TYPE_DOC_TO_SEC:
    301336        {
    302             Document originalDocument = getDocXML(oid, collection, userContext);
     337                Document originalDocument = getDocXML(oid, optDocVersion, collection, userContext);
    303338            Element originalSection = getTopLevelSectionElement(originalDocument);
    304339
    305             documentXMLCreateSection(newOID, newCollection, userContext);
     340            documentXMLCreateSection(newOID, optNewDocVersion, newCollection, userContext);
    306341            if (_errorStatus != NO_ERROR)
    307342            {
     
    309344            }
    310345
    311             documentXMLSetSection(newOID, newCollection, originalSection, operation, userContext);
     346            documentXMLSetSection(newOID, optNewDocVersion, newCollection, originalSection, operation, userContext);
    312347
    313348            if (move)
    314349            {
    315                 String archiveDirStr = archiveGetDocumentFilePath(oid, collection, userContext);
     350                    String archiveDirStr = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext);
    316351                if (_errorStatus != NO_ERROR)
    317352                {
     
    324359                {
    325360                    deleteDirectory(archiveDir);
     361
     362                    if (optDocVersion == null || optDocVersion.equals("")) {
     363                        // Have deleted the 'top-level' (i.e. live) version
     364                        // => Remove the entry from the archive database
     365                        archiveRemoveEntryFromDatabase(oid, collection, userContext);
     366                    }
    326367                }
    327368            }
     
    330371        case OPERATION_TYPE_SEC_TO_DOC:
    331372        {
    332             Document originalDocument = getDocXML(oid, collection, userContext);
     373                Document originalDocument = getDocXML(oid, optDocVersion, collection, userContext);
    333374            Element originalSection = getSectionBySectionNumber(originalDocument, getSectionFromOID(oid));
    334375
    335             documentCreate(newOID, newCollection, userContext);
     376            documentCreate(newOID, optNewDocVersion, newCollection, userContext);
    336377            if (_errorStatus != NO_ERROR)
    337378            {
     
    339380            }
    340381
    341             documentXMLCreateSection(newOID, newCollection, userContext);
     382            documentXMLCreateSection(newOID, optNewDocVersion, newCollection, userContext);
    342383            if (_errorStatus != NO_ERROR)
    343384            {
     
    345386            }
    346387
    347             documentXMLSetSection(newOID, newCollection, originalSection, operation, userContext);
     388            documentXMLSetSection(newOID, optNewDocVersion, newCollection, originalSection, operation, userContext);
    348389
    349390            if (move)
    350391            {
    351                 originalDocument = getDocXML(oid, collection, userContext);
     392                    originalDocument = getDocXML(oid, optDocVersion, collection, userContext);
    352393                originalSection.getParentNode().removeChild(originalSection);
    353394
    354395                //Write the new change back into the file
    355                 if (!writeXMLFile(originalDocument, oid, collection, userContext))
     396                if (!writeXMLFile(originalDocument, oid, optDocVersion, collection, userContext))
    356397                {
    357398                    _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    365406        case OPERATION_TYPE_SEC_TO_SEC:
    366407        {
    367             Document originalDocument = getDocXML(oid, collection, userContext);
     408                Document originalDocument = getDocXML(oid, optDocVersion, collection, userContext);
    368409            Element originalSection = getSectionBySectionNumber(originalDocument, getSectionFromOID(oid));
    369410
    370411            if (operation == OPERATION_REPLACE)
    371412            {
    372                 documentXMLCreateSection(newOID, newCollection, userContext);
     413                documentXMLCreateSection(newOID, optNewDocVersion, newCollection, userContext);
    373414                if (_errorStatus != NO_ERROR)
    374415                {
     
    377418            }
    378419
    379             documentXMLSetSection(newOID, newCollection, originalSection, operation, userContext);
     420            documentXMLSetSection(newOID, optNewDocVersion, newCollection, originalSection, operation, userContext);
    380421            if (_errorStatus != NO_ERROR)
    381422            {
     
    385426            if (move)
    386427            {
    387                 originalDocument = getDocXML(oid, collection, userContext);
     428                    originalDocument = getDocXML(oid, optDocVersion, collection, userContext);
    388429                originalSection.getParentNode().removeChild(originalSection);
    389430
    390431                //Write the new change back into the file
    391                 if (!writeXMLFile(originalDocument, oid, collection, userContext))
     432                if (!writeXMLFile(originalDocument, oid, optDocVersion, collection, userContext))
    392433                {
    393434                    _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    417458     * @param oid
    418459     *            is the identifier of the document or section.
     460     * @param optDocVersion
     461     *            is the (optional) document version of the specified oid.
    419462     * @param collection
    420463     *            is the collection the document or section resides in.
     
    423466     * @return This returns an array containing the requested information.
    424467     */
    425     public String[] documentGetInformation(String oid, String collection, String[] requestedInfo, UserContext userContext)
    426     {
    427         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
     468    public String[] documentGetInformation(String oid, String optDocVersion, String collection, String[] requestedInfo, UserContext userContext)
     469    {
     470        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
    428471        {
    429472            return null;
     
    449492     * @param oid
    450493     *            the identifier of the section that is to be merged.
     494     * @param optDocVersion
     495     *            is the (optional) document version of the specified oid.
    451496     * @param collection
    452497     *            the collection the section resides in.
     
    455500     *            merged into.
    456501     */
    457     public void documentMerge(String oid, String collection, String mergeOID, UserContext userContext)
    458     {
    459         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    460         {
    461             return;
    462         }
    463 
    464         if ((_errorStatus = checkOIDandCollection(mergeOID, collection, userContext)) != NO_ERROR)
     502    public void documentMerge(String oid, String optDocVersion, String collection, String mergeOID, UserContext userContext)
     503    {
     504        // Based on description of method above, this method requires 'oid' and 'mergeOID' to be secifying
     505        // sections within the same document
     506        // => adding in check to ensure this
     507
     508        String oid_root = oid.substring(0, oid.indexOf("."));
     509        String merge_oid_root = mergeOID.substring(0, oid.indexOf("."));
     510
     511        if (!oid_root.equals(merge_oid_root))
     512        {
     513            _errorStatus = ERROR_INVALID_MERGE;
     514            return;
     515        }
     516
     517        String optMergeDocVersion = optDocVersion; // constraint of 'from the same doc' implies must be the same docVersion
     518
     519        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     520        {
     521            return;
     522        }
     523
     524        if ((_errorStatus = checkOIDandCollection(mergeOID, optMergeDocVersion, collection, userContext)) != NO_ERROR)
    465525        {
    466526            return;
     
    492552        }
    493553
    494         Document docXML = getDocXML(oid, collection, userContext);
     554        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    495555        if (docXML == null)
    496556        {
     
    557617        }
    558618
    559         documentXMLSetSection(mergeOID, collection, sourceSection, OPERATION_REPLACE, userContext);
     619        documentXMLSetSection(mergeOID, optMergeDocVersion, collection, sourceSection, OPERATION_REPLACE, userContext);
    560620        if (_errorStatus != NO_ERROR)
    561621        {
     
    563623        }
    564624
    565         documentXMLDeleteSection(oid, collection, userContext);
     625        documentXMLDeleteSection(oid, optDocVersion, collection, userContext);
    566626    }
    567627
     
    573633     * @param oid
    574634     *            is the identifer of the section to be split.
     635     * @param optDocVersion
     636     *            is the (optional) document version of the specified oid.
    575637     * @param collection
    576638     *            is the collection the section resides in.
     
    578640     *            is the point in the text we want to split at.
    579641     */
    580     public void documentSplit(String oid, String collection, int splitPoint, UserContext userContext)
    581     {
    582         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    583         {
    584             return;
    585         }
    586 
    587         Document docXML = getDocXML(oid, collection, userContext);
     642    public void documentSplit(String oid, String optDocVersion, String collection, int splitPoint, UserContext userContext)
     643    {
     644        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     645        {
     646            return;
     647        }
     648
     649        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    588650        if (docXML == null)
    589651        {
     
    632694        newSection.appendChild(newContent);
    633695
    634         documentXMLSetSection(oid, collection, newSection, OPERATION_INSERT_BEFORE, userContext);
     696        documentXMLSetSection(oid, optDocVersion, collection, newSection, OPERATION_INSERT_BEFORE, userContext);
    635697        if (_errorStatus != NO_ERROR)
    636698        {
     
    640702
    641703        //Write the new change back into the file
    642         if (!writeXMLFile(docXML, oid, collection, userContext))
     704        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    643705        {
    644706            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    654716     *            is the collection the new document will reside in.
    655717     */
    656     public void documentXMLCreateDocXML(String oid, String collection, UserContext userContext)
     718    public void documentXMLCreateNewImportDocXML(String oid, String collection, UserContext userContext)
    657719    {
    658720        _errorStatus = NO_ERROR;
     
    714776     *
    715777     * @param oid
    716      *            is the identifier of the section or document to get metadata
    717      *            from.
     778     *            is the identifier of the section or document to get metadata from.
     779     * @param optDocVersion
     780     *            is the (optional) document version of the specified oid.
    718781     * @param collection
    719782     *            is the collection the section or document resides in.
     
    722785     * @return an array of metadata elements containing the resquested metadata
    723786     */
    724     public ArrayList<Element> documentXMLGetMetadata(String oid, String collection, String metadataName, UserContext userContext)
    725     {
    726         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
     787    public ArrayList<Element> documentXMLGetMetadata(String oid, String optDocVersion, String collection, String metadataName, UserContext userContext)
     788    {
     789        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
    727790        {
    728791            return null;
     
    734797        }
    735798
    736         Document docXML = getDocXML(oid, collection, userContext);
     799        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    737800        if (docXML == null)
    738801        {
     
    748811     * @param oid
    749812     *            is the identifier of the document or section that is to have
    750      *            it's metadata set.
     813     *            its metadata set.
     814     * @param optDocVersion
     815     *            is the (optional) document version of the specified oid.
    751816     * @param collection
    752817     *            is the collection the document/section resides in.
     
    761826     *            OPERATION_INSERT_AFTER or OPERATION_APPEND.
    762827     */
    763     public void documentXMLSetMetadata(String oid, String collection, String metadataName, String newMetadataValue, int position, int operation, UserContext userContext)
    764     {
    765         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
     828    public void documentXMLSetMetadata(String oid, String optDocVersion, String collection, String metadataName, String newMetadataValue, int position, int operation, UserContext userContext)
     829    {
     830        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
    766831        {
    767832            return;
     
    778843        }
    779844
    780         Document docXML = getDocXML(oid, collection, userContext);
     845        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    781846        if (docXML == null)
    782847        {
     
    833898
    834899        //Write the new change back into the file
    835         if (!writeXMLFile(docXML, oid, collection, userContext))
     900        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    836901        {
    837902            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    844909     *
    845910     * @param oid
    846      *            is the identifier of the document/section to delete metadata
    847      *            from.
     911     *            is the identifier of the document/section to delete metadata from.
     912     * @param optDocVersion
     913     *            is the (optional) document version of the specified oid.
    848914     * @param collection
    849915     *            is the collection the document resides in.
     
    853919     *            is position of the item that is to be deleted.
    854920     */
    855     public void documentXMLDeleteMetadata(String oid, String collection, String metadataName, int position, UserContext userContext)
    856     {
    857         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
     921    public void documentXMLDeleteMetadata(String oid, String optDocVersion, String collection, String metadataName, int position, UserContext userContext)
     922    {
     923        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
    858924        {
    859925            return;
     
    865931        }
    866932
    867         Document docXML = getDocXML(oid, collection, userContext);
     933        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    868934        if (docXML == null)
    869935        {
     
    880946
    881947        //Write the new change back into the file
    882         if (!writeXMLFile(docXML, oid, collection, userContext))
     948        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    883949        {
    884950            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    892958     *
    893959     * @param oid
    894      *            is the identifier of the document or section to delete the
    895      *            metadata from.
     960     *            is the identifier of the document or section to delete the metadata from.
     961     * @param optDocVersion
     962     *            is the (optional) document version of the specified oid.
    896963     * @param collection
    897964     *            is the collection the document resides in.
     
    899966     *            is the name of the metadata to delete.
    900967     */
    901     public void documentXMLDeleteMetadata(String oid, String collection, String metadataName, UserContext userContext)
    902     {
    903         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
     968    public void documentXMLDeleteMetadata(String oid, String optDocVersion, String collection, String metadataName, UserContext userContext)
     969    {
     970        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
    904971        {
    905972            return;
     
    911978        }
    912979
    913         Document docXML = getDocXML(oid, collection, userContext);
     980        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    914981        if (docXML == null)
    915982        {
     
    926993
    927994        //Write the new change back into the file
    928         if (!writeXMLFile(docXML, oid, collection, userContext))
     995        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    929996        {
    930997            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    9381005     *
    9391006     * @param oid
    940      *            is the document/section of the metadata that is to be
    941      *            replaced.
     1007     *            is the document/section of the metadata that is to be replaced.
     1008     * @param optDocVersion
     1009     *            is the (optional) document version of the specified oid.
    9421010     * @param collection
    9431011     *            is the collection the document resides in.
     
    9511019     *            value.
    9521020     */
    953     public void documentXMLReplaceMetadata(String oid, String collection, String metadataName, String oldMetadataValue, String newMetadataValue, UserContext userContext)
    954     {
    955         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
     1021    public void documentXMLReplaceMetadata(String oid, String optDocVersion, String collection, String metadataName, String oldMetadataValue, String newMetadataValue, UserContext userContext)
     1022    {
     1023        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
    9561024        {
    9571025            return;
     
    9731041        }
    9741042
    975         Document docXML = getDocXML(oid, collection, userContext);
     1043        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    9761044        if (docXML == null)
    9771045        {
     
    9931061
    9941062        //Write the new change back into the file
    995         if (!writeXMLFile(docXML, oid, collection, userContext))
     1063        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    9961064        {
    9971065            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    10041072     * @param oid
    10051073     *            is the identifier of the section to be created.
     1074     * @param optDocVersion
     1075     *            is the (optional) document version of the specified oid.
    10061076     * @param collection
    10071077     *            is the collection the document resides in.
    10081078     */
    1009     public void documentXMLCreateSection(String oid, String collection, UserContext userContext)
     1079    public void documentXMLCreateSection(String oid, String optDocVersion, String collection, UserContext userContext)
    10101080    {
    10111081        _errorStatus = NO_ERROR;
     
    10211091        }
    10221092
    1023         if (oid.contains(".") && !archiveCheckDocumentOrSectionExists(oid.substring(0, oid.indexOf(".")), collection, userContext))
    1024         {
    1025             documentCreate(oid.substring(0, oid.indexOf(".")), collection, userContext);
     1093        if (oid.contains(".") && !archiveCheckDocumentOrSectionExists(oid.substring(0, oid.indexOf(".")), optDocVersion, collection, userContext))
     1094        {
     1095            // **** This code looks to create a new doc in 'import', but below, then looks to read
     1096            // **** the new doc in from 'archives.
     1097            // SEEMS TO BE PROBLEMATIC
     1098            // Caused by some other code change where the impact here wasn't accounted for????
     1099           
     1100            // Creating a section in a document that does not exist yet => create a basic top-level doc first
     1101                String oid_root = oid.substring(0, oid.indexOf("."));
     1102                documentXMLCreateNewImportDocXML(oid_root, collection, userContext); // created in the import area, so optDocVersion not relevant
     1103           
    10261104            if (_errorStatus != NO_ERROR)
    10271105            {
     
    10301108        }
    10311109
    1032         Document docXML = getDocXML(oid, collection, userContext);
     1110        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    10331111        if (docXML == null)
    10341112        {
     
    10901168
    10911169        //Write the new change back into the file
    1092         if (!writeXMLFile(docXML, oid, collection, userContext))
     1170        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    10931171        {
    10941172            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    11011179     * @param oid
    11021180     *            is the identifier of the section to be deleted.
     1181     * @param optDocVersion
     1182     *            is the (optional) document version of the specified oid.
    11031183     * @param collection
    11041184     *            is the collection the document resides in.
    11051185     */
    1106     public void documentXMLDeleteSection(String oid, String collection, UserContext userContext)
    1107     {
    1108         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    1109         {
    1110             return;
    1111         }
    1112 
    1113         Document docXML = getDocXML(oid, collection, userContext);
     1186    public void documentXMLDeleteSection(String oid, String optDocVersion, String collection, UserContext userContext)
     1187    {
     1188        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     1189        {
     1190            return;
     1191        }
     1192
     1193        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    11141194        if (docXML == null)
    11151195        {
     
    11281208
    11291209        //Write the new change back into the file
    1130         if (!writeXMLFile(docXML, oid, collection, userContext))
     1210        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    11311211        {
    11321212            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    11391219     * @param oid
    11401220     *            is the identifier of the section to get.
     1221     * @param optDocVersion
     1222     *            is the (optional) document version of the specified oid.
    11411223     * @param collection
    11421224     *            is the collection the document resides in.
    11431225     * @return the requested section.
    11441226     */
    1145     public Element documentXMLGetSection(String oid, String collection, UserContext userContext)
    1146     {
    1147         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    1148         {
    1149             return null;
    1150         }
    1151 
    1152         Document docXML = getDocXML(oid, collection, userContext);
     1227    public Element documentXMLGetSection(String oid, String optDocVersion, String collection, UserContext userContext)
     1228    {
     1229        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     1230        {
     1231            return null;
     1232        }
     1233
     1234        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    11531235        if (docXML == null)
    11541236        {
     
    11811263     * @param oid
    11821264     *            is the identifier of the section to be set.
     1265     * @param optDocVersion
     1266     *            is the (optional) document version of the specified oid.
    11831267     * @param collection
    11841268     *            is the collection the section will reside in.
     
    11901274     * @throws IOException
    11911275     */
    1192     public void documentXMLSetSection(String oid, String collection, Element newSection, int operation, UserContext userContext)
    1193     {
    1194         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    1195         {
    1196             return;
    1197         }
    1198 
    1199         Document docXML = getDocXML(oid, collection, userContext);
     1276    public void documentXMLSetSection(String oid, String optDocVersion, String collection, Element newSection, int operation, UserContext userContext)
     1277    {
     1278        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     1279        {
     1280            return;
     1281        }
     1282
     1283        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    12001284        if (docXML == null)
    12011285        {
     
    12621346
    12631347        //Write the new change back into the file
    1264         if (!writeXMLFile(docXML, oid, collection, userContext))
     1348        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    12651349        {
    12661350            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    12741358     * @param oid
    12751359     *            is the identifier of the section to get the text from.
     1360     * @param optDocVersion
     1361     *            is the (optional) document version of the specified oid.
    12761362     * @param collection
    12771363     *            is the collection the document resides in.
    12781364     * @return the text from the section.
    12791365     */
    1280     public String documentXMLGetText(String oid, String collection, UserContext userContext)
    1281     {
    1282         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    1283         {
    1284             return null;
    1285         }
    1286 
    1287         Document docXML = getDocXML(oid, collection, userContext);
     1366    public String documentXMLGetText(String oid, String optDocVersion, String collection, UserContext userContext)
     1367    {
     1368        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     1369        {
     1370            return null;
     1371        }
     1372
     1373        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    12881374        if (docXML == null)
    12891375        {
     
    13281414     * @param oid
    13291415     *            is the identifier of the section to set the text of.
     1416     * @param optDocVersion
     1417     *            is the (optional) document version of the specified oid.
    13301418     * @param collection
    13311419     *            is the collection the document resides in.
     
    13331421     *            is the new content element for the section.
    13341422     */
    1335     public void documentXMLSetText(String oid, String collection, Element newContent, UserContext userContext)
    1336     {
    1337         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    1338         {
    1339             return;
    1340         }
    1341 
    1342         Document docXML = getDocXML(oid, collection, userContext);
     1423    public void documentXMLSetText(String oid, String optDocVersion, String collection, Element newContent, UserContext userContext)
     1424    {
     1425        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     1426        {
     1427            return;
     1428        }
     1429
     1430        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    13431431        if (docXML == null)
    13441432        {
     
    13851473
    13861474        //Write the new change back into the file
    1387         if (!writeXMLFile(docXML, oid, collection, userContext))
     1475        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    13881476        {
    13891477            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    13971485     * @param oid
    13981486     *            is the identifier of the section to set the text of.
     1487     * @param optDocVersion
     1488     *            is the (optional) document version of the specified oid.
    13991489     * @param collection
    14001490     *            is the collection the document resides in.
     
    14021492     *            is the new text for the section.
    14031493     */
    1404     public void documentXMLSetText(String oid, String collection, String newContent, UserContext userContext)
    1405     {
    1406         if ((_errorStatus = checkOIDandCollection(oid, collection, userContext)) != NO_ERROR)
    1407         {
    1408             return;
    1409         }
    1410 
    1411         Document docXML = getDocXML(oid, collection, userContext);
     1494    public void documentXMLSetText(String oid, String optDocVersion, String collection, String newContent, UserContext userContext)
     1495    {
     1496        if ((_errorStatus = checkOIDandCollection(oid, optDocVersion, collection, userContext)) != NO_ERROR)
     1497        {
     1498            return;
     1499        }
     1500
     1501        Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
    14121502        if (docXML == null)
    14131503        {
     
    14551545
    14561546        //Write the new change back into the file
    1457         if (!writeXMLFile(docXML, oid, collection, userContext))
     1547        if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext))
    14581548        {
    14591549            _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML;
     
    14671557     *
    14681558     * @param oid
    1469      *            is the identifier of the document/section to get the doc.xml
    1470      *            of.
     1559     *            is the identifier of the document/section to get the doc.xml of.
     1560     * @param optDocVersion
     1561     *            is the (optional) document version of the specified oid.
    14711562     * @param collection
    14721563     *            is the collection the document resides in.
    14731564     * @return the file path to the doc.xml file.
    14741565     */
    1475     public String archiveGetDocumentFilePath(String oid, String collection, UserContext userContext)
     1566    public String archiveGetDocumentFilePath(String oid, String optDocVersion, String collection, UserContext userContext)
    14761567    {
    14771568        _errorStatus = NO_ERROR;
     
    14941585        }
    14951586
     1587        if ((optDocVersion != null) && (!optDocVersion.equals(""))) {
     1588            int last_dirchar_pos = assocFilePath.lastIndexOf(File.separatorChar);
     1589            String assocDir = assocFilePath.substring(0,last_dirchar_pos);
     1590            String assocFile = assocFilePath.substring(last_dirchar_pos+1);
     1591           
     1592            assocFilePath = assocDir + File.separatorChar + ARCHIVES_DOCVERSION_DIR + File.separatorChar + optDocVersion + File.separatorChar + assocFile;
     1593        }
     1594       
    14961595        String docFilePath = _siteHome + File.separatorChar + "collect" + File.separatorChar + collection + File.separatorChar + "archives" + File.separatorChar + assocFilePath;
    14971596        return docFilePath;
     
    15361635     * @param oid
    15371636     *            is the identifier of the document/section to check.
     1637     * @param optDocVersion
     1638     *            is the (optional) document version of the specified oid.
    15381639     * @param collection
    15391640     *            is the collection to search in.
    15401641     * @return true if the document/section exists, false otherwise.
    15411642     */
    1542     public boolean archiveCheckDocumentOrSectionExists(String oid, String collection, UserContext userContext)
     1643    public boolean archiveCheckDocumentOrSectionExists(String oid, String optDocVersion, String collection, UserContext userContext)
    15431644    {
    15441645        _errorStatus = NO_ERROR;
     
    15681669
    15691670        coll_db.closeDatabase();
    1570         if (section && exists)
    1571         {
    1572             Document docXML = getDocXML(oid, collection, userContext);
    1573             if (getSectionBySectionNumber(docXML, getSectionFromOID(oid)) == null)
    1574             {
    1575                 return false;
    1576             }
    1577             return true;
     1671
     1672        if (exists) {
     1673            // exists in database, but does it when optDocVersion factored in??
     1674            Document docXML = getDocXML(oid, optDocVersion, collection, userContext);
     1675
     1676            exists = (docXML != null);
     1677           
     1678            if (section && exists) {
     1679            // exists as a doc on the file system, but does the section exist in the document?
     1680            Element section_elem = getSectionBySectionNumber(docXML, getSectionFromOID(oid));
     1681
     1682            exists = (section_elem != null);
     1683            }
    15781684        }
    15791685
     
    16621768     *
    16631769     * @param oid
    1664      *            is the identifier that will be used to search for associated
    1665      *            documents.
     1770     *            is the identifier that will be used to search for associated documents.
    16661771     * @param collection
    16671772     *            is the collection whose database will be searched.
     
    18331938    }
    18341939
    1835     public int checkOIDandCollection(String oid, String collection, UserContext userContext)
     1940    public int checkOIDandCollection(String oid, String optDocVersion, String collection, UserContext userContext)
    18361941    {
    18371942        if (oid == null || oid.equals(""))
     
    18451950        }
    18461951
    1847         if (!archiveCheckDocumentOrSectionExists(oid, collection, userContext))
     1952        if (!archiveCheckDocumentOrSectionExists(oid, optDocVersion, collection, userContext))
    18481953        {
    18491954            return ERROR_SOURCE_DOCUMENT_OR_SECTION_DOES_NOT_EXIST;
     
    19012006    }
    19022007
    1903     public boolean writeXMLFile(Document doc, String oid, String collection, UserContext userContext)
     2008    public boolean writeXMLFile(Document doc, String oid, String optDocVersion, String collection, UserContext userContext)
    19042009    {
    19052010        try
     
    19072012            DOMSource source = new DOMSource(doc);
    19082013
    1909             String test = archiveGetDocumentFilePath(oid, collection, userContext);
     2014            String test = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext);
    19102015            File xmlFile = new File(test);
    19112016            Result result = new StreamResult(xmlFile);
     
    19212026    }
    19222027
    1923     public Document getDocXML(String oid, String collection, UserContext userContext)
     2028    public Document getDocXML(String oid, String optDocVersion, String collection, UserContext userContext)
    19242029    {
    19252030        if (oid.contains("."))
     
    19312036        //if ((docXML = _docCache.get(oid + "__" + collection)) == null)
    19322037        //  {
    1933             String filePath = archiveGetDocumentFilePath(oid, collection, userContext);
     2038            String filePath = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext);
    19342039            File docFile = new File(filePath);
    19352040
    19362041            if (!docFile.exists())
    19372042            {
     2043                System.err.println("Error - GSDocumentModel::getDocXML() failed to find: " + filePath);
    19382044                return null;
    19392045            }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r35295 r37177  
    171171    // document stuff
    172172    public static final String DOC_TYPE_ATT = "docType";
     173        public static final String DOC_VERSION_ATT = "docVersion";  // File-Level Document-Version History _fldv_history
    173174    public static final String DOC_NODE_ELEM = "documentNode";
    174175    public static final String NODE_CONTENT_ELEM = "nodeContent";
Note: See TracChangeset for help on using the changeset viewer.