public Entity createResource(
      final Entity position,
      final Entity warehouse,
      final Entity resource,
      final BigDecimal quantity,
      Object date) {
    DataDefinition resourceDD =
        dataDefinitionService.get(
            MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
            MaterialFlowResourcesConstants.MODEL_RESOURCE);

    Entity newResource = resourceDD.create();

    if (position != null) {
      Entity document = position.getBelongsToField(PositionFields.DOCUMENT);

      if (document != null) {
        Entity user = document.getBelongsToField(DocumentFields.USER);

        newResource.setField(
            ResourceFields.USER_NAME,
            user.getStringField(_FIRST_NAME) + " " + user.getStringField(L_LAST_NAME));
      }
    }

    newResource.setField(ResourceFields.TIME, date);
    newResource.setField(ResourceFields.LOCATION, warehouse);
    newResource.setField(
        ResourceFields.PRODUCT, resource.getBelongsToField(PositionFields.PRODUCT));
    newResource.setField(ResourceFields.QUANTITY, quantity);
    newResource.setField(ResourceFields.AVAILABLE_QUANTITY, quantity);
    newResource.setField(ResourceFields.RESERVED_QUANTITY, BigDecimal.ZERO);
    newResource.setField(ResourceFields.PRICE, resource.getField(PositionFields.PRICE));
    newResource.setField(ResourceFields.BATCH, resource.getField(PositionFields.BATCH));
    newResource.setField(
        ResourceFields.EXPIRATION_DATE, resource.getField(PositionFields.EXPIRATION_DATE));
    newResource.setField(
        ResourceFields.PRODUCTION_DATE, resource.getField(PositionFields.PRODUCTION_DATE));
    newResource.setField(
        ResourceFields.STORAGE_LOCATION, resource.getField(ResourceFields.STORAGE_LOCATION));
    newResource.setField(
        ResourceFields.ADDITIONAL_CODE, resource.getField(ResourceFields.ADDITIONAL_CODE));
    newResource.setField(ResourceFields.CONVERSION, resource.getField(ResourceFields.CONVERSION));
    newResource.setField(
        ResourceFields.PALLET_NUMBER, resource.getField(ResourceFields.PALLET_NUMBER));
    newResource.setField(
        ResourceFields.TYPE_OF_PALLET, resource.getField(ResourceFields.TYPE_OF_PALLET));
    newResource.setField(ResourceFields.GIVEN_UNIT, resource.getField(ResourceFields.GIVEN_UNIT));

    BigDecimal quantityInAdditionalUnit =
        numberService.setScale(
            quantity.multiply(resource.getDecimalField(ResourceFields.CONVERSION)));

    newResource.setField(ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT, quantityInAdditionalUnit);

    setResourceAttributesFromResource(newResource, resource);

    resourceStockService.addResourceStock(newResource);
    return resourceDD.save(newResource);
  }
  public boolean checkIfCustomTranslationIsUnique(
      final DataDefinition customTranslationDD, final Entity customTranslation) {
    String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER);
    String locale = customTranslation.getStringField(LOCALE);
    String key = customTranslation.getStringField(KEY);

    SearchCriteriaBuilder searchCriteriaBuilder =
        customTranslationDD
            .find()
            .add(SearchRestrictions.eq(PLUGIN_IDENTIFIER, pluginIdentifier))
            .add(SearchRestrictions.eq(LOCALE, locale))
            .add(SearchRestrictions.eq(KEY, key));

    if (customTranslation.getId() != null) {
      searchCriteriaBuilder.add(SearchRestrictions.ne("id", customTranslation.getId()));
    }

    SearchResult searchResult = searchCriteriaBuilder.list();

    if (!searchResult.getEntities().isEmpty()) {
      customTranslation.addError(
          customTranslationDD.getField(KEY),
          "customTranslation.customTranslation.error.customTranslationIsntUnique");

      return false;
    }

    return true;
  }
