use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class OrderClosingHelperTest method mockEntityList.
private EntityList mockEntityList(final int size) {
EntityList list = mock(EntityList.class);
given(list.size()).willReturn(size);
return list;
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class OrderDetailsHooksPPS method checkOrderDates.
private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
if (order.getId() == null) {
return;
}
Entity pps = productionPerShiftDataProvider.getProductionPerShiftDD().find().add(SearchRestrictions.belongsTo("order", OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, order.getId())).setMaxResults(1).uniqueResult();
if (pps != null) {
boolean shouldBeCorrected = OrderState.of(order).compareTo(OrderState.PENDING) != 0;
Set<Long> progressForDayIds = productionPerShiftDataProvider.findIdsOfEffectiveProgressForDay(pps, shouldBeCorrected);
DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY);
Optional<OrderDates> maybeOrderDates;
try {
maybeOrderDates = OrderDates.of(order);
} catch (IllegalArgumentException e) {
return;
}
DataDefinition orderDD = order.getDataDefinition();
Entity dbOrder = orderDD.get(order.getId());
boolean areDatesCorrect = true;
if (maybeOrderDates.isPresent()) {
OrderDates orderDates = maybeOrderDates.get();
Date orderStart = removeTime(orderDates.getStart().effectiveWithFallback().toDate());
Date orderEnd = orderDates.getEnd().effectiveWithFallback().toDate();
Date ppsFinishDate = null;
for (Long id : progressForDayIds) {
Entity progressForDay = progressForDayDD.get(id);
Date progressDate = progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY);
if (progressDate == null) {
progressDate = progressForDay.getDateField(ProgressForDayFields.DATE_OF_DAY);
}
EntityList dailyProgresses = progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS);
for (Entity dailyProgress : dailyProgresses) {
Date shiftFinishDate = ppsTimeHelper.findFinishDate(dailyProgress, progressDate, dbOrder);
if (shiftFinishDate == null) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
return;
}
if (ppsFinishDate == null || ppsFinishDate.before(shiftFinishDate)) {
ppsFinishDate = shiftFinishDate;
}
if (shiftFinishDate.before(orderStart)) {
areDatesCorrect = false;
}
}
}
if (ppsFinishDate != null) {
if (ppsFinishDate.after(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooLate", MessageType.INFO, false);
} else if (ppsFinishDate.before(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooEarly", MessageType.INFO, false);
}
}
}
if (!areDatesCorrect) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
}
}
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class StateChangeTest method stubStateChangeEntity.
protected void stubStateChangeEntity(final StateChangeEntityDescriber describer) {
given(stateChangeEntity.getDataDefinition()).willReturn(stateChangeDD);
final EntityList emptyEntityList = mockEntityList(Collections.<Entity>emptyList());
given(stateChangeEntity.getHasManyField(describer.getMessagesFieldName())).willReturn(emptyEntityList);
stubEntityField(stateChangeEntity, describer.getStatusFieldName(), StateChangeStatus.IN_PROGRESS.getStringValue());
given(stateChangeEntity.isValid()).willReturn(true);
given(stateChangeDD.save(Mockito.any(Entity.class))).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
return (Entity) invocation.getArguments()[0];
}
});
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class AbstractStateChangeAspectTest method mockEmptyEntityList.
@SuppressWarnings("unchecked")
private EntityList mockEmptyEntityList() {
EntityList entityList = mock(EntityList.class);
given(entityList.isEmpty()).willReturn(true);
given(entityList.iterator()).willReturn(Collections.EMPTY_LIST.iterator());
return entityList;
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class AbstractStateChangeAspectTest method init.
@Before
public void init() {
MockitoAnnotations.initMocks(this);
stubStateChangeEntity(DESCRIBER);
EntityList emptyEntityList = mockEmptyEntityList();
stubStateChangeContext();
stubOwner();
given(stateChangeEntity.getHasManyField("messages")).willReturn(emptyEntityList);
given(DESCRIBER.getOwnerDataDefinition().save(Mockito.any(Entity.class))).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
return (Entity) invocation.getArguments()[0];
}
});
}
Aggregations