use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ScheduleOrderCriteriaModifiers method filterByState.
public void filterByState(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
scb.add(SearchRestrictions.in(OrderFields.STATE, Lists.newArrayList(OrderState.ACCEPTED.getStringValue(), OrderState.PENDING.getStringValue())));
scb.add(SearchRestrictions.eq(L_TYPE_OF_PRODUCTION_RECORDING, L_FOR_EACH));
if (filterValueHolder.has(SCHEDULE_PARAMETER)) {
SearchCriteriaBuilder subCriteria = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_SCHEDULE).findWithAlias(OrdersConstants.MODEL_SCHEDULE).add(SearchRestrictions.idEq(filterValueHolder.getLong(SCHEDULE_PARAMETER))).createAlias(ScheduleFields.ORDERS, ScheduleFields.ORDERS, JoinType.INNER).add(SearchRestrictions.eqField(ScheduleFields.ORDERS + ".id", "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 OperationalTaskValidators method checkIfAlreadyExists.
private boolean checkIfAlreadyExists(DataDefinition operationalTaskDD, Entity operationalTask) {
String type = operationalTask.getStringField(OperationalTaskFields.TYPE);
if (OperationalTaskType.EXECUTION_OPERATION_IN_ORDER.getStringValue().equalsIgnoreCase(type)) {
Entity order = operationalTask.getBelongsToField(OperationalTaskFields.ORDER);
Entity toc = operationalTask.getBelongsToField(OperationalTaskFields.TECHNOLOGY_OPERATION_COMPONENT);
SearchCriteriaBuilder scb = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_OPERATIONAL_TASK).find().add(SearchRestrictions.belongsTo(OperationalTaskFields.ORDER, order)).add(SearchRestrictions.belongsTo(OperationalTaskFields.TECHNOLOGY_OPERATION_COMPONENT, toc)).add(SearchRestrictions.in(OperationalTaskFields.STATE, Lists.newArrayList(OperationalTaskStateStringValues.PENDING, OperationalTaskStateStringValues.STARTED, OperationalTaskStateStringValues.FINISHED)));
if (Objects.nonNull(operationalTask.getId())) {
scb.add(SearchRestrictions.idNe(operationalTask.getId()));
}
scb.setProjection(alias(rowCount(), L_COUNT));
scb.addOrder(asc(L_COUNT));
Entity countProjection = scb.setMaxResults(1).uniqueResult();
boolean isValid = ((countProjection == null) || ((Long) countProjection.getField(L_COUNT) == 0));
if (!isValid) {
operationalTask.addGlobalError("orders.operationalTask.error.notUnique");
}
return isValid;
}
return true;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ProductCatalogNumbersHooks method checkIfExistsCatalogNumberWithNumberAndCompany.
public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) {
SearchCriteriaBuilder criteria = dataDefinitionService.get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find().add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))).add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY)));
if (entity.getId() != null) {
criteria.add(SearchRestrictions.ne("id", entity.getId()));
}
List<Entity> catalogsNumbers = criteria.list().getEntities();
if (catalogsNumbers.isEmpty()) {
return true;
} else {
entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany");
return false;
}
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class CommonReasonTypeModelHooksTest method stubFindResults.
private void stubFindResults(final boolean existsMatchingEntity) {
SearchCriteriaBuilder scb = mock(SearchCriteriaBuilder.class);
given(reasonDD.find()).willReturn(scb);
given(scb.setMaxResults(anyInt())).willReturn(scb);
given(scb.add(any(SearchCriterion.class))).willReturn(scb);
given(scb.setProjection(any(SearchProjection.class))).willReturn(scb);
SearchResult searchResult = mock(SearchResult.class);
given(scb.list()).willReturn(searchResult);
given(searchResult.getTotalNumberOfEntities()).willReturn(existsMatchingEntity ? 1 : 0);
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class StaffCriteriaModifierPFTD method filterByProductionLine.
public void filterByProductionLine(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
if (filterValueHolder.has(L_ORDER_ID)) {
SearchCriteriaBuilder subCriteria = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).findWithAlias(OrdersConstants.MODEL_ORDER).add(SearchRestrictions.idEq(filterValueHolder.getLong(L_ORDER_ID))).createAlias(OrderFields.STAFF, OrderFields.STAFF, JoinType.INNER).add(SearchRestrictions.eqField(OrderFields.STAFF + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
scb.add(SearchSubqueries.notExists(subCriteria));
}
if (filterValueHolder.has(L_PRODUCTION_LINE_ID)) {
scb.add(SearchRestrictions.or(SearchRestrictions.belongsTo(StaffFields.PRODUCTION_LINE, ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE, filterValueHolder.getLong(L_PRODUCTION_LINE_ID)), SearchRestrictions.isNull(StaffFields.PRODUCTION_LINE)));
} else {
scb.add(SearchRestrictions.isNull(StaffFields.PRODUCTION_LINE));
}
}
Aggregations