Search in sources :

Example 46 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class WfsSource method registerFeatureMetacardTypes.

private void registerFeatureMetacardTypes(Map<String, MetacardTypeRegistration> mcTypeRegs) {
    // Unregister all MetacardType services - the DescribeFeatureTypeRequest should
    // have returned all of the most current metacard types that will now be registered.
    // As Source(s) are added/removed from this instance or to other Source(s)
    // that this instance is federated to, the list of metacard types will change.
    // This is done here vs. inside the above loop so that minimal time is spent clearing and
    // registering the MetacardTypes - the concern is that if this registration is too lengthy
    // a query could come in that is handled while the MetacardType registrations are
    // in a state of flux.
    unregisterAllMetacardTypes();
    if (!mcTypeRegs.isEmpty()) {
        for (MetacardTypeRegistration registration : mcTypeRegs.values()) {
            FeatureMetacardType ftMetacard = registration.getFtMetacard();
            String simpleName = ftMetacard.getFeatureType().getLocalPart();
            ServiceRegistration serviceRegistration = context.registerService(MetacardType.class.getName(), ftMetacard, registration.getProps());
            this.metacardTypeServiceRegistrations.put(simpleName, serviceRegistration);
        }
    }
}
Also used : FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 47 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class MetacardVersionImpl method toMetacard.

public static Metacard toMetacard(Metacard source, List<MetacardType> types) {
    String id = (String) source.getAttribute(MetacardVersion.VERSION_OF_ID).getValue();
    if (isNullOrEmpty(id)) {
        throw new IllegalStateException("Cannot convert history metacard without the original metacard id");
    }
    String typeString = (String) source.getAttribute(VERSION_TYPE).getValue();
    Optional<MetacardType> typeFromExisting = types.stream().filter(mt -> mt.getName().equals(typeString)).findFirst();
    MetacardImpl result = new MetacardImpl(source, typeFromExisting.orElseGet(() -> getMetacardTypeBinary(source).orElseThrow(cannotDeserializeException)));
    result.setId(id);
    result.setTags(getVersionTags(source));
    try {
        result.setResourceURI(new URI(String.valueOf(source.getAttribute(VERSIONED_RESOURCE_URI).getValue())));
    } catch (URISyntaxException e) {
        LOGGER.debug("Could not replace the versioned resource URI, It might not be valid", e);
    }
    sanitizeVersionAttributes(result);
    return result;
}
Also used : MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) Subject(org.apache.shiro.subject.Subject) Metacard(ddf.catalog.data.Metacard) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) ObjectOutputStream(java.io.ObjectOutputStream) URI(java.net.URI) SubjectUtils(ddf.security.SubjectUtils) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) List(java.util.List) Attribute(ddf.catalog.data.Attribute) Optional(java.util.Optional) Collections(java.util.Collections) BasicTypes(ddf.catalog.data.impl.BasicTypes) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 48 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class MetacardServicesTest method testApplyNewAttributesWithEmptyMap.

@Test
public void testApplyNewAttributesWithEmptyMap() throws Exception {
    Metacard metacard = createMetacard();
    List<Metacard> metacards = ImmutableList.of(metacard);
    Map<String, String> attributeMap = ImmutableMap.of();
    List<MetacardType> mockMetacardTypes = mock(List.class);
    metacardServices = new MetacardServices(mockMetacardTypes);
    AttributeFactory mockAttributeFactory = mock(AttributeFactory.class);
    List<Metacard> newMetacards = metacardServices.setAttributesIfAbsent(metacards, attributeMap, mockAttributeFactory);
    assertThat(newMetacards, hasSize(1));
    verifyZeroInteractions(mockMetacardTypes, mockAttributeFactory);
    assertThatMetacardHasExpectedTitleAndDescription(newMetacards.get(0));
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 49 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class ResourceUriPolicyTest method getMockMetacard.

private Metacard getMockMetacard(String inputResourceUri) throws URISyntaxException {
    MetacardType metacardType = mock(MetacardType.class);
    when(metacardType.getName()).thenReturn("ddf.metacard");
    Metacard inputMetacard = mock(Metacard.class);
    when(inputMetacard.getId()).thenReturn("id");
    when(inputMetacard.getResourceURI()).thenReturn(new URI(inputResourceUri));
    when(inputMetacard.getMetacardType()).thenReturn(metacardType);
    return inputMetacard;
}
Also used : Metacard(ddf.catalog.data.Metacard) URI(java.net.URI) MetacardType(ddf.catalog.data.MetacardType)

Example 50 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestMetacardValueResolver method testResolveType.

@Test
public void testResolveType() {
    MetacardImpl mc = new MetacardImpl();
    String expected = "feature";
    MetacardType expectedType = new MetacardTypeImpl(expected, (Set<AttributeDescriptor>) null);
    mc.setType(expectedType);
    MetacardValueResolver mvr = new MetacardValueResolver();
    Object props = mvr.resolve(mc, "properties");
    Object actual = mvr.resolve(props, "type");
    assertEquals(expected, actual);
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Aggregations

MetacardType (ddf.catalog.data.MetacardType)88 Test (org.junit.Test)57 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)41 Metacard (ddf.catalog.data.Metacard)35 ArrayList (java.util.ArrayList)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)17 HashSet (java.util.HashSet)15 Attribute (ddf.catalog.data.Attribute)12 Serializable (java.io.Serializable)10 IOException (java.io.IOException)8 Date (java.util.Date)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)7 InputStream (java.io.InputStream)7 Set (java.util.Set)7 ContentItem (ddf.catalog.content.data.ContentItem)6 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)6