Beispiel #3
0
  private void updateTechnology(final Entity technology) {
    String number = technology.getStringField(TechnologyFields.NUMBER);
    Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);

    technology.setField(TechnologyFields.NAME, makeTechnologyName(number, product));
    technology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, null);
    technology.setField(
        TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_OWN_TECHNOLOGY.getStringValue());

    EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);

    if ((operationComponents != null) && !operationComponents.isEmpty()) {
      EntityTreeNode root = operationComponents.getRoot();

      root.getDataDefinition().delete(root.getId());
    }

    technology.setField(TechnologyFields.OPERATION_COMPONENTS, Lists.newArrayList());

    technology.getDataDefinition().save(technology);

    if (TechnologyStateStringValues.CHECKED.equals(
        technology.getStringField(TechnologyFields.STATE))) {
      changeTechnologyState(technology, TechnologyStateStringValues.DRAFT);
    }
  }
  @Override
  @Transactional
  public void updateResourcesForReleaseDocuments(final Entity document) {
    Entity warehouse = document.getBelongsToField(DocumentFields.LOCATION_FROM);
    WarehouseAlgorithm warehouseAlgorithm;

    boolean enoughResources = true;

    StringBuilder errorMessage = new StringBuilder();

    Multimap<Long, BigDecimal> quantitiesForWarehouse =
        getQuantitiesInWarehouse(warehouse, getProductsAndPositionsFromDocument(document));

    List<Entity> generatedPositions = Lists.newArrayList();

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      Entity product = position.getBelongsToField(PositionFields.PRODUCT);
      Entity resource = position.getBelongsToField(PositionFields.RESOURCE);

      BigDecimal quantityInWarehouse;

      if (resource != null) {
        warehouse = resource.getBelongsToField(ResourceFields.LOCATION);
        warehouseAlgorithm = WarehouseAlgorithm.MANUAL;
      } else {
        warehouse = document.getBelongsToField(DocumentFields.LOCATION_FROM);
        warehouseAlgorithm =
            WarehouseAlgorithm.parseString(warehouse.getStringField(LocationFieldsMFR.ALGORITHM));
      }

      if (warehouseAlgorithm.equals(WarehouseAlgorithm.MANUAL)) {
        quantityInWarehouse = getQuantityOfProductInWarehouse(warehouse, product, position);
      } else {
        quantityInWarehouse = getQuantityOfProductFromMultimap(quantitiesForWarehouse, product);
      }

      generatedPositions.addAll(updateResources(warehouse, position, warehouseAlgorithm));

      enoughResources = enoughResources && position.isValid();

      if (!position.isValid()) {
        BigDecimal quantity = position.getDecimalField(QUANTITY);

        errorMessage.append(product.getStringField(ProductFields.NAME));
        errorMessage.append(" - ");
        errorMessage.append(numberService.format(quantity.subtract(quantityInWarehouse)));
        errorMessage.append(" ");
        errorMessage.append(product.getStringField(ProductFields.UNIT));
        errorMessage.append(", ");
      }
    }

    if (!enoughResources) {
      addDocumentError(document, warehouse, errorMessage);
    } else {
      deleteReservations(document);
      document.setField(DocumentFields.POSITIONS, generatedPositions);
    }
  }
  public void changeActiveState(
      final DataDefinition customTranslationDD, final Entity customTranslation) {
    String pluginIdentifier = customTranslation.getStringField(PLUGIN_IDENTIFIER);
    String translation = customTranslation.getStringField(CUSTOM_TRANSLATION);

    if (pluginStateResolver.isEnabled(pluginIdentifier)) {
      customTranslation.setField(ACTIVE, (translation != null));
    }
  }
  public void updateCache(
      final DataDefinition customTranslationDD, final Entity customTranslation) {
    boolean active = customTranslation.getBooleanField(ACTIVE);

    String key = customTranslation.getStringField(KEY);
    String locale = customTranslation.getStringField(LOCALE);
    String translation = (active) ? customTranslation.getStringField(CUSTOM_TRANSLATION) : null;

    customTranslationCacheService.manageCustomTranslation(key, locale, translation);
  }
 private String getOrderDescription(final Entity order, final Locale locale) {
   return order.getStringField("number")
       + " - "
       + order.getStringField("name")
       + "<br/>"
       + translationService.translate("orders.order.state.label", locale)
       + ": "
       + translationService.translate(
           "orders.order.state.value." + order.getStringField("state"), locale);
 }
  public Entity createResource(
      final Entity document, final Entity warehouse, final Entity position, final Object date) {
    DataDefinition resourceDD =
        dataDefinitionService.get(
            MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
            MaterialFlowResourcesConstants.MODEL_RESOURCE);

    Entity product = position.getBelongsToField(PositionFields.PRODUCT);
    Entity resource = resourceDD.create();
    Entity user = document.getBelongsToField(DocumentFields.USER);

    resource.setField(
        ResourceFields.USER_NAME,
        user.getStringField(_FIRST_NAME) + " " + user.getStringField(L_LAST_NAME));
    resource.setField(ResourceFields.TIME, date);
    resource.setField(ResourceFields.LOCATION, warehouse);
    resource.setField(ResourceFields.PRODUCT, position.getBelongsToField(PositionFields.PRODUCT));
    resource.setField(ResourceFields.QUANTITY, position.getField(PositionFields.QUANTITY));
    resource.setField(ResourceFields.RESERVED_QUANTITY, BigDecimal.ZERO);
    resource.setField(
        ResourceFields.AVAILABLE_QUANTITY, position.getDecimalField(PositionFields.QUANTITY));
    resource.setField(ResourceFields.PRICE, position.getField(PositionFields.PRICE));
    resource.setField(ResourceFields.BATCH, position.getField(PositionFields.BATCH));
    resource.setField(
        ResourceFields.EXPIRATION_DATE, position.getField(PositionFields.EXPIRATION_DATE));
    resource.setField(
        ResourceFields.PRODUCTION_DATE, position.getField(PositionFields.PRODUCTION_DATE));
    resource.setField(
        ResourceFields.STORAGE_LOCATION, position.getField(PositionFields.STORAGE_LOCATION));
    resource.setField(
        ResourceFields.ADDITIONAL_CODE, position.getField(PositionFields.ADDITIONAL_CODE));
    resource.setField(
        ResourceFields.PALLET_NUMBER, position.getField(PositionFields.PALLET_NUMBER));
    resource.setField(
        ResourceFields.TYPE_OF_PALLET, position.getField(PositionFields.TYPE_OF_PALLET));
    resource.setField(ResourceFields.WASTE, position.getField(PositionFields.WASTE));

    if (StringUtils.isEmpty(product.getStringField(ProductFields.ADDITIONAL_UNIT))) {
      resource.setField(ResourceFields.GIVEN_UNIT, product.getField(ProductFields.UNIT));
      resource.setField(
          ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT, position.getField(PositionFields.QUANTITY));
      resource.setField(ResourceFields.CONVERSION, BigDecimal.ONE);
    } else {
      resource.setField(ResourceFields.GIVEN_UNIT, position.getField(PositionFields.GIVEN_UNIT));
      resource.setField(
          ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT,
          position.getField(PositionFields.GIVEN_QUANTITY));
      resource.setField(ResourceFields.CONVERSION, position.getField(PositionFields.CONVERSION));
    }

    setResourceAttributesFromPosition(resource, position);

    resourceStockService.addResourceStock(resource);
    return resourceDD.save(resource);
  }
  public void closeOrder(final StateChangeContext stateChangeContext) {
    final Entity productionTracking = stateChangeContext.getOwner();
    final Entity order = productionTracking.getBelongsToField(ORDER);

    if (!orderClosingHelper.orderShouldBeClosed(productionTracking)) {
      return;
    }
    if (order.getStringField(STATE).equals(COMPLETED.getStringValue())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderIsAlreadyClosed", StateMessageType.INFO, false);
      return;
    }
    final StateChangeContext orderStateChangeContext =
        stateChangeContextBuilder.build(
            orderStateChangeAspect.getChangeEntityDescriber(),
            order,
            OrderState.COMPLETED.getStringValue());
    orderStateChangeAspect.changeState(orderStateChangeContext);
    Entity orderFromDB = order.getDataDefinition().get(orderStateChangeContext.getOwner().getId());
    if (orderFromDB.getStringField(STATE).equals(COMPLETED.getStringValue())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderClosed", StateMessageType.INFO, false);
    } else if (StateChangeStatus.PAUSED.equals(orderStateChangeContext.getStatus())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderWillBeClosedAfterExtSync", StateMessageType.INFO, false);
    } else {
      stateChangeContext.addMessage(
          "productionCounting.order.orderCannotBeClosed", StateMessageType.FAILURE, false);

      List<ErrorMessage> errors = Lists.newArrayList();

      if (!orderFromDB.getErrors().isEmpty()) {
        errors.addAll(order.getErrors().values());
      }
      if (!orderFromDB.getGlobalErrors().isEmpty()) {
        errors.addAll(order.getGlobalErrors());
      }

      if (!errors.isEmpty()) {
        StringBuilder errorMessages = new StringBuilder();

        for (ErrorMessage errorMessage : errors) {
          String translatedErrorMessage =
              translationService.translate(
                  errorMessage.getMessage(), Locale.getDefault(), errorMessage.getVars());
          errorMessages.append(translatedErrorMessage);
          errorMessages.append(", ");
        }

        stateChangeContext.addValidationError(
            "orders.order.orderStates.error", errorMessages.toString());
      }
    }
  }
 public String generateName(final Entity product) {
   LocalDate date = LocalDate.now();
   String currentDateString = String.format("%s.%s", date.getYear(), date.getMonthValue());
   String productName = product.getStringField(ProductFields.NAME);
   String productNumber = product.getStringField(ProductFields.NUMBER);
   return translationService.translate(
       "technologies.operation.name.default",
       LocaleContextHolder.getLocale(),
       productName,
       productNumber,
       currentDateString);
 }
