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);
}
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;
}
Aggregations