コード例 #1
0
  /**
   * Delete a custom KPI.
   *
   * @param kpiDefinitionId the KPI definition id
   */
  public Result delete(Long kpiDefinitionId) {

    // get the KPI
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    if (!kpiDefinition.isStandard) {

      // cancel the scheduler
      kpi.cancel();

      // delete the values and data
      deleteKpiValueDefinition(kpiDefinition.mainKpiValueDefinition);
      deleteKpiValueDefinition(kpiDefinition.additional1KpiValueDefinition);
      deleteKpiValueDefinition(kpiDefinition.additional2KpiValueDefinition);

      // delete the colors
      if (kpiDefinition.kpiColorRules != null) {
        for (KpiColorRule kpiColorRule : kpiDefinition.kpiColorRules) {
          kpiColorRule.doDelete();
        }
      }

      kpiDefinition.deleted = true;
      kpiDefinition.save();

      Utilities.sendSuccessFlashMessage(Msg.get("admin.kpi.delete.successful"));

    } else {
      Utilities.sendSuccessFlashMessage(Msg.get("admin.kpi.delete.error"));
    }

    return redirect(controllers.admin.routes.KpiManagerController.index());
  }
コード例 #2
0
  /**
   * Form to manage (add or edit) a KPI color rule.
   *
   * @param kpiDefinitionId the KPI definition id
   * @param kpiColorRuleId the KPI color rule id, set 0 for the add case
   */
  public Result manageRule(Long kpiDefinitionId, Long kpiColorRuleId) {

    // get the KPI
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    // initiate the form with the template
    Form<KpiColorRuleFormData> form = kpiColorRuleFormTemplate;

    // edit case: inject values
    if (!kpiColorRuleId.equals(Long.valueOf(0))) {

      // get the KPI color rule
      KpiColorRule kpiColorRule = KpiColorRule.getById(kpiColorRuleId);

      form =
          kpiColorRuleFormTemplate.fill(
              new KpiColorRuleFormData(kpiColorRule, getI18nMessagesPlugin()));
    }

    return ok(
        views.html.admin.kpi.manageRule.render(
            kpiDefinition,
            kpi,
            form,
            Color.getColorsAsValueHolderCollection(getI18nMessagesPlugin())));
  }
コード例 #3
0
  /** Process the edit form of the scheduler of a KPI definition. */
  public Result saveScheduler() {

    // bind the form
    Form<KpiSchedulerFormData> boundForm = kpiSchedulerFormTemplate.bindFromRequest();

    // get the KPI
    Long kpiDefinitionId = Long.valueOf(boundForm.data().get("id"));
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    if (boundForm.hasErrors()) {
      return ok(views.html.admin.kpi.editScheduler.render(kpiDefinition, kpi, boundForm));
    }

    KpiSchedulerFormData kpiSchedulerFormData = boundForm.get();

    kpiSchedulerFormData.fill(kpiDefinition);
    kpiDefinition.update();

    reloadKpiDefinition(kpiDefinition.uid);

    Utilities.sendSuccessFlashMessage(Msg.get("admin.kpi.editscheduler.successful"));

    return redirect(controllers.admin.routes.KpiManagerController.view(kpiDefinition.id));
  }
コード例 #4
0
  /**
   * Form to edit the main data of a KPI value definition.
   *
   * @param kpiValueDefinitionId the KPI value definition
   * @param valueType the value type (main, additional1, additional2)
   */
  public Result editValue(Long kpiValueDefinitionId, String valueType) {

    // get the KPI value
    KpiValueDefinition kpiValueDefinition = KpiValueDefinition.getById(kpiValueDefinitionId);

    // get the KPI
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiValueDefinition.getKpiDefinition().id);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    Form<KpiValueDefinitionFormData> form = null;

    if (kpiDefinition.isStandard) {
      form =
          standardKpiValueDefinitionFormTemplate.fill(
              new KpiValueDefinitionFormData(kpiValueDefinition, getI18nMessagesPlugin()));
    } else {
      form =
          customKpiValueDefinitionFormTemplate.fill(
              new KpiValueDefinitionFormData(kpiValueDefinition, getI18nMessagesPlugin()));
    }

    return ok(
        views.html.admin.kpi.editValue.render(
            kpiDefinition,
            kpi,
            kpiValueDefinition,
            valueType,
            form,
            getRenderTypesAsValueHolderCollection()));
  }
