Changeset 6830
- Timestamp:
- 11/19/15 15:44:00 (9 years ago)
- Location:
- FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/Constants.java
r6826 r6830 18 18 public static final String FCS_DIAGNOSTIC_REQUESTED_DATA_VIEW_INVALID = 19 19 FCS_DIAGNOSTIC_URI_PREFIX + 4; 20 public static final String FCS_DIAGNOSTIC_GENERAL_QUERY_SYNTAX_ERROR = 21 FCS_DIAGNOSTIC_URI_PREFIX + 10; 22 public static final String FCS_DIAGNOSTIC_GENERAL_QUERY_TOO_COMPLEX_CANNOT_PERFORM_QUERY = 23 FCS_DIAGNOSTIC_URI_PREFIX + 11; 24 public static final String FCS_DIAGNOSTIC_QUERY_WAS_REWRITTEN = 25 FCS_DIAGNOSTIC_URI_PREFIX + 12; 26 public static final String FCS_DIAGNOSTIC_GENERAL_PROCESSING_HINT = 27 FCS_DIAGNOSTIC_URI_PREFIX + 13; 20 28 21 29 -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/EndpointDescription.java
r5546 r6830 60 60 61 61 /** 62 * Get the list of layers that are supported in Advanced Search by this 63 * endpoint. 64 * <p> 65 * The implementation of this method <em>must</em> be thread-safe. 66 * </p> 67 * 68 * @return the list of layers supported in Advanced Search by this endpoint 69 */ 70 public List<Layer> getSupportedLayers(); 71 72 73 /** 62 74 * Get a list of all resources sub-ordinate to a resource identified by a 63 75 * given persistent identifier. -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java
r5546 r6830 19 19 private final List<String> languages; 20 20 private final List<DataView> availableDataViews; 21 private final List<Layer> availableLayers; 21 22 private final List<ResourceInfo> subResources; 22 23 … … 42 43 * @param availableDataViews 43 44 * the list of available data views for this resource 45 * @param availableLayers 46 * the list if layers available for Advanced Search or 47 * <code>null</code> if not applicable 44 48 * @param subResources 45 49 * a list of resource sub-ordinate to this resource or … … 49 53 Map<String, String> description, String landingPageURI, 50 54 List<String> languages, List<DataView> availableDataViews, 55 List<Layer> availableLayers, 51 56 List<ResourceInfo> subResources) { 52 57 if (pid == null) { … … 83 88 Collections.unmodifiableList(availableDataViews); 84 89 90 if ((availableLayers != null) && !availableDataViews.isEmpty()) { 91 this.availableLayers = 92 Collections.unmodifiableList(availableLayers); 93 } else { 94 this.availableLayers = null; 95 } 96 85 97 if ((subResources != null) && !subResources.isEmpty()) { 86 98 this.subResources = Collections.unmodifiableList(subResources); … … 182 194 183 195 /** 196 * Get the list of data views that are available for this resource. 197 * 198 * @return the list of data views 199 */ 200 public List<DataView> getAvailableDataViews() { 201 return availableDataViews; 202 } 203 204 205 /** 206 * Get the list of layers that are available in Advanced Search for this 207 * resource. 208 * 209 * @return the list of layers or <code>null</code> 210 */ 211 public List<Layer> getAvailableLayers() { 212 return availableLayers; 213 } 214 215 216 /** 217 * Check if any layers are available for Advanced Search 218 * 219 * @return <code>true</code> if any layer for Advanced Search is available, 220 * <code>false</code> otherwise 221 */ 222 public boolean hasAvailableLayers() { 223 return (availableLayers != null); 224 } 225 226 227 /** 184 228 * Get the direct sub-ordinate resources of this resource. 185 229 * … … 191 235 } 192 236 193 194 public List<DataView> getAvailableDataViews() {195 return availableDataViews;196 }197 198 237 } // class ResourceInfo -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java
r6826 r6830 39 39 "http://clarin.eu/fcs/endpoint-description"; 40 40 private static final String ED_PREFIX = "ed"; 41 private static final int ED_VERSION = 1;41 private static final int ED_VERSION = 2; 42 42 private static final Logger logger = 43 43 LoggerFactory.getLogger(SimpleEndpointSearchEngineBase.class); … … 239 239 writer.writeAttribute("version", Integer.toString(ED_VERSION)); 240 240 241 // capabilities241 // Capabilities 242 242 writer.writeStartElement(ED_NS, "Capabilities"); 243 243 for (URI capability : endpointDescription.getCapabilities()) { … … 248 248 writer.writeEndElement(); // "Capabilities" element 249 249 250 // supported data views250 // SupportedDataViews 251 251 writer.writeStartElement(ED_NS, "SupportedDataViews"); 252 252 for (DataView dataView : endpointDescription.getSupportedDataViews()) { … … 272 272 writer.writeEndElement(); // "SupportedDataViews" element 273 273 274 // SupportedLayers 275 final List<Layer> layers = endpointDescription.getSupportedLayers(); 276 if (layers != null) { 277 writer.writeStartElement(ED_NS, "SupportedLayers"); 278 for (Layer layer : layers) { 279 writer.writeStartElement(ED_NS, "SupportedLayer"); 280 writer.writeAttribute("id", layer.getId()); 281 writer.writeAttribute("result-id", 282 layer.getResultId().toString()); 283 if (layer.getContentEncoding() == Layer.ContentEncoding.EMPTY) { 284 writer.writeAttribute("type", "empty"); 285 } 286 if (layer.getQualifier() != null) { 287 writer.writeAttribute("qualifier", layer.getQualifier()); 288 } 289 if (layer.getAltValueInfo() != null) { 290 writer.writeAttribute("alt-value-info", 291 layer.getAltValueInfo()); 292 if (layer.getAltValueInfoURI() != null) { 293 writer.writeAttribute("alt-value-info-uri", 294 layer.getAltValueInfoURI()); 295 } 296 } 297 writer.writeCharacters(layer.getType()); 298 writer.writeEndElement(); // "SupportedLayer" element 299 } 300 writer.writeEndElement(); // "SupportedLayers" element 301 302 } 303 304 // Resources 274 305 try { 275 // resources276 306 List<ResourceInfo> resources = 277 307 endpointDescription.getResourceList( … … 351 381 writer.writeAttribute("ref", sb.toString()); 352 382 383 final List<Layer> layers = resource.getAvailableLayers(); 384 if (layers != null) { 385 sb = new StringBuilder(); 386 for (Layer layer : resource.getAvailableLayers()) { 387 if (sb.length() > 0) { 388 sb.append(" "); 389 } 390 sb.append(layer.getId()); 391 } 392 writer.writeEmptyElement(ED_NS, "AvailableLayers"); 393 writer.writeAttribute("ref", sb.toString()); 394 } 395 353 396 // child resources 354 397 List<ResourceInfo> subs = resource.getSubResources(); -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/AbstractEndpointDescriptionBase.java
r5670 r6830 7 7 import eu.clarin.sru.server.fcs.DataView; 8 8 import eu.clarin.sru.server.fcs.EndpointDescription; 9 import eu.clarin.sru.server.fcs.Layer; 9 10 10 11 … … 19 20 protected final List<URI> capabilities; 20 21 protected final List<DataView> supportedDataViews; 22 protected final List<Layer> supportedLayers; 23 21 24 22 25 /** … … 29 32 */ 30 33 protected AbstractEndpointDescriptionBase(List<URI> capabilities, 31 List<DataView> supportedDataViews ) {34 List<DataView> supportedDataViews, List<Layer> supportedLayers) { 32 35 if (capabilities == null) { 33 36 throw new NullPointerException("capabilities == null"); … … 58 61 this.supportedDataViews = 59 62 Collections.unmodifiableList(supportedDataViews); 63 64 if ((supportedLayers != null) && !supportedLayers.isEmpty()) { 65 for (Layer layer : supportedLayers) { 66 if (layer == null) { 67 throw new IllegalArgumentException( 68 "supportedLayers must not contain a 'null' item"); 69 } 70 } 71 this.supportedLayers = 72 Collections.unmodifiableList(supportedLayers); 73 } else { 74 this.supportedLayers = null; 75 } 60 76 } 61 77 … … 72 88 } 73 89 90 91 @Override 92 public List<Layer> getSupportedLayers() { 93 return supportedLayers; 94 } 95 74 96 } // abstract class EndpointDescriptionBase -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescription.java
r5546 r6830 8 8 import eu.clarin.sru.server.fcs.DataView; 9 9 import eu.clarin.sru.server.fcs.EndpointDescription; 10 import eu.clarin.sru.server.fcs.Layer; 10 11 import eu.clarin.sru.server.fcs.ResourceInfo; 11 12 … … 32 33 * @param supportedDataViews 33 34 * a list of data views that are supported by this endpoint 35 * @param supportedLayers 36 * a list of layers supported for Advanced Search by this 37 * endpoint or <code>null</code> 34 38 * @param resources 35 39 * a static list of resource info records … … 40 44 */ 41 45 public SimpleEndpointDescription(List<URI> capabilities, 42 List<DataView> supportedDataViews, List<ResourceInfo> resources, 46 List<DataView> supportedDataViews, 47 List<Layer> supportedLayers, 48 List<ResourceInfo> resources, 43 49 boolean pidCaseSensitive) { 44 super(capabilities, supportedDataViews );50 super(capabilities, supportedDataViews, supportedLayers); 45 51 46 52 if (resources == null) { -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescriptionParser.java
r5547 r6830 36 36 import eu.clarin.sru.server.fcs.DataView.DeliveryPolicy; 37 37 import eu.clarin.sru.server.fcs.EndpointDescription; 38 import eu.clarin.sru.server.fcs.Layer; 38 39 import eu.clarin.sru.server.fcs.ResourceInfo; 39 40 … … 54 55 private static final String NS_LEGACY = 55 56 "http://clarin.eu/fcs/1.0/resource-info"; 56 private static final String CAP_BASIC_SEARCH = 57 "http://clarin.eu/fcs/capability/basic-search"; 57 private static final URI CAP_BASIC_SEARCH = 58 URI.create("http://clarin.eu/fcs/capability/basic-search"); 59 private static final URI CAP_ADVANCED_SEARCH = 60 URI.create("http://clarin.eu/fcs/capability/advanced-search"); 58 61 private static final String LANG_EN = "en"; 59 62 private static final String POLICY_SEND_DEFAULT = "send-by-default"; … … 140 143 // capabilities 141 144 List<URI> capabilities = new ArrayList<URI>(); 142 XPathExpression exp 1=145 XPathExpression exp = 143 146 xpath.compile("//ed:Capabilities/ed:Capability"); 144 NodeList list1 = (NodeList) exp1.evaluate(doc, XPathConstants.NODESET); 145 if ((list1 != null) && (list1.getLength() > 0)) { 147 NodeList list = 148 (NodeList) exp.evaluate(doc, XPathConstants.NODESET); 149 if ((list != null) && (list.getLength() > 0)) { 146 150 logger.debug("parsing capabilities"); 147 for (int i = 0; i < list 1.getLength(); i++) {148 String s = list 1.item(i).getTextContent().trim();151 for (int i = 0; i < list.getLength(); i++) { 152 String s = list.item(i).getTextContent().trim(); 149 153 try { 150 154 URI uri = new URI(s); … … 163 167 "endpoint configuration"); 164 168 } 165 URI cap = URI.create(CAP_BASIC_SEARCH); 166 if (!capabilities.contains(cap)) { 169 if (!capabilities.contains(CAP_BASIC_SEARCH)) { 167 170 logger.warn("capability '{}' was not defined in endpoint " + 168 171 "description; added it to meet specification. Please " + 169 172 "update your endpoint description!", CAP_BASIC_SEARCH); 170 capabilities.add( cap);173 capabilities.add(CAP_BASIC_SEARCH); 171 174 } 172 175 logger.debug("CAPS:'{}'", capabilities); … … 174 177 // supported data views 175 178 List<DataView> supportedDataViews = new ArrayList<DataView>(); 176 XPathExpression exp2 = 177 xpath.compile("//ed:SupportedDataViews/ed:SupportedDataView"); 178 NodeList list2 = (NodeList) exp2.evaluate(doc, XPathConstants.NODESET); 179 if ((list2 != null) && (list2.getLength() > 0)) { 179 exp = xpath.compile("//ed:SupportedDataViews/ed:SupportedDataView"); 180 list = (NodeList) exp.evaluate(doc, XPathConstants.NODESET); 181 if ((list != null) && (list.getLength() > 0)) { 180 182 logger.debug("parsing supported data views"); 181 for (int i = 0; i < list 2.getLength(); i++) {182 Element item = (Element) list 2.item(i);183 for (int i = 0; i < list.getLength(); i++) { 184 Element item = (Element) list.item(i); 183 185 String id = getAttribute(item, "id"); 184 186 if (id == null) { … … 238 240 239 241 242 // supported layers 243 List<Layer> supportedLayers = null; 244 exp = xpath.compile("//ed:SupportedLayers/ed:SupportedLayer"); 245 list = (NodeList) exp.evaluate(doc, XPathConstants.NODESET); 246 if ((list != null) && (list.getLength() > 0)) { 247 logger.debug("parsing supported layers"); 248 for (int i = 0; i < list.getLength(); i++) { 249 Element item = (Element) list.item(i); 250 String id = getAttribute(item, "id"); 251 if (id == null) { 252 throw new SRUConfigException("Element <ed:SupportedLayer> " 253 + "must carry a proper 'id' attribute"); 254 } 255 String s = getAttribute(item, "result-id"); 256 if (s == null) { 257 throw new SRUConfigException("Element <ed:SupportedLayer> " 258 + "must carry a proper 'result-id' attribute"); 259 } 260 URI resultId = null; 261 try { 262 resultId = new URI(s); 263 } catch (URISyntaxException e) { 264 throw new SRUConfigException("Attribute 'result-id' on " + 265 "Element <ed:SupportedLayer> is not encoded " + 266 "as proper URI: " + s); 267 } 268 269 String type = cleanString(item.getTextContent()); 270 if ((type != null) && !type.isEmpty()) { 271 272 } else { 273 throw new SRUConfigException("Element <ed:SupportedLayer> " 274 + "as no proper type"); 275 } 276 277 String qualifier = getAttribute(item, "qualifier"); 278 279 // FIXME: implement parsing of content encoding! 280 Layer.ContentEncoding encoding = 281 Layer.ContentEncoding.VALUE; 282 283 String altValueInfo = getAttribute(item, "alt-value-info"); 284 String altValueInfoURI = null; 285 if (altValueInfo != null) { 286 altValueInfoURI = getAttribute(item, "alt-value-info-uri"); 287 } 288 289 290 291 if (supportedLayers == null) { 292 supportedLayers = new ArrayList<Layer>(list.getLength()); 293 } 294 supportedLayers.add(new Layer(id, resultId, type, encoding, 295 qualifier, altValueInfo, altValueInfoURI)); 296 } 297 } 298 299 if ((supportedLayers != null) && 300 !capabilities.contains(CAP_ADVANCED_SEARCH)) { 301 logger.warn("capability '{}' was not defined in endpoint " + 302 "description; added it to meet specification. Please " + 303 "update your endpoint description!", CAP_ADVANCED_SEARCH); 304 capabilities.add(CAP_ADVANCED_SEARCH); 305 } 306 logger.debug("L: {}", supportedLayers); 307 240 308 // resources 241 XPathExpression x3 = 242 xpath.compile("/ed:EndpointDescription/ed:Resources/ed:Resource"); 243 NodeList l3 = (NodeList) x3.evaluate(doc, XPathConstants.NODESET); 309 exp = xpath.compile("/ed:EndpointDescription/ed:Resources/ed:Resource"); 310 list = (NodeList) exp.evaluate(doc, XPathConstants.NODESET); 244 311 final Set<String> ids = new HashSet<String>(); 245 List<ResourceInfo> resources = 246 parseRessources(xpath, l3, ids, supportedDataViews);312 List<ResourceInfo> resources = parseRessources(xpath, list, ids, 313 supportedDataViews, supportedLayers); 247 314 if ((resources == null) || resources.isEmpty()) { 248 315 throw new SRUConfigException("No resources where " + … … 252 319 return new SimpleEndpointDescription(capabilities, 253 320 supportedDataViews, 321 supportedLayers, 254 322 resources, 255 323 false); … … 258 326 259 327 private static List<ResourceInfo> parseRessources(XPath xpath, 260 NodeList nodes, Set<String> ids, List<DataView> supportedDataViews) 261 throws SRUConfigException, XPathExpressionException { 262 List<ResourceInfo> ris = null; 328 NodeList nodes, Set<String> ids, List<DataView> supportedDataViews, 329 List<Layer> supportedLayers) 330 throws SRUConfigException, XPathExpressionException { 331 List<ResourceInfo> ris = null; 263 332 for (int k = 0; k < nodes.getLength(); k++) { 264 333 final Element node = (Element) nodes.item(k); … … 269 338 List<String> langs = null; 270 339 List<DataView> availableDataViews = null; 340 List<Layer> availableLayers = null; 271 341 List<ResourceInfo> sub = null; 272 342 … … 435 505 NodeList l6 = (NodeList) x6.evaluate(node, XPathConstants.NODESET); 436 506 if ((l6 != null) && (l6.getLength() > 0)) { 437 sub = parseRessources(xpath, l6, ids, supportedDataViews); 507 sub = parseRessources(xpath, l6, ids, 508 supportedDataViews, supportedLayers); 438 509 } 439 510 … … 447 518 langs, 448 519 availableDataViews, 520 availableLayers, 449 521 sub)); 450 522 }
Note: See TracChangeset
for help on using the changeset viewer.