Beispiel #11
0
 public String generateNumberForTechnologyInOrder(final Entity order, final Entity technology) {
   StringBuffer number = new StringBuffer();
   if (technology == null) {
     number.append(
         numberGeneratorService.generateNumber(
             TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY));
   } else {
     number.append(technology.getStringField(TechnologyFields.NUMBER));
   }
   number.append(" - ");
   number.append(order.getStringField(OrderFields.NUMBER));
   return number.toString();
 }
  @Override
  @Transactional
  public void moveResourcesForTransferDocument(Entity document) {
    Entity warehouseFrom = document.getBelongsToField(DocumentFields.LOCATION_FROM);
    Entity warehouseTo = document.getBelongsToField(DocumentFields.LOCATION_TO);
    Object date = document.getField(DocumentFields.TIME);

    WarehouseAlgorithm warehouseAlgorithm =
        WarehouseAlgorithm.parseString(warehouseFrom.getStringField(LocationFieldsMFR.ALGORITHM));

    boolean enoughResources = true;

    StringBuilder errorMessage = new StringBuilder();

    Multimap<Long, BigDecimal> quantitiesForWarehouse =
        getQuantitiesInWarehouse(warehouseFrom, getProductsAndPositionsFromDocument(document));

    for (Entity position : document.getHasManyField(DocumentFields.POSITIONS)) {
      Entity product = position.getBelongsToField(PositionFields.PRODUCT);
      BigDecimal quantityInWarehouse;

      if (warehouseAlgorithm.equals(WarehouseAlgorithm.MANUAL)) {
        quantityInWarehouse = getQuantityOfProductInWarehouse(warehouseFrom, product, position);
      } else {
        quantityInWarehouse = getQuantityOfProductFromMultimap(quantitiesForWarehouse, product);
      }

      moveResources(warehouseFrom, warehouseTo, position, date, warehouseAlgorithm);
      enoughResources = enoughResources && position.isValid();

      if (!position.isValid()) {
        BigDecimal quantity = position.getDecimalField(QUANTITY);

        errorMessage.append(product.getStringField(ProductFields.NAME));
        errorMessage.append(" - ");
        errorMessage.append(numberService.format(quantity.subtract(quantityInWarehouse)));
        errorMessage.append(" ");
        errorMessage.append(product.getStringField(ProductFields.UNIT));
        errorMessage.append(", ");
      }
    }

    if (!enoughResources) {
      addDocumentError(document, warehouseFrom, errorMessage);
    } else {
      deleteReservations(document);
    }
  }
  public void checkIfExistsFinalRecord(final StateChangeContext stateChangeContext) {
    final Entity productionTracking = stateChangeContext.getOwner();
    final Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
    final String typeOfProductionRecording =
        order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);

    final SearchCriteriaBuilder searchBuilder = productionTracking.getDataDefinition().find();
    searchBuilder.add(
        SearchRestrictions.eq(
            ProductionTrackingFields.STATE, ProductionTrackingStateStringValues.ACCEPTED));
    searchBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order));
    searchBuilder.add(SearchRestrictions.eq(ProductionTrackingFields.LAST_TRACKING, true));

    if (productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)) {
      searchBuilder.add(
          SearchRestrictions.belongsTo(
              ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT,
              productionTracking.getBelongsToField(
                  ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT)));
    }

    if (searchBuilder.list().getTotalNumberOfEntities() != 0) {
      stateChangeContext.addValidationError(
          "productionCounting.productionTracking.messages.error.finalExists");
    }
  }
