Search in sources :

Example 11 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdminServiceImpl method getRegistryMetacardsByFilter.

private List<Metacard> getRegistryMetacardsByFilter(Filter filter, Set<String> sourceIds) throws FederationAdminException {
    if (filter == null) {
        throw new FederationAdminException("Error getting registry metacards. Null filter provided.");
    }
    PropertyName propertyName = new PropertyNameImpl(Metacard.MODIFIED);
    SortBy sortBy = new SortByImpl(propertyName, SortOrder.ASCENDING);
    QueryImpl query = new QueryImpl(filter);
    query.setSortBy(sortBy);
    query.setPageSize(PAGE_SIZE);
    QueryRequest queryRequest = new QueryRequestImpl(query, sourceIds);
    try {
        QueryResponse queryResponse = security.runWithSubjectOrElevate(() -> catalogFramework.query(queryRequest));
        return queryResponse.getResults().stream().map(Result::getMetacard).filter(Objects::nonNull).collect(Collectors.toList());
    } catch (SecurityServiceException | InvocationTargetException e) {
        String message = "Error querying for registry metacards.";
        LOGGER.debug("{} For Filter: {}", message, filter);
        throw new FederationAdminException(message, e);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) PropertyName(org.opengis.filter.expression.PropertyName) SecurityServiceException(ddf.security.service.SecurityServiceException) QueryRequest(ddf.catalog.operation.QueryRequest) SortBy(org.opengis.filter.sort.SortBy) InvocationTargetException(java.lang.reflect.InvocationTargetException) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl)

Example 12 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdminServiceImpl method getRegistryObjectByRegistryId.

@Override
public RegistryPackageType getRegistryObjectByRegistryId(String registryId, Set<String> sourceIds) throws FederationAdminException {
    if (StringUtils.isBlank(registryId)) {
        throw new FederationAdminException("Error getting registry object by metacard id. Empty id provided.");
    }
    List<Filter> filters = getBasicFilter();
    filters.add(filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_ID).is().equalTo().text(registryId));
    Filter filter = filterBuilder.allOf(filters);
    List<Metacard> metacards = getRegistryMetacardsByFilter(filter, sourceIds);
    if (CollectionUtils.isEmpty(metacards)) {
        String message = "Error getting registry object by metacard id. No result returned.";
        LOGGER.debug("{} For metacard ID: {}, optional sources: {}", message, registryId, sourceIds);
        throw new FederationAdminException(message);
    }
    if (metacards.size() > 1) {
        String message = "Error getting registry object by metacard id. More than one metacards were returned.";
        LOGGER.debug("{} For metacard ID: {}, optional sources: {}", message, registryId, sourceIds);
        throw new FederationAdminException(message);
    }
    return getRegistryPackageFromMetacard(metacards.get(0));
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter)

Example 13 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdminServiceImpl method getRegistryMetacardsByRegistryIds.

@Override
public List<Metacard> getRegistryMetacardsByRegistryIds(List<String> ids, boolean includeInternal) throws FederationAdminException {
    if (CollectionUtils.isEmpty(ids)) {
        throw new FederationAdminException("Error getting registry metacards by registry ids. Null list of Ids provided.");
    }
    List<Filter> idFilters = ids.stream().map(id -> filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_ID).is().equalTo().text(id)).collect(Collectors.toList());
    List<Filter> filters = getBasicFilter();
    Filter filter = filterBuilder.allOf(filters);
    if (includeInternal) {
        filter = filterBuilder.anyOf(filter, filterBuilder.allOf(getBasicFilter(RegistryConstants.REGISTRY_TAG_INTERNAL)));
    }
    filter = filterBuilder.allOf(filter, filterBuilder.anyOf(idFilters));
    return getRegistryMetacardsByFilter(filter);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) CreateRequest(ddf.catalog.operation.CreateRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) LoggerFactory(org.slf4j.LoggerFactory) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Map(java.util.Map) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Bundle(org.osgi.framework.Bundle) InputTransformer(ddf.catalog.transform.InputTransformer) PrintWriter(java.io.PrintWriter) SortByImpl(org.geotools.filter.SortByImpl) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) Set(java.util.Set) ParserException(org.codice.ddf.parser.ParserException) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Objects(java.util.Objects) DeleteRequest(ddf.catalog.operation.DeleteRequest) IOUtils(org.apache.commons.io.IOUtils) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) SlotTypeHelper(org.codice.ddf.registry.schemabindings.helper.SlotTypeHelper) Optional(java.util.Optional) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UpdateResponse(ddf.catalog.operation.UpdateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterBuilder(ddf.catalog.filter.FilterBuilder) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashMap(java.util.HashMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) SecurityServiceException(ddf.security.service.SecurityServiceException) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) SortBy(org.opengis.filter.sort.SortBy) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) InternationalStringTypeHelper(org.codice.ddf.registry.schemabindings.helper.InternationalStringTypeHelper) Result(ddf.catalog.data.Result) SortOrder(org.opengis.filter.sort.SortOrder) 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) Security(org.codice.ddf.security.common.Security) StringWriter(java.io.StringWriter) IOException(java.io.IOException) AbstractMap(java.util.AbstractMap) PropertyName(org.opengis.filter.expression.PropertyName) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Filter(org.opengis.filter.Filter)

Example 14 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdminServiceImpl method getLocalRegistryMetacardsByRegistryIds.

