Changeset 5485


Ignore:
Timestamp:
07/23/14 13:34:48 (10 years ago)
Author:
margaretha@ids-mannheim.de
Message:

Enabled x-cmd-resource-info

Location:
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java

    r5477 r5485  
    2020    private final String landingPageURI;
    2121    private final List<String> languages;
    22     private final List<String> availableDataViews;
     22    private List<String> availableDataViews;
    2323    private List<ResourceInfo> subResources;
    2424   
     
    5252            Map<String, String> title, Map<String, String> description,
    5353            String landingPageURI, List<String> languages,
    54             List<String> availableDataViews,
    5554            List<ResourceInfo> subResources) {
    5655        if (pid == null) {
     
    7978        }
    8079        this.languages = languages;
    81         if (availableDataViews == null){
    82                 throw new IllegalArgumentException("available data views == null");
    83         }
    84         if (availableDataViews.isEmpty()){
    85                 throw new IllegalArgumentException("available data views are empty");
    86         }
    87         this.availableDataViews = availableDataViews;
     80       
    8881        if ((subResources != null) && !subResources.isEmpty()) {
    8982            this.subResources = Collections.unmodifiableList(subResources);
     
    9386    }
    9487
     88    public ResourceInfo(String pid, int resourceCount,
     89            Map<String, String> title, Map<String, String> description,
     90            String landingPageURI, List<String> languages,
     91            List<String> availableDataViews,
     92            List<ResourceInfo> subResources) {
     93        this(pid,resourceCount, title, description, landingPageURI, languages, subResources);
     94       
     95        if (availableDataViews == null){
     96                throw new IllegalArgumentException("available data views == null");
     97        }
     98        if (availableDataViews.isEmpty()){
     99                throw new IllegalArgumentException("available data views are empty");
     100        }
     101        this.availableDataViews = availableDataViews;       
     102    }
     103   
    95104
    96105    /**
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfoWriter.java

    r5477 r5485  
    5353                if (writer == null) {
    5454            throw new NullPointerException("writer == null");
    55         }
    56                 if (prefix == null) {
    57             throw new NullPointerException("prefix == null");
    58         }
    59                 if (prefix.isEmpty()) {
    60             throw new IllegalArgumentException("prefix is empty");
    61         }
     55        }               
    6256                if (resourceInfo == null) {
    6357            throw new NullPointerException("resourceInfo == null");
     
    129123        }
    130124        writer.writeEndElement(); // "Languages" element
    131 
    132         final List<String> availableDataViews = resourceInfo.getAvailableDataViews();
    133         writer.writeStartElement(FCS_RESOURCE_INFO_NS, "AvailableDataViews");
    134125       
    135         StringBuilder sb = new StringBuilder();
    136         for (int i = 0; i < availableDataViews.size(); i++) {
    137             sb.append(availableDataViews.get(i));
    138             sb.append(" ");
    139         }       
    140         writer.writeAttribute("ref", sb.toString().trim());
    141        
    142         writer.writeEndElement(); // "Languages" element
    143 
     126        if (!defaultNS && prefix.equals(EndpointDescriptionWriter.PREFIX)){
     127                final List<String> availableDataViews = resourceInfo.getAvailableDataViews();
     128                writer.writeStartElement(FCS_RESOURCE_INFO_NS, "AvailableDataViews");
     129               
     130                StringBuilder sb = new StringBuilder();
     131                for (int i = 0; i < availableDataViews.size(); i++) {
     132                    sb.append(availableDataViews.get(i));
     133                    sb.append(" ");
     134                }       
     135                writer.writeAttribute("ref", sb.toString().trim());
     136               
     137                writer.writeEndElement(); // "AvailableDataViews" element
     138        }
    144139       
    145140        if (recursive && resourceInfo.hasSubResources()) {
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java

    r5477 r5485  
    3737        SRUSearchEngineBase {
    3838   
    39 //    private static final String X_CMD_RESOURCE_INFO = "x-cmd-resource-info";
     39    private static final String X_CMD_RESOURCE_INFO = "x-cmd-resource-info";
    4040    private static final String X_FCS_ENDPOINT_DESCRIPTION = "x-fcs-endpoint-description";
    4141   
     
    5858    public void addDataView(DataView d){
    5959        supportedDataViews.add(d);
    60     }
    61        
     60    }   
     61       
     62    public void setCapabilities(){
     63         logger.debug("Setting basic capability");
     64         capabilities = new ArrayList<String>();
     65         capabilities.add("http://clarin.eu/fcs/capability/basic-search");
     66    }     
     67   
     68    public void setSupportedDataViews(){
     69         logger.debug("Setting Generic Hits dataview");
     70         supportedDataViews = new ArrayList<DataView>();
     71         supportedDataViews.add(
     72                        new DataView("The representation of the hit",
     73                                "application/x-clarin-fcs-hits+xml",
     74                                DataView.PayloadDisposition.INLINE,
     75                                DataView.PayloadDelivery.SEND_BY_DEFAULT,
     76                                "hits")
     77         );
     78    }
     79   
    6280        /**
    6381     * This method should not be overridden. Perform your custom initialization
     
    7189            Map<String, String> params) throws SRUConfigException {
    7290        logger.debug("initializing");
    73         super.init(context, config, params);
    74        
    75         logger.debug("Setting basic capability");
    76         capabilities = new ArrayList<String>();
    77         capabilities.add("http://clarin.eu/fcs/capability/basic-search");
    78        
    79         logger.debug("Setting Generic Hits dataview");
    80         supportedDataViews = new ArrayList<DataView>();
    81         supportedDataViews.add(
    82                         new DataView("The representation of the hit",
    83                                 "application/x-clarin-fcs-hits+xml",
    84                                 DataView.PayloadDisposition.INLINE,
    85                                 DataView.PayloadDelivery.SEND_BY_DEFAULT,
    86                                 "hits")
    87         );
     91        super.init(context, config, params);             
    8892       
    8993        logger.debug("initializing search engine implementation");
     
    121125            SRURequest request, SRUDiagnosticList diagnostics)
    122126            throws SRUException {
    123         final boolean provideResourceInfo =
     127       
     128        final boolean provideCmdResourceInfo =
     129                parseBoolean(request.getExtraRequestData(X_CMD_RESOURCE_INFO));
     130        final boolean provideFcsResourceInfo =
    124131                parseBoolean(request.getExtraRequestData(X_FCS_ENDPOINT_DESCRIPTION));
    125         if (provideResourceInfo) {
     132               
     133        if (provideCmdResourceInfo) {
    126134            final List<ResourceInfo> resourceInfoList =
    127135                    resourceInfoInventory.getResourceInfoList(
    128136                            ResourceInfoInventory.PID_ROOT);
     137           
    129138            return new SRUExplainResult(diagnostics) {
    130 
    131139                @Override
    132140                public boolean hasExtraResponseData() {
    133                     return provideResourceInfo;
    134                 }
    135 
     141                    return provideCmdResourceInfo;
     142                }
    136143                @Override
    137144                public void writeExtraResponseData(XMLStreamWriter writer)
    138145                        throws XMLStreamException {
    139                         EndpointDescriptionWriter.writeEndpointDescription(writer,
    140                                         capabilities, supportedDataViews, resourceInfoList);
    141                     //ResourceInfoWriter.writeFullResourceInfo(writer, null, resourceInfoList);
     146                    ResourceInfoWriter.writeFullResourceInfo(writer, null, resourceInfoList);
    142147                }
    143148            };
    144         } else {
     149        }
     150        else if (provideFcsResourceInfo && capabilities != null
     151                        && supportedDataViews != null){
     152               
     153                final List<ResourceInfo> resourceInfoList =
     154                    resourceInfoInventory.getResourceInfoList(
     155                            ResourceInfoInventory.PID_ROOT);
     156               
     157//              if (capabilities == null){
     158//                      throw new SRUException(SRUConstants.SRU_GENERAL_SYSTEM_ERROR,
     159//                                      "Capabilities are not set.");
     160//              }
     161//              if (supportedDataViews == null){
     162//                      throw new SRUException(SRUConstants.SRU_GENERAL_SYSTEM_ERROR,
     163//                                      "Supported data views are not set.");
     164//              }
     165                return new SRUExplainResult(diagnostics) {
     166                @Override
     167                public boolean hasExtraResponseData() {
     168                    return provideFcsResourceInfo;
     169                }
     170                @Override
     171                public void writeExtraResponseData(XMLStreamWriter writer)
     172                        throws XMLStreamException {
     173                        EndpointDescriptionWriter.writeEndpointDescription(writer,
     174                                capabilities, supportedDataViews, resourceInfoList);
     175                }
     176            };
     177        }
     178        else {
    145179            return null;
    146180        }
Note: See TracChangeset for help on using the changeset viewer.