Search in sources :

Example 16 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class DispositionOrderPdfService method getDataForTargetPallet.

private String getDataForTargetPallet(Entity position) {
    DataDefinition resourceDD = dataDefinitionService.get(MaterialFlowResourcesConstants.PLUGIN_IDENTIFIER, MaterialFlowResourcesConstants.MODEL_RESOURCE);
    Entity locationFrom = position.getBelongsToField(PositionFields.DOCUMENT).getBelongsToField(DocumentFields.LOCATION_FROM);
    Entity palletNumber = position.getBelongsToField(PositionFields.PALLET_NUMBER);
    if (palletNumber == null) {
        return "";
    }
    SearchCriterion criterionLocation = SearchRestrictions.belongsTo(ResourceFields.LOCATION, locationFrom);
    SearchCriterion criterionPallet = SearchRestrictions.belongsTo(ResourceFields.PALLET_NUMBER, palletNumber);
    long count = resourceDD.count(SearchRestrictions.and(criterionLocation, criterionPallet));
    return count > 0 ? "N" : palletNumber.getStringField(PalletNumberFields.NUMBER);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 17 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class ProductCatalogNumbersHooksTest method shouldReturnFalseWhenEntityWithGivenNumberAndCompanyDoesExistsInDB.

@Test
public void shouldReturnFalseWhenEntityWithGivenNumberAndCompanyDoesExistsInDB() throws Exception {
    // given
    SearchCriterion criterion1 = SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER));
    SearchCriterion criterion2 = SearchRestrictions.belongsTo(ProductCatalogNumberFields.COMPANY, company);
    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.checkIfExistsCatalogNumberWithNumberAndCompany(dataDefinition, entity);
    // then
    Assert.assertFalse(result);
    Mockito.verify(entity).addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany");
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class BatchModelValidators method buildCriteriaForExternalNumber.

private SearchCriterion buildCriteriaForExternalNumber(final Entity batch) {
    SearchCriterion externalNumberMatches = eq(BatchFields.EXTERNAL_NUMBER, batch.getStringField(BatchFields.EXTERNAL_NUMBER));
    if (Objects.isNull(batch.getId())) {
        return externalNumberMatches;
    }
    SearchCriterion isNotTheSameBatch = idNe(batch.getId());
    return and(isNotTheSameBatch, externalNumberMatches);
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 19 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class AssignmentToShiftXlsHelper method getStaffsList.

public List<Entity> getStaffsList(final Entity assignmentToShift, final String occupationType, final Entity productionLine) {
    List<Entity> staffs = Lists.newArrayList();
    if (assignmentToShift == null) {
        return staffs;
    }
    SearchCriterion criterion = SearchRestrictions.eq(StaffAssignmentToShiftFields.OCCUPATION_TYPE, occupationType);
    SearchCriteriaBuilder builder = assignmentToShift.getHasManyField(AssignmentToShiftFields.STAFF_ASSIGNMENT_TO_SHIFTS).find().add(criterion).add(SearchRestrictions.belongsTo(StaffAssignmentToShiftFields.PRODUCTION_LINE, productionLine));
    String assignmentState = assignmentToShift.getStringField(AssignmentToShiftFields.STATE);
    if (AssignmentToShiftState.CORRECTED.getStringValue().equals(assignmentState)) {
        staffs = builder.add(SearchRestrictions.eq(StaffAssignmentToShiftFields.STATE, StaffAssignmentToShiftState.CORRECTED.getStringValue())).list().getEntities();
    } else if (!AssignmentToShiftState.DRAFT.getStringValue().equals(assignmentState)) {
        staffs = builder.add(SearchRestrictions.eq(StaffAssignmentToShiftFields.STATE, StaffAssignmentToShiftState.ACCEPTED.getStringValue())).list().getEntities();
    }
    return staffs;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 20 with SearchCriterion

use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.

the class StaffAssignmentToShiftDetailsHooksTest method shouldSetOccupationTypeToDefaultWhenDictionary.

@Test
public void shouldSetOccupationTypeToDefaultWhenDictionary() {
    // given
    given(staffAssignmentToShiftForm.getEntityId()).willReturn(null);
    given(occupationType.getFieldValue()).willReturn(null);
    SearchCriterion criterion = SearchRestrictions.eq(TECHNICAL_CODE, WORK_ON_LINE.getStringValue());
    given(builder.add(criterion)).willReturn(builder);
    given(builder.uniqueResult()).willReturn(dictionary);
    given(dictionary.getStringField(NAME)).willReturn(Mockito.anyString());
    // when
    detailsHooks.setOccupationTypeToDefault(view);
    // then
    verify(occupationType).setFieldValue(Mockito.anyString());
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Test(org.junit.Test)

Aggregations

SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)41 Entity (com.qcadoo.model.api.Entity)16 Test (org.junit.Test)12 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 DataDefinition (com.qcadoo.model.api.DataDefinition)4 SearchProjection (com.qcadoo.model.api.search.SearchProjection)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 SearchResult (com.qcadoo.model.api.search.SearchResult)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableList (com.google.common.collect.ImmutableList)1 BatchNumberUniqueness (com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)1 AssignmentToShiftCriteria (com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftCriteria)1 SearchDisjunction (com.qcadoo.model.api.search.SearchDisjunction)1 SearchOrder (com.qcadoo.model.api.search.SearchOrder)1 ParseException (java.text.ParseException)1 List (java.util.List)1