public String getInputUsername(StudyBean studyBean, StudySubjectBean studySubjectBean) {
    String inputUserName = null;
    if (studySubjectBean != null) {
      if (studyBean.getParentStudyId() > 0) studyBean = getStudy(studyBean.getParentStudyId());

      inputUserName = studyBean.getOid() + "." + studySubjectBean.getOid();
    }
    return inputUserName;
  }
 public void collectOdmStudy() {
   StudyBean study = studyBase.getStudy();
   String studyOID = study.getOid();
   if (studyOID == null || studyOID.length() <= 0) {
     logger.info(
         "Constructed studyOID using study_id because oc_oid is missing from the table - study.");
     studyOID = "" + study.getId();
   }
   odmStudy.setOid(studyOID);
   collectGlobalVariables();
   collectBasicDefinitions();
   collectMetaDataVersion();
 }
  public SimpleTrigger generateImportTrigger(
      FormProcessor fp,
      UserAccountBean userAccount,
      StudyBean study,
      Date startDateTime,
      String locale) {

    String jobName = fp.getString(JOB_NAME);

    String email = fp.getString(EMAIL);
    String jobDesc = fp.getString(JOB_DESC);
    String directory = fp.getString(DIRECTORY);

    // what kinds of periods do we have? hourly, daily, weekly?
    long interval = 0;
    int hours = fp.getInt("hours");
    int minutes = fp.getInt("minutes");
    if (hours > 0) {
      long hoursInt = hours * 3600000;
      interval = interval + hoursInt;
    }
    if (minutes > 0) {
      long minutesInt = minutes * 60000;
      interval = interval + minutesInt;
    }
    SimpleTrigger trigger = new SimpleTrigger(jobName, IMPORT_TRIGGER, 64000, interval);
    trigger.setDescription(jobDesc);
    // set just the start date
    trigger.setStartTime(startDateTime);
    trigger.setName(jobName); // + datasetId);
    trigger.setGroup(IMPORT_TRIGGER); // + datasetId);
    trigger.setMisfireInstruction(
        SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT);
    // set job data map
    JobDataMap jobDataMap = new JobDataMap();

    jobDataMap.put(EMAIL, email);
    jobDataMap.put(USER_ID, userAccount.getId());
    jobDataMap.put(STUDY_NAME, study.getName());
    jobDataMap.put(STUDY_OID, study.getOid());
    jobDataMap.put(DIRECTORY, directory);
    jobDataMap.put(ExampleSpringJob.LOCALE, locale);
    jobDataMap.put("hours", hours);
    jobDataMap.put("minutes", minutes);

    trigger.setJobDataMap(jobDataMap);
    trigger.setVolatility(false);
    return trigger;
  }
  private void collectMetaDataVersion() {
    ArrayList<StudyEventDefinitionBean> sedBeansInStudy =
        (ArrayList<StudyEventDefinitionBean>) studyBase.getSedBeansInStudy();
    if (sedBeansInStudy == null || sedBeansInStudy.size() < 1) {
      logger.info("null, because there is no study event definition in this study.");
      return;
    }

    StudyBean study = studyBase.getStudy();
    MetaDataVersionBean metadata = this.odmStudy.getMetaDataVersion();

    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(this.ds);
    int parentId = study.getParentStudyId() > 0 ? study.getParentStudyId() : study.getId();
    StudyParameterValueBean spv = spvdao.findByHandleAndStudy(parentId, "discrepancyManagement");
    metadata.setSoftHard(spv.getValue().equalsIgnoreCase("true") ? "Hard" : "Soft");

    OdmExtractDAO oedao = new OdmExtractDAO(this.ds);
    int studyId = study.getId();
    int parentStudyId = study.getParentStudyId() > 0 ? study.getParentStudyId() : studyId;
    if (this.getCategory() == 1 && study.isSite(study.getParentStudyId())) {
      // populate MetaDataVersion attributes
      if (dataset != null) {
        metadata.setOid(dataset.getODMMetaDataVersionOid() + "-" + study.getOid());
        metadata.setName(dataset.getODMMetaDataVersionName() + "-" + study.getOid());
        this.setParentMetaDataVersionOid(dataset.getODMMetaDataVersionOid());
      }
      if (metadata.getOid() == null || metadata.getOid().length() <= 0) {
        metadata.setOid("v1.0.0" + "-" + study.getOid());
        this.setParentMetaDataVersionOid("v1.0.0");
      }
      if (metadata.getName() == null || metadata.getName().length() <= 0) {
        metadata.setName("MetaDataVersion_v1.0.0" + "-" + study.getOid());
      }

      // populate Include
      this.collectIncludeFromParentInSameFile();

      // populate protocol
      oedao.getUpdatedSiteMetadata(parentStudyId, studyId, metadata, this.odmBean.getODMVersion());
    } else {
      if (dataset != null) {
        metadata.setOid(dataset.getODMMetaDataVersionOid());
        metadata.setName(dataset.getODMMetaDataVersionName());
      }
      if (metadata.getOid() == null || metadata.getOid().length() <= 0) {
        metadata.setOid("v1.0.0");
      }
      if (metadata.getName() == null || metadata.getName().length() <= 0) {
        metadata.setName("MetaDataVersion_v1.0.0");
      }

      // populate Include
      String psOid = new String();
      String pmOid = new String();
      if (dataset != null) {
        psOid = dataset.getODMPriorStudyOid();
        pmOid = dataset.getODMPriorMetaDataVersionOid();
      }
      if (pmOid != null && pmOid.length() > 0) {
        MetaDataVersionIncludeBean ib = metadata.getInclude();
        ib.setMetaDataVersionOID(pmOid);
        if (psOid != null && psOid.length() > 0) {
          ib.setStudyOID(psOid);
        } else {
          ib.setStudyOID(study.getOid());
        }
      }

      // populate protocol
      // Set<Integer> nullCodeSet = oedao.getMetadata(parentStudyId,
      // studyId,
      // metadata, this.getODMBean().getODMVersion());
      // studyBase.setNullClSet(nullCodeSet);
      oedao.getMetadata(parentStudyId, studyId, metadata, this.odmBean.getODMVersion());
    }
  }
  public SimpleTrigger generateTrigger(
      FormProcessor fp, UserAccountBean userAccount, StudyBean study, String locale) {
    Date startDateTime = fp.getDateTime(DATE_START_JOB);
    // check the above?
    int datasetId = fp.getInt(DATASET_ID);
    String period = fp.getString(PERIOD);
    String email = fp.getString(EMAIL);
    String jobName = fp.getString(JOB_NAME);
    String jobDesc = fp.getString(JOB_DESC);
    String spss = fp.getString(SPSS);
    String tab = fp.getString(TAB);
    String cdisc = fp.getString(CDISC);
    String cdisc12 = fp.getString(ExampleSpringJob.CDISC12);
    String cdisc13 = fp.getString(ExampleSpringJob.CDISC13);
    String cdisc13oc = fp.getString(ExampleSpringJob.CDISC13OC);
    BigInteger interval = new BigInteger("0");
    if ("monthly".equalsIgnoreCase(period)) {
      interval = new BigInteger("2419200000"); // how many
      // milliseconds in
      // a month? should
      // be 24192000000
    } else if ("weekly".equalsIgnoreCase(period)) {
      interval = new BigInteger("604800000"); // how many
      // milliseconds in
      // a week? should
      // be 6048000000
    } else { // daily
      interval = new BigInteger("86400000"); // how many
      // milliseconds in a
      // day?
    }
    // set up and commit job here

    SimpleTrigger trigger = new SimpleTrigger(jobName, "DEFAULT", 64000, interval.longValue());

    // set the job detail name,
    // based on our choice of format above
    // what if there is more than one detail?
    // what is the number of times it should repeat?
    // arbitrary large number, 64K should be enough :)

    trigger.setDescription(jobDesc);
    // set just the start date
    trigger.setStartTime(startDateTime);
    trigger.setName(jobName); // + datasetId);
    trigger.setGroup("DEFAULT"); // + datasetId);
    trigger.setMisfireInstruction(
        SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT);
    // set job data map
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put(DATASET_ID, datasetId);
    jobDataMap.put(PERIOD, period);
    jobDataMap.put(EMAIL, email);
    jobDataMap.put(TAB, tab);
    jobDataMap.put(CDISC, cdisc);
    jobDataMap.put(ExampleSpringJob.CDISC12, cdisc12);
    jobDataMap.put(ExampleSpringJob.LOCALE, locale);
    // System.out.println("found 1.2: " +
    // jobDataMap.get(ExampleSpringJob.CDISC12));
    jobDataMap.put(ExampleSpringJob.CDISC13, cdisc13);
    // System.out.println("found 1.3: " +
    // jobDataMap.get(ExampleSpringJob.CDISC13));
    jobDataMap.put(ExampleSpringJob.CDISC13OC, cdisc13oc);
    // System.out.println("found 1.3oc: " +
    // jobDataMap.get(ExampleSpringJob.CDISC13OC));
    jobDataMap.put(SPSS, spss);
    jobDataMap.put(USER_ID, userAccount.getId());
    // StudyDAO studyDAO = new StudyDAO();
    jobDataMap.put(STUDY_ID, study.getId());
    jobDataMap.put(STUDY_NAME, study.getName());
    jobDataMap.put(STUDY_OID, study.getOid());

    trigger.setJobDataMap(jobDataMap);
    // trigger.setRepeatInterval(interval.longValue());
    // System.out.println("default for volatile: " + trigger.isVolatile());
    trigger.setVolatility(false);
    return trigger;
  }