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);
}
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();
}
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();
}
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));
}
}
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));
}
}
Aggregations