Author: tchemit Date: 2011-11-09 09:55:29 +0100 (Wed, 09 Nov 2011) New Revision: 30 Url: http://forge.codelutin.com/repositories/revision/echobase/30 Log: db editor story Added: 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/dbeditor/LoadEntities.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java Removed: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetTableDatas.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadTablePage.java Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ImportModel.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml trunk/echobase-ui/src/main/resources/config/struts-import.xml trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ImportModel.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ImportModel.java 2011-11-09 08:49:36 UTC (rev 29) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ImportModel.java 2011-11-09 08:55:29 UTC (rev 30) @@ -25,34 +25,45 @@ import fr.ifremer.echobase.entities.Survey; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; import java.io.File; +import java.io.Serializable; /** * Object representing all import configuration * * @author sletellier <letellier@codelutin.com> + * @since 0.1 */ -public class ImportModel { +public class ImportModel implements Serializable { + private static final long serialVersionUID = 1L; + protected Survey surveySelected; protected File accessImport; + protected String accessImportFileName; protected File accousticImport; + protected String accousticImportFileName; protected File pecherieImport; + protected String pecherieImportFileName; protected File lectureAgeGenImport; + protected String lectureAgeGenImportFileName; protected File eventsImport; + protected String eventsImportFileName; protected File typeEchoSpeciesImport; + protected String typeEchoSpeciesImportFileName; protected String comment; @@ -65,7 +76,6 @@ this.surveySelected = surveySelected; } - public String getComment() { return comment; } @@ -182,40 +192,51 @@ pecherieImport != null || eventsImport != null || typeEchoSpeciesImport != null); - return result; } @Override public String toString() { - StringBuilder builder = new StringBuilder(); - - // Add selected survey - if (surveySelected != null) { - addToBuilder(builder, "surveySelected", surveySelected.getName()); - } - - // Add all import files - addToBuilder(builder, "accessImportFile", accessImportFileName); - addToBuilder(builder, "accousticImportFile", accousticImportFileName); - addToBuilder(builder, "pecherieImportFile", pecherieImportFileName); - addToBuilder(builder, "lectureAgeGenImportFile", lectureAgeGenImportFileName); - addToBuilder(builder, "eventsImportFile", eventsImportFileName); - addToBuilder(builder, "pecherieImportFile", typeEchoSpeciesImportFileName); - + ToStringBuilder builder = new ToStringBuilder(this); + builder.append("surveySelected", surveySelected.getName()); + builder.append("accessImportFile", accessImportFileName); + builder.append("accousticImportFile", accousticImportFileName); + builder.append("pecherieImportFile", pecherieImportFileName); + builder.append("lectureAgeGenImportFile", lectureAgeGenImportFileName); + builder.append("eventsImportFile", eventsImportFileName); + builder.append("pecherieImportFile", typeEchoSpeciesImportFileName); if (StringUtils.isNotEmpty(comment)) { - addToBuilder(builder, "comment", comment); + builder.append("comment", comment); } - return builder.toString().trim(); + return builder.toString(); +// StringBuilder builder = new StringBuilder(); +// +// // Add selected survey +// if (surveySelected != null) { +// addToBuilder(builder, "surveySelected", surveySelected.getName()); +// } +// +// // Add all import files +// addToBuilder(builder, "accessImportFile", accessImportFileName); +// addToBuilder(builder, "accousticImportFile", accousticImportFileName); +// addToBuilder(builder, "pecherieImportFile", pecherieImportFileName); +// addToBuilder(builder, "lectureAgeGenImportFile", lectureAgeGenImportFileName); +// addToBuilder(builder, "eventsImportFile", eventsImportFileName); +// addToBuilder(builder, "pecherieImportFile", typeEchoSpeciesImportFileName); +// +// if (StringUtils.isNotEmpty(comment)) { +// addToBuilder(builder, "comment", comment); +// } +// return builder.toString().trim(); } - protected void addToBuilder(StringBuilder builder, String name, String value) { - if (StringUtils.isNotEmpty(value)) { - builder.append(" "); - builder.append(name); - builder.append("["); - builder.append(value); - builder.append("]"); - } - } +// protected void addToBuilder(StringBuilder builder, String name, String value) { +// if (StringUtils.isNotEmpty(value)) { +// builder.append(" "); +// builder.append(name); +// builder.append("["); +// builder.append(value); +// builder.append("]"); +// } +// } } Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2011-11-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2011-11-09 08:55:29 UTC (rev 30) @@ -108,7 +108,7 @@ applicationContext.setRootContextSupplier(rootContextSupplier); List<EchoBaseEntityEnum> entityEnums = Lists.newArrayList(EchoBaseEntityEnum.values()); - entityEnums.remove(EchoBaseEntityEnum.EchoBaseUser); +// entityEnums.remove(EchoBaseEntityEnum.EchoBaseUser); DbMeta dbMeta = new DbMeta(entityEnums.toArray(new EchoBaseEntityEnum[entityEnums.size()])); applicationContext.setDbMeta(dbMeta); @@ -123,7 +123,8 @@ // init database (and create minimal admin user if required) try { boolean schemaExist = isSchemaCreated(); - if (!schemaExist) { + if (!schemaExist || + configuration.getOptionAsBoolean("updateSchema")) { updateSchema(configuration); } Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java 2011-11-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java 2011-11-09 08:55:29 UTC (rev 30) @@ -1,7 +1,29 @@ +/* + * #%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.google.common.collect.Maps; -import com.opensymphony.xwork2.Preparable; import fr.ifremer.echobase.entities.Survey; import fr.ifremer.echobase.services.SurveyService; import fr.ifremer.echobase.services.models.ImportModel; @@ -19,6 +41,8 @@ */ public class ImportAction extends EchoBaseActionSupport { + private static final long serialVersionUID = 1L; + protected static final Log log = LogFactory.getLog(ImportAction.class); protected ImportModel importModel; Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.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/dbeditor/GetEntities.java (from rev 25, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetTableDatas.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-09 08:55:29 UTC (rev 30) @@ -0,0 +1,220 @@ +/* + * #%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.services.DbEditorService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.json.JSONUtil; + +import java.util.Map; + +/** + * To obtain the data for the given request. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class GetEntities extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(GetEntities.class); + + private static final String SIDX_PREFIX = "tableDatas_"; + + /** Name of the table to load. */ + protected String tableName; + + /** Datas of the given table. */ + protected Map<?,?>[] datas; + + //get how many rows we want to have into the grid - rowNum attribute in the grid + protected Integer rows = 0; + + //Get the requested page. By default grid sets this to 1. + protected Integer page = 0; + + // sorting order - asc or desc + protected String sord; + + // get index row - i.e. user click to sort. + protected String sidx; + + // Search Field + protected String searchField; + + // The Search String + protected String searchString; + + // he Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'] + protected String searchOper; + + protected String filters; + + // Your Total Pages + protected Integer total = 0; + + // All Record + protected Integer records = 0; + + public Map<?,?>[] getDatas() { + return datas; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + @Override + public String execute() throws Exception { + DbEditorService dbEditorService = newService(DbEditorService.class); + + int to = rows * page; + int from = to - rows; + + Boolean ascendantOrder = null; + + if (StringUtils.isNotEmpty(sidx)) { + + // there is a sort to do + sidx = sidx.substring(SIDX_PREFIX.length()); + + ascendantOrder = "asc".equals(sord); + } + + Object filterObject = null; + + + if (StringUtils.isNotEmpty(filters)) { + filterObject = JSONUtil.deserialize(filters); + } + + if (log.isInfoEnabled()) { + log.info("searchField = " + searchField); + log.info("searchField = " + searchField); + log.info("searchString = " + searchString); + log.info("searchOper = " + searchOper); + log.info("filters = " + filters); + log.info("filterObject = " + filterObject); + log.info("sidx = " + sidx); + log.info("sord = " + sord); + } + + DbEditorService.ResultDatas resultDatas = + dbEditorService.getDatas(tableName, from, to, sidx, ascendantOrder); + + datas = resultDatas.getRows(); + + records = resultDatas.getCount(); + + //calculate the total pages for the query + total = (int) Math.ceil((double) records / (double) rows); + + return SUCCESS; + } + + public Integer getRows() { + return rows; + } + + public void setRows(Integer rows) { + this.rows = rows; + } + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + this.page = 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 getSearchField() { + return searchField; + } + + public void setSearchField(String searchField) { + this.searchField = searchField; + } + + public String getSearchString() { + return searchString; + } + + public void setSearchString(String searchString) { + this.searchString = searchString; + } + + public String getSearchOper() { + return searchOper; + } + + public void setSearchOper(String searchOper) { + this.searchOper = searchOper; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + public Integer getRecords() { + return records; + } + + public void setRecords(Integer records) { + this.records = records; + } + + public String getFilters() { + return filters; + } + + public void setFilters(String filters) { + this.filters = filters; + } +} 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 Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetTableDatas.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetTableDatas.java 2011-11-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetTableDatas.java 2011-11-09 08:55:29 UTC (rev 30) @@ -1,63 +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.dbeditor; - -import fr.ifremer.echobase.services.DbEditorService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; - -import java.util.Map; - -/** - * To obtain the data for the given request. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class GetTableDatas extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - /** Name of the table to load. */ - protected String tableName; - - /** Datas of the given table. */ - protected Map[] datas; - - public Map[] getDatas() { - return datas; - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - @Override - public String execute() throws Exception { - DbEditorService dbEditorService = newService(DbEditorService.class); - datas = dbEditorService.getDatas(tableName); - return SUCCESS; - } - - -} Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java (from rev 25, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadTablePage.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java 2011-11-09 08:55:29 UTC (rev 30) @@ -0,0 +1,95 @@ +/* + * #%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 com.google.common.collect.Maps; +import fr.ifremer.echobase.entities.meta.ColumnMeta; +import fr.ifremer.echobase.entities.meta.DbMeta; +import fr.ifremer.echobase.entities.meta.TableMeta; +import fr.ifremer.echobase.services.DbEditorService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import org.apache.commons.lang.StringUtils; + +import java.util.List; +import java.util.Map; + +import static org.nuiton.i18n.I18n.l_; + +/** + * To load the db editor pages. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class LoadEntities extends EchoBaseActionSupport { + + private static final long serialVersionUID = 1L; + + /** Name of the table to load. */ + protected String tableName; + + /** All tables availables */ + protected Map<String, String> tableNames; + + /** Metas of the table */ + protected TableMeta tableMeta; + + public String getTableName() { + return tableName; + } + + public Map<String, String> getTableNames() { + return tableNames; + } + + public List<ColumnMeta> getColumnMetas() { + return tableMeta.getColumns(); + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + @Override + public String input() throws Exception { + tableNames = Maps.newTreeMap(); + DbMeta dbMeta = getEchoBaseApplicationContext().getDbMeta(); + for (TableMeta tableMeta : dbMeta) { + String name = tableMeta.getName(); + String i18nKey = tableMeta.getI18nKey(); + tableNames.put(name, l_(getLocale(), i18nKey)); + } + if (StringUtils.isEmpty(tableName)) { + + // no table selected + addActionMessage(_("echobase.info.no.table.selected")); + } else { + + // load table metas + DbEditorService dbEditorService = newService(DbEditorService.class); + tableMeta = dbEditorService.getTableMetas(tableName); + } + return INPUT; + } +} Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.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/dbeditor/LoadTablePage.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadTablePage.java 2011-11-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadTablePage.java 2011-11-09 08:55:29 UTC (rev 30) @@ -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.dbeditor; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.meta.ColumnMeta; -import fr.ifremer.echobase.entities.meta.DbMeta; -import fr.ifremer.echobase.entities.meta.TableMeta; -import fr.ifremer.echobase.services.DbEditorService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; -import org.apache.commons.lang.StringUtils; - -import java.util.List; -import java.util.Map; - -import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.l_; - -/** - * To load the db editor page.s - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class LoadTablePage extends EchoBaseActionSupport { - - private static final long serialVersionUID = 1L; - - /** Name of the table to load. */ - protected String tableName; - - /** All tables availables */ - protected Map<String, String> tableNames; - - /** Metas of the table */ - protected TableMeta tableMeta; - - public String getTableName() { - return tableName; - } - - public Map<String, String> getTableNames() { - return tableNames; - } - - public List<ColumnMeta> getColumnMetas() { - return tableMeta.getColumns(); - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - @Override - public String input() throws Exception { - tableNames = Maps.newTreeMap(); - DbMeta dbMeta = getEchoBaseApplicationContext().getDbMeta(); - for (TableMeta tableMeta : dbMeta) { - String name = tableMeta.getName(); - String i18nKey = tableMeta.getI18nKey(); - tableNames.put(name, l_(getLocale(), i18nKey)); - } - if (StringUtils.isEmpty(tableName)) { - - // no table selected - addActionMessage(_("echobase.info.no.table.selected")); - } else { - - // load table metas - DbEditorService dbEditorService = newService(DbEditorService.class); - tableMeta = dbEditorService.getTableMetas(tableName); - } - return INPUT; - } -} Added: 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 (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java 2011-11-09 08:55:29 UTC (rev 30) @@ -0,0 +1,117 @@ +/* + * #%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 com.google.common.collect.Maps; +import fr.ifremer.echobase.entities.meta.TableMeta; +import fr.ifremer.echobase.services.DbEditorService; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import org.apache.commons.lang.StringUtils; +import org.apache.struts2.interceptor.ParameterAware; +import org.nuiton.util.beans.PropertyDiff; + +import java.util.List; +import java.util.Map; + +/** + * Save the edition of a row of a table. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class SaveEntity extends EchoBaseActionSupport implements ParameterAware { + + private static final long serialVersionUID = 1L; + + /** Name of the table to load. */ + protected String tableName; + + /** id of entity to save. */ + protected String id; + + /** Metas of the table */ + protected TableMeta tableMeta; + + protected Map<String, String[]> params; + + protected transient DbEditorService dbEditorService; + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String execute() throws Exception { + + DbEditorService dbEditorService = newService(DbEditorService.class); + TableMeta tableMeta = dbEditorService.getTableMetas(tableName); + Map<String, String> properties = Maps.newHashMap(); + List<String> columnNames = tableMeta.getColumnNames(); + for (String columnName : columnNames) { + if (params.containsKey(columnName)) { + + // there is a such property to edit + String[] values = params.get(columnName); + + if (values.length > 0) { + + // take only the first value + String propertyValue = values[0]; + if (StringUtils.isNotEmpty(propertyValue)) { + + // only keep properties with no empty value + properties.put(columnName, propertyValue); + } + } + } + } + + PropertyDiff[] diffs = + dbEditorService.saveEntity(tableMeta, + id, + properties, + getEchoBaseSession().getEchoBaseUser()); + + for (PropertyDiff diff : diffs) { + addActionMessage(_("echobase.message.modified.property", + diff.getSourceProperty(), + diff.getSourceValue(), + diff.getTargetValue()) + ); + } + return NONE; + } + + @Override + public void setParameters(Map<String, String[]> parameters) { + params = Maps.newHashMap(); + params.putAll(parameters); + } + +} + Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml 2011-11-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml 2011-11-09 08:55:29 UTC (rev 30) @@ -32,17 +32,22 @@ <package name="dbeditor" extends="loggued" namespace="/dbeditor"> <action name="dbeditor" method="input" - class="fr.ifremer.echobase.ui.actions.dbeditor.LoadTablePage"> + class="fr.ifremer.echobase.ui.actions.dbeditor.LoadEntities"> <interceptor-ref name="basicStackLoggued"/> <result name="input">/WEB-INF/jsp/dbeditor/dbeditor.jsp</result> </action> - + <action name="getTableDatas" - class="fr.ifremer.echobase.ui.actions.dbeditor.GetTableDatas"> + class="fr.ifremer.echobase.ui.actions.dbeditor.GetEntities"> <interceptor-ref name="basicStackLoggued"/> <result type="json"/> </action> + <action name="editTableData" + class="fr.ifremer.echobase.ui.actions.dbeditor.SaveEntity"> + <interceptor-ref name="basicStackLoggued"/> + </action> + </package> </struts> Modified: trunk/echobase-ui/src/main/resources/config/struts-import.xml =================================================================== --- trunk/echobase-ui/src/main/resources/config/struts-import.xml 2011-11-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/resources/config/struts-import.xml 2011-11-09 08:55:29 UTC (rev 30) @@ -1,5 +1,29 @@ <?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"> Property changes on: trunk/echobase-ui/src/main/resources/config/struts-import.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native 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-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-09 08:55:29 UTC (rev 30) @@ -43,8 +43,10 @@ echobase.menu.import=Imports echobase.menu.logs=Logs echobase.menu.users=Utilisateurs +echobase.message.modified.property= echobase.msg.warnImportInProgress=Merci de ne pas fermer la fenêtre pour pouvoir acceder au résultats de l'import. echobase.survey.selectHeader=Selectionnez une campagne +echobase.title.dbEditor=Modification de la base echobase.title.export=Export echobase.title.import=Imports echobase.title.importProgress=Import en cours 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-09 08:49:36 UTC (rev 29) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp 2011-11-09 08:55:29 UTC (rev 30) @@ -36,7 +36,7 @@ $('[name="tableName"]').change(function(event) { - var url = "${reloadUrl}?" + $.param({ tableName:this.value}); + var url = "${reloadUrl}?" + $.param({tableName:this.value}); window.location = url; }); }); @@ -46,7 +46,6 @@ <s:select key="tableName" label='%{getText("echobase.common.tableName")}' list="tableNames" headerKey="" headerValue=""/> - </div> <br/> @@ -56,25 +55,35 @@ <s:param name="tableName" value="%{tableName}"/> </s:url> + <s:url id="editUrl" action="editTableData" namespace="/dbeditor" + escapeAmp="false"> + <s:param name="tableName" value="%{tableName}"/> + </s:url> + <sjg:grid id="tableDatas" caption="%{getText('echobase.common.tableDatas', tableNames[tableName])}" dataType="json" href="%{loadUrl}" gridModel="datas" - pager="true" pagerButtons="false" pagerInput="false" + pager="true" pagerButtons="true" pagerInput="true" navigator="true" autowidth="true" rownumbers="false" navigatorEdit="true" navigatorDelete="false" navigatorSearch="true" navigatorRefresh="true" navigatorAdd="false" - resizable="true" editinline="false"> + editurl="%{editUrl}" + rowList="10,15,20, 50" + rowNum="10" + resizable="true" editinline="false" + navigatorSearchOptions="{multipleGroup:false,showQuery:true,multipleSearch:true,sopt:['eq','ne','cn','nc','bw','bn','ew','en','lt','le','gt','ge','nu','nn','in','ni']}" + > - <sjg:gridColumn name="id" title="id" hidden="true"/> + <sjg:gridColumn name="id" title="id" hidden="true" editable="true"/> <s:iterator value="columnMetas" var="meta" status="status"> - <sjg:gridColumn name="%{#meta.name}" title="%{getText(#meta.i18nKey)}" - edittype="%{#meta.columnType}" - sortable="false" editable="true"/> + <sjg:gridColumn name="%{#meta.name}" + title="%{getText(#meta.i18nKey)}" + sortable="true" editable="true" /> </s:iterator>