Search in sources :

Example 1 with InjectableAttribute

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

the class EndpointUtil method getMetacardTypeMap.

@SuppressWarnings("unchecked")
public Map<String, Object> getMetacardTypeMap() {
    Map<String, Object> resultTypes = new HashMap<>();
    for (MetacardType metacardType : metacardTypes) {
        Map<String, Object> attributes = new HashMap<>();
        for (AttributeDescriptor descriptor : metacardType.getAttributeDescriptors()) {
            Map<String, Object> attributeProperties = new HashMap<>();
            attributeProperties.put("type", descriptor.getType().getAttributeFormat().name());
            attributeProperties.put("multivalued", descriptor.isMultiValued());
            attributeProperties.put("id", descriptor.getName());
            attributes.put(descriptor.getName(), attributeProperties);
        }
        resultTypes.put(metacardType.getName(), attributes);
    }
    for (InjectableAttribute attribute : injectableAttributes) {
        Optional<AttributeDescriptor> lookup = attributeRegistry.lookup(attribute.attribute());
        if (!lookup.isPresent()) {
            continue;
        }
        AttributeDescriptor descriptor = lookup.get();
        Map<String, Object> attributeProperties = new HashMap<>();
        attributeProperties.put("type", descriptor.getType().getAttributeFormat().name());
        attributeProperties.put("multivalued", descriptor.isMultiValued());
        attributeProperties.put("id", descriptor.getName());
        Set<String> types = attribute.metacardTypes().isEmpty() ? resultTypes.keySet() : attribute.metacardTypes();
        for (String type : types) {
            Map<String, Object> attributes = (Map) resultTypes.getOrDefault(type, new HashMap<String, Object>());
            attributes.put(attribute.attribute(), attributeProperties);
            resultTypes.put(type, attributes);
        }
    }
    return resultTypes;
}
Also used : HashMap(java.util.HashMap) InjectableAttribute(ddf.catalog.data.InjectableAttribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) MetacardType(ddf.catalog.data.MetacardType)

Example 2 with InjectableAttribute

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

the class ValidationParser method parseInjections.

private List<Callable<Boolean>> parseInjections(Changeset changeset, List<Outer.Injection> injections) {
    BundleContext context = getBundleContext();
    return injections.stream().map(injection -> (Callable<Boolean>) () -> {
        String attribute = injection.attribute;
        InjectableAttribute injectableAttribute = new InjectableAttributeImpl(attribute, injection.metacardTypes);
        ServiceRegistration<InjectableAttribute> injectableAttributeService = context.registerService(InjectableAttribute.class, injectableAttribute, null);
        changeset.injectableAttributeServices.add(injectableAttributeService);
        return true;
    }).collect(toList());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Date(java.util.Date) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) BigDecimal(java.math.BigDecimal) ISO3CountryCodeValidator(ddf.catalog.validation.impl.validator.ISO3CountryCodeValidator) Map(java.util.Map) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) Bundle(org.osgi.framework.Bundle) JsonIgnore(org.boon.json.annotations.JsonIgnore) Collectors.toSet(java.util.stream.Collectors.toSet) ArtifactInstaller(org.apache.felix.fileinstall.ArtifactInstaller) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) Serializable(java.io.Serializable) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) InjectableAttribute(ddf.catalog.data.InjectableAttribute) List(java.util.List) Optional(java.util.Optional) BasicTypes(ddf.catalog.data.impl.BasicTypes) Dictionary(java.util.Dictionary) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) EnumerationValidator(ddf.catalog.validation.impl.validator.EnumerationValidator) SizeValidator(ddf.catalog.validation.impl.validator.SizeValidator) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) AttributeValidatorRegistry(ddf.catalog.validation.AttributeValidatorRegistry) AttributeRegistry(ddf.catalog.data.AttributeRegistry) DefaultAttributeValueRegistry(ddf.catalog.data.DefaultAttributeValueRegistry) InjectableAttributeImpl(ddf.catalog.data.impl.InjectableAttributeImpl) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CollectionUtils(org.apache.commons.collections.CollectionUtils) PatternValidator(ddf.catalog.validation.impl.validator.PatternValidator) FutureDateValidator(ddf.catalog.validation.impl.validator.FutureDateValidator) Hashtable(java.util.Hashtable) Nullable(javax.annotation.Nullable) ServiceRegistration(org.osgi.framework.ServiceRegistration) PastDateValidator(ddf.catalog.validation.impl.validator.PastDateValidator) Logger(org.slf4j.Logger) MetacardValidator(ddf.catalog.validation.MetacardValidator) JsonFactory(org.boon.json.JsonFactory) FileInputStream(java.io.FileInputStream) File(java.io.File) AttributeValidator(ddf.catalog.validation.AttributeValidator) Collectors.toList(java.util.stream.Collectors.toList) RequiredAttributesMetacardValidator(ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator) DateTimeFormatter(java.time.format.DateTimeFormatter) RangeValidator(ddf.catalog.validation.impl.validator.RangeValidator) FrameworkUtil(org.osgi.framework.FrameworkUtil) InputStream(java.io.InputStream) InjectableAttribute(ddf.catalog.data.InjectableAttribute) InjectableAttributeImpl(ddf.catalog.data.impl.InjectableAttributeImpl) Callable(java.util.concurrent.Callable) BundleContext(org.osgi.framework.BundleContext)

