예제 #1
0
  private Entity generateFormEntity(final ViewDefinitionState view) {
    DataDefinition dd =
        dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT);

    FormComponent form = getForm(view);
    Entity formEntity = form.getEntity();
    GridComponent parentsGrid = (GridComponent) view.getComponentByReference("parents");
    if (parentsGrid.getSelectedEntities().isEmpty()) {
      return null;
    }
    Long productId = parentsGrid.getSelectedEntities().get(0).getId();

    if (productId == null) {
      throw new FormValidationException("basic.productFamiliesTree.noProductSelected");
    }

    Entity product = dd.get(productId);

    List<Entity> tree = productsFamiliesTreeService.getHierarchyProductsTree(product);
    EntityTree entityTree = EntityTreeUtilsService.getDetachedEntityTree(tree);
    formEntity.setId(productId);
    formEntity.setField(PRODUCT_FAMILY_CHILDREN_TREE, entityTree);

    return formEntity;
  }
  public void checkDoneCalculate(final ViewDefinitionState viewDefinitionState) {
    FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form");
    Entity order =
        dataDefinitionService
            .get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)
            .get(orderId);

    Integer realizationTime = (Integer) order.getField("realizationTime");
    if (realizationTime == null) {
      form.addMessage("orders.order.report.realizationTime", MessageType.INFO, false);
    }
  }
 public boolean isRealizationTimeGenerated(final ViewDefinitionState viewDefinitionState) {
   FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form");
   if (form.getEntityId() == null) {
     return false;
   }
   Entity order =
       dataDefinitionService
           .get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)
           .get(form.getEntityId());
   Integer realizationTime = (Integer) order.getField("realizationTime");
   return !(realizationTime == null || realizationTime == 0);
 }
  private void setStaffFilter(ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(L_FORM);
    Entity multiAssignment = form.getPersistedEntityWithIncludedFormValues();
    Entity assignment = multiAssignment.getBelongsToField("assignmentToShift");
    if (assignment != null) {
      Entity crew = assignment.getBelongsToField(AssignmentToShiftFields.CREW);

      LookupComponent staffLookup = (LookupComponent) view.getComponentByReference("staffLookup");

      staffCriteriaModifier.putCrewNumber(staffLookup, crew);
    }
  }
