Changeset 7905


Ignore:
Timestamp:
14/03/11 08:37:51 (8 years ago)
Author:
mnagni
Message:

Implemented the Query element for the CSWProvider element.
Fixed the provider statistic response (even if the ProviderID in the DWS table is a String instead of an Integer!)

Location:
RevitalizationWS/ws/DPWS/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • RevitalizationWS/ws/DPWS/trunk/pom.xml

    r7629 r7905  
    3030                                <groupId>org.apache.maven.plugins</groupId> 
    3131                                <artifactId>maven-compiler-plugin</artifactId> 
     32                                <version>2.3.2</version> 
    3233                                <configuration> 
    3334                                        <source>1.6</source> 
     
    171172 
    172173                <dependency> 
     174                        <groupId>ndg.services.schemas</groupId> 
     175                        <artifactId>gml</artifactId> 
     176                        <version>3.1.1</version> 
     177                        <scope>provided</scope> 
     178                </dependency> 
     179 
     180                <dependency> 
    173181                        <groupId>xerces</groupId> 
    174182                        <artifactId>xercesImpl</artifactId> 
     
    191199                        <name>triton.badc.rl.ac.uk-snapshots</name> 
    192200                        <url>http://triton.badc.rl.ac.uk:8180/artifactory/libs-snapshots-local</url> 
     201                        <uniqueVersion>false</uniqueVersion>                     
    193202                </snapshotRepository> 
    194203        </distributionManagement> 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/DPWS.java

    r7660 r7905  
    3333 
    3434import javax.ejb.Stateless; 
    35 import javax.jws.WebMethod; 
    36 import javax.jws.WebParam; 
    3735import javax.jws.WebService; 
     36 
     37import org.jboss.wsf.spi.annotation.WebContext; 
    3838 
    3939import ndg.services.revitalization.ejb.interfaces.DPWSLocal; 
     
    7878import ndg.services.schemas.revitalization.GetProviderStatisticResponse; 
    7979 
    80 import org.jboss.wsf.spi.annotation.WebContext; 
    81  
    8280/** 
    8381 * Session Bean implementation class DPWS 
     
    9593 * secureWSDLAccess=false) 
    9694 */ 
    97 @WebService 
     95@WebService(endpointInterface="ndg.services.revitalization.ejb.DPWSInterface") 
     96@WebContext(contextRoot = "/discovery", urlPattern = "/dpws") 
    9897@Stateless(name = "dpws") 
    99 @WebContext(contextRoot = "/discovery", urlPattern = "/dpws") 
    10098public class DPWS implements DPWSRemote, DPWSLocal { 
    10199 
    102         @WebMethod(operationName = "doHarvest") 
    103         @Override 
    104         public DoHarvestResponse doHarvest(@WebParam(name = "request") DoHarvestRequest request) { 
     100        public DoHarvestResponse doHarvest(DoHarvestRequest request) { 
    105101                ServiceExecutor<DoHarvestRequest, DoHarvestResponse> executor = new ExecuteHarvest(); 
    106102                return executor.doService(request); 
    107103        } 
    108104 
    109         @WebMethod(operationName = "getStatusProcess") 
    110         public GetProcessStatusResponse getUsageStats(@WebParam(name = "request") GetProcessStatusRequest request) { 
     105        public GetProcessStatusResponse getUsageStats(GetProcessStatusRequest request) { 
    111106                ServiceExecutor<GetProcessStatusRequest, GetProcessStatusResponse> executor = new ExecuteGetProcessStatusRequest(); 
    112107                return executor.doService(request); 
    113108        } 
    114109 
    115         @WebMethod(operationName = "getList") 
    116         public GetListResponse getList(@WebParam(name = "request") GetListType request) { 
     110        public GetListResponse getList(GetListType request) { 
    117111                ServiceExecutor<GetListType, GetListResponse> executor = new ExecuteGetList(); 
    118112                return executor.doService(request); 
    119113        } 
    120114 
    121         @WebMethod(operationName = "doNewUpdateProvider") 
    122         public DoNewUpdateProviderResponse doNewProvider(@WebParam(name = "request") DoNewUpdateProviderRequest request) { 
     115        public DoNewUpdateProviderResponse doNewProvider(DoNewUpdateProviderRequest request) { 
    123116                ServiceExecutor<DoNewUpdateProviderRequest, DoNewUpdateProviderResponse> executor = new ExecuteDoNewProvider(); 
    124117                return executor.doService(request); 
    125118        } 
    126119 
    127         @WebMethod(operationName = "getListNames") 
    128120        public GetListNamesResponse getListNames() { 
    129121                ServiceExecutor<Object, GetListNamesResponse> executor = new ExecuteGetListNames(); 
     
    131123        } 
    132124 
    133         @WebMethod(operationName = "getProviderDetails") 
    134         public GetProviderDetailsResponse getProviderDetails(@WebParam(name = "request") GetProviderDetailsRequest request) { 
     125        public GetProviderDetailsResponse getProviderDetails(GetProviderDetailsRequest request) { 
    135126                ServiceExecutor<GetProviderDetailsRequest, GetProviderDetailsResponse> executor = new ExecuteGetProviderDetails(); 
    136127                return executor.doService(request); 
    137128        } 
    138129 
    139         @WebMethod(operationName = "getHarvestHistory") 
    140         public GetHarvestHistoryResponse getHarvestHistory(@WebParam(name = "request") GetHistoryRequest request) { 
     130        public GetHarvestHistoryResponse getHarvestHistory(GetHistoryRequest request) { 
    141131                ServiceExecutor<GetHistoryRequest, GetHarvestHistoryResponse> executor = new ExecuteGetHarvestHistory(); 
    142132                return executor.doService(request); 
    143133        } 
    144134 
    145         @WebMethod(operationName = "getIngestHistory") 
    146         public GetIngestHistoryResponse getIngestHistory(@WebParam(name = "request") GetHistoryRequest request) { 
     135        public GetIngestHistoryResponse getIngestHistory(GetHistoryRequest request) { 
    147136                ServiceExecutor<GetHistoryRequest, GetIngestHistoryResponse> executor = new ExecuteGetIngestHistory(); 
    148137                return executor.doService(request); 
    149138        } 
    150139 
    151         @WebMethod(operationName = "doIngest") 
    152         @Override 
    153         public DoIngestResponse doIngest(@WebParam(name = "request") DoIngestRequest request) { 
     140        public DoIngestResponse doIngest(DoIngestRequest request) { 
    154141                ServiceExecutor<DoIngestRequest, DoIngestResponse> executor = new ExecuteDoIngest(); 
    155142                return executor.doService(request); 
    156143        } 
    157144         
    158         @WebMethod(operationName = "addTimer") 
    159         public AddTimerResponse addTimer(@WebParam(name = "request") AddTimerRequest request) { 
     145        public AddTimerResponse addTimer(AddTimerRequest request) { 
    160146                ServiceExecutor<AddTimerRequest, AddTimerResponse> executor = new ExecuteAddTimer(); 
    161147                return executor.doService(request); 
    162148        } 
    163149         
    164         @WebMethod(operationName = "deleteTimer") 
    165         public DeleteTimerResponse deleteTimer(@WebParam(name = "request") DeleteTimerRequest request) { 
     150        public DeleteTimerResponse deleteTimer(DeleteTimerRequest request) { 
    166151                ServiceExecutor<DeleteTimerRequest, DeleteTimerResponse> executor = new ExecuteDeleteTimer(); 
    167152                return executor.doService(request); 
    168153        } 
    169154         
    170         @WebMethod(operationName = "deleteProvider") 
    171         public DeleteProviderResponse deleteProvider(@WebParam(name = "request") DeleteProviderRequest request) { 
     155        public DeleteProviderResponse deleteProvider(DeleteProviderRequest request) { 
    172156                ServiceExecutor<DeleteProviderRequest, DeleteProviderResponse> executor = new ExecuteDeleteProvider(); 
    173157                return executor.doService(request); 
    174158        } 
    175159         
    176         @WebMethod(operationName = "getProviderStatistic") 
    177         public GetProviderStatisticResponse getProviderStatistic(@WebParam(name = "request") GetProviderStatisticRequest request) { 
     160        public GetProviderStatisticResponse getProviderStatistic(GetProviderStatisticRequest request) { 
    178161                ServiceExecutor<GetProviderStatisticRequest, GetProviderStatisticResponse> executor = new ExecuteGetProviderStatistic(); 
    179162                return executor.doService(request); 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/ModelManager.java

    r7868 r7905  
    3636import java.util.ArrayList; 
    3737import java.util.Calendar; 
     38import java.util.Collections; 
    3839import java.util.Iterator; 
    3940import java.util.List; 
     
    4748import javax.persistence.Query; 
    4849import javax.xml.namespace.QName; 
     50 
     51import org.apache.log4j.Logger; 
    4952 
    5053import ndg.common.ejb.exception.TimerCreationException; 
     
    5760import ndg.services.revitalization.executor.ProviderLogs; 
    5861import ndg.services.revitalization.harvest.Harvester; 
     62import ndg.services.revitalization.harvest.csw.CSWHarvester; 
    5963import ndg.services.revitalization.jpa.CswProvider; 
    6064import ndg.services.revitalization.jpa.HarvestLog; 
     
    9195        private final static String GET_INGEST_LOG_BY_PROVIDER = "select l, p.providerId from IngestSearchLogging l, HiProcess p  where l.reqId=p.id and p.providerId=:providerID and l.startIngest >= :start and l.stopIngest <= :end"; 
    9296        private final static String GET_INGEST_LOG_ALL_PROVIDER = "select l, p.providerId from IngestSearchLogging l, HiProcess p  where l.reqId=p.id and l.startIngest >= :start and l.stopIngest <= :end"; 
    93         private final static String GET_PROVIDER_STATISTIC = "select count(datacentre_name) from original_document where datacentre_name IN (:providerIDs) group by datacentre_name"; 
    94         private final static String GET_ALL_PROVIDER_STATISTIC = "select count(datacentre_name), datacentre_name from original_document group by datacentre_name"; 
    95          
     97        private final static String GET_PROVIDER_STATISTIC = "select count(datacentre_dpws_id), datacentre_dpws_id  from original_document where datacentre_dpws_id IN (:providerIDs) group by datacentre_dpws_id"; 
     98        private final static String GET_ALL_PROVIDER_STATISTIC = "select count(datacentre_dpws_id), datacentre_dpws_id from original_document group by datacentre_dpws_id"; 
     99         
     100        private final static Logger logger = Logger.getLogger(ModelManager.class.getName()); 
    96101 
    97102        @PersistenceContext(unitName = "discoveryDPWS") 
     
    342347                                                oldCSW.setOutputSchema(newCSW.getOutputSchema()); 
    343348                                        } 
     349                                         
     350                                        if (newCSW.getQuery()!= null && !newCSW.getQuery().equals(oldCSW.getQuery()))   { 
     351                                                oldCSW.setQuery(newCSW.getQuery()); 
     352                                        }                                        
    344353                                         
    345354                                        Iterator<QName> cswIter = oldCSW.getTypeNames().iterator(); 
     
    476485         
    477486        public List<ProviderStatistic> getProviderStatistic(List<Integer> providerID) throws NdgExecutionException { 
    478                  
    479                 //to delete and substitute with the commented code 
    480                 String sqlString = GET_ALL_PROVIDER_STATISTIC;           
    481                 /* 
     487 
    482488                String sqlString = GET_PROVIDER_STATISTIC; 
    483489                if (providerID == null || providerID.size() == 0) 
    484490                        sqlString = GET_ALL_PROVIDER_STATISTIC; 
    485                 */ 
    486491                 
    487492                Query query = emDiscovery.createNativeQuery(sqlString); 
     493 
     494                /*  
     495                  Patch because the DDS database use a text field instead of a integer as it should be 
     496                  To delete and use the code commented below 
     497                  */ 
     498                /*----------*/ 
     499                if (sqlString.equals(GET_PROVIDER_STATISTIC)) { 
     500                        List<String> ids = new ArrayList<String>(); 
     501                        for (Integer id : providerID) { 
     502                                ids.add(id.toString()); 
     503                        } 
     504                        query.setParameter("providerIDs", ids); 
     505                } 
     506                /*----------*/   
     507                 
     508                /* 
    488509                if (sqlString.equals(GET_PROVIDER_STATISTIC)) 
    489510                        query.setParameter("providerIDs", providerID); 
     511                */ 
     512                 
    490513                List<Object[]> origDocs = query.getResultList(); 
    491514                 
     
    495518                        ps = new ProviderStatistic(); 
    496519                        ps.setProviderID(-1); 
    497                         if (stat[1] != null && stat[1].getClass().isAssignableFrom(Integer.class)) 
    498                                 ps.setProviderID((Integer)stat[1]); 
     520                        if (stat[1] != null) { 
     521                                try { 
     522                                        Integer id = Integer.parseInt((String)stat[1]); 
     523                                        ps.setProviderID(id); 
     524                                } catch (NumberFormatException e) { 
     525                                        logger.error(e); 
     526                                } 
     527                        }                                
    499528                        ps.setIngestedRecord(((BigInteger)stat[0]).intValue()); 
    500529                        ret.add(ps); 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/HarvestRequest.java

    r7389 r7905  
    1 /* 
     1/** 
    22 * BSD Licence 
    3  * Copyright (c) 2009, Science & Technology Facilities Council (STFC) 
    4  * All rights reserved. 
    5  
    6  * See the LICENSE file in the source distribution of this software for 
    7  * the full license text.        
    8  * Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council). 
    9  * This software may be distributed under the terms of the 
    10  * Q Public License, version 1.0 or later. 
    11  * http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt 
     3 * Copyright (c) 2009, Science & Technology Facilities Council (STFC) All rights reserved. 
     4 * Redistribution and use in source and binary forms, with or without 
     5 * modification, are permitted provided that the following conditions are 
     6 * met: 
     7 * 
     8 *   - Redistributions of source code must retain the above copyright 
     9 *     notice, this list of conditions and the following disclaimer. 
     10 *   - Redistributions in binary form must reproduce the above 
     11 *     copyright notice, this list of conditions and the following disclaimer 
     12 *     in the documentation and/or other materials provided with the 
     13 *     distribution. 
     14 *   - Neither the name of the Science & Technology Facilities Council 
     15 *     (STFC) nor the names of its contributors may be used to endorse or 
     16 *     promote products derived from this software without specific prior 
     17 *     written permission. 
     18 * 
     19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
     22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
     23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
     24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
     25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
     26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
     27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
     29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     30 *  
    1231 */ 
    1332package ndg.services.revitalization.harvest; 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/csw/CSWAdapterHelper.java

    r7389 r7905  
     1/** 
     2 * BSD Licence Copyright (c) 2009, Science & Technology Facilities Council 
     3 * (STFC) All rights reserved. Redistribution and use in source and binary 
     4 * forms, with or without modification, are permitted provided that the 
     5 * following conditions are met: 
     6 *  
     7 * - Redistributions of source code must retain the above copyright notice, this 
     8 * list of conditions and the following disclaimer. - Redistributions in binary 
     9 * form must reproduce the above copyright notice, this list of conditions and 
     10 * the following disclaimer in the documentation and/or other materials provided 
     11 * with the distribution. - Neither the name of the Science & Technology 
     12 * Facilities Council (STFC) nor the names of its contributors may be used to 
     13 * endorse or promote products derived from this software without specific prior 
     14 * written permission. 
     15 *  
     16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
     17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
     18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
     19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
     20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
     21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
     22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
     23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
     24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
     25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
     26 * POSSIBILITY OF SUCH DAMAGE. 
     27 *  
     28 */ 
    129package ndg.services.revitalization.harvest.csw; 
    230 
     
    836 
    937import ndg.common.exception.NdgExecutionException; 
     38import ndg.common.jaxb.JAXBManager; 
    1039import ndg.services.revitalization.harvest.HarvestRequest; 
    1140import ndg.services.revitalization.harvest.ProviderAdapterHelper; 
     
    1342import ndg.services.revitalization.jpa.ProviderCommon; 
    1443import ndg.services.schemas.revitalization.CSWProviderDetailsType; 
     44import ndg.services.schemas.revitalization.CSWProviderDetailsType.TypeName; 
    1545import ndg.services.schemas.revitalization.ObjectFactory; 
    16 import ndg.services.schemas.revitalization.CSWProviderDetailsType.TypeName; 
    1746 
    18 public class CSWAdapterHelper  
    19                 implements ProviderAdapterHelper<CswProvider, CSWProviderDetailsType, CSWHarvester> { 
     47import org.apache.log4j.Logger; 
     48 
     49/** 
     50 * Adapts the ProviderCommon to the CSW specific fields 
     51 *  
     52 * @author Maurizio Nagni <maurizio.nagni@stfc.ac.uk> 
     53 */ 
     54public class CSWAdapterHelper implements ProviderAdapterHelper<CswProvider, CSWProviderDetailsType, CSWHarvester> { 
     55 
     56        private final static Logger logger = Logger.getLogger(CSWAdapterHelper.class.getName()); 
     57 
     58        private JAXBManager manager; 
     59         
     60        /** 
     61         *  
     62         */ 
     63        public CSWAdapterHelper() { 
     64                super(); 
     65                manager = JAXBManager.getInstance(); 
     66        } 
    2067 
    2168        @Override 
    22         public CSWHarvester assembleHarvester(ProviderCommon provider, HarvestRequest request) 
    23                         throws NdgExecutionException { 
    24                 CSWHarvestRequest harvesterReq = new CSWHarvestRequest(request, (CswProvider)provider);                  
     69        public CSWHarvester assembleHarvester(ProviderCommon provider, HarvestRequest request) throws NdgExecutionException { 
     70                CSWHarvestRequest harvesterReq = new CSWHarvestRequest(request, (CswProvider) provider); 
    2571                return new CSWHarvester(harvesterReq, request.getProcess()); 
    2672        } 
     
    4187 
    4288                nprovider.setOutputSchema(providerDetails.getOutputSchema()); 
     89 
    4390                if (providerDetails.getTypeName() != null) { 
    4491                        nprovider.setTypeNames(new ArrayList<QName>()); 
     
    5097                        } 
    5198                } 
     99 
     100                if (providerDetails.getQuery() != null) { 
     101                        nprovider.setQuery(providerDetails.getQuery()); 
     102                } 
     103 
     104 
    52105                return nprovider; 
    53106        } 
     
    57110                CSWProviderDetailsType pdt = of.createCSWProviderDetailsType(); 
    58111                pdt.setOutputSchema(provider.getOutputSchema()); 
     112 
    59113                if (provider.getTypeNames() != null) { 
    60114                        Iterator<QName> iter = provider.getTypeNames().iterator(); 
     
    69123                        } 
    70124                } 
     125 
     126                if (provider.getQuery() != null) { 
     127                        pdt.setQuery(provider.getQuery()); 
     128                } 
    71129                return of.createCSWProvider(pdt); 
    72130        } 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/csw/CSWHarvestRequest.java

    r7389 r7905  
    1 /* 
    2  * BSD Licence 
    3  * Copyright (c) 2009, Science & Technology Facilities Council (STFC) 
    4  * All rights reserved. 
    5  
    6  * See the LICENSE file in the source distribution of this software for 
    7  * the full license text.        
    8  * Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council). 
    9  * This software may be distributed under the terms of the 
    10  * Q Public License, version 1.0 or later. 
    11  * http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt 
     1/** 
     2 * BSD Licence Copyright (c) 2009, Science & Technology Facilities Council 
     3 * (STFC) All rights reserved. Redistribution and use in source and binary 
     4 * forms, with or without modification, are permitted provided that the 
     5 * following conditions are met: 
     6 *  
     7 * - Redistributions of source code must retain the above copyright notice, this 
     8 * list of conditions and the following disclaimer. - Redistributions in binary 
     9 * form must reproduce the above copyright notice, this list of conditions and 
     10 * the following disclaimer in the documentation and/or other materials provided 
     11 * with the distribution. - Neither the name of the Science & Technology 
     12 * Facilities Council (STFC) nor the names of its contributors may be used to 
     13 * endorse or promote products derived from this software without specific prior 
     14 * written permission. 
     15 *  
     16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
     17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
     18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
     19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
     20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
     21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
     22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
     23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
     24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
     25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
     26 * POSSIBILITY OF SUCH DAMAGE. 
     27 *  
    1228 */ 
    1329package ndg.services.revitalization.harvest.csw; 
     
    1632import java.util.List; 
    1733 
     34import javax.xml.bind.JAXBException; 
    1835import javax.xml.namespace.QName; 
    1936 
     37import ndg.common.exception.ResourceNotAvailable; 
     38import ndg.common.jaxb.JAXBManager; 
    2039import ndg.services.revitalization.harvest.HarvestRequest; 
    2140import ndg.services.revitalization.jpa.CswProvider; 
     41import net.opengis.csw._202.QueryType; 
     42 
     43import org.apache.commons.io.IOUtils; 
     44import org.apache.log4j.Logger; 
    2245 
    2346/** 
    24  * Represents an Harvest request to a CSW provider  
    25  * @author Maurizio Nagni <maurizio.nagni@stfc.ac.uk>   
     47 * Represents an Harvest request to a CSW provider 
     48 *  
     49 * @author Maurizio Nagni <maurizio.nagni@stfc.ac.uk> 
    2650 */ 
    2751public class CSWHarvestRequest extends HarvestRequest { 
    2852 
    29         /** 
    30          *  
    31          */ 
    3253        private static final long serialVersionUID = -2304315475605358186L; 
    3354 
    3455        private final String outputSchema; 
    35          
     56 
    3657        private final List<QName> queryTypeNames = new ArrayList<QName>(); 
    37          
     58 
    3859        private String url; 
    39          
     60 
     61        private QueryType query; 
     62 
     63        private final static Logger logger = Logger.getLogger(CSWHarvestRequest.class.getName()); 
     64 
    4065        public CSWHarvestRequest(HarvestRequest request, CswProvider provider) { 
    4166                super(request.getProcess(), request.getEmailID()); 
     67                JAXBManager manager = JAXBManager.getInstance(); 
    4268                url = provider.getBaseUrl(); 
    4369                queryTypeNames.addAll(provider.getTypeNames()); 
    4470                outputSchema = provider.getOutputSchema(); 
     71                if (provider.getQuery() != null) { 
     72                        try { 
     73                                query = manager.unmarshall(IOUtils.toInputStream(provider.getQuery()), QueryType.class); 
     74                        } catch (ResourceNotAvailable e) { 
     75                                logger.info("Cannot set the ogc:Filter", e); 
     76                        } catch (JAXBException e) { 
     77                                logger.info("Cannot set the ogc:Filter", e); 
     78                        } 
     79                } 
    4580        } 
    4681 
    4782        public String getUrl() { 
    4883                return url; 
    49         }                
    50          
     84        } 
     85 
    5186        /** 
    5287         * Returns the CSW's GetRecord outputSchema 
    53          * @return a List of QNames   
    54          * */    
     88         *  
     89         * @return a List of QNames 
     90         * */ 
    5591        public String getOutputSchema() { 
    5692                return outputSchema; 
     
    5995        /** 
    6096         * Returns the CSW's GetRecords Query typeNames attribute 
    61          * @return a List of QNames   
     97         *  
     98         * @return a List of QNames 
    6299         * */ 
    63100        public List<QName> getQueryTypeNames() { 
    64101                return queryTypeNames; 
    65         }        
     102        } 
     103 
     104        /** 
     105         * Returns the csw:Query element 
     106         *  
     107         * @return the filter 
     108         */ 
     109        public QueryType getQuery() { 
     110                return query; 
     111        } 
    66112} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/csw/CSWHarvester.java

    r7783 r7905  
    1111package ndg.services.revitalization.harvest.csw; 
    1212 
     13import java.io.BufferedInputStream; 
     14import java.io.ByteArrayInputStream; 
     15import java.io.ByteArrayOutputStream; 
    1316import java.io.File; 
    1417import java.io.IOException; 
     
    3538import ndg.services.revitalization.harvest.HarvesterBase; 
    3639import ndg.services.revitalization.jpa.HiProcess; 
    37 import net.opengis.csw._202.ElementSetNameType; 
    38 import net.opengis.csw._202.ElementSetType; 
    3940import net.opengis.csw._202.GetRecordsResponseType; 
    4041import net.opengis.csw._202.GetRecordsType; 
    4142import net.opengis.csw._202.ObjectFactory; 
    42 import net.opengis.csw._202.QueryType; 
    4343import net.opengis.csw._202.ResultType; 
    4444 
     45import org.apache.commons.io.IOUtils; 
     46import org.apache.log4j.Logger; 
    4547import org.apache.xerces.dom.ElementNSImpl; 
    4648import org.w3c.dom.Document; 
     
    6163         */ 
    6264        private static final long serialVersionUID = 7555651653412200168L; 
     65 
     66        private final static Logger logger = Logger.getLogger(CSWHarvester.class.getName()); 
    6367 
    6468        private GetRecordsType recordsRequest; 
     
    100104                        conn.setRequestProperty("Content-Type", "text/xml"); 
    101105                        ((HttpURLConnection) conn).setRequestMethod("POST"); 
     106                        if (logger.isDebugEnabled()) { 
     107                                ByteArrayOutputStream bo = new ByteArrayOutputStream(); 
     108                                CSWHarvester.manager.marshall(recordsRequest, bo); 
     109                                logger.debug("POST: " + new String(bo.toByteArray()));  
     110                        } 
     111                         
    102112                        CSWHarvester.manager.marshall(recordsRequest, conn.getOutputStream()); 
    103                         return getResponseType(conn.getInputStream()); 
     113                         
     114                        InputStream is = conn.getInputStream(); 
     115                        if (logger.isDebugEnabled()) { 
     116                                byte[] ba =  IOUtils.toByteArray(is); 
     117                                logger.debug("POST response: " + new String(ba));  
     118                                is = new ByteArrayInputStream(ba); 
     119                        }                                                
     120                        return getResponseType(is); 
     121                         
    104122                } catch (ProtocolException e) { 
    105123                        throw new NdgExecutionException(e.getMessage(), e); 
     
    132150                ret.setResultType(ResultType.RESULTS); 
    133151 
    134                 QueryType qt = of.createQueryType(); 
    135                 qt.getTypeNames().addAll(getHarvestRequest().getQueryTypeNames()); 
    136  
    137                 ElementSetNameType nameType = of.createElementSetNameType(); 
    138                 nameType.setValue(ElementSetType.BRIEF); 
    139                 qt.setElementSetName(nameType); 
    140  
    141                 ret.setAbstractQuery(of.createQuery(qt)); 
     152                if (getHarvestRequest().getQuery() != null) { 
     153                        ret.setAbstractQuery(of.createQuery(getHarvestRequest().getQuery())); 
     154                } 
    142155                recordsRequest = ret; 
    143156        } 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/jpa/CswProvider.java

    r7660 r7905  
    1 /* 
     1/** 
    22 * BSD Licence 
    3  * Copyright (c) 2009, Science & Technology Facilities Council (STFC) 
    4  * All rights reserved. 
    5  
    6  * See the LICENSE file in the source distribution of this software for 
    7  * the full license text.        
    8  * Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council). 
    9  * This software may be distributed under the terms of the 
    10  * Q Public License, version 1.0 or later. 
    11  * http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt 
     3 * Copyright (c) 2009, Science & Technology Facilities Council (STFC) All rights reserved. 
     4 * Redistribution and use in source and binary forms, with or without 
     5 * modification, are permitted provided that the following conditions are 
     6 * met: 
     7 * 
     8 *   - Redistributions of source code must retain the above copyright 
     9 *     notice, this list of conditions and the following disclaimer. 
     10 *   - Redistributions in binary form must reproduce the above 
     11 *     copyright notice, this list of conditions and the following disclaimer 
     12 *     in the documentation and/or other materials provided with the 
     13 *     distribution. 
     14 *   - Neither the name of the Science & Technology Facilities Council 
     15 *     (STFC) nor the names of its contributors may be used to endorse or 
     16 *     promote products derived from this software without specific prior 
     17 *     written permission. 
     18 * 
     19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
     22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
     23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
     24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
     25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
     26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
     27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
     29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     30 *  
    1231 */ 
    1332package ndg.services.revitalization.jpa; 
     
    1736import javax.persistence.Column; 
    1837import javax.persistence.Entity; 
    19 import javax.persistence.PersistenceContext; 
    2038import javax.persistence.PrimaryKeyJoinColumn; 
    2139import javax.persistence.Table; 
     
    4361        private String outputSchema; 
    4462         
     63        private String query; 
     64         
    4565        public CswProvider() { 
    4666    } 
     
    6383        public void setOutputSchema(String outputSchema) { 
    6484                this.outputSchema = outputSchema; 
     85        } 
     86 
     87        @Column(name="query")    
     88        public String getQuery() { 
     89                return query; 
     90        } 
     91 
     92        public void setQuery(String query) { 
     93                this.query = query; 
    6594        }        
    6695} 
Note: See TracChangeset for help on using the changeset viewer.