Search in sources :

Example 91 with SearchCriteriaBuilder

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

the class AdvancedGenealogyTreeServiceTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    treeService = new AdvancedGenealogyTreeService();
    ReflectionTestUtils.setField(treeService, "dataDefinitionService", dataDefinitionService);
    ReflectionTestUtils.setField(treeService, "pluginAccessor", pluginAccessor);
    when(pluginAccessor.getPlugin("advancedGenealogyForOrders")).thenReturn(null);
    when(dataDefinitionService.get(AdvancedGenealogyConstants.PLUGIN_IDENTIFIER, AdvancedGenealogyConstants.MODEL_BATCH)).thenReturn(dataDefinition);
    when(batch1.getId()).thenReturn(1L);
    when(batch2.getId()).thenReturn(2L);
    EntityList batch1Trs = mockEntityList(asList(batch1Tr));
    when(batch1.getHasManyField("trackingRecords")).thenReturn(batch1Trs);
    when(batch1Tr.getStringField("entityType")).thenReturn(TrackingRecordType.SIMPLE);
    when(batch1Tr.getStringField("state")).thenReturn(TrackingRecordState.DRAFT.getStringValue());
    Entity batch1TrUsedBatch1 = mock(Entity.class);
    when(batch1TrUsedBatch1.getBelongsToField("batch")).thenReturn(batch2);
    EntityList batch1TrUsedBatches = mockEntityList(asList(batch1TrUsedBatch1));
    when(batch1Tr.getHasManyField("usedBatchesSimple")).thenReturn(batch1TrUsedBatches);
    EntityList batch2Trs = mockEntityList(new LinkedList<Entity>());
    when(batch2.getHasManyField("trackingRecords")).thenReturn(batch2Trs);
    SearchCriteriaBuilder searchCriteriaBuilder = Mockito.mock(SearchCriteriaBuilder.class);
    when(dataDefinition.find()).thenReturn(searchCriteriaBuilder);
    when(searchCriteriaBuilder.list()).thenReturn(searchResult);
    when(searchResult.getEntities()).thenReturn(asList(batch1));
    String number1 = "QWD33";
    String number2 = "POS22";
    String productName2 = "productName2";
    String productNumber2 = "productNumber2";
    when(batch1.getField("parent")).thenReturn(parent1);
    when(batch2.getField("parent")).thenReturn(parent2);
    when(batch1.getBelongsToField("product")).thenReturn(product1);
    when(batch2.getBelongsToField("product")).thenReturn(product2);
    when(product1.getStringField("name")).thenReturn(productName1);
    when(product1.getStringField("number")).thenReturn(productNumber1);
    when(product2.getStringField("name")).thenReturn(productName2);
    when(product2.getStringField("number")).thenReturn(productNumber2);
    when(batch1.getField("number")).thenReturn(number1);
    when(batch2.getField("number")).thenReturn(number2);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) EntityList(com.qcadoo.model.api.EntityList) Before(org.junit.Before)

Example 92 with SearchCriteriaBuilder

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

the class BatchModelHelper method findByExternalNumber.

public Entity findByExternalNumber(final String externalNumber) {
    if (StringUtils.isBlank(externalNumber)) {
        return null;
    }
    SearchCriteriaBuilder scb = getBatchDataDef().find();
    scb.add(eq(BatchFields.EXTERNAL_NUMBER, externalNumber));
    return scb.setMaxResults(1).uniqueResult();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 93 with SearchCriteriaBuilder

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

the class BatchModelHelper method findFirstByNumberProductAndOptionallySupplier.

public Entity findFirstByNumberProductAndOptionallySupplier(final String number, final Entity product, final Entity supplier) {
    SearchCriteriaBuilder scb = getBatchDataDef().find();
    scb.add(eq(BatchFields.NUMBER, number));
    scb.add(belongsTo(BatchFields.PRODUCT, product));
    scb.add(or(belongsTo(BatchFields.SUPPLIER, supplier), isNull(BatchFields.SUPPLIER)));
    scb.addOrder(asc(BatchFields.SUPPLIER));
    scb.setMaxResults(1);
    return scb.uniqueResult();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 94 with SearchCriteriaBuilder

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

the class SkillCriteriaModifiers method filterBySkill.

public void filterBySkill(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    if (filterValueHolder.has(L_SKILL_ID)) {
        SearchCriteriaBuilder subCriteria = getSkillDD().findWithAlias(BasicConstants.MODEL_SKILL).add(SearchRestrictions.idEq(filterValueHolder.getLong(L_SKILL_ID))).createAlias(StaffFields.STAFF_SKILLS, StaffFields.STAFF_SKILLS, JoinType.INNER).createAlias(StaffFields.STAFF_SKILLS + L_DOT + StaffSkillsFields.STAFF, StaffSkillsFields.STAFF, JoinType.INNER).add(SearchRestrictions.eqField(StaffSkillsFields.STAFF + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
        scb.add(SearchSubqueries.notExists(subCriteria));
    }
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 95 with SearchCriteriaBuilder

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

the class SkillCriteriaModifiers method filterByStaff.

public void filterByStaff(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    if (filterValueHolder.has(L_STAFF_ID)) {
        SearchCriteriaBuilder subCriteria = getStaffDD().findWithAlias(BasicConstants.MODEL_STAFF).add(SearchRestrictions.idEq(filterValueHolder.getLong(L_STAFF_ID))).createAlias(StaffFields.STAFF_SKILLS, StaffFields.STAFF_SKILLS, JoinType.INNER).createAlias(StaffFields.STAFF_SKILLS + L_DOT + StaffSkillsFields.SKILL, StaffSkillsFields.SKILL, JoinType.INNER).add(SearchRestrictions.eqField(StaffSkillsFields.SKILL + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
        scb.add(SearchSubqueries.notExists(subCriteria));
    }
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Aggregations

SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)176 Entity (com.qcadoo.model.api.Entity)82 DataDefinition (com.qcadoo.model.api.DataDefinition)26 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Service (org.springframework.stereotype.Service)19 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)18 EntityList (com.qcadoo.model.api.EntityList)17 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)17 Collectors (java.util.stream.Collectors)17 SearchResult (com.qcadoo.model.api.search.SearchResult)16 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)14 Objects (java.util.Objects)14 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)11 BigDecimal (java.math.BigDecimal)11 Set (java.util.Set)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 CustomRestriction (com.qcadoo.model.api.search.CustomRestriction)8