/** * @param sor * @throws XdsPatientIdDoesNotMatchException * @throws XdsDeprecatedException * @throws XdsUnknownPatientIdException * @throws MetadataException * @throws MetadataValidationException * @throws XDSNonIdenticalHashException * @throws XdsInternalException * @throws XdsException */ void handleSubmitObjectsRequest(OMElement sor) throws XdsPatientIdDoesNotMatchException, XDSNonIdenticalHashException, XdsDeprecatedException, MetadataValidationException, MetadataException, XdsInternalException, XdsException { // Run XML schema validation. RegistryUtility.schema_validate_local(sor, MetadataTypes.METADATA_TYPE_Rb); boolean commitCompleted = false; // Get backend registry instance. BackendRegistry backendRegistry = new BackendRegistry(log_message); try { // Create metadata instance from SOR. Metadata m = new Metadata(sor); this.logMetadata(m); SubmitObjectsRequestStoredQuerySupport sqSupport = new SubmitObjectsRequestStoredQuerySupport(response, log_message, backendRegistry); // Run validations. RegistryObjectValidator rov = new RegistryObjectValidator(response, log_message, backendRegistry); rov.validate(m, true /* isSubmit */, response.registryErrorList, this.getConfigActor()); if (!response.has_errors()) { // Only continue if response does not have any errors (a bit ugly). // Change symbolic names to UUIDs. IdParser idParser = new IdParser(m); idParser.compileSymbolicNamesIntoUuids(); // If this submission includes a DocumentEntry replace and the original DocumentEntry is in // a folder // then the replacement document must be put into the folder as well. This must happen here // so the following logic to update folder lastUpdateTime can be triggered. this.updateFolderContentsOnDocumentReplace(m, backendRegistry); // if this submission adds a document to a folder then update that folder's lastUpdateTime // Slot this.updateFoldersLastUpdateTimeSlot(m, sqSupport, backendRegistry); m.setStatusOnApprovableObjects(); // Finally, make the actual submission: this.submitRegistryRequest(m, backendRegistry, "SubmitObjectsRequest"); // Approve // this.approveObjects(m, backendRegistry); // Deprecate this.deprecateObjects(m, sqSupport, backendRegistry); } backendRegistry.commit(); commitCompleted = true; } finally { if (!commitCompleted) { backendRegistry.rollback(); } } }
public Metadata run_internal() throws XdsInternalException, XdsException { OMElement results = impl(); Metadata m = MetadataParser.parseNonSubmission(results); if (log_message != null) log_message.addOtherParam("Results structure", m.structure()); return m; }
/** * @param m * @param sqSupport * @param backendRegistry * @throws XdsException */ private void updateFoldersLastUpdateTimeSlot( Metadata m, SubmitObjectsRequestStoredQuerySupport sqSupport, BackendRegistry backendRegistry) throws XdsException { // Update any folders "lastUpdateTime" slot with the current time: m.updateFoldersLastUpdateTimeSlot(); // if this submission adds a document to a folder then update that folder's lastUpdateTime Slot for (OMElement assoc : m.getAssociations()) { if (MetadataSupport.xdsB_eb_assoc_type_has_member.equals(m.getAssocType(assoc))) { String sourceId = m.getAssocSource(assoc); if (!m.getSubmissionSetId().equals(sourceId) && !m.getFolderIds().contains(sourceId)) { // Assoc src not part of the submission logger.info("Adding to Folder (1)" + sourceId); if (this.isFolder(sourceId, sqSupport)) { logger.info("Adding to Folder (2)" + sourceId); OMElement res = backendRegistry.basicQuery( "SELECT * from RegistryPackage rp WHERE rp.id='" + sourceId + "'", true); // Update any folders "lastUpdateTime" slot: Metadata fm = MetadataParser.parseNonSubmission(res); fm.updateFoldersLastUpdateTimeSlot(); // OMElement to_backend = fm.getV3SubmitObjectsRequest(); // log_message.addOtherParam("From Registry Adaptor", to_backend); this.submitRegistryRequest(fm, backendRegistry, "Update Folder LastUpdateTime Slot"); } } } } }
/** * @param m * @param rov * @param backendRegistry * @throws MetadataValidationException * @throws MetadataException * @throws XdsException */ private void deprecateObjects( Metadata m, SubmitObjectsRequestStoredQuerySupport sqSupport, BackendRegistry backendRegistry) throws MetadataValidationException, MetadataException, XdsException { List<String> deprecatableObjectIds = m.getDeprecatableObjectIds(); // add to the list of things to deprecate, any XFRM or APND documents hanging off documents // in the deprecatable_object_ids list List<String> XFRMandAPNDDocuments = sqSupport.getXFRMandAPNDDocuments(deprecatableObjectIds); deprecatableObjectIds.addAll(XFRMandAPNDDocuments); if (deprecatableObjectIds.size() > 0) { // validate that these are documents first List<String> missing = sqSupport.getMissingDocuments(deprecatableObjectIds); if (missing != null) { throw new XdsException( "The following documents were referenced by this submission but are not present in the registry: " + missing); } this.submitDeprecateObjectsRequest(backendRegistry, deprecatableObjectIds); } }
/** * @param m * @throws MetadataException */ private void logMetadata(Metadata m) throws MetadataException { // Log relevant data (if logger is turned on of course). if (log_message.isLogEnabled() == true) { log_message.addOtherParam("SSuid", m.getSubmissionSetUniqueId()); ArrayList<String> doc_uids = new ArrayList<String>(); for (String id : m.getExtrinsicObjectIds()) { String uid = m.getUniqueIdValue(id); if (uid != null && !uid.equals("")) { doc_uids.add(uid); } } log_message.addOtherParam("DOCuids", doc_uids); ArrayList<String> fol_uids = new ArrayList<String>(); for (String id : m.getFolderIds()) { String uid = m.getUniqueIdValue(id); if (uid != null && !uid.equals("")) { fol_uids.add(uid); } } log_message.addOtherParam("FOLuids", fol_uids); log_message.addOtherParam("Structure", m.structure()); } }
/** * @param m * @param backendRegistry * @throws XdsException */ private void updateFolderContentsOnDocumentReplace(Metadata m, BackendRegistry backendRegistry) throws XdsException { // If this submission includes a DocumentEntry replace and the original DocumentEntry is in a // folder // then the replacement document must be put into the folder as well. This must happen here // so the following logic to update folder lastUpdateTime can be triggered. HashMap<String, String> rplcToOrigIds = new HashMap<String, String>(); for (OMElement assoc : m.getAssociations()) { if (MetadataSupport.xdsB_ihe_assoc_type_rplc.equals(m.getAssocType(assoc))) { rplcToOrigIds.put(m.getAssocSource(assoc), m.getAssocTarget(assoc)); } } for (String replacementDocumentId : rplcToOrigIds.keySet()) { String originalDocumentId = rplcToOrigIds.get(replacementDocumentId); // for each original document, find the collection of folders it belongs to Metadata me = this.findFoldersForDocumentByUuid(originalDocumentId, backendRegistry); List<String> folderIds = me.getObjectIds(me.getObjectRefs()); // for each folder, add an association placing replacment in that folder // This brings up interesting question, should the Assoc between SS and Assoc be generated // also? YES! for (String fid : folderIds) { OMElement assoc = m.addAssociation( m.makeAssociation( MetadataSupport.xdsB_eb_assoc_type_has_member, fid, replacementDocumentId)); OMElement assoc2 = m.addAssociation( m.makeAssociation( MetadataSupport.xdsB_eb_assoc_type_has_member, m.getSubmissionSetId(), assoc.getAttributeValue(MetadataSupport.id_qname))); } } }