use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class IngestCommand method readMetacard.
private Metacard readMetacard(File file) throws IngestException {
Metacard result = null;
FileInputStream fis = null;
ObjectInputStream ois = null;
try {
if (SERIALIZED_OBJECT_ID.matches(transformerId)) {
ois = new ObjectInputStream(new FileInputStream(file));
result = (Metacard) ois.readObject();
ois.close();
} else {
fis = new FileInputStream(file);
result = generateMetacard(fis);
if (StringUtils.isBlank(result.getTitle())) {
LOGGER.debug("Metacard title was blank. Setting title to filename.");
result.setAttribute(new AttributeImpl(Metacard.TITLE, file.getName()));
}
fis.close();
}
} catch (IOException | IllegalArgumentException | ClassNotFoundException e) {
throw new IngestException(e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e1) {
console.println(e1);
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e2) {
console.println(e2);
}
}
}
return result;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class ValidateCommand method createMetacardsFromFiles.
private List<Metacard> createMetacardsFromFiles() throws IOException {
Collection<File> files = getFiles();
List<Metacard> metacards = new ArrayList<>();
for (File file : files) {
Metacard metacard = new MetacardImpl();
String metadata = IOUtils.toString(file.toURI());
metacard.setAttribute(new AttributeImpl(Metacard.METADATA, metadata));
metacard.setAttribute(new AttributeImpl(Metacard.TITLE, file.getName()));
metacards.add(metacard);
}
return metacards;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class StandardMetacardGroomerPlugin method applyCreatedOperationRules.
protected void applyCreatedOperationRules(CreateRequest createRequest, Metacard aMetacard, Date now) {
LOGGER.debug("Applying standard rules on CreateRequest");
if ((aMetacard.getResourceURI() != null && !isCatalogResourceUri(aMetacard.getResourceURI())) || !uuidGenerator.validateUuid(aMetacard.getId())) {
aMetacard.setAttribute(new AttributeImpl(Metacard.ID, uuidGenerator.generateUuid()));
}
if (aMetacard.getCreatedDate() == null) {
aMetacard.setAttribute(new AttributeImpl(Metacard.CREATED, now));
}
if (aMetacard.getModifiedDate() == null) {
aMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, now));
}
if (aMetacard.getEffectiveDate() == null) {
aMetacard.setAttribute(new AttributeImpl(Metacard.EFFECTIVE, now));
}
if (isDateAttributeEmpty(aMetacard, Core.METACARD_CREATED)) {
aMetacard.setAttribute(new AttributeImpl(Core.METACARD_CREATED, now));
logMetacardAttributeUpdate(aMetacard, Core.METACARD_CREATED, now);
}
aMetacard.setAttribute(new AttributeImpl(Core.METACARD_MODIFIED, now));
logMetacardAttributeUpdate(aMetacard, Core.METACARD_MODIFIED, now);
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class FileSystemStorageProvider method update.
@Override
public UpdateStorageResponse update(UpdateStorageRequest updateRequest) throws StorageException {
LOGGER.trace("ENTERING: update");
List<ContentItem> contentItems = updateRequest.getContentItems();
List<ContentItem> updatedItems = new ArrayList<>(updateRequest.getContentItems().size());
for (ContentItem contentItem : contentItems) {
try {
if (!ContentItemValidator.validate(contentItem)) {
LOGGER.warn("Item is not valid: {}", contentItem);
continue;
}
ContentItem updateItem = contentItem;
if (StringUtils.isBlank(contentItem.getFilename()) || StringUtils.equals(contentItem.getFilename(), ContentItem.DEFAULT_FILE_NAME)) {
ContentItem existingItem = readContent(new URI(contentItem.getUri()));
updateItem = new ContentItemDecorator(contentItem, existingItem);
}
Path contentIdDir = getTempContentItemDir(updateRequest.getId(), new URI(updateItem.getUri()));
updatedItems.add(generateContentFile(updateItem, contentIdDir, (String) updateRequest.getPropertyValue(Constants.STORE_REFERENCE_KEY)));
} catch (IOException | URISyntaxException | IllegalArgumentException e) {
throw new StorageException(e);
}
}
for (ContentItem contentItem : updatedItems) {
if (contentItem.getMetacard().getResourceURI() == null && StringUtils.isBlank(contentItem.getQualifier())) {
contentItem.getMetacard().setAttribute(new AttributeImpl(Metacard.RESOURCE_URI, contentItem.getUri()));
try {
contentItem.getMetacard().setAttribute(new AttributeImpl(Metacard.RESOURCE_SIZE, contentItem.getSize()));
} catch (IOException e) {
LOGGER.info("Could not set size of content item [{}] on metacard [{}]", contentItem.getId(), contentItem.getMetacard().getId(), e);
}
}
}
UpdateStorageResponse response = new UpdateStorageResponseImpl(updateRequest, updatedItems);
updateMap.put(updateRequest.getId(), updatedItems.stream().map(ContentItem::getUri).collect(Collectors.toSet()));
LOGGER.trace("EXITING: update");
return response;
}
use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.
the class TestMetacardGroomerPlugin method getStandardMetacard.
private Metacard getStandardMetacard(String id) {
DateTime currentDate = new DateTime();
Date defaultDate = currentDate.minusMinutes(1).toDate();
MetacardImpl metacard = new MetacardImpl(getHybridMetacardType());
if (id != null) {
metacard.setId(id);
}
metacard.setTitle(DEFAULT_TITLE);
metacard.setCreatedDate(defaultDate);
metacard.setAttribute(new AttributeImpl(Core.METACARD_CREATED, defaultDate));
metacard.setEffectiveDate(defaultDate);
metacard.setExpirationDate(defaultDate);
metacard.setModifiedDate(defaultDate);
metacard.setAttribute(new AttributeImpl(Core.METACARD_MODIFIED, defaultDate));
metacard.setMetadata(DEFAULT_METADATA);
metacard.setContentTypeName(DEFAULT_TYPE);
metacard.setContentTypeVersion(DEFAULT_VERSION);
metacard.setLocation(DEFAULT_LOCATION);
byte[] defaultBytes = { -86 };
metacard.setThumbnail(defaultBytes);
return metacard;
}
Aggregations