Advertisement
Guest User

Untitled

a guest
Jun 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. package org.openxdata.server.sms.send.statistics.task;
  2.  
  3. import java.util.List;
  4. import java.util.ArrayList;
  5. import java.util.Hashtable;
  6.  
  7.  
  8. import org.apache.log4j.Logger;
  9.  
  10. import org.openxdata.server.Task;
  11. import org.openxdata.server.admin.model.FormData;
  12. import org.openxdata.server.admin.model.FormDefVersion;
  13. import org.openxdata.server.admin.model.TaskDef;
  14. import org.openxdata.server.context.Context;
  15. import org.openxdata.server.dao.jdbc.JdbcRdmsExporterDAO;
  16. import org.openxdata.server.export.rdbms.engine.Constants;
  17. import org.quartz.JobExecutionContext;
  18. import org.quartz.JobExecutionException;
  19. import org.springframework.scheduling.quartz.QuartzJobBean;
  20.  
  21. /**
  22. * Class represents the task that handles the sending of statistics to Statkeholders in a school
  23. * The statistics in sent out as an SMS
  24. * @author Simon, smuwanga@cit.mak.ac.ug
  25. *
  26. */
  27. public class SendStaticsTask extends QuartzJobBean implements Task{
  28.  
  29. private TaskDef taskDef = null;
  30. private boolean running = false;
  31.  
  32.  
  33. private static final String DB_MYSQL="MYSQL";
  34. private static final String DB_ORACLE ="ORACLE";
  35. private static final String DB_SQLSERVER ="SQLSERVER";
  36. private static final String DB_POSTGRESQL= "POSTGRESQL";
  37. private static final String DB_DERBY= "DERBY";
  38. private static final String DB_ACCESS = "MSACCESS";
  39.  
  40. private String serverName= "";
  41. private String portNumber = "";
  42. private String databaseName= "";
  43. private String dbUsername = "";
  44. private String dbPassword = "";
  45. private String DBMS = "";
  46.  
  47. private Logger log = Logger.getLogger(this.getClass());
  48.  
  49. @Override
  50. protected void executeInternal(JobExecutionContext context)
  51. throws JobExecutionException {
  52. try {
  53. if (taskDef == null) {
  54. taskDef = (TaskDef)context.getJobDetail().getJobDataMap().get("taskdef");
  55. Context.getSchedulerService().registerTaskRunningInstance(this);
  56. /**
  57. * for now call this method until Dan works on solving the
  58. * Init(TaskDef) method call
  59. */
  60. init2(taskDef);
  61. }
  62.  
  63. //Data to be sent out
  64. //List<FormData> dataList = Context.getDataExportService().getFormDataToExport(EXPORT_TASK_BIT);
  65.  
  66. log.info("Running SMS service to send out statistics to 10 school stakeholders");
  67. running = true;
  68.  
  69. //You should receive the list of statistical records here
  70. //exporter = new JdbcRdmsExporterDAO(getDatabase(this.DBMS), getConnectionURL(this.DBMS));
  71. String msgStatistics = "girls: 60%, boys: 78%, female teachers: 40% and male teachers: 38%";
  72.  
  73.  
  74. //Invoke the sms engine
  75.  
  76. /*for (int index = 0; index < dataList.size(); index++) {
  77. FormData formData = dataList.get(index);
  78. if (formData == null) continue;
  79. try {
  80. FormDefVersion formDefVersion =(FormDefVersion)formDefTable.get(new Integer(formData.getFormDefVersionId()));
  81. if (formDefVersion == null) {
  82. formDefVersion = Context.getDataExportService().getFormDefVersion(formData.getFormDefVersionId());
  83. formDefTable.put(new Integer(formDefVersion.getFormDefVersionId()), formDefVersion);
  84. }
  85. //The actual sending of data should take place here, u should call the sms engine at this point, :)
  86. //exportFormData(formData, formDefVersion);
  87.  
  88.  
  89. // export successful if we are still here...
  90. //Context.getDataExportService().setFormDataExported(formData, EXPORT_TASK_BIT);
  91. } catch(Exception ex) {
  92. log.error("Exception caught while attempting export of form data with id '"+formData.getFormDataId()+"'", ex);
  93. }
  94. }*/
  95. } catch(Exception ex) {
  96. log.error("SendSMS of Statistics Task has been aborted due to exception "+ex.getMessage(), ex);
  97. }
  98.  
  99. }
  100.  
  101. private void init2(TaskDef taskDef) {
  102. if(taskDef != null){
  103. this.serverName = taskDef.getParamValue("server");//localhost
  104. this.portNumber = taskDef.getParamValue("port");//3306
  105. this.databaseName = taskDef.getParamValue("database");//snv_db
  106. this.dbUsername = taskDef.getParamValue("dbusername");//root
  107. this.dbPassword = taskDef.getParamValue("dbpassword");//
  108. this.DBMS = taskDef.getParamValue("DBMS");
  109. }
  110. }
  111.  
  112. public static int getDatabase(String dbms){
  113. if(dbms.equalsIgnoreCase(DB_MYSQL))
  114. return Constants.DB_MYSQL;
  115. else if(dbms.equalsIgnoreCase(DB_ORACLE))
  116. return Constants.DB_ORACLE;
  117. else if(dbms.equalsIgnoreCase(DB_POSTGRESQL))
  118. return Constants.DB_POSTGRESQL;
  119. else if(dbms.equalsIgnoreCase(DB_SQLSERVER))
  120. return Constants.DB_SQLSERVER;
  121. else if(dbms.equalsIgnoreCase(DB_DERBY))
  122. return Constants.DB_DERBY;
  123. else if(dbms.equalsIgnoreCase(DB_ACCESS))
  124. return Constants.DB_MSACCESS;
  125. else
  126. return Constants.DB_MYSQL;
  127. }
  128.  
  129. @Override
  130. public TaskDef getTaskDef() {
  131. return taskDef;
  132. }
  133.  
  134. @Override
  135. public void init(TaskDef taskDef) {
  136. this.taskDef = taskDef;
  137. init2(taskDef);
  138. }
  139.  
  140. @Override
  141. public boolean isRunning() {
  142. return running;
  143. }
  144.  
  145. @Override
  146. public void stop() {
  147. log.info("Stopping Data Export Service");
  148. taskDef = null;
  149. running = false;
  150.  
  151. }
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement