Search in sources :

Example 1 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class RegistryPublicationManagerTest method testInitFederationAdminException.

@Test
public void testInitFederationAdminException() throws Exception {
    when(federationAdmin.getRegistryMetacards()).thenThrow(new FederationAdminException("Test error"));
    publicationManager.init();
    verify(executorService).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
    publicationManager.destroy();
    verify(executorService).shutdown();
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 2 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class FederationAdmin method createLocalEntry.

@Override
public String createLocalEntry(Map<String, Object> registryMap) throws FederationAdminException {
    Optional<RegistryPackageType> registryPackageOptional = registryTypeConverter.convert(registryMap);
    RegistryPackageType registryPackage = registryPackageOptional.orElseThrow(() -> new FederationAdminException("Error creating local registry entry. Couldn't convert registry map to a registry package."));
    if (!registryPackage.isSetHome()) {
        registryPackage.setHome(SystemBaseUrl.getBaseUrl());
    }
    if (!registryPackage.isSetObjectType()) {
        registryPackage.setObjectType(RegistryConstants.REGISTRY_NODE_OBJECT_TYPE);
    }
    if (!registryPackage.isSetId()) {
        String registryPackageId = RegistryConstants.GUID_PREFIX + UUID.randomUUID().toString().replaceAll("-", "");
        registryPackage.setId(registryPackageId);
    }
    updateDateFields(registryPackage);
    Metacard metacard = getRegistryMetacardFromRegistryPackage(registryPackage);
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE, true));
    return federationAdminService.addRegistryEntry(metacard);
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl)

Example 3 with FederationAdminException

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;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Serializable(java.io.Serializable) SecurityServiceException(ddf.security.service.SecurityServiceException) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl)

Example 4 with FederationAdminException

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;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 5 with FederationAdminException

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException in project ddf by codice.

the class RegistryRestEndpointTest method testPublishHelperException.

@Test
public void testPublishHelperException() throws Exception {
    doThrow(new FederationAdminException("error")).when(registryPublicationService).publish(REGISTRY_ID, DESTINATION_ID);
    Response response = restEndpoint.publish(REGISTRY_ID, DESTINATION_ID);
    verify(registryPublicationService).publish(REGISTRY_ID, DESTINATION_ID);
    assertThat(response.getStatusInfo().getStatusCode(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
}
Also used : Response(javax.ws.rs.core.Response) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) 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