예제 #1
0
 @Test
 public void checkMissingMimeType() throws Exception {
   log.info(
       "\n############################# TEST: missing mimeType in DocumentEntry  ############################");
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   ExtrinsicObjectType doc =
       (ExtrinsicObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
   doc.setMimeType("");
   doRegisterDocumentAndCheckError(
       req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, "Check missing mimeType");
 }
예제 #2
0
 private String checkPatientIDs(
     ProvideAndRegisterDocumentSetRequestType req,
     RegistryPackageType submissionSet,
     List<ExtrinsicObjectType> extrObjs)
     throws XDSException {
   String submissionPatId =
       InfosetUtil.getExternalIdentifierValue(
           XDSConstants.UUID_XDSSubmissionSet_patientId, submissionSet);
   String docPatId;
   ExtrinsicObjectType eo;
   for (int i = 0, len = extrObjs.size(); i < len; i++) {
     eo = extrObjs.get(i);
     docPatId =
         InfosetUtil.getExternalIdentifierValue(XDSConstants.UUID_XDSDocumentEntry_patientId, eo);
     if (docPatId != null && !docPatId.equals(submissionPatId)) {
       String msg =
           "XDSDocumentEntry.patientId ("
               + docPatId
               + ")and XDSSubmissionSet.patientId ("
               + submissionPatId
               + ") doesn't match! ExtrinsicObject.Id:"
               + eo.getId();
       log.warn(msg);
       throw new XDSException(XDSException.XDS_ERR_PATID_DOESNOT_MATCH, msg, null);
     }
   }
   RegistryPackageType folder =
       InfosetUtil.getRegistryPackage(req.getSubmitObjectsRequest(), XDSConstants.UUID_XDSFolder);
   String folderPatId =
       folder == null
           ? null
           : InfosetUtil.getExternalIdentifierValue(XDSConstants.UUID_XDSFolder_patientId, folder);
   if (folderPatId != null && !folderPatId.equals(submissionPatId)) {
     String msg =
         "XDSFolder.patientId ("
             + folderPatId
             + ")and XDSSubmissionSet.patientId ("
             + submissionPatId
             + ") doesn't match!";
     log.warn(msg);
     throw new XDSException(XDSException.XDS_ERR_PATID_DOESNOT_MATCH, msg, null);
   }
   return submissionPatId;
 }
예제 #3
0
 private XDSDocument[] storeDocuments(
     ProvideAndRegisterDocumentSetRequestType req,
     List<ExtrinsicObjectType> extrObjs,
     String groupID)
     throws XDSException {
   Map<String, Document> docs = InfosetUtil.getDocuments(req);
   Document doc;
   ExtrinsicObjectType eo;
   String docUID;
   XDSDocument[] storedDocs = new XDSDocument[extrObjs.size()];
   String[] mimetypes = cfg.isCheckMimetype() ? cfg.getAcceptedMimeTypes() : null;
   for (int i = 0, len = extrObjs.size(); i < len; i++) {
     eo = extrObjs.get(i);
     if (eo.getId() == null || eo.getId().trim().length() == 0)
       throw new XDSException(
           XDSException.XDS_ERR_REPOSITORY_METADATA_ERROR,
           "Missing XDSDocumentEntry.entryUUID!",
           null);
     doc = docs.get(eo.getId());
     docUID =
         InfosetUtil.getExternalIdentifierValue(XDSConstants.UUID_XDSDocumentEntry_uniqueId, eo);
     if (docUID == null)
       throw new XDSException(
           XDSException.XDS_ERR_REPOSITORY_METADATA_ERROR,
           "Missing XDSDocumentEntry.uniqueId!",
           null);
     if (mimetypes != null) {
       boolean unsupportedMimetype = true;
       for (int j = 0; j < mimetypes.length; j++) {
         if (mimetypes[j].equals(eo.getMimeType())) {
           unsupportedMimetype = false;
           break;
         }
       }
       if (unsupportedMimetype)
         throw new XDSException(
             XDSException.XDS_ERR_REPOSITORY_METADATA_ERROR,
             "Mimetype not supported:" + eo.getMimeType(),
             null);
     }
     try {
       storedDocs[i] = storage.storeDocument(groupID, docUID, doc.getValue(), eo.getMimeType());
       if (storedDocs[i].isCommitted()) {
         log.warn("Document already exists! docUid:" + docUID);
       }
       Map<String, SlotType1> slots =
           InfosetUtil.addOrOverwriteSlot(
               eo, XDSConstants.SLOT_NAME_REPOSITORY_UNIQUE_ID, getRepositoryUniqueId());
       String oldValue =
           InfosetUtil.addOrCheckedOverwriteSlot(
               eo,
               slots,
               XDSConstants.SLOT_NAME_SIZE,
               String.valueOf(storedDocs[i].getSize()),
               false);
       if (oldValue != null) {
         throw new XDSException(
             XDSException.XDS_ERR_REPOSITORY_METADATA_ERROR,
             "Slot 'size' already exists but has different value! old:"
                 + oldValue
                 + " new:"
                 + storedDocs[i].getSize(),
             null);
       }
       oldValue =
           InfosetUtil.addOrCheckedOverwriteSlot(
               eo, slots, XDSConstants.SLOT_NAME_HASH, storedDocs[i].getDigest(), true);
       if (oldValue != null) {
         throw new XDSException(
             XDSException.XDS_ERR_REPOSITORY_METADATA_ERROR,
             "Slot 'hash' already exists but has different value! old:"
                 + oldValue
                 + " new:"
                 + storedDocs[i].getDigest(),
             null);
       }
     } catch (XDSException x) {
       this.commit(storedDocs, false);
       throw x;
     } catch (Exception x) {
       log.error("Storage of document failed! docUID:" + docUID, x);
       this.commit(storedDocs, false);
       throw new XDSException(
           XDSException.XDS_ERR_REPOSITORY_ERROR,
           "Storage of document " + docUID + " failed! : " + x.getMessage(),
           x);
     }
   }
   return storedDocs;
 }