Search in sources :

Example 71 with MetacardType

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

the class TestGenericXmlLib method testNoFactoriesTransform.

@Test
public void testNoFactoriesTransform() {
    XmlInputTransformer xmlInputTransformer = new XmlInputTransformer();
    xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("test"));
    xmlInputTransformer.setSaxEventHandlerFactories(Collections.emptyList());
    SaxEventHandlerDelegate delegate = xmlInputTransformer.create();
    MetacardType metacardType = delegate.getMetacardType(xmlInputTransformer.getId());
    assertThat(metacardType.getAttributeDescriptors(), is(BasicTypes.BASIC_METACARD.getAttributeDescriptors()));
}
Also used : MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 72 with MetacardType

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

the class ConfluenceSourceTest method setup.

@Before
public void setup() {
    MetacardType type = new MetacardTypeImpl("confluence", (List) null);
    transformer = new ConfluenceInputTransformer(type);
    encryptionService = mock(EncryptionService.class);
    reader = mock(ResourceReader.class);
    factory = mock(SecureCxfClientFactory.class);
    client = mock(SearchResource.class);
    clientResponse = mock(Response.class);
    when(factory.getClient()).thenReturn(client);
    doReturn(clientResponse).when(client).search(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean());
    when(encryptionService.decryptValue(anyString())).thenReturn("decryptedPass");
    confluence = new TestConfluenceSource(adapter, encryptionService, transformer, reader, factory);
    confluence.setAvailabilityPollInterval(1);
    confluence.setConfigurationPid("configPid");
    confluence.setEndpointUrl("https://confluence/rest/api/content");
    confluence.setExpandedSections(Collections.singletonList("expandedField"));
    confluence.setUsername("username");
    confluence.setPassword("password");
    confluence.setIncludeArchivedSpaces(false);
    List<String> additionalAttributes = new ArrayList<>();
    additionalAttributes.add("attrib1=val1");
    additionalAttributes.add("attrib2=val1,val2,val3");
    confluence.setAdditionalAttributes(additionalAttributes);
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) SourceResponse(ddf.catalog.operation.SourceResponse) Response(javax.ws.rs.core.Response) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) EncryptionService(ddf.security.encryption.EncryptionService) ArrayList(java.util.ArrayList) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Matchers.anyString(org.mockito.Matchers.anyString) SearchResource(org.codice.ddf.confluence.api.SearchResource) MetacardType(ddf.catalog.data.MetacardType) Before(org.junit.Before)

Example 73 with MetacardType

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

the class InspectCommand method executeWithSubject.

@Override
protected Object executeWithSubject() throws Exception {
    if (id == null) {
        return null;
    }
    Filter filter = filterBuilder.attribute(Metacard.ID).is().equalTo().text(id);
    QueryImpl query = new QueryImpl(filter);
    SourceResponse response = getCatalog().query(new QueryRequestImpl(query));
    String formatString = "%1$s%2$-30s%3$s: %4$-25s %n";
    String newLineFormatString = "%1$s%2$-30s%3$s  %4$-25s %n";
    if (response.getResults() != null && response.getResults().size() > 0) {
        Metacard card = response.getResults().get(0).getMetacard();
        MetacardType mType = card.getMetacardType();
        String rClass = card.getClass().getName();
        String siteShortName = card.getSourceId();
        console.println("------------------------------");
        console.printf(formatString, color(rClass), "Class", color(rClass), rClass);
        console.printf(formatString, color(siteShortName), "Sitename", color(siteShortName), siteShortName);
        for (AttributeDescriptor ad : mType.getAttributeDescriptors()) {
            Attribute attribute = card.getAttribute(ad.getName());
            Serializable value = null;
            if (attribute != null) {
                value = attribute.getValue();
            }
            // indent items with new lines in the value
            if (value != null && (value.toString().contains("\r\n") || value.toString().contains("\n"))) {
                String valueString = value.toString();
                String[] values = valueString.split("\r\n");
                if (values.length < 2) {
                    values = valueString.split("\n");
                }
                console.printf(formatString, color(attribute), ad.getName(), color(attribute), values[0]);
                for (int i = 1; i < values.length; i++) {
                    console.printf(newLineFormatString, color(""), "", color(""), values[i]);
                }
            } else {
                console.printf(formatString, color(attribute), ad.getName(), color(attribute), value);
            }
        }
        // make sure we put the console default color back.
        console.print(defaultColor());
        console.println("------------------------------");
    }
    return null;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) Attribute(ddf.catalog.data.Attribute) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType)

Example 74 with MetacardType

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

the class OperationsMetacardSupport method setDefaultValues.

/**
     * Updates any empty metacard attributes with those defined in the
     * {@link DefaultAttributeValueRegistry}.
     *
     * @param metacard the metacard to update with default attribute values
     */
void setDefaultValues(Metacard metacard) {
    MetacardType metacardType = metacard.getMetacardType();
    DefaultAttributeValueRegistry registry = frameworkProperties.getDefaultAttributeValueRegistry();
    metacardType.getAttributeDescriptors().stream().map(AttributeDescriptor::getName).filter(attributeName -> hasNoValue(metacard.getAttribute(attributeName))).forEach(attributeName -> {
        registry.getDefaultValue(metacardType.getName(), attributeName).ifPresent(defaultValue -> metacard.setAttribute(new AttributeImpl(attributeName, defaultValue)));
    });
}
Also used : DefaultProbDetector(org.apache.tika.detect.DefaultProbDetector) StringUtils(org.apache.commons.lang.StringUtils) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) LoggerFactory(org.slf4j.LoggerFactory) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) MediaType(org.apache.tika.mime.MediaType) DefaultAttributeValueRegistry(ddf.catalog.data.DefaultAttributeValueRegistry) StandardCopyOption(java.nio.file.StandardCopyOption) Metadata(org.apache.tika.metadata.Metadata) Charset(java.nio.charset.Charset) ContentItem(ddf.catalog.content.data.ContentItem) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) TikaInputStream(org.apache.tika.io.TikaInputStream) Path(java.nio.file.Path) Logger(org.slf4j.Logger) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Files(java.nio.file.Files) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Detector(org.apache.tika.detect.Detector) AttributeInjector(ddf.catalog.data.AttributeInjector) InputStreamReader(java.io.InputStreamReader) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) MimeTypeResolutionException(ddf.mime.MimeTypeResolutionException) MetacardType(ddf.catalog.data.MetacardType) List(java.util.List) Attribute(ddf.catalog.data.Attribute) InputValidation(org.codice.ddf.platform.util.InputValidation) BufferedReader(java.io.BufferedReader) FilenameUtils(org.apache.commons.io.FilenameUtils) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) DefaultAttributeValueRegistry(ddf.catalog.data.DefaultAttributeValueRegistry)

Example 75 with MetacardType

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

the class OverrideAttributesSupport method overrideMetacard.

public static Metacard overrideMetacard(Metacard currentMetacard, Metacard overrideMetacard, boolean ignoreType, boolean onlyFillNull) {
    MetacardType updatedMetacardType = currentMetacard.getMetacardType();
    if (!ignoreType && !BasicTypes.BASIC_METACARD.equals(overrideMetacard.getMetacardType())) {
        updatedMetacardType = overrideMetacard.getMetacardType();
    }
    Metacard updatedMetacard = new MetacardImpl(currentMetacard, updatedMetacardType);
    addAttributes(updatedMetacard, overrideMetacard, onlyFillNull);
    return updatedMetacard;
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

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