private String getRecordElement(CSWRecordsResult response) { switch (response.getElementSet()) { case BRIEF: return "BriefRecord"; case SUMMARY: return "SummaryRecord"; default: return "Record"; } }
Converters.convert(response.getTimestamp(), String.class)); element("csw:SearchStatus", null, attributes); if(response.getElementSet() == null) { response.setElementSet(ElementSetType.FULL); addAttribute(attributes, "numberOfRecordsMatched", response.getNumberOfRecordsMatched()); addAttribute(attributes, "numberOfRecordsReturned", response.getNumberOfRecordsReturned()); addAttribute(attributes, "nextRecord", response.getNextRecord()); addAttribute(attributes, "recordSchema", response.getRecordSchema()); addAttribute(attributes, "elementSet", response.getElementSet()); start("csw:SearchResults", attributes);
private CSWRecordsResult getCSWResponse() throws IOException { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.clear(); cal.set(Calendar.YEAR, 2012); cal.set(Calendar.MONTH, 6); cal.set(Calendar.DAY_OF_MONTH, 10); cal.set(Calendar.HOUR_OF_DAY, 15); FeatureCollection fc = store.getRecords(Query.ALL, Transaction.AUTO_COMMIT); CSWRecordsResult response = new CSWRecordsResult(ElementSetType.BRIEF, "http://www.opengis.net/cat/csw/2.0.2", 100, 12, 13, cal.getTime(), fc); return response; } }
public void testEncodeSummary() throws Exception { // setup the request CSWRecordsResult response = getCSWResponse(); response.setElementSet(ElementSetType.SUMMARY); GetRecordsType request = getCSWRequest(); // transform it into a GetRecordsResponse (this time with the canonical location) CSWRecordTransformer tx = new CSWRecordTransformer(request, true); tx.setIndentation(2); StringWriter sw = new StringWriter(); tx.transform(response, sw); // System.out.println(sw); Document dom = XMLUnit.buildControlDocument(sw.toString()); // checking root elements assertXpathEvaluatesTo("1", "count(/csw:GetRecordsResponse)", dom); assertXpathEvaluatesTo( "http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/record.xsd", "/csw:GetRecordsResponse/@xsi:schemaLocation", dom); assertXpathEvaluatesTo("2012-07-10T15:00:00Z", "//csw:SearchStatus/@timestamp", dom); // check that we got summary records assertXpathEvaluatesTo("summary", "//csw:SearchResults/@elementSet", dom); assertXpathEvaluatesTo("12", "count(//csw:SummaryRecord)", dom); // check one summary record assertXpathEvaluatesTo("5", "count(//csw:SummaryRecord[dc:identifier = 'urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd']/*)", dom); assertXpathEvaluatesTo("http://purl.org/dc/dcmitype/Service", "//csw:SummaryRecord[dc:identifier = 'urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd']/dc:type", dom); assertXpathEvaluatesTo("Proin sit amet justo. In justo. Aenean adipiscing nulla id tellus.", "//csw:SummaryRecord[dc:identifier = 'urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd']/dct:abstract", dom); assertXpathEvaluatesTo("60.042 13.754", "//csw:SummaryRecord[dc:identifier = 'urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd']/ows:BoundingBox/ows:LowerCorner", dom); assertXpathEvaluatesTo("68.41 17.92", "//csw:SummaryRecord[dc:identifier = 'urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd']/ows:BoundingBox/ows:UpperCorner", dom); }
private void encodeRecords(final CSWRecordsResult response) { // encode the records if(response.getRecords() != null) { try { response.getRecords().accepts(new FeatureVisitor() { @Override public void visit(Feature feature) { encode(response, feature); } }, new LoggingProgressListener()); } catch (IOException e) { throw new ServiceException("Failed to encoder records", e); } } }
attributes, "timestamp", Converters.convert(response.getTimestamp(), String.class)); element("csw:SearchStatus", null, attributes); if (response.getElementSet() == null) { response.setElementSet(ElementSetType.FULL); attributes, "numberOfRecordsMatched", response.getNumberOfRecordsMatched()); addAttribute( attributes, "numberOfRecordsReturned", response.getNumberOfRecordsReturned()); addAttribute(attributes, "nextRecord", response.getNextRecord()); addAttribute(attributes, "recordSchema", response.getRecordSchema()); addAttribute(attributes, "elementSet", response.getElementSet()); start("csw:SearchResults", attributes);
CSWRecordsResult result = new CSWRecordsResult(elementSet, request.getOutputSchema(), numberOfRecordsMatched, numberOfRecordsMatched, 0, timestamp, records); return result;
public void testEncodeFull() throws Exception { response.setElementSet(null); GetRecordsType request = getCSWRequest();
private void encodeRecords(final CSWRecordsResult response) { // encode the records if (response.getRecords() != null) { try { response.getRecords() .accepts( new FeatureVisitor() { @Override public void visit(Feature feature) { encode(response, feature); } }, new LoggingProgressListener()); } catch (IOException e) { throw new ServiceException("Failed to encoder records", e); } } }
new CSWRecordsResult( elementSet, request.getOutputSchema(),
private List<Name> getElements(CSWRecordsResult response) { switch (response.getElementSet()) { case BRIEF: return CSWRecordDescriptor.BRIEF_ELEMENTS; case SUMMARY: return CSWRecordDescriptor.SUMMARY_ELEMENTS; default: return null; } }
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { CSWRecordsResult result = (CSWRecordsResult) value; RequestBaseType request = (RequestBaseType) operation.getParameters()[0]; CSWInfo csw = gs.getService(CSWInfo.class); // check the output schema is valid if (result.getRecords() != null) { FeatureType recordSchema = result.getRecords().getSchema(); if (recordSchema != null && !recordType.equals(recordSchema)) { throw new IllegalArgumentException("Cannot encode this kind of record " + recordSchema.getName() + " into schema " + schema); } } if (getResultType(request) == ResultType.VALIDATE) { // this one is output schema independent transformAcknowledgement(output, request, csw); } else { transformResponse(output, result, request, csw); } }
CSWRecordsResult result = new CSWRecordsResult(elementSet, request.getOutputSchema(), numberOfRecordsMatched, numberOfRecordsReturned, nextRecord, timestamp, records); return result;
private List<Name> getElements(CSWRecordsResult response) { switch (response.getElementSet()) { case BRIEF: return CSWRecordDescriptor.BRIEF_ELEMENTS; case SUMMARY: return CSWRecordDescriptor.SUMMARY_ELEMENTS; default: return null; } } }
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { CSWRecordsResult result = (CSWRecordsResult) value; RequestBaseType request = (RequestBaseType) operation.getParameters()[0]; CSWInfo csw = gs.getService(CSWInfo.class); // check the output schema is valid if (result.getRecords() != null) { FeatureType recordSchema = result.getRecords().getSchema(); if (recordSchema != null && !recordType.equals(recordSchema)) { throw new IllegalArgumentException( "Cannot encode this kind of record " + recordSchema.getName() + " into schema " + schema); } } if (getResultType(request) == ResultType.VALIDATE) { // this one is output schema independent transformAcknowledgement(output, request, csw); } else { transformResponse(output, result, request, csw); } }
new CSWRecordsResult( elementSet, request.getOutputSchema(),
private String getRecordElement(CSWRecordsResult response) { switch (response.getElementSet()) { case BRIEF: return "BriefRecord"; case SUMMARY: return "SummaryRecord"; default: return "Record"; } }