Author: bleny Date: 2010-11-03 11:22:57 +0000 (Wed, 03 Nov 2010) New Revision: 732 Log: make global synthesis main indicator depends on data in the DB to make it modifiable by a user Added: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisParametersImpl.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java trunk/wao-ui/src/main/webapp/Administration.tml trunk/wao-ui/src/main/webapp/Synthesis.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-11-03 11:22:57 UTC (rev 732) @@ -355,7 +355,15 @@ coefficientValue)); } + // now insert an indicator corresponding to the global level + String globalIndicatorTopiaId = topiaIndicatorIdPrefix + "g"; + queries.add(String.format(insertIntoIndicator, globalIndicatorTopiaId, + topiaVersion, + topiaCreateDateValue, + null, + null)); + String topiaIndicatorLevelIdPrefix = "fr.ifremer.wao.entities.IndicatorLevel#1286890064000#1929220062_"; int topiaIdSuffix = 0; @@ -397,6 +405,11 @@ queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 4, 95.0, indicatorTopiaId)); queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 5, 100.0, indicatorTopiaId)); + + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 0, 2.0, globalIndicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 1, 3.0, globalIndicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 2, 5.0, globalIndicatorTopiaId)); + queries.add(getInsertIndicatorLevelQuery_1_6(topiaIndicatorLevelIdPrefix + topiaIdSuffix++, 3, 5.5, globalIndicatorTopiaId)); } /** Help method to create insertion for initial data in table levels. Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalIndicatorValue.java 2010-11-03 11:22:57 UTC (rev 732) @@ -23,4 +23,13 @@ public String getLabel() { return _(label); } + + public static GlobalIndicatorValue valueOf(int ordinal) { + for (GlobalIndicatorValue globalIndicatorValue : GlobalIndicatorValue.values()) { + if (globalIndicatorValue.ordinal() == ordinal) { + return globalIndicatorValue; + } + } + return null; + } } Added: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisParametersImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisParametersImpl.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisParametersImpl.java 2010-11-03 11:22:57 UTC (rev 732) @@ -0,0 +1,26 @@ +package fr.ifremer.wao.bean; + +import fr.ifremer.wao.entity.Indicator; + +public class GlobalSynthesisParametersImpl extends GlobalSynthesisParameters { + + /** in the list of indicators, find the one with given synthesisId. */ + @Override + public Indicator getParameter(SynthesisId synthesisId) { + for (Indicator indicator : getParameters()) { + if (indicator.getSynthesisId().equals(synthesisId)) { + return indicator; + } + } + return null; + } + + @Override + public Double getTotalCoefficients() { + Double totalCoefficient = 0.0; + for (Indicator indicator : getParameters()) { + totalCoefficient += indicator.getCoefficient(); + } + return totalCoefficient; + } +} Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/GlobalSynthesisResultImpl.java 2010-11-03 11:22:57 UTC (rev 732) @@ -5,7 +5,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; import java.util.Map; public class GlobalSynthesisResultImpl extends GlobalSynthesisResult { @@ -15,32 +14,11 @@ protected Map<SynthesisId, Double> values; - protected List<Indicator> globalSynthesisParameters; - public void setIndicatorValues(Map<SynthesisId, Double> indicatorValues) { this.values = indicatorValues; } - public void setGlobalSynthesisParameters(List<Indicator> globalSynthesisParameters) { - this.globalSynthesisParameters = globalSynthesisParameters; - } - @Override - public List<Indicator> getGlobalSynthesisParameters() { - return globalSynthesisParameters; - } - - /** in the list of indicators, find the one with given synthesisId. */ - protected Indicator findIndicator(SynthesisId id) { - for (Indicator indicator : globalSynthesisParameters) { - if (indicator.getSynthesisId().equals(id)) { - return indicator; - } - } - return null; - } - - @Override public IndicatorLevel getLevelForIndicator(SynthesisId synthesisId) { if (log.isDebugEnabled()) { log.debug("looking for value of " + synthesisId); @@ -52,7 +30,7 @@ Double value = values.get(synthesisId); IndicatorLevel result = null; if (value != null) { - Indicator indicator = findIndicator(synthesisId); + Indicator indicator = globalSynthesisParameters.getParameter(synthesisId); result = indicator.getLevelForValue(value); } return result; @@ -65,7 +43,7 @@ double totalLevels = 0.0; double totalCoefficients = 0.0; - for (Indicator indicator : globalSynthesisParameters) { + for (Indicator indicator : globalSynthesisParameters.getParameters()) { IndicatorLevel indicatorLevel = getLevelForIndicator(indicator.getSynthesisId()); if (indicatorLevel == null) { @@ -92,18 +70,22 @@ log.debug("value for global indicator = " + value); } - GlobalIndicatorValue result = null; - if (value >= 1.0 && value < 2.0) { - result = GlobalIndicatorValue.VERY_BAD; - } else if (value >= 2.0 && value < 3.0) { - result = GlobalIndicatorValue.BAD; - } else if (value >= 3.0 && value < 5.0) { - result = GlobalIndicatorValue.NEUTRAL; - } else if (value >= 5.0 && value < 5.5) { - result = GlobalIndicatorValue.GOOD; - } else if (value >= 5.5 && value <= 6.0) { - result = GlobalIndicatorValue.VERY_GOOD; + // in this indicator, the level is the ordinal of GlobalIndicatorValue + Indicator globalIndicator = getGlobalSynthesisParameters().getGlobalIndicator(); + + if (log.isDebugEnabled()) { + log.debug("levels for global indicator are"); + for (IndicatorLevel level : globalIndicator.getIndicatorLevel()) { + log.debug(level.getLevel() + " -> " + level.getLowerBound() + + " to " + level.getUpperBound()); + } } + + int globalIndicatorValueOrdinal = globalIndicator.getLevelForValue(value).getLevel(); + GlobalIndicatorValue result = GlobalIndicatorValue.valueOf(globalIndicatorValueOrdinal); + if (log.isDebugEnabled()) { + log.debug("global indicator value is " + result); + } return result; } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/IndicatorImpl.java 2010-11-03 11:22:57 UTC (rev 732) @@ -14,7 +14,11 @@ @Override public SynthesisId getSynthesisId() { - return SynthesisId.valueOf(getIndicatorId()); + SynthesisId result = null; + if (getIndicatorId() != null) { + result = SynthesisId.valueOf(getIndicatorId()); + } + return result; } @Override Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-11-03 11:22:57 UTC (rev 732) @@ -830,21 +830,20 @@ value = getIndicatorValueForDataReliability(filter); indicatorValues.put(SynthesisId.IND_DATA_RELIABILITY, value); - GlobalSynthesisResultImpl result = null; - - result = new GlobalSynthesisResultImpl(); - List<Indicator> indicators = executeGetGlobalSynthesisParameters(transaction); + GlobalSynthesisResultImpl result = new GlobalSynthesisResultImpl(); + GlobalSynthesisParameters parameters = executeGetGlobalSynthesisParameters(transaction); result.setIndicatorValues(indicatorValues); - result.setGlobalSynthesisParameters(indicators); + result.setGlobalSynthesisParameters(parameters); return result; } @Override - protected List<Indicator> executeGetGlobalSynthesisParameters(TopiaContext transaction) throws Exception { + protected GlobalSynthesisParameters executeGetGlobalSynthesisParameters(TopiaContext transaction) throws Exception { IndicatorDAO indicatorDAO = WaoDAOHelper.getIndicatorDAO(transaction); List<Indicator> indicators = indicatorDAO.findAll(); + Indicator globalIndicator = null; // will be found in the list for (Indicator indicator : indicators) { @@ -853,7 +852,12 @@ double lowerBound; double lastUpperBound; - if (indicator.getSynthesisId() == SynthesisId.IND_ALLEGRO_REACTIVITY) { + if (indicator.getSynthesisId() == null) { + // this is the global average parameters + globalIndicator = indicator; + lowerBound = 1.0; + lastUpperBound = 6.0; + } else if (indicator.getSynthesisId() == SynthesisId.IND_ALLEGRO_REACTIVITY) { lowerBound = Double.MAX_VALUE; lastUpperBound = 0.0; } else { @@ -880,7 +884,13 @@ // but database should not be affected } - return indicators; + indicators.remove(globalIndicator); + + GlobalSynthesisParameters result = new GlobalSynthesisParametersImpl(); + result.setParameters(indicators); + result.setGlobalIndicator(globalIndicator); + + return result; } @Override Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-11-03 11:22:57 UTC (rev 732) @@ -29,11 +29,11 @@ import fr.ifremer.wao.WaoException; import fr.ifremer.wao.WaoProperty; import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.bean.GlobalSynthesisParameters; import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.CompanyImpl; import fr.ifremer.wao.entity.Indicator; -import fr.ifremer.wao.entity.IndicatorLevel; import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.io.ImportResults; import fr.ifremer.wao.io.ImportResultsImpl; @@ -79,8 +79,6 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; import java.util.List; /** @@ -610,34 +608,19 @@ @Inject private ServiceSynthesis serviceSynthesis; + private GlobalSynthesisParameters globalSynthesisParameters; + /* variable used in view */ @Property private Indicator indicator; - /* variable used in view */ - private List<Indicator> indicators; - - /** Sum of the coefficient of the indicators. */ - private Double totalCoefficient; - - public Double getTotalCoefficient() { - if (totalCoefficient == null) { - totalCoefficient = 0.0; - for (Indicator indicator : getIndicators()) { - totalCoefficient += indicator.getCoefficient(); - } + public GlobalSynthesisParameters getGlobalSynthesisParameters() { + if (globalSynthesisParameters == null) { + globalSynthesisParameters = serviceSynthesis.getGlobalSynthesisParameters(); } - return totalCoefficient; + return globalSynthesisParameters; } - public List<Indicator> getIndicators() { - if (indicators == null) { - indicators = serviceSynthesis.getGlobalSynthesisParameters(); - } - return indicators; - } - - @InjectComponent private Form synthesisParametersForm; @@ -655,7 +638,7 @@ } void onSuccessFromSynthesisParametersForm() { - for (Indicator indicator : getIndicators()) { + for (Indicator indicator : getGlobalSynthesisParameters().getParameters()) { serviceSynthesis.updateGlobalSynthesisParameter (indicator, currentUser.getUser(), comment); } 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-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-11-03 11:22:57 UTC (rev 732) @@ -31,6 +31,7 @@ import fr.ifremer.wao.bean.ContactState; import fr.ifremer.wao.bean.ContactStateStatistics; import fr.ifremer.wao.bean.GlobalIndicatorValue; +import fr.ifremer.wao.bean.GlobalSynthesisParameters; import fr.ifremer.wao.bean.GlobalSynthesisResult; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.SamplingFilterImpl; @@ -129,22 +130,10 @@ return activeSynthesis; } - /** in a list of indicators, find the one with given synthesisId. */ - protected Indicator findIndicator(SynthesisId id, - List<Indicator> indicators) { - for (Indicator indicator : indicators) { - if (indicator.getSynthesisId().equals(id)) { - return indicator; - } - } - log.warn("indicator not found : " + id); - return null; - } + private GlobalSynthesisParameters globalSynthesisParameters; - private List<Indicator> globalSynthesisParameters; - /** permit lazy call to serviceSynthesis to set globalSynthesisParameters field. */ - public List<Indicator> getGlobalSynthesisParameters() { + public GlobalSynthesisParameters getGlobalSynthesisParameters() { if (globalSynthesisParameters == null) { globalSynthesisParameters = getGlobalSynthesisResult().getGlobalSynthesisParameters(); @@ -166,8 +155,7 @@ */ public Indicator getActiveIndicator() { SynthesisId activeSynthesis = getActiveSynthesis(); - List<Indicator> globalSynthesisParameters = getGlobalSynthesisParameters(); - activeIndicator = findIndicator(activeSynthesis, globalSynthesisParameters); + activeIndicator = getGlobalSynthesisParameters().getParameter(activeSynthesis); return activeIndicator; } Modified: trunk/wao-ui/src/main/webapp/Administration.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Administration.tml 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-ui/src/main/webapp/Administration.tml 2010-11-03 11:22:57 UTC (rev 732) @@ -182,14 +182,14 @@ <t:errors t:banner="message:errors-banner" /> <!-- ALL ACTUAL VALUES FOR INDICATORS OF GLOBAL SYNTHESIS --> - <t:loop t:source="indicators" t:value="indicator" volatile="true"> + <t:loop t:source="globalSynthesisParameters.parameters" t:value="indicator" volatile="true"> <t:indicatorLevels t:indicator="indicator" editable="true" /> </t:loop> <table class="indicatorLevels"> <tr> <th>Total coefficients : </th> - <td>${totalCoefficient}</td> + <td>${globalSynthesisParameters.totalCoefficients}</td> </tr> </table> Modified: trunk/wao-ui/src/main/webapp/Synthesis.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Synthesis.tml 2010-11-03 09:10:05 UTC (rev 731) +++ trunk/wao-ui/src/main/webapp/Synthesis.tml 2010-11-03 11:22:57 UTC (rev 732) @@ -359,7 +359,7 @@ <h2>Synthèse globale</h2> <br /> - <t:loop t:source="globalSynthesisParameters" t:value="activeIndicator"> + <t:loop t:source="globalSynthesisParameters.parameters" t:value="activeIndicator"> <t:indicatorLevels t:indicator="activeIndicator" t:highlightLevel="activeIndicatorLevel" /> </t:loop>