public static Trigger convertTriggerFromNativeObject(org.quartz.Trigger quartzTrigger) {
    Trigger spagobiTrigger;

    spagobiTrigger = new Trigger();
    spagobiTrigger.setName(quartzTrigger.getName());
    spagobiTrigger.setGroupName(quartzTrigger.getGroup());
    spagobiTrigger.setDescription(quartzTrigger.getDescription());

    // spagobiTrigger.setCalendarName( quartzTrigger.getCalendarName() );
    Assert.assertTrue(
        quartzTrigger.getCalendarName() == null,
        "quartz trigger calendar name is not null: " + quartzTrigger.getCalendarName());

    spagobiTrigger.setStartTime(quartzTrigger.getStartTime());
    spagobiTrigger.setEndTime(quartzTrigger.getEndTime());

    // triggers that run immediately have a generated name that starts with schedule_uuid_ (see
    // TriggerXMLDeserializer)
    // It would be better anyway to relay on a specific property to recognize if a trigger is
    // thinked to run immediately
    spagobiTrigger.setRunImmediately(spagobiTrigger.getName().startsWith("schedule_uuid_"));

    if (quartzTrigger instanceof org.quartz.CronTrigger) {
      org.quartz.CronTrigger quartzCronTrigger = (org.quartz.CronTrigger) quartzTrigger;
      // dirty trick
      String expression = (String) quartzCronTrigger.getJobDataMap().get(SPAGOBI_CRON_EXPRESSION);
      if (expression != null) {
        quartzCronTrigger.getJobDataMap().remove(SPAGOBI_CRON_EXPRESSION);
      } else {
        // for back compatibility
        expression =
            (String) quartzCronTrigger.getJobDataMap().get(SPAGOBI_CRON_EXPRESSION_DEPRECATED);
        quartzCronTrigger.getJobDataMap().remove(SPAGOBI_CRON_EXPRESSION_DEPRECATED);
      }
      spagobiTrigger.setCronExpression(new CronExpression(expression));
    }

    Job job = new Job();
    job.setName(quartzTrigger.getJobName());
    job.setGroupName(quartzTrigger.getJobGroup());
    job.setVolatile(quartzTrigger.isVolatile());
    Map<String, String> parameters =
        convertParametersFromNativeObject(quartzTrigger.getJobDataMap());
    job.addParameters(parameters);

    spagobiTrigger.setJob(job);

    return spagobiTrigger;
  }
  public static org.quartz.Trigger convertTriggerToNativeObject(Trigger spagobiTrigger) {
    org.quartz.Trigger quartzTrigger;

    logger.debug("IN");

    quartzTrigger = null;
    try {
      Assert.assertNotNull(spagobiTrigger, "Input parameter [spagobiTrigger] csannot be null");

      if (spagobiTrigger.isRunImmediately()) {

        quartzTrigger = TriggerUtils.makeImmediateTrigger(spagobiTrigger.getName(), 0, 10000);
        quartzTrigger.setJobName(spagobiTrigger.getJob().getName());
        quartzTrigger.setJobGroup(spagobiTrigger.getJob().getGroupName());
        JobDataMap jobDataMap =
            convertParametersToNativeObject(spagobiTrigger.getJob().getParameters());
        quartzTrigger.setJobDataMap(jobDataMap);

      } else {

        if (spagobiTrigger.isSimpleTrigger()) {
          quartzTrigger = new org.quartz.SimpleTrigger();
        } else {
          org.quartz.CronTrigger quartzCronTrigger = new org.quartz.CronTrigger();
          String quartzCronExpression =
              convertCronExpressionToNativeObject(
                  spagobiTrigger.getChronExpression(), spagobiTrigger.getStartTime());
          quartzCronTrigger.setCronExpression(quartzCronExpression);
          quartzTrigger = quartzCronTrigger;
          // dirty trick
          spagobiTrigger
              .getJob()
              .addParameter(
                  SPAGOBI_CRON_EXPRESSION, spagobiTrigger.getChronExpression().getExpression());
        }

        quartzTrigger.setName(spagobiTrigger.getName());
        quartzTrigger.setDescription(spagobiTrigger.getDescription());
        if (spagobiTrigger.getGroupName() == null) {
          quartzTrigger.setGroup(Scheduler.DEFAULT_GROUP);
        } else {
          quartzTrigger.setGroup(spagobiTrigger.getGroupName());
        }

        quartzTrigger.setStartTime(spagobiTrigger.getStartTime());
        if (spagobiTrigger.getEndTime() != null) {
          quartzTrigger.setEndTime(spagobiTrigger.getEndTime());
        }
        quartzTrigger.setJobName(spagobiTrigger.getJob().getName());
        if (spagobiTrigger.getJob().getGroupName() == null) {
          quartzTrigger.setJobGroup(Scheduler.DEFAULT_GROUP);
        } else {
          quartzTrigger.setJobGroup(spagobiTrigger.getJob().getGroupName());
        }

        quartzTrigger.setVolatility(spagobiTrigger.getJob().isVolatile());

        JobDataMap jobDataMap =
            convertParametersToNativeObject(spagobiTrigger.getJob().getParameters());
        quartzTrigger.setJobDataMap(jobDataMap);
      }
    } catch (Throwable t) {
      throw new SpagoBIRuntimeException(
          "An unexpected error occured while converting Trigger to native object", t);
    } finally {
      logger.debug("OUT");
    }

    return quartzTrigger;
  }