Beispiel #14
0
  /**
   * Creates position with given field values (with the same base and given unit)
   *
   * @param product
   * @param quantity
   * @param price
   * @param batch
   * @param expirationDate
   * @param productionDate
   * @param resource
   * @return Created position entity
   */
  public Entity createPosition(
      final Entity product,
      final BigDecimal quantity,
      final BigDecimal price,
      final String batch,
      final Date productionDate,
      final Date expirationDate,
      final Entity resource) {
    DataDefinition positionDD =
        dataDefinitionService.get(
            MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
            MaterialFlowResourcesConstants.MODEL_POSITION);
    Entity position = positionDD.create();

    position.setField(PositionFields.PRODUCT, product);
    position.setField(PositionFields.QUANTITY, quantity);
    position.setField(PositionFields.GIVEN_QUANTITY, quantity);
    position.setField(PositionFields.GIVEN_UNIT, product.getStringField(ProductFields.UNIT));
    position.setField(PositionFields.PRICE, price);
    position.setField(PositionFields.BATCH, batch);
    position.setField(PositionFields.PRODUCTION_DATE, productionDate);
    position.setField(PositionFields.EXPIRATION_DATE, expirationDate);
    position.setField(PositionFields.RESOURCE, resource);
    return position;
  }
  @Test
  public void shouldReturnFalseWhenEntityWithGivenProductAndCompanyDoesExistsInDB()
      throws Exception {
    // given
    SearchCriterion criterion1 =
        SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER));
    SearchCriterion criterion2 =
        SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT));

    given(entity.getId()).willReturn(null);
    given(criteria.add(criterion1)).willReturn(criteria);
    given(criteria.add(criterion2)).willReturn(criteria);
    given(criteria.list()).willReturn(searchResult);
    given(searchResult.getEntities()).willReturn(productCatalogNumbers);
    given(productCatalogNumbers.isEmpty()).willReturn(false);
    // when
    boolean result =
        productCatalogNumbersHooks.checkIfExistsCatalogNumberWithProductAndCompany(
            dataDefinition, entity);
    // then
    Assert.assertFalse(result);
    Mockito.verify(entity)
        .addGlobalError(
            "productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsProductForCompany");
  }
  @Override
  public Set<ImportedOrder> getImportedOrders(final Set<Long> orderIds) {
    Set<ImportedOrder> result = new HashSet<ImportedOrder>();
    for (Long importedOrderId : orderIds) {
      Entity orderEntity =
          dataDefinitionService
              .get(SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_ORDER)
              .get(importedOrderId);

      ImportedOrder order = new ImportedOrder(importedOrderId);

      order.setNumber(orderEntity.getStringField(FIELD_NUMBER));
      order.setDrawDate((Date) orderEntity.getField(FIELD_DRAW_DATE));
      order.setRealizationDate((Date) orderEntity.getField(FIELD_REALIZATION_DATE));

      for (Entity orderProductEntity : orderEntity.getHasManyField("orderProducts")) {

        ImportedProduct orderItemProduct =
            createImportedProduct(orderProductEntity.getBelongsToField("product"), true);
        if (orderItemProduct != null) {
          ImportedOrderItem orderItem = new ImportedOrderItem();
          orderItem.setProduct(orderItemProduct);
          orderItem.setQuantity((BigDecimal) orderProductEntity.getField(FIELD_QUANTITY));
          order.addItem(orderItem);
        }
      }

      result.add(order);
    }

    return result;
  }
  public void showProductionTrackingsForProduct(
      final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent productionTrackingsForProductGroupedGrid =
        (GridComponent) view.getComponentByReference(L_GRID);

    if (productionTrackingsForProductGroupedGrid.getSelectedEntities().isEmpty()) {
      return;
    }

    Entity productionTrackingsForProductGrouped =
        productionTrackingsForProductGroupedGrid.getSelectedEntities().get(0);

    StringBuilder orderNumberBuilder = new StringBuilder();

    orderNumberBuilder.append("[");
    orderNumberBuilder.append(
        productionTrackingsForProductGrouped.getStringField(
            ProductionTrackingForProductGroupedDtoFields.ORDER_NUMBER));
    orderNumberBuilder.append("]");

    StringBuilder productNumberBuilder = new StringBuilder();

    String orderNumber = orderNumberBuilder.toString();

    productNumberBuilder.append("[");
    productNumberBuilder.append(
        productionTrackingsForProductGrouped.getStringField(
            ProductionTrackingForProductGroupedDtoFields.PRODUCT_NUMBER));
    productNumberBuilder.append("]");

    String productNumber = productNumberBuilder.toString();

    Map<String, String> filters = Maps.newHashMap();
    filters.put("orderNumber", orderNumber);
    filters.put("productNumber", productNumber);

    Map<String, Object> gridOptions = Maps.newHashMap();
    gridOptions.put(L_FILTERS, filters);

    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put(L_GRID_OPTIONS, gridOptions);

    parameters.put(L_WINDOW_ACTIVE_MENU, "ordersTracking.productionTrackingForProduct");

    String url = "../page/productionCounting/productionTrackingsForProductList.html";
    view.redirectTo(url, false, true, parameters);
  }
