use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.
the class RegistryPackageWebConverterTest method testRoundTrip.
@Test
public void testRoundTrip() throws Exception {
RegistryPackageWebConverter rpwConverter = new RegistryPackageWebConverter();
RegistryPackageType testRegistryPackage = getTestRegistryPackage();
Map<String, Object> testRegistryPackageMap = rpwConverter.convert(testRegistryPackage);
RegistryPackageTypeConverter rptConverter = new RegistryPackageTypeConverter();
Optional<RegistryPackageType> optionalRegistryPackage = rptConverter.convert(testRegistryPackageMap);
RegistryPackageType convertedTestRegistryPackage = optionalRegistryPackage.get();
assertThat(testRegistryPackage.getObjectType(), is(equalTo(convertedTestRegistryPackage.getObjectType())));
assertThat(testRegistryPackage.getId(), is(equalTo(convertedTestRegistryPackage.getId())));
assertThat(testRegistryPackage.getHome(), is(equalTo(convertedTestRegistryPackage.getHome())));
assertThat(testRegistryPackage.getExternalIdentifier(), is(equalTo(convertedTestRegistryPackage.getExternalIdentifier())));
assertThat((testRegistryPackage).getRegistryObjectList().getIdentifiable().size(), is(equalTo((convertedTestRegistryPackage).getRegistryObjectList().getIdentifiable().size())));
assertThat(testRegistryPackage, is(equalTo(convertedTestRegistryPackage)));
}
use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.
the class MetacardMarshaller method getRegistryPackageFromMetacard.
/**
* Converts the metacards metadata into a RegistryPackageType object
*
* @param mcard A metacard with ebrim metadata
* @return A RegistryPackageType object created from the ebrim metadata
* @throws ParserException
*/
public RegistryPackageType getRegistryPackageFromMetacard(Metacard mcard) throws ParserException {
JAXBElement<RegistryObjectType> registryObjectTypeJAXBElement;
String metadata = mcard.getMetadata();
try (InputStream inputStream = new ByteArrayInputStream(metadata.getBytes(StandardCharsets.UTF_8))) {
registryObjectTypeJAXBElement = parser.unmarshal(unmarshalConfigurator, JAXBElement.class, inputStream);
} catch (IOException e) {
throw new ParserException("Error parsing metacards xml as ebrim", e);
}
if (registryObjectTypeJAXBElement == null) {
throw new ParserException("Error parsing metacards xml as ebrim");
}
RegistryPackageType registryPackage = (RegistryPackageType) registryObjectTypeJAXBElement.getValue();
if (registryPackage == null) {
throw new ParserException("Error parsing metacards xml as ebrim. No value");
}
return registryPackage;
}
use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.
the class RegistryPackageConverter method getRegistryObjectMetacard.
public static Metacard getRegistryObjectMetacard(RegistryObjectType registryObject, MetacardType metacardType) throws RegistryConversionException {
MetacardImpl metacard = null;
if (registryObject == null) {
return metacard;
}
validateIdentifiable(registryObject);
metacard = new MetacardImpl(metacardType);
parseTopLevel(registryObject, metacard);
if (registryObject instanceof RegistryPackageType) {
parseRegistryPackage((RegistryPackageType) registryObject, metacard);
} else if (registryObject instanceof ExtrinsicObjectType) {
parseNodeExtrinsicObject(registryObject, metacard);
} else if (registryObject instanceof ServiceType) {
parseRegistryService((ServiceType) registryObject, metacard);
} else if (registryObject instanceof OrganizationType) {
parseRegistryOrganization((OrganizationType) registryObject, metacard);
} else if (registryObject instanceof PersonType) {
parseRegistryPerson((PersonType) registryObject, metacard);
} else {
LOGGER.debug("Unexpected object found: {}", registryObject);
}
return metacard;
}
use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.
the class FederationAdmin method createLocalEntry.
@Override
public String createLocalEntry(Map<String, Object> registryMap) throws FederationAdminException {
Optional<RegistryPackageType> registryPackageOptional = registryTypeConverter.convert(registryMap);
RegistryPackageType registryPackage = registryPackageOptional.orElseThrow(() -> new FederationAdminException("Error creating local registry entry. Couldn't convert registry map to a registry package."));
if (!registryPackage.isSetHome()) {
registryPackage.setHome(SystemBaseUrl.getBaseUrl());
}
if (!registryPackage.isSetObjectType()) {
registryPackage.setObjectType(RegistryConstants.REGISTRY_NODE_OBJECT_TYPE);
}
if (!registryPackage.isSetId()) {
String registryPackageId = RegistryConstants.GUID_PREFIX + UUID.randomUUID().toString().replaceAll("-", "");
registryPackage.setId(registryPackageId);
}
updateDateFields(registryPackage);
Metacard metacard = getRegistryMetacardFromRegistryPackage(registryPackage);
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE, true));
return federationAdminService.addRegistryEntry(metacard);
}
use of oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType in project ddf by codice.
the class FederationAdminTest method testBindEndpoint.
@Test
public void testBindEndpoint() throws Exception {
List<RegistryPackageType> regObjects = Collections.singletonList((RegistryPackageType) getRegistryObjectFromResource("/csw-full-registry-package.xml"));
when(federationAdminService.getRegistryObjects()).thenReturn(regObjects);
mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
when(federationAdminService.getRegistryMetacards()).thenReturn(Collections.singletonList(mcard));
ServiceReference reference = mock(ServiceReference.class);
CatalogEndpoint endpoint = mock(CatalogEndpoint.class);
Map<String, String> props = new HashMap<>();
props.put(CatalogEndpoint.ID_KEY, "myId");
when(endpoint.getEndpointProperties()).thenReturn(props);
when(context.getService(reference)).thenReturn(endpoint);
federationAdmin.bindEndpoint(reference);
Map<String, Object> autoValues = (Map<String, Object>) federationAdmin.getLocalNodes().get("autoPopulateValues");
assertThat(autoValues.size(), is(1));
Collection bindingValues = (Collection) autoValues.get("ServiceBinding");
assertThat(bindingValues.size(), is(1));
Map<String, String> bindings = (Map<String, String>) bindingValues.iterator().next();
assertThat(bindings.get(CatalogEndpoint.ID_KEY), equalTo("myId"));
}
Aggregations