Search in sources :

Example 1 with OperationTransaction

use of ddf.catalog.operation.OperationTransaction in project ddf by codice.

the class WorkspacePreIngestPluginTest method update.

private static UpdateRequest update(Metacard original, Metacard updated) {
    UpdateRequestImpl request = new UpdateRequestImpl(original.getId(), updated);
    OperationTransaction transaction = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Arrays.asList(original));
    request.setProperties(Collections.singletonMap(Constants.OPERATION_TRANSACTION_KEY, transaction));
    return request;
}
Also used : OperationTransaction(ddf.catalog.operation.OperationTransaction) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl)

Example 2 with OperationTransaction

use of ddf.catalog.operation.OperationTransaction in project ddf by codice.

the class RegistryStoreImpl method update.

@Override
public UpdateResponse update(UpdateRequest request) throws IngestException {
    if (request.getUpdates().stream().map(e -> RegistryUtility.getRegistryId(e.getValue())).anyMatch(Objects::isNull)) {
        throw new IngestException("One or more of the metacards is not a registry metacard");
    }
    Map<String, Metacard> updatedMetacards = request.getUpdates().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getValue()), Map.Entry::getValue));
    Map<String, Metacard> origMetacards = ((OperationTransaction) request.getPropertyValue(Constants.OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards().stream().collect(Collectors.toMap(RegistryUtility::getRegistryId, e -> e));
    //update the new metacards with the id from the orig so that they can be found on the remote system
    try {
        for (Map.Entry<String, Metacard> entry : updatedMetacards.entrySet()) {
            setMetacardExtID(entry.getValue(), origMetacards.get(entry.getKey()).getId());
        }
    } catch (ParserException e) {
        throw new IngestException("Could not update metacards id", e);
    }
    return super.update(request);
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) Locale(java.util.Locale) Map(java.util.Map) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) Converter(com.thoughtworks.xstream.converters.Converter) ImmutableSet(com.google.common.collect.ImmutableSet) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SourceMonitor(ddf.catalog.source.SourceMonitor) ParserException(org.codice.ddf.parser.ParserException) AbstractCswStore(org.codice.ddf.spatial.ogc.csw.catalog.common.source.AbstractCswStore) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Serializable(java.io.Serializable) Objects(java.util.Objects) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) DeleteRequest(ddf.catalog.operation.DeleteRequest) List(java.util.List) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UpdateResponse(ddf.catalog.operation.UpdateResponse) Dictionary(java.util.Dictionary) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) HashMap(java.util.HashMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) OperationTransaction(ddf.catalog.operation.OperationTransaction) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) ArrayList(java.util.ArrayList) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Configuration(org.osgi.service.cm.Configuration) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) SecurityConstants(ddf.security.SecurityConstants) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) EncryptionService(ddf.security.encryption.EncryptionService) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) Result(ddf.catalog.data.Result) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) IngestException(ddf.catalog.source.IngestException) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) IOException(java.io.IOException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) MetaTypeService(org.osgi.service.metatype.MetaTypeService) Consumer(java.util.function.Consumer) Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) OperationTransaction(ddf.catalog.operation.OperationTransaction) ParserException(org.codice.ddf.parser.ParserException) Metacard(ddf.catalog.data.Metacard) Objects(java.util.Objects) IngestException(ddf.catalog.source.IngestException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with OperationTransaction

use of ddf.catalog.operation.OperationTransaction in project ddf by codice.

the class PointOfContactPolicyPlugin method processPreUpdate.

@Override
public PolicyResponse processPreUpdate(Metacard newMetacard, Map<String, Serializable> properties) throws StopProcessingException {
    // If it's not a resource metacard, don't apply the policy.
    if (!newMetacard.getTags().isEmpty() && !newMetacard.getTags().contains("resource")) {
        return new PolicyResponseImpl();
    }
    List<Metacard> previousStateMetacards = ((OperationTransaction) properties.get(OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards();
    Metacard previous;
    previous = previousStateMetacards.stream().filter(x -> x.getId().equals(newMetacard.getId())).findFirst().orElse(null);
    return pointOfContactChanged(newMetacard, previous) ? new PolicyResponseImpl(null, permissionMap) : new PolicyResponseImpl();
}
Also used : OperationTransaction(ddf.catalog.operation.OperationTransaction) ResourceResponse(ddf.catalog.operation.ResourceResponse) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Logger(org.slf4j.Logger) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) LoggerFactory(org.slf4j.LoggerFactory) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Set(java.util.Set) OperationTransaction(ddf.catalog.operation.OperationTransaction) OPERATION_TRANSACTION_KEY(ddf.catalog.Constants.OPERATION_TRANSACTION_KEY) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) Permissions(ddf.security.permission.Permissions) List(java.util.List) Attribute(ddf.catalog.data.Attribute) Metacard(ddf.catalog.data.Metacard) ResourceRequest(ddf.catalog.operation.ResourceRequest) Map(java.util.Map) Result(ddf.catalog.data.Result) Nullable(javax.annotation.Nullable) Metacard(ddf.catalog.data.Metacard) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl)

