Search in sources :

Example 91 with Attribute

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

the class TestGenericXmlLib method getNewHandler.

private SaxEventHandler getNewHandler() {
    Attribute attribute = new AttributeImpl(Metacard.TITLE, "foo");
    Attribute attribute2 = new AttributeImpl(Metacard.TITLE, "bar");
    SaxEventHandler handler = mock(SaxEventHandler.class);
    when(handler.getAttributes()).thenReturn(Arrays.asList(attribute, attribute2));
    return handler;
}
Also used : Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) SaxEventHandler(org.codice.ddf.transformer.xml.streaming.SaxEventHandler)

Example 92 with Attribute

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

the class RangeCommand method executeWithSubject.

@Override
protected Object executeWithSubject() throws Exception {
    String formatString = "%1$-7s %2$-33s %3$-26s %4$-" + MAX_LENGTH + "s%n";
    console.printf(formatString, "", "", "", "");
    printHeaderMessage(String.format(formatString, NUMBER, ID, attributeName, TITLE));
    Filter filter;
    Date wayInTheFuture = new DateTime().plusYears(5000).toDate();
    Date wayInThePast = new DateTime().minusYears(5000).toDate();
    Date endDate = wayInTheFuture;
    Date startDate = wayInThePast;
    SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
    if (WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
        filter = filterBuilder.attribute(attributeName).before().date(endDate);
    } else if (WILDCARD.equals(rangeBeginning) && !WILDCARD.equals(rangeEnd)) {
        try {
            endDate = formatter.parse(rangeEnd);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse second parameter [" + rangeEnd + "]");
        }
        filter = filterBuilder.attribute(attributeName).before().date(endDate);
    } else if (!WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
        try {
            startDate = formatter.parse(rangeBeginning);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse first parameter [" + rangeBeginning + "]");
        }
        filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
    } else {
        try {
            startDate = formatter.parse(rangeBeginning);
            endDate = formatter.parse(rangeEnd);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse date parameters.");
        }
        filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
    }
    QueryImpl query = new QueryImpl(filter);
    query.setPageSize(MAX_RESULTS);
    query.setSortBy(new SortByImpl(attributeName, SortOrder.DESCENDING.name()));
    QueryRequest queryRequest = new QueryRequestImpl(query);
    SourceResponse response = getCatalog().query(queryRequest);
    List<Result> results = response.getResults();
    int i = 1;
    for (Result result : results) {
        Attribute attribute = result.getMetacard().getAttribute(attributeName);
        if (attribute != null && attribute.getValue() != null) {
            String returnedDate = new DateTime(attribute.getValue()).toString(DATETIME_FORMATTER);
            String title = result.getMetacard().getTitle();
            console.printf(formatString, i, result.getMetacard().getId(), returnedDate, title.substring(0, Math.min(title.length(), MAX_LENGTH)));
        }
        i++;
    }
    return null;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Attribute(ddf.catalog.data.Attribute) Date(java.util.Date) DateTime(org.joda.time.DateTime) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 93 with Attribute

use of ddf.catalog.data.Attribute 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 94 with Attribute

use of ddf.catalog.data.Attribute 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 95 with Attribute

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

the class PointOfContactPolicyPlugin method pointOfContactChanged.

private boolean pointOfContactChanged(Metacard newMetacard, Metacard previousMetacard) {
    Attribute newPointOfContact = newMetacard.getAttribute(Metacard.POINT_OF_CONTACT);
    Attribute oldPointOfContact = previousMetacard.getAttribute(Metacard.POINT_OF_CONTACT);
    if (newPointOfContact != null && oldPointOfContact != null) {
        return !newPointOfContact.getValue().equals(oldPointOfContact.getValue());
    }
    //Return true if only one of them is null
    return newPointOfContact != oldPointOfContact;
}
Also used : Attribute(ddf.catalog.data.Attribute)

Aggregations

Attribute (ddf.catalog.data.Attribute)103 Metacard (ddf.catalog.data.Metacard)39 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)30 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)29 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)26 Serializable (java.io.Serializable)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 HashMap (java.util.HashMap)15 Result (ddf.catalog.data.Result)14 List (java.util.List)14 MetacardType (ddf.catalog.data.MetacardType)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 Date (java.util.Date)11 Map (java.util.Map)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)8 Set (java.util.Set)8 Filter (org.opengis.filter.Filter)8 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)7