Search in sources :

Example 26 with ViewDefinitionState

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]);
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) OrderTimeCalculationFields(com.qcadoo.mes.productionScheduling.constants.OrderTimeCalculationFields) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) TimeNormsConstants(com.qcadoo.mes.timeNormsForOperations.constants.TimeNormsConstants) JoinType(com.qcadoo.model.api.search.JoinType) List(java.util.List) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) FormComponent(com.qcadoo.view.api.components.FormComponent) Transactional(org.springframework.transaction.annotation.Transactional) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with ViewDefinitionState

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()));
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) java.util(java.util) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) MaterialFlowConstants(com.qcadoo.mes.materialFlow.constants.MaterialFlowConstants) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) SubstituteComponentFields(com.qcadoo.mes.basic.constants.SubstituteComponentFields) DataDefinition(com.qcadoo.model.api.DataDefinition) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) BigDecimal(java.math.BigDecimal) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) JSONException(org.json.JSONException) Lists(com.google.common.collect.Lists) JSONObject(org.json.JSONObject) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) MaterialAvailabilityFields(com.qcadoo.mes.productFlowThruDivision.constants.MaterialAvailabilityFields) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal)

Example 28 with ViewDefinitionState

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();
}
Also used : RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Test(org.junit.Test)

Example 29 with ViewDefinitionState

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);
}
Also used : FaultTypesService(com.qcadoo.mes.basic.FaultTypesService) FactoryStructureElementsService(com.qcadoo.mes.productionLines.factoryStructure.FactoryStructureElementsService) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) EventHooks(com.qcadoo.mes.cmmsMachineParts.hooks.EventHooks) MaintenanceEventFields(com.qcadoo.mes.cmmsMachineParts.constants.MaintenanceEventFields) FactoryStructureElementType(com.qcadoo.mes.productionLines.constants.FactoryStructureElementType) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) MaintenanceEventType(com.qcadoo.mes.cmmsMachineParts.constants.MaintenanceEventType) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Map(java.util.Map) MaintenanceEventState(com.qcadoo.mes.cmmsMachineParts.states.constants.MaintenanceEventState) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) MaintenanceEventService(com.qcadoo.mes.cmmsMachineParts.MaintenanceEventService) CmmsMachinePartsConstants(com.qcadoo.mes.cmmsMachineParts.constants.CmmsMachinePartsConstants) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Collectors(java.util.stream.Collectors) PlannedEventFields(com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Entity(com.qcadoo.model.api.Entity) List(java.util.List) FieldComponent(com.qcadoo.view.api.components.FieldComponent) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FactoryStructureForEventHooks(com.qcadoo.mes.cmmsMachineParts.hooks.FactoryStructureForEventHooks) Optional(java.util.Optional) FactoryStructureElementFields(com.qcadoo.mes.productionLines.constants.FactoryStructureElementFields) Entity(com.qcadoo.model.api.Entity) FactoryStructureElementType(com.qcadoo.mes.productionLines.constants.FactoryStructureElementType) EntityTree(com.qcadoo.model.api.EntityTree) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 30 with ViewDefinitionState

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()));
}
Also used : WindowComponent(com.qcadoo.view.api.components.WindowComponent) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Comparator.naturalOrder(java.util.Comparator.naturalOrder) Date(java.util.Date) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) MasterOrdersConstants(com.qcadoo.mes.masterOrders.constants.MasterOrdersConstants) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) JSONException(org.json.JSONException) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) MasterOrderPositionDtoFields(com.qcadoo.mes.masterOrders.constants.MasterOrderPositionDtoFields) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) Comparator.nullsFirst(java.util.Comparator.nullsFirst) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Collection(java.util.Collection) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Optional(java.util.Optional) Comparator(java.util.Comparator) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent)

Aggregations

ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)50 Autowired (org.springframework.beans.factory.annotation.Autowired)35 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)32 Service (org.springframework.stereotype.Service)31 ComponentState (com.qcadoo.view.api.ComponentState)29 Collectors (java.util.stream.Collectors)28 Entity (com.qcadoo.model.api.Entity)27 Lists (com.google.common.collect.Lists)25 GridComponent (com.qcadoo.view.api.components.GridComponent)25 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)24 FormComponent (com.qcadoo.view.api.components.FormComponent)23 BigDecimal (java.math.BigDecimal)21 List (java.util.List)21 Maps (com.google.common.collect.Maps)18 Map (java.util.Map)18 DataDefinition (com.qcadoo.model.api.DataDefinition)16 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)15 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)13 FieldComponent (com.qcadoo.view.api.components.FieldComponent)11 Objects (java.util.Objects)11