Search in sources :

Example 11 with AttributeImpl

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) IngestException(ddf.catalog.source.IngestException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 12 with AttributeImpl

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) File(java.io.File) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 13 with AttributeImpl

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);
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 14 with AttributeImpl

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;
}
Also used : Path(java.nio.file.Path) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) UpdateStorageResponseImpl(ddf.catalog.content.operation.impl.UpdateStorageResponseImpl) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem)

Example 15 with AttributeImpl

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;
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) DateTime(org.joda.time.DateTime) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

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