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));
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class MetacardEditEndpoint method setAttribute.
@PUT
@Path("/{id}/{attribute}")
@Consumes(MediaType.TEXT_PLAIN)
public Response setAttribute(@Context HttpServletResponse response, @PathParam("id") String id, @PathParam("attribute") String attribute, String value) throws Exception {
Metacard metacard = endpointUtil.getMetacard(id);
if (metacard == null) {
return Response.status(404).build();
}
Attribute metacardAttribute = metacard.getAttribute(attribute);
Optional<AttributeDescriptor> attributeDescriptor = attributeRegistry.lookup(attribute);
if (!attributeDescriptor.isPresent()) {
/* Could not find attribute descriptor for requested attribute */
return Response.status(404).build();
}
AttributeDescriptor descriptor = attributeDescriptor.get();
if (descriptor.isMultiValued()) {
if (metacardAttribute == null || metacardAttribute.getValues() == null) {
metacard.setAttribute(new AttributeImpl(attribute, Collections.singletonList(value)));
} else {
List<Serializable> values = new ArrayList<>(metacardAttribute.getValues());
if (!values.contains(value)) {
values.add(value);
}
metacard.setAttribute(new AttributeImpl(attribute, values));
}
} else {
// not multivalued
metacard.setAttribute(new AttributeImpl(attribute, value));
}
catalogFramework.update(new UpdateRequestImpl(id, metacard));
Map<String, Object> responseMap = getResponseMap(attribute, metacard.getAttribute(attribute), descriptor);
return Response.ok(endpointUtil.getJson(responseMap), MediaType.APPLICATION_JSON).build();
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class MetacardEditEndpoint method setBinaryAttribute.
@SuppressFBWarnings
@PUT
@Path("/{id}/{attribute}")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response setBinaryAttribute(@Context HttpServletResponse response, @PathParam("id") String id, @PathParam("attribute") String attribute, byte[] value) throws Exception {
Metacard metacard = endpointUtil.getMetacard(id);
if (metacard == null) {
return Response.status(404).build();
}
Attribute metacardAttribute = metacard.getAttribute(attribute);
Optional<AttributeDescriptor> attributeDescriptor = attributeRegistry.lookup(attribute);
if (!attributeDescriptor.isPresent()) {
/* Could not find attribute descriptor for requested attribute */
response.setStatus(404);
return Response.status(404).build();
}
AttributeDescriptor descriptor = attributeDescriptor.get();
if (!descriptor.getType().getAttributeFormat().equals(AttributeType.AttributeFormat.BINARY)) {
return Response.status(400).build();
}
if (descriptor.isMultiValued()) {
List<Serializable> values;
if (metacardAttribute == null) {
values = new ArrayList<>();
} else {
values = metacardAttribute.getValues();
}
if (!values.contains(value)) {
values.add(value);
}
metacard.setAttribute(new AttributeImpl(attribute, values));
} else {
metacard.setAttribute(new AttributeImpl(attribute, value));
}
catalogFramework.update(new UpdateRequestImpl(id, metacard));
Map<String, Object> responseMap = getResponseMap(attribute, metacard.getAttribute(attribute), descriptor);
return Response.ok(endpointUtil.getJson(response), MediaType.APPLICATION_JSON).build();
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class Associated method putAssociations.
public void putAssociations(String id, Collection<Edge> edges) throws UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
Collection<Edge> oldEdges = getAssociations(id);
List<String> ids = Stream.concat(oldEdges.stream(), edges.stream()).flatMap(e -> Stream.of(e.child, e.parent)).filter(Objects::nonNull).map(m -> m.get(Metacard.ID)).filter(Objects::nonNull).map(Object::toString).distinct().collect(Collectors.toList());
Map<String, Metacard> metacards = util.getMetacards(ids, getNonrestrictedTagsFilter()).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getMetacard()));
Map<String, Metacard> changedMetacards = new HashMap<>();
Set<Edge> oldEdgeSet = new HashSet<>(oldEdges);
Set<Edge> newEdgeSet = new HashSet<>(edges);
Set<Edge> oldDiff = Sets.difference(oldEdgeSet, newEdgeSet);
Set<Edge> newDiff = Sets.difference(newEdgeSet, oldEdgeSet);
for (Edge edge : oldDiff) {
removeEdge(edge, metacards, changedMetacards);
}
for (Edge edge : newDiff) {
addEdge(edge, metacards, changedMetacards);
}
if (changedMetacards.isEmpty()) {
return;
}
catalogFramework.update(new UpdateRequestImpl(changedMetacards.keySet().toArray(new String[0]), new ArrayList<>(changedMetacards.values())));
}
Aggregations