use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class RESTEndpoint method deleteDocument.
/**
* REST Delete. Deletes a record from the catalog.
*
* @param id
* @return
*/
@DELETE
@Path("/{id}")
public Response deleteDocument(@PathParam("id") String id, @Context HttpServletRequest httpRequest) {
LOGGER.debug("DELETE");
Response response;
try {
if (id != null) {
DeleteRequestImpl deleteReq = new DeleteRequestImpl(id);
catalogFramework.delete(deleteReq);
response = Response.ok(id).build();
LOGGER.debug("Attempting to delete Metacard with id: {}", id);
} else {
String errorMessage = "ID of entry not specified, cannot do DELETE.";
LOGGER.info(errorMessage);
throw new ServerErrorException(errorMessage, Status.BAD_REQUEST);
}
} catch (SourceUnavailableException ce) {
String exceptionMessage = "Could not delete entry from catalog since the source is unavailable: ";
LOGGER.info(exceptionMessage, ce);
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (InternalIngestException e) {
String exceptionMessage = "Error deleting entry from catalog: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (IngestException e) {
String exceptionMessage = "Error deleting entry from catalog: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
}
return response;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class RESTEndpoint method getHeaders.
/**
* REST Head. Returns headers only. Primarily used to let the client know that range requests (though limited)
* are accepted.
*
* @param sourceid
* @param id
* @param uriInfo
* @param httpRequest
* @return
*/
@HEAD
@Path("/sources/{sourceid}/{id}")
public Response getHeaders(@PathParam("sourceid") String sourceid, @PathParam("id") String id, @Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
Response response;
Response.ResponseBuilder responseBuilder;
QueryResponse queryResponse;
Metacard card = null;
LOGGER.trace("getHeaders");
URI absolutePath = uriInfo.getAbsolutePath();
MultivaluedMap<String, String> map = uriInfo.getQueryParameters();
if (id != null) {
LOGGER.debug("Got id: {}", id);
LOGGER.debug("Map of query parameters: \n{}", map.toString());
Map<String, Serializable> convertedMap = convert(map);
convertedMap.put("url", absolutePath.toString());
LOGGER.debug("Map converted, retrieving product.");
// default to xml if no transformer specified
try {
String transformer = DEFAULT_METACARD_TRANSFORMER;
Filter filter = getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id);
Collection<String> sources = null;
if (sourceid != null) {
sources = new ArrayList<String>();
sources.add(sourceid);
}
QueryRequestImpl request = new QueryRequestImpl(new QueryImpl(filter), sources);
request.setProperties(convertedMap);
queryResponse = catalogFramework.query(request, null);
// pull the metacard out of the blocking queue
List<Result> results = queryResponse.getResults();
// return null if timeout elapsed)
if (results != null && !results.isEmpty()) {
card = results.get(0).getMetacard();
}
if (card == null) {
throw new ServerErrorException("Unable to retrieve requested metacard.", Status.NOT_FOUND);
}
LOGGER.debug("Calling transform.");
final BinaryContent content = catalogFramework.transform(card, transformer, convertedMap);
LOGGER.debug("Read and transform complete, preparing response.");
responseBuilder = Response.noContent();
// Add the Accept-ranges header to let the client know that we accept ranges in bytes
responseBuilder.header(HEADER_ACCEPT_RANGES, BYTES);
String filename = null;
if (content instanceof Resource) {
// If we got a resource, we can extract the filename.
filename = ((Resource) content).getName();
} else {
String fileExtension = getFileExtensionForMimeType(content.getMimeTypeValue());
if (StringUtils.isNotBlank(fileExtension)) {
filename = id + fileExtension;
}
}
if (StringUtils.isNotBlank(filename)) {
LOGGER.debug("filename: {}", filename);
responseBuilder.header(HEADER_CONTENT_DISPOSITION, "inline; filename=\"" + filename + "\"");
}
long size = content.getSize();
if (size > 0) {
responseBuilder.header(HEADER_CONTENT_LENGTH, size);
}
response = responseBuilder.build();
} catch (FederationException e) {
String exceptionMessage = "READ failed due to unexpected exception: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (CatalogTransformerException e) {
String exceptionMessage = "Unable to transform Metacard. Try different transformer: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (SourceUnavailableException e) {
String exceptionMessage = "Cannot obtain query results because source is unavailable: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (UnsupportedQueryException e) {
String exceptionMessage = "Specified query is unsupported. Change query and resubmit: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
// The catalog framework will throw this if any of the transformers blow up. We need to
// catch this exception
// here or else execution will return to CXF and we'll lose this message and end up with
// a huge stack trace
// in a GUI or whatever else is connected to this endpoint
} catch (IllegalArgumentException e) {
throw new ServerErrorException(e, Status.BAD_REQUEST);
}
} else {
throw new ServerErrorException("No ID specified.", Status.BAD_REQUEST);
}
return response;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class InMemoryProcessingFramework method storeMetacardUpdates.
private void storeMetacardUpdates(Map<String, Metacard> metacardsToUpdate, Map<String, Serializable> properties) {
if (MapUtils.isNotEmpty(metacardsToUpdate)) {
LOGGER.trace("Storing metacard updates");
List<Map.Entry<Serializable, Metacard>> updateList = metacardsToUpdate.values().stream().map(metacard -> new AbstractMap.SimpleEntry<Serializable, Metacard>(metacard.getId(), metacard)).collect(Collectors.toList());
UpdateRequest updateMetacardsRequest = new UpdateRequestImpl(updateList, UpdateRequest.UPDATE_BY_ID, properties);
Subject subject = (Subject) updateMetacardsRequest.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
if (subject == null) {
LOGGER.debug("No subject to send UpdateRequest. Updates will not be sent back to the catalog.");
} else {
subject.execute(() -> {
try {
catalogFramework.update(updateMetacardsRequest);
LOGGER.debug("Successfully completed update metacards request");
} catch (IngestException | SourceUnavailableException | RuntimeException e) {
LOGGER.info("Unable to complete update request", e);
}
return null;
});
}
} else {
LOGGER.debug("No metacards to update");
}
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class InMemoryProcessingFramework method storeContentItemUpdates.
private void storeContentItemUpdates(Map<String, ContentItem> contentItemsToUpdate, Map<String, Serializable> properties) {
if (MapUtils.isNotEmpty(contentItemsToUpdate)) {
LOGGER.trace("Storing content item updates(s)");
UpdateStorageRequest updateStorageRequest = new UpdateStorageRequestImpl(new ArrayList<>(contentItemsToUpdate.values()), properties);
Subject subject = (Subject) updateStorageRequest.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
if (subject == null) {
LOGGER.debug("No subject to send UpdateStorageRequest. Updates will not be sent back to the catalog");
} else {
subject.execute(() -> {
try {
catalogFramework.update(updateStorageRequest);
LOGGER.debug("Successfully completed update storage request");
} catch (IngestException | SourceUnavailableException | RuntimeException e) {
LOGGER.info("Unable to complete update storage request", e);
}
return null;
});
}
} else {
LOGGER.debug("No content items to update");
}
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class ExceptionsTest method testSourceUnavailableException.
@Test
public void testSourceUnavailableException() {
SourceUnavailableException sue = new SourceUnavailableException();
assertNotNull(sue);
sue = new SourceUnavailableException(msg);
assertEquals(sue.getMessage(), msg);
sue = new SourceUnavailableException(testCause);
assertEquals(sue.getCause(), testCause);
sue = new SourceUnavailableException(msg, testCause);
assertEquals(sue.getMessage(), msg);
assertEquals(sue.getCause(), testCause);
}
Aggregations