Search in sources :

Example 11 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class MetacardValidityMarkerPluginTest method testMetacardFailsEnforcedValidatorNoDescribable.

@Test
public void testMetacardFailsEnforcedValidatorNoDescribable() throws ValidationException, StopProcessingException, PluginExecutionException {
    MetacardValidator mockValidator = getMockFailingValidatorNoDescribable();
    metacardValidators.add(mockValidator);
    enforcedMetacardValidators.add(mockValidator.getClass().getCanonicalName());
    CreateRequest createRequest = getMockCreateRequest();
    List<Metacard> createdMetacards = createRequest.getMetacards();
    verifyEnforcedCreate(createRequest, createdMetacards.subList(1, createdMetacards.size()));
    UpdateRequest updateRequest = getMockUpdateRequest();
    List<Metacard> updatedMetacards = getUpdatedMetacards(updateRequest);
    verifyEnforcedUpdate(updateRequest, updatedMetacards.subList(1, updatedMetacards.size()));
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardValidator(ddf.catalog.validation.MetacardValidator) UpdateRequest(ddf.catalog.operation.UpdateRequest) CreateRequest(ddf.catalog.operation.CreateRequest) Test(org.junit.Test)

Example 12 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class RegistryStoreImpl method update.

@Override
public UpdateResponse update(UpdateRequest request) throws IngestException {
    if (request.getUpdates().stream().map(e -> RegistryUtility.getRegistryId(e.getValue())).anyMatch(Objects::isNull)) {
        throw new IngestException("One or more of the metacards is not a registry metacard");
    }
    Map<String, Metacard> updatedMetacards = request.getUpdates().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getValue()), Map.Entry::getValue));
    Map<String, Metacard> origMetacards = ((OperationTransaction) request.getPropertyValue(Constants.OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards().stream().collect(Collectors.toMap(RegistryUtility::getRegistryId, e -> e));
    //update the new metacards with the id from the orig so that they can be found on the remote system
    try {
        for (Map.Entry<String, Metacard> entry : updatedMetacards.entrySet()) {
            setMetacardExtID(entry.getValue(), origMetacards.get(entry.getKey()).getId());
        }
    } catch (ParserException e) {
        throw new IngestException("Could not update metacards id", e);
    }
    return super.update(request);
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) Locale(java.util.Locale) Map(java.util.Map) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) Converter(com.thoughtworks.xstream.converters.Converter) ImmutableSet(com.google.common.collect.ImmutableSet) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SourceMonitor(ddf.catalog.source.SourceMonitor) ParserException(org.codice.ddf.parser.ParserException) AbstractCswStore(org.codice.ddf.spatial.ogc.csw.catalog.common.source.AbstractCswStore) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Serializable(java.io.Serializable) Objects(java.util.Objects) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) DeleteRequest(ddf.catalog.operation.DeleteRequest) List(java.util.List) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UpdateResponse(ddf.catalog.operation.UpdateResponse) Dictionary(java.util.Dictionary) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) HashMap(java.util.HashMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) OperationTransaction(ddf.catalog.operation.OperationTransaction) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) ArrayList(java.util.ArrayList) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Configuration(org.osgi.service.cm.Configuration) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) SecurityConstants(ddf.security.SecurityConstants) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) EncryptionService(ddf.security.encryption.EncryptionService) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) Result(ddf.catalog.data.Result) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) IngestException(ddf.catalog.source.IngestException) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) IOException(java.io.IOException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) MetaTypeService(org.osgi.service.metatype.MetaTypeService) Consumer(java.util.function.Consumer) Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) OperationTransaction(ddf.catalog.operation.OperationTransaction) ParserException(org.codice.ddf.parser.ParserException) Metacard(ddf.catalog.data.Metacard) Objects(java.util.Objects) IngestException(ddf.catalog.source.IngestException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class PointOfContactUpdatePluginTest method processPreUpdateDoesNothingIfNewPOCHasAValue.

@Test
public void processPreUpdateDoesNothingIfNewPOCHasAValue() throws Exception {
    listOfUpdatedMetacards.forEach(m -> m.setAttribute(new AttributeImpl(Metacard.POINT_OF_CONTACT, NEW_EMAIL)));
    UpdateRequest updateRequestOutput = pointOfContactUpdatePlugin.processPreUpdate(updateRequestInput, existingMetacards);
    assertThat(updateRequestOutput.getUpdates().get(0).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
    assertThat(updateRequestOutput.getUpdates().get(1).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
    assertThat(updateRequestOutput.getUpdates().get(2).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(NEW_EMAIL));
}
Also used : UpdateRequest(ddf.catalog.operation.UpdateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Test(org.junit.Test)

Example 14 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class PointOfContactUpdatePluginTest method processPreUpdateOnlyModifiesResourceMetacards.

@Test
public void processPreUpdateOnlyModifiesResourceMetacards() throws Exception {
    UpdateRequest updateRequestOutput = pointOfContactUpdatePlugin.processPreUpdate(updateRequestInput, existingMetacards);
    assertThat(updateRequestOutput.getUpdates().get(0).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(ADMIN_EMAIL));
    assertThat(updateRequestOutput.getUpdates().get(1).getValue().getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(ADMIN_EMAIL));
    assertThat(updateRequestOutput.getUpdates().get(2).getValue().getAttribute(Metacard.POINT_OF_CONTACT), is(nullValue()));
}
Also used : UpdateRequest(ddf.catalog.operation.UpdateRequest) Test(org.junit.Test)

Example 15 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class MetacardIngestNetworkPluginTest method testPassthroughMethods.

@Test
public void testPassthroughMethods() throws Exception {
    ThreadContext.put(CLIENT_INFO_KEY, INFO_MAP);
    when(mockMetacardCondition.applies(INFO_MAP)).thenReturn(true);
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    QueryRequest queryRequest = mock(QueryRequest.class);
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    QueryResponse queryResponse = mock(QueryResponse.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    assertThat(plugin.processPreUpdate(updateRequest, mock(Map.class)), is(updateRequest));
    assertThat(plugin.processPreDelete(deleteRequest), is(deleteRequest));
    assertThat(plugin.processPreQuery(queryRequest), is(queryRequest));
    assertThat(plugin.processPreResource(resourceRequest), is(resourceRequest));
    assertThat(plugin.processPostDelete(deleteResponse), is(deleteResponse));
    assertThat(plugin.processPostQuery(queryResponse), is(queryResponse));
    assertThat(plugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
    verifyZeroInteractions(mockMetacardCondition, mockMetacardServices, updateRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) ResourceResponse(ddf.catalog.operation.ResourceResponse) UpdateRequest(ddf.catalog.operation.UpdateRequest) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceRequest(ddf.catalog.operation.ResourceRequest) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Aggregations

UpdateRequest (ddf.catalog.operation.UpdateRequest)61 Test (org.junit.Test)44 Metacard (ddf.catalog.data.Metacard)41 ArrayList (java.util.ArrayList)32 Serializable (java.io.Serializable)25 UpdateResponse (ddf.catalog.operation.UpdateResponse)23 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)23 HashMap (java.util.HashMap)21 Update (ddf.catalog.operation.Update)17 List (java.util.List)16 Entry (java.util.Map.Entry)16 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 Map (java.util.Map)12 SimpleEntry (java.util.AbstractMap.SimpleEntry)11 IngestException (ddf.catalog.source.IngestException)10 URI (java.net.URI)10 Result (ddf.catalog.data.Result)9 CreateRequest (ddf.catalog.operation.CreateRequest)9 CatalogFramework (ddf.catalog.CatalogFramework)8 CreateResponse (ddf.catalog.operation.CreateResponse)8