Alejandro Acuña
2024-10-25 e51f4a713ed6e744c203c9493165584728a29c52
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
package art.servers.asfserver.controller;
 
import art.library.interop.InteropParameters;
import art.library.interop.InteropResponse;
import art.library.interop.serialization.Serialization;
import art.library.interop.serialization.SerializationException;
import art.library.model.devices.DeviceAction;
import art.library.model.devices.DeviceCommands;
import art.library.model.devices.vms.asf.Asf;
import art.library.model.devices.vms.asf.AsfCommands;
import art.servers.ServerException;
import art.servers.asfserver.Shared;
 
public class ListenerImplementation extends art.servers.controller.ListenerImplementation
{
    // <editor-fold defaultstate="collapsed" desc="Liberate">
 
    /**
     * device = Device identifier to liberate username = Username of user that
     * send order computer = Computer name from user send order
     */
    public InteropResponse liberate(InteropParameters parameters) throws SerializationException
    {
        String language = (String) parameters.getParameterValue("language");
        Asf device = null;
 
        try
        {
            String identifier = (parameters.hasParameter("device") == true) ? (String) parameters.getParameterValue("device") : null;
            ControllerAsf controller = (ControllerAsf) Shared.getDeviceController(identifier);
            device = controller.getDevice();
 
            AsfCommands commands = new AsfCommands();
            commands.liberate = DeviceCommands.CONDITION_YES;
            parameters.setParameter("body-content", Serialization.toString(commands));
 
            DeviceAction[] laction = controller.sendCommands(parameters);
            return (new InteropResponse(laction));
        } catch (ServerException exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
        } catch (Exception exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception);
        }
    }
 
    // <editor-fold defaultstate="collapsed" desc="Turn off">
    /**
     * device = Device identifier to turn off username = Username of user that
     * send order computer = Computer name from user send order
     */
    public InteropResponse turnOff(InteropParameters parameters) throws SerializationException
    {
        String language = (String) parameters.getParameterValue("language");
        Asf device = null;
 
        try
        {
            String identifier = (parameters.hasParameter("device") == true) ? (String) parameters.getParameterValue("device") : null;
            int priority = (parameters.hasParameter("priority") == true) ? Integer.parseInt((String) parameters.getParameterValue("priority")) : 0;
            ControllerAsf controller = (ControllerAsf) Shared.getDeviceController(identifier);
            device = controller.getDevice();
 
            AsfCommands commands = new AsfCommands();
            commands.state = AsfCommands.STATE_OFF;
            commands.priority = priority;
            parameters.setParameter("body-content", Serialization.toString(commands));
 
            DeviceAction[] laction = controller.sendCommands(parameters);
            return (new InteropResponse(laction));
        } catch (ServerException exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
        } catch (Exception exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception);
        }
    }
 
    // </editor-fold>  
    // <editor-fold defaultstate="collapsed" desc="Turn on">
    /**
     * device = Device identifier to turn on state = State to send to ASF
     * username = Username of user that send order computer = Computer name from
     * user send order
     */
    public InteropResponse turnOn(InteropParameters parameters) throws SerializationException
    {
 
        String language = (String) parameters.getParameterValue("language");
        Asf device = null;
 
        try
        {
            String identifier = (parameters.hasParameter("device") == true) ? (String) parameters.getParameterValue("device") : null;
            int state = (parameters.hasParameter("state") == true) ? Integer.parseInt((String) parameters.getParameterValue("state")) : -1;
            int priority = (parameters.hasParameter("priority") == true) ? Integer.parseInt((String) parameters.getParameterValue("priority")) : 0;
            ControllerAsf controller = (ControllerAsf) Shared.getDeviceController(identifier);
            device = controller.getDevice();
 
            if (state < 0)
            {
                throw new ServerException("No correct state received");
            }
 
            AsfCommands commands = new AsfCommands();
            commands.state = state;
            commands.priority = priority;
            parameters.setParameter("body-content", Serialization.toString(commands));
 
            DeviceAction[] laction = controller.sendCommands(parameters);
            return (new InteropResponse(laction));
        } catch (ServerException exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
        } catch (Exception exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception);
        }
    }
 
    // </editor-fold>  
    // <editor-fold defaultstate="collapsed" desc="Commands">
    /**
     * device = Device identifier to send commands username = Username of user
     * that send order computer = Computer name from user send order
     */
    public InteropResponse sendCommands(InteropParameters parameters) throws SerializationException
    {
        String language = (String) parameters.getParameterValue("language");
        Asf device = null;
 
        try
        {
            String identifier = (parameters.hasParameter("device") == true) ? (String) parameters.getParameterValue("device") : null;
            ControllerAsf controller = (ControllerAsf) Shared.getDeviceController(identifier);
            device = controller.getDevice();
 
            DeviceAction[] laction = controller.sendCommands(parameters);
            return (new InteropResponse(laction));
        } catch (ServerException exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
        } catch (Exception exception)
        {
            throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception);
        }
    }
 
    // </editor-fold>  
}