use of ddf.catalog.content.operation.UpdateStorageRequest in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagUpdateStorageRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagUpdateStorageRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
UpdateStorageRequest request = new UpdateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
framework.update(request);
}
use of ddf.catalog.content.operation.UpdateStorageRequest in project ddf by codice.
the class RESTEndpoint method updateDocument.
/**
* REST Put. Updates the specified entry with the provided document.
*
* @param id
* @param message
* @return
*/
@PUT
@Path("/{id}")
@Consumes("multipart/*")
public Response updateDocument(@PathParam("id") String id, @Context HttpHeaders headers, @Context HttpServletRequest httpRequest, MultipartBody multipartBody, @QueryParam("transform") String transformerParam, InputStream message) {
LOGGER.trace("PUT");
Response response;
try {
if (id != null && message != null) {
MimeType mimeType = getMimeType(headers);
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");
}
}
if (createInfo == null) {
UpdateRequest updateRequest = new UpdateRequestImpl(id, generateMetacard(mimeType, id, message, transformerParam));
catalogFramework.update(updateRequest);
} else {
UpdateStorageRequest streamUpdateRequest = new UpdateStorageRequestImpl(Collections.singletonList(new IncomingContentItem(id, createInfo.getStream(), createInfo.getContentType(), createInfo.getFilename(), 0, createInfo.getMetacard())), null);
catalogFramework.update(streamUpdateRequest);
}
LOGGER.debug("Metacard {} updated.", id);
response = Response.ok().build();
} else {
String errorResponseString = "Both ID and content are needed to perform UPDATE.";
LOGGER.info(errorResponseString);
throw new ServerErrorException(errorResponseString, Status.BAD_REQUEST);
}
} catch (SourceUnavailableException e) {
String exceptionMessage = "Cannot update catalog entry: Source is unavailable: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (InternalIngestException e) {
String exceptionMessage = "Error cataloging updated metadata: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
} catch (MetacardCreationException | IngestException e) {
String exceptionMessage = "Error cataloging updated metadata: ";
LOGGER.info(exceptionMessage, e);
throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
}
return response;
}
use of ddf.catalog.content.operation.UpdateStorageRequest in project ddf by codice.
the class TestVideoThumbnailPlugin method testUpdatedItemGifThumbnail.
@Test
public void testUpdatedItemGifThumbnail() throws Exception {
setUpMockContentItem("/medium.mp4");
final UpdateStorageResponse mockUpdateResponse = mock(UpdateStorageResponse.class);
doReturn(Collections.singletonList(mockContentItem)).when(mockUpdateResponse).getUpdatedContentItems();
final UpdateStorageRequest mockUpdateRequest = mock(UpdateStorageRequest.class);
doReturn(mockUpdateRequest).when(mockUpdateResponse).getRequest();
doReturn(properties).when(mockUpdateResponse).getProperties();
final UpdateStorageResponse processedUpdateResponse = videoThumbnailPlugin.process(mockUpdateResponse);
final byte[] thumbnail = (byte[]) processedUpdateResponse.getUpdatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL).getValue();
assertThat(thumbnail, notNullValue());
verifyThumbnailIsGif(thumbnail);
}
use of ddf.catalog.content.operation.UpdateStorageRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateItemWithQualifier.
/**
* Tests that the framework properly passes an update request to the local provider when the
* content item has a qualifier.
*/
@Test
public void testUpdateItemWithQualifier() throws Exception {
// store one item
MetacardImpl metacard = new MetacardImpl();
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl contentItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, metacard);
CreateResponse response = framework.create(new CreateStorageRequestImpl(Collections.singletonList(contentItem), null));
Metacard createResponseMetacard = response.getCreatedMetacards().get(0);
// update with 2 more content items that have a qualifier and the same id and metacard as the already-created item
List<ContentItem> updateRequestContentItems = new ArrayList<>();
ByteSource q1ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("q1 data".getBytes());
}
};
ContentItem q1ContentItem = new ContentItemImpl(createResponseMetacard.getId(), "q1", q1ByteSource, "application/octet-stream", createResponseMetacard);
updateRequestContentItems.add(q1ContentItem);
ByteSource q2ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("q2 data".getBytes());
}
};
ContentItem q2ContentItem = new ContentItemImpl(createResponseMetacard.getId(), "q2", q2ByteSource, "application/octet-stream", createResponseMetacard);
updateRequestContentItems.add(q2ContentItem);
UpdateStorageRequest request = new UpdateStorageRequestImpl(updateRequestContentItems, null);
List<Result> mockFederationResults = Stream.of(createResponseMetacard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
assertThat(returnedCards, hasSize(1));
final Metacard updateResponseMetacard = returnedCards.get(0).getNewMetacard();
assertThat(updateResponseMetacard.getId(), notNullValue());
assertThat(updateResponseMetacard.getResourceURI().toString(), is(contentItem.getUri()));
assertThat(updateResponseMetacard.getResourceSize(), is(Long.toString(byteSource.size())));
assertThat(response.getCreatedMetacards(), hasSize(storageProvider.size()));
// make sure that the event was posted correctly
assertThat(eventAdmin.wasEventPosted(), is(true));
}
use of ddf.catalog.content.operation.UpdateStorageRequest in project ddf by codice.
the class HistorianTest method testNullContentItemStorageReadRequest.
@Test
public void testNullContentItemStorageReadRequest() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// Make content item null
storageProvider.storageMap.put(METACARD_ID, null);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that the content item DIDN't updated
ReadStorageRequest request = mock(ReadStorageRequest.class);
when(request.getResourceUri()).thenReturn(new URI(RESOURCE_URI));
ContentItem item = storageProvider.read(request).getContentItem();
assertThat(item, nullValue());
}
Aggregations