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;
  }
  @Test
  public void
      shouldReturnFalseAndAddErrorWhenCheckMaterialFlowComponentUniquenessAndMaterialFlowComponentIsntUnique() {
    // given
    given(materialsInLocationComponent.getBelongsToField(LOCATION)).willReturn(location);
    given(materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION))
        .willReturn(materialsInLocation);

    given(materialsInLocationComponentDD.find()).willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class)))
        .willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.list()).willReturn(searchResult);

    given(searchResult.getTotalNumberOfEntities()).willReturn(1);
    given(searchResult.getEntities()).willReturn(entities);
    given(entities.get(0)).willReturn(materialsInLocationComponentOther);

    given(materialsInLocationComponent.getId()).willReturn(L_ID);
    given(materialsInLocationComponentOther.getId()).willReturn(L_ID_OTHER);

    // when
    boolean result =
        materialsInLocationComponentModelValidators.checkMaterialFlowComponentUniqueness(
            materialsInLocationComponentDD, materialsInLocationComponent);

    // then
    assertFalse(result);

    Mockito.verify(materialsInLocationComponent)
        .addError(
            Mockito.eq(materialsInLocationComponentDD.getField(LOCATION)), Mockito.anyString());
  }
 public boolean validateDates(
     final DataDefinition deliveredProductDD, final Entity deliveredProduct) {
   Date productionDate = deliveredProduct.getDateField(DeliveredProductFieldsDTMF.PRODUCTION_DATE);
   Date expirationDate = deliveredProduct.getDateField(DeliveredProductFieldsDTMF.EXPIRATION_DATE);
   if (productionDate != null && expirationDate != null) {
     if (productionDate.after(expirationDate)) {
       deliveredProduct.addError(
           deliveredProductDD.getField(DeliveredProductFieldsDTMF.EXPIRATION_DATE),
           "materialFlow.error.position.expirationDate.lessThenProductionDate");
       return false;
     }
   }
   return true;
 }
  @Test
  public final void shouldBuildDataDefinitionWithFieldWhichIsAllowedToBeBothCopyableAndUnique() {
    // when
    DataDefinition convertedDataDefinition =
        performConvert(Utils.UNIQUE_COPYABLE_ENTITY_XML_RESOURCE).iterator().next();

    // then
    for (String fieldName : Lists.newArrayList("stringField", "textField")) {
      FieldDefinition fieldDefinition = convertedDataDefinition.getField(fieldName);
      assertNotNull(String.format("Field '%s' is missing", fieldName), fieldDefinition);
      assertTrue(
          String.format("Field '%s' should be unique", fieldName), fieldDefinition.isUnique());
      assertTrue(
          String.format("Field '%s' should be copyable", fieldName),
          fieldDefinition.getType().isCopyable());
    }
  }
Esempio n. 5
0
  public boolean checkIfLocationIsWarehouse(
      final DataDefinition resourceDD, final Entity resource) {
    Entity location = resource.getBelongsToField(LOCATION);

    if (location != null) {
      String type = location.getStringField(TYPE);

      if (!"02warehouse".equals(type)) {
        resource.addError(
            resourceDD.getField(LOCATION),
            "materialFlowResources.validate.global.error.locationIsNotWarehouse");

        return false;
      }
    }

    return true;
  }
  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");
        }
      }
    }
  }