Search in sources :

Example 1 with FactoryStructureElementType

use of com.qcadoo.mes.productionLines.constants.FactoryStructureElementType 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 2 with FactoryStructureElementType

use of com.qcadoo.mes.productionLines.constants.FactoryStructureElementType in project mes by qcadoo.

the class FactoryStructureElementsService method getRelatedEntity.

public Entity getRelatedEntity(final Entity factoryStructureElement) {
    if (factoryStructureElement == null) {
        return null;
    }
    FactoryStructureElementType type = FactoryStructureElementType.of(factoryStructureElement);
    Long id = (Long) factoryStructureElement.getField(FactoryStructureElementFields.ENTITY_ID);
    if (type.compareTo(FactoryStructureElementType.COMPANY) == 0) {
        return getEntityById(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_COMPANY, id);
    } else if (type.compareTo(FactoryStructureElementType.FACTORY) == 0) {
        return getEntityById(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_FACTORY, id);
    } else if (type.compareTo(FactoryStructureElementType.DIVISION) == 0) {
        return getEntityById(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_DIVISION, id);
    } else if (type.compareTo(FactoryStructureElementType.PRODUCTION_LINE) == 0) {
        return getEntityById(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE, id);
    } else if (type.compareTo(FactoryStructureElementType.WORKSTATION) == 0) {
        return getEntityById(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION, id);
    } else if (type.compareTo(FactoryStructureElementType.SUBASSEMBLY) == 0) {
        return getEntityById(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBASSEMBLY, id);
    }
    return null;
}
Also used : FactoryStructureElementType(com.qcadoo.mes.productionLines.constants.FactoryStructureElementType)

Aggregations

FactoryStructureElementType (com.qcadoo.mes.productionLines.constants.FactoryStructureElementType)2 Maps (com.google.common.collect.Maps)1 FaultTypesService (com.qcadoo.mes.basic.FaultTypesService)1 WorkstationFields (com.qcadoo.mes.basic.constants.WorkstationFields)1 MaintenanceEventService (com.qcadoo.mes.cmmsMachineParts.MaintenanceEventService)1 CmmsMachinePartsConstants (com.qcadoo.mes.cmmsMachineParts.constants.CmmsMachinePartsConstants)1 MaintenanceEventFields (com.qcadoo.mes.cmmsMachineParts.constants.MaintenanceEventFields)1 MaintenanceEventType (com.qcadoo.mes.cmmsMachineParts.constants.MaintenanceEventType)1 PlannedEventFields (com.qcadoo.mes.cmmsMachineParts.constants.PlannedEventFields)1 EventHooks (com.qcadoo.mes.cmmsMachineParts.hooks.EventHooks)1 FactoryStructureForEventHooks (com.qcadoo.mes.cmmsMachineParts.hooks.FactoryStructureForEventHooks)1 MaintenanceEventState (com.qcadoo.mes.cmmsMachineParts.states.constants.MaintenanceEventState)1 FactoryStructureElementFields (com.qcadoo.mes.productionLines.constants.FactoryStructureElementFields)1 FactoryStructureElementsService (com.qcadoo.mes.productionLines.factoryStructure.FactoryStructureElementsService)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 Entity (com.qcadoo.model.api.Entity)1 EntityTree (com.qcadoo.model.api.EntityTree)1 ComponentState (com.qcadoo.view.api.ComponentState)1 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)1