package art.servers.pvvserver.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.pvv.Pvv;
|
import art.library.model.devices.vms.pvv.PvvCommands;
|
import art.servers.ServerException;
|
import art.servers.pvvserver.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");
|
Pvv device = null;
|
|
try
|
{
|
String identifier = (parameters.hasParameter("device") == true) ? (String) parameters.getParameterValue("device") : null;
|
ControllerPvv controller = (ControllerPvv) Shared.getDeviceController(identifier);
|
device = controller.getDevice();
|
|
PvvCommands commands = new PvvCommands();
|
commands.liberate = DeviceCommands.CONDITION_YES;
|
parameters.addBodycontent(commands);
|
|
DeviceAction[] laction = controller.sendCommands(parameters);
|
return (new InteropResponse(laction));
|
} catch (ServerException exception)
|
{
|
//Shared.printstack("liberate", exception);
|
throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
|
} catch (Exception exception)
|
{
|
//Shared.printstack("liberate", 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");
|
Pvv 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;
|
ControllerPvv controller = (ControllerPvv) Shared.getDeviceController(identifier);
|
device = controller.getDevice();
|
|
PvvCommands commands = new PvvCommands();
|
commands.turnOff = PvvCommands.CONDITION_YES;
|
commands.priority = priority;
|
parameters.addBodycontent(commands);
|
|
DeviceAction[] laction = controller.sendCommands(parameters);
|
return (new InteropResponse(laction));
|
} catch (ServerException exception)
|
{
|
//Shared.printstack("turnOff", exception);
|
throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
|
} catch (Exception exception)
|
{
|
//Shared.printstack("turnOff", 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 PVV
|
* 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");
|
Pvv 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;
|
ControllerPvv controller = (ControllerPvv) Shared.getDeviceController(identifier);
|
device = controller.getDevice();
|
|
if (state < 0)
|
{
|
throw new ServerException("No correct state received");
|
}
|
|
PvvCommands commands = new PvvCommands();
|
commands.turnOff = PvvCommands.CONDITION_NO;
|
commands.priority = priority;
|
parameters.addBodycontent(commands);
|
|
DeviceAction[] laction = controller.sendCommands(parameters);
|
return (new InteropResponse(laction));
|
} catch (ServerException exception)
|
{
|
//Shared.printstack("turnOn", exception);
|
throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
|
} catch (Exception exception)
|
{
|
//Shared.printstack("turnOn", 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");
|
Pvv device = null;
|
|
try
|
{
|
String identifier = (parameters.hasParameter("device") == true) ? (String) parameters.getParameterValue("device") : null;
|
ControllerPvv controller = (ControllerPvv) Shared.getDeviceController(identifier);
|
device = controller.getDevice();
|
|
DeviceAction[] laction = controller.sendCommands(parameters);
|
return (new InteropResponse(laction));
|
} catch (ServerException exception)
|
{
|
Shared.printstack("sendCommands", exception);
|
throw new SerializationException(Shared.getMessage(language, exception.getMessage()));
|
} catch (Exception exception)
|
{
|
Shared.printstack("sendCommands", exception);
|
throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception);
|
}
|
}
|
|
}
|