Example 4 with OperationTransaction

use of ddf.catalog.operation.OperationTransaction in project ddf by codice.

the class ResourceUriPolicy method processPreUpdate.

@Override
public PolicyResponse processPreUpdate(Metacard input, Map<String, Serializable> properties) throws StopProcessingException {
    if (!Requests.isLocal(properties)) {
        return new PolicyResponseImpl();
    }
    PolicyResponseImpl policyResponse = new PolicyResponseImpl(null, permissions.parsePermissionsFromString(getUpdatePermissions()));
    List<Metacard> previousStateMetacards = ((OperationTransaction) properties.get(OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards();
    Metacard previous = previousStateMetacards.stream().filter((x) -> x.getId().equals(input.getId())).findFirst().orElse(null);
    if (previous == null) {
        LOGGER.debug("Cannot locate metacard {} for update. Applying permissions to the item", input.getId());
        return policyResponse;
    }
    return requiresPermission(input.getResourceURI(), previous.getResourceURI()) ? policyResponse : new PolicyResponseImpl();
}
Also used : OperationTransaction(ddf.catalog.operation.OperationTransaction) Metacard(ddf.catalog.data.Metacard) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl)

Example 5 with OperationTransaction

use of ddf.catalog.operation.OperationTransaction in project ddf by codice.

the class IdentificationPluginTest method testSetTransientAttributesOnUpdateMetacard.

@Test
public void testSetTransientAttributesOnUpdateMetacard() throws Exception {
    String xml = convert("/registry-no-extid.xml");
    MetacardImpl previousMetacard = new MetacardImpl();
    previousMetacard.setAttribute(Metacard.ID, "MetacardId");
    previousMetacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "MetacardId");
    previousMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
    previousMetacard.setAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, "Published Locations");
    previousMetacard.setAttribute(RegistryObjectMetacardType.LAST_PUBLISHED, "Last Published Time");
    previousMetacard.setAttribute(Metacard.MODIFIED, new Date().from(Instant.now()));
    OperationTransaction operationTransaction = new OperationTransactionImpl(null, Collections.singletonList(previousMetacard));
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(Constants.OPERATION_TRANSACTION_KEY, operationTransaction);
    List<Map.Entry<Serializable, Metacard>> updatedEntries = new ArrayList<>();
    MetacardImpl updateMetacard = new MetacardImpl();
    updateMetacard.setAttribute(Metacard.ID, "MetacardId");
    updateMetacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "MetacardId");
    updateMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
    updateMetacard.setAttribute(Metacard.MODIFIED, new Date().from(Instant.now()));
    updateMetacard.setAttribute(Metacard.METADATA, xml);
    updatedEntries.add(new AbstractMap.SimpleEntry<>(updateMetacard.getId(), updateMetacard));
    UpdateRequest updateRequest = new UpdateRequestImpl(updatedEntries, Metacard.ID, properties);
    UpdateRequest processedUpdateRequest = identificationPlugin.process(updateRequest);
    Metacard processedMetacard = processedUpdateRequest.getUpdates().get(0).getValue();
    assertThat(processedMetacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS).getValue(), is("Published Locations"));
    assertThat(processedMetacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED).getValue(), is("Last Published Time"));
}
Also used : Serializable(java.io.Serializable) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) OperationTransaction(ddf.catalog.operation.OperationTransaction) AbstractMap(java.util.AbstractMap) Metacard(ddf.catalog.data.Metacard) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Aggregations

OperationTransaction (ddf.catalog.operation.OperationTransaction)10 Metacard (ddf.catalog.data.Metacard)8 Serializable (java.io.Serializable)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 UpdateRequest (ddf.catalog.operation.UpdateRequest)4 Map (java.util.Map)4 OperationTransactionImpl (ddf.catalog.operation.impl.OperationTransactionImpl)3 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)3 IngestException (ddf.catalog.source.IngestException)3 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)3 List (java.util.List)3 Constants (ddf.catalog.Constants)2 Attribute (ddf.catalog.data.Attribute)2 Result (ddf.catalog.data.Result)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)2 CreateRequest (ddf.catalog.operation.CreateRequest)2 DeleteRequest (ddf.catalog.operation.DeleteRequest)2 Query (ddf.catalog.operation.Query)2 StopProcessingException (ddf.catalog.plugin.StopProcessingException)2