Search in sources :

Example 21 with UpdateRequestImpl

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());
}
Also used : Serializable(java.io.Serializable) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 22 with UpdateRequestImpl

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();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 23 with UpdateRequestImpl

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;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) MetacardCreationException(ddf.catalog.data.MetacardCreationException) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) InternalIngestException(ddf.catalog.source.InternalIngestException) UpdateRequest(ddf.catalog.operation.UpdateRequest) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) MimeType(javax.activation.MimeType) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) IngestException(ddf.catalog.source.IngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 24 with UpdateRequestImpl

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();
}
Also used : UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Before(org.junit.Before)

Example 25 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)

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