Search in sources :

Example 21 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 22 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)

Example 23 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(String base64EncodedXmlData) throws FederationAdminException {
    if (StringUtils.isBlank(base64EncodedXmlData)) {
        throw new FederationAdminException("Error creating local entry. String provided was blank.");
    }
    String metacardId;
    try (InputStream xmlStream = new ByteArrayInputStream(Base64.getDecoder().decode(base64EncodedXmlData))) {
        Metacard metacard = getRegistryMetacardFromInputStream(xmlStream);
        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE, true));
        metacardId = federationAdminService.addRegistryEntry(metacard);
    } catch (IOException | IllegalArgumentException e) {
        throw new FederationAdminException("Error creating local entry. Couldn't decode string.", e);
    }
    return metacardId;
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) IOException(java.io.IOException)

Example 24 with FederationAdminException

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

the class FederationAdmin method updateLocalEntry.

@Override
public void updateLocalEntry(Map<String, Object> registryObjectMap) throws FederationAdminException {
    Optional<RegistryPackageType> registryPackageOptional = registryTypeConverter.convert(registryObjectMap);
    RegistryPackageType registryPackage = registryPackageOptional.orElseThrow(() -> new FederationAdminException("Error updating local registry entry. Couldn't convert registry map to a registry package."));
    updateDateFields(registryPackage);
    List<Metacard> existingMetacards = federationAdminService.getLocalRegistryMetacardsByRegistryIds(Collections.singletonList(registryPackage.getId()));
    if (CollectionUtils.isEmpty(existingMetacards)) {
        String message = "Error updating local registry entry. Registry metacard not found.";
        LOGGER.debug("{} Registry ID: {}", message, registryPackage.getId());
        throw new FederationAdminException(message);
    }
    if (existingMetacards.size() > 1) {
        throw new FederationAdminException("Error updating local registry entry. Multiple registry metacards found.");
    }
    Metacard existingMetacard = existingMetacards.get(0);
    Metacard updateMetacard = getRegistryMetacardFromRegistryPackage(registryPackage);
    updateMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacard.getId()));
    federationAdminService.updateRegistryEntry(updateMetacard);
}
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 25 with FederationAdminException

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

the class RegistryRestEndpoint method viewSummaryInfoHtml.

@Path("/{registryId}/report/summary")
@Produces(MediaType.TEXT_HTML)
@GET
public Response viewSummaryInfoHtml(@PathParam("registryId") final String registryId) {
    String html = "";
    Metacard metacard;
    if (StringUtils.isBlank(registryId)) {
        String message = "Registry ID cannot be blank";
        return Response.status(Response.Status.BAD_REQUEST).entity(getErrorHtmlString(message)).build();
    }
    try {
        List<Metacard> metacardList = federationAdminService.getRegistryMetacardsByRegistryIds((Collections.singletonList(registryId)));
        if (CollectionUtils.isNotEmpty(metacardList)) {
            metacard = metacardList.get(0);
        } else {
            String message = "Could not retrieve Metacard";
            LOGGER.debug("{} For registry id: '{}'", message, registryId);
            return Response.status(Response.Status.NOT_FOUND).entity(getErrorHtmlString(message)).build();
        }
    } catch (FederationAdminException e) {
        String message = "Error getting Metacard.";
        LOGGER.debug("{} For registry id: '{}'", message, registryId);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(getErrorHtmlString(message)).build();
    }
    try {
        html = registryReportBuilder.getSummaryHtmlFromMetacard(metacard);
    } catch (IOException e) {
        String message = "Error in compiling and applying summary template.";
        LOGGER.debug("{} For registry id: '{}'", message, registryId);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(getErrorHtmlString(message)).build();
    }
    return Response.ok(html).build();
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) Metacard(ddf.catalog.data.Metacard) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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