Changeset 7316


Ignore:
Timestamp:
11/08/10 17:11:54 (9 years ago)
Author:
mnagni
Message:

implemented the DoIngest? (missing the final email)

Location:
RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization
Files:
3 added
14 edited
2 copied
2 moved

Legend:

Unmodified
Added
Removed
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/MailHelper.java

    r7312 r7316  
    3232                } 
    3333                 
    34                 String text = mmr.getConfigurationParameter(ServiceConfigurationParameter.NEW_DISPATCHED_HARVEST_MAIL.name()); 
     34                String text = mmr.getConfigurationParameter(ServiceConfigurationParameter.NEW_DISPATCHED_HARVEST_MAIL); 
    3535                Object[] params =  {common.toString(), process.getId()};         
    3636                dispatchMail(mailTo, "ProcessId:" + process.getId(), text, params); 
    3737        } 
    3838         
    39         public void terminatedHarvestMail(int providerId, HiProcess hiProcess) throws NdgExecutionException { 
     39        public void terminatedHarvestMail(HiProcess hiProcess) throws NdgExecutionException { 
    4040                ModelManagerRemote mmr = EJBBeanFactory.getModelManager(); 
    41                 ProviderCommon common = mmr.getProviderCommon(providerId); 
     41                ProviderCommon common = mmr.getProviderCommon(hiProcess.getProviderId()); 
    4242                List<String> mailTo = new ArrayList<String>(); 
    4343                for (ProviderEmail email : common.getProviderEmails()) { 
    4444                                mailTo.add(email.getEmail()); 
    4545                } 
    46                 String text = mmr.getConfigurationParameter(ServiceConfigurationParameter.HARVEST_TERMINATED_MAIL.name()); 
     46                String text = mmr.getConfigurationParameter(ServiceConfigurationParameter.HARVEST_TERMINATED_MAIL); 
    4747                Object[] params =  {hiProcess.getId()};  
    4848                dispatchMail(mailTo, "ProcessId:" + hiProcess.getId(), text, params); 
    4949        } 
    5050         
     51        public void terminatedIngestMail(HiProcess hiProcess) throws NdgExecutionException { 
     52                //to be done 
     53        } 
    5154         
    5255        private void dispatchMail(List<String> mailTo, String subject, String msgText, Object[] msgTextParams) throws NdgExecutionException { 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/dictionary/ServiceConfigurationParameter.java

    r7282 r7316  
    44        HARVEST_ROOT_PATH, 
    55        NEW_DISPATCHED_HARVEST_MAIL, 
    6         HARVEST_TERMINATED_MAIL 
     6        HARVEST_TERMINATED_MAIL, 
     7        DO_INGEST_CMD 
    78} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/AsyncProcessManager.java

    r7312 r7316  
    1 package ndg.services.revitalization.harvest.ejb; 
     1package ndg.services.revitalization.ejb; 
    22 
    33import javax.ejb.Asynchronous; 
     
    66import ndg.common.exception.NdgException; 
    77import ndg.common.exception.NdgExecutionException; 
    8 import ndg.services.revitalization.harvest.HarvestRequest; 
    9 import ndg.services.revitalization.harvest.Harvester; 
    10 import ndg.services.revitalization.harvest.ejb.interfaces.AsyncHarvesterLocal; 
    11 import ndg.services.revitalization.harvest.ejb.interfaces.AsyncHarvesterRemote; 
     8import ndg.services.revitalization.InvokeProcess; 
     9import ndg.services.revitalization.harvest.ejb.interfaces.AsyncProcessManagerLocal; 
     10import ndg.services.revitalization.harvest.ejb.interfaces.AsyncProcessManagerRemote; 
    1211 
    13 @Stateless(name="ejb/AsyncHarvest") 
    14 public class AsyncHarvester implements AsyncHarvesterLocal, AsyncHarvesterRemote { 
     12@Stateless(name="ejb/AsyncProcessManager") 
     13public class AsyncProcessManager implements AsyncProcessManagerLocal, AsyncProcessManagerRemote { 
    1514 
    16         /* (non-Javadoc) 
    17          * @see ndg.services.revitalization.oai.AsyncHarvesterInterface#doHarvest(ndg.services.revitalization.oai.HarvestRequest) 
    18          */      
    1915        @Asynchronous 
    20         public final void doHarvest(Harvester<? extends HarvestRequest> request) {               
     16        public final void invoke(InvokeProcess process) {                
    2117                try { 
    22                         request.invokeHarvest(); 
     18                        process.invoke(); 
    2319                } catch (NdgExecutionException ex) { 
    2420                        manageError(ex); 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/DPWS.java

    r7312 r7316  
    88import ndg.services.revitalization.ejb.interfaces.DPWSLocal; 
    99import ndg.services.revitalization.ejb.interfaces.DPWSRemote; 
     10import ndg.services.revitalization.executor.ExecuteDoIngest; 
    1011import ndg.services.revitalization.executor.ExecuteDoNewProvider; 
    1112import ndg.services.revitalization.executor.ExecuteGetHarvestHistory; 
     
    3334import ndg.services.schemas.revitalization.GetProviderDetailsRequest; 
    3435import ndg.services.schemas.revitalization.GetProviderDetailsResponse; 
    35 import ndg.services.schemas.revitalization.ObjectFactory; 
    3636 
    3737/** 
     
    4141@Stateless(name="dpws") 
    4242public class DPWS implements DPWSRemote, DPWSLocal { 
    43      
    44         private final static ObjectFactory of = new ObjectFactory(); 
    4543         
    4644        @WebMethod(operationName="doHarvest") 
     
    9492        @WebMethod(operationName="doIngest") 
    9593        public DoIngestResponse doIngest(@WebParam(name="request") DoIngestRequest request) { 
    96                 return of.createDoIngestResponse(); 
     94                ServiceExecutor<DoIngestRequest, DoIngestResponse> executor = new ExecuteDoIngest(); 
     95                return executor.doService(request); 
    9796        } 
    9897} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/JMSConsumer.java

    r7312 r7316  
    1 package ndg.services.revitalization.harvest.ejb; 
     1package ndg.services.revitalization.ejb; 
    22 
    3 import javax.annotation.Resource; 
    43import javax.ejb.ActivationConfigProperty; 
    54import javax.ejb.EJB; 
    65import javax.ejb.MessageDriven; 
    7 import javax.ejb.MessageDrivenContext; 
    86import javax.ejb.TransactionManagement; 
    97import javax.ejb.TransactionManagementType; 
     
    1210import javax.jms.ObjectMessage; 
    1311 
    14 import ndg.common.exception.NdgExecutionException; 
    15 import ndg.services.revitalization.exception.NdgHarvestNotExistingException; 
    16 import ndg.services.revitalization.harvest.HarvestRequest; 
    17 import ndg.services.revitalization.harvest.Harvester; 
    18 import ndg.services.revitalization.harvest.ejb.interfaces.AsyncHarvesterLocal; 
     12import ndg.services.revitalization.InvokeProcess; 
     13import ndg.services.revitalization.harvest.ejb.interfaces.AsyncProcessManagerLocal; 
    1914 
    2015@MessageDriven(activationConfig = { 
     
    2318                @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Dups-ok-acknowledge")}) 
    2419@TransactionManagement(value = TransactionManagementType.BEAN) 
    25 public class HarvestRequestConsumer implements MessageListener { 
     20public class JMSConsumer implements MessageListener { 
    2621         
    2722        @EJB 
    28         private AsyncHarvesterLocal executor; 
     23        private AsyncProcessManagerLocal executor; 
    2924         
    3025        public void onMessage(Message message) { 
     
    3227                        ObjectMessage objMessage = (ObjectMessage) message; 
    3328 
    34                         if (!(objMessage.getObject() instanceof Harvester<?>)) 
    35                                 return; 
     29                        if ((objMessage.getObject() instanceof InvokeProcess)) 
     30                                executor.invoke((InvokeProcess) objMessage.getObject()); 
    3631                         
    37                         invokeHarvest((Harvester<?>) objMessage.getObject()); 
     32                        return; 
     33                         
    3834                } catch (Exception e) { 
    3935                        e.printStackTrace(); 
    4036                } 
    4137        } 
    42          
    43         @Resource  
    44         MessageDrivenContext ejbContext; 
    45          
    46         /** 
    47          * Dispatches the harvest request to the proper harvester. 
    48          * @param the service request object 
    49          * @throws NdgHarvestNotExistingException if <code>doRequest</code> does not contain enough information or 
    50          * the harvest object does not exist. 
    51          * @throws  NdgExecutionException if other errors occour 
    52          **/ 
    53         private void invokeHarvest(Harvester<? extends HarvestRequest> harvester) throws NdgHarvestNotExistingException, NdgExecutionException {                 
    54                 executor.doHarvest(harvester); 
    55         } 
    5638} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/ModelManager.java

    r7312 r7316  
    1717import javax.persistence.Query; 
    1818 
     19import ndg.services.revitalization.dictionary.ServiceConfigurationParameter; 
    1920import ndg.services.revitalization.ejb.interfaces.HiProcessModelLocal; 
    2021import ndg.services.revitalization.ejb.interfaces.ModelManagerLocal; 
     
    4243        private final static String GET_OAI_PROVIDER = "from OaiProvider p where p.id=:id"; 
    4344        private final static String GET_CSW_PROVIDER = "from CswProvider p where p.id=:id"; 
    44         private final static String GET_INGESTER_HISTORY = "from IngestSearchLogging p where p.id IN (:processIDs)"; 
    45         private final static String GET_HARVEST_HISTORY = "from HarvestLog p where p.reqId IN (:processIDs)"; 
     45        private final static String GET_INGESTER_HISTORY = "from IngestSearchLogging p where p.id IN (:processIds)"; 
     46        private final static String GET_HARVEST_HISTORY = "from HarvestLog p where p.reqId IN (:processIds)"; 
    4647        private final static String GET_HARVEST_LOG_BY_PROVIDER = "select l, p.providerId from HarvestLog l, HiProcess p  where l.reqId=p.id and p.providerId=:providerID and l.startHarvest >= :start and l.stopHarvest <= :end"; 
    4748        private final static String GET_HARVEST_LOG_ALL_PROVIDER = "select l, p.providerId from HarvestLog l, HiProcess p  where l.reqId=p.id and l.startHarvest >= :start and l.stopHarvest <= :end"; 
     
    183184        } 
    184185 
     186        public HiProcess getHiProcess(Integer processID) { 
     187                List<Integer> id = new ArrayList<Integer>(); 
     188                id.add(processID); 
     189                List<HiProcess> rets = processModel.getHiProcess(id); 
     190                return rets.size()>0 ? rets.get(0) : null; 
     191        } 
     192         
    185193        public ProviderCommon getProviderCommon(int commonId) { 
    186194                Query query = em.createQuery(GET_PROVIDER_COMMON); 
     
    192200        } 
    193201 
    194         public String getConfigurationParameter(String parameterName) { 
     202        public String getConfigurationParameter(ServiceConfigurationParameter param) { 
    195203                Query query = em.createQuery(GET_CONFIGURATION_PARAMETER); 
    196                 query.setParameter("id", parameterName); 
     204                query.setParameter("id", param.name()); 
    197205                List<ServiceConfig> values = query.getResultList(); 
    198206                if (values == null || values.size() == 0) 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/interfaces/ModelManagerLocal.java

    r7312 r7316  
    55import javax.ejb.Local; 
    66 
     7import ndg.services.revitalization.dictionary.ServiceConfigurationParameter; 
    78import ndg.services.revitalization.executor.ProviderLogs; 
    89import ndg.services.revitalization.jpa.HarvestLog; 
     
    4243        public <T extends ProviderCommon> void createNewProvider(T provider); 
    4344         
    44         public String getConfigurationParameter(String param); 
     45        public String getConfigurationParameter(ServiceConfigurationParameter param); 
    4546         
    4647        public List<? extends ProviderCommon> getHarvesterConfiguration(List<Integer> commonIDs); 
     48         
     49        /** 
     50         * Returns a single {@link HiProcess}, if exist, associated with the given <code>processID</code> 
     51         * @param processID the HiProcess ID 
     52         * @return an HiProcess or <code>null</code> if not exists 
     53         * */ 
     54        public HiProcess getHiProcess(Integer processID); 
    4755} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/ejb/interfaces/ModelManagerRemote.java

    r7312 r7316  
    55import javax.ejb.Remote; 
    66 
     7import ndg.services.revitalization.dictionary.ServiceConfigurationParameter; 
    78import ndg.services.revitalization.executor.ProviderLogs; 
    89import ndg.services.revitalization.jpa.HarvestLog; 
     
    4344        public <T extends ProviderCommon> void createNewProvider(T provider); 
    4445         
    45         public String getConfigurationParameter(String parameterName); 
     46        public String getConfigurationParameter(ServiceConfigurationParameter param); 
    4647         
    4748        public <T extends ProviderCommon> T getHarvesterConfiguration(int commonID); 
     
    5051         
    5152        public ProviderCommon getProviderCommon(int commonId); 
     53         
     54        /** 
     55         * Returns a single {@link HiProcess}, if exist, associated with the given <code>processID</code> 
     56         * @param processID the HiProcess ID 
     57         * @return an HiProcess or <code>null</code> if not exists 
     58         * */ 
     59        public HiProcess getHiProcess(Integer processID); 
    5260} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/executor/ExecuteDoNewProvider.java

    r7312 r7316  
    22 
    33import java.util.ArrayList; 
    4 import java.util.Iterator; 
    54import java.util.List; 
    65 
     
    8079        }        
    8180         
    82         private void checkRemoved(List<ProviderEmail> oldEmails, List<EmailContactType> newEmails) {             
    83                 Iterator<ProviderEmail> iterator = oldEmails.iterator(); 
    84                 ProviderEmail item = null; 
    85                 while (iterator.hasNext()) { 
    86                         item = iterator.next(); 
    87                         boolean delete = true; 
    88                         for (EmailContactType nemail : newEmails) {                              
    89                                 if (item.getId().equals(nemail.getID())) { 
    90                                         delete = false; 
    91                                         break; 
    92                                 }                        
    93                         } 
    94                         if (delete) { 
    95                                 iterator.remove(); 
    96                         } 
    97                 } 
    98         } 
    99          
    100         private ProviderEmail getNewUpdateEmail(List<ProviderEmail> emails, Integer id) { 
    101                 ProviderEmail ret = new ProviderEmail(); 
    102                 if (id == null)  
    103                         return ret; 
    104                  
    105                 int index = -1;   
    106                 ret.setId(id); 
    107                 index = emails.indexOf(ret); 
    108                 if (index > -1) { 
    109                         ret = emails.get(index); 
    110                 } else { 
    111                         ret = new ProviderEmail(); 
    112                         emails.add(ret); 
    113                 } 
    114                 return ret; 
    115         } 
    116          
    11781        private <T extends ProviderCommon> void prepareCommonProvider(ProviderDetail pdetails, T provider) { 
    11882                ProviderCommonType common = pdetails.getProviderCommon();                
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/executor/ExecuteHarvest.java

    r7312 r7316  
    5353        } 
    5454         
    55         private void dispatchHarvestRequest(Serializable doHarvestRequest) throws NdgExecutionException { 
     55        private void dispatchHarvestRequest(Serializable harvester) throws NdgExecutionException { 
    5656                JMSDispatcherRemote jmsDispatcher = EJBBeanFactory.getMessageDispatcher(); 
    57                 jmsDispatcher.dispatchHarvestRequest(doHarvestRequest); 
     57                jmsDispatcher.dispatchHarvestRequest(harvester); 
    5858        } 
    5959} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/executor/ProviderAdapter.java

    r7312 r7316  
    4747                ProviderCommon provider = mm.getHarvesterConfiguration(doRequest.getProviderID()); 
    4848 
    49                 File tmpDir = new File(mm.getConfigurationParameter(ServiceConfigurationParameter.HARVEST_ROOT_PATH.name()) 
     49                File tmpDir = new File(mm.getConfigurationParameter(ServiceConfigurationParameter.HARVEST_ROOT_PATH) 
    5050                                + "/" + Long.toString(Calendar.getInstance().getTimeInMillis())); 
    5151                if (!tmpDir.mkdir()) 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/executor/ProviderLogs.java

    r7312 r7316  
    88 
    99public class ProviderLogs implements Serializable { 
     10        /** 
     11         *  
     12         */ 
     13        private static final long serialVersionUID = -7684866617261132458L; 
    1014        private final List<HarvestLog> logs = new ArrayList<HarvestLog>(); 
    1115        private final Integer providerID; 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/executor/ServiceExecutor.java

    r7301 r7316  
    22 
    33import ndg.common.MessageFormatter; 
    4 import ndg.common.exception.NdgException; 
    54import ndg.common.exception.NdgExecutionException; 
    65import ndg.services.schemas.revitalization.ConfirmationType; 
     
    1110 
    1211public abstract class ServiceExecutor<Y, T extends ResponseType> { 
    13          
     12 
    1413        private final static ObjectFactory of = new ObjectFactory(); 
    1514        private T response = null; 
    1615        public final static String ERROR = "Error"; 
    1716        public final static String OK = "OK"; 
    18          
     17 
    1918        private final static Logger logger = Logger.getLogger(ServiceExecutor.class.getName()); 
    20          
     19 
    2120        static Logger getLogger() { 
    2221                return logger; 
    2322        } 
    24          
     23 
    2524        static ObjectFactory getOf() { 
    2625                return of; 
    2726        } 
    2827 
    29         public final T doService(Y request){ 
     28        public final T doService(Y request) { 
    3029                response = getResponse(); 
    3130                try { 
     
    3736                return response; 
    3837        } 
    39          
     38 
    4039        protected final T getResponse() { 
    4140                if (this.response == null) { 
    4241                        this.response = createResponse(); 
    4342                        this.response.setConfirmation(getOf().createConfirmationType()); 
    44                 }  
     43                } 
    4544                return this.response; 
    4645        } 
    47          
     46 
    4847        private void manageSuccess(ConfirmationType ct) { 
    4948                ct.setStatus(OK); 
    5049        } 
    5150 
    52         private void manageError(ConfirmationType ct, NdgException ex) { 
     51        private void manageError(ConfirmationType ct, NdgExecutionException ex) { 
    5352                MessageFormatter mf = new MessageFormatter(); 
    54                 ct.setMessage(mf.getFormattedText(ex.getBundlMessage())); 
     53                if (ex.getBundlMessage() != null) { 
     54                        ct.setMessage(mf.getFormattedText(ex.getBundlMessage()));        
     55                } else { 
     56                        ct.setMessage(mf.getFormattedText(ex.getMessage())); 
     57                } 
    5558                ct.setStatus(ERROR); 
     59                advanceErrorManage(ct, ex); 
    5660        } 
    57          
     61 
     62        /** 
     63         * Overwriting this method allows the class to customize/implements further actions (send 
     64         * mail, insert in a database log, send a message, etc) other than the basic ones 
     65         *   
     66         **/ 
     67        protected void advanceErrorManage(ConfirmationType ct, NdgExecutionException ex) { 
     68 
     69        } 
     70 
    5871        protected abstract T createResponse(); 
     72 
    5973        protected abstract void execute(Y request) throws NdgExecutionException; 
    6074} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/HarvestRequest.java

    r7312 r7316  
    11package ndg.services.revitalization.harvest; 
     2 
     3import java.io.Serializable; 
    24 
    35 
     
    68 * Represents an Harvest request 
    79 **/ 
    8 public class HarvestRequest { 
     10public class HarvestRequest implements Serializable { 
    911         
     12        /** 
     13         *  
     14         */ 
     15        private static final long serialVersionUID = 4539301981210054562L; 
    1016        final private int providerID; 
    1117        final private String url; 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/Harvester.java

    r7312 r7316  
    33import java.io.Serializable; 
    44 
    5 import ndg.common.exception.NdgExecutionException; 
     5import ndg.services.revitalization.InvokeProcess; 
    66 
    7  
    8 public interface Harvester<T extends HarvestRequest> extends Serializable { 
    9         /** 
    10          * Invokes the harvest operation  
    11          **/ 
    12         public void invokeHarvest() throws NdgExecutionException; 
    13          
     7public interface Harvester<T extends HarvestRequest> extends Serializable, InvokeProcess { 
    148        public T getHarvestRequest(); 
    159} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/HarvesterBase.java

    r7312 r7316  
    11package ndg.services.revitalization.harvest; 
    22 
     3import java.io.Serializable; 
    34import java.sql.Timestamp; 
    45import java.util.ArrayList; 
     
    3738        } 
    3839         
    39         public final void invokeHarvest() throws NdgExecutionException { 
     40        @Override 
     41        public final void invoke() throws NdgExecutionException { 
    4042                initializeHarvesting();          
    4143                doHarvest(); 
     
    7072                EJBBeanFactory.getModelManager().updateHarvestingLogAndStatus(hiProcess, harvestLog); 
    7173                 
    72                 MailHelper.getInstance().terminatedHarvestMail(request.getProviderID(), getHiProcess()); 
     74                MailHelper.getInstance().terminatedHarvestMail(getHiProcess()); 
    7375        } 
    7476         
     
    7779        } 
    7880         
    79         protected class HarvestResult { 
     81        protected class HarvestResult implements Serializable { 
     82                /** 
     83                 *  
     84                 */ 
     85                private static final long serialVersionUID = 5961172109741702814L; 
    8086                int totRecs; 
    8187                Timestamp startTime; 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/ejb/interfaces/AsyncProcessManagerLocal.java

    r7312 r7316  
    33import javax.ejb.Local; 
    44 
    5 import ndg.services.revitalization.harvest.HarvestRequest; 
    6 import ndg.services.revitalization.harvest.Harvester; 
     5import ndg.services.revitalization.InvokeProcess; 
    76 
    87@Local 
    9 public interface AsyncHarvesterLocal { 
     8public interface AsyncProcessManagerLocal { 
    109 
    1110        /**  
    12          * Invokes the harvest method  
     11         * Invokes the a process  
    1312         * */ 
    14         public void doHarvest(Harvester<? extends HarvestRequest> request); 
    15  
     13        public void invoke(InvokeProcess process); 
    1614} 
  • RevitalizationWS/ws/DPWS/trunk/src/main/java/ndg/services/revitalization/harvest/ejb/interfaces/AsyncProcessManagerRemote.java

    r7312 r7316  
    33import javax.ejb.Remote; 
    44 
    5 import ndg.services.revitalization.harvest.HarvestRequest; 
    6 import ndg.services.revitalization.harvest.Harvester; 
     5import ndg.services.revitalization.InvokeProcess; 
    76 
    87@Remote 
    9 public interface AsyncHarvesterRemote { 
     8public interface AsyncProcessManagerRemote { 
    109 
    1110        /**  
    12          * Invokes the harvest method  
     11         * Invokes the a process  
    1312         * */ 
    14         public void doHarvest(Harvester<? extends HarvestRequest> harvester); 
     13        public void invoke(InvokeProcess process); 
    1514 
    1615} 
Note: See TracChangeset for help on using the changeset viewer.