Beispiel #18
0
  private void generateNumber(final Entity palletNumber) {
    String number = palletNumber.getStringField(PalletNumberFields.NUMBER);

    if (StringUtils.isEmpty(number)) {
      number = palletNumberGenerator.generate();
    }

    palletNumber.setField(PalletNumberFields.NUMBER, number);
  }
Beispiel #19
0
  private String generateNumber(final Entity company, final Long number) {
    StringBuilder numberBuilder = new StringBuilder();

    numberBuilder.append(company.getStringField(CompanyFields.NUMBER));
    numberBuilder.append(L_DASH);
    numberBuilder.append(String.format("%02d", number));

    return numberBuilder.toString();
  }
  private ImportedProduct createImportedProduct(
      final Entity productEntity, final boolean isOrderConversion) {
    ImportedProduct product = new ImportedProduct(productEntity.getId());

    if ("02service".equals(productEntity.getField(FIELD_TYPE))) {
      return null;
    } else if (isOrderConversion || "04set".equals(productEntity.getField(FIELD_TYPE))) {
      product.setTypeOfMaterial("03finalProduct");
    } else {
      product.setTypeOfMaterial("01component");
    }

    product.setNumber(productEntity.getStringField(FIELD_IDENTIFICATION_CODE));
    product.setName(productEntity.getStringField(FIELD_NAME));
    product.setEan(productEntity.getStringField("ean"));
    product.setUnit(productEntity.getStringField(FIELD_UNIT));

    return product;
  }
  public BigDecimal convertToGivenUnit(BigDecimal quantity, Entity position) {
    Entity product = position.getBelongsToField(PositionFields.PRODUCT);
    String baseUnit = product.getStringField(ProductFields.UNIT);
    String givenUnit = position.getStringField(PositionFields.GIVEN_UNIT);

    if (!baseUnit.equals(givenUnit)) {
      PossibleUnitConversions unitConversions =
          unitConversionService.getPossibleConversions(
              baseUnit,
              searchCriteriaBuilder ->
                  searchCriteriaBuilder.add(
                      SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, product)));

      if (unitConversions.isDefinedFor(givenUnit)) {
        return unitConversions.convertTo(quantity, givenUnit);
      }
    }

    return quantity;
  }
  private void checkIfProductionLineFilled(
      DataDefinition multiAssignmentToShiftDD, Entity multiAssignmentToShift) {
    if (multiAssignmentToShift.getId() != null) {
      String occupationType =
          multiAssignmentToShift.getStringField(MultiAssignmentToShiftFields.OCCUPATION_TYPE);

      Entity dictionaryItem = findDictionaryItemByName(occupationType);

      String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE);

      if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) {
        if (multiAssignmentToShift.getBelongsToField(MultiAssignmentToShiftFields.PRODUCTION_LINE)
            == null) {
          multiAssignmentToShift.addError(
              multiAssignmentToShiftDD.getField(MultiAssignmentToShiftFields.PRODUCTION_LINE),
              "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty");
        }
      }
    }
  }
  public boolean isLocked(final Entity order) {
    if (order == null) {
      return true;
    }

    String state = order.getStringField(OrderFields.STATE);

    return (OrderStateStringValues.ACCEPTED.equals(state)
            || OrderStateStringValues.IN_PROGRESS.equals(state)
            || OrderStateStringValues.INTERRUPTED.equals(state))
        && isLocked();
  }
  @Test
  public void shouldSetTechnologyNumberToField() throws Exception {
    // given

    String technologyNumber = "0001";

    when(order.getBelongsToField("technology")).thenReturn(technology);
    when(technology.getStringField("number")).thenReturn(technologyNumber);
    // when
    hooks.setTechnologyNumber(view);
    // then
    Mockito.verify(technologyField).setFieldValue(technologyNumber);
  }
