use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class WorkPlanServiceImplTest method shouldReturnEmptyListIfOrdersWithGivenIdDoesNotExist.
@Test
public final void shouldReturnEmptyListIfOrdersWithGivenIdDoesNotExist() throws Exception {
// given
Entity order1 = mock(Entity.class);
when(order1.getId()).thenReturn(1L);
Entity order2 = mock(Entity.class);
when(order2.getId()).thenReturn(2L);
Entity order3 = mock(Entity.class);
when(order3.getId()).thenReturn(3L);
@SuppressWarnings("unchecked") Iterator<Long> iterator = mock(Iterator.class);
when(iterator.hasNext()).thenReturn(true, true, true, true, false);
when(iterator.next()).thenReturn(1L, 2L, 3L, 4L);
@SuppressWarnings("unchecked") Set<Long> selectedOrderIds = mock(Set.class);
when(selectedOrderIds.iterator()).thenReturn(iterator);
when(selectedOrderIds.size()).thenReturn(4);
SearchCriteriaBuilder criteria = mock(SearchCriteriaBuilder.class);
when(criteria.add(Mockito.any(SearchCriterion.class))).thenReturn(criteria);
SearchResult result = mock(SearchResult.class);
when(criteria.list()).thenReturn(result);
when(result.getTotalNumberOfEntities()).thenReturn(0);
DataDefinition orderDD = mock(DataDefinition.class);
when(orderDD.find()).thenReturn(criteria);
when(dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)).thenReturn(orderDD);
// when
List<Entity> resultList = workPlanService.getSelectedOrders(selectedOrderIds);
// then
Assert.assertEquals(0, resultList.size());
}
use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class DocumentPositionParametersItemModelValidators method validate.
public boolean validate(final DataDefinition itemDD, final Entity item) {
if (!item.getBooleanField("checked")) {
String name = item.getStringField("name");
switch(name) {
case DocumentPositionParametersItemValues.PRICE:
case DocumentPositionParametersItemValues.BATCH:
case DocumentPositionParametersItemValues.PRODUCTION_DATE:
case DocumentPositionParametersItemValues.EXPIRATION_DATE:
DataDefinition locationDD = dataDefinitionService.get(MaterialFlowConstants.PLUGIN_IDENTIFIER, MaterialFlowConstants.MODEL_LOCATION);
String camelCaseName = "require" + name.substring(0, 1).toUpperCase() + name.substring(1);
SearchResult result = locationDD.find().add(SearchRestrictions.eq(camelCaseName, true)).setMaxResults(1).list();
if (result.getTotalNumberOfEntities() > 0) {
String locationName = result.getEntities().get(0).getStringField(LocationFields.NAME);
String fieldTranslatedName = translationService.translate("materialFlowResources.materialFlowResourcesParameters.documentPositionParameters." + name, LocaleContextHolder.getLocale());
String errorMessage = translationService.translate("materialFlowResources.error.documentLocationPositionItemCantBeHidden", LocaleContextHolder.getLocale());
errorMessage = String.format(errorMessage, fieldTranslatedName, locationName);
item.addError(itemDD.getField("checked"), errorMessage);
return false;
}
}
}
return true;
}
use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class ProductionCountingOrderStatesListenerService method checkIfOrderHasFinalProductionTrackings.
private boolean checkIfOrderHasFinalProductionTrackings(final Entity order, final Entity technologyOperationComponent) {
final SearchCriteriaBuilder searchCriteriaBuilder = productionCountingService.getProductionTrackingDD().find().add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order)).add(SearchRestrictions.eq(ProductionTrackingFields.LAST_TRACKING, true));
if (Objects.nonNull(technologyOperationComponent)) {
searchCriteriaBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT, technologyOperationComponent));
}
SearchResult searchResult = searchCriteriaBuilder.list();
return (searchResult.getTotalNumberOfEntities() > 0);
}
use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class MessageServiceImpl method messageAlreadyExists.
@Override
public boolean messageAlreadyExists(final Entity message) {
final SearchCriteriaBuilder criteriaBuilder = getDataDefinition().find();
criteriaBuilder.add(SearchRestrictions.allEq(message.getFields()));
final SearchResult result = criteriaBuilder.list();
return result.getTotalNumberOfEntities() > 0;
}
use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.
the class TSFOrderSuppliesOrderStateValidationService method areSubcontracedOperations.
private boolean areSubcontracedOperations(final Entity order) {
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
SearchResult searchResult = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).find().add(SearchRestrictions.belongsTo(TechnologyOperationComponentFields.TECHNOLOGY, technology)).add(SearchRestrictions.eq(TechnologyOperationComponentFieldsTS.IS_SUBCONTRACTING, true)).list();
return !searchResult.getEntities().isEmpty();
}
Aggregations