use of net.opengis.cat.csw.v_2_0_2.InsertResultType in project ddf by codice.
the class AbstractCswStore method create.
@Override
public CreateResponse create(CreateRequest createRequest) throws IngestException {
Map<String, Serializable> properties = new HashMap<>();
validateOperation();
Subject subject = (Subject) createRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT);
Csw csw = factory.getClientForSubject(subject);
CswTransactionRequest transactionRequest = getTransactionRequest();
List<Metacard> metacards = createRequest.getMetacards();
List<String> metacardIds = metacards.stream().map(Metacard::getId).collect(Collectors.toList());
List<Metacard> createdMetacards = new ArrayList<>();
List<Filter> createdMetacardFilters;
HashSet<ProcessingDetails> errors = new HashSet<>();
String insertTypeName = schemaTransformerManager.getTransformerIdForSchema(cswSourceConfiguration.getOutputSchema());
if (insertTypeName == null) {
throw new IngestException("Could not find transformer for output schema " + cswSourceConfiguration.getOutputSchema());
}
transactionRequest.getInsertActions().add(new InsertAction(insertTypeName, null, metacards));
try {
TransactionResponseType response = csw.transaction(transactionRequest);
Set<String> processedIds = new HashSet<>();
//dive down into the response to get the created ID's. We need these so we can query
//the source again to get the created metacards and put them in the result
createdMetacardFilters = response.getInsertResult().stream().map(InsertResultType::getBriefRecord).flatMap(Collection::stream).map(BriefRecordType::getIdentifier).flatMap(Collection::stream).map(JAXBElement::getValue).map(SimpleLiteral::getContent).flatMap(Collection::stream).map(id -> {
processedIds.add(id);
return filterBuilder.attribute(Core.ID).is().equalTo().text(id);
}).collect(Collectors.toList());
metacardIds.removeAll(processedIds);
errors.addAll(metacardIds.stream().map(id -> new ProcessingDetailsImpl(id, null, "Failed to create metacard")).collect(Collectors.toList()));
} catch (CswException e) {
throw new IngestException("Csw Transaction Failed : ", e);
}
try {
createdMetacards = transactionQuery(createdMetacardFilters, subject);
} catch (UnsupportedQueryException e) {
errors.add(new ProcessingDetailsImpl(this.getId(), e, "Failed to retrieve newly created metacards"));
}
return new CreateResponseImpl(createRequest, properties, createdMetacards, errors);
}
use of net.opengis.cat.csw.v_2_0_2.InsertResultType in project ddf by codice.
the class TestRegistryStore method testCreateNoExistingMetacard.
@Test
public void testCreateNoExistingMetacard() throws Exception {
Metacard mcard = getDefaultMetacard();
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
InsertResultType insertResultType = mock(InsertResultType.class);
BriefRecordType briefRecord = mock(BriefRecordType.class);
JAXBElement identifier = mock(JAXBElement.class);
SimpleLiteral literal = mock(SimpleLiteral.class);
when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
when(identifier.getValue()).thenReturn(literal);
when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
queryResults.add(new ResultImpl(mcard));
CreateRequest request = new CreateRequestImpl(mcard);
CreateResponse response = registryStore.create(request);
assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
use of net.opengis.cat.csw.v_2_0_2.InsertResultType in project arctic-sea by 52North.
the class InsertResultRequestEncoder method create.
@Override
protected XmlObject create(InsertResultRequest request) throws EncodingException {
validateInput(request);
InsertResultDocument doc = InsertResultDocument.Factory.newInstance(getXmlOptions());
InsertResultType insertResult = doc.addNewInsertResult();
insertResult.setService(request.getService());
insertResult.setVersion(request.getVersion());
insertResult.setTemplate(request.getTemplateIdentifier());
addResultValues(request, insertResult);
return doc;
}
use of net.opengis.cat.csw.v_2_0_2.InsertResultType in project arctic-sea by 52North.
the class InsertResultRequestEncoderTest method shouldEncodeInsertResultRequest.
@Test
public void shouldEncodeInsertResultRequest() throws EncodingException {
String version = Sos2Constants.SERVICEVERSION;
String service = SosConstants.SOS;
String templateIdentifier = "test-template-identifier";
String resultValues = "test-result-values";
InsertResultRequest request = new InsertResultRequest(service, version);
request.setTemplateIdentifier(templateIdentifier);
request.setResultValues(resultValues);
XmlObject encodedRequest = encoder.create(request);
Assert.assertThat(encodedRequest, Matchers.instanceOf(InsertResultDocument.class));
Assert.assertThat(((InsertResultDocument) encodedRequest).getInsertResult(), Matchers.notNullValue());
InsertResultType xbRequest = ((InsertResultDocument) encodedRequest).getInsertResult();
Assert.assertThat(xbRequest.getService(), Is.is(service));
Assert.assertThat(xbRequest.getVersion(), Is.is(version));
Assert.assertThat(xbRequest.getTemplate(), Is.is(templateIdentifier));
Assert.assertThat(xbRequest.getResultValues(), Matchers.instanceOf(XmlString.class));
Assert.assertThat(((XmlString) xbRequest.getResultValues()).getStringValue(), Is.is(resultValues));
}
use of net.opengis.cat.csw.v_2_0_2.InsertResultType in project ddf by codice.
the class CswEndpoint method getInsertResultFromResponse.
private InsertResultType getInsertResultFromResponse(CreateResponse createResponse) throws CswException {
InsertResultType result = new InsertResultType();
WKTReader reader = new WKTReader();
for (Metacard metacard : createResponse.getCreatedMetacards()) {
BoundingBoxType boundingBox = new BoundingBoxType();
Geometry geometry = null;
String bbox = null;
try {
if (metacard.getAttribute(CswConstants.BBOX_PROP) != null) {
bbox = metacard.getAttribute(CswConstants.BBOX_PROP).getValue().toString();
geometry = reader.read(bbox);
} else if (StringUtils.isNotBlank(metacard.getLocation())) {
bbox = metacard.getLocation();
geometry = reader.read(bbox);
}
} catch (ParseException e) {
LOGGER.debug("Unable to parse BoundingBox : {}", bbox, e);
}
BriefRecordType briefRecordType = new BriefRecordType();
if (geometry != null) {
Envelope bounds = geometry.getEnvelopeInternal();
if (bounds != null) {
boundingBox.setCrs(CswConstants.SRS_NAME);
boundingBox.setLowerCorner(Arrays.asList(bounds.getMinX(), bounds.getMinY()));
boundingBox.setUpperCorner(Arrays.asList(bounds.getMaxX(), bounds.getMaxY()));
briefRecordType.getBoundingBox().add(new net.opengis.ows.v_1_0_0.ObjectFactory().createBoundingBox(boundingBox));
}
}
SimpleLiteral identifier = new SimpleLiteral();
identifier.getContent().add(metacard.getId());
briefRecordType.getIdentifier().add(new JAXBElement<>(CswConstants.DC_IDENTIFIER_QNAME, SimpleLiteral.class, identifier));
SimpleLiteral title = new SimpleLiteral();
title.getContent().add(metacard.getTitle());
briefRecordType.getTitle().add(new JAXBElement<>(CswConstants.DC_TITLE_QNAME, SimpleLiteral.class, title));
SimpleLiteral type = new SimpleLiteral();
type.getContent().add(metacard.getContentTypeName());
briefRecordType.setType(type);
result.getBriefRecord().add(briefRecordType);
}
return result;
}
Aggregations