use of fi.otavanopisto.pyramus.domainmodel.system.SettingKey in project pyramus by otavanopisto.
the class Mailer method getSetting.
private static String getSetting(String settingName) {
SettingDAO settingDAO = DAOFactory.getInstance().getSettingDAO();
SettingKeyDAO settingKeyDAO = DAOFactory.getInstance().getSettingKeyDAO();
SettingKey key = settingKeyDAO.findByName(settingName);
if (key != null) {
Setting setting = settingDAO.findByKey(key);
if (setting != null) {
return setting.getValue();
}
}
return null;
}
use of fi.otavanopisto.pyramus.domainmodel.system.SettingKey in project pyramus by otavanopisto.
the class MuikkuPluginTools method getMuikkuHost.
public static String getMuikkuHost() {
SettingKeyDAO settingKeyDAO = DAOFactory.getInstance().getSettingKeyDAO();
SettingDAO settingDAO = DAOFactory.getInstance().getSettingDAO();
SettingKey key = settingKeyDAO.findByName("muikkuplugin.muikkuhost");
if (key != null) {
Setting setting = settingDAO.findByKey(key);
if (setting != null) {
return setting.getValue();
}
}
return null;
}
use of fi.otavanopisto.pyramus.domainmodel.system.SettingKey in project pyramus by otavanopisto.
the class SystemSettingsViewController method processForm.
@Override
public void processForm(PageRequestContext requestContext) {
SettingDAO settingDAO = DAOFactory.getInstance().getSettingDAO();
SettingKeyDAO settingKeyDAO = DAOFactory.getInstance().getSettingKeyDAO();
Map<String, String> settings = new HashMap<>();
List<SettingKey> settingKeys = settingKeyDAO.listAll();
for (SettingKey settingKey : settingKeys) {
Setting setting = settingDAO.findByKey(settingKey);
if (setting != null)
settings.put(settingKey.getName(), setting.getValue());
}
requestContext.getRequest().setAttribute("settingKeys", settingKeys);
requestContext.getRequest().setAttribute("settings", settings);
requestContext.setIncludeJSP("/templates/system/systemsettings.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.system.SettingKey in project pyramus by otavanopisto.
the class CreateApplicationViewController method process.
public void process(PageRequestContext pageRequestContext) {
try {
SettingKeyDAO settingKeyDAO = DAOFactory.getInstance().getSettingKeyDAO();
SettingKey settingKey = settingKeyDAO.findByName("applications.storagePath");
if (settingKey == null) {
logger.log(Level.SEVERE, "SettingKey for applications.storagePath not found");
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
SettingDAO settingDAO = DAOFactory.getInstance().getSettingDAO();
Setting setting = settingDAO.findByKey(settingKey);
if (setting == null || setting.getValue() == null) {
logger.log(Level.SEVERE, "Setting applications.storagePath not defined");
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
File attachmentsFolder = Paths.get(setting.getValue()).toFile();
if (!attachmentsFolder.exists() || !attachmentsFolder.isDirectory() || !attachmentsFolder.canWrite()) {
logger.log(Level.SEVERE, "Setting applications.storagePath refers to a non-existing or non-writable folder");
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to serve 404 for applications.storagePath", e);
return;
}
String line = pageRequestContext.getString("line");
if (!StringUtils.isBlank(line) && ApplicationUtils.isValidLine(line)) {
pageRequestContext.getRequest().setAttribute("preselectLine", line);
pageRequestContext.getRequest().setAttribute("applicationId", UUID.randomUUID().toString());
pageRequestContext.getRequest().setAttribute("preload", Boolean.FALSE);
pageRequestContext.getRequest().setAttribute("donePage", Boolean.TRUE);
pageRequestContext.getRequest().setAttribute("saveUrl", "/1/applications/saveapplication");
pageRequestContext.setIncludeJSP("/templates/applications/application-edit.jsp");
} else {
pageRequestContext.setRedirectURL(pageRequestContext.getRequest().getContextPath() + "/applications/index.page");
}
}
use of fi.otavanopisto.pyramus.domainmodel.system.SettingKey in project pyramus by otavanopisto.
the class EditApplicationViewController method process.
public void process(PageRequestContext pageRequestContext) {
String applicationId = pageRequestContext.getRequest().getParameter("applicationId");
try {
if (applicationId != null) {
boolean validEntry = false;
String referer = pageRequestContext.getRequest().getHeader("Referer");
if (referer != null) {
try {
URI requestUri = new URI(pageRequestContext.getRequest().getRequestURL().toString());
URI refererUri = new URI(pageRequestContext.getRequest().getHeader("Referer"));
validEntry = StringUtils.equals(requestUri.getHost(), refererUri.getHost()) && StringUtils.equals(requestUri.getPath(), refererUri.getPath());
} catch (URISyntaxException e) {
}
}
if (!validEntry) {
logger.warning(String.format("Refused application edit. Application id %s from referer %s", applicationId, referer));
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
}
// Ensure attachment storage path has been properly set
SettingKeyDAO settingKeyDAO = DAOFactory.getInstance().getSettingKeyDAO();
SettingKey settingKey = settingKeyDAO.findByName("applications.storagePath");
if (settingKey == null) {
logger.log(Level.SEVERE, "SettingKey for applications.storagePath not found");
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
SettingDAO settingDAO = DAOFactory.getInstance().getSettingDAO();
Setting setting = settingDAO.findByKey(settingKey);
if (setting == null || setting.getValue() == null) {
logger.log(Level.SEVERE, "Setting applications.storagePath not defined");
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
File attachmentsFolder = Paths.get(setting.getValue()).toFile();
if (!attachmentsFolder.exists() || !attachmentsFolder.isDirectory() || !attachmentsFolder.canWrite()) {
logger.log(Level.SEVERE, "Setting applications.storagePath refers to a non-existing or non-writable folder");
pageRequestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (applicationId == null) {
pageRequestContext.setIncludeJSP("/templates/applications/application-edit-gateway.jsp");
} else {
// Find application by applicationId and pass form data to page
ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
Application application = applicationDAO.findByApplicationId(applicationId);
if (application == null || application.getArchived()) {
pageRequestContext.getRequest().setAttribute("notFound", Boolean.TRUE);
pageRequestContext.setIncludeJSP("/templates/applications/application-edit-gateway.jsp");
} else if (Boolean.FALSE.equals(application.getApplicantEditable())) {
pageRequestContext.getRequest().setAttribute("locked", Boolean.TRUE);
if (application.getHandler() != null) {
pageRequestContext.getRequest().setAttribute("handlerName", application.getHandler().getFullName());
Email email = application.getHandler().getPrimaryEmail();
if (email != null && email.getAddress() != null) {
pageRequestContext.getRequest().setAttribute("handlerEmail", email.getAddress());
}
}
pageRequestContext.setIncludeJSP("/templates/applications/application-edit-gateway.jsp");
} else {
pageRequestContext.getRequest().setAttribute("applicationId", applicationId);
pageRequestContext.getRequest().setAttribute("referenceCode", application.getReferenceCode());
pageRequestContext.getRequest().setAttribute("preload", Boolean.TRUE);
pageRequestContext.getRequest().setAttribute("donePage", Boolean.TRUE);
pageRequestContext.getRequest().setAttribute("saveUrl", "/1/applications/saveapplication");
pageRequestContext.setIncludeJSP("/templates/applications/application-edit.jsp");
}
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to serve error response", e);
}
}
Aggregations