use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdate.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdate() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
// create the entry manually in the provider
CreateResponse response = provider.create(new CreateRequestImpl(metacards, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
Result mockFederationResult = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId(insertedCard.getId());
when(mockFederationResult.getMetacard()).thenReturn(metacard);
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), Collections.singletonList(mockFederationResult), 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
List<Entry<Serializable, Metacard>> updatedEntries = new ArrayList<Entry<Serializable, Metacard>>();
updatedEntries.add(new SimpleEntry<Serializable, Metacard>(insertedCard.getId(), insertedCard));
UpdateRequest request = new UpdateRequestImpl(updatedEntries, Metacard.ID, null);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
for (Update curCard : returnedCards) {
assertNotNull(curCard.getNewMetacard().getId());
}
// make sure that the event was posted correctly
assertTrue(eventAdmin.wasEventPosted());
assertEquals(eventAdmin.getLastEvent().getId(), returnedCards.get(returnedCards.size() - 1).getOldMetacard().getId());
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByID.
/**
* Tests that the framework properly throws a catalog exception when the local provider is not
* available for update by id.
*
* @throws IngestException
* @throws SourceUnavailableException
*/
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByID() throws SourceUnavailableException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
List<Metacard> metacards = new ArrayList<Metacard>();
List<URI> uris = new ArrayList<URI>();
// expected to throw exception due to catalog provider being unavailable
try {
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("uri:///1234"));
metacards.add(newCard);
uris.add(new URI("uri:///1234"));
UpdateRequest update = new UpdateRequestImpl((URI[]) uris.toArray(new URI[uris.size()]), metacards);
framework.update(update);
} catch (URISyntaxException e) {
fail();
} catch (IngestException e) {
fail();
}
}
use of ddf.catalog.operation.impl.UpdateRequestImpl 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.operation.impl.UpdateRequestImpl in project ddf by codice.
the class PointOfContactUpdatePluginTest method setup.
@Before
public void setup() throws Exception {
listOfUpdatedMetacards = getListOfUpdatedMetacards();
updateRequestInput = new UpdateRequestImpl(new String[] { RESOURCE_ID1, RESOURCE_ID2, REGISTRY_ID }, listOfUpdatedMetacards);
existingMetacards = getPreviousMetacardsWithPointOfContact();
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class TestRegistryStore method testUpdate.
@Test
public void testUpdate() throws Exception {
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
TransactionSummaryType tst = new TransactionSummaryType();
tst.setTotalUpdated(new BigInteger("1"));
when(responseType.getTransactionSummary()).thenReturn(tst);
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
UpdateRequestImpl request = new UpdateRequestImpl("testId", getDefaultMetacard());
MetacardImpl updatedMcard = getDefaultMetacard();
updatedMcard.setId("newTestId");
OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Collections.singletonList(updatedMcard));
request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
queryResults.add(new ResultImpl(getDefaultMetacard()));
registryStore.update(request);
assertThat(request.getUpdates().get(0).getValue().getMetadata().contains("value=\"newTestId\""), is(true));
}
Aggregations