Beispiel #25
0
  private Collection<Long> extractNumericValues(final Iterable<Entity> numberProjections) {
    List<Long> numericValues = Lists.newArrayList();

    for (Entity projection : numberProjections) {
      String numberFieldValue = projection.getStringField(L_NUM_PROJECTION_ALIAS);

      if (StringUtils.isNumeric(numberFieldValue)) {
        numericValues.add(Long.valueOf(numberFieldValue));
      }
    }

    return numericValues;
  }
Beispiel #26
0
  public String getMainAddressType() {
    String addressType = null;

    Optional<Entity> mayBeMainAddressType = getMainAddressTypeDictionaryItem();

    if (mayBeMainAddressType.isPresent()) {
      Entity mainAddressType = mayBeMainAddressType.get();

      addressType = mainAddressType.getStringField(DictionaryItemFields.NAME);
    }

    return addressType;
  }
Beispiel #27
0
  private boolean isOrderTypeChangedToWithPatternTechnology(final Entity order) {
    Entity existingOrder = getExistingOrder(order);

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

    String orderType = existingOrder.getStringField(OrderFields.ORDER_TYPE);

    if (OrderType.WITH_PATTERN_TECHNOLOGY.getStringValue().equals(orderType)) {
      return false;
    }

    return true;
  }
  private void addDocumentError(
      final Entity document, final Entity warehouseFrom, final StringBuilder errorMessage) {
    String warehouseName = warehouseFrom.getStringField(LocationFields.NAME);

    if ((errorMessage.toString().length() + warehouseName.length()) < 255) {
      document.addGlobalError(
          "materialFlow.error.position.quantity.notEnoughResources",
          false,
          errorMessage.toString(),
          warehouseName);
    } else {
      document.addGlobalError(
          "materialFlow.error.position.quantity.notEnoughResourcesShort", false);
    }
  }
  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));
  }
  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();
      }
    }
  }