use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class FederationAdminServiceImpl method deleteRegistryEntriesByRegistryIds.
@Override
public void deleteRegistryEntriesByRegistryIds(List<String> registryIds, Set<String> destinations) throws FederationAdminException {
if (CollectionUtils.isEmpty(registryIds)) {
throw new FederationAdminException("An empty list of registry ids to be deleted was received. Nothing to delete.");
}
List<Serializable> serializableIds = new ArrayList<>(registryIds);
Map<String, Serializable> properties = new HashMap<>();
String deleteField = RegistryObjectMetacardType.REGISTRY_ID;
if (CollectionUtils.isNotEmpty(destinations)) {
deleteField = Metacard.ID;
try {
List<Metacard> localMetacards = security.runWithSubjectOrElevate(() -> this.getRegistryMetacardsByRegistryIds(registryIds));
List<Filter> idFilters = localMetacards.stream().map(e -> filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(e.getId())).collect(Collectors.toList());
Filter baseFilter = filterBuilder.allOf(getBasicFilter(RegistryConstants.REGISTRY_TAG_INTERNAL));
List<Metacard> toDelete = security.runWithSubjectOrElevate(() -> this.getRegistryMetacardsByFilter(filterBuilder.allOf(baseFilter, filterBuilder.anyOf(idFilters)), destinations));
serializableIds = toDelete.stream().map(e -> e.getId()).collect(Collectors.toList());
} catch (SecurityServiceException | InvocationTargetException e) {
throw new FederationAdminException("Error looking up metacards to delete.", e);
}
}
DeleteRequest deleteRequest = new DeleteRequestImpl(serializableIds, deleteField, properties, destinations);
try {
DeleteResponse deleteResponse = security.runWithSubjectOrElevate(() -> catalogFramework.delete(deleteRequest));
if (!deleteResponse.getProcessingErrors().isEmpty()) {
throw new FederationAdminException("Processing error occurred while deleting registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(deleteResponse.getProcessingErrors()));
}
} catch (SecurityServiceException | InvocationTargetException e) {
String message = "Error deleting registry entries by registry id.";
LOGGER.debug("{} Registry Ids provided: {}", message, registryIds);
throw new FederationAdminException(message, e);
}
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class RegistryPublicationServiceImpl method update.
@Override
public void update(Metacard metacard) throws FederationAdminException {
List<String> publishedLocations = RegistryUtility.getListOfStringAttribute(metacard, RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
if (publishedLocations.isEmpty()) {
return;
}
Set<String> locations = publishedLocations.stream().map(registryId -> getSourceIdFromRegistryId(registryId)).filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new));
if (CollectionUtils.isNotEmpty(locations)) {
try {
LOGGER.info("Updating publication for registry entry {}:{} at {}", metacard.getTitle(), RegistryUtility.getRegistryId(metacard), String.join(",", locations));
federationAdminService.updateRegistryEntry(metacard, locations);
} catch (FederationAdminException e) {
//This should not happen often but could occur if the remote registry removed the metacard
//that was to be updated. In that case performing an add will fix the problem. If the failure
//was for another reason like the site couldn't be contacted then the add will fail
//also and the end result will be the same.
federationAdminService.addRegistryEntry(metacard, locations);
}
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, Date.from(ZonedDateTime.now().toInstant())));
federationAdminService.updateRegistryEntry(metacard);
}
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class RegistryPublicationServiceImpl method publish.
@Override
public void publish(String registryId, String destinationRegistryId) throws FederationAdminException {
Metacard metacard = getMetacard(registryId);
String metacardId = metacard.getId();
List<String> locations = RegistryUtility.getListOfStringAttribute(metacard, RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
if (locations.contains(destinationRegistryId)) {
return;
}
String sourceId = getSourceIdFromRegistryId(destinationRegistryId);
if (sourceId == null) {
throw new FederationAdminException("Could not find a source id for registry-id " + destinationRegistryId);
}
LOGGER.info("Publishing registry entry {}:{} to {}", metacard.getTitle(), registryId, sourceId);
federationAdminService.addRegistryEntry(metacard, Collections.singleton(sourceId));
//need to reset the id since the framework reset it in the groomer plugin
//and we don't want to update with the wrong id
metacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId));
locations.add(destinationRegistryId);
locations.remove(NO_PUBLICATIONS);
ArrayList<String> locArr = new ArrayList<>(locations);
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, locArr));
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, Date.from(ZonedDateTime.now().toInstant())));
federationAdminService.updateRegistryEntry(metacard);
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class FederationAdminTest method testRegistryMetacardRegistryIdNotFound.
@Test
public void testRegistryMetacardRegistryIdNotFound() throws Exception {
when(federationAdminService.getRegistryObjectByRegistryId(any())).thenThrow(new FederationAdminException("Not found"));
when(federationAdminService.getRegistryMetacardsByRegistryIds(any())).thenReturn(Collections.emptyList());
List<Map<String, Object>> result = (List<Map<String, Object>>) federationAdmin.registryMetacard("urn:uuid:2014ca7f59ac46f495e32b4a67a51276").get("nodes");
assertThat(result.size(), is(0));
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class RegistryPublicationServiceImplTest method testUpdateException.
@Test
public void testUpdateException() throws Exception {
doThrow(new FederationAdminException("Test Error")).when(federationAdminService).updateRegistryEntry(any(Metacard.class), any(Set.class));
MetacardImpl mcard = new MetacardImpl();
mcard.setAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, REGISTRY_STORE_REGISTRY_ID);
registryPublicationService.update(mcard);
verify(federationAdminService).addRegistryEntry(mcard, Collections.singleton(REGISTRY_STORE_ID));
}
Aggregations