@Override
public List<Metacard> getLocalRegistryMetacardsByRegistryIds(List<String> ids) throws FederationAdminException {
    if (CollectionUtils.isEmpty(ids)) {
        throw new FederationAdminException("Error getting local registry metacards by registry ids. Null list of Ids provided.");
    }
    List<Filter> idFilters = ids.stream().map(id -> filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_ID).is().equalTo().text(id)).collect(Collectors.toList());
    List<Filter> filters = getBasicFilter();
    filters.add(filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE).is().bool(true));
    Filter filter = filterBuilder.allOf(filters);
    filter = filterBuilder.allOf(filter, filterBuilder.anyOf(idFilters));
    return getRegistryMetacardsByFilter(filter);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) CreateRequest(ddf.catalog.operation.CreateRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) LoggerFactory(org.slf4j.LoggerFactory) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Map(java.util.Map) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Bundle(org.osgi.framework.Bundle) InputTransformer(ddf.catalog.transform.InputTransformer) PrintWriter(java.io.PrintWriter) SortByImpl(org.geotools.filter.SortByImpl) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) Set(java.util.Set) ParserException(org.codice.ddf.parser.ParserException) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Objects(java.util.Objects) DeleteRequest(ddf.catalog.operation.DeleteRequest) IOUtils(org.apache.commons.io.IOUtils) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) SlotTypeHelper(org.codice.ddf.registry.schemabindings.helper.SlotTypeHelper) Optional(java.util.Optional) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UpdateResponse(ddf.catalog.operation.UpdateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterBuilder(ddf.catalog.filter.FilterBuilder) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashMap(java.util.HashMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) SecurityServiceException(ddf.security.service.SecurityServiceException) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) SortBy(org.opengis.filter.sort.SortBy) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) InternationalStringTypeHelper(org.codice.ddf.registry.schemabindings.helper.InternationalStringTypeHelper) Result(ddf.catalog.data.Result) SortOrder(org.opengis.filter.sort.SortOrder) 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) Security(org.codice.ddf.security.common.Security) StringWriter(java.io.StringWriter) IOException(java.io.IOException) AbstractMap(java.util.AbstractMap) PropertyName(org.opengis.filter.expression.PropertyName) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Filter(org.opengis.filter.Filter)

Example 15 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class RefreshRegistryEntries method getRemoteRegistryMetacardsMap.

/**
     * Directly queries the stores without going through the catalog framework
     */
private RemoteRegistryResults getRemoteRegistryMetacardsMap() throws FederationAdminException {
    Map<String, Metacard> remoteRegistryMetacards = new HashMap<>();
    List<String> failedQueries = new ArrayList<>();
    List<String> storesQueried = new ArrayList<>();
    List<String> localMetacardRegIds = getLocalRegistryIds();
    Map<String, Serializable> queryProps = new HashMap<>();
    queryProps.put(SecurityConstants.SECURITY_SUBJECT, security.runAsAdmin(() -> security.getSystemSubject()));
    LOGGER.debug("Querying {} remote registries", registryStores.size());
    //Create the remote query task to be run.
    List<Callable<RemoteResult>> tasks = new ArrayList<>();
    for (RegistryStore store : registryStores) {
        if (!store.isPullAllowed() || !store.isAvailable()) {
            LOGGER.debug("Skipping store {} because pull is disabled or it is unavailable", store.getId());
            continue;
        }
        storesQueried.add(store.getRegistryId());
        tasks.add(() -> {
            SourceResponse response = store.query(new QueryRequestImpl(getBasicRegistryQuery(), queryProps));
            Map<String, Metacard> results = response.getResults().stream().map(Result::getMetacard).filter(e -> !localMetacardRegIds.contains(RegistryUtility.getRegistryId(e))).collect(Collectors.toMap(Metacard::getId, Function.identity()));
            LOGGER.debug("Retrieved {} registry entries from {} with {} local entries filtered.", results.size(), store.getId(), response.getResults().size());
            logRegistryMetacards("Filtered remote entries", results.values());
            return new RemoteResult(store.getRegistryId(), results);
        });
    }
    failedQueries.addAll(storesQueried);
    List<RemoteResult> results = executeTasks(tasks);
    results.stream().forEach(result -> {
        failedQueries.remove(result.getRegistryId());
        remoteRegistryMetacards.putAll(result.getRemoteRegistryMetacards());
    });
    return new RemoteRegistryResults(remoteRegistryMetacards, failedQueries, storesQueried);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterBuilder(ddf.catalog.filter.FilterBuilder) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) SortBy(org.opengis.filter.sort.SortBy) CollectionUtils(org.apache.commons.collections.CollectionUtils) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) SecurityConstants(ddf.security.SecurityConstants) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) Result(ddf.catalog.data.Result) SortOrder(org.opengis.filter.sort.SortOrder) SortByImpl(org.geotools.filter.SortByImpl) PrivilegedActionException(java.security.PrivilegedActionException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) Security(org.codice.ddf.security.common.Security) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) Collection(java.util.Collection) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Query(ddf.catalog.operation.Query) List(java.util.List) SourceResponse(ddf.catalog.operation.SourceResponse) PropertyName(org.opengis.filter.expression.PropertyName) Filter(org.opengis.filter.Filter) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) Serializable(java.io.Serializable) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Aggregations

FederationAdminException (org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException)30 Metacard (ddf.catalog.data.Metacard)16 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 Test (org.junit.Test)9 IOException (java.io.IOException)8 SecurityServiceException (ddf.security.service.SecurityServiceException)7 Serializable (java.io.Serializable)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 RegistryPackageType (oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType)7 Filter (org.opengis.filter.Filter)7 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)6 Result (ddf.catalog.data.Result)5 PropertyNameImpl (ddf.catalog.filter.impl.PropertyNameImpl)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)5 List (java.util.List)5 Map (java.util.Map)5 RegistryUtility (org.codice.ddf.registry.common.metacard.RegistryUtility)5 SortByImpl (org.geotools.filter.SortByImpl)5