protected boolean fillData1D(List<Object[]> result, JSONArray data) { for (Object[] current : result) { if(current.length < 2) { SessionMessages.addErrorMessage("The query returned the wrong number of parameters (" + current.length + ") - 2 are required."); return false; } JSONObject datum = new JSONObject(); datum.put("label", ObjectUtils.toString(current[0])); datum.put("value", current[1]); data.put(datum); } return true; }
/** * Utility method to save the configuration object to a file in this page's directory. * @param configuration the object to save. It must be in a state that will produce a valid XML document. * @return true if the object was correctly saved, false otherwise. */ protected boolean saveConfiguration(Object configuration) { try { File confFile = DispatcherLogic.saveConfiguration(pageInstance.getDirectory(), configuration); logger.info("Configuration saved to " + confFile.getAbsolutePath()); return true; } catch (Exception e) { logger.error("Couldn't save configuration", e); SessionMessages.addErrorMessage("error saving conf"); return false; } }
@Button(list = "page-create", key = "create.new", order = 1, type = Button.TYPE_PRIMARY) public Resolution createPage() { try { return doCreateNewPage(); } catch (Exception e) { logger.error("Error creating page", e); String msg = ElementsThreadLocals.getText("error.creating.page._", e.getMessage()); SessionMessages.addErrorMessage(msg); return new ForwardResolution("/m/admin/page/new-page.jsp"); } }
/** * Utility method to save the configuration object to a file in this page's directory. * @param configuration the object to save. It must be in a state that will produce a valid XML document. * @return true if the object was correctly saved, false otherwise. */ protected boolean saveConfiguration(Object configuration) { try { FileObject confFile = PageLogic.saveConfiguration(pageInstance.getDirectory(), configuration); logger.info("Configuration saved to " + confFile.getName().getPath()); return true; } catch (Exception e) { logger.error("Couldn't save configuration", e); SessionMessages.addErrorMessage("error saving conf"); return false; } }
public Resolution afterCreateConnectionProvider() { try { configureEditSchemas(); } catch (Exception e) { logger.error("Couldn't read schema names from db", e); SessionMessages.addErrorMessage(ElementsThreadLocals.getText("couldnt.read.schema.names.from.db._", e)); return createConnectionProviderForm(); } return selectSchemasForm(); }
@Button(key = "delete", list="table-selection-provider", order = 2) @Guard(test = "getSelectionProviderName() != null", type = GuardType.VISIBLE) public Resolution removeSelectionProvider() { table = findTable(); ModelSelectionProvider sp = DatabaseLogic.findSelectionProviderByName(table, selectionProviderName); table.getSelectionProviders().remove(sp); try { saveModel(); } catch (Exception e) { logger.error("Could not save model", e); SessionMessages.addErrorMessage(e.toString()); } return editTable(); }
protected void updateModelFailed(Exception e) { logger.error("Could not update model", e); SessionMessages.addErrorMessage( ElementsThreadLocals.getText("could.not.save.model._", ExceptionUtils.getRootCauseMessage(e))); if(isNewConnectionProvider()) { persistence.getModel().getDatabases().remove(connectionProvider.getDatabase()); } persistence.initModel(); }
@Button(list = "connectionProviders-read", key = "delete", order = 6 , type = Button.TYPE_DANGER, icon = Button.ICON_TRASH ) public Resolution delete() { String[] databaseNames = new String[] {databaseName}; try { doDelete(databaseNames); persistence.initModel(); persistence.saveXmlModel(); } catch (Exception e) { String msg = "Cannot save model: " + ExceptionUtils.getRootCauseMessage(e); logger.error(msg, e); SessionMessages.addErrorMessage(msg); } return new RedirectResolution(this.getClass()); }
public Resolution confirmSignUp() { Subject subject = SecurityUtils.getSubject(); if (subject.getPrincipal() != null) { logger.debug("Already logged in"); return redirectToReturnUrl(); } SignUpToken token = new SignUpToken(this.token); try { subject.login(token); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("user.created")); return redirectToReturnUrl(); } catch (AuthenticationException e) { String errMsg = ElementsThreadLocals.getText("the.sign.up.confirmation.link.is.no.longer.active"); SessionMessages.addErrorMessage(errMsg); logger.warn(errMsg, e); return signUp(); } }
@Button(list = "pageHeaderButtons", titleKey = "edit", order = 2, icon = Button.ICON_EDIT, group = "pageHeaderButtons") @RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT }) @RequiresAuthentication public Resolution configure() { title = pageInstance.getPage().getTitle(); description = pageInstance.getPage().getDescription(); try { loadContent(); logger.debug("Edit content: {}", textFile.getAbsolutePath()); } catch (IOException e) { logger.error("Could not load content", e); SessionMessages.addErrorMessage("Could not load content: " + e); } return new ForwardResolution("/m/pageactions/text/edit-content.jsp"); }
@Button(list = "connectionProviders-read", key = "synchronize", order = 4 , type = Button.TYPE_PRIMARY, icon = Button.ICON_RELOAD ) public Resolution sync() { try { persistence.syncDataModel(databaseName); persistence.initModel(); persistence.saveXmlModel(); SessionMessages.addInfoMessage( "Connection provider synchronized correctly"); } catch (Exception e) { logger.error("Errore in sincronizzazione", e); SessionMessages.addErrorMessage( "Synchronization error: " + ExceptionUtils.getRootCauseMessage(e)); } return new RedirectResolution(getClass()) .addParameter("databaseName", databaseName); }
protected void setupChildPages() { File directory = getPageInstance().getDirectory(); childPagesForm = setupChildPagesForm(childPages, directory, getPage().getLayout(), ""); if(PageActionLogic.supportsDetail(getPageInstance().getActionClass())) { File detailDirectory = new File(directory, PageInstance.DETAIL); if(!detailDirectory.isDirectory() && !ElementsFileUtils.safeMkdir(detailDirectory)) { logger.error("Could not create detail directory{}", detailDirectory.getAbsolutePath()); SessionMessages.addErrorMessage("Could not create detail directory"); return; } detailChildPagesForm = setupChildPagesForm(detailChildPages, detailDirectory, getPage().getDetailLayout(), "detail"); } }
@Button(list = "connectionProviders-search", key = "delete", order = 2 , type = Button.TYPE_DANGER, icon = Button.ICON_TRASH ) public Resolution bulkDelete() { if(null!=selection && 0!=selection.length){ try { doDelete(selection); persistence.initModel(); persistence.saveXmlModel(); } catch (Exception e) { String msg = "Cannot save model: " + ExceptionUtils.getRootCauseMessage(e); logger.error(msg, e); SessionMessages.addErrorMessage(msg); } } else { SessionMessages.addInfoMessage(ElementsThreadLocals.getText("no.connection.providers.selected")); } return new RedirectResolution(this.getClass()); }
public Resolution copyPage() { buildCopyPageForm(); copyForm.readFromRequest(context.getRequest()); if(copyForm.validate()) { CopyPage p = new CopyPage(); copyForm.writeToObject(p); return copyPage(p.destinationPagePath, p.fragment, false); } else { Field field = (Field) copyForm.get(0).get(0); if(!field.getErrors().isEmpty()) { SessionMessages.addErrorMessage(field.getLabel() + ": " + field.getErrors().get(0)); } field = (Field) copyForm.get(0).get(1); if(!field.getErrors().isEmpty()) { SessionMessages.addErrorMessage(field.getLabel() + ": " + field.getErrors().get(0)); } return new RedirectResolution(originalPath); } }
@Button(list = "connectionProviders-read", key = "test", order = 3 , type = Button.TYPE_WARNING , icon = Button.ICON_FLASH ) public Resolution test() { connectionProvider = persistence.getConnectionProvider(databaseName); connectionProvider.init(persistence.getDatabasePlatformsRegistry()); String status = connectionProvider.getStatus(); if (ConnectionProvider.STATUS_CONNECTED.equals(status)) { SessionMessages.addInfoMessage(ElementsThreadLocals.getText("connection.tested.successfully")); } else { SessionMessages.addErrorMessage( ElementsThreadLocals.getText( "connection.failed.status._.error.message._", status, connectionProvider.getErrorMessage())); } return new RedirectResolution(this.getClass()) .addParameter("databaseName", databaseName); }
public Resolution movePage() { buildMovePageForm(); moveForm.readFromRequest(context.getRequest()); if(moveForm.validate()) { MovePage p = new MovePage(); moveForm.writeToObject(p); return copyPage(p.destinationPagePath, null, true); } else { Field field = (Field) moveForm.get(0).get(0); if(!field.getErrors().isEmpty()) { SessionMessages.addErrorMessage(field.getLabel() + ": " + field.getErrors().get(0)); } return new RedirectResolution(originalPath); } }
@Button(list = "manage-attachments-upload", key = "text.attachment.upload", order = 1 , icon=Button.ICON_UPLOAD ) @RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT }) @RequiresAuthentication public Resolution uploadAttachment() { if (upload == null) { SessionMessages.addWarningMessage(ElementsThreadLocals.getText("text.attachment.noFileSelected")); } else { try { commonUploadAttachment(); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("text.attachment.uploadSuccessful")); } catch (IOException e) { logger.error("Upload failed", e); SessionMessages.addErrorMessage(ElementsThreadLocals.getText("text.attachment.uploadFailed")); } } return new RedirectResolution(context.getActionPath()) .addParameter("manageAttachments") .addParameter("returnUrl", returnUrl); }
@Button(list = "crud-read", key = "delete", order = 2, icon = Button.ICON_TRASH) @RequiresPermissions(permissions = PERMISSION_DELETE) @Guard(test = "isDeleteEnabled()", type = GuardType.VISIBLE) public Resolution delete() { if(deleteValidate(object)) { try { doDelete(object); deletePostProcess(object); commitTransaction(); deleteBlobs(object); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("object.deleted.successfully")); } catch (Exception e) { String rootCauseMessage = ExceptionUtils.getRootCauseMessage(e); logger.debug(rootCauseMessage, e); SessionMessages.addErrorMessage(rootCauseMessage); return read(); } } return getSuccessfulDeleteView(); }
@Button(list = "configuration", key = "update.configuration", type = Button.TYPE_PRIMARY) @RequiresPermissions(level = AccessLevel.DEVELOP) public Resolution updateConfiguration() { prepareConfigurationForms(); readPageConfigurationFromRequest(); configurationForm.readFromRequest(context.getRequest()); boolean valid = validatePageConfiguration(); valid = valid && configurationForm.validate(); if(valid) { updatePageConfiguration(); configurationForm.writeToObject(pageInstance.getConfiguration()); saveConfiguration(pageInstance.getConfiguration()); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully")); return cancel(); } else { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved")); return new ForwardResolution("/m/gallery/configure.jsp"); } }
@Button(list = "configuration", key = "update.configuration", type = Button.TYPE_PRIMARY) @RequiresPermissions(level = AccessLevel.DEVELOP) public Resolution updateConfiguration() { prepareConfigurationForms(); readPageConfigurationFromRequest(); configurationForm.readFromRequest(context.getRequest()); boolean valid = validatePageConfiguration(); valid = valid && configurationForm.validate(); if(valid) { updatePageConfiguration(); configurationForm.writeToObject(pageInstance.getConfiguration()); saveConfiguration(pageInstance.getConfiguration()); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully")); return cancel(); } else { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved")); return new ForwardResolution("/m/calendar/configure.jsp"); } }