Search in sources :

Example 26 with SearchCriterion

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);
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Test(org.junit.Test)

Example 27 with SearchCriterion

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;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 28 with SearchCriterion

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) AssignmentToShiftCriteria(com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftCriteria) LocalDate(org.joda.time.LocalDate)

Example 29 with SearchCriterion

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) SearchResult(com.qcadoo.model.api.search.SearchResult) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 30 with SearchCriterion

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;
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) BatchNumberUniqueness(com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)

Aggregations

SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)41 Entity (com.qcadoo.model.api.Entity)16 Test (org.junit.Test)12 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 DataDefinition (com.qcadoo.model.api.DataDefinition)4 SearchProjection (com.qcadoo.model.api.search.SearchProjection)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 SearchResult (com.qcadoo.model.api.search.SearchResult)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableList (com.google.common.collect.ImmutableList)1 BatchNumberUniqueness (com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)1 AssignmentToShiftCriteria (com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftCriteria)1 SearchDisjunction (com.qcadoo.model.api.search.SearchDisjunction)1 SearchOrder (com.qcadoo.model.api.search.SearchOrder)1 ParseException (java.text.ParseException)1 List (java.util.List)1