use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class TestPlugin method testUpdate.
@Test
@Ignore
public void testUpdate() throws PluginExecutionException, IngestException, SourceUnavailableException {
// given
UpdateResponse updateResponse = new UpdateResponseImpl(new UpdateRequestImpl("23", metacard), null, Arrays.asList(metacard), Arrays.asList(metacard));
// when
UpdateResponse response = plugin.process(updateResponse);
// then
verify(endpoint).updateDocument(argThat(is("23")), isA(HttpHeaders.class), isA(InputStream.class));
assertThat(response, sameInstance(updateResponse));
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateWithStores.
// TODO (DDF-2436) -
@Ignore
@Test
public void testUpdateWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
Map<String, CatalogStore> storeMap = new HashMap<>();
Map<String, FederatedSource> sourceMap = new HashMap<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeMap.put(store.getId(), store);
sourceMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
List<Metacard> metacards = new ArrayList<>();
String id = UUID.randomUUID().toString();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(id);
newCard.setAttribute("myKey", "myValue1");
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
destinations.add("mockMemoryProvider");
destinations.add("catalogStoreId-1");
framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
MetacardImpl updateCard = new MetacardImpl();
updateCard.setId(id);
updateCard.setAttribute("myKey", "myValue2");
List<Entry<Serializable, Metacard>> updates = new ArrayList<>();
updates.add(new SimpleEntry<>(id, updateCard));
destinations.remove("mockMemoryProvider");
framework.update(new UpdateRequestImpl(updates, Metacard.ID, new HashMap<>(), destinations));
assertThat(provider.hasReceivedUpdateByIdentifier(), is(false));
assertThat(store.hasReceivedUpdateByIdentifier(), is(true));
QueryResponse storeResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
assertThat(storeResponse.getResults().size(), is(1));
assertThat(storeResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue2"));
destinations.clear();
QueryResponse providerResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
assertThat(providerResponse.getResults().size(), is(1));
assertThat(providerResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue1"));
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateByIdentifier.
/**
* Tests that the framework properly passes an update by identifier request to the local
* provider.
*/
@Test
public void testUpdateByIdentifier() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("DDF:///12345"));
metacards.add(newCard);
// create the entry manually in the provider
List<Metacard> insertedCards = provider.create(new CreateRequestImpl(metacards)).getCreatedMetacards();
ArrayList<URI> list = new ArrayList<URI>();
list.add(new URI("DDF:///12345"));
UpdateRequest request = new UpdateRequestImpl((URI[]) list.toArray(new URI[list.size()]), insertedCards);
List<Result> mockFederationResults = metacards.stream().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
UpdateResponse updateResponse = framework.update(request);
List<Update> returnedCards = updateResponse.getUpdatedMetacards();
assertNotNull(returnedCards);
assertEquals(list.size(), returnedCards.size());
assertTrue(provider.hasReceivedUpdateByIdentifier());
// 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 WorkspacePreIngestPluginTest method update.
private static UpdateRequest update(Metacard original, Metacard updated) {
UpdateRequestImpl request = new UpdateRequestImpl(original.getId(), updated);
OperationTransaction transaction = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Arrays.asList(original));
request.setProperties(Collections.singletonMap(Constants.OPERATION_TRANSACTION_KEY, transaction));
return request;
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class MetacardEditEndpoint method deleteAttribute.
@DELETE
@Path("/{id}/{attribute}")
public Response deleteAttribute(@Context HttpServletResponse response, @PathParam("id") String id, @PathParam("attribute") String attribute, String value) throws Exception {
Metacard metacard = endpointUtil.getMetacard(id);
Attribute metacardAttribute = metacard.getAttribute(attribute);
if (metacardAttribute == null) {
return Response.ok().build();
}
metacard.setAttribute(new AttributeImpl(attribute, (Serializable) null));
catalogFramework.update(new UpdateRequestImpl(id, metacard));
return Response.ok().build();
}
Aggregations