Changeset 37177 for main/trunk/greenstone3/src
- Timestamp:
- 2023-01-21T20:34:59+13:00 (17 months ago)
- 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 57 57 public static final String REALISTIC_BOOK_ARG = "book"; 58 58 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 61 62 /** 62 63 * if this is set to true, when a document is displayed, any annotation type … … 205 206 // are we editing mode? just get the archive document, convert to our internal doc format, and return it 206 207 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); 208 210 } 209 211 … … 825 827 } 826 828 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 ) { 828 831 // call get archive doc 829 832 Element dx_message = doc.createElement(GSXML.MESSAGE_ELEM); … … 834 837 dx_section.setAttribute(GSXML.NODE_ID_ATT, document_id); 835 838 dx_section.setAttribute(GSXML.COLLECTION_ATT, collection); 839 dx_section.setAttribute(GSXML.DOC_VERSION_ATT, opt_document_version); 836 840 dx_request.appendChild(dx_section); 837 841 -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/ArchiveIO.java
r28966 r37177 124 124 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false); 125 125 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); 130 131 131 132 Element metadataList = result_doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); … … 139 140 { 140 141 //Create a new (empty) result message 141 142 Document result_doc = XMLConverter.newDOM(); 142 143 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM); 143 144 result.setAttribute(GSXML.FROM_ATT, ARCHIVE_GET_SOURCE_FILE_OID); … … 190 191 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false); 191 192 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); 196 198 if(_GSDM.checkError(result, ARCHIVE_CHECK_DOCUMENT_OR_SECTION_EXISTS)) 197 199 { … … 212 214 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS); 213 215 216 214 217 UserContext userContext = new UserContext(request); 215 218 … … 225 228 String collection = null; 226 229 String oid = null; 227 230 //String optDocVersion = null; 231 228 232 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM); 229 233 for (int i = 0; i < params.getLength(); i++) … … 256 260 oid = value; 257 261 } 262 /*else if (name.equals(GSXML.DOC_VERSION_ATT)) 263 { 264 optDocVersion = value; 265 }*/ 258 266 } 259 267 } … … 285 293 String collection = null; 286 294 String oid = null; 287 295 // String optDocVersion = null; 296 288 297 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM); 289 298 for (int i = 0; i < params.getLength(); i++) … … 301 310 oid = value; 302 311 } 312 /*else if (name.equals(GSXML.DOC_VERSION_ATT)) 313 { 314 optDocVersion = value; 315 }*/ 303 316 } 304 317 … … 328 341 HashMap<String, Serializable> params = GSXML.extractParams(param_list, false); 329 342 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 333 347 ArrayList<String> assocFiles = _GSDM.archiveGetAssociatedImportFiles(oid, collection, userContext); 334 348 if(_GSDM.checkError(result, ARCHIVE_GET_ASSOCIATED_IMPORT_FILES)) -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocXMLUtil.java
r36975 r37177 132 132 { 133 133 Element currentDoc = (Element) docList.item(i); 134 String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT);134 String oid = currentDoc.getAttribute(GSXML.NODE_ID_ATT); 135 135 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); 138 139 if(_GSDM.checkError(result, DOC_XML_CREATE_EMPTY_FILE_SERVICE)) 139 140 { … … 146 147 protected Element processDocXMLGetMetadata(Element request) 147 148 { 148 149 Document result_doc = XMLConverter.newDOM(); 149 150 Element result = GSXML.createBasicResponse(result_doc, DOC_XML_GET_METADATA_SERVICE); 150 151 … … 162 163 { 163 164 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); 169 171 if(_GSDM.checkError(result, DOC_XML_GET_METADATA_SERVICE)) 170 172 { … … 202 204 { 203 205 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); 207 210 String newMetadataValue = currentMetadata.getAttribute(GSXML.VALUE_ATT); 208 211 … … 239 242 return result; 240 243 } 241 _GSDM.documentXMLSetMetadata(oid, collection, metadataName, newMetadataValue, pos, op, userContext);244 _GSDM.documentXMLSetMetadata(oid, optDocVersion, collection, metadataName, newMetadataValue, pos, op, userContext); 242 245 if(_GSDM.checkError(result, DOC_XML_SET_METADATA_SERVICE)) 243 246 { … … 248 251 else if (oldMetadataValue != null && !oldMetadataValue.equals("")) 249 252 { 250 _GSDM.documentXMLReplaceMetadata(oid, collection, metadataName, oldMetadataValue, newMetadataValue, userContext);253 _GSDM.documentXMLReplaceMetadata(oid, optDocVersion, collection, metadataName, oldMetadataValue, newMetadataValue, userContext); 251 254 if(_GSDM.checkError(result, DOC_XML_SET_METADATA_SERVICE)) 252 255 { … … 282 285 { 283 286 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); 288 292 if(_GSDM.checkError(result, DOC_XML_CREATE_SECTION_SERVICE)) 289 293 { … … 312 316 { 313 317 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); 318 323 if(_GSDM.checkError(result, DOC_XML_DELETE_SECTION_SERVICE)) 319 324 { … … 342 347 { 343 348 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); 348 354 if(_GSDM.checkError(result, DOC_XML_GET_SECTION_SERVICE)) 349 355 { 350 logger.error("there was an error getting the archive section for " +oid);351 356 logger.error("there was an error getting the archive section for " +oid); 357 return result; 352 358 } 353 359 result.appendChild(result_doc.importNode(section,true)); … … 374 380 { 375 381 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 378 386 String operation = currentSection.getAttribute("operation"); 379 387 … … 392 400 } 393 401 394 _GSDM.documentXMLSetSection(oid, collection, currentSection, op, userContext);402 _GSDM.documentXMLSetSection(oid, optDocVersion, collection, currentSection, op, userContext); 395 403 if(_GSDM.checkError(result, DOC_XML_SET_SECTION_SERVICE)) 396 404 { … … 420 428 { 421 429 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); 426 435 if(_GSDM.checkError(result, DOC_XML_GET_TEXT_SERVICE)) 427 436 { … … 463 472 { 464 473 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); 469 479 if(_GSDM.checkError(result, DOC_XML_SET_TEXT_SERVICE)) 470 480 { -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocumentMaker.java
r30731 r37177 142 142 //Get information about the current new document 143 143 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); 148 149 if (_GSDM.checkError(result, DOCUMENT_CREATE)) 149 150 { … … 173 174 { 174 175 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); 179 181 if (_GSDM.checkError(result, DOCUMENT_DELETE)) 180 182 { … … 204 206 { 205 207 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); 210 214 String operation = currentDoc.getAttribute("operation"); 211 215 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); 213 219 if (_GSDM.checkError(result, DOCUMENT_DUPLICATE)) 214 220 { … … 238 244 { 239 245 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); 242 249 243 250 NodeList requestedInfoList = currentDoc.getElementsByTagName("info"); //TODO: Replace info with a constant … … 249 256 } 250 257 251 _GSDM.documentGetInformation(oid, collection, requestedInfo, userContext);258 _GSDM.documentGetInformation(oid, optDocVersion, collection, requestedInfo, userContext); 252 259 if (_GSDM.checkError(result, DOCUMENT_GET_INFORMATION)) 253 260 { … … 277 284 { 278 285 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); 279 323 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 processDocument Merge(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); 302 346 return result; 303 347 } … … 310 354 { 311 355 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); 346 359 String splitPoint = currentDoc.getAttribute("splitpoint"); 347 360 … … 357 370 } 358 371 359 _GSDM.documentSplit(oid, collection, split, userContext);372 _GSDM.documentSplit(oid, optDocVersion, collection, split, userContext); 360 373 if (_GSDM.checkError(result, DOCUMENT_SPLIT)) 361 374 { … … 413 426 if (operation.equals("move") || operation.equals("duplicate")) 414 427 { 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"); 419 434 String subOperation = (String) keyValueMap.get("subOperation"); 420 435 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); 422 439 } 423 440 else if (operation.equals("createDocument")) 424 441 { 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); 429 447 } 430 448 else if (operation.equals("create")) 431 449 { 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"); 434 453 String subOperation = (String) keyValueMap.get("subOperation"); 435 454 436 //_GSDM.documentCreate(oid, collection, userContext); <--- Maybe go back to this437 _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); 438 457 } 439 458 else if (operation.equals("delete")) 440 459 { 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); 445 465 } 446 466 else if (operation.equals("setText")) 447 467 { 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"); 450 471 String newContent = (String) keyValueMap.get("text"); 451 472 452 _GSDM.documentXMLSetText(oid, collection, newContent, userContext);473 _GSDM.documentXMLSetText(oid, optDocVersion, collection, newContent, userContext); 453 474 // 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); 455 476 // only top level doc ids are in database 456 477 markDocumentInFlatDatabase("R", collection, OID.getTop(oid)); -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSDocumentModel.java
r36107 r37177 31 31 { 32 32 //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 34 39 protected static final String ARCHIVEINFSRC = "archiveinf-src"; 35 40 protected static final String ARCHIVEINFDOC = "archiveinf-doc"; 36 41 42 37 43 //Set operations 38 44 public static final int OPERATION_REPLACE = 1; … … 121 127 * @param oid 122 128 * is the identifier of the document/section to create. 129 * @param optDocVersion 130 * is the (optional) document version of the specified oid. 123 131 * @param collection 124 132 * is the collection we want to create the document/section in. 125 133 */ 126 public void documentCreate(String oid, String collection, UserContext userContext)134 public void documentCreate(String oid, String optDocVersion, String collection, UserContext userContext) 127 135 { 128 136 _errorStatus = NO_ERROR; … … 141 149 } 142 150 143 if (archiveCheckDocumentOrSectionExists(oid, collection, userContext))151 if (archiveCheckDocumentOrSectionExists(oid, optDocVersion, collection, userContext)) 144 152 { 145 153 _errorStatus = ERROR_DESTINATION_DOCUMENT_OR_SECTION_ALREADY_EXISTS; … … 157 165 { 158 166 //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 160 168 } 161 169 else 162 170 { 163 documentXMLCreateSection(oid, collection, userContext);171 documentXMLCreateSection(oid, optDocVersion, collection, userContext); 164 172 } 165 173 } … … 170 178 * @param oid 171 179 * is the identifier of the document/section to delete. 180 * @param optDocVersion 181 * is the (optional) document version of the specified oid. 172 182 * @param collection 173 183 * is the collection to delete the document/section from. 174 184 */ 175 public void documentDelete(String oid, String collection, UserContext userContext)185 public void documentDelete(String oid, String optDocVersion, String collection, UserContext userContext) 176 186 { 177 187 _errorStatus = NO_ERROR; … … 187 197 } 188 198 189 if (!archiveCheckDocumentOrSectionExists(oid, collection, userContext))199 if (!archiveCheckDocumentOrSectionExists(oid, optDocVersion, collection, userContext)) 190 200 { 191 201 _errorStatus = ERROR_SOURCE_DOCUMENT_OR_SECTION_DOES_NOT_EXIST; … … 202 212 if (!section) 203 213 { 204 String archivesFile = archiveGetDocumentFilePath(oid, collection, userContext);214 String archivesFile = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext); 205 215 String archivesFolder = archivesFile.substring(0, archivesFile.lastIndexOf(File.separator)); 206 216 File dirToDelete = new File(archivesFolder); … … 212 222 } 213 223 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 } 216 229 } 217 230 else 218 231 { 219 documentXMLDeleteSection(oid, collection, userContext);232 documentXMLDeleteSection(oid, optDocVersion, collection, userContext); 220 233 } 221 234 } … … 225 238 * 226 239 * @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. 229 243 * @param collection 230 244 * is the collection the source document resides in. … … 232 246 * is the new identifier for the document/section (it cannot 233 247 * already exist). 248 * @param optNewDocVersion 249 * is the (optional) document version of the specified newOID. 234 250 * @param newCollection 235 251 * is the collection the new document/section will be copied to. … … 237 253 * instead. 238 254 */ 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) 242 260 { 243 261 return; … … 263 281 case OPERATION_TYPE_DOC_TO_DOC: 264 282 { 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); 266 295 if (_errorStatus != NO_ERROR) 267 296 { … … 293 322 { 294 323 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 } 295 330 } 296 331 … … 300 335 case OPERATION_TYPE_DOC_TO_SEC: 301 336 { 302 Document originalDocument = getDocXML(oid, collection, userContext);337 Document originalDocument = getDocXML(oid, optDocVersion, collection, userContext); 303 338 Element originalSection = getTopLevelSectionElement(originalDocument); 304 339 305 documentXMLCreateSection(newOID, newCollection, userContext);340 documentXMLCreateSection(newOID, optNewDocVersion, newCollection, userContext); 306 341 if (_errorStatus != NO_ERROR) 307 342 { … … 309 344 } 310 345 311 documentXMLSetSection(newOID, newCollection, originalSection, operation, userContext);346 documentXMLSetSection(newOID, optNewDocVersion, newCollection, originalSection, operation, userContext); 312 347 313 348 if (move) 314 349 { 315 String archiveDirStr = archiveGetDocumentFilePath(oid, collection, userContext);350 String archiveDirStr = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext); 316 351 if (_errorStatus != NO_ERROR) 317 352 { … … 324 359 { 325 360 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 } 326 367 } 327 368 } … … 330 371 case OPERATION_TYPE_SEC_TO_DOC: 331 372 { 332 Document originalDocument = getDocXML(oid, collection, userContext);373 Document originalDocument = getDocXML(oid, optDocVersion, collection, userContext); 333 374 Element originalSection = getSectionBySectionNumber(originalDocument, getSectionFromOID(oid)); 334 375 335 documentCreate(newOID, newCollection, userContext);376 documentCreate(newOID, optNewDocVersion, newCollection, userContext); 336 377 if (_errorStatus != NO_ERROR) 337 378 { … … 339 380 } 340 381 341 documentXMLCreateSection(newOID, newCollection, userContext);382 documentXMLCreateSection(newOID, optNewDocVersion, newCollection, userContext); 342 383 if (_errorStatus != NO_ERROR) 343 384 { … … 345 386 } 346 387 347 documentXMLSetSection(newOID, newCollection, originalSection, operation, userContext);388 documentXMLSetSection(newOID, optNewDocVersion, newCollection, originalSection, operation, userContext); 348 389 349 390 if (move) 350 391 { 351 originalDocument = getDocXML(oid, collection, userContext);392 originalDocument = getDocXML(oid, optDocVersion, collection, userContext); 352 393 originalSection.getParentNode().removeChild(originalSection); 353 394 354 395 //Write the new change back into the file 355 if (!writeXMLFile(originalDocument, oid, collection, userContext))396 if (!writeXMLFile(originalDocument, oid, optDocVersion, collection, userContext)) 356 397 { 357 398 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 365 406 case OPERATION_TYPE_SEC_TO_SEC: 366 407 { 367 Document originalDocument = getDocXML(oid, collection, userContext);408 Document originalDocument = getDocXML(oid, optDocVersion, collection, userContext); 368 409 Element originalSection = getSectionBySectionNumber(originalDocument, getSectionFromOID(oid)); 369 410 370 411 if (operation == OPERATION_REPLACE) 371 412 { 372 documentXMLCreateSection(newOID, newCollection, userContext);413 documentXMLCreateSection(newOID, optNewDocVersion, newCollection, userContext); 373 414 if (_errorStatus != NO_ERROR) 374 415 { … … 377 418 } 378 419 379 documentXMLSetSection(newOID, newCollection, originalSection, operation, userContext);420 documentXMLSetSection(newOID, optNewDocVersion, newCollection, originalSection, operation, userContext); 380 421 if (_errorStatus != NO_ERROR) 381 422 { … … 385 426 if (move) 386 427 { 387 originalDocument = getDocXML(oid, collection, userContext);428 originalDocument = getDocXML(oid, optDocVersion, collection, userContext); 388 429 originalSection.getParentNode().removeChild(originalSection); 389 430 390 431 //Write the new change back into the file 391 if (!writeXMLFile(originalDocument, oid, collection, userContext))432 if (!writeXMLFile(originalDocument, oid, optDocVersion, collection, userContext)) 392 433 { 393 434 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 417 458 * @param oid 418 459 * is the identifier of the document or section. 460 * @param optDocVersion 461 * is the (optional) document version of the specified oid. 419 462 * @param collection 420 463 * is the collection the document or section resides in. … … 423 466 * @return This returns an array containing the requested information. 424 467 */ 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) 428 471 { 429 472 return null; … … 449 492 * @param oid 450 493 * the identifier of the section that is to be merged. 494 * @param optDocVersion 495 * is the (optional) document version of the specified oid. 451 496 * @param collection 452 497 * the collection the section resides in. … … 455 500 * merged into. 456 501 */ 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) 465 525 { 466 526 return; … … 492 552 } 493 553 494 Document docXML = getDocXML(oid, collection, userContext);554 Document docXML = getDocXML(oid, optDocVersion, collection, userContext); 495 555 if (docXML == null) 496 556 { … … 557 617 } 558 618 559 documentXMLSetSection(mergeOID, collection, sourceSection, OPERATION_REPLACE, userContext);619 documentXMLSetSection(mergeOID, optMergeDocVersion, collection, sourceSection, OPERATION_REPLACE, userContext); 560 620 if (_errorStatus != NO_ERROR) 561 621 { … … 563 623 } 564 624 565 documentXMLDeleteSection(oid, collection, userContext);625 documentXMLDeleteSection(oid, optDocVersion, collection, userContext); 566 626 } 567 627 … … 573 633 * @param oid 574 634 * is the identifer of the section to be split. 635 * @param optDocVersion 636 * is the (optional) document version of the specified oid. 575 637 * @param collection 576 638 * is the collection the section resides in. … … 578 640 * is the point in the text we want to split at. 579 641 */ 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); 588 650 if (docXML == null) 589 651 { … … 632 694 newSection.appendChild(newContent); 633 695 634 documentXMLSetSection(oid, collection, newSection, OPERATION_INSERT_BEFORE, userContext);696 documentXMLSetSection(oid, optDocVersion, collection, newSection, OPERATION_INSERT_BEFORE, userContext); 635 697 if (_errorStatus != NO_ERROR) 636 698 { … … 640 702 641 703 //Write the new change back into the file 642 if (!writeXMLFile(docXML, oid, collection, userContext))704 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 643 705 { 644 706 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 654 716 * is the collection the new document will reside in. 655 717 */ 656 public void documentXMLCreate DocXML(String oid, String collection, UserContext userContext)718 public void documentXMLCreateNewImportDocXML(String oid, String collection, UserContext userContext) 657 719 { 658 720 _errorStatus = NO_ERROR; … … 714 776 * 715 777 * @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. 718 781 * @param collection 719 782 * is the collection the section or document resides in. … … 722 785 * @return an array of metadata elements containing the resquested metadata 723 786 */ 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) 727 790 { 728 791 return null; … … 734 797 } 735 798 736 Document docXML = getDocXML(oid, collection, userContext);799 Document docXML = getDocXML(oid, optDocVersion, collection, userContext); 737 800 if (docXML == null) 738 801 { … … 748 811 * @param oid 749 812 * 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. 751 816 * @param collection 752 817 * is the collection the document/section resides in. … … 761 826 * OPERATION_INSERT_AFTER or OPERATION_APPEND. 762 827 */ 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) 766 831 { 767 832 return; … … 778 843 } 779 844 780 Document docXML = getDocXML(oid, collection, userContext);845 Document docXML = getDocXML(oid, optDocVersion, collection, userContext); 781 846 if (docXML == null) 782 847 { … … 833 898 834 899 //Write the new change back into the file 835 if (!writeXMLFile(docXML, oid, collection, userContext))900 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 836 901 { 837 902 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 844 909 * 845 910 * @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. 848 914 * @param collection 849 915 * is the collection the document resides in. … … 853 919 * is position of the item that is to be deleted. 854 920 */ 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) 858 924 { 859 925 return; … … 865 931 } 866 932 867 Document docXML = getDocXML(oid, collection, userContext);933 Document docXML = getDocXML(oid, optDocVersion, collection, userContext); 868 934 if (docXML == null) 869 935 { … … 880 946 881 947 //Write the new change back into the file 882 if (!writeXMLFile(docXML, oid, collection, userContext))948 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 883 949 { 884 950 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 892 958 * 893 959 * @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. 896 963 * @param collection 897 964 * is the collection the document resides in. … … 899 966 * is the name of the metadata to delete. 900 967 */ 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) 904 971 { 905 972 return; … … 911 978 } 912 979 913 Document docXML = getDocXML(oid, collection, userContext);980 Document docXML = getDocXML(oid, optDocVersion, collection, userContext); 914 981 if (docXML == null) 915 982 { … … 926 993 927 994 //Write the new change back into the file 928 if (!writeXMLFile(docXML, oid, collection, userContext))995 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 929 996 { 930 997 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 938 1005 * 939 1006 * @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. 942 1010 * @param collection 943 1011 * is the collection the document resides in. … … 951 1019 * value. 952 1020 */ 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) 956 1024 { 957 1025 return; … … 973 1041 } 974 1042 975 Document docXML = getDocXML(oid, collection, userContext);1043 Document docXML = getDocXML(oid, optDocVersion, collection, userContext); 976 1044 if (docXML == null) 977 1045 { … … 993 1061 994 1062 //Write the new change back into the file 995 if (!writeXMLFile(docXML, oid, collection, userContext))1063 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 996 1064 { 997 1065 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 1004 1072 * @param oid 1005 1073 * is the identifier of the section to be created. 1074 * @param optDocVersion 1075 * is the (optional) document version of the specified oid. 1006 1076 * @param collection 1007 1077 * is the collection the document resides in. 1008 1078 */ 1009 public void documentXMLCreateSection(String oid, String collection, UserContext userContext)1079 public void documentXMLCreateSection(String oid, String optDocVersion, String collection, UserContext userContext) 1010 1080 { 1011 1081 _errorStatus = NO_ERROR; … … 1021 1091 } 1022 1092 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 1026 1104 if (_errorStatus != NO_ERROR) 1027 1105 { … … 1030 1108 } 1031 1109 1032 Document docXML = getDocXML(oid, collection, userContext);1110 Document docXML = getDocXML(oid, optDocVersion, collection, userContext); 1033 1111 if (docXML == null) 1034 1112 { … … 1090 1168 1091 1169 //Write the new change back into the file 1092 if (!writeXMLFile(docXML, oid, collection, userContext))1170 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 1093 1171 { 1094 1172 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 1101 1179 * @param oid 1102 1180 * is the identifier of the section to be deleted. 1181 * @param optDocVersion 1182 * is the (optional) document version of the specified oid. 1103 1183 * @param collection 1104 1184 * is the collection the document resides in. 1105 1185 */ 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); 1114 1194 if (docXML == null) 1115 1195 { … … 1128 1208 1129 1209 //Write the new change back into the file 1130 if (!writeXMLFile(docXML, oid, collection, userContext))1210 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 1131 1211 { 1132 1212 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 1139 1219 * @param oid 1140 1220 * is the identifier of the section to get. 1221 * @param optDocVersion 1222 * is the (optional) document version of the specified oid. 1141 1223 * @param collection 1142 1224 * is the collection the document resides in. 1143 1225 * @return the requested section. 1144 1226 */ 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); 1153 1235 if (docXML == null) 1154 1236 { … … 1181 1263 * @param oid 1182 1264 * is the identifier of the section to be set. 1265 * @param optDocVersion 1266 * is the (optional) document version of the specified oid. 1183 1267 * @param collection 1184 1268 * is the collection the section will reside in. … … 1190 1274 * @throws IOException 1191 1275 */ 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); 1200 1284 if (docXML == null) 1201 1285 { … … 1262 1346 1263 1347 //Write the new change back into the file 1264 if (!writeXMLFile(docXML, oid, collection, userContext))1348 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 1265 1349 { 1266 1350 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 1274 1358 * @param oid 1275 1359 * is the identifier of the section to get the text from. 1360 * @param optDocVersion 1361 * is the (optional) document version of the specified oid. 1276 1362 * @param collection 1277 1363 * is the collection the document resides in. 1278 1364 * @return the text from the section. 1279 1365 */ 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); 1288 1374 if (docXML == null) 1289 1375 { … … 1328 1414 * @param oid 1329 1415 * is the identifier of the section to set the text of. 1416 * @param optDocVersion 1417 * is the (optional) document version of the specified oid. 1330 1418 * @param collection 1331 1419 * is the collection the document resides in. … … 1333 1421 * is the new content element for the section. 1334 1422 */ 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); 1343 1431 if (docXML == null) 1344 1432 { … … 1385 1473 1386 1474 //Write the new change back into the file 1387 if (!writeXMLFile(docXML, oid, collection, userContext))1475 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 1388 1476 { 1389 1477 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 1397 1485 * @param oid 1398 1486 * is the identifier of the section to set the text of. 1487 * @param optDocVersion 1488 * is the (optional) document version of the specified oid. 1399 1489 * @param collection 1400 1490 * is the collection the document resides in. … … 1402 1492 * is the new text for the section. 1403 1493 */ 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); 1412 1502 if (docXML == null) 1413 1503 { … … 1455 1545 1456 1546 //Write the new change back into the file 1457 if (!writeXMLFile(docXML, oid, collection, userContext))1547 if (!writeXMLFile(docXML, oid, optDocVersion, collection, userContext)) 1458 1548 { 1459 1549 _errorStatus = ERROR_COULD_NOT_WRITE_TO_DOC_XML; … … 1467 1557 * 1468 1558 * @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. 1471 1562 * @param collection 1472 1563 * is the collection the document resides in. 1473 1564 * @return the file path to the doc.xml file. 1474 1565 */ 1475 public String archiveGetDocumentFilePath(String oid, String collection, UserContext userContext)1566 public String archiveGetDocumentFilePath(String oid, String optDocVersion, String collection, UserContext userContext) 1476 1567 { 1477 1568 _errorStatus = NO_ERROR; … … 1494 1585 } 1495 1586 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 1496 1595 String docFilePath = _siteHome + File.separatorChar + "collect" + File.separatorChar + collection + File.separatorChar + "archives" + File.separatorChar + assocFilePath; 1497 1596 return docFilePath; … … 1536 1635 * @param oid 1537 1636 * is the identifier of the document/section to check. 1637 * @param optDocVersion 1638 * is the (optional) document version of the specified oid. 1538 1639 * @param collection 1539 1640 * is the collection to search in. 1540 1641 * @return true if the document/section exists, false otherwise. 1541 1642 */ 1542 public boolean archiveCheckDocumentOrSectionExists(String oid, String collection, UserContext userContext)1643 public boolean archiveCheckDocumentOrSectionExists(String oid, String optDocVersion, String collection, UserContext userContext) 1543 1644 { 1544 1645 _errorStatus = NO_ERROR; … … 1568 1669 1569 1670 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 } 1578 1684 } 1579 1685 … … 1662 1768 * 1663 1769 * @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. 1666 1771 * @param collection 1667 1772 * is the collection whose database will be searched. … … 1833 1938 } 1834 1939 1835 public int checkOIDandCollection(String oid, String collection, UserContext userContext)1940 public int checkOIDandCollection(String oid, String optDocVersion, String collection, UserContext userContext) 1836 1941 { 1837 1942 if (oid == null || oid.equals("")) … … 1845 1950 } 1846 1951 1847 if (!archiveCheckDocumentOrSectionExists(oid, collection, userContext))1952 if (!archiveCheckDocumentOrSectionExists(oid, optDocVersion, collection, userContext)) 1848 1953 { 1849 1954 return ERROR_SOURCE_DOCUMENT_OR_SECTION_DOES_NOT_EXIST; … … 1901 2006 } 1902 2007 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) 1904 2009 { 1905 2010 try … … 1907 2012 DOMSource source = new DOMSource(doc); 1908 2013 1909 String test = archiveGetDocumentFilePath(oid, collection, userContext);2014 String test = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext); 1910 2015 File xmlFile = new File(test); 1911 2016 Result result = new StreamResult(xmlFile); … … 1921 2026 } 1922 2027 1923 public Document getDocXML(String oid, String collection, UserContext userContext)2028 public Document getDocXML(String oid, String optDocVersion, String collection, UserContext userContext) 1924 2029 { 1925 2030 if (oid.contains(".")) … … 1931 2036 //if ((docXML = _docCache.get(oid + "__" + collection)) == null) 1932 2037 // { 1933 String filePath = archiveGetDocumentFilePath(oid, collection, userContext);2038 String filePath = archiveGetDocumentFilePath(oid, optDocVersion, collection, userContext); 1934 2039 File docFile = new File(filePath); 1935 2040 1936 2041 if (!docFile.exists()) 1937 2042 { 2043 System.err.println("Error - GSDocumentModel::getDocXML() failed to find: " + filePath); 1938 2044 return null; 1939 2045 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r35295 r37177 171 171 // document stuff 172 172 public static final String DOC_TYPE_ATT = "docType"; 173 public static final String DOC_VERSION_ATT = "docVersion"; // File-Level Document-Version History _fldv_history 173 174 public static final String DOC_NODE_ELEM = "documentNode"; 174 175 public static final String NODE_CONTENT_ELEM = "nodeContent";
Note:
See TracChangeset
for help on using the changeset viewer.