public String execute() throws Exception {
    // ---------------------------------------------------------------------
    // Prepare values
    // ---------------------------------------------------------------------

    code = nullIfEmpty(code);
    shortName = nullIfEmpty(shortName);
    description = nullIfEmpty(description);

    PeriodType periodType = PeriodType.getPeriodTypeByName(frequencySelect);

    DataSet dataSet = new DataSet(name, shortName, code, periodType);

    MapLegendSet legendSet = mappingService.getMapLegendSet(selectedLegendSetId);

    dataSet.setExpiryDays(expiryDays);
    dataSet.setTimelyDays(timelyDays);
    dataSet.setSkipAggregation(skipAggregation);

    for (String id : dataElementsSelectedList) {
      dataSet.addDataElement(dataElementService.getDataElement(Integer.parseInt(id)));
    }

    Set<Indicator> indicators = new HashSet<Indicator>();

    for (String id : indicatorsSelectedList) {
      indicators.add(indicatorService.getIndicator(Integer.parseInt(id)));
    }

    if (categoryComboId != null) {
      dataSet.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
    }

    dataSet.setDescription(description);
    dataSet.setVersion(1);
    dataSet.setMobile(false);
    dataSet.setIndicators(indicators);
    dataSet.setNotificationRecipients(userGroupService.getUserGroup(notificationRecipients));
    dataSet.setAllowFuturePeriods(allowFuturePeriods);
    dataSet.setFieldCombinationRequired(fieldCombinationRequired);
    dataSet.setValidCompleteOnly(validCompleteOnly);
    dataSet.setNotifyCompletingUser(notifyCompletingUser);
    dataSet.setApproveData(approveData);
    dataSet.setSkipOffline(skipOffline);
    dataSet.setDataElementDecoration(dataElementDecoration);
    dataSet.setRenderAsTabs(renderAsTabs);
    dataSet.setRenderHorizontally(renderHorizontally);
    dataSet.setLegendSet(legendSet);

    dataSetService.addDataSet(dataSet);

    userService.assignDataSetToUserRole(dataSet);

    return SUCCESS;
  }
  @Override
  public String execute() throws Exception {
    TaskId taskId = new TaskId(TaskCategory.DATAMART, currentUserService.getCurrentUser());

    notifier.clear(taskId);

    ScheduledTasks tasks = new ScheduledTasks();

    // ---------------------------------------------------------------------
    // Analytics
    // ---------------------------------------------------------------------

    if (analytics) {
      analyticsTableTask.setTaskId(taskId);

      tasks.addTask(resourceTableTask);
      tasks.addTask(analyticsTableTask);
    }

    // ---------------------------------------------------------------------
    // Data mart
    // ---------------------------------------------------------------------

    if (dataMart) {
      Date start = DateUtils.getMediumDate(startDate);
      Date end = DateUtils.getMediumDate(endDate);

      List<Period> periods = new ArrayList<Period>();

      for (String type : periodTypes) {
        CalendarPeriodType periodType = (CalendarPeriodType) PeriodType.getPeriodTypeByName(type);

        periods.addAll(periodType.generatePeriods(start, end));
      }

      if (periods.size() > 0) {
        dataMartTask.setPeriods(periods);
        dataMartTask.setTaskId(taskId);

        tasks.addTask(dataMartTask);
      }
    }

    if (!tasks.isEmpty()) {
      scheduler.executeTask(tasks);
    }

    return SUCCESS;
  }
 public PeriodType getPeriodTypeByName(String name) {
   return PeriodType.getPeriodTypeByName(name);
 }