use of ddf.catalog.operation.impl.CreateResponseImpl in project ddf by codice.
the class SolrCatalogProviderImpl method create.
@Override
public CreateResponse create(CreateRequest request) throws IngestException {
nonNull(request);
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);
}
long startTime = System.currentTimeMillis();
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).", e);
}
LOGGER.debug("Time elapsed to create {} metacards is {} ms", metacards.size(), System.currentTimeMillis() - startTime);
return new CreateResponseImpl(request, request.getProperties(), output);
}
Aggregations