Author: tchemit Date: 2011-11-13 17:20:45 +0100 (Sun, 13 Nov 2011) New Revision: 51 Url: http://forge.codelutin.com/repositories/revision/echobase/51 Log: remove json package Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractJSONPaginedAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSql.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/GetUsers.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java Removed: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ConnectToDbInformations.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlQueryToFile.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadExportSqlMainPage.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadSqlQueryInGrid.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageSqlQuery.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/AbstractJSONPaginedAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetEntities.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetSqlResult.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetUsers.java trunk/echobase-ui/src/main/resources/config/struts-json.xml Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/interceptors/CheckLogguedInterceptor.java trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml trunk/echobase-ui/src/main/resources/config/struts-export.xml trunk/echobase-ui/src/main/resources/config/struts-import.xml trunk/echobase-ui/src/main/resources/config/struts-user.xml trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties trunk/echobase-ui/src/main/resources/struts.xml trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/connectToDbInformations.jsp trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportGrid.jsp trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/modificationLogs.jsp trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/user/userList.jsp Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractJSONPaginedAction.java (from rev 35, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/AbstractJSONPaginedAction.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractJSONPaginedAction.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractJSONPaginedAction.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,125 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions; + +import fr.ifremer.echobase.services.Pager; +import org.apache.commons.lang.StringUtils; +import org.apache.struts2.json.JSONException; +import org.apache.struts2.json.JSONUtil; + +/** + * Abstract JSON action with pagination support. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public abstract class AbstractJSONPaginedAction extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + public abstract Integer getRows(); + + public abstract Integer getPage(); + + public abstract Integer getTotal(); + + public abstract Integer getRecords(); + + protected Pager pager = new Pager(); + + // sorting order - asc or desc + protected String sord; + + // get index row - i.e. user click to sort. + protected String sidx; + + protected String filters; + + /** Prefix added to the sidx when used. */ + protected final String sidx_prefix; + + protected AbstractJSONPaginedAction(String sidx_prefix) { + this.sidx_prefix = sidx_prefix; + } + + public void setRows(Integer rows) { + pager.setPageSize(rows); + } + + public void setPage(Integer page) { + pager.setPageNumber(page); + } + + public String getSord() { + return sord; + } + + public void setSord(String sord) { + this.sord = sord; + } + + public String getSidx() { + return sidx; + } + + public void setSidx(String sidx) { + this.sidx = sidx; + } + + public String getFilters() { + return filters; + } + + public void setFilters(String filters) { + this.filters = filters; + } + + protected String getSortColumn() { + String result = null; + if (useSort()) { + result = sidx.substring(sidx_prefix.length()); + } + return result; + } + + protected Boolean isSortAscendant() { + Boolean result = null; + if (useSort()) { + result = "asc".equals(sord); + } + return result; + } + + protected boolean useSort() { + return StringUtils.isNotEmpty(sidx); + } + + protected Object getFilterObject() throws JSONException { + Object filterObject = null; + if (StringUtils.isNotEmpty(filters)) { + filterObject = JSONUtil.deserialize(filters); + } + return filterObject; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractJSONPaginedAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ConnectToDbInformations.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ConnectToDbInformations.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ConnectToDbInformations.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,61 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions; - -import fr.ifremer.echobase.EchoBaseConfiguration; -import org.nuiton.topia.TopiaContextFactory; - -import java.util.Properties; - -/** - * Display a page to show connection details. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class ConnectToDbInformations extends EchoBaseActionSupport { - private static final long serialVersionUID = 1L; - - protected String jdbcUrl; - - protected String jdbcLogin; - - public String getJdbcUrl() { - return jdbcUrl; - } - - public String getJdbcLogin() { - return jdbcLogin; - } - - @Override - public String execute() throws Exception { - EchoBaseConfiguration configuration = - getEchoBaseApplicationContext().getConfiguration(); - Properties properties = configuration.getProperties(); - jdbcUrl = properties.getProperty(TopiaContextFactory.CONFIG_URL); - jdbcLogin = properties.getProperty(TopiaContextFactory.CONFIG_USER); - return SUCCESS; - } -} Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/HomeAction.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,44 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions; - - -/** - * To go to the home page. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class HomeAction extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - @Override - public String execute() throws Exception { - - - return SUCCESS; - } - -} Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,134 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions; - -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.interceptor.I18nInterceptor; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.services.UserService; -import fr.ifremer.echobase.ui.EchoBaseSession; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts2.interceptor.SessionAware; - -import java.util.Locale; -import java.util.Map; - -/** - * Login and Logout action. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class LoginAction extends EchoBaseActionSupport implements SessionAware { - - protected static final Log log = LogFactory.getLog(LoginAction.class); - - private static final long serialVersionUID = 1L; - - protected String email; - - protected String password; - - protected String redirectAction; - - private transient Map<String, Object> session; - - protected transient UserService userService; - - public UserService getUserService() { - if (userService == null) { - userService = newService(UserService.class); - } - return userService; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getRedirectAction() { - return redirectAction; - } - - public void setRedirectAction(String redirectAction) { - this.redirectAction = redirectAction; - } - - public String doLogin() throws Exception { - - EchoBaseUser user = getUserService().getUserByEmail(email); - - EchoBaseSession userSession = getEchoBaseSession(); - - // user is authorized, keep it in his echoBaseSession - userSession.setEchoBaseUser(user); - - // add locale in echoBaseSession if required - Object o = session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE); - if (o == null) { - - // push the locale in echoBaseSession to be able to use it everywhere - Locale locale = ActionContext.getContext().getLocale(); - session.put(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, locale); - } - - // redecode parameters - if (log.isInfoEnabled()) { - log.info("success login for user " + email + - ", will redirect to " + redirectAction); - } - return "redirect"; - } - - public String doLogout() { - - EchoBaseSession userSession = getEchoBaseSession(); - - // remove user from session - userSession.setEchoBaseUser(null); - - // remove echoBaseSession from application session - ActionContext.getContext().getSession().remove(SESSION_PARAMETER); - - return SUCCESS; - } - - @Override - public void setSession(Map<String, Object> session) { - this.session = session; - } -} Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,185 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions; - -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserDTO; -import fr.ifremer.echobase.entities.EchoBaseUserDTOImpl; -import fr.ifremer.echobase.services.UserService; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Action to manage user (create - update - change password,...) - * - * @author sletellier <letellier@codelutin.com> - * @since 0.1 - */ -public class UserAction extends EchoBaseActionSupport implements Preparable { - - protected static final Log log = LogFactory.getLog(UserAction.class); - - private static final long serialVersionUID = 1L; - - public static final String BACK_TO_LIST = "backToList"; - - protected transient UserService service; - - protected EchoBaseUserDTO user; - - protected String userEditAction; - - public String getUserEditAction() { - return userEditAction; - } - - public void setUserEditAction(String userEditAction) { - this.userEditAction = userEditAction; - } - - protected UserService getUserService() { - if (service == null) { - service = newService(UserService.class); - } - return service; - } - - @Override - public void prepare() throws Exception { - - String userId = getUser().getId(); - if (!StringUtils.isEmpty(userId)) { - - // load user - user = getUserService().getUserById(userId).toDTO(); - - log.info("Selected user " + user.getEmail()); - } - } - - public String doCreateOrUpdate() throws Exception { - EchoBaseUserDTO user = getUser(); - String userEmail = user.getEmail(); - - if (log.isInfoEnabled()) { - log.info("will create user " + userEmail); - } - - // create user - getUserService().createOrUpdate(user); - return BACK_TO_LIST; - } - - public String doDelete() throws Exception { - EchoBaseUserDTO user = getUser(); - String userEmail = user.getEmail(); - - if (log.isInfoEnabled()) { - log.info("will delete user " + userEmail); - } - getUserService().delete(user); - return BACK_TO_LIST; - } - - @Override - public void validate() { - - EditActionEnum action = getEditActionEnum(); - - log.info("Edit action : " + action); - - if (action == null) { - - // no validation (no edit action) - return; - } - - EchoBaseUserDTO user = getUser(); - String userEmail = user.getEmail(); - - switch (action) { - - case CREATE: - - // login + password required - if (StringUtils.isEmpty(userEmail)) { - - // empty user login - addFieldError("user.email", - _("echobase.error.required.email")); - } else { - - // check login not already used - EchoBaseUser login; - try { - login = getUserService().getUserByEmail(userEmail); - } catch (Exception e) { - - // could not get user - throw new IllegalStateException( - "Could not obtain user " + userEmail, e); - } - if (login != null) { - addFieldError("user.email", - _("echobase.error.email.already.used")); - } - } - - String userPassword = user.getPassword(); - if (StringUtils.isEmpty(userPassword)) { - - // empty user password - addFieldError("user.password", - _("echobase.error.required.password")); - } - - break; - case EDIT: - - // at the moment nothing to validate - break; - case DELETE: - - // Do nothing - default: - // nothing to validate - } - } - - public EchoBaseUserDTO getUser() { - if (user == null) { - user = new EchoBaseUserDTOImpl(); - } - return user; - } - - protected EditActionEnum getEditActionEnum() { - if (userEditAction == null) { - return null; - } - return EditActionEnum.valueOf(userEditAction); - } -} Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java (from rev 49, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetEntities.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,121 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.dbeditor; + +import fr.ifremer.echobase.entities.EntityModificationLogImpl; +import fr.ifremer.echobase.services.DbEditorService; +import fr.ifremer.echobase.ui.actions.AbstractJSONPaginedAction; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Map; + +/** + * To obtain the data for the given request. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class GetEntities extends AbstractJSONPaginedAction { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(GetEntities.class); + + /** Name of the table to load. */ + protected String tableName; + + /** Datas of the given table. */ + protected Map<?, ?>[] datas; + + public GetEntities() { + super("datas_"); + } + + public Map<?, ?>[] getDatas() { + return datas; + } + + @Override + public Integer getRows() { + return pager.getPageSize(); + } + + @Override + public Integer getPage() { + return pager.getPageNumber(); + } + + @Override + public Integer getTotal() { + return pager.getPageCount(); + } + + @Override + public Integer getRecords() { + return pager.getRecords(); + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + @Override + public String execute() throws Exception { + + Boolean ascendantOrder = isSortAscendant(); + String sortColumn = getSortColumn(); + Object filterObject = getFilterObject(); + + if (log.isDebugEnabled()) { + log.debug("filters = " + getFilters()); + log.debug("filterObject = " + filterObject); + log.debug("sidx = " + sortColumn); + log.debug("sord = " + ascendantOrder); + } + + DbEditorService dbEditorService = newService(DbEditorService.class); + + datas = dbEditorService.getDatas( + tableName, + pager, + sortColumn, + ascendantOrder + ); + + if (log.isDebugEnabled()) { + log.debug("Total page = " + getTotal()); + } + + return SUCCESS; + } + + + public String entityModificationLogs() throws Exception { + tableName = EntityModificationLogImpl.class.getName(); + execute(); + return SUCCESS; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java 2011-11-13 16:20:45 UTC (rev 51) @@ -73,7 +73,7 @@ } @Override - public String input() throws Exception { + public String execute() throws Exception { tableNames = Maps.newTreeMap(); DbMeta dbMeta = getEchoBaseApplicationContext().getDbMeta(); for (TableMeta tableMeta : dbMeta) { @@ -91,7 +91,7 @@ DbEditorService dbEditorService = newService(DbEditorService.class); tableMeta = dbEditorService.getTableMetas(tableName); } - return INPUT; + return SUCCESS; } public String getEditType(ColumnMeta meta) { Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java 2011-11-13 16:20:45 UTC (rev 51) @@ -55,8 +55,6 @@ protected Map<String, String[]> params; - protected transient DbEditorService dbEditorService; - public void setTableName(String tableName) { this.tableName = tableName; } Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java (from rev 49, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlQueryToFile.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,96 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.export; + +import fr.ifremer.echobase.services.ExportSqlService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +/** + * To export sql to a csv file. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class DownloadExportSqlResult extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + /** Sql request to execute. */ + protected String sql; + + /** Input stream of the file to download. */ + protected transient InputStream inputStream; + + /** File name of the download. */ + protected String fileName; + + /** Length of the file to download. */ + protected int contentLength; + + /** Content type of the file to download. */ + protected String contentType; + + public void setSql(String sql) { + this.sql = sql; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public InputStream getInputStream() { + return inputStream; + } + + public String getFileName() { + return fileName; + } + + public int getContentLength() { + return contentLength; + } + + public String getContentType() { + return contentType; + } + + @Override + public String execute() throws Exception { + + ExportSqlService service = newService(ExportSqlService.class); + + contentType = "text/csv"; + String content = service.createCsvStream( + sql, + getEchoBaseSession().getEchoBaseUser() + ); + contentLength = content.length(); + inputStream = new ByteArrayInputStream(content.getBytes()); + + return SUCCESS; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSql.java (from rev 49, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadExportSqlMainPage.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSql.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSql.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,92 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.export; + +import fr.ifremer.echobase.entities.ExportQuery; +import fr.ifremer.echobase.entities.ExportQueryImpl; +import fr.ifremer.echobase.services.ExportSqlService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import org.apache.commons.lang.StringUtils; + +import java.util.Collection; +import java.util.Map; + +/** + * Load export sql main page. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class ExportSql extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + /** All available queries from database. */ + protected Map<String, String> queries; + + /** Selected query loaded from database if his id is not empty. */ + protected ExportQuery query; + + public ExportQuery getQuery() { + if (query == null) { + query = new ExportQueryImpl(); + } + return query; + } + + public Map<String, String> getQueries() { + return queries; + } + + public Map<String, String> getTableNames() { + return queries; + } + + @Override + public String execute() throws Exception { + ExportSqlService service = newService(ExportSqlService.class); + + Collection<ExportQuery> sqlQueries = service.getQueries(); + queries = sortAndDecorate(sqlQueries, null); + + if (sqlQueries.isEmpty()) { + // no query saved + addActionMessage(_("echobase.info.no.sqlQuery.saved")); + } + + String selectedQueryId = getQuery().getTopiaId(); + + if (StringUtils.isEmpty(selectedQueryId)) { + + // no query selected + addActionMessage(_("echobase.info.no.sqlQuery.selected")); + } else { + + // load query from database + query = service.getQuery(selectedQueryId); + } + return SUCCESS; + } + +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSql.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlQueryToFile.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlQueryToFile.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlQueryToFile.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,96 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.export; - -import fr.ifremer.echobase.services.ExportSqlService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -/** - * To export sql to a csv file. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class ExportSqlQueryToFile extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - /** Sql request to execute. */ - protected String sql; - - /** Input stream of the file to download. */ - protected transient InputStream inputStream; - - /** File name of the download. */ - protected String fileName; - - /** Length of the file to download. */ - protected int contentLength; - - /** Content type of the file to download. */ - protected String contentType; - - public void setSql(String sql) { - this.sql = sql; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public InputStream getInputStream() { - return inputStream; - } - - public String getFileName() { - return fileName; - } - - public int getContentLength() { - return contentLength; - } - - public String getContentType() { - return contentType; - } - - @Override - public String execute() throws Exception { - - ExportSqlService service = newService(ExportSqlService.class); - - contentType = "text/csv"; - String content = service.createCsvStream( - sql, - getEchoBaseSession().getEchoBaseUser() - ); - contentLength = content.length(); - inputStream = new ByteArrayInputStream(content.getBytes()); - - return SUCCESS; - } -} Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java (from rev 49, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadSqlQueryInGrid.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,76 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.export; + +import fr.ifremer.echobase.services.ExportSqlService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; + +/** + * Load export sql result fragment page. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class ExportSqlResult extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + /** Sql request to execute. */ + protected String sql; + + /** Default file name for export. */ + protected String fileName; + + /** names of columns from the executed sql request. */ + protected String[] columnNames; + + public String getSql() { + return sql; + } + + public String[] getColumnNames() { + return columnNames; + } + + public String getFileName() { + return fileName; + } + + public void setSql(String sql) { + this.sql = sql; + } + + @Override + public String execute() throws Exception { + + // obtain columNames from the request + ExportSqlService service = newService(ExportSqlService.class); + columnNames = service.getColumnNames(sql); + + // create default file name + + fileName = "export.csv"; + return SUCCESS; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java (from rev 47, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetSqlResult.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,86 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.export; + +import fr.ifremer.echobase.services.ExportSqlService; +import fr.ifremer.echobase.ui.actions.AbstractJSONPaginedAction; + +import java.util.Map; + +/** + * Obtains result of a sql query. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class GetSqlResult extends AbstractJSONPaginedAction { + + private static final long serialVersionUID = 1L; + + /** Sql request to execute. */ + protected String sql; + + /** Datas of the given table. */ + protected Map<?, ?>[] datas; + + public GetSqlResult() { + super("datas_"); + } + + public void setSql(String sql) { + this.sql = sql; + } + + public Map<?, ?>[] getDatas() { + return datas; + } + + @Override + public Integer getRows() { + return pager.getPageSize(); + } + + @Override + public Integer getPage() { + return pager.getPageNumber(); + } + + @Override + public Integer getTotal() { + return pager.getPageCount(); + } + + @Override + public Integer getRecords() { + return pager.getRecords(); + } + + @Override + public String execute() throws Exception { + + ExportSqlService service = newService(ExportSqlService.class); + datas = service.executeSql(sql, pager); + return SUCCESS; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadExportSqlMainPage.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadExportSqlMainPage.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadExportSqlMainPage.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,92 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.export; - -import fr.ifremer.echobase.entities.ExportQuery; -import fr.ifremer.echobase.entities.ExportQueryImpl; -import fr.ifremer.echobase.services.ExportSqlService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; -import org.apache.commons.lang.StringUtils; - -import java.util.Collection; -import java.util.Map; - -/** - * Load export sql main page. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class LoadExportSqlMainPage extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - /** All available queries from database. */ - protected Map<String, String> queries; - - /** Selected query loaded from database if his id is not empty. */ - protected ExportQuery query; - - public ExportQuery getQuery() { - if (query == null) { - query = new ExportQueryImpl(); - } - return query; - } - - public Map<String, String> getQueries() { - return queries; - } - - public Map<String, String> getTableNames() { - return queries; - } - - @Override - public String execute() throws Exception { - ExportSqlService service = newService(ExportSqlService.class); - - Collection<ExportQuery> sqlQueries = service.getQueries(); - queries = sortAndDecorate(sqlQueries, null); - - if (sqlQueries.isEmpty()) { - // no query saved - addActionMessage(_("echobase.info.no.sqlQuery.saved")); - } - - String selectedQueryId = getQuery().getTopiaId(); - - if (StringUtils.isEmpty(selectedQueryId)) { - - // no query selected - addActionMessage(_("echobase.info.no.sqlQuery.selected")); - } else { - - // load query from database - query = service.getQuery(selectedQueryId); - } - return SUCCESS; - } - -} Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadSqlQueryInGrid.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadSqlQueryInGrid.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/LoadSqlQueryInGrid.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,76 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.export; - -import fr.ifremer.echobase.services.ExportSqlService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; - -/** - * Load export sql grid page. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class LoadSqlQueryInGrid extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - /** Sql request to execute. */ - protected String sql; - - /** Default file name for export. */ - protected String fileName; - - /** names of columns from the executed sql request. */ - protected String[] columnNames; - - public String getSql() { - return sql; - } - - public String[] getColumnNames() { - return columnNames; - } - - public String getFileName() { - return fileName; - } - - public void setSql(String sql) { - this.sql = sql; - } - - @Override - public String execute() throws Exception { - - // obtain columNames from the request - ExportSqlService service = newService(ExportSqlService.class); - columnNames = service.getColumnNames(sql); - - // create default file name - - fileName = "export.csv"; - return SUCCESS; - } -} Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java (from rev 49, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageSqlQuery.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,82 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.export; + +import fr.ifremer.echobase.entities.ExportQuery; +import fr.ifremer.echobase.entities.ExportQueryImpl; +import fr.ifremer.echobase.services.ExportSqlService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; + +/** + * To manage {@link ExportQuery}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class ManageExportQuery extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + /** Selected query */ + protected ExportQuery query; + + public ExportQuery getQuery() { + if (query == null) { + query = new ExportQueryImpl(); + } + return query; + } + + public String saveQuery() throws Exception { + + //TODO : do validation + ExportSqlService service = newService(ExportSqlService.class); + + query = service.createOrUpdate(getQuery(), + getEchoBaseSession().getEchoBaseUser() + ); + return SUCCESS; + } + + public String cloneQuery() throws Exception { + + //TODO : do validation + ExportSqlService service = newService(ExportSqlService.class); + + getQuery().setTopiaId(null); + query = service.createOrUpdate(getQuery(), + getEchoBaseSession().getEchoBaseUser() + ); + return SUCCESS; + } + + public String deleteQuery() throws Exception { + + //TODO : do validation + ExportSqlService service = newService(ExportSqlService.class); + service.delete(getQuery().getTopiaId()); + query = null; + return SUCCESS; + } +} \ No newline at end of file Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageSqlQuery.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageSqlQuery.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageSqlQuery.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,82 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.export; - -import fr.ifremer.echobase.entities.ExportQuery; -import fr.ifremer.echobase.entities.ExportQueryImpl; -import fr.ifremer.echobase.services.ExportSqlService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; - -/** - * To manage {@link ExportQuery}. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class ManageSqlQuery extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - /** Selected query */ - protected ExportQuery query; - - public ExportQuery getQuery() { - if (query == null) { - query = new ExportQueryImpl(); - } - return query; - } - - public String saveQuery() throws Exception { - - //TODO : do validation - ExportSqlService service = newService(ExportSqlService.class); - - query = service.createOrUpdate(getQuery(), - getEchoBaseSession().getEchoBaseUser() - ); - return SUCCESS; - } - - public String cloneQuery() throws Exception { - - //TODO : do validation - ExportSqlService service = newService(ExportSqlService.class); - - getQuery().setTopiaId(null); - query = service.createOrUpdate(getQuery(), - getEchoBaseSession().getEchoBaseUser() - ); - return SUCCESS; - } - - public String deleteQuery() throws Exception { - - //TODO : do validation - ExportSqlService service = newService(ExportSqlService.class); - service.delete(getQuery().getTopiaId()); - query = null; - return SUCCESS; - } -} \ No newline at end of file Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/AbstractJSONPaginedAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/AbstractJSONPaginedAction.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/AbstractJSONPaginedAction.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,126 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.json; - -import fr.ifremer.echobase.services.Pager; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; -import org.apache.commons.lang.StringUtils; -import org.apache.struts2.json.JSONException; -import org.apache.struts2.json.JSONUtil; - -/** - * Abstract JSON action with pagination support. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public abstract class AbstractJSONPaginedAction extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - public abstract Integer getRows(); - - public abstract Integer getPage(); - - public abstract Integer getTotal(); - - public abstract Integer getRecords(); - - protected Pager pager = new Pager(); - - // sorting order - asc or desc - protected String sord; - - // get index row - i.e. user click to sort. - protected String sidx; - - protected String filters; - - /** Prefix added to the sidx when used. */ - protected final String sidx_prefix; - - protected AbstractJSONPaginedAction(String sidx_prefix) { - this.sidx_prefix = sidx_prefix; - } - - public void setRows(Integer rows) { - pager.setPageSize(rows); - } - - public void setPage(Integer page) { - pager.setPageNumber(page); - } - - public String getSord() { - return sord; - } - - public void setSord(String sord) { - this.sord = sord; - } - - public String getSidx() { - return sidx; - } - - public void setSidx(String sidx) { - this.sidx = sidx; - } - - public String getFilters() { - return filters; - } - - public void setFilters(String filters) { - this.filters = filters; - } - - protected String getSortColumn() { - String result = null; - if (useSort()) { - result = sidx.substring(sidx_prefix.length()); - } - return result; - } - - protected Boolean isSortAscendant() { - Boolean result = null; - if (useSort()) { - result = "asc".equals(sord); - } - return result; - } - - protected boolean useSort() { - return StringUtils.isNotEmpty(sidx); - } - - protected Object getFilterObject() throws JSONException { - Object filterObject = null; - if (StringUtils.isNotEmpty(filters)) { - filterObject = JSONUtil.deserialize(filters); - } - return filterObject; - } -} Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetEntities.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetEntities.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetEntities.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,120 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.json; - -import fr.ifremer.echobase.entities.EntityModificationLogImpl; -import fr.ifremer.echobase.services.DbEditorService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.util.Map; - -/** - * To obtain the data for the given request. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class GetEntities extends AbstractJSONPaginedAction { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(GetEntities.class); - - /** Name of the table to load. */ - protected String tableName; - - /** Datas of the given table. */ - protected Map<?, ?>[] datas; - - public GetEntities() { - super("datas_"); - } - - public Map<?, ?>[] getDatas() { - return datas; - } - - @Override - public Integer getRows() { - return pager.getPageSize(); - } - - @Override - public Integer getPage() { - return pager.getPageNumber(); - } - - @Override - public Integer getTotal() { - return pager.getPageCount(); - } - - @Override - public Integer getRecords() { - return pager.getRecords(); - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - @Override - public String execute() throws Exception { - - Boolean ascendantOrder = isSortAscendant(); - String sortColumn = getSortColumn(); - Object filterObject = getFilterObject(); - - if (log.isDebugEnabled()) { - log.debug("filters = " + getFilters()); - log.debug("filterObject = " + filterObject); - log.debug("sidx = " + sortColumn); - log.debug("sord = " + ascendantOrder); - } - - DbEditorService dbEditorService = newService(DbEditorService.class); - - datas = dbEditorService.getDatas( - tableName, - pager, - sortColumn, - ascendantOrder - ); - - if (log.isDebugEnabled()) { - log.debug("Total page = " + getTotal()); - } - - return SUCCESS; - } - - - public String entityModificationLogs() throws Exception { - tableName = EntityModificationLogImpl.class.getName(); - execute(); - return SUCCESS; - } -} Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetSqlResult.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetSqlResult.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetSqlResult.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,85 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.json; - -import fr.ifremer.echobase.services.ExportSqlService; - -import java.util.Map; - -/** - * To get a export sql DTO. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class GetSqlResult extends AbstractJSONPaginedAction { - - private static final long serialVersionUID = 1L; - - /** Sql request to execute. */ - protected String sql; - - /** Datas of the given table. */ - protected Map<?, ?>[] datas; - - public GetSqlResult() { - super("datas_"); - } - - public void setSql(String sql) { - this.sql = sql; - } - - public Map<?, ?>[] getDatas() { - return datas; - } - - @Override - public Integer getRows() { - return pager.getPageSize(); - } - - @Override - public Integer getPage() { - return pager.getPageNumber(); - } - - @Override - public Integer getTotal() { - return pager.getPageCount(); - } - - @Override - public Integer getRecords() { - return pager.getRecords(); - } - - @Override - public String execute() throws Exception { - - ExportSqlService service = newService(ExportSqlService.class); - datas = service.executeSql(sql, pager); - return SUCCESS; - } -} Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetUsers.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetUsers.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetUsers.java 2011-11-13 16:20:45 UTC (rev 51) @@ -1,87 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui.actions.json; - -import com.google.common.collect.Lists; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserDTO; -import fr.ifremer.echobase.services.UserService; - -import java.util.List; - -/** - * Obtains all users of the echobase internal database. - * - * @author sletellier <letellier@codelutin.com> - * @since 0.1 - */ -public class GetUsers extends AbstractJSONPaginedAction { - - private static final long serialVersionUID = 1L; - - protected List<EchoBaseUserDTO> users; - - public GetUsers() { - super("users_"); - } - - public List<EchoBaseUserDTO> getUsers() { - return users; - } - - @Override - public Integer getRows() { - return pager.getPageSize(); - } - - @Override - public Integer getPage() { - return pager.getPageNumber(); - } - - @Override - public Integer getTotal() { - return pager.getPageCount(); - } - - @Override - public Integer getRecords() { - return pager.getRecords(); - } - - @Override - public String execute() throws Exception { - - List<EchoBaseUser> allUsers = - newService(UserService.class).getUsers(pager); - - users = Lists.newArrayList(); - for (EchoBaseUser user : allUsers) { - users.add(user.toDTO()); - } - - return SUCCESS; - } - -} Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java (from rev 49, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ConnectToDbInformations.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,81 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.user; + +import fr.ifremer.echobase.EchoBaseConfiguration; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import org.nuiton.topia.TopiaContextFactory; + +import java.util.Properties; + +/** + * Display a page to show connection details. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class ConnectToDbInformations extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + protected String jdbcUrl; + + protected String jdbcLogin; + + protected String jdbcPassword; + + protected boolean askPassword; + + public String getJdbcUrl() { + return jdbcUrl; + } + + public String getJdbcLogin() { + return jdbcLogin; + } + + public String getJdbcPassword() { + return jdbcPassword; + } + + public boolean isAskPassword() { + return askPassword; + } + + @Override + public String execute() throws Exception { + EchoBaseConfiguration configuration = + getEchoBaseApplicationContext().getConfiguration(); + Properties properties = configuration.getProperties(); + if (configuration.isEmbedded()) { + jdbcPassword = properties.getProperty(TopiaContextFactory.CONFIG_PASS); + } else { + askPassword = true; + jdbcPassword = "***"; + } + jdbcUrl = properties.getProperty(TopiaContextFactory.CONFIG_URL); + jdbcLogin = properties.getProperty(TopiaContextFactory.CONFIG_USER); + return SUCCESS; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/GetUsers.java (from rev 45, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/json/GetUsers.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/GetUsers.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/GetUsers.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,88 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.user; + +import com.google.common.collect.Lists; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.EchoBaseUserDTO; +import fr.ifremer.echobase.services.UserService; +import fr.ifremer.echobase.ui.actions.AbstractJSONPaginedAction; + +import java.util.List; + +/** + * Obtains all users of the echobase internal database. + * + * @author sletellier <letellier@codelutin.com> + * @since 0.1 + */ +public class GetUsers extends AbstractJSONPaginedAction { + + private static final long serialVersionUID = 1L; + + protected List<EchoBaseUserDTO> users; + + public GetUsers() { + super("users_"); + } + + public List<EchoBaseUserDTO> getUsers() { + return users; + } + + @Override + public Integer getRows() { + return pager.getPageSize(); + } + + @Override + public Integer getPage() { + return pager.getPageNumber(); + } + + @Override + public Integer getTotal() { + return pager.getPageCount(); + } + + @Override + public Integer getRecords() { + return pager.getRecords(); + } + + @Override + public String execute() throws Exception { + + List<EchoBaseUser> allUsers = + newService(UserService.class).getUsers(pager); + + users = Lists.newArrayList(); + for (EchoBaseUser user : allUsers) { + users.add(user.toDTO()); + } + + return SUCCESS; + } + +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/GetUsers.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java (from rev 35, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/LoginAction.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,135 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.user; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.interceptor.I18nInterceptor; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.services.UserService; +import fr.ifremer.echobase.ui.EchoBaseSession; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.interceptor.SessionAware; + +import java.util.Locale; +import java.util.Map; + +/** + * Login and Logout action. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class LoginAction extends EchoBaseActionSupport implements SessionAware { + + protected static final Log log = LogFactory.getLog(LoginAction.class); + + private static final long serialVersionUID = 1L; + + protected String email; + + protected String password; + + protected String redirectAction; + + private transient Map<String, Object> session; + + protected transient UserService userService; + + public UserService getUserService() { + if (userService == null) { + userService = newService(UserService.class); + } + return userService; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRedirectAction() { + return redirectAction; + } + + public void setRedirectAction(String redirectAction) { + this.redirectAction = redirectAction; + } + + public String doLogin() throws Exception { + + EchoBaseUser user = getUserService().getUserByEmail(email); + + EchoBaseSession userSession = getEchoBaseSession(); + + // user is authorized, keep it in his echoBaseSession + userSession.setEchoBaseUser(user); + + // add locale in echoBaseSession if required + Object o = session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE); + if (o == null) { + + // push the locale in echoBaseSession to be able to use it everywhere + Locale locale = ActionContext.getContext().getLocale(); + session.put(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, locale); + } + + // redecode parameters + if (log.isInfoEnabled()) { + log.info("success login for user " + email + + ", will redirect to " + redirectAction); + } + return "redirect"; + } + + public String doLogout() { + + EchoBaseSession userSession = getEchoBaseSession(); + + // remove user from session + userSession.setEchoBaseUser(null); + + // remove echoBaseSession from application session + ActionContext.getContext().getSession().remove(SESSION_PARAMETER); + + return SUCCESS; + } + + @Override + public void setSession(Map<String, Object> session) { + this.session = session; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java (from rev 35, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/UserAction.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java 2011-11-13 16:20:45 UTC (rev 51) @@ -0,0 +1,187 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui.actions.user; + +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.EchoBaseUserDTO; +import fr.ifremer.echobase.entities.EchoBaseUserDTOImpl; +import fr.ifremer.echobase.services.UserService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import fr.ifremer.echobase.ui.actions.EditActionEnum; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Action to manage user (create - update - change password,...) + * + * @author sletellier <letellier@codelutin.com> + * @since 0.1 + */ +public class ManageUser extends EchoBaseActionSupport implements Preparable { + + protected static final Log log = LogFactory.getLog(ManageUser.class); + + private static final long serialVersionUID = 1L; + + public static final String BACK_TO_LIST = "backToList"; + + protected transient UserService service; + + protected EchoBaseUserDTO user; + + protected String userEditAction; + + public String getUserEditAction() { + return userEditAction; + } + + public void setUserEditAction(String userEditAction) { + this.userEditAction = userEditAction; + } + + protected UserService getUserService() { + if (service == null) { + service = newService(UserService.class); + } + return service; + } + + @Override + public void prepare() throws Exception { + + String userId = getUser().getId(); + if (!StringUtils.isEmpty(userId)) { + + // load user + user = getUserService().getUserById(userId).toDTO(); + + log.info("Selected user " + user.getEmail()); + } + } + + public String doCreateOrUpdate() throws Exception { + EchoBaseUserDTO user = getUser(); + String userEmail = user.getEmail(); + + if (log.isInfoEnabled()) { + log.info("will create user " + userEmail); + } + + // create user + getUserService().createOrUpdate(user); + return BACK_TO_LIST; + } + + public String doDelete() throws Exception { + EchoBaseUserDTO user = getUser(); + String userEmail = user.getEmail(); + + if (log.isInfoEnabled()) { + log.info("will delete user " + userEmail); + } + getUserService().delete(user); + return BACK_TO_LIST; + } + + @Override + public void validate() { + + EditActionEnum action = getEditActionEnum(); + + log.info("Edit action : " + action); + + if (action == null) { + + // no validation (no edit action) + return; + } + + EchoBaseUserDTO user = getUser(); + String userEmail = user.getEmail(); + + switch (action) { + + case CREATE: + + // login + password required + if (StringUtils.isEmpty(userEmail)) { + + // empty user login + addFieldError("user.email", + _("echobase.error.required.email")); + } else { + + // check login not already used + EchoBaseUser login; + try { + login = getUserService().getUserByEmail(userEmail); + } catch (Exception e) { + + // could not get user + throw new IllegalStateException( + "Could not obtain user " + userEmail, e); + } + if (login != null) { + addFieldError("user.email", + _("echobase.error.email.already.used")); + } + } + + String userPassword = user.getPassword(); + if (StringUtils.isEmpty(userPassword)) { + + // empty user password + addFieldError("user.password", + _("echobase.error.required.password")); + } + + break; + case EDIT: + + // at the moment nothing to validate + break; + case DELETE: + + // Do nothing + default: + // nothing to validate + } + } + + public EchoBaseUserDTO getUser() { + if (user == null) { + user = new EchoBaseUserDTOImpl(); + } + return user; + } + + protected EditActionEnum getEditActionEnum() { + if (userEditAction == null) { + return null; + } + return EditActionEnum.valueOf(userEditAction); + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/interceptors/CheckLogguedInterceptor.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/interceptors/CheckLogguedInterceptor.java 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/interceptors/CheckLogguedInterceptor.java 2011-11-13 16:20:45 UTC (rev 51) @@ -26,7 +26,7 @@ import com.opensymphony.xwork2.ActionInvocation; import fr.ifremer.echobase.ui.EchoBaseSession; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; -import fr.ifremer.echobase.ui.actions.LoginAction; +import fr.ifremer.echobase.ui.actions.user.LoginAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml 2011-11-13 16:20:45 UTC (rev 51) @@ -31,21 +31,27 @@ <package name="dbeditor" extends="loggued" namespace="/dbeditor"> - <action name="dbeditor" method="input" + <!-- load db editor main page --> + <action name="dbeditor" class="fr.ifremer.echobase.ui.actions.dbeditor.LoadEntities"> - <interceptor-ref name="basicStackLoggued"/> - <result name="input">/WEB-INF/jsp/dbeditor/dbeditor.jsp</result> + <result>/WEB-INF/jsp/dbeditor/dbeditor.jsp</result> </action> + <!-- get foreign entities as a select box --> <action name="getForeignEntities" class="fr.ifremer.echobase.ui.actions.dbeditor.GetForeignEntities"> - <interceptor-ref name="basicStackLoggued"/> <result>/WEB-INF/jsp/dbeditor/foreignEntities.jsp</result> </action> + <!-- Get datas of the selected table --> + <action name="getTableDatas" + class="fr.ifremer.echobase.ui.actions.dbeditor.GetEntities"> + <result type="json"/> + </action> + + <!-- save the modified entity (no result as a grid json edit action)--> <action name="editTableData" class="fr.ifremer.echobase.ui.actions.dbeditor.SaveEntity"> - <interceptor-ref name="basicStackLoggued"/> </action> </package> Modified: trunk/echobase-ui/src/main/resources/config/struts-export.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-export.xml 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/resources/config/struts-export.xml 2011-11-13 16:20:45 UTC (rev 51) @@ -40,35 +40,45 @@ </result-type> </result-types> - <default-interceptor-ref name="basicStackLoggued"/> - + <!-- Display export sql main page --> <action name="exportSql" - class="fr.ifremer.echobase.ui.actions.export.LoadExportSqlMainPage"> + class="fr.ifremer.echobase.ui.actions.export.ExportSql"> <result>/WEB-INF/jsp/export/export.jsp</result> </action> + <!-- Display the result of the sql query execution --> <action name="loadResult" - class="fr.ifremer.echobase.ui.actions.export.LoadSqlQueryInGrid"> + class="fr.ifremer.echobase.ui.actions.export.ExportSqlResult"> <result>/WEB-INF/jsp/export/exportGrid.jsp</result> </action> - + + <!-- Get result of the sql query execution --> + <action name="getExportSqlResult" method="execute" + class="fr.ifremer.echobase.ui.actions.export.GetSqlResult"> + <result type="json"/> + </action> + + <!-- Clone the sql query --> <action name="cloneQuery" method="cloneQuery" - class="fr.ifremer.echobase.ui.actions.export.ManageSqlQuery"> + class="fr.ifremer.echobase.ui.actions.export.ManageExportQuery"> <result type="redirectToMainPage"/> </action> + <!-- Save the sql query --> <action name="saveQuery" method="saveQuery" - class="fr.ifremer.echobase.ui.actions.export.ManageSqlQuery"> + class="fr.ifremer.echobase.ui.actions.export.ManageExportQuery"> <result type="redirectToMainPage"/> </action> + <!-- Delete the sql query --> <action name="deleteQuery" method="deleteQuery" - class="fr.ifremer.echobase.ui.actions.export.ManageSqlQuery"> + class="fr.ifremer.echobase.ui.actions.export.ManageExportQuery"> <result type="redirectToMainPage"/> </action> + <!-- Download the sql query csb file --> <action name="downloadExport" - class="fr.ifremer.echobase.ui.actions.export.ExportSqlQueryToFile"> + class="fr.ifremer.echobase.ui.actions.export.DownloadExportSqlResult"> <result type="stream"> <param name="contentType">${contentType}</param> <param name="contentLength">${contentLength}</param> Modified: trunk/echobase-ui/src/main/resources/config/struts-import.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-import.xml 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/resources/config/struts-import.xml 2011-11-13 16:20:45 UTC (rev 51) @@ -33,15 +33,16 @@ <package name="import" extends="loggued" namespace="/import"> <!-- Display import page --> - <action name="import" class="fr.ifremer.echobase.ui.actions.ImportAction" method="input"> - <interceptor-ref name="basicStackLoggued"/> + <action name="import" class="fr.ifremer.echobase.ui.actions.ImportAction" + method="input"> <result name="input">/WEB-INF/jsp/import/import.jsp</result> - <result name="success" type="redirectAction">doImport</result> + <result type="redirectAction">doImport</result> </action> <!-- Display import page --> <action name="doImport" class="fr.ifremer.echobase.ui.actions.ImportAction"> <interceptor-ref name="paramsPrepareParamsStackLoggued"/> + <result name="wait">/WEB-INF/jsp/import/importProgress.jsp</result> <result>/WEB-INF/jsp/import/importProgress.jsp</result> </action> Deleted: trunk/echobase-ui/src/main/resources/config/struts-json.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-json.xml 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/resources/config/struts-json.xml 2011-11-13 16:20:45 UTC (rev 51) @@ -1,60 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - #%L - EchoBase :: UI - - $Id$ - $HeadURL$ - %% - Copyright (C) 2011 Ifremer, Codelutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - #L% - --> - -<!DOCTYPE struts PUBLIC - "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" - "http://struts.apache.org/dtds/struts-2.1.7.dtd"> - -<struts> - - <package name="json" extends="loggued" namespace="/json"> - - <default-interceptor-ref name="basicStackLoggued"/> - - <action name="getUsers" - class="fr.ifremer.echobase.ui.actions.json.GetUsers"> - <!--interceptor-ref name="basicStackLoggued"/> - <interceptor-ref name="checkUserIsAdmin"/--> - <result type="json"/> - </action> - - <action name="getExportSqlResult" method="execute" - class="fr.ifremer.echobase.ui.actions.json.GetSqlResult"> - <result type="json"/> - </action> - - <action name="getTableDatas" - class="fr.ifremer.echobase.ui.actions.json.GetEntities"> - <result type="json"/> - </action> - <action name="getEntityModificationLogs" method="entityModificationLogs" - class="fr.ifremer.echobase.ui.actions.json.GetEntities"> - <result type="json"/> - </action> - - </package> - -</struts> - Modified: trunk/echobase-ui/src/main/resources/config/struts-user.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-user.xml 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/resources/config/struts-user.xml 2011-11-13 16:20:45 UTC (rev 51) @@ -31,16 +31,18 @@ <package name="user" extends="loggued" namespace="/user"> - <!-- login action --> - <action name="login" class="fr.ifremer.echobase.ui.actions.LoginAction" + <default-interceptor-ref name="basicStackLoggued"/> + + <!-- Login --> + <action name="login" class="fr.ifremer.echobase.ui.actions.user.LoginAction" method="doLogin"> <result name="input">/WEB-INF/jsp/user/login.jsp</result> <result name="redirect" type="redirect">${redirectAction}</result> <interceptor-ref name="paramsPrepareParamsStack"/> </action> - <!-- logout action --> - <action name="logout" class="fr.ifremer.echobase.ui.actions.LoginAction" + <!-- Logout --> + <action name="logout" class="fr.ifremer.echobase.ui.actions.user.LoginAction" method="doLogout"> <result type="redirectAction"> <param name="namespace">/</param> @@ -50,36 +52,47 @@ <interceptor-ref name="basicStack"/> </action> - <!-- display lists of users --> - <action name="userList" class="fr.ifremer.echobase.ui.actions.UserAction"> + <!-- Display lists of users --> + <action name="userList" class="fr.ifremer.echobase.ui.actions.user.ManageUser"> <interceptor-ref name="basicStackLoggued"/> <interceptor-ref name="checkUserIsAdmin"/> <result>/WEB-INF/jsp/user/userList.jsp</result> </action> - <!-- get detail of a user --> - <action name="userForm" class="fr.ifremer.echobase.ui.actions.UserAction" + <!-- Get detail of a user --> + <action name="userForm" class="fr.ifremer.echobase.ui.actions.user.ManageUser" method="input"> <interceptor-ref name="paramsPrepareParamsStackLoggued"/> <interceptor-ref name="checkUserIsAdmin"/> <result name="input">/WEB-INF/jsp/user/userForm.jsp</result> - <result name="success">/WEB-INF/jsp/user/userForm.jsp</result> + <result>/WEB-INF/jsp/user/userForm.jsp</result> <result name="backToList" type="redirectAction">userList</result> </action> - <!-- get db modifications --> + <!-- Get db modifications --> <action name="logs" class="fr.ifremer.echobase.ui.actions.EchoBaseActionSupport"> - <interceptor-ref name="basicStackLoggued"/> <result>/WEB-INF/jsp/modificationLogs.jsp</result> </action> + <!-- Get db connexion informations --> <action name="connectToDbInformations" - class="fr.ifremer.echobase.ui.actions.ConnectToDbInformations"> - <interceptor-ref name="basicStackLoggued"/> + class="fr.ifremer.echobase.ui.actions.user.ConnectToDbInformations"> <result>/WEB-INF/jsp/connectToDbInformations.jsp</result> </action> + <!-- Get list of users in database --> + <action name="getUsers" + class="fr.ifremer.echobase.ui.actions.user.GetUsers"> + <result type="json"/> + </action> + + <!-- Get modification logs entries --> + <action name="getEntityModificationLogs" method="entityModificationLogs" + class="fr.ifremer.echobase.ui.actions.dbeditor.GetEntities"> + <result type="json"/> + </action> + </package> </struts> Modified: trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties =================================================================== --- trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-13 16:20:45 UTC (rev 51) @@ -18,6 +18,9 @@ echobase.common.email=Email echobase.common.exportFileName=Nom du fichier d'export echobase.common.import=Import configuration +echobase.common.jdbcLogin=Login de connexion +echobase.common.jdbcPassword=Mot de passe +echobase.common.jdbcUrl=Url de connexion echobase.common.password=Mot de passe echobase.common.query.description=Description echobase.common.query.name=Nom @@ -60,6 +63,7 @@ echobase.menu.import=Importer des données echobase.menu.logs=Visualiser les modifications echobase.menu.users=Gérer les utilisateurs +echobase.message.askAdministratorPassword=Demander à un administrateur le mot de passe pour l'utilisateur donné echobase.message.modified.property= echobase.message.noEntrySelection=Aucune entrée sélectionnée echobase.msg.warnImportInProgress=Merci de ne pas fermer la fenêtre pour pouvoir accéder aux résultats de l'import. @@ -78,5 +82,3 @@ echobase.title.users=Adminitration des utilisateurs echobase.user.gridTitle=Liste des utilisateurs echobase.voyage.selectHeader=Selectionnez une campagne -echobase.common.jdbcUrl=Url de connexion -echobase.common.jdbcLogin=Login de connexion Modified: trunk/echobase-ui/src/main/resources/struts.xml =================================================================== --- trunk/echobase-ui/src/main/resources/struts.xml 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/resources/struts.xml 2011-11-13 16:20:45 UTC (rev 51) @@ -104,13 +104,13 @@ </interceptors> <!-- must be authenticated to perform any actions --> - <default-interceptor-ref name="paramsPrepareParamsStackLoggued"/> + <default-interceptor-ref name="basicStackLoggued"/> </package> <package name="applicationDefault" extends="default" namespace="/"> <!-- go to home --> - <action name="home" class="fr.ifremer.echobase.ui.actions.HomeAction"> + <action name="home" class="fr.ifremer.echobase.ui.actions.EchoBaseActionSupport"> <result>/WEB-INF/jsp/home.jsp</result> @@ -125,7 +125,6 @@ </package> <include file="config/struts-dbeditor.xml"/> - <include file="config/struts-json.xml"/> <include file="config/struts-user.xml"/> <include file="config/struts-import.xml"/> <include file="config/struts-export.xml"/> Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml 2011-11-13 16:20:45 UTC (rev 51) @@ -31,7 +31,7 @@ <pattern>/index*</pattern> <pattern>/dbeditor/getForeignEntities*</pattern> <pattern>/export/loadResult*</pattern> - <pattern>/json/*</pattern> + <!--<pattern>/json/*</pattern>--> </excludes> <decorator name="layout-default" page="layout-default.jsp"> Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/connectToDbInformations.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/connectToDbInformations.jsp 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/connectToDbInformations.jsp 2011-11-13 16:20:45 UTC (rev 51) @@ -32,10 +32,16 @@ <legend><s:text name="echobase.title.connectionToDb.detail"/></legend> <s:label key="jdbcUrl" label='%{getText("echobase.common.jdbcUrl")}'/> <s:label key="jdbcLogin" label='%{getText("echobase.common.jdbcLogin")}'/> + <s:label key="jdbcPassword" label='%{getText("echobase.common.jdbcPassword")} (*)'/> </fieldset> <br/> +<s:if test="askPassword"> + <div> + (*) <s:text name="echobase.message.askAdministratorPassword"/>. + </div> +</s:if> <div> </div> Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp 2011-11-13 16:20:45 UTC (rev 51) @@ -53,7 +53,7 @@ <br/> <s:if test="tableName!=null and tableName != ''"> - <s:url id="loadUrl" action="getTableDatas" namespace="/json" + <s:url id="loadUrl" action="getTableDatas" namespace="/dbeditor" escapeAmp="false"> <s:param name="tableName" value="%{tableName}"/> </s:url> Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportGrid.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportGrid.jsp 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportGrid.jsp 2011-11-13 16:20:45 UTC (rev 51) @@ -26,7 +26,7 @@ <%@ taglib prefix="sj" uri="/struts-jquery-tags" %> <%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %> -<s:url id="loadUrl" action="getExportSqlResult" namespace="/json" +<s:url id="loadUrl" action="getExportSqlResult" namespace="/export" escapeAmp="false"> <s:param name="sql" value="%{sql}"/> </s:url> Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/modificationLogs.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/modificationLogs.jsp 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/modificationLogs.jsp 2011-11-13 16:20:45 UTC (rev 51) @@ -46,7 +46,7 @@ </script> <title><s:text name="echobase.title.entityModificationLogs"/></title> -<s:url id="loadUrl" action="getEntityModificationLogs" namespace="/json" +<s:url id="loadUrl" action="getEntityModificationLogs" namespace="/user" escapeAmp="false"/> <sjg:grid id="datas" dataType="json" href="%{loadUrl}" gridModel="datas" Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/user/userList.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/user/userList.jsp 2011-11-13 14:29:26 UTC (rev 50) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/user/userList.jsp 2011-11-13 16:20:45 UTC (rev 51) @@ -29,7 +29,7 @@ <title><s:text name="echobase.title.users"/></title> -<s:url id="loadUrl" action="getUsers" namespace="/json" escapeAmp="false"/> +<s:url id="loadUrl" action="getUsers" namespace="/user" escapeAmp="false"/> <s:url id="addUrl" action="userForm" namespace="/user" escapeAmp="false" method="input"> <s:param name="userEditAction"><%=EditActionEnum.CREATE%></s:param>