Search in sources :

Example 36 with RegistryPackageType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.

the class FederationAdmin method updateDateFields.

private void updateDateFields(RegistryPackageType rpt) {
    ExtrinsicObjectType nodeInfo = null;
    for (JAXBElement identifiable : rpt.getRegistryObjectList().getIdentifiable()) {
        RegistryObjectType registryObject = (RegistryObjectType) identifiable.getValue();
        if (registryObject instanceof ExtrinsicObjectType && RegistryConstants.REGISTRY_NODE_OBJECT_TYPE.equals(registryObject.getObjectType())) {
            nodeInfo = (ExtrinsicObjectType) registryObject;
            break;
        }
    }
    if (nodeInfo != null) {
        boolean liveDateFound = false;
        boolean lastUpdatedFound = false;
        OffsetDateTime now = OffsetDateTime.now(ZoneId.of(ZoneOffset.UTC.toString()));
        String rightNow = now.toString();
        for (SlotType1 slot : nodeInfo.getSlot()) {
            if (slot.getName().equals(RegistryConstants.XML_LIVE_DATE_NAME)) {
                liveDateFound = true;
            } else if (slot.getName().equals(RegistryConstants.XML_LAST_UPDATED_NAME)) {
                ValueListType valueList = EbrimConstants.RIM_FACTORY.createValueListType();
                valueList.getValue().add(rightNow);
                slot.setValueList(EbrimConstants.RIM_FACTORY.createValueList(valueList));
                lastUpdatedFound = true;
            }
        }
        if (!liveDateFound) {
            SlotType1 liveDate = slotHelper.create(RegistryConstants.XML_LIVE_DATE_NAME, rightNow, DATE_TIME);
            nodeInfo.getSlot().add(liveDate);
        }
        if (!lastUpdatedFound) {
            SlotType1 lastUpdated = slotHelper.create(RegistryConstants.XML_LAST_UPDATED_NAME, rightNow, DATE_TIME);
            nodeInfo.getSlot().add(lastUpdated);
        }
    }
}
Also used : SlotType1(oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1) OffsetDateTime(java.time.OffsetDateTime) ValueListType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType) ExtrinsicObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType) JAXBElement(javax.xml.bind.JAXBElement) RegistryObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType)

Example 37 with RegistryPackageType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.

the class FederationAdmin method getWebMapsFromRegistryPackages.

private List<Map<String, Object>> getWebMapsFromRegistryPackages(List<RegistryPackageType> packages, Map<String, Metacard> metacardByRegistryIdMap) {
    List<Map<String, Object>> registryMaps = new ArrayList<>();
    for (RegistryPackageType registryPackage : packages) {
        Map<String, Object> registryWebMap = registryMapConverter.convert(registryPackage);
        Metacard metacard = metacardByRegistryIdMap.get(registryPackage.getId());
        Map<String, Object> transientValues = getTransientValuesMap(metacard);
        if (MapUtils.isNotEmpty(transientValues)) {
            registryWebMap.put(TRANSIENT_VALUES_KEY, transientValues);
        }
        if (MapUtils.isNotEmpty(registryWebMap)) {
            registryMaps.add(registryWebMap);
        }
    }
    return registryMaps;
}
Also used : Metacard(ddf.catalog.data.Metacard) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 38 with RegistryPackageType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.

the class FederationAdmin method updateLocalEntry.

