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 { // /** * 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); } } // /** * 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); } } // // /** * 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); } } // // /** * 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); } } // }