Search in sources :

Example 51 with AttributeImpl

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

the class DeleteOperations method populateDeleteRequestPolicyMap.

private DeleteRequest populateDeleteRequestPolicyMap(DeleteRequest deleteRequest, DeleteResponse deleteResponse) throws StopProcessingException {
    HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
    Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(deleteRequest.getProperties());
    if (deleteResponse != null && deleteResponse.getDeletedMetacards() != null) {
        for (Metacard metacard : deleteResponse.getDeletedMetacards()) {
            HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
            for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
                PolicyResponse policyResponse = plugin.processPostDelete(metacard, unmodifiableProperties);
                opsSecuritySupport.buildPolicyMap(itemPolicyMap, policyResponse.itemPolicy().entrySet());
                opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
            }
            metacard.setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
        }
    }
    deleteRequest.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
    return deleteRequest;
}
Also used : Serializable(java.io.Serializable) Metacard(ddf.catalog.data.Metacard) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponse(ddf.catalog.plugin.PolicyResponse)

Example 52 with AttributeImpl

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

the class MetacardFactory method generateMetacard.

Metacard generateMetacard(String mimeTypeRaw, String id, String fileName, Path tmpContentPath) throws MetacardCreationException, MimeTypeParseException {
    Metacard generatedMetacard = null;
    MimeType mimeType = new MimeType(mimeTypeRaw);
    List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType);
    List<String> stackTraceList = new ArrayList<>();
    LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
    for (InputTransformer candidate : listOfCandidates) {
        try (InputStream transformerStream = com.google.common.io.Files.asByteSource(tmpContentPath.toFile()).openStream()) {
            generatedMetacard = candidate.transform(transformerStream);
        } catch (CatalogTransformerException | IOException e) {
            List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e));
            stackTraceList.add(String.format("Transformer [%s] could not create metacard.", candidate));
            stackTraceList.addAll(stackTraces);
            LOGGER.debug("Transformer [{}] could not create metacard.", candidate, e);
        }
        if (generatedMetacard != null) {
            break;
        }
    }
    if (generatedMetacard == null) {
        throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeTypeRaw, StringUtils.join(stackTraceList, "\n")));
    }
    if (id != null) {
        generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id));
    } else {
        generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, uuidGenerator.generateUuid()));
    }
    if (StringUtils.isBlank(generatedMetacard.getTitle())) {
        generatedMetacard.setAttribute(new AttributeImpl(Metacard.TITLE, fileName));
    }
    return generatedMetacard;
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer) MimeType(javax.activation.MimeType) Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) List(java.util.List)

Example 53 with AttributeImpl

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

the class PointOfContactUpdatePluginTest method processPreUpdateDoesNothingIfNewPOCHasAValue.

@Test
public void processPreUpdateDoesNothingIfNewPOCHasAValue() throws Exception {
    listOfUpdatedMetacards.forEach(m -> m.setAttribute(new AttributeImpl(Metacard.POINT_OF_CONTACT, NEW_EMAIL)));
    UpdateRequest updateRequestOutput = pointOfContactUpdatePlugin.processPreUpdate(updateRequestInput, existingMetacards);
    assertThat(updateRequestOutput.getUpdates().get(0).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
    assertThat(updateRequestOutput.getUpdates().get(1).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
    assertThat(updateRequestOutput.getUpdates().get(2).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
}
Also used : UpdateRequest(ddf.catalog.operation.UpdateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Test(org.junit.Test)

Example 54 with AttributeImpl

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

the class PointOfContactUpdatePluginTest method getPreviousMetacardsWithPointOfContact.

private Map<String, Metacard> getPreviousMetacardsWithPointOfContact() {
    Attribute pocAttribute = new AttributeImpl(Metacard.POINT_OF_CONTACT, ADMIN_EMAIL);
    Metacard resourceMetacard1 = getMetacardWithIdAndTag(RESOURCE_ID1, "resource");
    resourceMetacard1.setAttribute(pocAttribute);
    Metacard resourceMetacard2 = getMetacardWithIdAndTag(RESOURCE_ID2, null);
    resourceMetacard2.setAttribute(pocAttribute);
    Metacard registryMetacard = getMetacardWithIdAndTag(REGISTRY_ID, "registry");
    registryMetacard.setAttribute(pocAttribute);
    Map<String, Metacard> existingMetacards = new HashMap<String, Metacard>();
    existingMetacards.put(RESOURCE_ID1, resourceMetacard1);
    existingMetacards.put(RESOURCE_ID2, resourceMetacard2);
    existingMetacards.put(REGISTRY_ID, registryMetacard);
    return existingMetacards;
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 55 with AttributeImpl

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

the class GeoCoderPlugin method setCountryCode.

/**
     * Sets the country code attribute of the {@param metacard} when the {@param metacard} has a
     * location and there is not already a country code attribute. Does not update the country code
     * if the country code attribute is already set.
     *
     * @param metacard
     */
private void setCountryCode(Metacard metacard, GeoCoder geoCoder) {
    Optional<String> wktLocation = Optional.ofNullable(metacard.getLocation());
    if (geoCoder != null && wktLocation.isPresent() && !hasCountryCode(metacard)) {
        Optional<String> alpha3CountryCode = geoCoder.getCountryCode(wktLocation.get(), radiusInKm);
        alpha3CountryCode.ifPresent(countryCode -> {
            LOGGER.trace("Setting metacard country code to {} for metacard with id {}", countryCode, metacard.getId());
            metacard.setAttribute(new AttributeImpl(Location.COUNTRY_CODE, countryCode));
        });
    }
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

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