Search in sources :

Example 31 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class SolrCatalogProvider method create.

@Override
public CreateResponse create(CreateRequest request) throws IngestException {
    if (request == null) {
        throw new IngestException(REQUEST_MUST_NOT_BE_NULL_MESSAGE);
    }
    List<Metacard> metacards = request.getMetacards();
    List<Metacard> output = new ArrayList<>();
    if (metacards == null) {
        return new CreateResponseImpl(request, null, output);
    }
    for (Metacard metacard : metacards) {
        boolean isSourceIdSet = (metacard.getSourceId() != null && !"".equals(metacard.getSourceId()));
        /*
             * If an ID is not provided, then one is generated so that documents are unique. Solr
             * will not accept documents unless the id is unique.
             */
        if (metacard.getId() == null || metacard.getId().equals("")) {
            if (isSourceIdSet) {
                throw new IngestException("Metacard from a separate distribution must have ID");
            }
            metacard.setAttribute(new AttributeImpl(Metacard.ID, generatePrimaryKey()));
        }
        if (!isSourceIdSet) {
            metacard.setSourceId(getId());
        }
        output.add(metacard);
    }
    try {
        client.add(output, isForcedAutoCommit());
    } catch (SolrServerException | SolrException | IOException | MetacardCreationException e) {
        LOGGER.info("Solr could not ingest metacard(s) during create.", e);
        throw new IngestException("Could not ingest metacard(s).");
    }
    pendingNrtIndex.putAll(output.stream().collect(Collectors.toMap(Metacard::getId, m -> copyMetacard(m))));
    return new CreateResponseImpl(request, request.getProperties(), output);
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardCreationException(ddf.catalog.data.MetacardCreationException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 32 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class TestMetacardGroomerPlugin method testCreateNoContentTypeNull.

@Test
public void testCreateNoContentTypeNull() throws PluginExecutionException, StopProcessingException, ParseException {
    Date snapshotOfNow = new Date();
    Metacard inputMetacard = getStandardMetacard(null);
    AttributeImpl contentType = new AttributeImpl(Metacard.CONTENT_TYPE, "");
    contentType.clearValues();
    inputMetacard.setAttribute(contentType);
    AttributeImpl contentTypeVersion = new AttributeImpl(Metacard.CONTENT_TYPE_VERSION, "");
    contentTypeVersion.clearValues();
    inputMetacard.setAttribute(contentTypeVersion);
    Metacard outputMetacard = processCreate(inputMetacard);
    assertNotNull(outputMetacard.getId());
    assertEquals(DEFAULT_TITLE, outputMetacard.getTitle());
    assertEquals(DEFAULT_LOCATION, outputMetacard.getLocation());
    assertThat(outputMetacard.getContentTypeName(), is(nullValue()));
    assertThat(outputMetacard.getContentTypeVersion(), is(nullValue()));
    assertThat(outputMetacard.getMetadata(), is(DEFAULT_METADATA));
    assertThat(outputMetacard.getCreatedDate().getTime(), is(equalTo(inputMetacard.getCreatedDate().getTime())));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime(), is(equalTo(((Date) inputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime())));
    assertThat(outputMetacard.getModifiedDate().getTime(), is(equalTo(inputMetacard.getModifiedDate().getTime())));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    assertEquals(inputMetacard.getEffectiveDate(), outputMetacard.getEffectiveDate());
    assertEquals(inputMetacard.getExpirationDate(), outputMetacard.getExpirationDate());
    assertTrue(Arrays.equals(inputMetacard.getThumbnail(), outputMetacard.getThumbnail()));
    assertEquals(inputMetacard.getLocation(), outputMetacard.getLocation());
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Date(java.util.Date) Test(org.junit.Test)

Example 33 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class TestMetacardGroomerPlugin method testCreateNoTitleNull.

@Test
public void testCreateNoTitleNull() throws PluginExecutionException, StopProcessingException, ParseException {
    Date snapshotOfNow = new Date();
    Metacard inputMetacard = getStandardMetacard(null);
    AttributeImpl title = new AttributeImpl(Metacard.TITLE, "");
    title.clearValues();
    inputMetacard.setAttribute(title);
    Metacard outputMetacard = processCreate(inputMetacard);
    assertNotNull(outputMetacard.getId());
    assertThat(outputMetacard.getTitle(), is(nullValue()));
    assertEquals(DEFAULT_LOCATION, outputMetacard.getLocation());
    assertEquals(DEFAULT_TYPE, outputMetacard.getContentTypeName());
    assertEquals(DEFAULT_VERSION, outputMetacard.getContentTypeVersion());
    assertThat(outputMetacard.getMetadata(), is(DEFAULT_METADATA));
    assertThat(outputMetacard.getCreatedDate().getTime(), is(equalTo(inputMetacard.getCreatedDate().getTime())));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime(), is(equalTo(((Date) inputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime())));
    assertThat(outputMetacard.getModifiedDate().getTime(), is(equalTo(inputMetacard.getModifiedDate().getTime())));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    assertEquals(inputMetacard.getEffectiveDate(), outputMetacard.getEffectiveDate());
    assertEquals(inputMetacard.getExpirationDate(), outputMetacard.getExpirationDate());
    assertTrue(Arrays.equals(inputMetacard.getThumbnail(), outputMetacard.getThumbnail()));
    assertEquals(inputMetacard.getLocation(), outputMetacard.getLocation());
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Date(java.util.Date) Test(org.junit.Test)

Example 34 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class TestMetacardGroomerPlugin method testCreateNoDates.

@Test
public void testCreateNoDates() throws PluginExecutionException, StopProcessingException {
    Date snapshotOfNow = new Date();
    Metacard inputMetacard = getStandardMetacard(null);
    inputMetacard.setAttribute(new AttributeImpl(Metacard.CREATED, ""));
    inputMetacard.setAttribute(new AttributeImpl(Core.METACARD_CREATED, ""));
    inputMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, ""));
    inputMetacard.setAttribute(new AttributeImpl(Core.METACARD_MODIFIED, ""));
    inputMetacard.setAttribute(new AttributeImpl(Metacard.EXPIRATION, ""));
    inputMetacard.setAttribute(new AttributeImpl(Metacard.EFFECTIVE, ""));
    Metacard outputMetacard = processCreate(inputMetacard);
    assertNotNull(outputMetacard.getId());
    assertEquals(DEFAULT_TITLE, outputMetacard.getTitle());
    assertEquals(DEFAULT_LOCATION, outputMetacard.getLocation());
    assertEquals(DEFAULT_TYPE, outputMetacard.getContentTypeName());
    assertEquals(DEFAULT_VERSION, outputMetacard.getContentTypeVersion());
    assertThat(outputMetacard.getMetadata(), is(DEFAULT_METADATA));
    // CREATED
    assertThat(inputMetacard.getCreatedDate(), is(nullValue()));
    assertThat(outputMetacard.getCreatedDate().getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    // ddf.catalog.data.types.Metacard.CREATED
    assertThat(inputMetacard.getAttribute(Core.METACARD_CREATED).getValue().toString(), is(isEmptyOrNullString()));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    // MODIFIED
    assertThat(inputMetacard.getModifiedDate(), is(nullValue()));
    assertThat(outputMetacard.getModifiedDate().getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    // ddf.catalog.data.types.Metacard.MODIFIED
    assertThat(inputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue().toString(), is(isEmptyOrNullString()));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    // EFFECTIVE
    assertThat(inputMetacard.getEffectiveDate(), is(nullValue()));
    assertThat(outputMetacard.getEffectiveDate().getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    // EXPIRATION
    assertEquals(inputMetacard.getExpirationDate(), outputMetacard.getExpirationDate());
    assertTrue(Arrays.equals(inputMetacard.getThumbnail(), outputMetacard.getThumbnail()));
    assertEquals(inputMetacard.getLocation(), outputMetacard.getLocation());
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Date(java.util.Date) Test(org.junit.Test)

Example 35 with AttributeImpl

use of ddf.catalog.data.impl.AttributeImpl in project ddf by codice.

the class TestMetacardGroomerPlugin method testCreateNoTitleEmptyString.

@Test
public void testCreateNoTitleEmptyString() throws PluginExecutionException, StopProcessingException, ParseException {
    Date snapshotOfNow = new Date();
    Metacard inputMetacard = getStandardMetacard(null);
    inputMetacard.setAttribute(new AttributeImpl(Metacard.TITLE, ""));
    Metacard outputMetacard = processCreate(inputMetacard);
    assertNotNull(outputMetacard.getId());
    assertThat(outputMetacard.getTitle(), is(""));
    assertEquals(DEFAULT_LOCATION, outputMetacard.getLocation());
    assertEquals(DEFAULT_TYPE, outputMetacard.getContentTypeName());
    assertEquals(DEFAULT_VERSION, outputMetacard.getContentTypeVersion());
    assertThat(outputMetacard.getMetadata(), is(DEFAULT_METADATA));
    assertThat(outputMetacard.getCreatedDate().getTime(), is(equalTo(inputMetacard.getCreatedDate().getTime())));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime(), is(equalTo(((Date) inputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime())));
    assertThat(outputMetacard.getModifiedDate().getTime(), is(equalTo(inputMetacard.getModifiedDate().getTime())));
    assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
    assertEquals(inputMetacard.getEffectiveDate(), outputMetacard.getEffectiveDate());
    assertEquals(inputMetacard.getExpirationDate(), outputMetacard.getExpirationDate());
    assertTrue(Arrays.equals(inputMetacard.getThumbnail(), outputMetacard.getThumbnail()));
    assertEquals(inputMetacard.getLocation(), outputMetacard.getLocation());
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Date(java.util.Date) Test(org.junit.Test)

Aggregations

AttributeImpl (ddf.catalog.data.impl.AttributeImpl)181 Metacard (ddf.catalog.data.Metacard)109 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)49 Serializable (java.io.Serializable)30 Date (java.util.Date)30 Attribute (ddf.catalog.data.Attribute)29 List (java.util.List)23 HashMap (java.util.HashMap)20 IOException (java.io.IOException)18 InputStream (java.io.InputStream)17 Result (ddf.catalog.data.Result)15 HashSet (java.util.HashSet)15 PolicyResponse (ddf.catalog.plugin.PolicyResponse)14 ResultImpl (ddf.catalog.data.impl.ResultImpl)11 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)11 Set (java.util.Set)11 ContentItem (ddf.catalog.content.data.ContentItem)10 QueryResponse (ddf.catalog.operation.QueryResponse)10