private void updateBasicProductionCounting(
      final Entity productionTracking, final Operation operation) {
    final Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);

    final List<Entity> basicProductionCountings =
        order.getHasManyField(OrderFieldsBPC.BASIC_PRODUCTION_COUNTINGS);

    final List<Entity> trackingOperationProductInComponents =
        productionTracking.getHasManyField(
            ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENTS);
    final List<Entity> trackingOperationProductOutComponents =
        productionTracking.getHasManyField(
            ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS);

    for (Entity trackingOperationProductInComponent : trackingOperationProductInComponents) {
      Entity basicProductionCounting;

      try {
        basicProductionCounting =
            getBasicProductionCounting(
                trackingOperationProductInComponent, basicProductionCountings);
      } catch (IllegalStateException e) {
        continue;
      }

      final BigDecimal usedQuantity =
          basicProductionCounting.getDecimalField(BasicProductionCountingFields.USED_QUANTITY);
      final BigDecimal productQuantity =
          trackingOperationProductInComponent.getDecimalField(
              TrackingOperationProductInComponentFields.USED_QUANTITY);
      final BigDecimal result = operation.perform(usedQuantity, productQuantity);

      basicProductionCounting.setField(BasicProductionCountingFields.USED_QUANTITY, result);
      basicProductionCounting =
          basicProductionCounting.getDataDefinition().save(basicProductionCounting);
    }

    for (Entity trackingOperationProductOutComponent : trackingOperationProductOutComponents) {
      Entity productionCounting;

      try {
        productionCounting =
            getBasicProductionCounting(
                trackingOperationProductOutComponent, basicProductionCountings);
      } catch (IllegalStateException e) {
        continue;
      }

      final BigDecimal usedQuantity =
          productionCounting.getDecimalField(BasicProductionCountingFields.PRODUCED_QUANTITY);
      final BigDecimal productQuantity =
          trackingOperationProductOutComponent.getDecimalField(
              TrackingOperationProductOutComponentFields.USED_QUANTITY);
      final BigDecimal result = operation.perform(usedQuantity, productQuantity);

      productionCounting.setField(BasicProductionCountingFields.PRODUCED_QUANTITY, result);
      productionCounting = productionCounting.getDataDefinition().save(productionCounting);
    }
  }
  private void generateAndAddWorkPlan() {
    Entity workPlan = dataDefinitionService.get("workPlans", "workPlan").create();

    workPlan.setField(
        L_NAME,
        getNameFromNumberAndPrefix(
            "WorkPlan-", 5 + generateString(CHARS_AND_DIGITS, RANDOM.nextInt(45))));
    workPlan.setField("date", new Date(generateRandomDate()));
    workPlan.setField(
        "worker",
        getNameFromNumberAndPrefix(
            "Worker-", 5 + generateString(CHARS_AND_DIGITS, RANDOM.nextInt(45))));
    workPlan.setField("generated", false);
    workPlan.setField("type", "01noDistinction");

    workPlan = workPlan.getDataDefinition().save(workPlan);

    List<Entity> allOrders =
        dataDefinitionService.get("orders", L_ORDERS_MODEL_ORDER).find().list().getEntities();

    int iters = RANDOM.nextInt(allOrders.size() / 30 + 1);
    for (int i = 0; i < iters; i++) {
      addWorkPlanComponent(workPlan, allOrders);
    }
  }
  private Entity addOperationComponent(
      final Entity technology,
      final Entity parent,
      final Entity operation,
      final int productsComponentsQuantity) {
    Preconditions.checkNotNull(technology, "Technology entity is null");
    Entity operationComponent =
        dataDefinitionService
            .get(L_TECHNOLOGIES_PLUGIN_IDENTIFIER, "technologyOperationComponent")
            .create();

    int productInComponentQuantity = RANDOM.nextInt(productsComponentsQuantity);
    int productOutComponentQuantity = productsComponentsQuantity - productInComponentQuantity;

    operationComponent.setField(
        L_NAME, "operationComponent" + generateString(CHARS_AND_DIGITS, 15));
    operationComponent.setField(L_NUMBER, generateString(CHARS_AND_DIGITS, 20));
    operationComponent.setField(L_TECHNOLOGY_MODEL_TECHNOLOGY, technology);
    operationComponent.setField("parent", parent);
    operationComponent.setField(L_TECHNOLOGY_MODEL_OPERATION, operation);
    operationComponent.setField("entityType", L_TECHNOLOGY_MODEL_OPERATION);
    operationComponent.setField(L_TPZ, operation.getField(L_TPZ));
    operationComponent.setField(L_TJ, operation.getField(L_TJ));
    operationComponent.setField("machineUtilization", operation.getField("machineUtilization"));
    operationComponent.setField("laborUtilization", operation.getField("laborUtilization"));
    operationComponent.setField("productionInOneCycle", operation.getField("productionInOneCycle"));
    operationComponent.setField(
        L_NEXT_OPERATION_AFTER_PRODUCED_TYPE,
        operation.getField(L_NEXT_OPERATION_AFTER_PRODUCED_TYPE));
    operationComponent.setField("nextOperationAfterProducedQuantity", "0");
    operationComponent.setField("timeNextOperation", operation.getField("timeNextOperation"));

    operationComponent = operationComponent.getDataDefinition().save(operationComponent);
    List<Entity> listOut = new LinkedList<Entity>();
    Entity productOut = null;
    for (int i = 0; i < productOutComponentQuantity; i++) {
      productOut = getRandomProduct();

      while (listOut.contains(productOut)) {
        productOut = getRandomProduct();
      }
      listOut.add(productOut);
      generateAndAddOperationProductOutComponent(
          operationComponent, new BigDecimal(RANDOM.nextInt(50) + 5), productOut);
    }
    List<Entity> listIn = new LinkedList<Entity>();
    Entity productIn = null;
    for (int i = 0; i < productInComponentQuantity; i++) {
      productIn = getRandomProduct();

      while (listIn.contains(productIn)) {
        productIn = getRandomProduct();
      }
      listIn.add(productIn);
      generateAndAddOperationProductInComponent(
          operationComponent, new BigDecimal(RANDOM.nextInt(50) + 5), productIn);
    }

    return operationComponent;
  }
Beispiel #4
0
  private Entity getExistingOrder(final Entity order) {
    if (order.getId() == null) {
      return null;
    }

    return order.getDataDefinition().get(order.getId());
  }
  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");
    }
  }
  @Before
  public final void init() {
    workPlanService = new WorkPlansServiceImpl();

    dataDefinitionService = mock(DataDefinitionService.class);
    TranslationService translationService = mock(TranslationService.class);
    workPlan = mock(Entity.class);
    workPlanDD = mock(DataDefinition.class);

    when(dataDefinitionService.get(
            WorkPlansConstants.PLUGIN_IDENTIFIER, WorkPlansConstants.MODEL_WORK_PLAN))
        .thenReturn(workPlanDD);

    when(translationService.translate(
            Mockito.anyString(), Mockito.any(Locale.class), Mockito.anyString()))
        .thenReturn(TRANSLATED_STRING);

    when(workPlanDD.getName()).thenReturn(WorkPlansConstants.MODEL_WORK_PLAN);
    when(workPlanDD.getPluginIdentifier()).thenReturn(WorkPlansConstants.PLUGIN_IDENTIFIER);
    when(workPlanDD.get(Mockito.anyLong())).thenReturn(workPlan);

    when(workPlan.getDataDefinition()).thenReturn(workPlanDD);
    when(workPlan.getId()).thenReturn(1L);

    ReflectionTestUtils.setField(workPlanService, "dataDefinitionService", dataDefinitionService);
    ReflectionTestUtils.setField(workPlanService, "translationService", translationService);
  }
Beispiel #7
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);
    }
  }