예제 #5
0
 public void generateTreeWhenIdIsSet(final ViewDefinitionState view) {
   FormComponent form = getForm(view);
   try {
     Entity formEntity = generateFormEntity(view);
     if (formEntity == null) {
       return;
     }
     form.setEntity(formEntity);
     view.getComponentByReference(PRODUCT_FAMILY_CHILDREN_TREE).setEnabled(true);
   } catch (FormValidationException e) {
     form.addMessage(e.getMessage(), MessageType.FAILURE);
   }
 }
  private boolean orderHasTechnologyAndCorrectState(final ViewDefinitionState view) {
    FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM);

    Long orderId = orderForm.getEntityId();

    if (orderId == null) {
      return false;
    }

    Entity order = orderForm.getEntity().getDataDefinition().get(orderId);

    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
    String state = order.getStringField(OrderFields.STATE);

    return ((technology != null) && checkIfOrderStateIsCorrect(state));
  }
  private void enableAddButton(ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(L_FORM);
    Entity multiAssignment = form.getPersistedEntityWithIncludedFormValues();

    GridComponent workersComponent = (GridComponent) view.getComponentByReference("workers");
    WindowComponent window = (WindowComponent) view.getComponentByReference("window");
    RibbonGroup add = (RibbonGroup) window.getRibbon().getGroupByName("add");
    RibbonActionItem addMany = (RibbonActionItem) add.getItemByName("addManyWorkers");
    if (workersComponent.getEntities().isEmpty() || !multiAssignment.isValid()) {
      addMany.setEnabled(false);
      addMany.requestUpdate(true);
    } else {
      addMany.setEnabled(true);
      addMany.requestUpdate(true);
    }
  }
  public void setOccupationTypeToDefault(final ViewDefinitionState view) {
    FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form");
    FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE);

    if ((staffAssignmentToShiftForm.getEntityId() == null)
        && (occupationType.getFieldValue() == null)) {
      Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue());

      if (dictionaryItem != null) {
        String occupationTypeName = dictionaryItem.getStringField(NAME);

        occupationType.setFieldValue(occupationTypeName);
        occupationType.requestComponentUpdateState();
      }
    }
  }
  public void disableCalendarButtonWhenRealizationTimeNotGenerated(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference("form");
    if (form.getEntity() == null) {
      return;
    }

    WindowComponent window = (WindowComponent) view.getComponentByReference("window");
    RibbonActionItem showOnCalendarButton =
        window
            .getRibbon()
            .getGroupByName(ProductionSchedulingConstants.VIEW_RIBBON_ACTION_ITEM_GROUP)
            .getItemByName(ProductionSchedulingConstants.VIEW_RIBBON_ACTION_ITEM_NAME);
    if (isRealizationTimeGenerated(view)) {
      showOnCalendarButton.setEnabled(true);
    } else {
      showOnCalendarButton.setEnabled(false);
    }
    showOnCalendarButton.requestUpdate(true);
  }
  public void fillUnitField(
      final ViewDefinitionState viewDefinitionState,
      final String fieldName,
      final boolean inProduct) {
    checkArgument(viewDefinitionState != null, L_VIEW_DEFINITION_STATE_IS_NULL);

    FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference(L_FORM);
    FieldComponent unitField =
        (FieldComponent) viewDefinitionState.getComponentByReference(fieldName);
    unitField.setFieldValue(L_EMPTY);
    unitField.setEnabled(false);
    if (form == null || form.getEntityId() == null) {
      return;
    }

    Long productId = null;

    if (inProduct) {
      productId = (Long) form.getFieldValue();
    } else {
      FieldComponent productField =
          (FieldComponent) viewDefinitionState.getComponentByReference("product");

      if (productField == null) {
        return;
      }

      productId = (Long) productField.getFieldValue();
    }

    Entity product =
        dataDefinitionService
            .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT)
            .get(productId);

    if (product == null) {
      return;
    }

    String unit = product.getStringField(UNIT);

    fillField(unitField, unit);
  }
  public void fillCurrencyFields(
      final ViewDefinitionState viewDefinitionState, final Set<String> fieldNames) {
    checkArgument(viewDefinitionState != null, L_VIEW_DEFINITION_STATE_IS_NULL);

    FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference(L_FORM);
    clearAndDisabledFields(viewDefinitionState, fieldNames);
    if (form == null || form.getEntityId() == null) {
      return;
    }
    String currency = currencyService.getCurrencyAlphabeticCode();
    if (currency == null) {
      return;
    }
    for (String fieldName : fieldNames) {
      FieldComponent currencyField =
          (FieldComponent) viewDefinitionState.getComponentByReference(fieldName);
      fillField(currencyField, currency);
    }
  }
  public void setGenerateButtonState(
      final ViewDefinitionState state,
      final Locale locale,
      final String plugin,
      final String entityName) {
    WindowComponent window = (WindowComponent) state.getComponentByReference("window");
    FormComponent form = (FormComponent) state.getComponentByReference("form");
    RibbonActionItem generateButton =
        window.getRibbon().getGroupByName("generate").getItemByName("generate");
    RibbonActionItem deleteButton =
        window.getRibbon().getGroupByName("actions").getItemByName("delete");

    if (form.getEntityId() == null) {
      generateButton.setMessage("recordNotCreated");
      generateButton.setEnabled(false);
      deleteButton.setMessage(null);
      deleteButton.setEnabled(false);
    } else {

      Entity simpleMaterialBalanceEntity =
          dataDefinitionService.get(plugin, entityName).get(form.getEntityId());

      if (simpleMaterialBalanceEntity.getField(L_GENERATED) == null) {
        simpleMaterialBalanceEntity.setField(L_GENERATED, "0");
      }

      if ("1".equals(simpleMaterialBalanceEntity.getField(L_GENERATED))) {
        generateButton.setMessage("orders.ribbon.message.recordAlreadyGenerated");
        generateButton.setEnabled(false);
        deleteButton.setMessage("orders.ribbon.message.recordAlreadyGenerated");
        deleteButton.setEnabled(false);
      } else {
        generateButton.setMessage(null);
        generateButton.setEnabled(true);
        deleteButton.setMessage(null);
        deleteButton.setEnabled(true);
      }
    }
    generateButton.requestUpdate(true);
    deleteButton.requestUpdate(true);
    window.requestRibbonRender();
  }
  public void enabledFieldForExternalID(final ViewDefinitionState view) {
    FieldComponent nominalCost = (FieldComponent) view.getComponentByReference(L_NOMINAL_COST);
    FormComponent form = (FormComponent) view.getComponentByReference(L_FORM);
    if (form.getEntityId() == null) {
      return;
    }
    Entity entity =
        dataDefinitionService
            .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT)
            .get(form.getEntityId());

    if (entity == null) {
      return;
    }
    String externalNumber = entity.getStringField("externalNumber");

    if (externalNumber != null) {
      nominalCost.setEnabled(true);
    }
  }
  @Before
  public void init() {
    hooks = new TechnologyOperationComponentInOrderListHooks();
    MockitoAnnotations.initMocks(this);
    ReflectionTestUtils.setField(hooks, "dataDefinitionService", dataDefinitionService);

    Long orderId = 1L;
    when(dataDefinitionService.get(PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER))
        .thenReturn(dataDefinition);
    when(view.getComponentByReference("form")).thenReturn(form);
    when(form.getEntityId()).thenReturn(orderId);
    when(dataDefinition.get(orderId)).thenReturn(order);
    when(view.getComponentByReference("technology")).thenReturn(technologyField);
  }
  @Transactional
  public void generateRealizationTime(
      final ViewDefinitionState viewDefinitionState,
      final ComponentState state,
      final String[] args) {
    FormComponent orderForm = (FormComponent) viewDefinitionState.getComponentByReference(L_FORM);
    FieldComponent startTimeField =
        (FieldComponent) viewDefinitionState.getComponentByReference(L_START_TIME);

    if (!StringUtils.hasText((String) startTimeField.getFieldValue())) {
      startTimeField.addMessage(L_PRODUCTION_SCHEDULING_ERROR_FIELD_REQUIRED, MessageType.FAILURE);

      return;
    }

    FieldComponent plannedQuantityField =
        (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PLANNED_QUANTITY);
    FieldComponent productionLineLookup =
        (FieldComponent) viewDefinitionState.getComponentByReference(OrderFields.PRODUCTION_LINE);
    FieldComponent generatedEndDateField =
        (FieldComponent)
            viewDefinitionState.getComponentByReference(OrderFieldsPS.GENERATED_END_DATE);
    FieldComponent includeTpzField =
        (FieldComponent) viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_TPZ);
    FieldComponent includeAdditionalTimeField =
        (FieldComponent)
            viewDefinitionState.getComponentByReference(OrderFieldsPS.INCLUDE_ADDITIONAL_TIME);

    boolean isGenerated = false;

    Entity productionLine =
        dataDefinitionService
            .get(
                ProductionLinesConstants.PLUGIN_IDENTIFIER,
                ProductionLinesConstants.MODEL_PRODUCTION_LINE)
            .get((Long) productionLineLookup.getFieldValue());

    Entity order =
        dataDefinitionService
            .get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)
            .get(orderForm.getEntity().getId());

    // copy of technology from order
    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
    Validate.notNull(technology, "technology is null");
    BigDecimal quantity =
        orderRealizationTimeService.getBigDecimalFromField(
            plannedQuantityField.getFieldValue(), viewDefinitionState.getLocale());

    // Included in work time
    Boolean includeTpz = "1".equals(includeTpzField.getFieldValue());
    Boolean includeAdditionalTime = "1".equals(includeAdditionalTimeField.getFieldValue());

    final Map<Long, BigDecimal> operationRuns = Maps.newHashMap();

    productQuantitiesService.getProductComponentQuantities(technology, quantity, operationRuns);

    OperationWorkTime workTime =
        operationWorkTimeService.estimateTotalWorkTimeForOrder(
            order, operationRuns, includeTpz, includeAdditionalTime, productionLine, true);

    fillWorkTimeFields(viewDefinitionState, workTime);

    order = getActualOrderWithChanges(order);

    int maxPathTime =
        orderRealizationTimeService.estimateMaxOperationTimeConsumptionForWorkstation(
            technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).getRoot(),
            quantity,
            includeTpz,
            includeAdditionalTime,
            productionLine);

    if (maxPathTime > OrderRealizationTimeService.MAX_REALIZATION_TIME) {
      state.addMessage("orders.validate.global.error.RealizationTimeIsToLong", MessageType.FAILURE);

      generatedEndDateField.setFieldValue(null);
    } else {
      order.setField(OrderFieldsPS.REALIZATION_TIME, maxPathTime);

      Date startTime = order.getDateField(OrderFields.DATE_FROM);

      if (startTime == null) {
        startTimeField.addMessage(
            "orders.validate.global.error.dateFromIsNull", MessageType.FAILURE);
      } else {
        Date stopTime = shiftsService.findDateToForOrder(startTime, maxPathTime);

        if (stopTime == null) {
          orderForm.addMessage("productionScheduling.timenorms.isZero", MessageType.FAILURE, false);

          generatedEndDateField.setFieldValue(null);
        } else {
          generatedEndDateField.setFieldValue(orderRealizationTimeService.setDateToField(stopTime));

          order.setField(
              OrderFieldsPS.GENERATED_END_DATE,
              orderRealizationTimeService.setDateToField(stopTime));

          scheduleOrder(order.getId());

          isGenerated = true;
        }

        orderForm.addMessage(
            "orders.dateFrom.info.dateFromSetToFirstPossible", MessageType.INFO, false);
      }

      order = order.getDataDefinition().save(order);
      orderForm.setEntity(order);
    }

    generatedEndDateField.requestComponentUpdateState();

    if (isGenerated) {
      orderForm.addMessage("productionScheduling.info.calculationGenerated", MessageType.SUCCESS);
    }
  }