@Test public void givenSedaHasMessageIdWhengetMessageIdThenReturnCorrect() throws Exception { when(workspaceClient.getObject(any(), eq("SIP/manifest.xml"))) .thenReturn(Response.status(Status.OK).entity(seda).build()); when(handlerIO.getInputStreamFromWorkspace(any())).thenReturn(seda); assertEquals(3, utils.getMandatoryValues(params).size()); }
public Map<String, Object> getMandatoryValues(WorkerParameters params) throws ProcessingException { ParametersChecker.checkNullOrEmptyParameters(params); Map<String, Object> madatoryValueMap = new HashMap<>(); XMLEventReader reader = null; InputStream xmlFile = null; try { try { xmlFile = handlerIO.getInputStreamFromWorkspace( IngestWorkflowConstants.SEDA_FOLDER + "/" + IngestWorkflowConstants.SEDA_FILE); } catch (ContentAddressableStorageNotFoundException | ContentAddressableStorageServerException | IOException e) { LOGGER.error(MANIFEST_NOT_FOUND); throw new ProcessingException(e); } final XMLInputFactory xmlInputFactory = XMLInputFactoryUtils.newInstance(); final QName messageObjectName = new QName(NAMESPACE_URI, SedaConstants.TAG_MESSAGE_IDENTIFIER); final QName originatingAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER); final QName submissionAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER); final QName contractName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVAL_AGREEMENT); final QName commentName = new QName(NAMESPACE_URI, SedaConstants.TAG_COMMENT); final QName profilName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVE_PROFILE); final QName acquisitionInformationName = new QName(NAMESPACE_URI, SedaConstants.TAG_ACQUISITIONINFORMATION); final QName legalStatusName = new QName(NAMESPACE_URI, SedaConstants.TAG_LEGALSTATUS); StringBuffer sedaComment = new StringBuffer(); reader = xmlInputFactory.createXMLEventReader(xmlFile); while (true) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { final StartElement element = event.asStartElement(); if (element.getName().equals(contractName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVAL_AGREEMENT, reader.getElementText()); } if (element.getName().equals(messageObjectName)) { madatoryValueMap.put(SedaConstants.TAG_MESSAGE_IDENTIFIER, reader.getElementText()); } if (element.getName().equals(profilName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVE_PROFILE, reader.getElementText()); } if (element.getName().equals(submissionAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(commentName)) { if (!"".equals(sedaComment.toString())) { sedaComment.append("_" + reader.getElementText()); } else { sedaComment.append(reader.getElementText()); } } if (element.getName().equals(originatingAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(acquisitionInformationName)) { madatoryValueMap.put(SedaConstants.TAG_ACQUISITIONINFORMATION, reader.getElementText()); } if (element.getName().equals(legalStatusName)) { madatoryValueMap.put(SedaConstants.TAG_LEGALSTATUS, reader.getElementText()); } } if (event.isEndDocument()) { break; } } if (sedaComment.length() > 0) { madatoryValueMap.put(SedaConstants.TAG_COMMENT, sedaComment.toString()); } } catch (final XMLStreamException e) { LOGGER.error(CANNOT_READ_SEDA, e); throw new ProcessingException(e); } finally { try { if (reader != null) { reader.close(); } } catch (final XMLStreamException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } StreamUtils.closeSilently(xmlFile); } return madatoryValueMap; }
SedaUtils { public Map<String, Object> getMandatoryValues(WorkerParameters params) throws ProcessingException { ParametersChecker.checkNullOrEmptyParameters(params); Map<String, Object> madatoryValueMap = new HashMap<>(); XMLEventReader reader = null; InputStream xmlFile = null; try { try { xmlFile = handlerIO.getInputStreamFromWorkspace( IngestWorkflowConstants.SEDA_FOLDER + "/" + IngestWorkflowConstants.SEDA_FILE); } catch (ContentAddressableStorageNotFoundException | ContentAddressableStorageServerException | IOException e) { LOGGER.error(MANIFEST_NOT_FOUND); throw new ProcessingException(e); } final XMLInputFactory xmlInputFactory = XMLInputFactoryUtils.newInstance(); final QName messageObjectName = new QName(NAMESPACE_URI, SedaConstants.TAG_MESSAGE_IDENTIFIER); final QName originatingAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER); final QName submissionAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER); final QName contractName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVAL_AGREEMENT); final QName commentName = new QName(NAMESPACE_URI, SedaConstants.TAG_COMMENT); final QName profilName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVE_PROFILE); final QName acquisitionInformationName = new QName(NAMESPACE_URI, SedaConstants.TAG_ACQUISITIONINFORMATION); final QName legalStatusName = new QName(NAMESPACE_URI, SedaConstants.TAG_LEGALSTATUS); StringBuffer sedaComment = new StringBuffer(); reader = xmlInputFactory.createXMLEventReader(xmlFile); while (true) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { final StartElement element = event.asStartElement(); if (element.getName().equals(contractName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVAL_AGREEMENT, reader.getElementText()); } if (element.getName().equals(messageObjectName)) { madatoryValueMap.put(SedaConstants.TAG_MESSAGE_IDENTIFIER, reader.getElementText()); } if (element.getName().equals(profilName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVE_PROFILE, reader.getElementText()); } if (element.getName().equals(submissionAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(commentName)) { if (!"".equals(sedaComment.toString())) { sedaComment.append("_" + reader.getElementText()); } else { sedaComment.append(reader.getElementText()); } } if (element.getName().equals(originatingAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(acquisitionInformationName)) { madatoryValueMap.put(SedaConstants.TAG_ACQUISITIONINFORMATION, reader.getElementText()); } if (element.getName().equals(legalStatusName)) { madatoryValueMap.put(SedaConstants.TAG_LEGALSTATUS, reader.getElementText()); } } if (event.isEndDocument()) { break; } } if (sedaComment.length() > 0) { madatoryValueMap.put(SedaConstants.TAG_COMMENT, sedaComment.toString()); } } catch (final XMLStreamException e) { LOGGER.error(CANNOT_READ_SEDA, e); throw new ProcessingException(e); } finally { try { if (reader != null) { reader.close(); } } catch (final XMLStreamException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } StreamUtils.closeSilently(xmlFile); } return madatoryValueMap; } }
SedaUtils { public Map<String, Object> getMandatoryValues(WorkerParameters params) throws ProcessingException { ParametersChecker.checkNullOrEmptyParameters(params); Map<String, Object> madatoryValueMap = new HashMap<>(); XMLEventReader reader = null; InputStream xmlFile = null; try { try { xmlFile = handlerIO.getInputStreamFromWorkspace( IngestWorkflowConstants.SEDA_FOLDER + "/" + IngestWorkflowConstants.SEDA_FILE); } catch (ContentAddressableStorageNotFoundException | ContentAddressableStorageServerException | IOException e) { LOGGER.error(MANIFEST_NOT_FOUND); throw new ProcessingException(e); } final XMLInputFactory xmlInputFactory = XMLInputFactoryUtils.newInstance(); final QName messageObjectName = new QName(NAMESPACE_URI, SedaConstants.TAG_MESSAGE_IDENTIFIER); final QName originatingAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER); final QName submissionAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER); final QName contractName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVAL_AGREEMENT); final QName commentName = new QName(NAMESPACE_URI, SedaConstants.TAG_COMMENT); final QName profilName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVE_PROFILE); final QName acquisitionInformationName = new QName(NAMESPACE_URI, SedaConstants.TAG_ACQUISITIONINFORMATION); final QName legalStatusName = new QName(NAMESPACE_URI, SedaConstants.TAG_LEGALSTATUS); StringBuffer sedaComment = new StringBuffer(); reader = xmlInputFactory.createXMLEventReader(xmlFile); while (true) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { final StartElement element = event.asStartElement(); if (element.getName().equals(contractName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVAL_AGREEMENT, reader.getElementText()); } if (element.getName().equals(messageObjectName)) { madatoryValueMap.put(SedaConstants.TAG_MESSAGE_IDENTIFIER, reader.getElementText()); } if (element.getName().equals(profilName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVE_PROFILE, reader.getElementText()); } if (element.getName().equals(submissionAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(commentName)) { if (!"".equals(sedaComment.toString())) { sedaComment.append("_" + reader.getElementText()); } else { sedaComment.append(reader.getElementText()); } } if (element.getName().equals(originatingAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(acquisitionInformationName)) { madatoryValueMap.put(SedaConstants.TAG_ACQUISITIONINFORMATION, reader.getElementText()); } if (element.getName().equals(legalStatusName)) { madatoryValueMap.put(SedaConstants.TAG_LEGALSTATUS, reader.getElementText()); } } if (event.isEndDocument()) { break; } } if (sedaComment.length() > 0) { madatoryValueMap.put(SedaConstants.TAG_COMMENT, sedaComment.toString()); } } catch (final XMLStreamException e) { LOGGER.error(CANNOT_READ_SEDA, e); throw new ProcessingException(e); } finally { try { if (reader != null) { reader.close(); } } catch (final XMLStreamException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } StreamUtils.closeSilently(xmlFile); } return madatoryValueMap; } protected  SedaUtils(HandlerIO handlerIO); }
SedaUtils { public Map<String, Object> getMandatoryValues(WorkerParameters params) throws ProcessingException { ParametersChecker.checkNullOrEmptyParameters(params); Map<String, Object> madatoryValueMap = new HashMap<>(); XMLEventReader reader = null; InputStream xmlFile = null; try { try { xmlFile = handlerIO.getInputStreamFromWorkspace( IngestWorkflowConstants.SEDA_FOLDER + "/" + IngestWorkflowConstants.SEDA_FILE); } catch (ContentAddressableStorageNotFoundException | ContentAddressableStorageServerException | IOException e) { LOGGER.error(MANIFEST_NOT_FOUND); throw new ProcessingException(e); } final XMLInputFactory xmlInputFactory = XMLInputFactoryUtils.newInstance(); final QName messageObjectName = new QName(NAMESPACE_URI, SedaConstants.TAG_MESSAGE_IDENTIFIER); final QName originatingAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER); final QName submissionAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER); final QName contractName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVAL_AGREEMENT); final QName commentName = new QName(NAMESPACE_URI, SedaConstants.TAG_COMMENT); final QName profilName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVE_PROFILE); final QName acquisitionInformationName = new QName(NAMESPACE_URI, SedaConstants.TAG_ACQUISITIONINFORMATION); final QName legalStatusName = new QName(NAMESPACE_URI, SedaConstants.TAG_LEGALSTATUS); StringBuffer sedaComment = new StringBuffer(); reader = xmlInputFactory.createXMLEventReader(xmlFile); while (true) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { final StartElement element = event.asStartElement(); if (element.getName().equals(contractName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVAL_AGREEMENT, reader.getElementText()); } if (element.getName().equals(messageObjectName)) { madatoryValueMap.put(SedaConstants.TAG_MESSAGE_IDENTIFIER, reader.getElementText()); } if (element.getName().equals(profilName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVE_PROFILE, reader.getElementText()); } if (element.getName().equals(submissionAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(commentName)) { if (!"".equals(sedaComment.toString())) { sedaComment.append("_" + reader.getElementText()); } else { sedaComment.append(reader.getElementText()); } } if (element.getName().equals(originatingAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(acquisitionInformationName)) { madatoryValueMap.put(SedaConstants.TAG_ACQUISITIONINFORMATION, reader.getElementText()); } if (element.getName().equals(legalStatusName)) { madatoryValueMap.put(SedaConstants.TAG_LEGALSTATUS, reader.getElementText()); } } if (event.isEndDocument()) { break; } } if (sedaComment.length() > 0) { madatoryValueMap.put(SedaConstants.TAG_COMMENT, sedaComment.toString()); } } catch (final XMLStreamException e) { LOGGER.error(CANNOT_READ_SEDA, e); throw new ProcessingException(e); } finally { try { if (reader != null) { reader.close(); } } catch (final XMLStreamException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } StreamUtils.closeSilently(xmlFile); } return madatoryValueMap; } protected  SedaUtils(HandlerIO handlerIO); Map<String, String> getBinaryDataObjectIdToGuid(); Map<String, List<String>> getObjectGroupIdToBinaryDataObjectId(); Map<String, String> getObjectGroupIdToGuid(); Map<String, String> getUnitIdToGuid(); Map<String, String> getBinaryDataObjectIdToGroupId(); Map<String, String> getUnitIdToGroupId(); Map<String, Object> getMandatoryValues(WorkerParameters params); CheckSedaValidationStatus checkSedaValidation(WorkerParameters params, ItemStatus itemStatus); ExtractUriResponse getAllDigitalObjectUriFromManifest(); Map<String, Map<String, String>> checkSupportedDataObjectVersion(WorkerParameters params); SedaUtilInfo getDataObjectInfo(XMLEventReader evenReader); Map<String, List<DataObjectInfo>> manifestVersionList(XMLEventReader evenReader); Map<String, Map<String, String>> compareVersionList(XMLEventReader eventReader); long computeTotalSizeOfObjectsInManifest(WorkerParameters params); }
SedaUtils { public Map<String, Object> getMandatoryValues(WorkerParameters params) throws ProcessingException { ParametersChecker.checkNullOrEmptyParameters(params); Map<String, Object> madatoryValueMap = new HashMap<>(); XMLEventReader reader = null; InputStream xmlFile = null; try { try { xmlFile = handlerIO.getInputStreamFromWorkspace( IngestWorkflowConstants.SEDA_FOLDER + "/" + IngestWorkflowConstants.SEDA_FILE); } catch (ContentAddressableStorageNotFoundException | ContentAddressableStorageServerException | IOException e) { LOGGER.error(MANIFEST_NOT_FOUND); throw new ProcessingException(e); } final XMLInputFactory xmlInputFactory = XMLInputFactoryUtils.newInstance(); final QName messageObjectName = new QName(NAMESPACE_URI, SedaConstants.TAG_MESSAGE_IDENTIFIER); final QName originatingAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER); final QName submissionAgencyName = new QName(NAMESPACE_URI, SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER); final QName contractName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVAL_AGREEMENT); final QName commentName = new QName(NAMESPACE_URI, SedaConstants.TAG_COMMENT); final QName profilName = new QName(NAMESPACE_URI, SedaConstants.TAG_ARCHIVE_PROFILE); final QName acquisitionInformationName = new QName(NAMESPACE_URI, SedaConstants.TAG_ACQUISITIONINFORMATION); final QName legalStatusName = new QName(NAMESPACE_URI, SedaConstants.TAG_LEGALSTATUS); StringBuffer sedaComment = new StringBuffer(); reader = xmlInputFactory.createXMLEventReader(xmlFile); while (true) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { final StartElement element = event.asStartElement(); if (element.getName().equals(contractName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVAL_AGREEMENT, reader.getElementText()); } if (element.getName().equals(messageObjectName)) { madatoryValueMap.put(SedaConstants.TAG_MESSAGE_IDENTIFIER, reader.getElementText()); } if (element.getName().equals(profilName)) { madatoryValueMap.put(SedaConstants.TAG_ARCHIVE_PROFILE, reader.getElementText()); } if (element.getName().equals(submissionAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_SUBMISSIONAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(commentName)) { if (!"".equals(sedaComment.toString())) { sedaComment.append("_" + reader.getElementText()); } else { sedaComment.append(reader.getElementText()); } } if (element.getName().equals(originatingAgencyName)) { madatoryValueMap.put(SedaConstants.TAG_ORIGINATINGAGENCYIDENTIFIER, reader.getElementText()); } if (element.getName().equals(acquisitionInformationName)) { madatoryValueMap.put(SedaConstants.TAG_ACQUISITIONINFORMATION, reader.getElementText()); } if (element.getName().equals(legalStatusName)) { madatoryValueMap.put(SedaConstants.TAG_LEGALSTATUS, reader.getElementText()); } } if (event.isEndDocument()) { break; } } if (sedaComment.length() > 0) { madatoryValueMap.put(SedaConstants.TAG_COMMENT, sedaComment.toString()); } } catch (final XMLStreamException e) { LOGGER.error(CANNOT_READ_SEDA, e); throw new ProcessingException(e); } finally { try { if (reader != null) { reader.close(); } } catch (final XMLStreamException e) { SysErrLogger.FAKE_LOGGER.ignoreLog(e); } StreamUtils.closeSilently(xmlFile); } return madatoryValueMap; } protected  SedaUtils(HandlerIO handlerIO); Map<String, String> getBinaryDataObjectIdToGuid(); Map<String, List<String>> getObjectGroupIdToBinaryDataObjectId(); Map<String, String> getObjectGroupIdToGuid(); Map<String, String> getUnitIdToGuid(); Map<String, String> getBinaryDataObjectIdToGroupId(); Map<String, String> getUnitIdToGroupId(); Map<String, Object> getMandatoryValues(WorkerParameters params); CheckSedaValidationStatus checkSedaValidation(WorkerParameters params, ItemStatus itemStatus); ExtractUriResponse getAllDigitalObjectUriFromManifest(); Map<String, Map<String, String>> checkSupportedDataObjectVersion(WorkerParameters params); SedaUtilInfo getDataObjectInfo(XMLEventReader evenReader); Map<String, List<DataObjectInfo>> manifestVersionList(XMLEventReader evenReader); Map<String, Map<String, String>> compareVersionList(XMLEventReader eventReader); long computeTotalSizeOfObjectsInManifest(WorkerParameters params); static final String NAMESPACE_URI; static final String XSI_URI; static final String NB_AU_EXISTING; static final String INVALID_DATAOBJECT_VERSION; static final String VALID_DATAOBJECT_VERSION; static final String SEDA_XSD_VERSION; }