Beispiel #8
0
 @Override
 public Entity save(final Entity entity) {
   if (!this.equals(entity.getDataDefinition())) {
     throw new IllegalStateException("Incompatible types");
   }
   return dataAccessService.save(this, entity);
 }
  protected void addCompany(final Map<String, String> values) {
    Entity company =
        dataDefinitionService
            .get(SamplesConstants.BASIC_PLUGIN_IDENTIFIER, SamplesConstants.BASIC_MODEL_COMPANY)
            .create();

    LOG.debug(
        "id: "
            + values.get("id")
            + "number: "
            + values.get("number")
            + " companyFullName "
            + values.get("companyfullname")
            + " tax "
            + values.get("tax")
            + " street "
            + values.get("street")
            + " house "
            + values.get("house")
            + " flat "
            + values.get("flat")
            + " zipCode "
            + values.get("zipcode")
            + " city "
            + values.get("city")
            + " state "
            + values.get("state")
            + " country "
            + values.get("country")
            + " email "
            + values.get(EMAIL)
            + " website "
            + values.get("website")
            + " phone "
            + values.get("phone")
            + " owner "
            + values.get("owner"));

    company.setField("number", values.get("number"));
    company.setField(NAME, values.get(NAME));
    company.setField("tax", values.get("tax"));
    company.setField("street", values.get("street"));
    company.setField("house", values.get("house"));
    company.setField("flat", values.get("flat"));
    company.setField("zipCode", values.get("zipcode"));
    company.setField("city", values.get("city"));
    company.setField("state", values.get("state"));
    company.setField("country", values.get("country"));
    company.setField(EMAIL, values.get(EMAIL));
    company.setField("website", values.get("website"));
    company.setField("phone", values.get("phone"));
    company.setField("owner", values.get("owner"));

    if (LOG.isDebugEnabled()) {
      LOG.debug("Add test company item {company=" + company.getField(NAME) + "}");
    }

    company.getDataDefinition().save(company);
  }
Beispiel #10
0
  private Entity copyTechnology(final Entity order, final Entity technologyPrototype) {
    Entity copyOfTechnology = getTechnologyDD().create();

    String number = generateNumberForTechnologyInOrder(order, technologyPrototype);

    copyOfTechnology =
        copyOfTechnology.getDataDefinition().copy(technologyPrototype.getId()).get(0);

    copyOfTechnology.setField(TechnologyFields.NUMBER, number);
    copyOfTechnology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, technologyPrototype);
    copyOfTechnology.setField(
        TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_PATTERN_TECHNOLOGY.getStringValue());

    copyOfTechnology = copyOfTechnology.getDataDefinition().save(copyOfTechnology);
    changeTechnologyState(copyOfTechnology, TechnologyStateStringValues.CHECKED);
    return copyOfTechnology;
  }
  @Test
  public final void shouldReturnWorkPlan() throws Exception {
    // when
    Entity resultEntity = workPlanService.getWorkPlan(1L);

    // then
    Assert.assertSame(workPlanDD, resultEntity.getDataDefinition());
    Assert.assertEquals(workPlan.getId(), resultEntity.getId());
  }
  private void setOrderDoneQuantity(final Entity productionTracking) {
    Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);

    order.setField(
        OrderFields.DONE_QUANTITY,
        basicProductionCountingService.getProducedQuantityFromBasicProductionCountings(order));

    order.getDataDefinition().save(order);
  }
  @Test
  public void shouldCreatetTechnologyInstOperProductInComp() throws Exception {
    // given
    Long orderId = 1L;
    Long technologyId = 2L;
    BigDecimal nominalCost1 = BigDecimal.TEN;
    BigDecimal nominalCost2 = BigDecimal.TEN;

    when(productQuantities.entrySet()).thenReturn(entrySet);
    when(entrySet.iterator()).thenReturn(iterator);
    when(iterator.hasNext()).thenReturn(true, true, false);
    when(iterator.next()).thenReturn(entry1, entry2);

    when(entry1.getKey()).thenReturn(prod1);
    when(entry2.getKey()).thenReturn(prod2);

    when(prod1.getDecimalField("nominalCost")).thenReturn(nominalCost1);
    when(prod2.getDecimalField("nominalCost")).thenReturn(nominalCost2);

    when(order.getBelongsToField("technology")).thenReturn(technology);
    when(order.getId()).thenReturn(orderId);
    when(orderDD.get(orderId)).thenReturn(orderFromDB);
    when(technology.getId()).thenReturn(technologyId);

    when(costNormsForMaterialsService.getProductQuantitiesFromTechnology(technologyId))
        .thenReturn(productQuantities);
    when(techInsOperCompProdInDD.create())
        .thenReturn(techInsOperCompProdIn1, techInsOperCompProdIn2);
    when(techInsOperCompProdIn1.getDataDefinition()).thenReturn(techInsOperCompProdInDD);
    when(techInsOperCompProdIn2.getDataDefinition()).thenReturn(techInsOperCompProdInDD);
    when(techInsOperCompProdInDD.save(techInsOperCompProdIn1))
        .thenReturn(techInsOperCompProdIn1, techInsOperCompProdIn2);
    // when
    orderHooksCNFM.fillOrderOperationProductsInComponents(orderDD, order);

    // then
    Mockito.verify(techInsOperCompProdIn1).setField("order", order);
    Mockito.verify(techInsOperCompProdIn1).setField("product", prod1);
    Mockito.verify(techInsOperCompProdIn1).setField("nominalCost", nominalCost1);
    Mockito.verify(techInsOperCompProdIn2).setField("order", order);
    Mockito.verify(techInsOperCompProdIn2).setField("product", prod2);
    Mockito.verify(techInsOperCompProdIn2).setField("nominalCost", nominalCost2);
  }
  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());
      }
    }
  }
  protected void addParameters(final Map<String, String> values) {
    LOG.info("Adding parameters");
    Entity params = parameterService.getParameter();

    Entity currency =
        dataDefinitionService
            .get(SamplesConstants.BASIC_PLUGIN_IDENTIFIER, SamplesConstants.BASIC_MODEL_CURRENCY)
            .find()
            .add(SearchRestrictions.eq("alphabeticCode", values.get("code")))
            .uniqueResult();

    params.setField("currency", currency);
    params.setField("unit", values.get("unit"));
    params.setField("company", getCompany(values.get("owner")));

    if (isEnabledOrEnabling("productionCounting")) {
      params.setField("registerQuantityInProduct", true);
      params.setField("registerQuantityOutProduct", true);
      params.setField("registerProductionTime", true);
      params.setField("justOne", false);
      params.setField("allowToClose", false);
      params.setField("autoCloseOrder", false);
    }

    if (isEnabledOrEnabling("qualityControls")) {
      params.setField("checkDoneOrderForQuality", false);
      params.setField("autoGenerateQualityControl", false);
    }

    if (isEnabledOrEnabling("genealogies")) {
      params.setField("batchForDoneOrder", "01none");
    }

    if (isEnabledOrEnabling("advancedGenealogy")) {
      params.setField("batchNumberUniqueness", "01globally");
    }

    if (isEnabledOrEnabling("advancedGenealogyForOrders")) {
      params.setField("trackingRecordForOrderTreatment", "01duringProduction");
      params.setField("batchNumberRequiredInputProducts", false);
    }

    if (isEnabledOrEnabling("materialRequirements")) {
      params.setField("inputProductsRequiredForType", "01startOrder");
    }

    if (isEnabledOrEnabling("materialFlowResources")) {
      params.setField("changeDateWhenTransferToWarehouseType", "01never");
    }

    params.getDataDefinition().save(params);
  }
  @Before
  public void init() {
    orderHooksCNFM = new OrderHooksCNFM();

    MockitoAnnotations.initMocks(this);

    ReflectionTestUtils.setField(
        orderHooksCNFM, "costNormsForMaterialsService", costNormsForMaterialsService);
    ReflectionTestUtils.setField(orderHooksCNFM, "dataDefinitionService", dataDefinitionService);

    when(order.getDataDefinition()).thenReturn(orderDD);
    when(dataDefinitionService.get("costNormsForMaterials", "technologyInstOperProductInComp"))
        .thenReturn(techInsOperCompProdInDD);
  }
  private void generateAndAddOrderGroup() {
    Entity orderGroup =
        dataDefinitionService
            .get(ORDER_GROUPS_PLUGIN_NAME, ORDER_GROUPS_MODEL_ORDER_GROUP)
            .create();

    final String number = generateString(CHARS_AND_DIGITS, RANDOM.nextInt(34) + 5);

    orderGroup.setField(L_NUMBER, number);
    orderGroup.setField(L_NAME, getNameFromNumberAndPrefix("OrderGroup-", number));

    orderGroup = orderGroup.getDataDefinition().save(orderGroup);

    addOrdersToOrderGroup(orderGroup);
  }
  private void generateAndAddOperationProductInComponent(
      final Entity operationComponent, final BigDecimal quantity, final Entity product) {
    Entity productComponent =
        dataDefinitionService
            .get(L_TECHNOLOGIES_PLUGIN_IDENTIFIER, "operationProductInComponent")
            .create();

    productComponent.setField(L_BASIC_MODEL_PRODUCT, product);
    productComponent.setField("operationComponent", operationComponent);
    productComponent.setField("quantity", quantity);
    productComponent.setField("batchRequired", true);
    productComponent.setField("productBatchRequired", true);
    productComponent = productComponent.getDataDefinition().save(productComponent);
    operationComponent.setField("operationProductInComponents", productComponent);
  }
  private void generateAndAddProduct() {
    Entity product =
        dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_PRODUCT).create();

    String number = generateString(DIGITS_ONLY, RANDOM.nextInt(34) + 5);

    product.setField("category", getRandomDictionaryItem("categories"));
    product.setField("ean", generateString(DIGITS_ONLY, 13));
    product.setField(L_NAME, getNameFromNumberAndPrefix("Product-", number));
    product.setField("unit", getRandomDictionaryItem("units"));
    product.setField("globalTypeOfMaterial", generateTypeOfProduct());
    product.setField(L_NUMBER, number);

    product = product.getDataDefinition().save(product);
    addSubstituteToProduct(product);
  }
  private void generateAndAddOperationProductOutComponent(
      final Entity operationComponent, final BigDecimal quantity, final Entity product) {

    Preconditions.checkArgument(operationComponent != null, "operation component is null");

    Entity productComponent =
        dataDefinitionService
            .get(L_TECHNOLOGIES_PLUGIN_IDENTIFIER, "operationProductOutComponent")
            .create();

    productComponent.setField(L_BASIC_MODEL_PRODUCT, product);
    productComponent.setField("operationComponent", operationComponent);
    productComponent.setField("quantity", quantity);
    productComponent = productComponent.getDataDefinition().save(productComponent);
    operationComponent.setField("operationProductOutComponents", productComponent);
  }
Beispiel #21
0
 public void setTechnologyNumber(final DataDefinition orderDD, final Entity order) {
   String orderType = order.getStringField(OrderFields.ORDER_TYPE);
   Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
   if (technology == null) {
     return;
   }
   String number = "";
   if (OrderType.WITH_PATTERN_TECHNOLOGY.getStringValue().equals(orderType)) {
     number =
         generateNumberForTechnologyInOrder(
             order, order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE));
   } else if (OrderType.WITH_OWN_TECHNOLOGY.getStringValue().equals(orderType)) {
     number = generateNumberForTechnologyInOrder(order, null);
   }
   technology.setField(TechnologyFields.NUMBER, number);
   technology = technology.getDataDefinition().save(technology);
   order.setField(OrderFields.TECHNOLOGY, technology);
 }
Beispiel #22
0
  private Entity createTechnology(final Entity order) {
    Entity newTechnology = getTechnologyDD().create();

    String number = generateNumberForTechnologyInOrder(order, null);

    Entity product = order.getBelongsToField(TechnologyFields.PRODUCT);
    Entity technologyPrototype = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE);

    newTechnology.setField(TechnologyFields.NUMBER, number);
    newTechnology.setField(TechnologyFields.NAME, makeTechnologyName(number, product));
    newTechnology.setField(TechnologyFields.PRODUCT, product);
    newTechnology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, technologyPrototype);
    newTechnology.setField(
        TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_OWN_TECHNOLOGY.getStringValue());

    newTechnology = newTechnology.getDataDefinition().save(newTechnology);

    return newTechnology;
  }
  @Test
  public final void shouldGenerateWorkPlanEntity() throws Exception {
    // given
    Entity emptyWorkPlan = mock(Entity.class);
    when(workPlanDD.create()).thenReturn(emptyWorkPlan);
    when(workPlanDD.save(emptyWorkPlan)).thenReturn(emptyWorkPlan);
    when(emptyWorkPlan.getDataDefinition()).thenReturn(workPlanDD);

    Entity order = mock(Entity.class);

    @SuppressWarnings("unchecked")
    Iterator<Entity> iterator = mock(Iterator.class);
    when(iterator.hasNext()).thenReturn(true, true, true, false);
    when(iterator.next()).thenReturn(order);

    @SuppressWarnings("unchecked")
    List<Entity> orders = mock(List.class);
    when(orders.iterator()).thenReturn(iterator);
    when(orders.size()).thenReturn(3);
    when(orders.get(Mockito.anyInt())).thenReturn(order);

    @SuppressWarnings("rawtypes")
    ArgumentCaptor<List> listArgCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<String> stringArgCaptor = ArgumentCaptor.forClass(String.class);

    // when
    workPlanService.generateWorkPlanEntity(orders);

    // then
    verify(emptyWorkPlan, times(1)).setField(Mockito.eq("orders"), listArgCaptor.capture());
    @SuppressWarnings("unchecked")
    List<Entity> resultOrders = listArgCaptor.getValue();
    Assert.assertEquals(orders.size(), resultOrders.size());
    Assert.assertSame(order, resultOrders.get(0));
    Assert.assertSame(order, resultOrders.get(1));
    Assert.assertSame(order, resultOrders.get(2));

    verify(emptyWorkPlan, times(1)).setField(Mockito.eq("name"), stringArgCaptor.capture());
    Assert.assertEquals(TRANSLATED_STRING, stringArgCaptor.getValue());

    verify(emptyWorkPlan, times(1)).setField(Mockito.eq("type"), stringArgCaptor.capture());
    Assert.assertEquals(WorkPlanType.NO_DISTINCTION.getStringValue(), stringArgCaptor.getValue());
  }
  protected void addDictionaryItems(final Map<String, String> values) {
    Entity dictionary = getDictionaryByName(values.get(NAME));

    Entity item = dataDefinitionService.get("qcadooModel", "dictionaryItem").create();
    item.setField("dictionary", dictionary);
    item.setField(NAME, values.get("item"));
    item.setField("description", values.get("description"));

    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "Add test dictionary item {dictionary="
              + dictionary.getField(NAME)
              + ", item="
              + item.getField(NAME)
              + ", description="
              + item.getField("description")
              + "}");
    }

    item.getDataDefinition().save(item);
  }
 private void addOrdersToOrderGroup(final Entity orderGroup) {
   List<Entity> orders;
   SearchCriteriaBuilder searchBuilder =
       dataDefinitionService.get(L_ORDERS_PLUGIN_IDENTIFIER, L_ORDERS_MODEL_ORDER).find();
   int ordersLeft =
       searchBuilder
           .add(SearchRestrictions.isNull(ORDER_GROUP_LITERAL))
           .list()
           .getTotalNumberOfEntities();
   if (ordersLeft >= 0) {
     orders =
         searchBuilder
             .add(SearchRestrictions.isNull(ORDER_GROUP_LITERAL))
             .setMaxResults(10)
             .list()
             .getEntities();
     for (Entity order : orders) {
       order.setField(ORDER_GROUP_LITERAL, orderGroup);
       order.setField("doneQuantity", RANDOM.nextInt(10) + 1);
       order.getDataDefinition().save(order);
     }
   }
 }
Beispiel #26
0
  private void createOrUpdateForOwnTechnology(
      final Entity order, final Entity technologyPrototype) {
    Entity existingOrder = getExistingOrder(order);

    if (isTechnologyCopied(order)) {
      if (technologyPrototype != null) {
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);

        updateTechnology(technology);

        order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null);
      } else if (technologyPrototype == null) {
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
        if (technology != null) {
          technology.setField(
              TechnologyFields.PRODUCT, order.getBelongsToField(OrderFields.PRODUCT));
          technology = technology.getDataDefinition().save(technology);
        }
        order.getGlobalErrors();
      }
    } else {
      if (existingOrder == null) {
        order.setField(OrderFields.TECHNOLOGY, createTechnology(order));

        if (technologyPrototype != null) {
          order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null);
        }
      } else if (existingOrder.getBelongsToField(OrderFields.TECHNOLOGY) == null) {
        order.setField(OrderFields.TECHNOLOGY, createTechnology(order));

        if (technologyPrototype != null) {
          order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null);
        }
      }
    }
  }
  private List<Entity> updateResources(
      Entity warehouse, Entity position, WarehouseAlgorithm warehouseAlgorithm) {
    DataDefinition positionDD =
        dataDefinitionService.get(
            MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
            MaterialFlowResourcesConstants.MODEL_POSITION);

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

    Entity product = position.getBelongsToField(PositionFields.PRODUCT);

    List<Entity> resources =
        getResourcesForWarehouseProductAndAlgorithm(
            warehouse, product, position, warehouseAlgorithm);

    BigDecimal quantity = position.getDecimalField(PositionFields.QUANTITY);

    resourceStockService.removeResourceStock(product, warehouse, quantity);
    for (Entity resource : resources) {
      BigDecimal resourceQuantity = resource.getDecimalField(ResourceFields.QUANTITY);
      BigDecimal resourceAvailableQuantity =
          resource.getDecimalField(ResourceFields.AVAILABLE_QUANTITY);

      Entity newPosition = positionDD.create();

      newPosition.setField(
          PositionFields.PRODUCT, position.getBelongsToField(PositionFields.PRODUCT));
      newPosition.setField(
          PositionFields.GIVEN_QUANTITY, position.getDecimalField(PositionFields.GIVEN_QUANTITY));
      newPosition.setField(
          PositionFields.GIVEN_UNIT, position.getStringField(PositionFields.GIVEN_UNIT));
      newPosition.setField(PositionFields.PRICE, resource.getField(ResourceFields.PRICE));
      newPosition.setField(PositionFields.BATCH, resource.getField(ResourceFields.BATCH));
      newPosition.setField(
          PositionFields.PRODUCTION_DATE, resource.getField(ResourceFields.PRODUCTION_DATE));
      newPosition.setField(
          PositionFields.EXPIRATION_DATE, resource.getField(ResourceFields.EXPIRATION_DATE));
      newPosition.setField(PositionFields.RESOURCE, resource);
      newPosition.setField(
          PositionFields.STORAGE_LOCATION, resource.getField(ResourceFields.STORAGE_LOCATION));
      newPosition.setField(
          PositionFields.ADDITIONAL_CODE, resource.getField(ResourceFields.ADDITIONAL_CODE));
      newPosition.setField(PositionFields.CONVERSION, position.getField(PositionFields.CONVERSION));
      newPosition.setField(
          PositionFields.PALLET_NUMBER, resource.getField(ResourceFields.PALLET_NUMBER));
      newPosition.setField(
          PositionFields.TYPE_OF_PALLET, resource.getField(ResourceFields.TYPE_OF_PALLET));
      // newPosition.setField(PositionFields.GIVEN_UNIT,
      // resource.getField(ResourceFields.GIVEN_UNIT));

      setPositionAttributesFromResource(newPosition, resource);

      if (quantity.compareTo(resourceAvailableQuantity) >= 0) {
        quantity = quantity.subtract(resourceAvailableQuantity, numberService.getMathContext());
        if (resourceQuantity.compareTo(resourceAvailableQuantity) <= 0) {
          resource.getDataDefinition().delete(resource.getId());
        } else {
          BigDecimal newResourceQuantity = resourceQuantity.subtract(resourceAvailableQuantity);
          BigDecimal resourceConversion = resource.getDecimalField(ResourceFields.CONVERSION);
          BigDecimal quantityInAdditionalUnit = newResourceQuantity.multiply(resourceConversion);
          resource.setField(ResourceFields.AVAILABLE_QUANTITY, BigDecimal.ZERO);
          resource.setField(ResourceFields.QUANTITY, newResourceQuantity);
          resource.setField(
              ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT,
              numberService.setScale(quantityInAdditionalUnit));
          resource.getDataDefinition().save(resource);
        }

        newPosition.setField(
            PositionFields.QUANTITY, numberService.setScale(resourceAvailableQuantity));

        BigDecimal givenResourceQuantity = convertToGivenUnit(resourceAvailableQuantity, position);

        newPosition.setField(
            PositionFields.GIVEN_QUANTITY, numberService.setScale(givenResourceQuantity));

        newPositions.add(newPosition);

        if (BigDecimal.ZERO.compareTo(quantity) == 0) {
          return newPositions;
        }
      } else {
        resourceQuantity = resourceQuantity.subtract(quantity, numberService.getMathContext());
        resourceAvailableQuantity =
            resourceAvailableQuantity.subtract(quantity, numberService.getMathContext());
        if (position.getBelongsToField(PositionFields.RESOURCE) != null
            && reservationsService.reservationsEnabledForDocumentPositions()) {
          BigDecimal reservedQuantity =
              resource
                  .getDecimalField(ResourceFields.RESERVED_QUANTITY)
                  .subtract(quantity, numberService.getMathContext());
          resource.setField(ResourceFields.RESERVED_QUANTITY, reservedQuantity);
        }
        BigDecimal resourceConversion = resource.getDecimalField(ResourceFields.CONVERSION);
        BigDecimal quantityInAdditionalUnit = resourceQuantity.multiply(resourceConversion);

        resource.setField(
            ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT,
            numberService.setScale(quantityInAdditionalUnit));
        resource.setField(ResourceFields.QUANTITY, numberService.setScale(resourceQuantity));
        resource.setField(ResourceFields.AVAILABLE_QUANTITY, resourceAvailableQuantity);

        resource.getDataDefinition().save(resource);
        newPosition.setField(PositionFields.QUANTITY, numberService.setScale(quantity));

        BigDecimal givenQuantity = convertToGivenUnit(quantity, position);

        newPosition.setField(PositionFields.GIVEN_QUANTITY, numberService.setScale(givenQuantity));
        newPositions.add(newPosition);

        return newPositions;
      }
    }

    position.addError(
        position.getDataDefinition().getField(PositionFields.QUANTITY),
        "materialFlow.error.position.quantity.notEnough");

    return Lists.newArrayList(position);
  }
Beispiel #28
0
 private void deleteTechnology(final Entity technology) {
   if (technology == null || technology.getId() == null) {
     return;
   }
   technology.getDataDefinition().delete(technology.getId());
 }
  private void moveResources(
      Entity warehouseFrom,
      Entity warehouseTo,
      Entity position,
      Object date,
      WarehouseAlgorithm warehouseAlgorithm) {
    Entity product = position.getBelongsToField(PositionFields.PRODUCT);

    List<Entity> resources =
        getResourcesForWarehouseProductAndAlgorithm(
            warehouseFrom, product, position, warehouseAlgorithm);

    BigDecimal quantity = position.getDecimalField(PositionFields.QUANTITY);

    resourceStockService.removeResourceStock(product, warehouseFrom, quantity);
    for (Entity resource : resources) {
      BigDecimal resourceQuantity = resource.getDecimalField(QUANTITY);

      BigDecimal resourceAvailableQuantity =
          resource.getDecimalField(ResourceFields.AVAILABLE_QUANTITY);
      if (quantity.compareTo(resourceAvailableQuantity) >= 0) {
        quantity = quantity.subtract(resourceAvailableQuantity, numberService.getMathContext());
        if (resourceQuantity.compareTo(resourceAvailableQuantity) <= 0) {
          resource.getDataDefinition().delete(resource.getId());
        } else {
          BigDecimal newResourceQuantity = resourceQuantity.subtract(resourceAvailableQuantity);
          BigDecimal resourceConversion = resource.getDecimalField(ResourceFields.CONVERSION);
          BigDecimal quantityInAdditionalUnit = newResourceQuantity.multiply(resourceConversion);
          resource.setField(ResourceFields.AVAILABLE_QUANTITY, BigDecimal.ZERO);
          resource.setField(ResourceFields.QUANTITY, newResourceQuantity);
          resource.setField(
              ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT,
              numberService.setScale(quantityInAdditionalUnit));
          resource.getDataDefinition().save(resource);
        }

        createResource(position, warehouseTo, resource, resourceAvailableQuantity, date);

        if (BigDecimal.ZERO.compareTo(quantity) == 0) {
          return;
        }
      } else {
        resourceQuantity = resourceQuantity.subtract(quantity, numberService.getMathContext());
        resourceAvailableQuantity =
            resourceAvailableQuantity.subtract(quantity, numberService.getMathContext());
        String givenUnit = resource.getStringField(ResourceFields.GIVEN_UNIT);
        BigDecimal quantityInAdditionalUnit =
            convertToGivenUnit(resourceQuantity, product, givenUnit);

        resource.setField(
            ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT,
            numberService.setScale(quantityInAdditionalUnit));
        resource.setField(ResourceFields.QUANTITY, numberService.setScale(resourceQuantity));
        resource.setField(ResourceFields.AVAILABLE_QUANTITY, resourceAvailableQuantity);

        resource.getDataDefinition().save(resource);

        createResource(position, warehouseTo, resource, quantity, date);

        return;
      }
    }

    position.addError(
        position.getDataDefinition().getField(PositionFields.QUANTITY),
        "materialFlow.error.position.quantity.notEnough");
  }
 private void markSamplesAsLoaded() {
   Entity parameter = parameterService.getParameter();
   parameter.setField(SAMPLES_WERE_LOADED, true);
   parameter.getDataDefinition().save(parameter);
 }