use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class ShiftTest method shouldParseTimeTableExceptions.
@Test
public final void shouldParseTimeTableExceptions() {
// given
String hours = "6:00-12:00, 21:30-2:30";
given(shiftEntity.getStringField(ShiftFields.MONDAY_HOURS)).willReturn(hours);
given(shiftEntity.getBooleanField(ShiftFields.MONDAY_WORKING)).willReturn(true);
DateTime mondayMidnight = new DateTime(2013, 9, 2, 0, 0);
DateTime freeTimeBegin = mondayMidnight.plusHours(8);
DateTime freeTimeEnd = freeTimeBegin.plusHours(4);
Entity freeTime = mockTimetableException(TimetableExceptionType.FREE_TIME, freeTimeBegin, freeTimeEnd);
DateTime workTimeBegin = mondayMidnight.plusHours(20);
DateTime workTimeEnd = workTimeBegin.plusHours(2);
Entity workTime = mockTimetableException(TimetableExceptionType.WORK_TIME, workTimeBegin, workTimeEnd);
EntityList timetableExceptionsList = mockEntityList(Lists.newArrayList(freeTime, workTime));
given(shiftEntity.getHasManyField(ShiftFields.TIMETABLE_EXCEPTIONS)).willReturn(timetableExceptionsList);
// when
Shift shift = new Shift(shiftEntity);
// then
assertTrue(shift.worksAt(DateTimeConstants.MONDAY, new LocalTime(10, 30)));
assertFalse(shift.worksAt(DateTimeConstants.SUNDAY, new LocalTime(12, 0)));
assertFalse(shift.worksAt(DateTimeConstants.MONDAY, new LocalTime(12, 01)));
assertEquals(Optional.of(new DateRange(mondayMidnight.plusHours(6).toDate(), mondayMidnight.plusHours(12).toDate())), shift.findWorkTimeAt(mondayMidnight.plusHours(7).toDate()));
assertFalse(shift.findWorkTimeAt(mondayMidnight.plusDays(2).toDate()).isPresent());
assertFalse(shift.findWorkTimeAt(mondayMidnight.plusHours(9).toDate()).isPresent());
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class CopyOfTechnologyHooks method getOrderForTechnology.
public Entity getOrderForTechnology(final ViewDefinitionState state) {
DataDefinition orderDD = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER);
String orderId = null;
try {
orderId = state.getJsonContext().getString("window.mainTab.technology.orderId");
} catch (JSONException ex) {
EntityList entities = ((FormComponent) state.getComponentByReference(QcadooViewConstants.L_FORM)).getPersistedEntityWithIncludedFormValues().getHasManyField("orders");
if (!entities.isEmpty()) {
orderId = String.valueOf(entities.get(0).getId());
}
}
return orderDD.get(Long.valueOf(orderId));
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class WarehouseIssueListenerAspect method onDiscard.
@RunInPhase(WarehouseIssueStateChangePhase.LAST)
@RunForStateTransition(sourceState = WarehouseIssueStringValues.DRAFT, targetState = WarehouseIssueStringValues.DISCARD)
@After(PHASE_EXECUTION_POINTCUT)
public void onDiscard(final StateChangeContext stateChangeContext, final int phase) {
Entity warehouseIssue = stateChangeContext.getOwner();
EntityList productsToIssue = warehouseIssue.getHasManyField(WarehouseIssueFields.PRODUCTS_TO_ISSUES);
productsToIssue.forEach(productToIssue -> {
reservationsServiceForProductsToIssue.deleteReservationFromProductToIssue(productToIssue);
});
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class WarehouseIssueListenerAspect method onCompleted.
@RunInPhase(WarehouseIssueStateChangePhase.PRE_VALIDATION)
@RunForStateTransition(sourceState = WarehouseIssueStringValues.IN_PROGRESS, targetState = WarehouseIssueStringValues.COMPLETED)
@After(PHASE_EXECUTION_POINTCUT)
public void onCompleted(final StateChangeContext stateChangeContext, final int phase) {
if (issueStateService.checkIfAnyNotIssuedPositionsExists(stateChangeContext)) {
return;
}
Entity warehouseIssue = stateChangeContext.getOwner();
EntityList productsToIssue = warehouseIssue.getHasManyField(WarehouseIssueFields.PRODUCTS_TO_ISSUES);
productsToIssue.forEach(productToIssue -> {
reservationsServiceForProductsToIssue.deleteReservationFromProductToIssue(productToIssue);
});
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class TechnologyValidationService method checkTopComponentsProducesProductForTechnology.
private boolean checkTopComponentsProducesProductForTechnology(final StateChangeContext stateChangeContext, final FormComponent technologyForm, final Entity technology) {
final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
final Entity product = savedTechnology.getBelongsToField(TechnologyFields.PRODUCT);
final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
final EntityTreeNode root = operationComponents.getRoot();
if (Objects.nonNull(root)) {
final EntityList operationProductOutComponents = root.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
for (Entity operationProductOutComponent : operationProductOutComponents) {
if (product.getId().equals(operationProductOutComponent.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId())) {
return true;
}
}
}
if (Objects.nonNull(technologyForm)) {
technologyForm.addMessage("technologies.technology.validate.global.error.noFinalProductInTechnologyTree", MessageType.FAILURE);
} else {
stateChangeContext.addValidationError("technologies.technology.validate.global.error.noFinalProductInTechnologyTree");
}
return false;
}
Aggregations