class 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;
    }

    public  ObjectGroupMapper();

}