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);
}
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations