Search in sources :

Example 21 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class Jpeg2000ThumbnailConverter method process.

@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
    for (Result result : input.getResults()) {
        Metacard metacard = result.getMetacard();
        byte[] thumbnailBytes = metacard.getThumbnail();
        if (thumbnailBytes == null) {
            continue;
        }
        try (ByteArrayInputStream original = new ByteArrayInputStream(thumbnailBytes);
            ByteArrayOutputStream converted = new ByteArrayOutputStream()) {
            IISRandomAccessIO in = new IISRandomAccessIO(ImageIO.createImageInputStream(original));
            if (in.length() == 0) {
                continue;
            }
            // extracted from jj2000.j2k.fileformat.reader.FileFormatReader
            if (in.readInt() != OTHER_JP2_SIGNATURE || in.readInt() != JP2_SIGNATURE_BOX || in.readInt() != OFFICIAL_JP2_SIGNATURE) {
                // Not a JP2 file
                in.seek(0);
                if (in.readShort() != START_OF_CODESTREAM_MARKER) {
                    //Standard syntax marker found
                    continue;
                }
            }
            // convert j2k thumbnail to jpeg thumbnail
            original.reset();
            BufferedImage thumbnail = ImageIO.read(original);
            if (thumbnail == null) {
                continue;
            }
            ImageIO.write(thumbnail, "jpeg", converted);
            metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, converted.toByteArray()));
        } catch (IOException e) {
            throw new PluginExecutionException(e);
        }
    }
    return input;
}
Also used : Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IISRandomAccessIO(com.github.jaiimageio.jpeg2000.impl.IISRandomAccessIO) BufferedImage(java.awt.image.BufferedImage) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) Result(ddf.catalog.data.Result)

Example 22 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class Jpeg2000ThumbnailConverterTest method testEmptyThumbnail.

@Test
public void testEmptyThumbnail() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, new byte[0]));
    List<Result> resultList = new ArrayList<>();
    resultList.add(new ResultImpl(metacard));
    QueryResponseImpl queryResponse = new QueryResponseImpl(null, resultList, 1);
    jpeg2000ThumbnailConverter.process(queryResponse);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 23 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class TestExpirationDatePlugin method createMockMetacardsWithExpirationDate.

private List<Metacard> createMockMetacardsWithExpirationDate(int number) {
    List<Metacard> mockMetacards = new ArrayList(number);
    for (int i = 0; i < number; i++) {
        Metacard mockMetacard = new MetacardImpl();
        Attribute id = new AttributeImpl(Metacard.ID, Integer.toString(i));
        mockMetacard.setAttribute(id);
        Attribute title = new AttributeImpl(Metacard.TITLE, Integer.toString(i));
        mockMetacard.setAttribute(title);
        Attribute createdDate = new AttributeImpl(Core.METACARD_CREATED, CREATED_DATE.toDate());
        mockMetacard.setAttribute(createdDate);
        Attribute expirationDate = new AttributeImpl(Metacard.EXPIRATION, ORIG_EXPIRATION_DATE.toDate());
        mockMetacard.setAttribute(expirationDate);
        mockMetacards.add(mockMetacard);
    }
    return mockMetacards;
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 24 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class MetacardValidityMarkerPlugin method validate.

private <T> T validate(T item, Function<T, Metacard> itemToMetacard, Map<String, Integer> counter) {
    Set<String> errors = new HashSet<>();
    Set<String> warnings = new HashSet<>();
    Set<String> errorValidators = new HashSet<>();
    Set<String> warningValidators = new HashSet<>();
    Metacard metacard = itemToMetacard.apply(item);
    Set<String> tags = metacard.getTags();
    tags.remove(VALID_TAG);
    tags.remove(INVALID_TAG);
    String valid = VALID_TAG;
    for (MetacardValidator validator : metacardValidators) {
        try {
            validator.validate(metacard);
        } catch (ValidationException e) {
            String validatorName = getValidatorName(validator);
            boolean validationErrorsExist = CollectionUtils.isNotEmpty(e.getErrors());
            boolean validationWarningsExist = CollectionUtils.isNotEmpty(e.getWarnings());
            valid = INVALID_TAG;
            if ((isValidatorEnforced(validatorName) && validationErrorsExist && enforceErrors) || isValidatorEnforced(validatorName) && validationWarningsExist && enforceWarnings) {
                INGEST_LOGGER.debug("The metacard with id={} is being removed from the operation because it failed the enforced validator [{}].", metacard.getId(), validatorName);
                return null;
            } else {
                getValidationProblems(validatorName, e, errors, warnings, errorValidators, warningValidators, counter);
            }
        }
    }
    tags.add(valid);
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, new ArrayList<String>(tags)));
    metacard.setAttribute(new AttributeImpl(Validation.VALIDATION_ERRORS, (List<Serializable>) new ArrayList<Serializable>(errors)));
    metacard.setAttribute(new AttributeImpl(Validation.VALIDATION_WARNINGS, (List<Serializable>) new ArrayList<Serializable>(warnings)));
    metacard.setAttribute(new AttributeImpl(Validation.FAILED_VALIDATORS_WARNINGS, (List<Serializable>) new ArrayList<Serializable>(warningValidators)));
    metacard.setAttribute(new AttributeImpl(Validation.FAILED_VALIDATORS_ERRORS, (List<Serializable>) new ArrayList<Serializable>(errorValidators)));
    return item;
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) ValidationException(ddf.catalog.validation.ValidationException) MetacardValidator(ddf.catalog.validation.MetacardValidator) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 25 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class MetacardValidityMarkerPluginTest method testMultipleValidationTagsValid.

@Test
public void testMultipleValidationTagsValid() throws StopProcessingException, PluginExecutionException {
    metacardValidators.add(getMockPassingValidator());
    CreateRequest request = getMockCreateRequest();
    Metacard m1 = request.getMetacards().get(0);
    Set<String> tags = m1.getTags();
    tags.add(INVALID_TAG);
    m1.setAttribute(new AttributeImpl(Metacard.TAGS, new ArrayList<String>(tags)));
    CreateRequest filteredRequest = plugin.process(request);
    assertThat(filteredRequest.getMetacards().get(0).getTags(), hasItem(VALID_TAG));
    assertThat(filteredRequest.getMetacards().get(0).getTags(), not(hasItem(INVALID_TAG)));
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

AttributeImpl (ddf.catalog.data.impl.AttributeImpl)181 Metacard (ddf.catalog.data.Metacard)109 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)49 Serializable (java.io.Serializable)30 Date (java.util.Date)30 Attribute (ddf.catalog.data.Attribute)29 List (java.util.List)23 HashMap (java.util.HashMap)20 IOException (java.io.IOException)18 InputStream (java.io.InputStream)17 Result (ddf.catalog.data.Result)15 HashSet (java.util.HashSet)15 PolicyResponse (ddf.catalog.plugin.PolicyResponse)14 ResultImpl (ddf.catalog.data.impl.ResultImpl)11 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)11 Set (java.util.Set)11 ContentItem (ddf.catalog.content.data.ContentItem)10 QueryResponse (ddf.catalog.operation.QueryResponse)10