Search in sources :

Example 26 with FederationAdminException

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);
    }
}
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) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) DeleteRequest(ddf.catalog.operation.DeleteRequest)

Example 27 with FederationAdminException

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);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 28 with FederationAdminException

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);
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList)

Example 29 with FederationAdminException

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));
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.anyList(org.mockito.Matchers.anyList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 30 with FederationAdminException

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));
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) Set(java.util.Set) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

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