コード例 #5
0
  /**
   * Change the order of a KPI definition comparing to the other KPIs with the same object type.
   *
   * @param kpiDefinitionId the KPI definition id
   * @param isDecrement if true then we decrement the order, else we increment it
   */
  public Result changeOrder(Long kpiDefinitionId, Boolean isDecrement) {

    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);

    KpiDefinition kpiDefinitionToReverse = null;
    if (isDecrement) {
      kpiDefinitionToReverse =
          KpiDefinition.getPrevious(kpiDefinition.objectType, kpiDefinition.order);
    } else {
      kpiDefinitionToReverse = KpiDefinition.getNext(kpiDefinition.objectType, kpiDefinition.order);
    }

    if (kpiDefinitionToReverse != null) {

      Integer newOrder = kpiDefinitionToReverse.order;

      kpiDefinitionToReverse.order = kpiDefinition.order;
      kpiDefinitionToReverse.save();

      kpiDefinition.order = newOrder;
      kpiDefinition.save();
    }

    return redirect(controllers.admin.routes.KpiManagerController.index());
  }
コード例 #6
0
  /**
   * Form to edit the parameters of the scheduler of a KPI definition.
   *
   * <p>Possible only if the scheduler is active.
   *
   * @param kpiDefinitionId the KPI definition id
   */
  public Result editScheduler(Long kpiDefinitionId) {

    // get the KPI
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    Form<KpiSchedulerFormData> form =
        kpiSchedulerFormTemplate.fill(new KpiSchedulerFormData(kpiDefinition));

    return ok(views.html.admin.kpi.editScheduler.render(kpiDefinition, kpi, form));
  }
コード例 #7
0
  /** Process the manage form of a KPI color rule. */
  public Result saveRule() {

    // bind the form
    Form<KpiColorRuleFormData> boundForm = kpiColorRuleFormTemplate.bindFromRequest();

    // get the KPI
    Long kpiDefinitionId = Long.valueOf(boundForm.data().get("kpiDefinitionId"));
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    if (boundForm.hasErrors()) {
      return ok(
          views.html.admin.kpi.manageRule.render(
              kpiDefinition,
              kpi,
              boundForm,
              Color.getColorsAsValueHolderCollection(getI18nMessagesPlugin())));
    }

    KpiColorRuleFormData kpiColorRuleFormData = boundForm.get();

    KpiColorRule kpiColorRule = null;

    if (kpiColorRuleFormData.kpiColorRuleId == null) { // create case

      kpiColorRule = new KpiColorRule();

      kpiColorRule.kpiDefinition = kpiDefinition;
      kpiColorRule.order = KpiColorRule.getLastOrder(kpiDefinition.id) + 1;

      kpiColorRuleFormData.fill(kpiColorRule);

      kpiColorRule.save();

      Utilities.sendSuccessFlashMessage(Msg.get("admin.kpi.rule.add.successful"));

    } else { // edit case

      kpiColorRule = KpiColorRule.getById(kpiColorRuleFormData.kpiColorRuleId);

      kpiColorRuleFormData.fill(kpiColorRule);

      kpiColorRule.update();

      Utilities.sendSuccessFlashMessage(Msg.get("admin.kpi.rule.edit.successful"));
    }

    kpiColorRuleFormData.renderLabel.persist(getI18nMessagesPlugin());

    reloadKpiDefinition(kpiDefinition.uid);

    return redirect(controllers.admin.routes.KpiManagerController.view(kpiDefinition.id));
  }
コード例 #8
0
  /**
   * Delete the scheduler of a KPI definition.
   *
   * @param kpiDefinitionId the KPI definition id
   */
  public Result deleteScheduler(Long kpiDefinitionId) {

    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);

    kpiDefinition.schedulerFrequency = null;
    kpiDefinition.schedulerRealTime = null;
    kpiDefinition.schedulerStartTime = null;
    kpiDefinition.save();

    reloadKpiDefinition(kpiDefinition.uid);

    Utilities.sendSuccessFlashMessage(Msg.get("admin.kpi.scheduler.delete"));

    return redirect(controllers.admin.routes.KpiManagerController.view(kpiDefinitionId));
  }
