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));
}
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;
}
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);
}
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();
}
Aggregations