Search in sources :

Example 41 with ComponentState

use of com.qcadoo.view.api.ComponentState 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 42 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class MatchingChangeoverNormsDetailsHooks method setFieldsVisible.

public void setFieldsVisible(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    ComponentState matchingNorm = view.getComponentByReference("matchingNorm");
    ComponentState matchingNormNotFound = view.getComponentByReference("matchingNormNotFound");
    if (form.getEntityId() == null) {
        matchingNorm.setVisible(false);
        matchingNormNotFound.setVisible(true);
    } else {
        matchingNorm.setVisible(true);
        matchingNormNotFound.setVisible(false);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 43 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class DivisionDetailsListenersPL method onRemoveSelectedProductionLines.

public void onRemoveSelectedProductionLines(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent productionLinesGrid = (GridComponent) view.getComponentByReference("productionLines");
    List<Entity> productionLinesToDelete = productionLinesGrid.getSelectedEntities();
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Long divisionId = form.getEntityId();
    for (Entity productionLine : productionLinesToDelete) {
        List<Entity> workstations = productionLine.getHasManyField(ProductionLineFields.WORKSTATIONS);
        workstations.stream().filter(workstation -> workstation.getBelongsToField(WorkstationFields.DIVISION).getId().equals(divisionId)).forEach(workstation -> {
            workstation.setField(WorkstationFieldsPL.PRODUCTION_LINE, null);
            workstation.setField(WorkstationFields.DIVISION, null);
            workstation.getDataDefinition().save(workstation);
        });
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) WorkstationFieldsPL(com.qcadoo.mes.productionLines.constants.WorkstationFieldsPL) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) ProductionLineFields(com.qcadoo.mes.productionLines.constants.ProductionLineFields) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) GridComponent(com.qcadoo.view.api.components.GridComponent) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) List(java.util.List) LookupUtils(com.qcadoo.mes.basic.LookupUtils) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 44 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class ProductionLineDetailsListeners method onRemoveSelectedDivisions.

public void onRemoveSelectedDivisions(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    GridComponent divisionsGrid = (GridComponent) view.getComponentByReference("divisions");
    List<Entity> divisionsToDelete = divisionsGrid.getSelectedEntities();
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Long productionLineId = form.getEntityId();
    for (Entity division : divisionsToDelete) {
        List<Entity> workstations = division.getHasManyField(DivisionFields.WORKSTATIONS);
        workstations.stream().filter(workstation -> workstation.getBelongsToField(WorkstationFieldsPL.PRODUCTION_LINE).getId().equals(productionLineId)).forEach(workstation -> {
            workstation.setField(WorkstationFieldsPL.PRODUCTION_LINE, null);
            workstation.setField(WorkstationFields.DIVISION, null);
            workstation.getDataDefinition().save(workstation);
        });
    }
}
Also used : WindowComponent(com.qcadoo.view.api.components.WindowComponent) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) WorkstationFieldsPL(com.qcadoo.mes.productionLines.constants.WorkstationFieldsPL) FactoryStructureGenerationService(com.qcadoo.mes.productionLines.factoryStructure.FactoryStructureGenerationService) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) DivisionFields(com.qcadoo.mes.basic.constants.DivisionFields) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) EntityTree(com.qcadoo.model.api.EntityTree) GridComponent(com.qcadoo.view.api.components.GridComponent) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) List(java.util.List) LookupUtils(com.qcadoo.mes.basic.LookupUtils) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 45 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class ScheduleDetailsListenersPS method assignOperationsToWorkstations.

