Changeset 6830


Ignore:
Timestamp:
11/19/15 15:44:00 (9 years ago)
Author:
Oliver Schonefeld
Message:
  • some FCS 2.0 stuff (incomplete!)
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  
    1818    public static final String FCS_DIAGNOSTIC_REQUESTED_DATA_VIEW_INVALID =
    1919            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;
    2028
    2129
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/EndpointDescription.java

    r5546 r6830  
    6060
    6161    /**
     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    /**
    6274     * Get a list of all resources sub-ordinate to a resource identified by a
    6375     * given persistent identifier.
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java

    r5546 r6830  
    1919    private final List<String> languages;
    2020    private final List<DataView> availableDataViews;
     21    private final List<Layer> availableLayers;
    2122    private final List<ResourceInfo> subResources;
    2223
     
    4243     * @param availableDataViews
    4344     *            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
    4448     * @param subResources
    4549     *            a list of resource sub-ordinate to this resource or
     
    4953            Map<String, String> description, String landingPageURI,
    5054            List<String> languages, List<DataView> availableDataViews,
     55            List<Layer> availableLayers,
    5156            List<ResourceInfo> subResources) {
    5257        if (pid == null) {
     
    8388                Collections.unmodifiableList(availableDataViews);
    8489
     90        if ((availableLayers != null) && !availableDataViews.isEmpty()) {
     91            this.availableLayers =
     92                    Collections.unmodifiableList(availableLayers);
     93        } else {
     94            this.availableLayers = null;
     95        }
     96
    8597        if ((subResources != null) && !subResources.isEmpty()) {
    8698            this.subResources = Collections.unmodifiableList(subResources);
     
    182194
    183195    /**
     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    /**
    184228     * Get the direct sub-ordinate resources of this resource.
    185229     *
     
    191235    }
    192236
    193 
    194         public List<DataView> getAvailableDataViews() {
    195                 return availableDataViews;
    196         }
    197 
    198237} // class ResourceInfo
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java

    r6826 r6830  
    3939            "http://clarin.eu/fcs/endpoint-description";
    4040    private static final String ED_PREFIX = "ed";
    41     private static final int ED_VERSION = 1;
     41    private static final int ED_VERSION = 2;
    4242    private static final Logger logger =
    4343            LoggerFactory.getLogger(SimpleEndpointSearchEngineBase.class);
     
    239239        writer.writeAttribute("version", Integer.toString(ED_VERSION));
    240240
    241         // capabilities
     241        // Capabilities
    242242        writer.writeStartElement(ED_NS, "Capabilities");
    243243        for (URI capability : endpointDescription.getCapabilities()) {
     
    248248        writer.writeEndElement(); // "Capabilities" element
    249249
    250         // supported data views
     250        // SupportedDataViews
    251251        writer.writeStartElement(ED_NS, "SupportedDataViews");
    252252        for (DataView dataView : endpointDescription.getSupportedDataViews()) {
     
    272272        writer.writeEndElement(); // "SupportedDataViews" element
    273273
     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
    274305        try {
    275             // resources
    276306            List<ResourceInfo> resources =
    277307                    endpointDescription.getResourceList(
     
    351381                writer.writeAttribute("ref", sb.toString());
    352382
     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
    353396                // child resources
    354397                List<ResourceInfo> subs = resource.getSubResources();
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/AbstractEndpointDescriptionBase.java

    r5670 r6830  
    77import eu.clarin.sru.server.fcs.DataView;
    88import eu.clarin.sru.server.fcs.EndpointDescription;
     9import eu.clarin.sru.server.fcs.Layer;
    910
    1011
     
    1920    protected final List<URI> capabilities;
    2021    protected final List<DataView> supportedDataViews;
     22    protected final List<Layer> supportedLayers;
     23
    2124
    2225    /**
     
    2932     */
    3033    protected AbstractEndpointDescriptionBase(List<URI> capabilities,
    31             List<DataView> supportedDataViews) {
     34            List<DataView> supportedDataViews, List<Layer> supportedLayers) {
    3235        if (capabilities == null) {
    3336            throw new NullPointerException("capabilities == null");
     
    5861        this.supportedDataViews =
    5962                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        }
    6076    }
    6177
     
    7288    }
    7389
     90
     91    @Override
     92    public List<Layer> getSupportedLayers() {
     93        return supportedLayers;
     94    }
     95
    7496} // abstract class EndpointDescriptionBase
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescription.java

    r5546 r6830  
    88import eu.clarin.sru.server.fcs.DataView;
    99import eu.clarin.sru.server.fcs.EndpointDescription;
     10import eu.clarin.sru.server.fcs.Layer;
    1011import eu.clarin.sru.server.fcs.ResourceInfo;
    1112
     
    3233     * @param supportedDataViews
    3334     *            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>
    3438     * @param resources
    3539     *            a static list of resource info records
     
    4044     */
    4145    public SimpleEndpointDescription(List<URI> capabilities,
    42             List<DataView> supportedDataViews, List<ResourceInfo> resources,
     46            List<DataView> supportedDataViews,
     47            List<Layer> supportedLayers,
     48            List<ResourceInfo> resources,
    4349            boolean pidCaseSensitive) {
    44         super(capabilities, supportedDataViews);
     50        super(capabilities, supportedDataViews, supportedLayers);
    4551
    4652        if (resources == null) {
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescriptionParser.java

    r5547 r6830  
    3636import eu.clarin.sru.server.fcs.DataView.DeliveryPolicy;
    3737import eu.clarin.sru.server.fcs.EndpointDescription;
     38import eu.clarin.sru.server.fcs.Layer;
    3839import eu.clarin.sru.server.fcs.ResourceInfo;
    3940
     
    5455    private static final String NS_LEGACY =
    5556            "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");
    5861    private static final String LANG_EN = "en";
    5962    private static final String POLICY_SEND_DEFAULT = "send-by-default";
     
    140143        // capabilities
    141144        List<URI> capabilities = new ArrayList<URI>();
    142         XPathExpression exp1 =
     145        XPathExpression exp =
    143146                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)) {
    146150            logger.debug("parsing capabilities");
    147             for (int i = 0; i < list1.getLength(); i++) {
    148                 String s = list1.item(i).getTextContent().trim();
     151            for (int i = 0; i < list.getLength(); i++) {
     152                String s = list.item(i).getTextContent().trim();
    149153                try {
    150154                    URI uri = new URI(s);
     
    163167                    "endpoint configuration");
    164168        }
    165         URI cap = URI.create(CAP_BASIC_SEARCH);
    166         if (!capabilities.contains(cap)) {
     169        if (!capabilities.contains(CAP_BASIC_SEARCH)) {
    167170            logger.warn("capability '{}' was not defined in endpoint " +
    168171                    "description; added it to meet specification. Please " +
    169172                    "update your endpoint description!", CAP_BASIC_SEARCH);
    170             capabilities.add(cap);
     173            capabilities.add(CAP_BASIC_SEARCH);
    171174        }
    172175        logger.debug("CAPS:'{}'", capabilities);
     
    174177        // supported data views
    175178        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)) {
    180182            logger.debug("parsing supported data views");
    181             for (int i = 0; i < list2.getLength(); i++) {
    182                 Element item = (Element) list2.item(i);
     183            for (int i = 0; i < list.getLength(); i++) {
     184                Element item = (Element) list.item(i);
    183185                String id = getAttribute(item, "id");
    184186                if (id == null) {
     
    238240
    239241
     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
    240308        // 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);
    244311        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);
    247314        if ((resources == null) || resources.isEmpty()) {
    248315            throw new SRUConfigException("No resources where " +
     
    252319        return new SimpleEndpointDescription(capabilities,
    253320                supportedDataViews,
     321                supportedLayers,
    254322                resources,
    255323                false);
     
    258326
    259327    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;
    263332      for (int k = 0; k < nodes.getLength(); k++) {
    264333          final Element node                = (Element) nodes.item(k);
     
    269338          List<String> langs                = null;
    270339          List<DataView> availableDataViews = null;
     340          List<Layer> availableLayers       = null;
    271341          List<ResourceInfo> sub            = null;
    272342
     
    435505          NodeList l6 = (NodeList) x6.evaluate(node, XPathConstants.NODESET);
    436506          if ((l6 != null) && (l6.getLength() > 0)) {
    437               sub = parseRessources(xpath, l6, ids, supportedDataViews);
     507              sub = parseRessources(xpath, l6, ids,
     508                      supportedDataViews, supportedLayers);
    438509          }
    439510
     
    447518                  langs,
    448519                  availableDataViews,
     520                  availableLayers,
    449521                  sub));
    450522      }
Note: See TracChangeset for help on using the changeset viewer.