use of org.geotoolkit.csw.xml.v202.AbstractRecordType in project ddf by codice.
the class TestCswSourceBase method generateCswCollection.
protected CswRecordCollection generateCswCollection(String file) {
InputStream stream = getClass().getResourceAsStream(file);
GetRecordsResponseType recordsResponse = parseXml(stream);
GetRecordsResponseType records = new GetRecordsResponseType();
recordsResponse.copyTo(records);
List<Metacard> cswRecords = new LinkedList<>();
for (JAXBElement<? extends AbstractRecordType> rec : records.getSearchResults().getAbstractRecord()) {
MetacardImpl metacard = new MetacardImpl();
cswRecords.add(metacard);
if (rec.getValue() instanceof BriefRecordType) {
BriefRecordType record = (BriefRecordType) rec.getValue();
metacard.setId(record.getIdentifier().get(0).getValue().getContent().get(0));
if (!CollectionUtils.isEmpty(record.getType().getContent())) {
metacard.setContentTypeName(record.getType().getContent().get(0));
}
} else if (rec.getValue() instanceof SummaryRecordType) {
SummaryRecordType record = (SummaryRecordType) rec.getValue();
metacard.setId(record.getIdentifier().get(0).getValue().getContent().get(0));
if (!CollectionUtils.isEmpty(record.getType().getContent())) {
metacard.setContentTypeName(record.getType().getContent().get(0));
}
} else if (rec.getValue() instanceof RecordType) {
RecordType record = (RecordType) rec.getValue();
for (JAXBElement<SimpleLiteral> jb : record.getDCElement()) {
if ("identifier".equals(jb.getName().getLocalPart())) {
metacard.setId(jb.getValue().getContent().get(0));
}
if ("type".equals(jb.getName().getLocalPart()) && !CollectionUtils.isEmpty(jb.getValue().getContent())) {
metacard.setContentTypeName(jb.getValue().getContent().get(0));
}
}
}
}
CswRecordCollection collection = new CswRecordCollection();
collection.setCswRecords(cswRecords);
collection.setNumberOfRecordsMatched(records.getSearchResults().getNumberOfRecordsMatched().intValue());
collection.setNumberOfRecordsReturned(records.getSearchResults().getNumberOfRecordsReturned().intValue());
return collection;
}
use of org.geotoolkit.csw.xml.v202.AbstractRecordType in project geotoolkit by Geomatys.
the class CswXMLBindingTest method getRecordByIdResponseUnMarshalingTest.
/**
* Test getRecordById request Marshalling.
*/
@Test
public void getRecordByIdResponseUnMarshalingTest() throws JAXBException {
Unmarshaller unmarshaller = pool.acquireUnmarshaller();
/*
* Test marshalling csw getRecordByIdResponse v2.0.2
*/
SimpleLiteral id = new SimpleLiteral("{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}");
SimpleLiteral title = new SimpleLiteral("(JASON-1)");
SimpleLiteral type = new SimpleLiteral("clearinghouse");
List<SimpleLiteral> subject = new ArrayList<>();
subject.add(new SimpleLiteral("oceans elevation NASA/JPL/JASON-1"));
subject.add(new SimpleLiteral("oceans elevation 2"));
SimpleLiteral modified = new SimpleLiteral("2007-11-15 21:26:49");
SimpleLiteral Abstract = new SimpleLiteral("Jason-1 is the first follow-on to the highly successful TOPEX/Poseidonmission that measured ocean surface topography to an accuracy of 4.2cm.");
SimpleLiteral references = new SimpleLiteral("http://keel.esri.com/output/TOOLKIT_Browse_Metadata_P7540_T8020_D1098.xml");
SimpleLiteral spatial = new SimpleLiteral("northlimit=65.9999999720603; eastlimit=180; southlimit=-66.0000000558794; westlimit=-180;");
List<BoundingBoxType> bbox = new ArrayList<>();
bbox.add(new WGS84BoundingBoxType(180, -66.0000000558794, -180, 65.9999999720603));
RecordType record = new RecordType(id, title, type, subject, null, modified, null, Abstract, bbox, null, null, null, spatial, references);
BriefRecordType briefRecord = new BriefRecordType(id, title, type, bbox);
SummaryRecordType sumRecord = new SummaryRecordType(id, title, type, bbox, subject, null, modified, Abstract);
List<AbstractRecordType> records = new ArrayList<>();
records.add(record);
records.add(briefRecord);
records.add(sumRecord);
GetRecordByIdResponse expResult = new GetRecordByIdResponseType(records);
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<csw:GetRecordByIdResponse xmlns:ows=\"http://www.opengis.net/ows\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" xmlns:dct=\"http://purl.org/dc/terms/\">\n" + " <csw:Record>\n" + " <dc:identifier>{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}</dc:identifier>\n" + " <dc:title>(JASON-1)</dc:title>\n" + " <dc:type>clearinghouse</dc:type>\n" + " <dc:subject>oceans elevation NASA/JPL/JASON-1</dc:subject>\n" + " <dc:subject>oceans elevation 2</dc:subject>\n" + " <dct:modified>2007-11-15 21:26:49</dct:modified>\n" + " <dct:abstract>Jason-1 is the first follow-on to the highly successful TOPEX/Poseidonmission that measured ocean surface topography to an accuracy of 4.2cm.</dct:abstract>\n" + " <dct:references>http://keel.esri.com/output/TOOLKIT_Browse_Metadata_P7540_T8020_D1098.xml</dct:references>\n" + " <dct:spatial>northlimit=65.9999999720603; eastlimit=180; southlimit=-66.0000000558794; westlimit=-180;</dct:spatial>\n" + " <ows:WGS84BoundingBox dimensions=\"2\">\n" + " <ows:LowerCorner>180.0 -66.0000000558794</ows:LowerCorner>\n" + " <ows:UpperCorner>-180.0 65.9999999720603</ows:UpperCorner>\n" + " </ows:WGS84BoundingBox>\n" + " </csw:Record>\n" + " <csw:BriefRecord>\n" + " <dc:identifier>{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}</dc:identifier>\n" + " <dc:title>(JASON-1)</dc:title>\n" + " <dc:type>clearinghouse</dc:type>\n" + " <ows:WGS84BoundingBox dimensions=\"2\">\n" + " <ows:LowerCorner>180.0 -66.0000000558794</ows:LowerCorner>\n" + " <ows:UpperCorner>-180.0 65.9999999720603</ows:UpperCorner>\n" + " </ows:WGS84BoundingBox>\n" + " </csw:BriefRecord>\n" + " <csw:SummaryRecord>\n" + " <dc:identifier>{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}</dc:identifier>\n" + " <dc:title>(JASON-1)</dc:title>\n" + " <dc:type>clearinghouse</dc:type>\n" + " <dc:subject>oceans elevation NASA/JPL/JASON-1</dc:subject>\n" + " <dc:subject>oceans elevation 2</dc:subject>\n" + " <dct:modified>2007-11-15 21:26:49</dct:modified>\n" + " <dct:abstract>Jason-1 is the first follow-on to the highly successful TOPEX/Poseidonmission that measured ocean surface topography to an accuracy of 4.2cm.</dct:abstract>\n" + " <ows:WGS84BoundingBox dimensions=\"2\">\n" + " <ows:LowerCorner>180.0 -66.0000000558794</ows:LowerCorner>\n" + " <ows:UpperCorner>-180.0 65.9999999720603</ows:UpperCorner>\n" + " </ows:WGS84BoundingBox>\n" + " </csw:SummaryRecord>\n" + "</csw:GetRecordByIdResponse>\n";
GetRecordByIdResponse result = ((JAXBElement<GetRecordByIdResponse>) unmarshaller.unmarshal(new StringReader(xml))).getValue();
assertTrue(result.getAny() instanceof List);
List<Object> resultList = result.getAny();
List<Object> expResultList = expResult.getAny();
assertEquals(resultList.get(0), expResultList.get(0));
assertEquals(resultList.get(1), expResultList.get(1));
assertEquals(resultList.get(2), expResultList.get(2));
assertEquals(resultList, expResultList);
assertEquals(expResult.getAny(), result.getAny());
assertEquals(expResult, result);
pool.recycle(unmarshaller);
}
use of org.geotoolkit.csw.xml.v202.AbstractRecordType in project ARLAS-server by gisaia.
the class CSWRESTService method doKVP.
@Timed
@Path("/csw")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, ATOM.APPLICATION_ATOM_XML, MIME_TYPE__OPENSEARCH_XML })
@ApiOperation(value = "CSW", produces = MediaType.APPLICATION_XML + "," + MediaType.TEXT_XML + "," + ATOM.APPLICATION_ATOM_XML + "," + MIME_TYPE__OPENSEARCH_XML, notes = "CSW")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class) })
public Response doKVP(@ApiParam(name = "version", value = "version", allowMultiple = false, required = true) @QueryParam(value = "version") String version, @ApiParam(name = "acceptversions", value = "acceptversions", allowMultiple = false, required = true) @QueryParam(value = "acceptversions") String acceptVersions, @ApiParam(name = "service", value = "service", allowMultiple = false, required = true) @QueryParam(value = "service") String service, @ApiParam(name = "request", value = "request", allowMultiple = false, required = true) @QueryParam(value = "request") String request, @ApiParam(name = "elementname", value = "elementname", allowMultiple = false, required = true) @QueryParam(value = "elementname") String elementName, @ApiParam(name = "elementsetname", value = "elementsetname", allowMultiple = false, required = true) @QueryParam(value = "elementsetname") String elementSetName, @ApiParam(name = "filter", value = "filter", allowMultiple = false, required = true) @QueryParam(value = "filter") String filter, @ApiParam(name = "constraint", value = "constraint", allowMultiple = false, required = true) @QueryParam(value = "constraint") String constraint, @ApiParam(name = "constraintLanguage", value = "constraintLanguage", allowMultiple = false, required = true) @QueryParam(value = "constraintLanguage") String constraintLanguage, @ApiParam(name = "startposition", value = "startposition", allowMultiple = false, required = false) @QueryParam(value = "startposition") Integer startPosition, @ApiParam(name = "maxrecords", value = "maxrecords", allowMultiple = false, required = false) @QueryParam(value = "maxrecords") Integer maxRecords, @ApiParam(name = "sections", value = "sections", allowMultiple = false, required = false) @QueryParam(value = "sections") String sections, @ApiParam(name = "acceptformats", value = "acceptformats", allowMultiple = false, required = false) @QueryParam(value = "acceptformats") String acceptFormats, @ApiParam(name = "q", value = "q", allowMultiple = false, required = false) @QueryParam(value = "q") String query, @ApiParam(name = "bbox", value = "bbox", allowMultiple = false, required = false) @QueryParam(value = "bbox") String bbox, @ApiParam(name = "outputformat", value = "outputformat", allowMultiple = false, required = false) @QueryParam(value = "outputformat") String outputFormat, @ApiParam(name = "outputschema", value = "outputschema", allowMultiple = false, required = false) @QueryParam(value = "outputschema") String outputSchema, @ApiParam(name = "typenames", value = "typenames", allowMultiple = false, required = false) @QueryParam(value = "typenames") String typeNames, @ApiParam(name = "recordids", value = "recordids", allowMultiple = false, required = false) @QueryParam(value = "recordids") String recordIds, @ApiParam(name = "id", value = "id", allowMultiple = false, required = false) @QueryParam(value = "id") String id, @ApiParam(name = "language", value = "language", allowMultiple = false, required = false) @QueryParam(value = "language") String language, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = Documentation.FORM_PRETTY, allowMultiple = false, defaultValue = "false", required = false) @QueryParam(value = "pretty") Boolean pretty, @Context HttpHeaders headers) throws ArlasException, DatatypeConfigurationException, IOException {
String acceptFormatMediaType = MediaType.APPLICATION_XML;
String outputFormatMediaType = MediaType.APPLICATION_XML;
for (MediaType mediaType : headers.getAcceptableMediaTypes()) {
if (mediaType.getSubtype().contains("opensearchdescription")) {
OpenSearchHandler openSearchHandler = cswHandler.openSearchHandler;
OpenSearchDescription description = openSearchHandler.getOpenSearchDescription(serverBaseUri);
return Response.ok(description).build();
} else if (mediaType.getSubtype().contains("atom")) {
outputFormatMediaType = MediaType.APPLICATION_ATOM_XML;
}
}
if (request == null & version == null & service == null) {
request = "GetCapabilities";
version = CSWConstant.SUPPORTED_CSW_VERSION;
service = CSWConstant.CSW;
}
String[] sectionList;
if (sections == null) {
sectionList = new String[] { "All" };
} else {
sectionList = sections.split(",");
for (String section : sectionList) {
if (!Arrays.asList(CSWConstant.SECTION_NAMES).contains(section)) {
throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid sections", "sections", Service.CSW);
}
}
}
if (acceptFormats != null) {
if (acceptFormats.equals("text/xml")) {
acceptFormatMediaType = MediaType.TEXT_XML;
} else if (acceptFormats.equals("application/xml")) {
acceptFormatMediaType = MediaType.APPLICATION_XML;
} else {
throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid acceptFormats", "acceptFormats", Service.CSW);
}
}
if (outputFormat != null) {
if (outputFormat.equals("application/xml")) {
outputFormatMediaType = MediaType.APPLICATION_XML;
} else if (outputFormat.equals("application/atom+xml")) {
outputFormatMediaType = MediaType.APPLICATION_ATOM_XML;
} else {
throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid outputFormat", "outputFormat", Service.CSW);
}
}
RequestUtils.checkRequestTypeByName(request, CSWConstant.SUPPORTED_CSW_REQUESTYPE, Service.CSW);
CSWRequestType requestType = CSWRequestType.valueOf(request);
CSWCheckParam.checkQuerySyntax(requestType, elementName, elementSetName, acceptVersions, version, service, outputSchema, typeNames, bbox, recordIds, query, id, constraintLanguage);
String[] ids = null;
if (recordIds != null && recordIds.length() > 0) {
ids = recordIds.split(",");
} else if (id != null) {
ids = new String[] { id };
}
BoundingBox boundingBox = null;
if (bbox != null && bbox.length() > 0) {
// west, south, east, north CSW spec
double[] bboxList = GeoFormat.toDoubles(bbox, Service.CSW);
if (!(isBboxLatLonInCorrectRanges(bboxList) && bboxList[3] > bboxList[1]) && bboxList[0] != bboxList[2]) {
throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, FluidSearchService.INVALID_BBOX, "bbox", Service.CSW);
}
boundingBox = new BoundingBox(bboxList[3], bboxList[1], bboxList[0], bboxList[2]);
}
startPosition = Optional.ofNullable(startPosition).orElse(1);
maxRecords = Optional.ofNullable(maxRecords).orElse(cswHandler.ogcConfiguration.queryMaxFeature.intValue());
elementSetName = Optional.ofNullable(elementSetName).orElse("summary");
String[] elements = new String[] {};
if (elementName != null) {
elements = new String[elementName.split(",").length];
int i = 0;
for (String element : elementName.split(",")) {
if (element.contains(":")) {
elements[i] = elementName.split(":")[1];
element = elements[i];
} else {
elements[i] = element;
}
if (!Arrays.asList(CSWConstant.DC_FIELDS).contains(element.toLowerCase()))
throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid elementName", "elementName", Service.CSW);
i++;
}
}
List<CollectionReference> collections;
switch(requestType) {
case GetCapabilities:
GetCapabilitiesHandler getCapabilitiesHandler = cswHandler.getCapabilitiesHandler;
List<String> responseSections = Arrays.asList(sectionList);
String serviceUrl = serverBaseUri + "ogc/csw/?";
getCapabilitiesHandler.setCapabilitiesType(responseSections, serviceUrl, serverBaseUri + "ogc/csw/opensearch");
if (cswHandler.inspireConfiguration.enabled) {
collections = collectionReferenceService.getAllCollectionReferences(columnFilter);
collections.removeIf(collectionReference -> collectionReference.collectionName.equals(getMetacollectionName()));
filterCollectionsByColumnFilter(columnFilter, collections);
if (CollectionUtils.isNotEmpty(collections)) {
getCapabilitiesHandler.addINSPIRECompliantElements(collections, responseSections, serviceUrl, language);
}
}
JAXBElement<CapabilitiesType> getCapabilitiesResponse = getCapabilitiesHandler.getCSWCapabilitiesResponse();
return Response.ok(getCapabilitiesResponse).type(acceptFormatMediaType).build();
case GetRecords:
GetRecordsHandler getRecordsHandler = cswHandler.getRecordsHandler;
CollectionReferences collectionReferences = getCollectionReferencesForGetRecords(elements, null, maxRecords, startPosition, ids, query, constraint, boundingBox);
collections = new ArrayList<>(collectionReferences.collectionReferences);
filterCollectionsByColumnFilter(columnFilter, collections);
long recordsMatched = collectionReferences.totalCollectionReferences;
if (recordIds != null && recordIds.length() > 0) {
if (collections.size() == 0) {
throw new OGCException(OGCExceptionCode.NOT_FOUND, "Document not Found", "id", Service.CSW);
}
}
GetRecordsResponseType getRecordsResponse = getRecordsHandler.getCSWGetRecordsResponse(collections, ElementSetName.valueOf(elementSetName), startPosition - 1, recordsMatched, elements, outputSchema);
return Response.ok(getRecordsResponse).type(outputFormatMediaType).build();
case GetRecordById:
GetRecordsByIdHandler getRecordsByIdHandler = cswHandler.getRecordsByIdHandler;
CollectionReferences recordCollectionReferences = ogcDao.getCollectionReferences(elements, null, maxRecords, startPosition - 1, ids, query, constraint, boundingBox);
collections = new ArrayList<>(recordCollectionReferences.collectionReferences);
ColumnFilterUtil.assertCollectionsAllowed(columnFilter, collections);
if (outputSchema != null && outputSchema.equals(CSWConstant.SUPPORTED_CSW_OUTPUT_SCHEMA[2])) {
GetRecordByIdResponse getRecordByIdResponse = getRecordsByIdHandler.getMDMetadaTypeResponse(collections, ElementSetName.valueOf(elementSetName));
return Response.ok(getRecordByIdResponse).type(outputFormatMediaType).build();
} else {
AbstractRecordType abstractRecordType = getRecordsByIdHandler.getAbstractRecordTypeResponse(collections, ElementSetName.valueOf(elementSetName));
return Response.ok(abstractRecordType).type(outputFormatMediaType).build();
}
default:
throw new OGCException(OGCExceptionCode.INTERNAL_SERVER_ERROR, "Internal error: Unhandled request '" + request + "'.", Service.CSW);
}
}
Aggregations