@Transactional
public void assignOperationsToWorkstations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    Entity schedule = ((FormComponent) state).getEntity();
    Map<Long, Date> workstationsFinishDates = Maps.newHashMap();
    Set<Long> ordersToAvoid = Sets.newHashSet();
    List<Long> positionsIds = sortPositionsForWorkstations(schedule.getId());
    Date scheduleStartTime = schedule.getDateField(ScheduleFields.START_TIME);
    for (Long positionId : positionsIds) {
        Entity position = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_SCHEDULE_POSITION).get(positionId);
        if (ordersToAvoid.contains(position.getBelongsToField(SchedulePositionFields.ORDER).getId())) {
            continue;
        }
        List<Entity> workstations = getWorkstationsFromTOC(position);
        if (workstations.isEmpty()) {
            ordersToAvoid.add(position.getBelongsToField(SchedulePositionFields.ORDER).getId());
            continue;
        }
        Map<Long, PositionNewData> operationWorkstationsPositionNewData = Maps.newHashMap();
        boolean allMachineWorkTimesEqualsZero = getWorkstationsNewFinishDate(workstationsFinishDates, scheduleStartTime, position, workstations, operationWorkstationsPositionNewData);
        if (allMachineWorkTimesEqualsZero) {
            ordersToAvoid.add(position.getBelongsToField(SchedulePositionFields.ORDER).getId());
            continue;
        }
        if (ScheduleWorkstationAssignCriterion.SHORTEST_TIME.getStringValue().equals(schedule.getStringField(ScheduleFields.WORKSTATION_ASSIGN_CRITERION))) {
            operationWorkstationsPositionNewData.entrySet().stream().min(Comparator.comparing(e -> e.getValue().getFinishDate())).ifPresent(entry -> updatePositionWorkstationAndDates(entry, workstationsFinishDates, position));
        } else {
            Map.Entry<Long, PositionNewData> firstEntry;
            if (workstationsFinishDates.isEmpty()) {
                firstEntry = operationWorkstationsPositionNewData.entrySet().iterator().next();
            } else {
                firstEntry = operationWorkstationsPositionNewData.entrySet().stream().filter(entry -> workstationsFinishDates.containsKey(entry.getKey())).findFirst().orElse(operationWorkstationsPositionNewData.entrySet().iterator().next());
            }
            updatePositionWorkstationAndDates(firstEntry, workstationsFinishDates, position);
        }
    }
}
Also used : WorkstationFieldsPL(com.qcadoo.mes.productionLines.constants.WorkstationFieldsPL) ProductFamilyElementType(com.qcadoo.mes.basic.constants.ProductFamilyElementType) Date(java.util.Date) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) BigDecimal(java.math.BigDecimal) PluginManager(com.qcadoo.plugin.api.PluginManager) Map(java.util.Map) ProductQuantitiesService(com.qcadoo.mes.technologies.ProductQuantitiesService) REJECTED(com.qcadoo.mes.orders.states.constants.OperationalTaskStateStringValues.REJECTED) ScheduleDetailsListeners(com.qcadoo.mes.orders.listeners.ScheduleDetailsListeners) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Set(java.util.Set) WorkstationFields(com.qcadoo.mes.basic.constants.WorkstationFields) TechnologyOperationComponentFieldsTNFO(com.qcadoo.mes.timeNormsForOperations.constants.TechnologyOperationComponentFieldsTNFO) SchedulePositionFields(com.qcadoo.mes.orders.constants.SchedulePositionFields) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) Sets(com.google.common.collect.Sets) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) OperationProductOutComponentFields(com.qcadoo.mes.technologies.constants.OperationProductOutComponentFields) ScheduleSortOrder(com.qcadoo.mes.orders.constants.ScheduleSortOrder) OperationWorkTimeService(com.qcadoo.mes.operationTimeCalculations.OperationWorkTimeService) Optional(java.util.Optional) ScheduleWorkstationAssignCriterion(com.qcadoo.mes.orders.constants.ScheduleWorkstationAssignCriterion) TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ShiftsService(com.qcadoo.mes.basic.ShiftsService) WorkstationTypeFields(com.qcadoo.mes.basic.constants.WorkstationTypeFields) ComponentState(com.qcadoo.view.api.ComponentState) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) SearchProjections(com.qcadoo.model.api.search.SearchProjections) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) TechnologyService(com.qcadoo.mes.technologies.TechnologyService) TechOperCompWorkstationTimeFields(com.qcadoo.mes.timeNormsForOperations.constants.TechOperCompWorkstationTimeFields) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) SearchOrders(com.qcadoo.model.api.search.SearchOrders) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) SearchProjections.list(com.qcadoo.model.api.search.SearchProjections.list) SchedulePositionValidators(com.qcadoo.mes.orders.validators.SchedulePositionValidators) AssignedToOperation(com.qcadoo.mes.technologies.constants.AssignedToOperation) DateTime(org.joda.time.DateTime) Maps(com.google.common.collect.Maps) GridComponent(com.qcadoo.view.api.components.GridComponent) OperationWorkTime(com.qcadoo.mes.operationTimeCalculations.OperationWorkTime) ScheduleFields(com.qcadoo.mes.orders.constants.ScheduleFields) NumberService(com.qcadoo.model.api.NumberService) SearchProjections.rowCount(com.qcadoo.model.api.search.SearchProjections.rowCount) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) SearchProjections.alias(com.qcadoo.model.api.search.SearchProjections.alias) Comparator(java.util.Comparator) OperationalTaskFields(com.qcadoo.mes.orders.constants.OperationalTaskFields) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Entity(com.qcadoo.model.api.Entity) FormComponent(com.qcadoo.view.api.components.FormComponent) Date(java.util.Date) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8