package art.servers.colorsserver; import art.library.interop.InteropParameters; import art.library.interop.serialization.Serialization; import art.library.interop.serialization.SerializationException; import art.library.model.devices.DeviceAction; import art.library.model.devices.DeviceActionResult; import art.library.model.devices.DeviceCommands; import art.library.model.devices.colors.controller.M.M_Controller; import art.library.model.devices.colors.controller.M.M_ControllerCommands; import art.servers.colorsserver.controller.ControllerConnection; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class Shared extends art.servers.Shared { private static HashMap hcontrollerConnection = new HashMap(); public static Model getModel() { return (art.servers.colorsserver.Model)model; } public static ControllerConnection getControllerConnection (String key) { return(hcontrollerConnection.get(key)); } public static void addControllerConnection (String key, ControllerConnection controller) { hcontrollerConnection.putIfAbsent(key, controller); } public static DeviceAction[] responseError (M_Controller device, InteropParameters parameters, Exception exception) throws SerializationException { List result = new ArrayList(); String language = (String)parameters.getParameterValue("language"); M_ControllerCommands m_controllerCommands = (M_ControllerCommands)(Serialization.deserialize(M_ControllerCommands.class, (String)parameters.getParameterValue("body-content"))); if (m_controllerCommands.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.operationMode = m_controllerCommands.operationMode; DeviceAction action = new DeviceAction(device, parameters, command); if (command.operationMode == M_ControllerCommands.OPERATIONMODE_FIXED) action.actionName = Shared.getMessage(language, "Fixed times"); else if (command.operationMode == M_ControllerCommands.OPERATIONMODE_ACTUATED) action.actionName = Shared.getMessage(language, "Actuated"); else if (command.operationMode == M_ControllerCommands.OPERATIONMODE_SEMIACTUATED) action.actionName = Shared.getMessage(language, "Semiactuated"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.userControlManual != M_ControllerCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.userControlManual = m_controllerCommands.userControlManual; DeviceAction action = new DeviceAction(device, parameters, command); if (command.userControlManual == M_ControllerCommands.CONDITION_YES) action.actionName = Shared.getMessage(language, "User manual control (on)"); else if (command.userControlManual == M_ControllerCommands.CONDITION_NO) action.actionName = Shared.getMessage(language, "User manual control (off)"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.shiftPhase != M_ControllerCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.shiftPhase = m_controllerCommands.shiftPhase; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = Shared.getMessage(language, "Shift phase"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.userControlPlan != M_ControllerCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.userControlPlan = m_controllerCommands.userControlPlan; DeviceAction action = new DeviceAction(device, parameters, command); if (command.userControlPlan == M_ControllerCommands.CONDITION_YES) action.actionName = Shared.getMessage(language, "User forced plan (on)"); else if (command.userControlPlan == M_ControllerCommands.CONDITION_NO) action.actionName = Shared.getMessage(language, "User forced plan (off)"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.recordablePlan != null) { M_ControllerCommands command = new M_ControllerCommands(); command.recordablePlan = m_controllerCommands.recordablePlan; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = Shared.getMessage(language, "Custom plan"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.localPlan != DeviceCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.localPlan = m_controllerCommands.localPlan; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = Shared.getMessage(language, "Local plan"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.clearAlarms == DeviceCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.clearAlarms = m_controllerCommands.clearAlarms; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = Shared.getMessage(language, "Clear alarms"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.colorsMode != M_ControllerCommands.COLORS_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.colorsMode = m_controllerCommands.colorsMode; DeviceAction action = new DeviceAction(device, parameters, command); if (command.colorsMode == M_ControllerCommands.COLORS_COLORS) action.actionName = Shared.getMessage(language, "Colors on"); else if (command.colorsMode == M_ControllerCommands.COLORS_FLASHING) action.actionName = Shared.getMessage(language, "Colors flashing yellow"); else if (command.colorsMode == M_ControllerCommands.COLORS_OFF) action.actionName = Shared.getMessage(language, "Colors off"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.updateTime != M_ControllerCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.updateTime = m_controllerCommands.updateTime; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = Shared.getMessage(language, "Update time"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.realtime != DeviceCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.realtime = m_controllerCommands.realtime; DeviceAction action = new DeviceAction(device, parameters, command); if (command.realtime == DeviceCommands.CONDITION_YES) action.actionName = Shared.getMessage(language, "Realtime (on)"); else if (command.realtime == DeviceCommands.CONDITION_NO) action.actionName = Shared.getMessage(language, "Realtime (off)"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.emergency != DeviceCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.emergency = m_controllerCommands.emergency; DeviceAction action = new DeviceAction(device, parameters, command); if (command.emergency == DeviceCommands.CONDITION_YES) action.actionName = Shared.getMessage(language, "Emergency (on)"); else if (command.emergency == DeviceCommands.CONDITION_NO) action.actionName = Shared.getMessage(language, "Emergency (off)"); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } return result.toArray(new DeviceAction[result.size()]); } }