use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class ParameterDAO method readByKey.
@Override
public AnswerItem readByKey(String system, String param) {
AnswerItem<Parameter> ans = new AnswerItem<>();
MessageEvent msg = null;
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(Query.READ_BY_KEY)) {
// Prepare and execute query
preStat.setString(1, system);
preStat.setString(2, param);
try (ResultSet resultSet = preStat.executeQuery()) {
while (resultSet.next()) {
ans.setItem(loadFromResultSet(resultSet));
}
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
}
} catch (Exception e) {
LOG.warn("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
// We always set the result message
ans.setResultMessage(msg);
}
return ans;
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class ApplicationObjectDAO method readImageByKey.
@Override
public BufferedImage readImageByKey(String application, String object) {
BufferedImage image = null;
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", "cerberus_applicationobject_path Parameter not found");
AnswerItem a = parameterService.readByKey("", "cerberus_applicationobject_path");
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
Parameter p = (Parameter) a.getItem();
String uploadPath = p.getValue();
a = readByKey(application, object);
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
ApplicationObject ao = (ApplicationObject) a.getItem();
if (ao != null) {
File picture = new File(uploadPath + File.separator + ao.getID() + File.separator + ao.getScreenShotFileName());
try {
image = ImageIO.read(picture);
} catch (IOException e) {
LOG.warn("Impossible to read the image");
}
}
} else {
LOG.warn("Application Object not found");
}
} else {
LOG.warn("cerberus_applicationobject_path Parameter not found");
}
a.setResultMessage(msg);
return image;
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class ApplicationObjectDAO method uploadFile.
@Override
public Answer uploadFile(int id, FileItem file) {
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", "cerberus_applicationobject_path Parameter not found");
AnswerItem a = parameterService.readByKey("", "cerberus_applicationobject_path");
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
Parameter p = (Parameter) a.getItem();
String uploadPath = p.getValue();
File appDir = new File(uploadPath + File.separator + id);
if (!appDir.exists()) {
try {
appDir.mkdirs();
} catch (SecurityException se) {
LOG.warn("Unable to create application dir: " + se.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", se.toString());
a.setResultMessage(msg);
}
}
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
deleteFolder(appDir, false);
File picture = new File(uploadPath + File.separator + id + File.separator + file.getName());
try {
file.write(picture);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION", "Application Object file uploaded");
msg.setDescription(msg.getDescription().replace("%ITEM%", "Application Object").replace("%OPERATION%", "Upload"));
} catch (Exception e) {
LOG.warn("Unable to upload application object file: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
}
}
} else {
LOG.warn("cerberus_applicationobject_path Parameter not found");
}
a.setResultMessage(msg);
return a;
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class ParameterService method findParameterByKey.
@Override
public Parameter findParameterByKey(String key, String system) throws CerberusException {
Parameter myParameter;
/**
* We try to get the parameter using the system parameter but if it does
* not exist or empty, we get it with system="" which correspond to the
* default global Cerberus Parameter.
*/
try {
LOG.debug("Trying to retrieve parameter : " + key + " - [" + system + "]");
myParameter = parameterDao.findParameterByKey(system, key);
if (myParameter != null && myParameter.getValue().equalsIgnoreCase("")) {
myParameter = parameterDao.findParameterByKey("", key);
}
} catch (CerberusException ex) {
LOG.debug("Trying to retrieve parameter (default value) : " + key + " - []");
myParameter = parameterDao.findParameterByKey("", key);
return myParameter;
}
return myParameter;
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class ParameterService method getParameterLongByKey.
@Override
public long getParameterLongByKey(String key, String system, long defaultValue) {
Parameter myParameter;
long outPutResult = defaultValue;
try {
myParameter = this.findParameterByKey(key, system);
outPutResult = Long.parseLong(myParameter.getValue());
} catch (CerberusException | NumberFormatException ex) {
LOG.error("Error when trying to retreive parameter : '" + key + "' for system : '" + system + "'. Default value returned : '" + defaultValue + "'. Trace : " + ex);
}
LOG.debug("Success loading parameter : '" + key + "' for system : '" + system + "'. Value returned : '" + outPutResult + "'");
return outPutResult;
}
Aggregations