Search in sources :

Example 36 with UpdateRequestImpl

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));
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) BigInteger(java.math.BigInteger) ResultImpl(ddf.catalog.data.impl.ResultImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 37 with UpdateRequestImpl

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();
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 38 with UpdateRequestImpl

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();
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) PUT(javax.ws.rs.PUT)

Example 39 with UpdateRequestImpl

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())));
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogFramework(ddf.catalog.CatalogFramework) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) SortBy(org.opengis.filter.sort.SortBy) EndpointUtil(org.codice.ddf.catalog.ui.util.EndpointUtil) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) Result(ddf.catalog.data.Result) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) QueryImpl(ddf.catalog.operation.impl.QueryImpl) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) IngestException(ddf.catalog.source.IngestException) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Set(java.util.Set) FederationException(ddf.catalog.federation.FederationException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Stream(java.util.stream.Stream) Attribute(ddf.catalog.data.Attribute) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Metacard(ddf.catalog.data.Metacard) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)39 Metacard (ddf.catalog.data.Metacard)30 ArrayList (java.util.ArrayList)24 UpdateRequest (ddf.catalog.operation.UpdateRequest)22 Test (org.junit.Test)21 HashMap (java.util.HashMap)19 Serializable (java.io.Serializable)17 UpdateResponse (ddf.catalog.operation.UpdateResponse)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)13 CatalogFramework (ddf.catalog.CatalogFramework)11 IngestException (ddf.catalog.source.IngestException)11 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)10 List (java.util.List)10 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)9 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)9 Entry (java.util.Map.Entry)9 QueryResponse (ddf.catalog.operation.QueryResponse)8 Update (ddf.catalog.operation.Update)8 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)8 URI (java.net.URI)8