@Override public String getMimeType(Object value, Operation operation) throws ServiceException { String mimeType = ((RepositoryItem) value).getMime(); return mimeType; }
@Override public CatalogStoreCapabilities getCapabilities() { return new CatalogStoreCapabilities(descriptorByType); }
@Override public int getRecordsCount(Query q, Transaction t) throws IOException { // simply delegate to the feature collection, we have no optimizations // available for the time being (even counting the files in case of no filtering // would be wrong as we have to return getRecords(q, t, null).size(); }
@Test public void testCapabilities() throws Exception { CatalogStoreCapabilities capabilities = store.getCapabilities(); assertFalse(capabilities.supportsTransactions()); Name cswRecordName = CSWRecordDescriptor.RECORD_DESCRIPTOR.getName(); assertTrue(capabilities.supportsGetRepositoryItem(cswRecordName)); assertTrue(capabilities.getQueriables(cswRecordName).contains(new NameImpl(CSW.NAMESPACE, "AnyText"))); assertTrue(capabilities.getDomainQueriables(cswRecordName).contains(new NameImpl(DC.NAMESPACE, "title"))); }
public GetDomain(CSWInfo csw, CatalogStore store) { this.csw = csw; this.store = store; try { for (RecordDescriptor rd : store.getRecordDescriptors()) { for (Name prop : store.getCapabilities().getDomainQueriables(rd.getFeatureDescriptor().getName())) { attributeTypeMap.put(prop, rd.getFeatureDescriptor().getName()); Enumeration declaredPrefixes = rd.getNamespaceSupport().getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = rd.getNamespaceSupport().getURI(prefix); ns.declarePrefix(prefix, uri); } } } } catch (IOException e) { throw new ServiceException(e, "Failed to retrieve the domain values", ServiceException.NO_APPLICABLE_CODE); } }
@Test public void testGetRepositoryItem() throws IOException { RepositoryItem item = store.getRepositoryItem("foo"); assertNull(item); item = store.getRepositoryItem("urn:uuid:19887a8a-f6b0-4a63-ae56-7fba0e17801f"); assertNotNull(item); assertEquals("application/xml", item.getMime()); String contents = IOUtils.toString(item.getContents(), "UTF-8"); String expected = "This is a random comment that will show up only when fetching the repository item"; assertTrue(contents.contains(expected)); } }
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { InputStream input = null; try { input = ((RepositoryItem) value).getContents(); if (null != input) { IOUtils.copy(input, output); } else { throw new HttpErrorCodeException(404, "Repository item had no content"); } } catch (IOException e) { throw new ServiceException("Failed to encode the repository item onto the output", e); } finally { IOUtils.closeQuietly(input); output.flush(); } } }
int[] counts = new int[queries.size()]; for (int i = 0; i < queries.size(); i++) { counts[i] = store.getRecordsCount(queries.get(i), Transaction.AUTO_COMMIT); numberOfRecordsMatched += counts[i]; FeatureCollection collection = store.getRecords(queries.get(i), Transaction.AUTO_COMMIT, request.getOutputSchema()); if(collection != null && collection.size() > 0) { results.add(collection);
@Test public void testNamespaceSupport() throws IOException, URISyntaxException { AbstractCatalogStore store = new AbstractCatalogStore() { { support(CSWRecordDescriptor.getInstance()); support(GSRecordDescriptor.getInstance()); } @Override public FeatureCollection getRecordsInternal(RecordDescriptor rd, RecordDescriptor rdOutput, Query q, Transaction t) throws IOException { if(rd == GSRecordDescriptor.getInstance()) { return new MemoryFeatureCollection(GSRecordDescriptor.getInstance().getFeatureType()); } else { throw new RuntimeException("Was expecting the geoserver record descriptor"); } } }; RecordDescriptor[] descriptors = store.getRecordDescriptors(); assertEquals(2, descriptors.length); assertEquals(CSWRecordDescriptor.getInstance(), descriptors[0]); assertEquals(GSRecordDescriptor.getInstance(), descriptors[1]); Query query = new Query("Record"); query.setNamespace(new URI(GSRecordDescriptor.GS_NAMESPACE)); FeatureCollection records = store.getRecords(query, Transaction.AUTO_COMMIT, null); assertEquals(GSRecordDescriptor.getInstance().getFeatureType(), records.getSchema()); }
/** * Returns the requested RepositoryItem * * @param request */ public RepositoryItem run(GetRepositoryItemType request) { try { RepositoryItem item = store.getRepositoryItem(request.getId()); if (item == null) { // by spec we have to return a 404 throw new HttpErrorCodeException( 404, "No repository item found for id " + request.getId()); } return item; } catch (IOException e) { throw new ServiceException("Failed to load the repository item", e); } } }
private Set<Name> getSupportedTypes() throws IOException { Set<Name> result = new HashSet<Name>(); for (RecordDescriptor rd : store.getRecordDescriptors()) { result.add(rd.getFeatureDescriptor().getName()); } return result; }
private List<PropertyName> getPropertyNames(RecordDescriptor rd, QueryType query) { if (query.getElementName() != null && !query.getElementName().isEmpty()) { // turn the QName into PropertyName. We don't do any verification cause the // elements in the actual feature could be parts of substitution groups // of the elements in the feature's schema List<PropertyName> result = new ArrayList<PropertyName>(); for (QName qn : query.getElementName()) { result.add(store.translateProperty(rd, Types.toTypeName(qn))); } return result; } else { ElementSetType elementSet = getElementSet(query); List<Name> properties = rd.getPropertiesForElementSet(elementSet); if (properties != null) { List<PropertyName> result = new ArrayList<PropertyName>(); for (Name pn : properties) { result.add(store.translateProperty(rd, pn)); } return result; } else { // the profile is the full one return null; } } }
public RecordDescriptor get(Object key) { if (!(key instanceof Name)) { return null; } Name name = (Name) key; RecordDescriptor descriptor = super.get(key); if (descriptor == null && name.getNamespaceURI() == null) { // relaxed match, see if we can find the record without the namespace for (Map.Entry<Name, RecordDescriptor> entry : entrySet()) { if (entry.getKey().getLocalPart().equals(name.getLocalPart())) { return entry.getValue(); } } } return descriptor; } }
@Override public FeatureCollection getRecords(Query q, Transaction t, String outputSchema) throws IOException { RecordDescriptor rd; Name typeName = null; if (q.getTypeName() == null) { typeName = CSWRecordDescriptor.RECORD_DESCRIPTOR.getName(); } else if (q.getNamespace() != null) { typeName = new NameImpl(q.getNamespace().toString(), q.getTypeName()); } else { typeName = new NameImpl(q.getTypeName()); } rd = descriptorByType.get(typeName); RecordDescriptor rdOutput; if (outputSchema == null || "".equals(outputSchema)) { rdOutput = descriptorByOutputSchema.get( CSWRecordDescriptor.getInstance().getOutputSchema()); } else { rdOutput = descriptorByOutputSchema.get(outputSchema); } if (rd == null) { throw new IOException(q.getTypeName() + " is not a supported type"); } if (rdOutput == null) { throw new IOException(outputSchema + " is not a supported output schema"); } return getRecordsInternal(rd, rdOutput, q, t); }
public GetDomain(CSWInfo csw, CatalogStore store) { this.csw = csw; this.store = store; try { for (RecordDescriptor rd : store.getRecordDescriptors()) { for (Name prop : store.getCapabilities() .getDomainQueriables(rd.getFeatureDescriptor().getName())) { attributeTypeMap.put(prop, rd.getFeatureDescriptor().getName()); Enumeration declaredPrefixes = rd.getNamespaceSupport().getDeclaredPrefixes(); while (declaredPrefixes.hasMoreElements()) { String prefix = (String) declaredPrefixes.nextElement(); String uri = rd.getNamespaceSupport().getURI(prefix); ns.declarePrefix(prefix, uri); } } } } catch (IOException e) { throw new ServiceException( e, "Failed to retrieve the domain values", ServiceException.NO_APPLICABLE_CODE); } }
@Override public String getMimeType(Object value, Operation operation) throws ServiceException { String mimeType = ((RepositoryItem) value).getMime(); return mimeType; }
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { InputStream input = null; try { input = ((RepositoryItem) value).getContents(); if (null != input) { IOUtils.copy(input, output); } else { throw new HttpErrorCodeException(404, "Repository item had no content"); } } catch (IOException e) { throw new ServiceException("Failed to encode the repository item onto the output", e); } finally { IOUtils.closeQuietly(input); output.flush(); } }
/** * Returns the requested RepositoryItem * * @param request * @return */ public RepositoryItem run(GetRepositoryItemType request) { try { RepositoryItem item = store.getRepositoryItem(request.getId()); if(item == null) { // by spec we have to return a 404 throw new HttpErrorCodeException(404, "No repository item found for id " + request.getId()); } return item; } catch (IOException e) { throw new ServiceException("Failed to load the repository item", e); } } }
private Set<Name> getSupportedTypes() throws IOException { Set<Name> result = new HashSet<Name>(); for (RecordDescriptor rd : store.getRecordDescriptors()) { result.add(rd.getFeatureDescriptor().getName()); } return result; }
private List<PropertyName> getPropertyNames(RecordDescriptor rd, QueryType query) { if(query.getElementName() != null && !query.getElementName().isEmpty()) { // turn the QName into PropertyName. We don't do any verification cause the // elements in the actual feature could be parts of substitution groups // of the elements in the feature's schema List<PropertyName> result = new ArrayList<PropertyName>(); for (QName qn : query.getElementName()) { result.add(store.translateProperty(rd, Types.toTypeName(qn))); } return result; } else { ElementSetType elementSet = getElementSet(query); List<Name> properties = rd.getPropertiesForElementSet(elementSet); if(properties != null) { List<PropertyName> result = new ArrayList<PropertyName>(); for (Name pn : properties) { result.add(store.translateProperty(rd, pn)); } return result; } else { // the profile is the full one return null; } } }