@Test public void should_map_object_group_with_physical_and_binary() throws JsonProcessingException, FileNotFoundException, InvalidParseOperationException, InternalServerException, DatatypeConfigurationException, JAXBException { final JsonNode GOTMetadataResponse = JsonHandler.getFromFile( PropertiesUtils.getResourceFile(SIMPLE_OBJECT_GROUP_DBREQUEST_RESULT_WITH_METADATA)); ObjectMapper objectMapper = UnitMapper.buildObjectMapper(); ObjectGroupResponse objectGroupSource = objectMapper.treeToValue(GOTMetadataResponse, ObjectGroupResponse.class); ObjectGroupMapper objectGroupMapper = new ObjectGroupMapper(); final DataObjectPackageType dataObjectPackageType = objectGroupMapper.map(objectGroupSource); Marshaller marshaller = jaxbContext.createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(dataObjectPackageType, writer); final List<Object> dataObjectGroupList = dataObjectPackageType.getDataObjectGroupOrBinaryDataObjectOrPhysicalDataObject(); assertNotNull(dataObjectGroupList); assertEquals(dataObjectGroupList.size(), 1); assertTrue(dataObjectGroupList.get(0) instanceof DataObjectGroupType); final DataObjectGroupType dataObjectGroup = (DataObjectGroupType) dataObjectGroupList.get(0); assertNotNull(dataObjectGroup); assertEquals(dataObjectGroup.getId(), objectGroupSource.getId()); List<MinimalDataObjectType> binaryDataObjectOrPhysicalDataObject = dataObjectGroup.getBinaryDataObjectOrPhysicalDataObject(); assertNotNull(binaryDataObjectOrPhysicalDataObject); assertTrue(!binaryDataObjectOrPhysicalDataObject.isEmpty()); if (binaryDataObjectOrPhysicalDataObject.get(1) instanceof BinaryDataObjectType) { BinaryDataObjectType binaryDataObjectType = (BinaryDataObjectType) binaryDataObjectOrPhysicalDataObject.get(1); final QualifiersModel qualifiersModel = objectGroupSource.getQualifiers().get(1); final VersionsModel versionsModel = qualifiersModel.getVersions().get(0); final FileInfoModel fileInfoModel = versionsModel.getFileInfoModel(); final FileInfoType fileInfo = binaryDataObjectType.getFileInfo(); assertEquals(fileInfoModel.getFilename(), fileInfo.getFilename()); assertEquals(fileInfoModel.getCreatingApplicationName(), fileInfo.getCreatingApplicationName()); assertEquals(fileInfoModel.getCreatingOs(), fileInfo.getCreatingOs()); assertEquals(fileInfoModel.getCreatingOsVersion(), fileInfo.getCreatingOsVersion()); assertEquals(fileInfoModel.getCreatingApplicationVersion(), fileInfo.getCreatingApplicationVersion()); if (fileInfoModel.getLastModified() != null) { final XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance() .newXMLGregorianCalendar(fileInfoModel.getLastModified()); assertEquals(xmlGregorianCalendar, fileInfo.getDateCreatedByApplication()); assertEquals(xmlGregorianCalendar, fileInfo.getLastModified()); } final FormatIdentificationType formatIdentificationType = binaryDataObjectType.getFormatIdentification(); final FormatIdentificationModel formatIdentificationModel = versionsModel.getFormatIdentification(); assertEquals(formatIdentificationModel.getFormatId(), formatIdentificationType.getFormatId()); assertEquals(formatIdentificationModel.getFormatLitteral(), formatIdentificationType.getFormatLitteral()); assertEquals(formatIdentificationModel.getMimeType(), formatIdentificationType.getMimeType()); assertEquals(formatIdentificationModel.getEncoding(), formatIdentificationType.getEncoding()); assertEquals(new BigInteger(String.valueOf(versionsModel.getSize())), binaryDataObjectType.getSize()); assertEquals(versionsModel.getUri(), binaryDataObjectType.getUri()); assertEquals(versionsModel.getMessageDigest(), binaryDataObjectType.getMessageDigest().getValue()); assertEquals(versionsModel.getAlgorithm(), binaryDataObjectType.getMessageDigest().getAlgorithm()); final MinimalDataObjectType minimalDataObjectType = binaryDataObjectOrPhysicalDataObject.get(1); assertEquals(versionsModel.getId(), minimalDataObjectType.getId()); assertEquals(versionsModel.getDataObjectVersion(), minimalDataObjectType.getDataObjectVersion()); Map<String, Object> otherMetadataFromVersionModel = versionsModel.getOtherMetadata(); DescriptiveTechnicalMetadataType otherMetadadata = ((BinaryDataObjectType) minimalDataObjectType).getOtherMetadata(); assertNotNull(otherMetadadata); assertEquals(((List) otherMetadadata.getAny()).size(), otherMetadataFromVersionModel.size()); assertEquals(((List) otherMetadadata.getAny()).size(), 1); assertTrue(otherMetadadata.getAny() instanceof List); ElementNSImpl eleNsImplObject = ((ElementNSImpl) ((List<Object>)otherMetadadata.getAny()).get(0)); String optionalMDkey = otherMetadataFromVersionModel.keySet().iterator().next(); Object optionalMDValue = otherMetadataFromVersionModel.get(optionalMDkey); assertEquals(eleNsImplObject.getNodeName(), optionalMDkey); assertEquals(eleNsImplObject.getTextContent(), optionalMDValue); } if (binaryDataObjectOrPhysicalDataObject.get(0) instanceof PhysicalDataObjectType) { final QualifiersModel qualifiersModel = objectGroupSource.getQualifiers().get(0); final VersionsModel versionsModel = qualifiersModel.getVersions().get(0); final PhysicalDimensionsModel physicalDimensionsModel = versionsModel.getPhysicalDimensionsModel(); final PhysicalDataObjectType physicalDataObjectType = (PhysicalDataObjectType) binaryDataObjectOrPhysicalDataObject.get(0); final DimensionsType dimensionsType = physicalDataObjectType.getPhysicalDimensions(); check_equality_between_measurementModel_and_dimensionType(physicalDimensionsModel.getDepth(), dimensionsType.getDepth()); check_equality_between_measurementModel_and_dimensionType(physicalDimensionsModel.getDiameter(), dimensionsType.getDiameter()); check_equality_between_measurementModel_and_dimensionType(physicalDimensionsModel.getHeight(), dimensionsType.getHeight()); check_equality_between_measurementModel_and_dimensionType(physicalDimensionsModel.getLength(), dimensionsType.getLength()); assertEquals(physicalDimensionsModel.getNumberOfPage(), dimensionsType.getNumberOfPage()); assertEquals(physicalDimensionsModel.getShape(), dimensionsType.getShape()); check_equality_between_measurementModel_and_dimensionType(physicalDimensionsModel.getThickness(), dimensionsType.getThickness()); check_Equality_Beatween_MeasurementWeightType_And_DimensionType(physicalDimensionsModel.getWeight(), dimensionsType.getWeight()); check_equality_between_measurementModel_and_dimensionType(physicalDimensionsModel.getWidth(), dimensionsType.getWidth()); } }
public DataObjectPackageType map(ObjectGroupResponse objectGroupResponse) throws InternalServerException { final DataObjectPackageType dataObjectPackageType = new DataObjectPackageType(); if (!objectGroupResponse.getQualifiers().isEmpty()) { String objectGroupId = objectGroupResponse.getId(); DataObjectGroupType dataObjectGroup = new DataObjectGroupType(); dataObjectGroup.setId(objectGroupId); for (QualifiersModel qualifiersModel : objectGroupResponse.getQualifiers()) { final int lastIndexVersion = qualifiersModel.getVersions().size() - 1; final VersionsModel version = qualifiersModel.getVersions().get(lastIndexVersion); MinimalDataObjectType minimalDataObjectType; if (version != null && version.getPhysicalId() != null && !version.getPhysicalId().isEmpty()) { minimalDataObjectType = mapPhysicalDataObject(version); } else { minimalDataObjectType = mapBinaryDataObject(version); } dataObjectGroup.getBinaryDataObjectOrPhysicalDataObject() .add(minimalDataObjectType); } dataObjectPackageType.getDataObjectGroupOrBinaryDataObjectOrPhysicalDataObject() .add(dataObjectGroup); } return dataObjectPackageType; }
ObjectGroupMapper { public DataObjectPackageType map(ObjectGroupResponse objectGroupResponse) throws InternalServerException { final DataObjectPackageType dataObjectPackageType = new DataObjectPackageType(); if (!objectGroupResponse.getQualifiers().isEmpty()) { String objectGroupId = objectGroupResponse.getId(); DataObjectGroupType dataObjectGroup = new DataObjectGroupType(); dataObjectGroup.setId(objectGroupId); for (QualifiersModel qualifiersModel : objectGroupResponse.getQualifiers()) { final int lastIndexVersion = qualifiersModel.getVersions().size() - 1; final VersionsModel version = qualifiersModel.getVersions().get(lastIndexVersion); MinimalDataObjectType minimalDataObjectType; if (version != null && version.getPhysicalId() != null && !version.getPhysicalId().isEmpty()) { minimalDataObjectType = mapPhysicalDataObject(version); } else { minimalDataObjectType = mapBinaryDataObject(version); } dataObjectGroup.getBinaryDataObjectOrPhysicalDataObject() .add(minimalDataObjectType); } dataObjectPackageType.getDataObjectGroupOrBinaryDataObjectOrPhysicalDataObject() .add(dataObjectGroup); } return dataObjectPackageType; } }
ObjectGroupMapper { public DataObjectPackageType map(ObjectGroupResponse objectGroupResponse) throws InternalServerException { final DataObjectPackageType dataObjectPackageType = new DataObjectPackageType(); if (!objectGroupResponse.getQualifiers().isEmpty()) { String objectGroupId = objectGroupResponse.getId(); DataObjectGroupType dataObjectGroup = new DataObjectGroupType(); dataObjectGroup.setId(objectGroupId); for (QualifiersModel qualifiersModel : objectGroupResponse.getQualifiers()) { final int lastIndexVersion = qualifiersModel.getVersions().size() - 1; final VersionsModel version = qualifiersModel.getVersions().get(lastIndexVersion); MinimalDataObjectType minimalDataObjectType; if (version != null && version.getPhysicalId() != null && !version.getPhysicalId().isEmpty()) { minimalDataObjectType = mapPhysicalDataObject(version); } else { minimalDataObjectType = mapBinaryDataObject(version); } dataObjectGroup.getBinaryDataObjectOrPhysicalDataObject() .add(minimalDataObjectType); } dataObjectPackageType.getDataObjectGroupOrBinaryDataObjectOrPhysicalDataObject() .add(dataObjectGroup); } return dataObjectPackageType; } ObjectGroupMapper(); }
ObjectGroupMapper { public DataObjectPackageType map(ObjectGroupResponse objectGroupResponse) throws InternalServerException { final DataObjectPackageType dataObjectPackageType = new DataObjectPackageType(); if (!objectGroupResponse.getQualifiers().isEmpty()) { String objectGroupId = objectGroupResponse.getId(); DataObjectGroupType dataObjectGroup = new DataObjectGroupType(); dataObjectGroup.setId(objectGroupId); for (QualifiersModel qualifiersModel : objectGroupResponse.getQualifiers()) { final int lastIndexVersion = qualifiersModel.getVersions().size() - 1; final VersionsModel version = qualifiersModel.getVersions().get(lastIndexVersion); MinimalDataObjectType minimalDataObjectType; if (version != null && version.getPhysicalId() != null && !version.getPhysicalId().isEmpty()) { minimalDataObjectType = mapPhysicalDataObject(version); } else { minimalDataObjectType = mapBinaryDataObject(version); } dataObjectGroup.getBinaryDataObjectOrPhysicalDataObject() .add(minimalDataObjectType); } dataObjectPackageType.getDataObjectGroupOrBinaryDataObjectOrPhysicalDataObject() .add(dataObjectGroup); } return dataObjectPackageType; } ObjectGroupMapper(); DataObjectPackageType map(ObjectGroupResponse objectGroupResponse); }
ObjectGroupMapper { public DataObjectPackageType map(ObjectGroupResponse objectGroupResponse) throws InternalServerException { final DataObjectPackageType dataObjectPackageType = new DataObjectPackageType(); if (!objectGroupResponse.getQualifiers().isEmpty()) { String objectGroupId = objectGroupResponse.getId(); DataObjectGroupType dataObjectGroup = new DataObjectGroupType(); dataObjectGroup.setId(objectGroupId); for (QualifiersModel qualifiersModel : objectGroupResponse.getQualifiers()) { final int lastIndexVersion = qualifiersModel.getVersions().size() - 1; final VersionsModel version = qualifiersModel.getVersions().get(lastIndexVersion); MinimalDataObjectType minimalDataObjectType; if (version != null && version.getPhysicalId() != null && !version.getPhysicalId().isEmpty()) { minimalDataObjectType = mapPhysicalDataObject(version); } else { minimalDataObjectType = mapBinaryDataObject(version); } dataObjectGroup.getBinaryDataObjectOrPhysicalDataObject() .add(minimalDataObjectType); } dataObjectPackageType.getDataObjectGroupOrBinaryDataObjectOrPhysicalDataObject() .add(dataObjectGroup); } return dataObjectPackageType; } ObjectGroupMapper(); DataObjectPackageType map(ObjectGroupResponse objectGroupResponse);  }