use of ddf.catalog.source.InternalIngestException in project ddf by codice.
the class UpdateOperations method doUpdate.
//
// Private helper methods
//
private UpdateResponse doUpdate(UpdateRequest updateRequest) throws IngestException, SourceUnavailableException {
updateRequest = queryOperations.setFlagsOnRequest(updateRequest);
updateRequest = validateUpdateRequest(updateRequest);
updateRequest = validateLocalSource(updateRequest);
try {
updateRequest = injectAttributes(updateRequest);
updateRequest = setDefaultValues(updateRequest);
updateRequest = populateMetacards(updateRequest);
updateRequest = processPreAuthorizationPlugins(updateRequest);
updateRequest = populateUpdateRequestPolicyMap(updateRequest);
updateRequest = processPreUpdateAccessPlugins(updateRequest);
updateRequest = processPreIngestPlugins(updateRequest);
updateRequest = validateUpdateRequest(updateRequest);
// Call the update on the catalog
LOGGER.debug("Calling catalog.update() with {} updates.", updateRequest.getUpdates().size());
UpdateResponse updateResponse = performLocalUpdate(updateRequest);
updateResponse = performRemoteUpdate(updateRequest, updateResponse);
// Handle the posting of messages to pubsub
updateResponse = validateFixUpdateResponse(updateResponse, updateRequest);
return updateResponse;
} catch (StopProcessingException see) {
throw new IngestException(PRE_INGEST_ERROR, see);
} catch (RuntimeException re) {
throw new InternalIngestException("Exception during runtime while performing update", re);
}
}
use of ddf.catalog.source.InternalIngestException in project ddf by codice.
the class RESTEndpoint method addDocument.
/**
* REST Post. Creates a new metadata entry in the catalog.
*
* @param message
* @return
*/
@POST
@Consumes("multipart/*")
public Response addDocument(@Context HttpHeaders headers, @Context UriInfo requestUriInfo, @Context HttpServletRequest httpRequest, MultipartBody multipartBody, @QueryParam("transform") String transformerParam, InputStream message) {
LOGGER.debug("POST");
Response response;
MimeType mimeType = getMimeType(headers);
try {
if (message != null) {
CreateInfo createInfo = null;
if (multipartBody != null) {
List<Attachment> contentParts = multipartBody.getAllAttachments();
if (contentParts != null && contentParts.size() > 0) {
createInfo = parseAttachments(contentParts, transformerParam);
} else {
LOGGER.debug("No file contents attachment found");
}
}
CreateResponse createResponse;
if (createInfo == null) {
CreateRequest createRequest = new CreateRequestImpl(generateMetacard(mimeType, null, message, transformerParam));
createResponse = catalogFramework.create(createRequest);
} else {
CreateStorageRequest streamCreateRequest = new CreateStorageRequestImpl(Collections.singletonList(new IncomingContentItem(uuidGenerator, createInfo.getStream(), createInfo.getContentType(), createInfo.getFilename(), createInfo.getMetacard())), null);
createResponse = catalogFramework.create(streamCreateRequest);
}
String id = createResponse.getCreatedMetacards().get(0).getId();
LOGGER.debug("Create Response id [{}]", id);
UriBuilder uriBuilder = requestUriInfo.getAbsolutePathBuilder().path("/" + id);
ResponseBuilder responseBuilder = Response.created(uriBuilder.build());
responseBuilder.header(Metacard.ID, id);
response = responseBuilder.build();
LOGGER.debug("Entry successfully saved, id: {}", id);
if (INGEST_LOGGER.isInfoEnabled()) {
INGEST_LOGGER.info("Entry successfully saved, id: {}", id);
}
} else {
String errorMessage = "No content found, cannot do CREATE.";
LOGGER.info(errorMessage);
throw new ServerErrorException(errorMessage, Status.BAD_REQUEST);
}
} catch (SourceUnavailableException e) {
String exceptionMessage = "Cannot create catalog entry because source is unavailable: ";
LOGGER.info(exceptionMessage, e);
// Catalog framework logs these exceptions to the ingest logger so we don't have to.
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (InternalIngestException e) {
String exceptionMessage = "Error while storing entry in catalog: ";
LOGGER.info(exceptionMessage, e);
// Catalog framework logs these exceptions to the ingest logger so we don't have to.
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (MetacardCreationException | IngestException e) {
String exceptionMessage = "Error while storing entry in catalog: ";
LOGGER.info(exceptionMessage, e);
// Catalog framework logs these exceptions to the ingest logger so we don't have to.
throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
} finally {
IOUtils.closeQuietly(message);
}
return response;
}
use of ddf.catalog.source.InternalIngestException 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.InternalIngestException in project ddf by codice.
the class CreateOperations method doCreate.
//
// Private helper methods
//
private CreateResponse doCreate(CreateRequest createRequest) throws IngestException, SourceUnavailableException {
CreateResponse createResponse = null;
Exception ingestError = null;
createRequest = queryOperations.setFlagsOnRequest(createRequest);
createRequest = validateCreateRequest(createRequest);
createRequest = validateLocalSource(createRequest);
try {
createRequest = injectAttributes(createRequest);
createRequest = setDefaultValues(createRequest);
createRequest = processPreAuthorizationPlugins(createRequest);
createRequest = updateCreateRequestPolicyMap(createRequest);
createRequest = processPrecreateAccessPlugins(createRequest);
createRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.CREATE, Collections.emptyList()));
createRequest = processPreIngestPlugins(createRequest);
createRequest = validateCreateRequest(createRequest);
createResponse = getCreateResponse(createRequest);
createResponse = performRemoteCreate(createRequest, createResponse);
} catch (IngestException iee) {
INGEST_LOGGER.debug("Ingest error", iee);
ingestError = iee;
throw iee;
} catch (StopProcessingException see) {
ingestError = see;
throw new IngestException(PRE_INGEST_ERROR, see);
} catch (RuntimeException re) {
ingestError = re;
throw new InternalIngestException("Exception during runtime while performing create", re);
} finally {
if (ingestError != null && INGEST_LOGGER.isInfoEnabled()) {
INGEST_LOGGER.info("Error on create operation. {} metacards failed to ingest. {}", createRequest.getMetacards().size(), buildIngestLog(createRequest), ingestError);
}
}
try {
createResponse = validateFixCreateResponse(createResponse, createRequest);
} catch (RuntimeException re) {
LOGGER.info("Exception during runtime while performing doing post create operations (plugins and pubsub)", re);
}
return createResponse;
}
use of ddf.catalog.source.InternalIngestException in project ddf by codice.
the class DeleteOperations method performLocalDelete.
private DeleteResponse performLocalDelete(DeleteRequest deleteRequest, DeleteStorageRequest deleteStorageRequest) throws IngestException {
if (!Requests.isLocal(deleteRequest)) {
return null;
}
try {
sourceOperations.getStorage().delete(deleteStorageRequest);
} catch (StorageException e) {
LOGGER.info("Unable to delete stored content items. Not removing stored metacards", e);
throw new InternalIngestException("Unable to delete stored content items. Not removing stored metacards.", e);
}
DeleteResponse deleteResponse = sourceOperations.getCatalog().delete(deleteRequest);
deleteResponse = injectAttributes(deleteResponse);
try {
historian.version(deleteResponse);
} catch (SourceUnavailableException e) {
LOGGER.debug("Could not version deleted item!", e);
throw new IngestException("Could not version deleted Item!");
}
return deleteResponse;
}
Aggregations