use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class RegistryPublicationServiceImpl method unpublish.
@Override
public void unpublish(String registryId, String destinationRegistryId) throws FederationAdminException {
Metacard metacard = getMetacard(registryId);
List<String> locations = RegistryUtility.getListOfStringAttribute(metacard, RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
if (!locations.contains(destinationRegistryId)) {
return;
}
locations.remove(destinationRegistryId);
if (locations.isEmpty()) {
locations.add(NO_PUBLICATIONS);
}
ArrayList<String> locArr = new ArrayList<>();
locArr.addAll(locations);
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, locArr));
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, Date.from(ZonedDateTime.now().toInstant())));
federationAdminService.updateRegistryEntry(metacard);
String sourceId = getSourceIdFromRegistryId(destinationRegistryId);
if (sourceId == null) {
throw new FederationAdminException("Could not find a source id for registry-id " + destinationRegistryId);
}
LOGGER.info("Unpublishing registry entry {}:{} from {}", metacard.getTitle(), registryId, sourceId);
federationAdminService.deleteRegistryEntriesByRegistryIds(Collections.singletonList(registryId), Collections.singleton(sourceId));
}
use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.
the class FederationAdminServiceImpl method deleteRegistryEntriesByMetacardIds.
@Override
public void deleteRegistryEntriesByMetacardIds(List<String> metacardIds, Set<String> destinations) throws FederationAdminException {
if (CollectionUtils.isEmpty(metacardIds)) {
throw new FederationAdminException("An empty list of metacard ids to be deleted was received. Nothing to delete.");
}
List<Serializable> serializableIds = new ArrayList<>(metacardIds);
Map<String, Serializable> properties = new HashMap<>();
DeleteRequest deleteRequest = new DeleteRequestImpl(serializableIds, Metacard.ID, 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 metacard ids.";
LOGGER.debug("{} Metacard Ids provided: {}", message, metacardIds);
throw new FederationAdminException(message, e);
}
}
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);
}
Aggregations