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;
}
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);
}
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;
}
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;
}
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)));
}
Aggregations