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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations