Search in sources :

Example 1 with SettingDAO

use of fi.otavanopisto.pyramus.dao.system.SettingDAO 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;
}
Also used : SettingKeyDAO(fi.otavanopisto.pyramus.dao.system.SettingKeyDAO) SettingDAO(fi.otavanopisto.pyramus.dao.system.SettingDAO) Setting(fi.otavanopisto.pyramus.domainmodel.system.Setting) SettingKey(fi.otavanopisto.pyramus.domainmodel.system.SettingKey)

Example 2 with SettingDAO

use of fi.otavanopisto.pyramus.dao.system.SettingDAO 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;
}
Also used : SettingKeyDAO(fi.otavanopisto.pyramus.dao.system.SettingKeyDAO) SettingDAO(fi.otavanopisto.pyramus.dao.system.SettingDAO) Setting(fi.otavanopisto.pyramus.domainmodel.system.Setting) SettingKey(fi.otavanopisto.pyramus.domainmodel.system.SettingKey)

Example 3 with SettingDAO

use of fi.otavanopisto.pyramus.dao.system.SettingDAO in project pyramus by otavanopisto.

the class GoogleOauthAuthorizationStrategy method getClientSecret.

private String getClientSecret() {
    SettingDAO settingDAO = DAOFactory.getInstance().getSettingDAO();
    SettingKeyDAO settingKeyDAO = DAOFactory.getInstance().getSettingKeyDAO();
    return settingDAO.findByKey(settingKeyDAO.findByName("google.oauth.clientsecret")).getValue();
}
Also used : SettingKeyDAO(fi.otavanopisto.pyramus.dao.system.SettingKeyDAO) SettingDAO(fi.otavanopisto.pyramus.dao.system.SettingDAO)

Example 4 with SettingDAO

use of fi.otavanopisto.pyramus.dao.system.SettingDAO 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");
}
Also used : SettingKeyDAO(fi.otavanopisto.pyramus.dao.system.SettingKeyDAO) HashMap(java.util.HashMap) SettingDAO(fi.otavanopisto.pyramus.dao.system.SettingDAO) Setting(fi.otavanopisto.pyramus.domainmodel.system.Setting) SettingKey(fi.otavanopisto.pyramus.domainmodel.system.SettingKey)

Example 5 with SettingDAO

use of fi.otavanopisto.pyramus.dao.system.SettingDAO 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");
    }
}
Also used : SettingKeyDAO(fi.otavanopisto.pyramus.dao.system.SettingKeyDAO) SettingDAO(fi.otavanopisto.pyramus.dao.system.SettingDAO) Setting(fi.otavanopisto.pyramus.domainmodel.system.Setting) SettingKey(fi.otavanopisto.pyramus.domainmodel.system.SettingKey) IOException(java.io.IOException) File(java.io.File)

Aggregations

SettingDAO (fi.otavanopisto.pyramus.dao.system.SettingDAO)19 SettingKeyDAO (fi.otavanopisto.pyramus.dao.system.SettingKeyDAO)18 Setting (fi.otavanopisto.pyramus.domainmodel.system.Setting)16 SettingKey (fi.otavanopisto.pyramus.domainmodel.system.SettingKey)16 File (java.io.File)2 IOException (java.io.IOException)2 ApplicationDAO (fi.otavanopisto.pyramus.dao.application.ApplicationDAO)1 Application (fi.otavanopisto.pyramus.domainmodel.application.Application)1 Email (fi.otavanopisto.pyramus.domainmodel.base.Email)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1