Search in sources :

Example 6 with RegistryPackageType

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)));
}
Also used : RegistryPackageWebConverter(org.codice.ddf.registry.schemabindings.converter.web.RegistryPackageWebConverter) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) RegistryPackageTypeConverter(org.codice.ddf.registry.schemabindings.converter.type.RegistryPackageTypeConverter) Test(org.junit.Test)

Example 7 with RegistryPackageType

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;
}
Also used : ParserException(org.codice.ddf.parser.ParserException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) RegistryObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType)

Example 8 with RegistryPackageType

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;
}
Also used : RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) ServiceType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ServiceType) ExtrinsicObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType) PersonType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PersonType) OrganizationType(oasis.names.tc.ebxml_regrep.xsd.rim._3.OrganizationType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 9 with RegistryPackageType

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);
}
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 10 with RegistryPackageType

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"));
}
Also used : HashMap(java.util.HashMap) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) Collection(java.util.Collection) CatalogEndpoint(ddf.catalog.endpoint.CatalogEndpoint) Map(java.util.Map) HashMap(java.util.HashMap) ServiceReference(org.osgi.framework.ServiceReference) 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