use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class StaffAssignmentToShiftDetailsHooksTest method shouldDisabledProductionLineAndEnableOccupationTypeNameFieldsWhenOtherCaseIsSelected.
@Test
public void shouldDisabledProductionLineAndEnableOccupationTypeNameFieldsWhenOtherCaseIsSelected() {
// given
String dictionaryName = "Inne zadania";
String technicalCode = "02otherCase";
given(occupationType.getFieldValue()).willReturn(dictionaryName);
SearchCriterion criterion = SearchRestrictions.eq(NAME, dictionaryName);
given(builder.add(criterion)).willReturn(builder);
given(builder.uniqueResult()).willReturn(dictionary);
given(dictionary.getStringField(TECHNICAL_CODE)).willReturn(technicalCode);
// when
detailsHooks.setFieldsEnabledWhenTypeIsSpecific(view);
// then
verify(productionLine).setVisible(false);
verify(occupationTypeName).setVisible(true);
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class AssignmentToShiftDataProvider method createCriteriaBuilder.
public SearchCriteriaBuilder createCriteriaBuilder(final AssignmentToShiftCriteria criteria) {
SearchCriteriaBuilder scb = getAssignmentDD().find();
SearchCriteriaBuilder shiftScb = scb.createCriteria(AssignmentToShiftFields.SHIFT, "shift_alias", JoinType.INNER);
for (SearchCriterion searchCriterion : criteria.getShiftCriteria().asSet()) {
shiftScb.add(searchCriterion);
}
SearchCriteriaBuilder factoryScb = scb.createCriteria(AssignmentToShiftFields.FACTORY, "factory_alias", JoinType.INNER);
for (SearchCriterion searchCriterion : criteria.getFactoryCriteria().asSet()) {
factoryScb.add(searchCriterion);
}
if (criteria.getCrewCriteria().isPresent()) {
SearchCriteriaBuilder crewScb = scb.createCriteria(AssignmentToShiftFields.CREW, "crew_alias", JoinType.INNER);
for (SearchCriterion searchCriterion : criteria.getCrewCriteria().asSet()) {
crewScb.add(searchCriterion);
}
}
for (SearchCriterion searchCriterion : criteria.getCriteria().asSet()) {
scb.add(searchCriterion);
}
return scb;
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class AssignmentToShiftHooks method checkUniqueEntity.
boolean checkUniqueEntity(final Entity assignmentToShift) {
Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE);
Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT);
Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY);
Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW);
AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty();
SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate);
criteria.withShiftCriteria(idEq(shift.getId()));
criteria.withFactoryCriteria(idEq(factory.getId()));
if (crew != null) {
criteria.withCrewCriteria(idEq(crew.getId()));
} else {
additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW));
}
if (assignmentToShift.getId() != null) {
additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId()));
}
criteria.withCriteria(additionalCriteria);
for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) {
addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift);
return false;
}
return true;
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class BatchModelValidatorsTest method stubSearchResultsAndReturnCriteriaCaptor.
private ArgumentCaptor<SearchCriterion> stubSearchResultsAndReturnCriteriaCaptor(final Collection<Entity> entities) {
given(batchDD.find()).willReturn(searchCriteriaBuilder);
SearchResult searchResult = mock(SearchResult.class);
given(searchCriteriaBuilder.list()).willReturn(searchResult);
given(searchCriteriaBuilder.setMaxResults(anyInt())).willReturn(searchCriteriaBuilder);
// stub .list() results
given(searchResult.getTotalNumberOfEntities()).willReturn(entities.size());
given(searchResult.getEntities()).willAnswer(new Answer<List<Entity>>() {
@Override
public List<Entity> answer(final InvocationOnMock ignored) throws Throwable {
return Lists.newArrayList(entities);
}
});
// stub unique result
given(searchCriteriaBuilder.uniqueResult()).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock ignored) throws Throwable {
return Iterables.getFirst(entities, null);
}
});
// build argumentCaptor
ArgumentCaptor<SearchCriterion> criterionCaptor = ArgumentCaptor.forClass(SearchCriterion.class);
given(searchCriteriaBuilder.add(criterionCaptor.capture())).willReturn(searchCriteriaBuilder);
return criterionCaptor;
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class BatchModelValidators method checkIfBatchNumberIsUnique.
public boolean checkIfBatchNumberIsUnique(final DataDefinition batchDD, final Entity batch) {
BatchNumberUniqueness batchNumberUniqueness = getBatchNumberUniqueness();
if (batchNumberUniqueness == null) {
return true;
}
SearchCriterion criterion = batchNumberUniqueness.buildCriterionFor(batch);
if (existsAnyBatchMatchingCriterion(batchDD, criterion)) {
String errorMessage = getBatchNumberErrorMessage(batchNumberUniqueness);
batch.addError(batchDD.getField(BatchFields.NUMBER), errorMessage);
return false;
}
return true;
}
Aggregations