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);
}
}
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));
}
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);
}
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);
}
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);
}
Aggregations