コード例 #1
0
  public void copyRealizationTime(
      final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FieldComponent generatedEndDateField =
        (FieldComponent) view.getComponentByReference(OrderFieldsPS.GENERATED_END_DATE);
    FieldComponent stopTimeField = (FieldComponent) view.getComponentByReference(L_STOP_TIME);

    stopTimeField.setFieldValue(generatedEndDateField.getFieldValue());

    state.performEvent(view, "save", new String[0]);
  }
コード例 #2
0
  @Transactional
  public void generateSimpleMaterialBalance(
      final ViewDefinitionState viewDefinitionState,
      final ComponentState state,
      final String[] args) {
    if (state instanceof FormComponent) {
      ComponentState generated = viewDefinitionState.getComponentByReference(L_GENERATED);
      ComponentState date = viewDefinitionState.getComponentByReference(L_DATE);
      ComponentState worker = viewDefinitionState.getComponentByReference(L_WORKER);

      Entity simpleMaterialBalance =
          dataDefinitionService
              .get(
                  SimpleMaterialBalanceConstants.PLUGIN_IDENTIFIER,
                  SimpleMaterialBalanceConstants.MODEL_SIMPLE_MATERIAL_BALANCE)
              .get((Long) state.getFieldValue());

      if (simpleMaterialBalance == null) {
        state.addMessage("qcadooView.message.entityNotFound", MessageType.FAILURE);
        return;
      } else if (StringUtils.hasText(simpleMaterialBalance.getStringField(L_FILE_NAME))) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalanceDetails.window.simpleMaterialBalance.documentsWasGenerated",
            MessageType.FAILURE);
        return;
      } else if (simpleMaterialBalance
          .getHasManyField(L_SIMPLE_MATERIAL_BALANCE_ORDERS_COMPONENTS)
          .isEmpty()) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalance.window.simpleMaterialBalance.missingAssosiatedOrders",
            MessageType.FAILURE);
        return;
      } else if (simpleMaterialBalance
          .getHasManyField(L_SIMPLE_MATERIAL_BALANCE_LOCATIONS_COMPONENTS)
          .isEmpty()) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalance.window.simpleMaterialBalance.missingAssosiatedLocations",
            MessageType.FAILURE);
        return;
      }

      if ("0".equals(generated.getFieldValue())) {
        worker.setFieldValue(securityService.getCurrentUserName());
        generated.setFieldValue("1");
        date.setFieldValue(
            new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, LocaleContextHolder.getLocale())
                .format(new Date()));
      }

      state.performEvent(viewDefinitionState, "save", new String[0]);

      if (state.getFieldValue() == null || !((FormComponent) state).isValid()) {
        worker.setFieldValue(null);
        generated.setFieldValue("0");
        date.setFieldValue(null);
        return;
      }

      simpleMaterialBalance =
          dataDefinitionService
              .get(
                  SimpleMaterialBalanceConstants.PLUGIN_IDENTIFIER,
                  SimpleMaterialBalanceConstants.MODEL_SIMPLE_MATERIAL_BALANCE)
              .get((Long) state.getFieldValue());

      try {
        generateSimpleMaterialBalanceDocuments(state, simpleMaterialBalance);
        state.performEvent(viewDefinitionState, "reset", new String[0]);
      } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
      } catch (DocumentException e) {
        throw new IllegalStateException(e.getMessage(), e);
      }
    }
  }