コード例 #9
0
  /**
   * Display the details of a KPI definition.
   *
   * @param kpiDefinitionId the KPI definition id
   */
  public Result view(Long kpiDefinitionId) {

    // get the KPI
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiDefinitionId);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    // create the table values
    List<KpiValueDefinitionListView> kpiValueDefinitionListView =
        new ArrayList<KpiValueDefinitionListView>();
    kpiValueDefinitionListView.add(
        new KpiValueDefinitionListView(kpiDefinition.mainKpiValueDefinition, DataType.MAIN));
    if (kpi.hasBoxDisplay()) {
      kpiValueDefinitionListView.add(
          new KpiValueDefinitionListView(
              kpiDefinition.additional1KpiValueDefinition, DataType.ADDITIONAL1));
      kpiValueDefinitionListView.add(
          new KpiValueDefinitionListView(
              kpiDefinition.additional2KpiValueDefinition, DataType.ADDITIONAL2));
    }
    Table<KpiValueDefinitionListView> valuesTable =
        this.getTableProvider()
            .get()
            .kpiValueDefinition
            .templateTable
            .fill(kpiValueDefinitionListView);

    // create the color rules table
    List<KpiColorRuleListView> kpiColorRuleListView = new ArrayList<KpiColorRuleListView>();
    for (KpiColorRule kpiColorRule : kpiDefinition.kpiColorRules) {
      kpiColorRuleListView.add(new KpiColorRuleListView(kpiColorRule, getI18nMessagesPlugin()));
    }
    Table<KpiColorRuleListView> rulesTable =
        this.getTableProvider().get().kpiColorRule.templateTable.fill(kpiColorRuleListView);

    return ok(views.html.admin.kpi.view.render(kpiDefinition, kpi, valuesTable, rulesTable));
  }
コード例 #10
0
  /** Process the edit form of a KPI value definition. */
  public Result saveValue() {

    // get the KPI value
    Long kpiValueDefinitionId = Long.valueOf(request().body().asFormUrlEncoded().get("id")[0]);
    KpiValueDefinition kpiValueDefinition = KpiValueDefinition.getById(kpiValueDefinitionId);

    // get the KPI
    KpiDefinition kpiDefinition = KpiDefinition.getById(kpiValueDefinition.getKpiDefinition().id);
    Kpi kpi = new Kpi(kpiDefinition, getKpiService());

    // bind the form
    Form<KpiValueDefinitionFormData> boundForm = null;
    if (kpiDefinition.isStandard) {
      boundForm = standardKpiValueDefinitionFormTemplate.bindFromRequest();
    } else {
      boundForm = customKpiValueDefinitionFormTemplate.bindFromRequest();
    }

    // get the value type
    String valueType = boundForm.data().get("valueType");

    if (boundForm.hasErrors()) {
      return ok(
          views.html.admin.kpi.editValue.render(
              kpiDefinition,
              kpi,
              kpiValueDefinition,
              valueType,
              boundForm,
              getRenderTypesAsValueHolderCollection()));
    }

    KpiValueDefinitionFormData kpiValueDefinitionFormData = boundForm.get();

    if (kpiValueDefinitionFormData.renderType.equals(RenderType.PATTERN.name())
        && (kpiValueDefinitionFormData.renderPattern == null
            || kpiValueDefinitionFormData.renderPattern.equals(""))) {
      boundForm.reject(
          "renderPattern", Msg.get("object.kpi_value_definition.render_pattern.invalid"));
      return ok(
          views.html.admin.kpi.editValue.render(
              kpiDefinition,
              kpi,
              kpiValueDefinition,
              valueType,
              boundForm,
              getRenderTypesAsValueHolderCollection()));
    }

    kpiValueDefinitionFormData.fill(kpiValueDefinition, !kpiDefinition.isStandard);
    kpiValueDefinition.update();

    if (!kpiDefinition.isStandard) {
      kpiValueDefinitionFormData.name.persist(getI18nMessagesPlugin());
    }

    reloadKpiDefinition(kpiDefinition.uid);

    Utilities.sendSuccessFlashMessage(Msg.get("admin.kpi.value.edit.successful"));

    return redirect(controllers.admin.routes.KpiManagerController.view(kpiDefinition.id));
  }