Search in sources :

Example 1 with Settings

use of com.manydesigns.portofino.upstairs.Settings in project Portofino by ManyDesigns.

the class SettingsAction method update.

@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Form update(String jsonObject) {
    Form form = setupFormAndBean();
    FormUtil.readFromJson(form, new JSONObject(jsonObject));
    if (form.validate()) {
        logger.debug("Applying settings to model");
        try {
            Settings settings = new Settings();
            form.writeToObject(settings);
            ResourceAction action = (ResourceAction) getRoot();
            String[] loginPath = settings.loginPath.split("/");
            for (String loginPathSegment : loginPath) {
                Object subResource = action.getSubResource(loginPathSegment);
                if (!(subResource instanceof ResourceAction)) {
                    throw new WebApplicationException("Invalid login path");
                }
                action = (ResourceAction) subResource;
            }
            configuration.getProperties().setProperty(PortofinoProperties.APP_NAME, settings.appName);
            configuration.getProperties().setProperty(PortofinoProperties.APP_VERSION, settings.appVersion);
            configuration.getProperties().setProperty(PortofinoProperties.LOGIN_PATH, settings.loginPath);
            if (!settings.preloadGroovyPages || configuration.getProperties().getProperty(PortofinoProperties.PRELOAD_ACTIONS) != null) {
                configuration.getProperties().setProperty(PortofinoProperties.PRELOAD_ACTIONS, settings.preloadGroovyPages);
            }
            if (!settings.preloadGroovyClasses || configuration.getProperties().getProperty(PortofinoProperties.PRELOAD_CLASSES) != null) {
                configuration.getProperties().setProperty(PortofinoProperties.PRELOAD_CLASSES, settings.preloadGroovyClasses);
            }
            configuration.save();
            return form;
        } catch (Exception e) {
            logger.error("Configuration not saved", e);
            throw new WebApplicationException("Configuration not saved", e);
        }
    } else {
        throw new WebApplicationException(Response.serverError().entity(form).build());
    }
}
Also used : JSONObject(org.json.JSONObject) Form(com.manydesigns.elements.forms.Form) JSONObject(org.json.JSONObject) Settings(com.manydesigns.portofino.upstairs.Settings) AbstractResourceAction(com.manydesigns.portofino.resourceactions.AbstractResourceAction) ResourceAction(com.manydesigns.portofino.resourceactions.ResourceAction)

Example 2 with Settings

use of com.manydesigns.portofino.upstairs.Settings in project Portofino by ManyDesigns.

the class SettingsAction method setupFormAndBean.

protected Form setupFormAndBean() {
    Settings settings = new Settings();
    settings.appName = configuration.getProperties().getString(PortofinoProperties.APP_NAME);
    settings.appVersion = configuration.getProperties().getString(PortofinoProperties.APP_VERSION);
    settings.loginPath = configuration.getProperties().getString(PortofinoProperties.LOGIN_PATH);
    settings.preloadGroovyPages = configuration.getProperties().getBoolean(PortofinoProperties.PRELOAD_ACTIONS, false);
    settings.preloadGroovyClasses = configuration.getProperties().getBoolean(PortofinoProperties.PRELOAD_CLASSES, false);
    Form form = new FormBuilder(Settings.class).build();
    form.readFromObject(settings);
    return form;
}
Also used : FormBuilder(com.manydesigns.elements.forms.FormBuilder) Form(com.manydesigns.elements.forms.Form) Settings(com.manydesigns.portofino.upstairs.Settings)

Aggregations

Form (com.manydesigns.elements.forms.Form)2 Settings (com.manydesigns.portofino.upstairs.Settings)2 FormBuilder (com.manydesigns.elements.forms.FormBuilder)1 AbstractResourceAction (com.manydesigns.portofino.resourceactions.AbstractResourceAction)1 ResourceAction (com.manydesigns.portofino.resourceactions.ResourceAction)1 JSONObject (org.json.JSONObject)1