use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException 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;
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class FederationAdmin method allRegistryMetacardsSummary.
@Override
public Map<String, Object> allRegistryMetacardsSummary() {
Map<String, Object> nodes = new HashMap<>();
if (!cacheInitialized) {
try {
federationAdminService.getRegistryMetacards().stream().forEach(metacard -> summaryCache.put(RegistryUtility.getRegistryId(metacard), getSummaryMap(metacard)));
cacheInitialized = true;
} catch (FederationAdminException e) {
LOGGER.info("Couldn't get remote registry metacards ", e);
}
}
if (customSlots != null) {
nodes.put(CUSTOM_SLOTS_KEY, customSlots);
}
Map<String, Object> autoPopulateMap = new HashMap<>();
autoPopulateMap.put(SERVICE_BINDINGS_KEY, endpointMap.values());
nodes.put(AUTO_POPULATE_VALUES_KEY, autoPopulateMap);
nodes.put(NODES_KEY, new ArrayList(summaryCache.values()));
return nodes;
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class SourceConfigurationHandler method regenerateOneSource.
@Override
public void regenerateOneSource(String registryId) throws FederationAdminException {
try {
List<Metacard> metacards = federationAdminService.getRegistryMetacardsByRegistryIds(Collections.singletonList(registryId));
if (metacards.size() != 1) {
throw new FederationAdminException("Error looking up metacard to regenerate sources. registry-id=" + registryId);
}
deleteRegistryConfigurations(metacards.get(0));
updateRegistryConfigurations(metacards.get(0), true);
} catch (IOException | ParserException | InvalidSyntaxException e) {
throw new FederationAdminException("Error regenerating sources for registry entry " + registryId, e);
}
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class FederationAdminServiceImpl method getLocalRegistryIdentityMetacard.
@Override
public Optional<Metacard> getLocalRegistryIdentityMetacard() throws FederationAdminException {
Optional<Metacard> metacardOptional = Optional.empty();
List<Filter> filters = getBasicFilter();
filters.add(filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE).is().bool(true));
Filter filter = filterBuilder.allOf(filters);
List<Metacard> identityMetacards = getRegistryMetacardsByFilter(filter);
if (CollectionUtils.isNotEmpty(identityMetacards)) {
if (identityMetacards.size() > 1) {
String message = "Error getting registry identity metacard. More than one result found.";
LOGGER.debug("{} Found these: {}", message, identityMetacards);
throw new FederationAdminException(message);
}
metacardOptional = Optional.of(identityMetacards.get(0));
}
return metacardOptional;
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class FederationAdminServiceImpl method updateRegistryEntry.
@Override
public void updateRegistryEntry(Metacard updateMetacard, Set<String> destinations) throws FederationAdminException {
validateRegistryMetacards(Collections.singletonList(updateMetacard));
Map<String, Serializable> properties = new HashMap<>();
String mcardId = updateMetacard.getId();
if (isRemoteMetacard(updateMetacard) || CollectionUtils.isNotEmpty(destinations)) {
Filter idFilter = filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(updateMetacard.getId());
Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().like().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
List<Metacard> results = this.getRegistryMetacardsByFilter(filterBuilder.allOf(tagFilter, idFilter), destinations);
if (results.size() != 1) {
throw new FederationAdminException("Could not find metacard to update.");
}
mcardId = results.get(0).getId();
LOGGER.debug("Looked up remote-mcard-id {} and got id {}", updateMetacard.getId(), mcardId);
}
List<Map.Entry<Serializable, Metacard>> updateList = new ArrayList<>();
updateList.add(new AbstractMap.SimpleEntry<>(mcardId, updateMetacard));
UpdateRequest updateRequest = new UpdateRequestImpl(updateList, Metacard.ID, properties, destinations);
try {
UpdateResponse updateResponse = security.runWithSubjectOrElevate(() -> catalogFramework.update(updateRequest));
if (!updateResponse.getProcessingErrors().isEmpty()) {
throw new FederationAdminException("Processing error occurred while updating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(updateResponse.getProcessingErrors()));
}
} catch (SecurityServiceException | InvocationTargetException e) {
String message = "Error updating registry entry.";
LOGGER.debug("{} Metacard ID: {}", message, updateMetacard.getId());
throw new FederationAdminException(message, e);
}
}
Aggregations