Example 3 with InjectableAttribute

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

the class InjectableAttributeImplTest method testSpecificMetacardTypes.

@Test
public void testSpecificMetacardTypes() {
    final String attribute = "attribute";
    final Set<String> metacardTypes = Sets.newHashSet("type1", "type2", "type3");
    InjectableAttribute injectableAttribute = new InjectableAttributeImpl(attribute, metacardTypes);
    assertThat(injectableAttribute.attribute(), is(attribute));
    assertThat(injectableAttribute.metacardTypes(), is(metacardTypes));
}
Also used : InjectableAttribute(ddf.catalog.data.InjectableAttribute) Test(org.junit.Test)

Example 4 with InjectableAttribute

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

the class InjectableAttributeImplTest method testNullMetacardTypeCollection.

@Test
public void testNullMetacardTypeCollection() {
    final String attribute = "attribute";
    InjectableAttribute injectableAttribute = new InjectableAttributeImpl(attribute, null);
    assertThat(injectableAttribute.attribute(), is(attribute));
    assertThat(injectableAttribute.metacardTypes(), is(empty()));
}
Also used : InjectableAttribute(ddf.catalog.data.InjectableAttribute) Test(org.junit.Test)

Aggregations

InjectableAttribute (ddf.catalog.data.InjectableAttribute)4 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)2 MetacardType (ddf.catalog.data.MetacardType)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 Sets (com.google.common.collect.Sets)1 AttributeRegistry (ddf.catalog.data.AttributeRegistry)1 DefaultAttributeValueRegistry (ddf.catalog.data.DefaultAttributeValueRegistry)1 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)1 BasicTypes (ddf.catalog.data.impl.BasicTypes)1 InjectableAttributeImpl (ddf.catalog.data.impl.InjectableAttributeImpl)1 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)1 AttributeValidator (ddf.catalog.validation.AttributeValidator)1 AttributeValidatorRegistry (ddf.catalog.validation.AttributeValidatorRegistry)1 MetacardValidator (ddf.catalog.validation.MetacardValidator)1 EnumerationValidator (ddf.catalog.validation.impl.validator.EnumerationValidator)1 FutureDateValidator (ddf.catalog.validation.impl.validator.FutureDateValidator)1 ISO3CountryCodeValidator (ddf.catalog.validation.impl.validator.ISO3CountryCodeValidator)1 PastDateValidator (ddf.catalog.validation.impl.validator.PastDateValidator)1