Search in sources :

Example 1 with RegistryUtility

use of org.codice.ddf.registry.common.metacard.RegistryUtility in project ddf by codice.

the class FederationAdminServiceImpl method addRegistryEntries.

@Override
public List<String> addRegistryEntries(List<Metacard> metacards, Set<String> destinations) throws FederationAdminException {
    validateRegistryMetacards(metacards);
    List<String> registryIds;
    Map<String, Serializable> properties = new HashMap<>();
    CreateRequest createRequest = new CreateRequestImpl(metacards, properties, destinations);
    try {
        CreateResponse createResponse = security.runWithSubjectOrElevate(() -> catalogFramework.create(createRequest));
        //loop through to get id's
        if (!createResponse.getProcessingErrors().isEmpty()) {
            throw new FederationAdminException("Processing error occurred while creating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(createResponse.getProcessingErrors()));
        }
        registryIds = createResponse.getCreatedMetacards().stream().filter(RegistryUtility::isRegistryMetacard).map(RegistryUtility::getRegistryId).collect(Collectors.toList());
    } catch (SecurityServiceException | InvocationTargetException e) {
        throw new FederationAdminException("Error adding local registry entry.", e);
    }
    return registryIds;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl)

Example 2 with RegistryUtility

use of org.codice.ddf.registry.common.metacard.RegistryUtility 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 RegistryUtility

use of org.codice.ddf.registry.common.metacard.RegistryUtility in project ddf by codice.

the class RegistryStoreImpl method create.

@Override
public CreateResponse create(CreateRequest request) throws IngestException {
    if (request.getMetacards().stream().map(RegistryUtility::getRegistryId).anyMatch(Objects::isNull)) {
        throw new IngestException("One or more of the metacards is not a registry metacard");
    }
    validateOperation();
    List<Filter> regIdFilters = request.getMetacards().stream().map(e -> filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(e.getId())).collect(Collectors.toList());
    Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
    Map<String, Serializable> queryProps = new HashMap<>();
    queryProps.put(SecurityConstants.SECURITY_SUBJECT, request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT));
    QueryImpl query = new QueryImpl(filterBuilder.allOf(tagFilter, filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE).empty(), filterBuilder.anyOf(regIdFilters)));
    QueryRequest queryRequest = new QueryRequestImpl(query, queryProps);
    try {
        SourceResponse queryResponse = super.query(queryRequest);
        Map<String, Metacard> responseMap = queryResponse.getResults().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getMetacard()), Result::getMetacard));
        List<Metacard> metacardsToCreate = request.getMetacards().stream().filter(e -> !responseMap.containsKey(RegistryUtility.getRegistryId(e))).collect(Collectors.toList());
        List<Metacard> allMetacards = new ArrayList<>(responseMap.values());
        if (CollectionUtils.isNotEmpty(metacardsToCreate)) {
            CreateResponse createResponse = super.create(new CreateRequestImpl(metacardsToCreate, request.getProperties()));
            allMetacards.addAll(createResponse.getCreatedMetacards());
        }
        return new CreateResponseImpl(request, request.getProperties(), allMetacards);
    } catch (UnsupportedQueryException e) {
        LOGGER.warn("Unable to perform pre-create remote query. Proceeding with original query. Error was {}", e.getMessage());
    }
    return super.create(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) Serializable(java.io.Serializable) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Objects(java.util.Objects) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 4 with RegistryUtility

use of org.codice.ddf.registry.common.metacard.RegistryUtility in project ddf by codice.

the class IdentificationPlugin method process.

/**
     * For registry metacards verifies the update should take place by checking that the update
     * metacard is at least as up to date as the existing one. Also updates the tags, identifiers,
     * and transient attributes of the updated metacard.
     *
     * @param input the {@link UpdateRequest} to process
     * @return
     * @throws PluginExecutionException
     * @throws StopProcessingException
     */
@Override
public UpdateRequest process(UpdateRequest input) throws PluginExecutionException, StopProcessingException {
    if (!Requests.isLocal(input)) {
        return input;
    }
    OperationTransaction operationTransaction = (OperationTransaction) input.getProperties().get(Constants.OPERATION_TRANSACTION_KEY);
    List<Metacard> previousMetacards = operationTransaction.getPreviousStateMetacards();
    Map<String, Metacard> previousMetacardsMap = previousMetacards.stream().filter(e -> RegistryUtility.isRegistryMetacard(e) || RegistryUtility.isInternalRegistryMetacard(e)).collect(Collectors.toMap(RegistryUtility::getRegistryId, Function.identity()));
    List<Map.Entry<Serializable, Metacard>> entriesToRemove = new ArrayList<>();
    List<Map.Entry<Serializable, Metacard>> registryUpdates = input.getUpdates().stream().filter(e -> RegistryUtility.isRegistryMetacard(e.getValue())).collect(Collectors.toList());
    for (Map.Entry<Serializable, Metacard> entry : registryUpdates) {
        Metacard updateMetacard = entry.getValue();
        Metacard existingMetacard = previousMetacardsMap.get(RegistryUtility.getRegistryId(updateMetacard));
        if (existingMetacard == null) {
            continue;
        }
        if (updateMetacard.getMetadata() != null && !updateMetacard.getModifiedDate().before(existingMetacard.getModifiedDate())) {
            updateMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacard.getId()));
            copyTransientAttributes(updateMetacard, existingMetacard);
            updateTags(updateMetacard);
            if (isInternal(updateMetacard)) {
                updateMetacard.setAttribute(existingMetacard.getAttribute(RegistryObjectMetacardType.REMOTE_METACARD_ID));
                updateMetacard.setAttribute(existingMetacard.getAttribute(RegistryObjectMetacardType.REMOTE_REGISTRY_ID));
            }
            updateIdentifiers(updateMetacard, false);
        } else {
            entriesToRemove.add(entry);
        }
    }
    input.getUpdates().removeAll(entriesToRemove);
    return input;
}
Also used : PreIngestPlugin(ddf.catalog.plugin.PreIngestPlugin) CreateRequest(ddf.catalog.operation.CreateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) OperationTransaction(ddf.catalog.operation.OperationTransaction) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Requests(ddf.catalog.util.impl.Requests) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) UpdateRequest(ddf.catalog.operation.UpdateRequest) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) StopProcessingException(ddf.catalog.plugin.StopProcessingException) ParserException(org.codice.ddf.parser.ParserException) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) DeleteRequest(ddf.catalog.operation.DeleteRequest) List(java.util.List) Attribute(ddf.catalog.data.Attribute) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) Serializable(java.io.Serializable) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) OperationTransaction(ddf.catalog.operation.OperationTransaction) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map)

Aggregations

CreateRequest (ddf.catalog.operation.CreateRequest)4 Serializable (java.io.Serializable)4 RegistryUtility (org.codice.ddf.registry.common.metacard.RegistryUtility)4 Constants (ddf.catalog.Constants)3 Metacard (ddf.catalog.data.Metacard)3 CreateResponse (ddf.catalog.operation.CreateResponse)3 DeleteRequest (ddf.catalog.operation.DeleteRequest)3 OperationTransaction (ddf.catalog.operation.OperationTransaction)3 UpdateRequest (ddf.catalog.operation.UpdateRequest)3 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Converter (com.thoughtworks.xstream.converters.Converter)2 Result (ddf.catalog.data.Result)2 TagsFilterDelegate (ddf.catalog.filter.delegate.TagsFilterDelegate)2 DeleteResponse (ddf.catalog.operation.DeleteResponse)2 Query (ddf.catalog.operation.Query)2