Alejandro Acuña
2024-10-25 bf65497ed7abf9c669eb3cc0ba219dfa4494b759
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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<String, ControllerConnection> hcontrollerConnection = new HashMap<String, ControllerConnection>();
 
 
    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<DeviceAction> result = new ArrayList<DeviceAction>();
        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()]);
    }
 
}