Search in sources :

Example 71 with CreateRequest

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

the class MetacardValidityMarkerPluginTest method testMultipleValidationTagsInvalid.

@Test
public void testMultipleValidationTagsInvalid() throws StopProcessingException, PluginExecutionException, ValidationException {
    metacardValidators.add(getMockFailingValidatorWithErrorsAndWarnings());
    CreateRequest request = getMockCreateRequest();
    Metacard m1 = request.getMetacards().get(0);
    Set<String> tags = m1.getTags();
    tags.add(VALID_TAG);
    m1.setAttribute(AttributeImpl.fromMultipleValues(Metacard.TAGS, new ArrayList<>(tags)));
    CreateRequest filteredRequest = plugin.process(request);
    assertThat(filteredRequest.getMetacards().get(0).getTags(), hasItem(INVALID_TAG));
    assertThat(filteredRequest.getMetacards().get(0).getTags(), not(hasItem(VALID_TAG)));
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 72 with CreateRequest

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

the class MetacardIngestNetworkPluginTest method testClientInfoMapNull.

@Test
public void testClientInfoMapNull() throws Exception {
    ThreadContext.put(CLIENT_INFO_KEY, null);
    CreateRequest createRequest = plugin.processPreCreate(mockCreateRequest);
    verifyZeroInteractions(mockMetacardServices, mockMetacardCondition);
    assertThat(createRequest, is(mockCreateRequest));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) Test(org.junit.Test)

Example 73 with CreateRequest

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

the class GeoNamesCatalogIndexer method executeCreateMetacardRequest.

private void executeCreateMetacardRequest(List<Metacard> metacards) {
    int totalMetacards = metacards.size();
    for (int i = 0; i < totalMetacards; i += BATCH_SIZE) {
        int lastIndex = i + BATCH_SIZE;
        if (lastIndex > metacards.size()) {
            lastIndex = metacards.size();
        }
        List<Metacard> sublist = metacards.subList(i, lastIndex);
        Map<String, Serializable> properties = new HashMap<>();
        CreateRequest createRequest = new CreateRequestImpl(sublist, properties);
        try {
            CreateResponse createResponse = catalogFramework.create(createRequest);
            List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
            LOGGER.trace("Created {} metacards.", createdMetacards == null ? 0 : createdMetacards.size());
        } catch (IngestException | SourceUnavailableException e) {
            LOGGER.debug("Unable to create Metacards", e);
        }
    }
    LOGGER.trace("Created {} metacards.", totalMetacards);
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException)

Example 74 with CreateRequest

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

the class GeoNamesCatalogIndexerTest method testUpdateIndexBatches.

@Test
public void testUpdateIndexBatches() throws Exception {
    List<Metacard> metacardList = new ArrayList<>();
    int totalExpectedEntries = 360;
    for (int i = 0; i < totalExpectedEntries; i++) {
        metacardList.add(METACARD);
    }
    ArgumentCaptor<CreateRequest> createRequestArgumentCaptor = ArgumentCaptor.forClass(CreateRequest.class);
    when(createResponse.getCreatedMetacards()).thenReturn(metacardList);
    geoNamesCatalogIndexer.updateIndex(LARGE_FILE_PATH, geoEntryExtractor, false, progressCallback);
    verify(catalogFramework, times(2)).create(createRequestArgumentCaptor.capture());
    List<CreateRequest> createRequestList = createRequestArgumentCaptor.getAllValues();
    int totalEntries = 0;
    for (CreateRequest createRequest : createRequestList) {
        totalEntries += createRequest.getMetacards().size();
    }
    assertThat(totalEntries, is(totalExpectedEntries));
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 75 with CreateRequest

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

the class CatalogFrameworkImplTest method testInjectsAttributesOnCreate.

@Test
public void testInjectsAttributesOnCreate() throws Exception {
    final String title = "Create";
    final String injectAttributeName = "new attribute";
    final double injectAttributeValue = 2;
    final MetacardImpl originalMetacard = new MetacardImpl();
    originalMetacard.setTitle(title);
    originalMetacard.setAttribute(injectAttributeName, injectAttributeValue);
    final List<Metacard> metacards = Collections.singletonList(originalMetacard);
    final CreateRequest request = new CreateRequestImpl(metacards, null);
    final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
    stubMetacardInjection(injectAttribute);
    final CreateResponse response = framework.create(request);
    final Metacard createdMetacard = response.getCreatedMetacards().get(0);
    final MetacardType createdMetacardType = createdMetacard.getMetacardType();
    final MetacardType originalMetacardType = originalMetacard.getMetacardType();
    assertThat(createdMetacardType.getName(), is(originalMetacardType.getName()));
    final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
    expectedAttributeDescriptors.add(injectAttribute);
    assertThat(createdMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
    assertThat(createdMetacard.getTitle(), is(title));
    assertThat(createdMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Metacard(ddf.catalog.data.Metacard) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CreateRequest (ddf.catalog.operation.CreateRequest)80 Test (org.junit.Test)62 Metacard (ddf.catalog.data.Metacard)44 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)39 CreateResponse (ddf.catalog.operation.CreateResponse)29 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 Subject (ddf.security.Subject)14 Serializable (java.io.Serializable)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)11 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)11 IngestException (ddf.catalog.source.IngestException)11 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)9 List (java.util.List)9 HashSet (java.util.HashSet)7 UpdateRequest (ddf.catalog.operation.UpdateRequest)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Map (java.util.Map)5 CatalogFramework (ddf.catalog.CatalogFramework)4