Search in sources :

Example 16 with CreateRequest

use of ddf.catalog.operation.CreateRequest 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 17 with CreateRequest

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

the class RegistryStoreImpl method create.

@Override
public CreateResponse create(CreateRequest request) throws IngestException {
    if (request.getMetacards().stream().map(RegistryUtility::getRegistryId).anyMatch(Objects::isNull)) {
        throw new IngestException("One or more of the metacards is not a registry metacard");
    }
    validateOperation();
    List<Filter> regIdFilters = request.getMetacards().stream().map(e -> filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(e.getId())).collect(Collectors.toList());
    Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
    Map<String, Serializable> queryProps = new HashMap<>();
    queryProps.put(SecurityConstants.SECURITY_SUBJECT, request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT));
    QueryImpl query = new QueryImpl(filterBuilder.allOf(tagFilter, filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE).empty(), filterBuilder.anyOf(regIdFilters)));
    QueryRequest queryRequest = new QueryRequestImpl(query, queryProps);
    try {
        SourceResponse queryResponse = super.query(queryRequest);
        Map<String, Metacard> responseMap = queryResponse.getResults().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getMetacard()), Result::getMetacard));
        List<Metacard> metacardsToCreate = request.getMetacards().stream().filter(e -> !responseMap.containsKey(RegistryUtility.getRegistryId(e))).collect(Collectors.toList());
        List<Metacard> allMetacards = new ArrayList<>(responseMap.values());
        if (CollectionUtils.isNotEmpty(metacardsToCreate)) {
            CreateResponse createResponse = super.create(new CreateRequestImpl(metacardsToCreate, request.getProperties()));
            allMetacards.addAll(createResponse.getCreatedMetacards());
        }
        return new CreateResponseImpl(request, request.getProperties(), allMetacards);
    } catch (UnsupportedQueryException e) {
        LOGGER.warn("Unable to perform pre-create remote query. Proceeding with original query. Error was {}", e.getMessage());
    }
    return super.create(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) Serializable(java.io.Serializable) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Objects(java.util.Objects) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 18 with CreateRequest

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

the class IdentificationPluginTest method testBothExtIdMissing.

//test ext IDs are not set (origin & local)
@Test
public void testBothExtIdMissing() throws Exception {
    //unmarshal metacard.metadata and confirm both origin and local ext id are set to metacard.getId()
    String xml = convert("/registry-no-extid.xml");
    sampleData.setAttribute(Metacard.METADATA, xml);
    CreateRequest result = identificationPlugin.process(new CreateRequestImpl(sampleData));
    Metacard testMetacard = result.getMetacards().get(0);
    String metadata = testMetacard.getMetadata();
    InputStream inputStream = new ByteArrayInputStream(metadata.getBytes(Charsets.UTF_8));
    JAXBElement<RegistryObjectType> registryObjectTypeJAXBElement = parser.unmarshal(configurator, JAXBElement.class, inputStream);
    RegistryObjectType registryObjectType = registryObjectTypeJAXBElement.getValue();
    List<ExternalIdentifierType> extIdList = registryObjectType.getExternalIdentifier();
    for (ExternalIdentifierType singleExtId : extIdList) {
        if (singleExtId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_LOCAL)) {
            assertThat(singleExtId.getValue(), is(testMetacard.getId()));
        } else if (singleExtId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN)) {
            assertThat(singleExtId.getId(), is(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN));
            assertThat(singleExtId.getValue(), is(testMetacard.getId()));
        }
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateRequest(ddf.catalog.operation.CreateRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) RegistryObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType) Test(org.junit.Test)

Example 19 with CreateRequest

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

the class PointOfContactUpdatePluginTest method testPassthroughMethods.

@Test
public void testPassthroughMethods() throws Exception {
    CreateRequest createRequest = mock(CreateRequest.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(pointOfContactUpdatePlugin.processPreCreate(createRequest), is(createRequest));
    assertThat(pointOfContactUpdatePlugin.processPreDelete(deleteRequest), is(deleteRequest));
    assertThat(pointOfContactUpdatePlugin.processPostDelete(deleteResponse), is(deleteResponse));
    assertThat(pointOfContactUpdatePlugin.processPreQuery(queryRequest), is(queryRequest));
    assertThat(pointOfContactUpdatePlugin.processPostQuery(queryResponse), is(queryResponse));
    assertThat(pointOfContactUpdatePlugin.processPreResource(resourceRequest), is(resourceRequest));
    assertThat(pointOfContactUpdatePlugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
    verifyZeroInteractions(createRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) ResourceResponse(ddf.catalog.operation.ResourceResponse) CreateRequest(ddf.catalog.operation.CreateRequest) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceRequest(ddf.catalog.operation.ResourceRequest) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 20 with CreateRequest

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

the class MetacardIngestNetworkPluginTest method testApplySucceeds.

@Test
public void testApplySucceeds() throws Exception {
    ThreadContext.put(CLIENT_INFO_KEY, INFO_MAP);
    when(mockMetacardCondition.applies(INFO_MAP)).thenReturn(true);
    CreateRequest createRequest = plugin.processPreCreate(mockCreateRequest);
    verify(mockMetacardServices).setAttributesIfAbsent(metacards, mockParsedAttributes, mockAttributeFactory);
    verifyNoMoreInteractions(mockMetacardServices);
    assertThat(createRequest, is(not(mockCreateRequest)));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Test(org.junit.Test)

Aggregations

CreateRequest (ddf.catalog.operation.CreateRequest)63 Test (org.junit.Test)49 Metacard (ddf.catalog.data.Metacard)38 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)36 CreateResponse (ddf.catalog.operation.CreateResponse)26 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)12 Subject (ddf.security.Subject)12 Serializable (java.io.Serializable)10 IngestException (ddf.catalog.source.IngestException)9 List (java.util.List)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 HashSet (java.util.HashSet)7 UpdateRequest (ddf.catalog.operation.UpdateRequest)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 CatalogFramework (ddf.catalog.CatalogFramework)4 QueryRequest (ddf.catalog.operation.QueryRequest)4