Search in sources :

Example 1 with Setting

use of fi.otavanopisto.pyramus.domainmodel.system.Setting 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 Setting

use of fi.otavanopisto.pyramus.domainmodel.system.Setting 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 Setting

use of fi.otavanopisto.pyramus.domainmodel.system.Setting 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 4 with Setting

use of fi.otavanopisto.pyramus.domainmodel.system.Setting 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)

Example 5 with Setting

use of fi.otavanopisto.pyramus.domainmodel.system.Setting 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);
    }
}
Also used : Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Setting(fi.otavanopisto.pyramus.domainmodel.system.Setting) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ApplicationDAO(fi.otavanopisto.pyramus.dao.application.ApplicationDAO) URI(java.net.URI) SettingKeyDAO(fi.otavanopisto.pyramus.dao.system.SettingKeyDAO) SettingDAO(fi.otavanopisto.pyramus.dao.system.SettingDAO) SettingKey(fi.otavanopisto.pyramus.domainmodel.system.SettingKey) File(java.io.File) Application(fi.otavanopisto.pyramus.domainmodel.application.Application)

Aggregations

Setting (fi.otavanopisto.pyramus.domainmodel.system.Setting)18 SettingDAO (fi.otavanopisto.pyramus.dao.system.SettingDAO)16 SettingKey (fi.otavanopisto.pyramus.domainmodel.system.SettingKey)16 SettingKeyDAO (fi.otavanopisto.pyramus.dao.system.SettingKeyDAO)15 File (java.io.File)2 IOException (java.io.IOException)2 EntityManager (javax.persistence.EntityManager)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 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1