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());
}
}
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;
}
Aggregations