Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.openxdata.server.sms.send.statistics.task;
- import java.util.List;
- import java.util.ArrayList;
- import java.util.Hashtable;
- import org.apache.log4j.Logger;
- import org.openxdata.server.Task;
- import org.openxdata.server.admin.model.FormData;
- import org.openxdata.server.admin.model.FormDefVersion;
- import org.openxdata.server.admin.model.TaskDef;
- import org.openxdata.server.context.Context;
- import org.openxdata.server.dao.jdbc.JdbcRdmsExporterDAO;
- import org.openxdata.server.export.rdbms.engine.Constants;
- import org.quartz.JobExecutionContext;
- import org.quartz.JobExecutionException;
- import org.springframework.scheduling.quartz.QuartzJobBean;
- /**
- * Class represents the task that handles the sending of statistics to Statkeholders in a school
- * The statistics in sent out as an SMS
- * @author Simon, smuwanga@cit.mak.ac.ug
- *
- */
- public class SendStaticsTask extends QuartzJobBean implements Task{
- private TaskDef taskDef = null;
- private boolean running = false;
- private static final String DB_MYSQL="MYSQL";
- private static final String DB_ORACLE ="ORACLE";
- private static final String DB_SQLSERVER ="SQLSERVER";
- private static final String DB_POSTGRESQL= "POSTGRESQL";
- private static final String DB_DERBY= "DERBY";
- private static final String DB_ACCESS = "MSACCESS";
- private String serverName= "";
- private String portNumber = "";
- private String databaseName= "";
- private String dbUsername = "";
- private String dbPassword = "";
- private String DBMS = "";
- private Logger log = Logger.getLogger(this.getClass());
- @Override
- protected void executeInternal(JobExecutionContext context)
- throws JobExecutionException {
- try {
- if (taskDef == null) {
- taskDef = (TaskDef)context.getJobDetail().getJobDataMap().get("taskdef");
- Context.getSchedulerService().registerTaskRunningInstance(this);
- /**
- * for now call this method until Dan works on solving the
- * Init(TaskDef) method call
- */
- init2(taskDef);
- }
- //Data to be sent out
- //List<FormData> dataList = Context.getDataExportService().getFormDataToExport(EXPORT_TASK_BIT);
- log.info("Running SMS service to send out statistics to 10 school stakeholders");
- running = true;
- //You should receive the list of statistical records here
- //exporter = new JdbcRdmsExporterDAO(getDatabase(this.DBMS), getConnectionURL(this.DBMS));
- String msgStatistics = "girls: 60%, boys: 78%, female teachers: 40% and male teachers: 38%";
- //Invoke the sms engine
- /*for (int index = 0; index < dataList.size(); index++) {
- FormData formData = dataList.get(index);
- if (formData == null) continue;
- try {
- FormDefVersion formDefVersion =(FormDefVersion)formDefTable.get(new Integer(formData.getFormDefVersionId()));
- if (formDefVersion == null) {
- formDefVersion = Context.getDataExportService().getFormDefVersion(formData.getFormDefVersionId());
- formDefTable.put(new Integer(formDefVersion.getFormDefVersionId()), formDefVersion);
- }
- //The actual sending of data should take place here, u should call the sms engine at this point, :)
- //exportFormData(formData, formDefVersion);
- // export successful if we are still here...
- //Context.getDataExportService().setFormDataExported(formData, EXPORT_TASK_BIT);
- } catch(Exception ex) {
- log.error("Exception caught while attempting export of form data with id '"+formData.getFormDataId()+"'", ex);
- }
- }*/
- } catch(Exception ex) {
- log.error("SendSMS of Statistics Task has been aborted due to exception "+ex.getMessage(), ex);
- }
- }
- private void init2(TaskDef taskDef) {
- if(taskDef != null){
- this.serverName = taskDef.getParamValue("server");//localhost
- this.portNumber = taskDef.getParamValue("port");//3306
- this.databaseName = taskDef.getParamValue("database");//snv_db
- this.dbUsername = taskDef.getParamValue("dbusername");//root
- this.dbPassword = taskDef.getParamValue("dbpassword");//
- this.DBMS = taskDef.getParamValue("DBMS");
- }
- }
- public static int getDatabase(String dbms){
- if(dbms.equalsIgnoreCase(DB_MYSQL))
- return Constants.DB_MYSQL;
- else if(dbms.equalsIgnoreCase(DB_ORACLE))
- return Constants.DB_ORACLE;
- else if(dbms.equalsIgnoreCase(DB_POSTGRESQL))
- return Constants.DB_POSTGRESQL;
- else if(dbms.equalsIgnoreCase(DB_SQLSERVER))
- return Constants.DB_SQLSERVER;
- else if(dbms.equalsIgnoreCase(DB_DERBY))
- return Constants.DB_DERBY;
- else if(dbms.equalsIgnoreCase(DB_ACCESS))
- return Constants.DB_MSACCESS;
- else
- return Constants.DB_MYSQL;
- }
- @Override
- public TaskDef getTaskDef() {
- return taskDef;
- }
- @Override
- public void init(TaskDef taskDef) {
- this.taskDef = taskDef;
- init2(taskDef);
- }
- @Override
- public boolean isRunning() {
- return running;
- }
- @Override
- public void stop() {
- log.info("Stopping Data Export Service");
- taskDef = null;
- running = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement