private void generateAndAddOrder() {
    Entity order =
        dataDefinitionService.get(L_ORDERS_PLUGIN_IDENTIFIER, L_ORDERS_MODEL_ORDER).create();

    long dateFrom = generateRandomDate();
    long dateTo = generateRandomDate(dateFrom);

    Preconditions.checkArgument(dateTo > dateFrom, "Order was finished before it was started !");

    Entity product = getRandomProduct();
    Entity technology =
        (getDefaultTechnologyForProduct(product) == null)
            ? getRandomProduct()
            : getDefaultTechnologyForProduct(product);

    String number = generateString(CHARS_AND_DIGITS, RANDOM.nextInt(34) + 5);
    order.setField(L_NUMBER, number);
    order.setField(L_NAME, getNameFromNumberAndPrefix("Order-", number));
    order.setField("dateFrom", new Date(dateFrom));
    order.setField("dateTo", new Date(dateTo));
    order.setField(STATE_L, "01pending");
    order.setField(L_BASIC_MODEL_PRODUCT, product);
    order.setField("plannedQuantity", RANDOM.nextInt(100) + 100);
    order.setField("doneQuantity", RANDOM.nextInt(100) + 1);
    order.setField(L_TECHNOLOGY_MODEL_TECHNOLOGY, technology);
    order.setField("externalSynchronized", true);
    order.setField("typeOfProductionRecording", "01basic");
    order.setField("trackingRecordTreatment", "01duringProduction");

    dataDefinitionService.get(L_ORDERS_PLUGIN_IDENTIFIER, L_ORDERS_MODEL_ORDER).save(order);
  }
  private void generateAndAddOperation() {
    Entity operation =
        dataDefinitionService.get(TECHNOLOGIES_PLUGIN, L_TECHNOLOGY_MODEL_OPERATION).create();

    String number = generateString(CHARS_ONLY, RANDOM.nextInt(40) + 5);

    operation.setField(L_NUMBER, number);
    operation.setField("name", getNameFromNumberAndPrefix("Operation-", number));
    operation.setField(L_BASIC_MODEL_STAFF, getRandomStaff());
    operation.setField(L_BASIC_MODEL_WORKSTATION_TYPE, getRandomMachine());

    operation.setField(L_TPZ, RANDOM.nextInt(1000));
    operation.setField(L_TJ, RANDOM.nextInt(1000));
    operation.setField("productionInOneCycle", RANDOM.nextInt(20));
    operation.setField(L_NEXT_OPERATION_AFTER_PRODUCED_TYPE, RANDOM.nextInt(10));
    operation.setField(
        "machineUtilization", numberService.setScale(new BigDecimal(RANDOM.nextDouble()).abs()));
    operation.setField(
        "laborUtilization", numberService.setScale(new BigDecimal(RANDOM.nextDouble()).abs()));
    operation.setField("nextOperationAfterProducedQuantity", RANDOM.nextInt(15));
    operation.setField(L_NEXT_OPERATION_AFTER_PRODUCED_TYPE, "01all");
    operation.setField("timeNextOperation", RANDOM.nextInt(30));
    operation.setField("nextOperationAfterProducedQuantity", "0");

    if (isEnabledOrEnabling("costNormsForOperation")) {
      operation.setField("pieceworkCost", RANDOM.nextInt(100));
      operation.setField("machineHourlyCost", RANDOM.nextInt(100));
      operation.setField("laborHourlyCost", RANDOM.nextInt(100));
      operation.setField("numberOfOperations", RANDOM.nextInt(10) + 1);
    }
    dataDefinitionService.get(TECHNOLOGIES_PLUGIN, L_TECHNOLOGY_MODEL_OPERATION).save(operation);
  }
  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 void generateDictionaryItem(final String name) {
    Entity dictionary = getDictionaryByName(name);

    Entity item = dataDefinitionService.get("qcadooModel", "dictionaryItem").create();
    item.setField("dictionary", dictionary);
    item.setField(L_NAME, generateString(CHARS_ONLY, 8));

    dataDefinitionService.get("qcadooModel", "dictionaryItem").save(item);
  }
  private void generateAndAddStaff() {
    Entity staff =
        dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_STAFF).create();

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

    staff.setField(L_NUMBER, number);
    staff.setField(L_NAME, getNameFromNumberAndPrefix("Staff-", number));
    staff.setField("surname", generateString(CHARS_ONLY, RANDOM.nextInt(12)));
    staff.setField("post", generateString(CHARS_ONLY, RANDOM.nextInt(5)));

    dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_STAFF).save(staff);
  }
  private void addSubstituteComponent(
      final Entity substitute, final Entity product, final double quantity) {
    Entity substituteComponent =
        dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "substituteComponent").create();

    substituteComponent.setField(
        "quantity", numberService.setScale(new BigDecimal(quantity + 1).abs()));
    substituteComponent.setField(L_BASIC_MODEL_PRODUCT, product);
    substituteComponent.setField("substitute", substitute);

    dataDefinitionService
        .get(L_BASIC_PLUGIN_IDENTIFIER, "substituteComponent")
        .save(substituteComponent);
  }
  private void generateAndAddShift(final String locale) {
    Entity shift = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "shift").create();

    shift.setField(
        L_NAME,
        getNameFromNumberAndPrefix("Shift-", generateString(CHARS_ONLY, RANDOM.nextInt(40) + 5)));

    for (int i = 0; i < SHIFT_HOURS.length; i++) {
      shift.setField(WORK_SHIFT[i], RANDOM.nextBoolean());
      shift.setField(SHIFT_HOURS[i], generateWorkingHours(locale));
    }

    dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "shift").save(shift);
  }
  private void addSubstituteToProduct(final Entity product) {
    Entity substitute = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "substitute").create();

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

    substitute.setField(L_NUMBER, number);
    substitute.setField(L_NAME, getNameFromNumberAndPrefix("ProductSubstitute-", number));
    substitute.setField(L_BASIC_MODEL_PRODUCT, product);
    substitute.setField("priority", RANDOM.nextInt(7));

    substitute =
        dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "substitute").save(substitute);
    addSubstituteComponent(
        substitute, getRandomProduct(), RANDOM.nextInt(997) * RANDOM.nextDouble());
  }
 private Entity getCompany(final String number) {
   return dataDefinitionService
       .get(SamplesConstants.BASIC_PLUGIN_IDENTIFIER, SamplesConstants.BASIC_MODEL_COMPANY)
       .find()
       .add(SearchRestrictions.eq("number", number))
       .uniqueResult();
 }
  public BigDecimal getQuantityOfProductInWarehouse(
      final Entity warehouse, final Entity product, Entity position) {
    BigDecimal quantity = BigDecimal.ZERO;

    Entity resource = position.getBelongsToField(PositionFields.RESOURCE);
    Entity reservation = reservationsService.getReservationForPosition(position);
    if (resource != null) {
      quantity = resource.getDecimalField(ResourceFields.AVAILABLE_QUANTITY);
    } else {
      List<Entity> resources =
          dataDefinitionService
              .get(
                  MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER,
                  MaterialFlowResourcesConstants.MODEL_RESOURCE)
              .find()
              .add(SearchRestrictions.belongsTo(ResourceFields.LOCATION, warehouse))
              .add(SearchRestrictions.belongsTo(ResourceFields.PRODUCT, product))
              .list()
              .getEntities();

      for (Entity res : resources) {
        quantity = quantity.add(res.getDecimalField(ResourceFields.AVAILABLE_QUANTITY));
      }
    }

    if (reservation != null) {
      quantity = quantity.add(reservation.getDecimalField(ReservationFields.QUANTITY));
    }
    return quantity;
  }
  public Entity createProductEntity(final ParsedProduct product) {
    Entity productEntity =
        dataDefinitionService
            .get(SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_PRODUCT)
            .create();

    switch (EppParser.ProductType.valueOf(product.getField(FIELD_TYPE))) {
      case ARTICLE:
        productEntity.setField(FIELD_TYPE, "01article");
        break;
      case SERVICE:
        productEntity.setField(FIELD_TYPE, "02service");
        break;
      case PACK:
        productEntity.setField(FIELD_TYPE, "03pack");
        break;
      case SET:
        productEntity.setField(FIELD_TYPE, "04set");
        break;
      default:
        throw new IllegalStateException("unknown product type");
    }
    productEntity.setField(FIELD_IDENTIFICATION_CODE, product.getIdentificationCode());
    productEntity.setField("ean", product.getField("ean"));
    productEntity.setField(FIELD_NAME, product.getField(FIELD_NAME));
    productEntity.setField("description", product.getField("description"));
    productEntity.setField(FIELD_UNIT, product.getField(FIELD_UNIT));
    productEntity.setField(FIELD_CONVERTED, 0);
    return productEntity;
  }
  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);
  }
 protected Entity findDictionaryItemByName(final String name) {
   return dataDefinitionService
       .get("qcadooModel", "dictionaryItem")
       .find()
       .add(SearchRestrictions.eq(NAME, name))
       .uniqueResult();
 }
  public void showCopyOfTechnology(
      final ViewDefinitionState view, final ComponentState state, final String[] args) {
    Long orderId = (Long) state.getFieldValue();

    if (orderId != null) {
      Entity order =
          dataDefinitionService
              .get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)
              .get(orderId);

      if (OrderType.WITH_PATTERN_TECHNOLOGY
              .getStringValue()
              .equals(order.getField(OrderFields.ORDER_TYPE))
          && (order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE) == null)) {
        state.addMessage("order.technology.patternTechnology.not.set", MessageType.INFO);

        return;
      }

      Long technologyId = order.getBelongsToField(OrderFields.TECHNOLOGY).getId();
      Map<String, Object> parameters = Maps.newHashMap();
      parameters.put("form.id", technologyId);

      String url = "../page/orders/copyOfTechnologyDetails.html";
      view.redirectTo(url, false, true, parameters);
    }
  }
 public Entity findDictionaryItemByTechnicalCode(final String technicalCode) {
   return dataDefinitionService
       .get("qcadooModel", "dictionaryItem")
       .find()
       .add(SearchRestrictions.eq(TECHNICAL_CODE, technicalCode))
       .uniqueResult();
 }
Beispiel #16
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;
  }
  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;
  }
Beispiel #18
0
  @Test
  public final void shouldGetPpsForOrderReturnNullIfPpsDoesNotExists() {
    // given
    Long givenOrderId = 1L;

    given(
            dataDefinitionService.get(
                ProductionPerShiftConstants.PLUGIN_IDENTIFIER,
                ProductionPerShiftConstants.MODEL_PRODUCTION_PER_SHIFT))
        .willReturn(dataDefinition);
    SearchQueryBuilder searchCriteriaBuilder = mock(SearchQueryBuilder.class);
    given(
            dataDefinition.find(
                "select id as ppsId from #productionPerShift_productionPerShift where order.id = :orderId"))
        .willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.setMaxResults(Mockito.anyInt())).willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.setLong(Mockito.anyString(), Mockito.eq(givenOrderId)))
        .willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.uniqueResult()).willReturn(null);

    // when
    final Long resultPpsId = ppsHelper.getPpsIdForOrder(givenOrderId);

    // then
    Assert.assertNull(resultPpsId);
  }
  @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);
  }
  @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;
  }
  private void generateAndAddWorkstationType() {
    Entity machine =
        dataDefinitionService
            .get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_WORKSTATION_TYPE)
            .create();

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

    machine.setField(L_NAME, getNameFromNumberAndPrefix("Workstation type-", number));
    machine.setField(L_NUMBER, number);
    machine.setField("description", generateString(CHARS_ONLY, RANDOM.nextInt(100)));

    dataDefinitionService
        .get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_WORKSTATION_TYPE)
        .save(machine);
  }
  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;
  }
  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);
  }
 public void setOrderAsConverted(final ImportedOrder order) {
   DataDefinition importedOrderDataDefinition =
       dataDefinitionService.get(
           SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_ORDER);
   Entity importedOrder = importedOrderDataDefinition.get(order.getOriginalEntityId());
   importedOrder.setField(FIELD_CONVERTED, "1");
   importedOrderDataDefinition.save(importedOrder);
 }
 public void deleteOrderProducts(final Entity orderEntity) {
   for (Entity orrderProductEntity : orderEntity.getHasManyField("orderProducts")) {
     dataDefinitionService
         .get(
             SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_ORDER_PRODUCT)
         .delete(orrderProductEntity.getId());
   }
 }
 public void setProductAsConverted(final ImportedProduct product) {
   DataDefinition importedProductDataDefinition =
       dataDefinitionService.get(
           SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_PRODUCT);
   Entity importedProduct = importedProductDataDefinition.get(product.getOriginalEntityId());
   importedProduct.setField(FIELD_CONVERTED, "1");
   importedProductDataDefinition.save(importedProduct);
 }
  @RequestMapping(value = "developReport/hql", method = RequestMethod.POST)
  public ModelAndView executeHql(@RequestParam(L_HQL) final String hql) {
    if (!showReportDevelopment) {
      return new ModelAndView(new RedirectView("/"));
    }

    try {
      List<Entity> entities =
          dataDefinitionService.get("qcadooPlugin", "plugin").find(hql).list().getEntities();

      if (entities.isEmpty()) {
        return new ModelAndView(L_QCADOO_REPORT_HQL)
            .addObject(L_HQL, hql)
            .addObject("isEmpty", true);
      } else {
        DataDefinition dataDefinition = entities.get(0).getDataDefinition();

        List<String> headers = new ArrayList<String>();

        if (!isDynamicDataDefinition(dataDefinition)) {
          headers.add("id");
        }

        headers.addAll(dataDefinition.getFields().keySet());

        List<List<String>> rows = new ArrayList<List<String>>();

        for (Entity entity : entities) {
          List<String> row = new ArrayList<String>();

          if (!isDynamicDataDefinition(dataDefinition)) {
            row.add(String.valueOf(entity.getId()));
          }

          for (String field : dataDefinition.getFields().keySet()) {
            if (entity.getField(field) == null) {
              row.add("");
            } else if (entity.getField(field) instanceof EntityList) {
              row.add("[]");
            } else {
              row.add(String.valueOf(entity.getField(field)));
            }
          }

          rows.add(row);
        }

        return new ModelAndView(L_QCADOO_REPORT_HQL)
            .addObject(L_HQL, hql)
            .addObject("headers", headers)
            .addObject("rows", rows)
            .addObject("isOk", true);
      }
    } catch (Exception e) {
      return showException(L_QCADOO_REPORT_HQL, e).addObject(L_HQL, hql);
    }
  }
 private Entity getRandomEntity(final String pluginIdentifier, final String modelName) {
   SearchCriteriaBuilder searchBuilder =
       dataDefinitionService.get(pluginIdentifier, modelName).find();
   int totalNumberOfEntities = searchBuilder.list().getTotalNumberOfEntities();
   return searchBuilder
       .setMaxResults(1)
       .setFirstResult(RANDOM.nextInt(totalNumberOfEntities))
       .uniqueResult();
 }
  @Before
  public void init() {
    MockitoAnnotations.initMocks(this);

    DataDefinition materialCostsComponentDD = mock(DataDefinition.class);
    given(materialCostsComponentDD.create()).willReturn(createdEntity);

    DataDefinitionService dataDefinitionService = mock(DataDefinitionService.class);
    given(
            dataDefinitionService.get(
                CostNormsForMaterialsConstants.PLUGIN_IDENTIFIER,
                CostNormsForMaterialsConstants.MODEL_TECHNOLOGY_INST_OPER_PRODUCT_IN_COMP))
        .willReturn(materialCostsComponentDD);

    orderMaterialCostsEntityBuilder = new OrderMaterialCostsEntityBuilderImpl();

    ReflectionTestUtils.setField(
        orderMaterialCostsEntityBuilder, "dataDefinitionService", dataDefinitionService);
  }
  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);
  }