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