package art.servers.transactionsserver.controller;
import art.library.interop.InteropParameter;
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.Device;
import art.library.model.devices.DeviceAction;
import art.library.model.devices.DeviceActionResult;
import art.library.model.devices.DeviceCommands;
import art.library.model.devices.application.Application;
import art.library.model.devices.application.ApplicationInformation;
import art.library.model.devices.user.User;
import art.library.model.devices.user.UserConfiguration;
import art.library.model.devices.user.UserInformation;
import art.library.model.devices.user.UserPermission;
import art.library.model.devices.user.configuration.UserConfigurationPermissionInterop;
import art.library.model.devices.user.configuration.UserConfigurationPermissionInteropParameter;
import art.library.model.general.ModelFile;
import art.library.model.transactions.alarms.DeviceAlarmCommands;
import art.library.model.transactions.commands.ScheduledTaskProcedureCommands;
import art.library.model.transactions.scheduler.ScheduledTask;
import art.library.model.transactions.scheduler.ScheduledTaskProcedure;
import art.library.model.transactions.scheduler.ScheduledTaskProcedureInterval;
import art.library.model.transactions.tutor.trafficalerts.TrafficAlertProcedure;
import art.library.utils.licence.Licence;
import art.library.utils.resources.Resources;
import art.servers.transactionsserver.Shared;
import eu.medsea.mimeutil.MimeUtil2;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
public class ListenerImplementation extends art.servers.controller.ListenerImplementation
{
public ListenerImplementation()
{
}
//
public InteropResponse listJavaLibraries (InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
try
{
// String folderName = (String)parameters.getParameterValue("folder");
// String folder = "data/" + Shared.getApplicationName() + "/";
// if (folderName != null) folder = folder + folderName + "/";
//
// File directory = new File(folder);
// List lfiles = new ArrayList();
// listFiles(directory, lfiles);
// List lmodelfile = new ArrayList();
//
// for (File file : lfiles)
// {
// try
// {
// if (file.isFile() == true)
// {
// ModelFile modelFile = new ModelFile();
// modelFile.folder = file.getAbsolutePath().replace(directory.getAbsolutePath(), "").replace("\\", "/").replaceFirst("/", "").replaceAll(file.getName(), "");
// if (folderName != null) modelFile.folder = modelFile.folder + "/" + folderName;
// modelFile.name = file.getName().substring(0, file.getName().lastIndexOf('.'));
// modelFile.extension = file.getName().substring(file.getName().lastIndexOf('.') + 1, file.getName().length());
//
// if (modelFile.extension.equalsIgnoreCase("svg"))
// {
// modelFile.mime = "image/svg+xml";
// }
// else
// {
// MimeUtil2 mimeUtil = new MimeUtil2();
// mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
// modelFile.mime = MimeUtil2.getMostSpecificMimeType(mimeUtil.getMimeTypes(file)).toString();
// }
//
// lmodelfile.add(modelFile);
// }
// }
// catch (Exception e)
// {
// }
// }
//
// InteropResponse response = new InteropResponse(lmodelfile.toArray(new ModelFile[lmodelfile.size()]));
// return response;
throw new Exception("Not implemented");
}
catch (Exception e)
{
throw getException(language, e);
}
}
public InteropResponse getJavaLibrary (InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
try
{
byte[] data = Resources.getExternalFileBytes(getFileName(parameters));
if (data.length == 0) data = Resources.getResourceBytes(getFileName(parameters));
InteropResponse response = new InteropResponse(data);
return response;
}
catch (Exception e)
{
throw getException(language, e);
}
}
//
//
/**
* @param parameters InteropParameters
* name: "set" class: addAlarmAction
*
name: "language" class: String
*
name: "username" class: String
*
name: "computer" class: String
*
name: "device" class: String device identifier who alarms belongs
*
name: "alarm" class: String Identifier of the alarm that is being validated, confirmed or cancelled
*
name: "type" class: Int type of action with alarm (DeviceAlarmCommands.TYPE_ALARM_VALIDATE, DeviceAlarmCommands.TYPE_ALARM_CONFIRM or DeviceAlarmCommands.TYPE_ALARM_CANCEL)
* @return InteropResponse
* @return InteropResponse with true Boolean if success
* @throws SerializationException
*/
public InteropResponse addAlarmAction(InteropParameters parameters) throws SerializationException
{
String language = (String) parameters.getParameterValue("language");
try
{
String username = (String) parameters.getParameterValue("username");
String computer = (String) parameters.getParameterValue("computer");
// String identifier = (String) parameters.getParameterValue("device");
// String alarm = (String) parameters.getParameterValue("alarm");
// int type = (parameters.hasParameter("type") == true) ? Integer.parseInt((String)parameters.getParameterValue("type")) : DeviceAlarmCommands.TYPE_ALARM_NOTHING;
DeviceAlarmCommands deviceAlarmCommands = parameters.getBodyContentValue(DeviceAlarmCommands.class);
Device device = null;
try
{
device = Shared.model.getDeviceExternal(deviceAlarmCommands.deviceIdentifier);
}
catch (Exception exception)
{
throw new SerializationException(Shared.getMessage(language, "Device does not exist"), exception);
}
DeviceAction action = new DeviceAction(device, parameters, deviceAlarmCommands);
action.actionName = deviceAlarmCommands.getActionName();
DeviceActionResult result = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT);
action.setResult(result);
Shared.model.addAction(action);
return new InteropResponse(true);
}
catch (SerializationException exception)
{
throw exception;
}
catch (Exception e)
{
throw new SerializationException(Shared.getMessage(language, "Error inserting alarm action"), e.getMessage());
}
}
//
//
/**
* @param parameters InteropParameters
* name: "set" class: createExternalLayer
*
name: "language" class: String
*
name: "lExternalLayer" class: ExternalLayer[]
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse createExternalLayer(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelExternalLayers.createExternalLayer(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: readExternalLayer
*
name: "language" class: String
*
name: "externalLayerName" class: String
* @return InteropResponse
* ExternalLayer
* @throws SerializationException
*/
public InteropResponse readExternalLayer(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelExternalLayers.readExternalLayer(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: getExternalLayers
*
name: "language" class: String
* @return InteropResponse
* ExternalLayer[]
* @throws SerializationException
*/
public InteropResponse getExternalLayers(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelExternalLayers.getExternalLayers(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: updateExternalLayer
*
name: "language" class: String
*
name: "lExternalLayer" class: ExternalLayer[]
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse updateExternalLayer(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelExternalLayers.updateExternalLayer(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: deleteExternalLayer
*
name: "language" class: String
*
name: "lName" class: String[]
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse deleteExternalLayer(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelExternalLayers.deleteExternalLayer(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: existExternalLayer
*
name: "language" class: String
*
name: "name" class: String
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse existExternalLayer(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelExternalLayers.existExternalLayer(parameters);
}
//
//
/**
* @param parameters InteropParameters
* name: "set" class: createConfigurationGeoline
*
name: "language" class: String
*
name: "lGeoLine" class: GeoLine[]
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse createConfigurationGeoline(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelConfigurationGeoline.createConfigurationGeoline(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: readConfigurationGeoline
*
name: "language" class: String
*
name: "id" class: Integer
* @return InteropResponse
* GeoLine
* @throws SerializationException
*/
public InteropResponse readConfigurationGeoline(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelConfigurationGeoline.readConfigurationGeoline(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: updateConfigurationGeoline
*
name: "language" class: String
*
name: "lGeoLine" class: GeoLine[]
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse updateConfigurationGeoline(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelConfigurationGeoline.updateConfigurationGeoline(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: deleteConfigurationGeoline
*
name: "language" class: String
*
name: "lId" class: Integer[]
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse deleteConfigurationGeoline(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelConfigurationGeoline.deleteConfigurationGeoline(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: existConfigurationGeoline
*
name: "language" class: String
*
name: "id" class: Integer
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse existConfigurationGeoline(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelConfigurationGeoline.existConfigurationGeoline(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: getLayerConfigurationByLayerAndZoom
*
name: "language" class: String
*
name: "geoline" class: GeoLine
* @return InteropResponse
* GeoLine[]
* @throws SerializationException
*/
public InteropResponse getLayerConfigurationByLayerAndZoom(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelConfigurationGeoline.getLayerConfigurationByLayerAndZoom(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: getLayerConfigurationByLayerName
*
name: "language" class: String
*
name: "layerName" class: String
* @return InteropResponse
* GeoLine[]
* @throws SerializationException
*/
public InteropResponse getLayerConfigurationByLayerName(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelConfigurationGeoline.getLayerConfigurationByLayerName(parameters);
}
//
//
/**
* @param parameters InteropParameters
* name: "set" class: addDevices
*
name: "language" class: String
*
name: "body-content" class: String[]
* @return InteropResponse
* @return InteropResponse with true Boolean if success
* @throws SerializationException
*/
public InteropResponse addUsers(InteropParameters parameters) throws SerializationException
{
return addDevices(parameters);
}
public InteropResponse addDevices(InteropParameters parameters) throws SerializationException
{
InteropResponse response;
String language = (String) parameters.getParameterValue("language");
boolean updateRole = false;
String username = "";
try
{
User[] luser = parameters.getBodyContentValue(User[].class);
for (User user : luser)
{
User currentuser = null;
username = user.getIdentifier();
createPermissions(user);
try
{
currentuser = (User)Shared.getModel().getDevice(user.getIdentifier());
}
catch (Exception e)
{
try
{
currentuser = (User)Shared.getModel().getDevice(Licence.encrypt(user.getIdentifier()));
}
catch (Exception ex)
{
currentuser = null;
}
}
if (currentuser != null) {
try
{
if (currentuser.getDeviceInformation().role.equals(user.getDeviceInformation().role) == false)
{
updateRole = true;
}
} catch (Exception ex) {
}
}
}
Shared.model.updateDevice(luser);
if (updateRole == true)
{
String resource = Shared.getMessage(language, "Username") + " : " + username;
Shared.traceInformation(Shared.getApplicationName(), Shared.getMessage(language, "Profile update"), resource, null, language);
}
return new InteropResponse(true);
}
catch (Exception e)
{
String resource = Shared.getMessage(language, "Username") + " : " + username;
Shared.traceError(Shared.getApplicationName(), Shared.getMessage(language, "Profile update"), resource, e, null, language);
throw new SerializationException("error inserting some users", e.getMessage());
}
}
private void createPermissions (User user) throws Exception
{
User userRole = null;
try
{
userRole = (User)Shared.getModel().getDevice(Licence.encrypt(user.getDeviceInformation().role));
}
catch (Exception exception)
{
try
{
userRole = (User)Shared.getModel().getDevice(user.getDeviceInformation().role);
}
catch (Exception e)
{
}
}
if (userRole != null)
{
user.configuration = userRole.configuration;
}
else
{
if (user.getDeviceConfiguration() == null)
{
user.configuration = new UserConfiguration();
if (user.getDeviceConfiguration().permissions == null)
{
user.getDeviceConfiguration().permissions = new UserPermission();
}
}
if ("IMH".equalsIgnoreCase(user.getDeviceInformation().role))
{
user.getDeviceConfiguration().permissions.linterop.clear();
String regex = "[\\s\\S]*";
UserConfigurationPermissionInterop interopGetGeoJson = new UserConfigurationPermissionInterop();
interopGetGeoJson.operation = "^getGeoJson.*";
interopGetGeoJson.application = "art.servers.zbe.ermserver";
interopGetGeoJson.devicesAllow.add(regex);
UserConfigurationPermissionInteropParameter permissionParameter = new UserConfigurationPermissionInteropParameter();
permissionParameter.name = regex;
permissionParameter.values.add(regex);
interopGetGeoJson.parametersAllow.add(permissionParameter);
user.getDeviceConfiguration().permissions.linterop.add(interopGetGeoJson);
UserConfigurationPermissionInterop interopGetVehicle = new UserConfigurationPermissionInterop();
interopGetVehicle.operation = "^getVehicle";
interopGetVehicle.application = "art.servers.zbe.listserver";
interopGetVehicle.devicesAllow.add(regex);
UserConfigurationPermissionInteropParameter permissionParameterVehicle = new UserConfigurationPermissionInteropParameter();
permissionParameterVehicle.name = regex;
permissionParameterVehicle.values.add(regex);
interopGetVehicle.parametersAllow.add(permissionParameterVehicle);
user.getDeviceConfiguration().permissions.linterop.add(interopGetVehicle);
}
else
{
user.getDeviceConfiguration().permissions.linterop.clear();
String regex = "[\\s\\S]*";
UserConfigurationPermissionInterop interop = new UserConfigurationPermissionInterop();
interop.actionsAllow.add(regex);
interop.devicesAllow.add(regex);
interop.application = regex;
interop.operation = regex;
UserConfigurationPermissionInteropParameter permissionParameter = new UserConfigurationPermissionInteropParameter();
permissionParameter.name = regex;
permissionParameter.values.add(regex);
interop.parametersAllow.add(permissionParameter);
user.getDeviceConfiguration().permissions.linterop.add(interop);
}
}
}
/**
* @param parameters InteropParameters
*
name: "get" class: getUsers
*
name: "language" class: String
*
name: "body-content" class: String[]
*
name: "timestamp" class: Long*
* @return InteropResponse
* User[]
* @throws SerializationException
*/
public InteropResponse getUsers(InteropParameters parameters) throws SerializationException
{
try
{
String language = parameters.hasParameter("language") ? parameters.getParameterValue("language") : Shared.getLanguage();
String[] lusername = parameters.getBodyContentValue(String[].class);
long timestamp = parameters.hasParameter("timestamp") ? getTimestamp(parameters.getParameterValue("timestamp")) : 0L;
return new InteropResponse(Shared.getModel().getDevices(lusername, timestamp));
} catch (Exception e)
{
throw new SerializationException(Shared.getMessage("error getting users"), e);
}
}
/**
* @param parameters InteropParameters
*
name: "get" class: getUsersIdentification
*
name: "language" class: String
*
name: "lGroup" class: String[]
* @return InteropResponse
* UserIdentification[]
* @throws SerializationException
*/
public InteropResponse getUsersIdentification(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelUsers.getUsersIdentification(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: getUsersIdentification
*
name: "language" class: String
*
name: "lGroup" class: String[]
* @return InteropResponse
* UserIdentification[]
* @throws SerializationException
*/
public InteropResponse getUsersInformation(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelUsers.getUsersInformation(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: getUserLdap
*
name: "language" class: String
*
name: "username" class: String
* @return InteropResponse
* UserInformation
* @throws SerializationException
*/
public InteropResponse getUserLdap(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelUsers.getUserLdap(parameters);
}
/**
* @param parameters InteropParameters
*
name: "art" class: updatePasswordUser
*
name: "language" class: String
*
name: "username" class: String
*
name: "oldpassword" class: String
*
name: "newpassword" class: String
* @return InteropResponse
* @return InteropResponse with true Boolean if success
* @throws SerializationException
*/
public InteropResponse updatePasswordUser(InteropParameters parameters) throws SerializationException
{
try
{
String language = parameters.hasParameter("language") ? parameters.getParameterValue("language") : Shared.getLanguage();
String username = parameters.hasParameter("username") ? parameters.getParameterValue("username") : null;
String oldpassword = parameters.hasParameter("oldpassword") ? parameters.getParameterValue("oldpassword") : null;
String newpassword = parameters.hasParameter("newpassword") ? parameters.getParameterValue("newpassword") : null;
if (username == null)
{
throw new SerializationException(Shared.getMessage(language, "Username cannot be null"));
}
else if (oldpassword == null)
{
throw new SerializationException(Shared.getMessage(language, "Old password cannot be null"));
}
else if (newpassword == null)
{
throw new SerializationException(Shared.getMessage(language, "New password cannot be null"));
}
User user = (User)Shared.getModel().getDevice(Licence.encrypt(username));
String currentpassword = Licence.decrypt(user.getDeviceInformation().password);
if (currentpassword.equals(oldpassword) == false)
{
throw new SerializationException(Shared.getMessage(language, "Old password is not correct"));
}
User newuser = Serialization.clone(user);
newuser.getDeviceInformation().password = Licence.encrypt(newpassword);
Shared.model.updateDevice(user, newuser);
return new InteropResponse(new Boolean(true));
}
catch (SerializationException e)
{
throw e;
}
catch (Exception e)
{
throw new SerializationException(Shared.getMessage("Error updating user password"), e);
}
}
//
//
public InteropResponse login(InteropParameters parameters) throws SerializationException
{
InteropResponse response = startSession(parameters);
return response;
}
/**
* @param parameters InteropParameters
* name: "get" class: startSession
*
name: "language" class: String
*
name: "identification" class: SessionIdentification
*
name: "lUserIdentification" class: UserIdentification[]
* @return InteropResponse
* Session
* @throws SerializationException
*/
public InteropResponse startSession(InteropParameters parameters) throws SerializationException
{
InteropResponse response = Shared.getModel().modelSessions.startSession(parameters);
return response;
}
/**
* @param parameters InteropParameters
*
name: "get" class: addUsersSession
*
name: "language" class: String
*
name: "session" class: Session
*
name: "lUserIdentification" class: UserIdentification[]
* @return InteropResponse
* Session
* @throws SerializationException
*/
public InteropResponse addUsersSession(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelSessions.addUsersSession(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: removeUsersSession
*
name: "language" class: String
*
name: "session" class: Session
*
name: "lusername" class: String[]
* @return InteropResponse
* Session
* @throws SerializationException
*/
public InteropResponse removeUsersSession(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelSessions.removeUsersSession(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: endSession
*
name: "language" class: String
*
name: "identification" class: SessionIdentification
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse endSession(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelSessions.endSession(parameters);
}
//
//
public InteropResponse checkToken(InteropParameters parameters) throws SerializationException
{
return new InteropResponse(new Boolean(true));
}
/**
* @param parameters InteropParameters
* name: "get" class: getPermissions
*
name: "language" class: String
* @return InteropResponse
* ListPermission
* @throws SerializationException
*/
public InteropResponse getPermissions(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelPermissions.getPermissions(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: getUserPermission
*
name: "language" class: String
*
name: "lusername" class: String[]
*
name: "timestamp" class: Long
* @return InteropResponse
* UserPermission
* @throws SerializationException
*/
public InteropResponse getUserPermission(InteropParameters parameters) throws SerializationException
{
try
{
return Shared.getModel().modelPermissions.getUserPermission(parameters);
} catch (Exception ex)
{
throw new SerializationException(Shared.getMessage("Error getting user permissions"), ex);
}
}
//
//
/**
* @param parameters InteropParameters
* name: "get" class: getAlarmsInformation
*
name: "language" class: String
* @return InteropResponse
* AlarmInformation[]
* @throws SerializationException
*/
public InteropResponse getAlarmsInformation(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelAlarms.getAlarmsInformation(parameters);
}
/**
* @param parameters InteropParameters
*
name: "get" class: getAlarmsUserConfiguration
*
name: "language" class: String
*
name: "lusername" class: String[]
*
name: "timestamp" class: Long *OPTIONAL
* @return InteropResponse
* UserAlarmConfiguration[]
* @throws SerializationException
*/
public InteropResponse getAlarmsUserConfiguration(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelAlarms.getAlarmsUserConfiguration(parameters);
}
//
//
/**
* @param parameters InteropParameters
* name: "get" class: getConfigurationLanguage
*
name: "language" class: String
* @return InteropResponse
* ConfigurationLanguage
* @throws SerializationException
*/
public InteropResponse getConfigurationLanguage(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelMessages.getConfigurationLanguage(parameters);
}
/**
* @param parameters InteropParameters
*
name: "set" class: setConfigurationLanguage
*
name: "language" class: String
*
name: "configurationLanguage" class: String[]
* @return InteropResponse
* Boolean
* @throws SerializationException
*/
public InteropResponse setConfigurationLanguage(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelMessages.setConfigurationLanguage(parameters);
}
//
//
public InteropResponse getApplications(InteropParameters parameters) throws SerializationException
{
String language = (String) parameters.getParameterValue("language");
long timestamp = 0;
try
{
if (parameters.hasParameter("timestamp"))
{
timestamp = Long.parseLong((String) parameters.getParameterValue("timestamp"));
}
Application[] result = Shared.getModel().getApplications(timestamp);
return new InteropResponse(result);
} catch (Exception e)
{
String msg = "error getting applications";
throw new SerializationException(e.getMessage());
}
}
public InteropResponse getApplicationsInformation(InteropParameters parameters) throws SerializationException
{
String language = (String) parameters.getParameterValue("language");
long timestamp = 0;
try
{
if (parameters.hasParameter("timestamp"))
{
timestamp = Long.parseLong((String) parameters.getParameterValue("timestamp"));
}
Application[] lapplication = Shared.getModel().getApplications(timestamp);
ApplicationInformation[] result = new ApplicationInformation[lapplication.length];
for (int i = 0; i < lapplication.length; i++)
{
result[i] = lapplication[i].getDeviceInformation();
}
return new InteropResponse(result);
}
catch (Exception e)
{
String msg = "error getting applications Information";
throw new SerializationException(e.getMessage());
}
}
//
//
/**
* @param parameters InteropParameters
*
* name: "language" class: String
* @return InteropResponse AddressLogin[0]
* @throws SerializationException
*/
public InteropResponse getBlockedUsers(InteropParameters parameters) throws SerializationException {
return Shared.getModel().loginBlockedManager.getBlockedUsers(parameters);
}
/**
* @param parameters InteropParameters
*
* name: "language" class: String
*
* name: "body-content" class: String[]
* @return InteropResponse Boolean
* @throws SerializationException
*/
public InteropResponse unlockUsers(InteropParameters parameters) throws SerializationException {
try
{
return Shared.getModel().loginBlockedManager.unlockUsers(
parameters.getBodyContentValue(String[].class));
} catch (Exception exception)
{
throw new SerializationException(Shared.getMessage(exception.getMessage()), exception);
}
}
/**
* @param parameters InteropParameters
*
* name: "language" class: String
* @return InteropResponse AddressLogin[0]
* @throws SerializationException
*/
public InteropResponse getBlockedIPAddresses(InteropParameters parameters) throws SerializationException {
return Shared.getModel().loginBlockedManager.getBlockedIPAddresses(parameters);
}
/**
* @param parameters InteropParameters
*
* name: "language" class: String
*
* name: "body-content" class: String[]
* @return InteropResponse Boolean
* @throws SerializationException
*/
public InteropResponse unlockIPAddresses(InteropParameters parameters) throws SerializationException {
try
{
return Shared.getModel().loginBlockedManager.unlockIPAddress(
parameters.getBodyContentValue(String[].class));
} catch (Exception exception)
{
throw new SerializationException(Shared.getMessage(exception.getMessage()), exception);
}
}
//
//
public InteropResponse addVmsGeneralCommandsMessages(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.addVmsGeneralCommandsMessages(parameters);
}
public InteropResponse removeVmsGeneralCommandsMessages(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.removeVmsGeneralCommandsMessages(parameters);
}
public InteropResponse getVmsGeneralCommandsMessages(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.getVmsGeneralCommandsMessages(parameters);
}
public InteropResponse getVmsGeneralCommandsMessagesFolders(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.getVmsGeneralCommandsMessagesFolders(parameters);
}
public InteropResponse renameVmsGeneralCommandsMessagesFolder(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.renameVmsGeneralCommandsMessagesFolder(parameters);
}
public InteropResponse getVmsGeneralCommandsMessageTypes(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.getVmsGeneralCommandsMessageTypes(parameters);
}
public InteropResponse getVmsGeneralCommandsMessagesFoldersDevice(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.getVmsGeneralCommandsMessagesFoldersDevice(parameters);
}
public InteropResponse getVmsGeneralCommandsMessagesDeviceFolder(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsMessagesLibrary.getVmsGeneralCommandsMessagesDeviceFolder(parameters);
}
//
//
public InteropResponse addVmsGeneralCommandsPictogram(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsPictogramsLibrary.addVmsGeneralCommandsPictogram(parameters);
}
public InteropResponse removeVmsGeneralCommandsPictogram(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsPictogramsLibrary.removeVmsGeneralCommandsPictogram(parameters);
}
public InteropResponse getVmsGeneralCommandsPictogram(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsPictogramsLibrary.getVmsGeneralCommandsPictogram(parameters);
}
public InteropResponse getVmsGeneralCommandsPictogramFolders(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsPictogramsLibrary.getVmsGeneralCommandsPictogramFolders(parameters);
}
public InteropResponse renameVmsGeneralCommandsPictogramFolder(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsPictogramsLibrary.renameVmsGeneralCommandsPictogramFolder(parameters);
}
public InteropResponse getVmsGeneralCommandsPictogramTypes(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVmsPictogramsLibrary.getVmsGeneralCommandsPictogramTypes(parameters);
}
//
//
public InteropResponse setUserConfigurationVideo(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVideo.setUserConfigurationVideo(parameters);
}
public InteropResponse addCameraInformationPresetOfLoggedUsers(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVideo.addCameraInformationPresetOfLoggedUsers(parameters);
}
public InteropResponse deleteCameraInformationPresetOfLoggedUsers(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelVideo.deleteCameraInformationPresetOfLoggedUsers(parameters);
}
//
//
public InteropResponse getObjectsFolders(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelCrudObject.getObjectsFolders(parameters);
}
public InteropResponse getObjectsSummary(InteropParameters parameters) throws SerializationException
{
parameters.addParameter("summary", null);
return Shared.getModel().modelCrudObject.getObjects(parameters);
}
public InteropResponse getObjects(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelCrudObject.getObjects(parameters);
}
public InteropResponse addObject(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelCrudObject.addObject(parameters);
}
public InteropResponse addHistoricalObject(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelCrudObject.addHistoricalObject(parameters);
}
public InteropResponse removeObject(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelCrudObject.removeObject(parameters);
}
public InteropResponse renameObjectFolder(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelCrudObject.renameObjectFolder(parameters);
}
//
//
public InteropResponse listFiles (InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
try
{
String folderName = (String)parameters.getParameterValue("folder");
String folder = "data/" + Shared.getApplicationName() + "/";
if (folderName != null) folder = folder + folderName + "/";
File directory = new File(folder);
List lfiles = new ArrayList();
listFiles(directory, lfiles);
List lmodelfile = new ArrayList();
for (File file : lfiles)
{
try
{
if (file.isFile() == true)
{
ModelFile modelFile = new ModelFile();
modelFile.folder = file.getAbsolutePath().replace(directory.getAbsolutePath(), "").replace("\\", "/").replaceFirst("/", "").replaceAll(file.getName(), "");
if (folderName != null) modelFile.folder = modelFile.folder + "/" + folderName;
modelFile.name = file.getName().substring(0, file.getName().lastIndexOf('.'));
modelFile.extension = file.getName().substring(file.getName().lastIndexOf('.') + 1, file.getName().length());
if (modelFile.extension.equalsIgnoreCase("svg"))
{
modelFile.mime = "image/svg+xml";
}
else
{
MimeUtil2 mimeUtil = new MimeUtil2();
mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
modelFile.mime = MimeUtil2.getMostSpecificMimeType(mimeUtil.getMimeTypes(file)).toString();
}
lmodelfile.add(modelFile);
}
}
catch (Exception e)
{
}
}
InteropResponse response = new InteropResponse(lmodelfile.toArray(new ModelFile[lmodelfile.size()]));
return response;
}
catch (Exception e)
{
throw getException(language, e);
}
}
public InteropResponse getFile (InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
try
{
byte[] data = Resources.getExternalFileBytes(getFileName(parameters));
if (data.length == 0) data = Resources.getResourceBytes(getFileName(parameters));
InteropResponse response = new InteropResponse(data);
response.mime = "image/svg+xml";
return response;
}
catch (Exception e)
{
throw getException(language, e);
}
}
public InteropResponse addFile (InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
try
{
byte[] data = parameters.getParameterValue("body-content");
File file = new File(getFileName(parameters));
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.close();
return new InteropResponse(new Boolean(true));
}
catch (Exception e)
{
throw getException(language, e);
}
}
public InteropResponse removeFile (InteropParameters parameters) throws SerializationException
{
String language = (String)parameters.getParameterValue("language");
try
{
File file = new File(getFileName(parameters));
return new InteropResponse(new Boolean(file.delete()));
}
catch (Exception e)
{
throw getException(language, e);
}
}
private void listFiles (File directory, List lfile) throws SerializationException
{
for (File file : directory.listFiles())
{
if (file.isDirectory() == true)
{
listFiles(file, lfile);
}
else
{
lfile.add(file);
}
}
}
private String getFileName(InteropParameters parameters) throws Exception
{
String folderName = (String)parameters.getParameterValue("folder");
String fileName = (String)parameters.getParameterValue("name");
String fileExtension = (String)parameters.getParameterValue("extension");
String result = "data/" + Shared.getApplicationName() + "/";
if (folderName != null) result = result + "/" + folderName;
if (fileName != null) result = result + "/" + fileName;
if (fileExtension != null) result = result + "." + fileExtension;
return result.replace("\\","/").replace("//", "/");
}
//
public InteropResponse getDefaultRecordingPath(InteropParameters parameters) throws SerializationException
{
try
{
return new InteropResponse(Shared.getConfiguration().videoViewer.defaultRecordingPath);
}
catch (Exception e)
{
throw new SerializationException(Shared.getMessage("the default route could not be obtained"), e);
}
}
//
public InteropResponse getScheduledTasks(InteropParameters parameters) throws SerializationException
{
return Shared.getModel().modelCrudObject.getScheduledTasks(parameters);
}
public InteropResponse getScheduledProceduresManual(InteropParameters parameters) throws SerializationException
{
String language = parameters.hasParameter("language") ? (String) parameters.getParameterValue("language") : art.servers.Shared.getLanguage();
String computer = parameters.hasParameter("computer") ? (String) parameters.getParameterValue("computer") : "?";
long millis = System.currentTimeMillis();
try
{
// Search SceduledTask that must be executed at this moment and
// that contain a manual procedure (with decisions and not automatic actions)
// Shared.println("Listener " + computer, "Getting ScheduledTasks");
List
public InteropResponse getScheduledProceduresManualTest(InteropParameters parameters) throws SerializationException
{
String language = parameters.hasParameter("language") ? (String) parameters.getParameterValue("language") : art.servers.Shared.getLanguage();
try
{
// TODO David
// Buscar los ScheduledTask que han de ejecutarse en este momento y
// que contienen un procedure manual (con ifs o acciones no automaticas)
List lobject = Shared.controllerDatabase.getTimelessPersistance().get(0).getObject(ScheduledTask.class.getName());
List lresult = new ArrayList();
long timestamp = System.currentTimeMillis();
for (Object object : lobject)
{
ScheduledTask task = (ScheduledTask)object;
if (task.scheduledTask != null)
{
if ((task.scheduledTask.enabled == true) && (task.scheduledTask.procedure != null))
{
if (task.scheduledTask.procedure.isManual() == true)
{
lresult.add(task);
// if (task.scheduledTask.specificTimestamp > 0)
// {
// if ((timestamp <= task.scheduledTask.specificTimestamp) && (task.scheduledTask.specificTimestamp <= (timestamp + 30000L)))
// {
// if (task.scheduledTask.procedure.isManual() == true) lresult.add(task);
// }
// }
// else
// {
// timestamp = toScheduledTaskTimestamp(timestamp);
// if ((task.scheduledTask.weekly != null) && (task.scheduledTask.weekly.size() > 0))
// {
// /**
// * Specific time interval every day of week
// * Timestamp 0 : Monday, 00:00:00
// * Timestamp 86.400.000 : Tuesday, 00:00:00
// * Null if not used
// */
//
// for (ScheduledTaskProcedureInterval weekly : task.scheduledTask.weekly)
// {
// if ((weekly.from<=timestamp) && (timestamp<=weekly.to))
// {
// lresult.add(task);
// break;
// }
// }
// }
// else
// {
// ScheduledTaskProcedureInterval interval = null;
// if (task.scheduledTask.interval != null) interval = task.scheduledTask.interval;
// if (task.scheduledTask.monthly != null) interval = task.scheduledTask.monthly;
//
// if (interval != null)
// {
// if ((interval.from<=timestamp) && (timestamp<=interval.to))
// {
// lresult.add(task);
// break;
// }
// }
// }
// }
}
}
}
}
return new InteropResponse(lresult.toArray(new ScheduledTask[0]));
}
catch (SerializationException exception)
{
exception.printStackTrace();
throw exception;
}
catch (Exception exception)
{
exception.printStackTrace();
throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception);
}
}
private long toScheduledTaskTimestamp(long timestamp)
{
try
{
long sumvalue = 86400000;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp);
int weekday = calendar.get(Calendar.DAY_OF_WEEK);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int seconds = calendar.get(Calendar.SECOND);
int milliseconds = calendar.get(Calendar.MILLISECOND);
long day = 0;
if (weekday == Calendar.MONDAY)
day = 0;
if (weekday == Calendar.TUESDAY)
day = 1;
if (weekday == Calendar.WEDNESDAY)
day = 2;
if (weekday == Calendar.THURSDAY)
day = 3;
if (weekday == Calendar.FRIDAY)
day = 4;
if (weekday == Calendar.SATURDAY)
day = 5;
if (weekday == Calendar.SUNDAY)
day = 6;
long result = day * sumvalue;
result = result + (hour*60L*60000L) + (minutes*60000L) + (seconds*1000L) + milliseconds;
return(result);
}
catch (Exception e)
{
}
return(timestamp);
}
private long scheduledTaskTimestampToTimestamp(long from)
{
try
{
long sumvalue = 86400000;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
int weekday = calendar.get(Calendar.DAY_OF_WEEK);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int seconds = calendar.get(Calendar.SECOND);
int milliseconds = calendar.get(Calendar.MILLISECOND);
long day = 0;
if (weekday == Calendar.MONDAY)
day = 0;
if (weekday == Calendar.TUESDAY)
day = 1;
if (weekday == Calendar.WEDNESDAY)
day = 2;
if (weekday == Calendar.THURSDAY)
day = 3;
if (weekday == Calendar.FRIDAY)
day = 4;
if (weekday == Calendar.SATURDAY)
day = 5;
if (weekday == Calendar.SUNDAY)
day = 6;
int taskday = (int)(from / sumvalue);
if (taskday == day)
{
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(System.currentTimeMillis());
calendar2.set(Calendar.HOUR_OF_DAY, 0);
calendar2.set(Calendar.MINUTE, 0);
calendar2.set(Calendar.SECOND, 0);
calendar2.set(Calendar.MILLISECOND, 0);
calendar2.add(Calendar.MILLISECOND, (int)(from % sumvalue));
return(calendar2.getTimeInMillis());
}
}
catch (Exception e)
{
}
return(-1);
}
private List getActiveTrafficAlert() throws SerializationException
{
List lresult = new ArrayList();
try
{
// Shared.println("Listener", "Sending request active traffic alerts");
// Buscar los procedures de Segments que tienen la traffic alert activa
Application applicationSegment = Shared.getModel().getApplicationService("traveltime");
// Shared.println("Listener", "Sending request active traffic alerts: " + applicationSegment.getDeviceInformation().serverAddress + ":" + applicationSegment.getDeviceInformation().serverPort + ", " + applicationSegment.getDeviceInformation().serverServiceName);
InteropParameters parameters = new InteropParameters();
parameters.addParameter(new InteropParameter("service", applicationSegment.getDeviceInformation().serverServiceName));
parameters.addParameter(new InteropParameter("operation", "getTrafficAlertProcedures"));
parameters.addParameter(new InteropParameter("language", Shared.configuration.general.language));
// Shared.println("Listener", "Sending socket request active traffic alerts: " + applicationSegment.getDeviceInformation().serverAddress + ":" + applicationSegment.getDeviceInformation().serverPort + ", " + applicationSegment.getDeviceInformation().serverServiceName);
InteropResponse response = (InteropResponse)Serialization.invoke("get", parameters, applicationSegment.getDeviceInformation().serverAddress, applicationSegment.getDeviceInformation().serverPort, 30000);
TrafficAlertProcedure[] ltrafficAlertProcedures = Arrays.copyOf(response.getValue(), response.getValue().length, TrafficAlertProcedure[].class);
// Shared.println("Listener", "Received response active traffic alerts: " + applicationSegment.getDeviceInformation().serverAddress + ":" + applicationSegment.getDeviceInformation().serverPort + ", " + applicationSegment.getDeviceInformation().serverServiceName + " - " + ltrafficAlertProcedures.length);
for (TrafficAlertProcedure trafficAlertProcedure : ltrafficAlertProcedures)
{
try
{
ScheduledTask scheduledTask = new ScheduledTask();
scheduledTask.folder = "";
scheduledTask.name = "";
scheduledTask.description = "";
scheduledTask.scheduledTask = new ScheduledTaskProcedure();
scheduledTask.scheduledTask.procedure = trafficAlertProcedure.procedure;
scheduledTask.scheduledTask.specificTimestamp = trafficAlertProcedure.tsTrafficAlert;
lresult.add(scheduledTask);
}
catch (Exception e)
{
}
}
// Shared.println("Listener", "Returning active traffic alerts: " + applicationSegment.getDeviceInformation().serverAddress + ":" + applicationSegment.getDeviceInformation().serverPort + ", " + applicationSegment.getDeviceInformation().serverServiceName + " - " + lresult.size());
}
catch (Exception exception)
{
}
return (lresult);
}
private long getTimestampScheduledTask (ScheduledTask task, long currenttime) throws SerializationException
{
try
{
if (task.scheduledTask != null)
{
if ((task.scheduledTask.enabled == true) && (task.scheduledTask.procedure != null))
{
if (task.scheduledTask.specificTimestamp > 0)
{
return(task.scheduledTask.specificTimestamp);
}
else
{
if ((task.scheduledTask.weekly != null) && (task.scheduledTask.weekly.size() > 0))
{
long tsWeekly = -1;
for (ScheduledTaskProcedureInterval weekly : task.scheduledTask.weekly)
{
long ts = scheduledTaskTimestampToTimestamp(weekly.from);
if ((ts > 0) && (ts <= currenttime))
{
if (tsWeekly < 0)
{
tsWeekly = ts;
}
else if ((tsWeekly > 0) && (ts > tsWeekly))
{
// Coger el que se aproxime mas a la fecha actual (anterior)
tsWeekly = ts;
}
}
}
if (tsWeekly > 0) return(tsWeekly);
}
else if (task.scheduledTask.interval != null)
{
}
else if (task.scheduledTask.monthly != null)
{
}
}
}
}
}
catch (Exception exception)
{
}
return (System.currentTimeMillis());
}
}