Author: tchemit Date: 2011-11-11 03:11:50 +0100 (Fri, 11 Nov 2011) New Revision: 34 Url: http://forge.codelutin.com/repositories/revision/echobase/34 Log: rename Survey to Voyage continue dbEditor code Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java Removed: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/SurveyService.java Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ImportModel.java Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-11 02:10:13 UTC (rev 33) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-11 02:11:50 UTC (rev 34) @@ -23,6 +23,7 @@ */ package fr.ifremer.echobase.services; +import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import fr.ifremer.echobase.EchoBaseTechnicalException; import fr.ifremer.echobase.entities.EchoBaseDAOHelper; @@ -70,26 +71,19 @@ return decoratorService; } - public static class ResultDatas { + public List<TopiaEntity> getForeignDatas(String entityType) { + Preconditions.checkNotNull(entityType); + EchoBaseEntityEnum entityEnum = EchoBaseEntityEnum.valueOf(entityType); + Preconditions.checkNotNull(entityEnum); + Class<? extends TopiaEntity> contract = entityEnum.getContract(); + try { + TopiaDAO dao = EchoBaseDAOHelper.getDAO(getTransaction(), contract); - /** Total count. */ - int count; - - /** Loaded datas (for the given asked page). */ - Map<?, ?>[] rows; - - public ResultDatas(int count, Map<?, ?>[] rows) { - this.count = count; - this.rows = rows; + List result = dao.findAll(); + return result; + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException("Could not obtain data", eee); } - - public int getCount() { - return count; - } - - public Map[] getRows() { - return rows; - } } public TableMeta getTableMetas(String tableName) { @@ -99,7 +93,7 @@ } //TODO Use an object to filter datas - public ResultDatas getDatas(String tableName, + public Map<?, ?>[] getDatas(String tableName, Pager pager, String sidx, Boolean ascendantOrder) { @@ -149,8 +143,7 @@ Map<String, Object> row = loadRow(tableMeta, entity); rows[i++] = row; } - ResultDatas result = new ResultDatas(count, rows); - return result; + return rows; } catch (TopiaException eee) { throw new EchoBaseTechnicalException("Could not obtain data", eee); } Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java 2011-11-11 02:10:13 UTC (rev 33) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java 2011-11-11 02:11:50 UTC (rev 34) @@ -27,6 +27,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.Voyage; import org.apache.commons.collections.CollectionUtils; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.decorator.Decorator; @@ -116,9 +117,12 @@ @Override protected void loadDecorators(Locale locale) { - // trip decorator + // user decorator registerJXPathDecorator(locale, EchoBaseUser.class, "${email}$s"); + // voyage decorator + registerJXPathDecorator(locale, Voyage.class, "${voyageName}$s"); + } } } Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java 2011-11-11 02:10:13 UTC (rev 33) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java 2011-11-11 02:11:50 UTC (rev 34) @@ -1,109 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $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.services; - -import org.apache.commons.lang3.tuple.Pair; -import org.nuiton.util.PagerUtil; - -import java.io.Serializable; - -/** - * A simple pager bean. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class Pager implements Serializable { - - private static final long serialVersionUID = 1L; - - protected int records; - - protected int startIndex; - - protected int endIndex; - - protected int pageNumber; - - protected int pageSize; - - protected int pageCount; - - public int getRecords() { - return records; - } - - public int getStartIndex() { - return startIndex; - } - - public int getEndIndex() { - return endIndex; - } - - public int getPageNumber() { - return pageNumber; - } - - public int getPageSize() { - return pageSize; - } - - public int getPageCount() { - return pageCount; - } - - public void setRecords(int records) { - this.records = records; - } - - public void setStartIndex(int startIndex) { - this.startIndex = startIndex; - } - - public void setEndIndex(int endIndex) { - this.endIndex = endIndex; - } - - public void setPageNumber(int pageNumber) { - this.pageNumber = pageNumber; - } - - public void setPageSize(int pageSize) { - this.pageSize = pageSize; - } - - public void setPageCount(int pageCount) { - this.pageCount = pageCount; - } - - public void computeIndexesAndPageCount() { - Pair<Integer, Integer> pageBound = - PagerUtil.getPageBound(records, pageNumber, pageSize); - startIndex = pageBound.getLeft(); - endIndex = pageBound.getRight(); - pageCount = PagerUtil.getTotalPage(records, pageSize); - } - -} Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java 2011-11-11 02:11:50 UTC (rev 34) @@ -0,0 +1,109 @@ +/* + * #%L + * EchoBase :: Services + * + * $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.services; + +import org.apache.commons.lang3.tuple.Pair; +import org.nuiton.util.PagerUtil; + +import java.io.Serializable; + +/** + * A simple pager bean. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class Pager implements Serializable { + + private static final long serialVersionUID = 1L; + + protected int records; + + protected int startIndex; + + protected int endIndex; + + protected int pageNumber; + + protected int pageSize; + + protected int pageCount; + + public int getRecords() { + return records; + } + + public int getStartIndex() { + return startIndex; + } + + public int getEndIndex() { + return endIndex; + } + + public int getPageNumber() { + return pageNumber; + } + + public int getPageSize() { + return pageSize; + } + + public int getPageCount() { + return pageCount; + } + + public void setRecords(int records) { + this.records = records; + } + + public void setStartIndex(int startIndex) { + this.startIndex = startIndex; + } + + public void setEndIndex(int endIndex) { + this.endIndex = endIndex; + } + + public void setPageNumber(int pageNumber) { + this.pageNumber = pageNumber; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public void setPageCount(int pageCount) { + this.pageCount = pageCount; + } + + public void computeIndexesAndPageCount() { + Pair<Integer, Integer> pageBound = + PagerUtil.getPageBound(records, pageNumber, pageSize); + startIndex = pageBound.getLeft(); + endIndex = pageBound.getRight(); + pageCount = PagerUtil.getTotalPage(records, pageSize); + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/Pager.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/SurveyService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/SurveyService.java 2011-11-11 02:10:13 UTC (rev 33) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/SurveyService.java 2011-11-11 02:11:50 UTC (rev 34) @@ -1,62 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $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.services; - -import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.entities.EchoBaseDAOHelper; -import fr.ifremer.echobase.entities.Survey; -import fr.ifremer.echobase.entities.SurveyDAO; -import org.nuiton.topia.TopiaException; - -import java.util.List; - -/** - * Service to manage all concerning survey - * - * @author sletellier <letellier@codelutin.com> - */ -public class SurveyService extends AbstractEchoBaseService { - - public List<Survey> getSurveys() { - try { - List<Survey> surveys = getDAO().findAll(); - return surveys; - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException(eee); - } - } - - public Survey getSurveyById(String topiaId) { - try { - Survey survey = getDAO().findByTopiaId(topiaId); - return survey; - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException(eee); - } - } - - protected SurveyDAO getDAO() throws TopiaException { - return EchoBaseDAOHelper.getSurveyDAO(getTransaction()); - } -} Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java (from rev 28, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/SurveyService.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java 2011-11-11 02:11:50 UTC (rev 34) @@ -0,0 +1,62 @@ +/* + * #%L + * EchoBase :: Services + * + * $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.services; + +import fr.ifremer.echobase.EchoBaseTechnicalException; +import fr.ifremer.echobase.entities.EchoBaseDAOHelper; +import fr.ifremer.echobase.entities.Voyage; +import fr.ifremer.echobase.entities.VoyageDAO; +import org.nuiton.topia.TopiaException; + +import java.util.List; + +/** + * Service to manage all concerning voayges. + * + * @author sletellier <letellier@codelutin.com> + */ +public class VoyageService extends AbstractEchoBaseService { + + public List<Voyage> getVoyages() { + try { + List<Voyage> voyages = getDAO().findAll(); + return voyages; + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(eee); + } + } + + public Voyage getVoyageById(String topiaId) { + try { + Voyage voyage = getDAO().findByTopiaId(topiaId); + return voyage; + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(eee); + } + } + + protected VoyageDAO getDAO() throws TopiaException { + return EchoBaseDAOHelper.getVoyageDAO(getTransaction()); + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native 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-11 02:10:13 UTC (rev 33) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ImportModel.java 2011-11-11 02:11:50 UTC (rev 34) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.services.models; -import fr.ifremer.echobase.entities.Survey; +import fr.ifremer.echobase.entities.Voyage; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -34,13 +34,13 @@ * Object representing all import configuration * * @author sletellier <letellier@codelutin.com> - * @since 0.1 + * @since 0.1 */ public class ImportModel implements Serializable { private static final long serialVersionUID = 1L; - protected Survey surveySelected; + protected Voyage selectedVoyage; protected File accessImport; @@ -68,14 +68,18 @@ protected String comment; - public Survey getSurveySelected() { - return surveySelected; + public Voyage getSelectedVoyage() { + return selectedVoyage; } - public void setSurveySelected(Survey surveySelected) { - this.surveySelected = surveySelected; + public String getSelectedVoyageId() { + return selectedVoyage == null ? null : selectedVoyage.getTopiaId(); } + public void setSelectedVoyage(Voyage selectedVoyage) { + this.selectedVoyage = selectedVoyage; + } + public String getComment() { return comment; } @@ -183,7 +187,7 @@ public boolean validate() { // access file or survey is selected, not both - boolean result = surveySelected == null ^ accessImport == null; + boolean result = selectedVoyage == null ^ accessImport == null; // Less one of other import result = result && (accessImport != null || @@ -198,7 +202,9 @@ @Override public String toString() { ToStringBuilder builder = new ToStringBuilder(this); - builder.append("surveySelected", surveySelected.getName()); + if (selectedVoyage != null) { + builder.append("selectedVoyage", selectedVoyage.getVoyageName()); + } builder.append("accessImportFile", accessImportFileName); builder.append("accousticImportFile", accousticImportFileName); builder.append("pecherieImportFile", pecherieImportFileName); @@ -209,34 +215,5 @@ builder.append("comment", comment); } 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("]"); -// } -// } }