Author: bleny Date: 2010-10-13 10:22:10 +0000 (Wed, 13 Oct 2010) New Revision: 667 Log: added global synthesis in model + migration code ; moved synthesisId to business Added: trunk/wao-business/src/main/java/fr/ifremer/wao/SynthesisId.java Removed: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/SynthesisId.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-10-08 23:52:14 UTC (rev 666) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-10-13 10:22:10 UTC (rev 667) @@ -38,6 +38,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.logging.Logger; /** * PgMigrationCallback @@ -47,7 +48,9 @@ * @author fdesbois <fdesbois at codelutin.com> */ public class PostgresMigrationCallback extends WaoMigrationCallBack { + private static final Logger logger = Logger.getLogger(PostgresMigrationCallback.class.getName()); + @Override protected void createUserRoleColumn_1_1a(List<String> queries) { // Evo #2063 @@ -267,4 +270,152 @@ queries.add("UPDATE Contact SET emailSent = FALSE WHERE dataInputDate IS NULL;"); queries.add("UPDATE Contact SET emailSent = TRUE WHERE dataInputDate IS NOT NULL;"); } + + @Override + protected void createTablesForIndicatorsAdministration_1_6(List<String> queries) { + // Evo #386 create Tables for Indicator IndicatorLevel and IndicatorLog + // entities + + queries.add("CREATE TABLE Indicator (" + + "topiaId CHARACTER VARYING(255) PRIMARY KEY," + + "topiaVersion BIGINT NOT NULL," + + "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," + + "indicatorId SMALLINT," + + "coefficient DOUBLE PRECISION);"); + + queries.add("CREATE TABLE IndicatorLevel (" + + "topiaId CHARACTER VARYING(255) PRIMARY KEY," + + "topiaVersion BIGINT NOT NULL," + + "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," + + "\"level\" SMALLINT," + + "upperBound DOUBLE PRECISION," + + "indicator CHARACTER VARYING(255)," + + "CONSTRAINT indicator_fkey FOREIGN KEY (indicator) " + + "REFERENCES Indicator (topiaid) MATCH SIMPLE " + + "ON UPDATE NO ACTION ON DELETE NO ACTION);"); + + // create table IndicatorLog with author FK + queries.add("CREATE TABLE IndicatorLog (" + + "topiaId CHARACTER VARYING(255) PRIMARY KEY," + + "topiaVersion BIGINT NOT NULL," + + "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," + + "logText TEXT," + + "\"comment\" TEXT," + + "indicator CHARACTER VARYING(255)," + + "author CHARACTER VARYING(255)," + + "CONSTRAINT author_fkey FOREIGN KEY (author) " + + "REFERENCES WaoUser (topiaid) MATCH SIMPLE " + + "ON UPDATE NO ACTION ON DELETE NO ACTION, " + + "CONSTRAINT indicator_fkey FOREIGN KEY (indicator) " + + "REFERENCES Indicator (topiaid) MATCH SIMPLE " + + "ON UPDATE NO ACTION ON DELETE NO ACTION);"); + + + + } + + @Override + protected void insertIndicatorLevelInitialValues_1_6(List<String> queries) { + + // first, fill Indicator relation + + int topiaVersion = 0; + String topiaCreateDateValue = "DATE '2010-10-12'"; + + String topiaIndicatorIdPrefix = "fr.ifremer.wao.entities.Indicator#1286887802000#1547308662"; + + String insertIntoIndicator = "INSERT INTO Indicator (topiaId, topiaVersion, topiaCreateDate, indicatorId, coefficient) " + + "VALUES ('%s', %s, %s, %s, %s);"; + + SynthesisId[] synthesisIds = { SynthesisId.GRAPH_SAMPLING, + SynthesisId.IND_COMPLIANCE_BOARDING, + SynthesisId.GRAPH_BOARDING, + SynthesisId.IND_ALLEGRO_REACTIVITY, + SynthesisId.IND_SAMPLE_RELIABILITY }; + + double coefficientValue = 1.0; + + Map <SynthesisId, String> indicatorsTopiaIds = new HashMap<SynthesisId, String>(); + + for (SynthesisId synthesisId : synthesisIds) { + String topiaId = topiaIndicatorIdPrefix + synthesisId.ordinal(); + indicatorsTopiaIds.put(synthesisId, topiaId); + queries.add(String.format(insertIntoIndicator, topiaId, + topiaVersion, + topiaCreateDateValue, + synthesisId.ordinal(), + coefficientValue)); + } + + + String topiaIndicatorLevelIdPrefix = "fr.ifremer.wao.entities.IndicatorLevel#1286890064000#1929220062_"; + int topiaIdSuffix = 0; + + // now filling IndicatorLevel + String indicatorTopiaId; + + indicatorTopiaId = indicatorsTopiaIds.get(SynthesisId.GRAPH_SAMPLING); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 1, 60.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 2, 70.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 3, 80.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 4, 90.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 5, 100.0, indicatorTopiaId)); + + indicatorTopiaId = indicatorsTopiaIds.get(SynthesisId.IND_COMPLIANCE_BOARDING); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 1, 60.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 2, 70.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 3, 80.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 4, 90.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 5, 100.0, indicatorTopiaId)); + + indicatorTopiaId = indicatorsTopiaIds.get(SynthesisId.GRAPH_BOARDING); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 1, 60.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 2, 70.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 3, 80.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 4, 90.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 5, 100.0, indicatorTopiaId)); + + indicatorTopiaId = indicatorsTopiaIds.get(SynthesisId.IND_ALLEGRO_REACTIVITY); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 1, 40.0, indicatorTopiaId)); // 40 days + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 2, 30.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 3, 20.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 4, 10.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 5, 5.0, indicatorTopiaId)); // 5 days + + indicatorTopiaId = indicatorsTopiaIds.get(SynthesisId.IND_SAMPLE_RELIABILITY); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 1, 80.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 2, 85.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 3, 90.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 4, 95.0, indicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 5, 100.0, indicatorTopiaId)); + + } + + /** + * help method to create insertion for initial data in table levels + * @param indicatorTopiaId the topiaId of the concerned indicator (foreign key) + * @param level value in the tuple + * @param upperBound value in the tuble + * @return an SQL "insert" request for table IndicatorLevel + */ + protected String getInsertIndicatorLevelQuery_1_6(String topiaId, + int level, double upperBound, + String indicatorTopiaId) { + + int topiaVersion = 0; + String topiaCreateDateValue = "DATE '2010-10-12'"; + + String insertIntoIndicatorLevel = + "INSERT INTO IndicatorLevel (topiaId, topiaVersion, topiaCreateDate, level, upperBound, indicator) " + + "VALUES ('%s', %s, %s, %s, %s, '%s');"; + + String request = String.format(insertIntoIndicatorLevel, + topiaId, + topiaVersion, + topiaCreateDateValue, + level, + upperBound, + indicatorTopiaId); + return request; + } } Copied: trunk/wao-business/src/main/java/fr/ifremer/wao/SynthesisId.java (from rev 666, trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/SynthesisId.java) =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/SynthesisId.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/SynthesisId.java 2010-10-13 10:22:10 UTC (rev 667) @@ -0,0 +1,74 @@ +/* + * #%L + * Wao :: Web Interface + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * 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.wao; + +/** + * SynthesisID + * + * Created: 9 févr. 2010 + * + * @author fdesbois <fdesbois at codelutin.com> + */ +public enum SynthesisId { + + /** */ + GRAPH_SAMPLING("graph1"), + + /** */ + GRAPH_BOARDING("graph2"), + + /** */ + IND_NON_COMPLIANCE_BOARDING("ind1"), + + /** */ + IND_CONTACT_STATE("ind2"), + + /** */ + IND_ALLEGRO_REACTIVITY("ind3"), + + /** */ + IND_COMPLIANCE_BOARDING("ind4"), + + /** */ + IND_SAMPLE_RELIABILITY("ind5"); + + private String blockId; + + SynthesisId(String blockId) { + this.blockId = blockId; + } + + public String getBlockId() { + return blockId; + } + + public static SynthesisId getSynthesisId(String blockId) { + for (SynthesisId synthesisId : SynthesisId.values()) { + if (synthesisId.getBlockId().equals(blockId)) { + return synthesisId; + } + } + return null; + } +} Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-10-08 23:52:14 UTC (rev 666) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-10-13 10:22:10 UTC (rev 667) @@ -78,13 +78,18 @@ protected abstract void createContactEmailSentColumn_1_5e(List<String> queries); + protected abstract void createTablesForIndicatorsAdministration_1_6(List<String> queries); + + protected abstract void insertIndicatorLevelInitialValues_1_6(List<String> queries); + protected static final Version[] VERSIONS = new Version[] { VersionUtil.valueOf("1.0"), VersionUtil.valueOf("1.1"), VersionUtil.valueOf("1.2"), VersionUtil.valueOf("1.3"), VersionUtil.valueOf("1.4"), - VersionUtil.valueOf("1.5") + VersionUtil.valueOf("1.5"), + VersionUtil.valueOf("1.6") }; @Override @@ -217,4 +222,28 @@ executeSQL(tx, showSql, showProgression, strings); } + /** creates Indicator, IndicatorLevel, IndicatorLog tables and inserts + * initial values. + */ + public void migrateTo_1_6(TopiaContextImplementor tx, + boolean showSql, + boolean showProgression) throws TopiaException { + if (log.isInfoEnabled()) { + log.info("migrating to version 1.6"); + } + + List<String> queries = new ArrayList<String>(); + + createTablesForIndicatorsAdministration_1_6(queries); + + insertIndicatorLevelInitialValues_1_6(queries); + + if (log.isDebugEnabled()) { + log.debug("queries for migration to version 1.6 are \n" + queries); + } + + String[] strings = queries.toArray(new String[queries.size()]); + executeSQL(tx, true, true, strings); + } + } Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Deleted: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/SynthesisId.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/SynthesisId.java 2010-10-08 23:52:14 UTC (rev 666) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/SynthesisId.java 2010-10-13 10:22:10 UTC (rev 667) @@ -1,64 +0,0 @@ -/* - * #%L - * Wao :: Web Interface - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * 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.wao.ui.data; - -/** - * SynthesisID - * - * Created: 9 févr. 2010 - * - * @author fdesbois <fdesbois at codelutin.com> - */ -public enum SynthesisId { - - GRAPH_SAMPLING("graph1"), - GRAPH_BOARDING("graph2"), - IND_NON_COMPLIANCE_BOARDING("ind1"), - IND_CONTACT_STATE("ind2"), - IND_ALLEGRO_REACTIVITY("ind3"); - private String blockId; - - SynthesisId(String blockId) { - this.blockId = blockId; - } - - public String getBlockId() { - return blockId; - } - - public static SynthesisId getSynthesisID(String blockId) { - if (blockId.equals(GRAPH_SAMPLING.getBlockId())) { - return GRAPH_SAMPLING; - } else if (blockId.equals(GRAPH_BOARDING.getBlockId())) { - return GRAPH_BOARDING; - } else if (blockId.equals(IND_CONTACT_STATE.getBlockId())) { - return IND_CONTACT_STATE; - } else if (blockId.equals(IND_NON_COMPLIANCE_BOARDING.getBlockId())) { - return IND_NON_COMPLIANCE_BOARDING; - } else if (blockId.equals(IND_ALLEGRO_REACTIVITY.getBlockId())) { - return IND_ALLEGRO_REACTIVITY; - } - return null; - } -} Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-10-08 23:52:14 UTC (rev 666) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-10-13 10:22:10 UTC (rev 667) @@ -24,6 +24,7 @@ package fr.ifremer.wao.ui.pages; +import fr.ifremer.wao.SynthesisId; import fr.ifremer.wao.WaoException; import fr.ifremer.wao.bean.BoardingResult; import fr.ifremer.wao.bean.ConnectedUser; @@ -39,7 +40,7 @@ import fr.ifremer.wao.ui.data.ChartUtils; import fr.ifremer.wao.ui.data.ChartUtils.ChartType; import fr.ifremer.wao.ui.data.RequiresAuthentication; -import fr.ifremer.wao.ui.data.SynthesisId; +import fr.ifremer.wao.SynthesisId; import fr.ifremer.wao.ui.services.WaoManager; import org.apache.commons.collections.CollectionUtils; import org.apache.tapestry5.Block; @@ -56,7 +57,6 @@ import org.nuiton.util.DateUtil; import org.nuiton.util.PeriodDates; import org.slf4j.Logger; - import java.text.DateFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat;