use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class OperationDurationDetailsInOrderListenerOFSPG method saveDatesInSubOrders.
@Transactional
public final void saveDatesInSubOrders(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Long orderId = form.getEntityId();
List<Entity> orders = getOrdersForComponent(orderId);
if (!orders.isEmpty()) {
List<Entity> ordersTimeCalculations = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().createAlias("order", "ord", JoinType.LEFT).add(SearchRestrictions.in("ord.id", getOrdersForComponent(orderId).stream().map(entity -> entity.getId()).collect(Collectors.toList()))).list().getEntities();
Map<Long, Entity> ordersTimeCalculationsByOrder = ordersTimeCalculations.stream().collect(Collectors.toMap(x -> x.getBelongsToField(OrderTimeCalculationFields.ORDER).getId(), x -> x));
for (Entity order : orders) {
order.setField(OrderFields.DATE_FROM, getStartDate(ordersTimeCalculationsByOrder.get(order.getId())));
order.setField(OrderFields.DATE_TO, getFinishDate(ordersTimeCalculationsByOrder.get(order.getId())));
order.getDataDefinition().save(order);
}
form.addMessage("productionScheduling.info.saveDatesInSubOrdersSuccess", ComponentState.MessageType.SUCCESS);
} else {
form.addMessage("productionScheduling.info.saveDatesInSubOrdersNoOrders", ComponentState.MessageType.INFO);
}
state.performEvent(view, "reset", new String[0]);
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class MaterialAvailabilityListHooks method fillInReplacementsAvailableQuantity.
public void fillInReplacementsAvailableQuantity(final ViewDefinitionState state) throws JSONException {
FormComponent formComponent = (FormComponent) state.getComponentByReference("product");
GridComponent grid = (GridComponent) state.getComponentByReference(QcadooViewConstants.L_GRID);
JSONObject context = state.getJsonContext();
Entity product = formComponent.getEntity().getDataDefinition().get(formComponent.getEntityId());
List<Entity> replacements = product.getDataDefinition().get(product.getId()).getHasManyField(ProductFields.SUBSTITUTE_COMPONENTS).stream().map(sc -> sc.getBelongsToField(SubstituteComponentFields.PRODUCT)).collect(Collectors.toList());
List<Entity> warehouses;
if (context.has(L_WINDOW_MAIN_TAB_AVAILABILITY_COMPONENT_FORM_GRID_LAYOUT_LOCATIONS_IDS)) {
List<Long> ids = Lists.newArrayList();
for (int i = 0; i < context.getJSONArray(L_WINDOW_MAIN_TAB_AVAILABILITY_COMPONENT_FORM_GRID_LAYOUT_LOCATIONS_IDS).length(); i++) {
ids.add(context.getJSONArray(L_WINDOW_MAIN_TAB_AVAILABILITY_COMPONENT_FORM_GRID_LAYOUT_LOCATIONS_IDS).getLong(i));
}
warehouses = dataDefinitionService.get(MaterialFlowConstants.PLUGIN_IDENTIFIER, MaterialFlowConstants.MODEL_LOCATION).find().add(SearchRestrictions.in("id", ids)).list().getEntities();
} else {
warehouses = materialFlowResourcesService.getWarehouseLocationsFromDB();
}
List<Entity> materialAvailabilityList = Lists.newArrayList();
DataDefinition orderMaterialAvailabilityDD = dataDefinitionService.get(ProductFlowThruDivisionConstants.PLUGIN_IDENTIFIER, ProductFlowThruDivisionConstants.MODEL_MATERIAL_AVAILABILITY);
for (Entity warehouse : warehouses) {
Map<Long, BigDecimal> availableQuantities = materialFlowResourcesService.getQuantitiesForProductsAndLocation(replacements, warehouse);
for (Entity replacement : replacements) {
if (Objects.nonNull(availableQuantities.get(replacement.getId())) && BigDecimal.ZERO.compareTo(availableQuantities.get(replacement.getId())) < 0) {
Entity materialAvailability = orderMaterialAvailabilityDD.create();
materialAvailability.setField(MaterialAvailabilityFields.PRODUCT, replacement);
materialAvailability.setField(MaterialAvailabilityFields.UNIT, replacement.getField(ProductFields.UNIT));
materialAvailability.setField(MaterialAvailabilityFields.AVAILABLE_QUANTITY, availableQuantities.get(replacement.getId()));
materialAvailability.setField(MaterialAvailabilityFields.LOCATION, warehouse);
materialAvailabilityList.add(materialAvailability);
}
}
}
grid.setEntities(materialAvailabilityList.stream().sorted(Comparator.comparing(e -> e.getBelongsToField(MaterialAvailabilityFields.PRODUCT).getStringField(LocationFields.NUMBER))).collect(Collectors.toList()));
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class WorkPlansListViewTest method shouldBuildFromViewDefinitionState.
@Test
public final void shouldBuildFromViewDefinitionState() {
// given
ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
given(viewDefinitionState.getComponentByReference(QcadooViewConstants.L_WINDOW)).willReturn(windowComponent);
Ribbon ribbon = mock(Ribbon.class);
given((windowComponent).getRibbon()).willReturn(ribbon);
RibbonGroup actionsRibbonGroup = mock(RibbonGroup.class);
given(ribbon.getGroupByName("actions")).willReturn(actionsRibbonGroup);
given(actionsRibbonGroup.getItemByName("delete")).willReturn(deleteButton);
given(viewDefinitionState.getComponentByReference(QcadooViewConstants.L_GRID)).willReturn(workPlansGrid);
// when
WorkPlansListView workPlansListView = WorkPlansListView.from(viewDefinitionState);
workPlansListView.setUpDeleteButton(true, null);
workPlansListView.getSelectedWorkPlans();
// then
verify(deleteButton).setEnabled(anyBoolean());
verify(workPlansGrid).getSelectedEntities();
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class EventListeners method addEvent.
public void addEvent(final ViewDefinitionState viewDefinitionState, final ComponentState triggerState, final String[] args) {
String eventType = args[0];
factoryStructureId = Long.parseLong(args[1]);
EntityTree tree = factoryStructureForEventHooks.getGeneratedTree();
Optional<Entity> maybeElement = tree.stream().filter(element -> element.getId() == factoryStructureId).findFirst();
if (!maybeElement.isPresent()) {
viewDefinitionState.addMessage("cmmsMachineParts.error.elementNotSelected", ComponentState.MessageType.FAILURE);
return;
}
Entity selectedElement = maybeElement.get();
FactoryStructureElementType elementType = FactoryStructureElementType.of(selectedElement);
if (elementType.compareTo(FactoryStructureElementType.COMPANY) == 0) {
viewDefinitionState.addMessage("cmmsMachineParts.error.companySelected", ComponentState.MessageType.INFO);
return;
}
if (elementType.compareTo(FactoryStructureElementType.FACTORY) == 0) {
viewDefinitionState.addMessage("cmmsMachineParts.error.factorySelected", ComponentState.MessageType.INFO);
return;
}
DataDefinition dataDefinition = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT);
Entity maintenanceEvent = dataDefinition.create();
if (elementType.compareTo(FactoryStructureElementType.DIVISION) == 0 || elementType.compareTo(FactoryStructureElementType.PRODUCTION_LINE) == 0 || MaintenanceEventType.parseString(eventType).compareTo(MaintenanceEventType.PROPOSAL) == 0) {
maintenanceEvent.setField(MaintenanceEventFields.FAULT_TYPE, faultTypesService.getDefaultFaultType());
}
fillEventFieldsFromSelectedElement(maintenanceEvent, selectedElement);
maintenanceEvent.setField(MaintenanceEventFields.TYPE, eventType);
maintenanceEvent = dataDefinition.save(maintenanceEvent);
Map<String, Object> parameters = Maps.newHashMap();
parameters.put("form.id", maintenanceEvent.getId());
viewDefinitionState.redirectTo("../page/" + CmmsMachinePartsConstants.PLUGIN_IDENTIFIER + "/maintenanceEventDetails.html", false, true, parameters);
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class MasterOrderPositionsListHooks method groupByProduct.
public void groupByProduct(final ViewDefinitionState view) throws JSONException {
String positionsIds = view.getJsonContext().get("window.mainTab.positionsIds").toString();
Set<Long> ids = Lists.newArrayList(positionsIds.split(",")).stream().map(Long::valueOf).collect(Collectors.toSet());
List<Entity> positionDtos = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_MASTER_ORDER_POSITION_DTO).find().add(SearchRestrictions.in("id", ids)).list().getEntities();
Map<Integer, Entity> positions = Maps.newHashMap();
for (Entity position : positionDtos) {
Integer productId = position.getIntegerField(MasterOrderPositionDtoFields.PRODUCT_ID);
if (positions.containsKey(productId)) {
Entity existingPosition = positions.get(productId);
sumPositionsValues(position, existingPosition);
} else {
positions.put(productId, position);
}
}
GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
grid.setEntities(positions.values().stream().sorted(Comparator.comparing(e -> e.getStringField(MasterOrderPositionDtoFields.PRODUCT_NUMBER))).collect(Collectors.toList()));
}
Aggregations