@Override
public void updateLocalEntry(Map<String, Object> registryObjectMap) throws FederationAdminException {
    Optional<RegistryPackageType> registryPackageOptional = registryTypeConverter.convert(registryObjectMap);
    RegistryPackageType registryPackage = registryPackageOptional.orElseThrow(() -> new FederationAdminException("Error updating local registry entry. Couldn't convert registry map to a registry package."));
    updateDateFields(registryPackage);
    List<Metacard> existingMetacards = federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryPackage.getId()));
    if (CollectionUtils.isEmpty(existingMetacards)) {
        String message = "Error updating local registry entry. Registry metacard not found.";
        LOGGER.debug("{} Registry ID: {}", message, registryPackage.getId());
        throw new FederationAdminException(message);
    }
    if (existingMetacards.size() > 1) {
        throw new FederationAdminException("Error updating local registry entry. Multiple registry metacards found.");
    }
    Metacard existingMetacard = existingMetacards.get(0);
    Metacard updateMetacard = getRegistryMetacardFromRegistryPackage(registryPackage);
    updateMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacard.getId()));
    federationAdminService.updateRegistryEntry(updateMetacard);
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 39 with RegistryPackageType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.

the class FederationAdminTest method testUpdateLocalEntry.

@Test
public void testUpdateLocalEntry() throws Exception {
    RegistryPackageType registryObject = getRegistryObjectFromResource("/csw-registry-package-smaller.xml");
    Map<String, Object> registryMap = getMapFromRegistryObject(registryObject);
    String existingMetacardId = "someUpdateMetacardId";
    Metacard existingMetacard = getTestMetacard();
    existingMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacardId));
    List<Metacard> existingMetacards = new ArrayList<>();
    existingMetacards.add(existingMetacard);
    Metacard updateMetacard = getTestMetacard();
    when(federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()))).thenReturn(existingMetacards);
    when(registryTransformer.transform(any(InputStream.class))).thenReturn(updateMetacard);
    federationAdmin.updateLocalEntry(registryMap);
    verify(federationAdminService).getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()));
    verify(registryTransformer).transform(any(InputStream.class));
    verify(federationAdminService).updateRegistryEntry(updateMetacard);
}
Also used : Metacard(ddf.catalog.data.Metacard) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 40 with RegistryPackageType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.

the class FederationAdminTest method testUpdateLocalEntryWithFederationAdminServiceException.

@Test(expected = FederationAdminException.class)
public void testUpdateLocalEntryWithFederationAdminServiceException() throws Exception {
    RegistryPackageType registryObject = getRegistryObjectFromResource("/csw-full-registry-package.xml");
    Map<String, Object> registryMap = getMapFromRegistryObject(registryObject);
    String existingMetacardId = "someUpdateMetacardId";
    Metacard existingMetacard = getTestMetacard();
    existingMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacardId));
    List<Metacard> existingMetacards = new ArrayList<>();
    existingMetacards.add(existingMetacard);
    Metacard updateMetacard = getTestMetacard();
    when(federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()))).thenReturn(existingMetacards);
    when(registryTransformer.transform(any(InputStream.class))).thenReturn(updateMetacard);
    doThrow(FederationAdminException.class).when(federationAdminService).updateRegistryEntry(updateMetacard);
    federationAdmin.updateLocalEntry(registryMap);
    verify(federationAdminService).getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryObject.getId()));
    verify(registryTransformer).transform(any(InputStream.class));
    verify(federationAdminService).updateRegistryEntry(updateMetacard);
}
Also used : Metacard(ddf.catalog.data.Metacard) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

RegistryPackageType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType)46 Test (org.junit.Test)26 Metacard (ddf.catalog.data.Metacard)16 InputStream (java.io.InputStream)12 RegistryObjectListType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectListType)11 ArrayList (java.util.ArrayList)9 JAXBElement (javax.xml.bind.JAXBElement)9 ExtrinsicObjectType (oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType)9 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)7 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 Map (java.util.Map)4 AssociationType1 (oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1)4 OrganizationType (oasis.names.tc.ebxml_regrep.xsd.rim._3.OrganizationType)4 PersonType (oasis.names.tc.ebxml_regrep.xsd.rim._3.PersonType)4 RegistryObjectType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType)4 ParserConfigurator (org.codice.ddf.parser.ParserConfigurator)4 FederationAdminException (org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException)4 QueryRequest (ddf.catalog.operation.QueryRequest)3 QueryResponse (ddf.catalog.operation.QueryResponse)3