@Test public void givenCompareVersionList() throws Exception { final XMLInputFactory factory = XMLInputFactoryUtils.newInstance(); XMLEventReader evenReader = factory.createXMLEventReader(new FileReader("src/test/resources/sip.xml")); Map<String, Map<String, String>> versionMap = utils.compareVersionList(evenReader); Map<String, String> invalidVersionMap = versionMap.get(SedaUtils.INVALID_DATAOBJECT_VERSION); Map<String, String> validVersionMap = versionMap.get(SedaUtils.VALID_DATAOBJECT_VERSION); assertEquals(0, invalidVersionMap.size()); assertEquals(5, validVersionMap.size()); evenReader = factory.createXMLEventReader(new FileReader("src/test/resources/sip-with-wrong-version.xml")); versionMap = utils.compareVersionList(evenReader); invalidVersionMap = versionMap.get(SedaUtils.INVALID_DATAOBJECT_VERSION); validVersionMap = versionMap.get(SedaUtils.VALID_DATAOBJECT_VERSION); assertEquals(3, invalidVersionMap.size()); assertEquals(2, validVersionMap.size()); assertTrue(invalidVersionMap.containsValue("PhysicalMaste")); assertTrue(invalidVersionMap.containsValue("Diffusion")); assertTrue(invalidVersionMap.containsValue("PhysicalMaster")); evenReader = factory.createXMLEventReader(new FileReader("src/test/resources/sip-incorrect-version-format.xml")); versionMap = utils.compareVersionList(evenReader); invalidVersionMap = versionMap.get(SedaUtils.INVALID_DATAOBJECT_VERSION); validVersionMap = versionMap.get(SedaUtils.VALID_DATAOBJECT_VERSION); assertEquals(2, invalidVersionMap.size()); assertEquals(3, validVersionMap.size()); assertTrue(invalidVersionMap.containsValue("PhysicalMaster_-1")); assertTrue(invalidVersionMap.containsValue("Dissemination_One")); evenReader = factory.createXMLEventReader(new FileReader("src/test/resources/sip_missing_required_value.xml")); versionMap = utils.compareVersionList(evenReader); invalidVersionMap = versionMap.get(SedaUtils.INVALID_DATAOBJECT_VERSION); validVersionMap = versionMap.get(SedaUtils.VALID_DATAOBJECT_VERSION); assertEquals(2, invalidVersionMap.size()); assertEquals(3, validVersionMap.size()); assertTrue(invalidVersionMap.containsKey("ID004_BinaryDataObject_IncorrectUri")); assertTrue(invalidVersionMap.containsKey("ID006_PhysicalDataObject_IncorrectPhysicalId")); }
public Map<String, Map<String, String>> compareVersionList(XMLEventReader eventReader) throws ProcessingException { SedaVersion sedaVersion; try { sedaVersion = SedaConfiguration.getSupportedVerion(); } catch (IOException e) { LOGGER.error(e); throw new ProcessingException(e); } final Map<String, List<DataObjectInfo>> manifestVersionListByType = manifestVersionList(eventReader); final Map<String, String> invalidVersionMap = new HashMap<>(); final Map<String, String> validVersionMap = new HashMap<>(); final Map<String, Map<String, String>> versionMap = new HashMap<String, Map<String, String>>(); for (Map.Entry<String, List<DataObjectInfo>> manifestVersionEntry : manifestVersionListByType.entrySet()) { List<String> fileVersions = sedaVersion.getVersionForType(manifestVersionEntry.getKey()); for (final DataObjectInfo doi : manifestVersionEntry.getValue()) { if (doi.getVersion() != null) { validVersionMap.put(doi.getId(), ""); final String versionParts[] = doi.getVersion().split("_"); String errorCode = manifestVersionEntry.getKey(); if (versionParts.length > 2 || !fileVersions.contains(versionParts[USAGE_POSITION])) { List<String> otherFileVersions = sedaVersion.getVersionForOtherType(manifestVersionEntry.getKey()); if (otherFileVersions.contains(versionParts[USAGE_POSITION])) { errorCode += CONTAINS_OTHER_TYPE; } else { errorCode += INCORRECT_VERSION_FORMAT; } invalidVersionMap.put(doi.getId() + "_" + errorCode, doi.getVersion()); validVersionMap.remove(doi.getId()); continue; } if (versionParts.length == 2) { try { int currentVersion = Integer.parseInt(versionParts[VERSION_POSITION]); if (currentVersion < 0) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } catch (NumberFormatException e) { LOGGER.warn("Wrong version ", e); invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } if (SedaConstants.TAG_BINARY_DATA_OBJECT.equals(doi.getType())) { if (Strings.isNullOrEmpty(doi.getUri())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_URI, SedaConstants.TAG_URI); validVersionMap.remove(doi.getId()); } } else if (Strings.isNullOrEmpty(doi.getPhysicalId())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_PHYSICAL_ID, SedaConstants.TAG_PHYSICAL_ID); validVersionMap.remove(doi.getId()); } } } } versionMap.put(INVALID_DATAOBJECT_VERSION, invalidVersionMap); versionMap.put(VALID_DATAOBJECT_VERSION, validVersionMap); return versionMap; }
SedaUtils { public Map<String, Map<String, String>> compareVersionList(XMLEventReader eventReader) throws ProcessingException { SedaVersion sedaVersion; try { sedaVersion = SedaConfiguration.getSupportedVerion(); } catch (IOException e) { LOGGER.error(e); throw new ProcessingException(e); } final Map<String, List<DataObjectInfo>> manifestVersionListByType = manifestVersionList(eventReader); final Map<String, String> invalidVersionMap = new HashMap<>(); final Map<String, String> validVersionMap = new HashMap<>(); final Map<String, Map<String, String>> versionMap = new HashMap<String, Map<String, String>>(); for (Map.Entry<String, List<DataObjectInfo>> manifestVersionEntry : manifestVersionListByType.entrySet()) { List<String> fileVersions = sedaVersion.getVersionForType(manifestVersionEntry.getKey()); for (final DataObjectInfo doi : manifestVersionEntry.getValue()) { if (doi.getVersion() != null) { validVersionMap.put(doi.getId(), ""); final String versionParts[] = doi.getVersion().split("_"); String errorCode = manifestVersionEntry.getKey(); if (versionParts.length > 2 || !fileVersions.contains(versionParts[USAGE_POSITION])) { List<String> otherFileVersions = sedaVersion.getVersionForOtherType(manifestVersionEntry.getKey()); if (otherFileVersions.contains(versionParts[USAGE_POSITION])) { errorCode += CONTAINS_OTHER_TYPE; } else { errorCode += INCORRECT_VERSION_FORMAT; } invalidVersionMap.put(doi.getId() + "_" + errorCode, doi.getVersion()); validVersionMap.remove(doi.getId()); continue; } if (versionParts.length == 2) { try { int currentVersion = Integer.parseInt(versionParts[VERSION_POSITION]); if (currentVersion < 0) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } catch (NumberFormatException e) { LOGGER.warn("Wrong version ", e); invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } if (SedaConstants.TAG_BINARY_DATA_OBJECT.equals(doi.getType())) { if (Strings.isNullOrEmpty(doi.getUri())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_URI, SedaConstants.TAG_URI); validVersionMap.remove(doi.getId()); } } else if (Strings.isNullOrEmpty(doi.getPhysicalId())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_PHYSICAL_ID, SedaConstants.TAG_PHYSICAL_ID); validVersionMap.remove(doi.getId()); } } } } versionMap.put(INVALID_DATAOBJECT_VERSION, invalidVersionMap); versionMap.put(VALID_DATAOBJECT_VERSION, validVersionMap); return versionMap; } }
SedaUtils { public Map<String, Map<String, String>> compareVersionList(XMLEventReader eventReader) throws ProcessingException { SedaVersion sedaVersion; try { sedaVersion = SedaConfiguration.getSupportedVerion(); } catch (IOException e) { LOGGER.error(e); throw new ProcessingException(e); } final Map<String, List<DataObjectInfo>> manifestVersionListByType = manifestVersionList(eventReader); final Map<String, String> invalidVersionMap = new HashMap<>(); final Map<String, String> validVersionMap = new HashMap<>(); final Map<String, Map<String, String>> versionMap = new HashMap<String, Map<String, String>>(); for (Map.Entry<String, List<DataObjectInfo>> manifestVersionEntry : manifestVersionListByType.entrySet()) { List<String> fileVersions = sedaVersion.getVersionForType(manifestVersionEntry.getKey()); for (final DataObjectInfo doi : manifestVersionEntry.getValue()) { if (doi.getVersion() != null) { validVersionMap.put(doi.getId(), ""); final String versionParts[] = doi.getVersion().split("_"); String errorCode = manifestVersionEntry.getKey(); if (versionParts.length > 2 || !fileVersions.contains(versionParts[USAGE_POSITION])) { List<String> otherFileVersions = sedaVersion.getVersionForOtherType(manifestVersionEntry.getKey()); if (otherFileVersions.contains(versionParts[USAGE_POSITION])) { errorCode += CONTAINS_OTHER_TYPE; } else { errorCode += INCORRECT_VERSION_FORMAT; } invalidVersionMap.put(doi.getId() + "_" + errorCode, doi.getVersion()); validVersionMap.remove(doi.getId()); continue; } if (versionParts.length == 2) { try { int currentVersion = Integer.parseInt(versionParts[VERSION_POSITION]); if (currentVersion < 0) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } catch (NumberFormatException e) { LOGGER.warn("Wrong version ", e); invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } if (SedaConstants.TAG_BINARY_DATA_OBJECT.equals(doi.getType())) { if (Strings.isNullOrEmpty(doi.getUri())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_URI, SedaConstants.TAG_URI); validVersionMap.remove(doi.getId()); } } else if (Strings.isNullOrEmpty(doi.getPhysicalId())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_PHYSICAL_ID, SedaConstants.TAG_PHYSICAL_ID); validVersionMap.remove(doi.getId()); } } } } versionMap.put(INVALID_DATAOBJECT_VERSION, invalidVersionMap); versionMap.put(VALID_DATAOBJECT_VERSION, validVersionMap); return versionMap; } protected  SedaUtils(HandlerIO handlerIO); }
SedaUtils { public Map<String, Map<String, String>> compareVersionList(XMLEventReader eventReader) throws ProcessingException { SedaVersion sedaVersion; try { sedaVersion = SedaConfiguration.getSupportedVerion(); } catch (IOException e) { LOGGER.error(e); throw new ProcessingException(e); } final Map<String, List<DataObjectInfo>> manifestVersionListByType = manifestVersionList(eventReader); final Map<String, String> invalidVersionMap = new HashMap<>(); final Map<String, String> validVersionMap = new HashMap<>(); final Map<String, Map<String, String>> versionMap = new HashMap<String, Map<String, String>>(); for (Map.Entry<String, List<DataObjectInfo>> manifestVersionEntry : manifestVersionListByType.entrySet()) { List<String> fileVersions = sedaVersion.getVersionForType(manifestVersionEntry.getKey()); for (final DataObjectInfo doi : manifestVersionEntry.getValue()) { if (doi.getVersion() != null) { validVersionMap.put(doi.getId(), ""); final String versionParts[] = doi.getVersion().split("_"); String errorCode = manifestVersionEntry.getKey(); if (versionParts.length > 2 || !fileVersions.contains(versionParts[USAGE_POSITION])) { List<String> otherFileVersions = sedaVersion.getVersionForOtherType(manifestVersionEntry.getKey()); if (otherFileVersions.contains(versionParts[USAGE_POSITION])) { errorCode += CONTAINS_OTHER_TYPE; } else { errorCode += INCORRECT_VERSION_FORMAT; } invalidVersionMap.put(doi.getId() + "_" + errorCode, doi.getVersion()); validVersionMap.remove(doi.getId()); continue; } if (versionParts.length == 2) { try { int currentVersion = Integer.parseInt(versionParts[VERSION_POSITION]); if (currentVersion < 0) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } catch (NumberFormatException e) { LOGGER.warn("Wrong version ", e); invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } if (SedaConstants.TAG_BINARY_DATA_OBJECT.equals(doi.getType())) { if (Strings.isNullOrEmpty(doi.getUri())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_URI, SedaConstants.TAG_URI); validVersionMap.remove(doi.getId()); } } else if (Strings.isNullOrEmpty(doi.getPhysicalId())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_PHYSICAL_ID, SedaConstants.TAG_PHYSICAL_ID); validVersionMap.remove(doi.getId()); } } } } versionMap.put(INVALID_DATAOBJECT_VERSION, invalidVersionMap); versionMap.put(VALID_DATAOBJECT_VERSION, validVersionMap); return versionMap; } 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, Map<String, String>> compareVersionList(XMLEventReader eventReader) throws ProcessingException { SedaVersion sedaVersion; try { sedaVersion = SedaConfiguration.getSupportedVerion(); } catch (IOException e) { LOGGER.error(e); throw new ProcessingException(e); } final Map<String, List<DataObjectInfo>> manifestVersionListByType = manifestVersionList(eventReader); final Map<String, String> invalidVersionMap = new HashMap<>(); final Map<String, String> validVersionMap = new HashMap<>(); final Map<String, Map<String, String>> versionMap = new HashMap<String, Map<String, String>>(); for (Map.Entry<String, List<DataObjectInfo>> manifestVersionEntry : manifestVersionListByType.entrySet()) { List<String> fileVersions = sedaVersion.getVersionForType(manifestVersionEntry.getKey()); for (final DataObjectInfo doi : manifestVersionEntry.getValue()) { if (doi.getVersion() != null) { validVersionMap.put(doi.getId(), ""); final String versionParts[] = doi.getVersion().split("_"); String errorCode = manifestVersionEntry.getKey(); if (versionParts.length > 2 || !fileVersions.contains(versionParts[USAGE_POSITION])) { List<String> otherFileVersions = sedaVersion.getVersionForOtherType(manifestVersionEntry.getKey()); if (otherFileVersions.contains(versionParts[USAGE_POSITION])) { errorCode += CONTAINS_OTHER_TYPE; } else { errorCode += INCORRECT_VERSION_FORMAT; } invalidVersionMap.put(doi.getId() + "_" + errorCode, doi.getVersion()); validVersionMap.remove(doi.getId()); continue; } if (versionParts.length == 2) { try { int currentVersion = Integer.parseInt(versionParts[VERSION_POSITION]); if (currentVersion < 0) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } catch (NumberFormatException e) { LOGGER.warn("Wrong version ", e); invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_VERSION_FORMAT, doi.getVersion()); validVersionMap.remove(doi.getId()); } } if (SedaConstants.TAG_BINARY_DATA_OBJECT.equals(doi.getType())) { if (Strings.isNullOrEmpty(doi.getUri())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_URI, SedaConstants.TAG_URI); validVersionMap.remove(doi.getId()); } } else if (Strings.isNullOrEmpty(doi.getPhysicalId())) { invalidVersionMap.put(doi.getId() + "_" + errorCode + "_" + INCORRECT_PHYSICAL_ID, SedaConstants.TAG_PHYSICAL_ID); validVersionMap.remove(doi.getId()); } } } } versionMap.put(INVALID_DATAOBJECT_VERSION, invalidVersionMap); versionMap.put(VALID_DATAOBJECT_VERSION, validVersionMap); return versionMap; } 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; }