This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository wao. See http://git.codelutin.com/wao.git commit 92dc9de394e2e65d86acf5fc4f04e9515ba2e27b Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Oct 9 18:29:52 2014 +0200 Dans ObsMerSamplingPlanService, on sépare les préoccupations entre calcul de la clé du cache, lecture du cache et calcul du plan --- .../service/ObsMerSamplingPlanService.java | 100 ++++++++++++--------- .../wao/services/service/SamplingPlanCacheKey.java | 12 +++ 2 files changed, 70 insertions(+), 42 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java index ff1fd94..2bd85ab 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java @@ -63,6 +63,7 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { SampleRowsFilter sampleRowsFilter) { Locale locale = serviceContext.getLocale(); + if (log.isDebugEnabled()) { log.debug("a sampling plan with locale " + locale + " is asked"); } @@ -78,6 +79,14 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { optionalCompanyId, sampleRowsFilter); + ObsMerSamplingPlan result = getSamplingPlan(samplingPlanCacheKey); + + return result; + + } + + protected ObsMerSamplingPlan getSamplingPlan(SamplingPlanCacheKey samplingPlanCacheKey) { + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache = serviceContext.getSamplingPlansCache(); @@ -85,54 +94,61 @@ public class ObsMerSamplingPlanService extends SamplingPlanService { if (result == null) { - SampleRowTopiaDao dao = getSampleRowDao(); - ContactTopiaDao contactDao = getContactDao(); - - // recuperation des lignes du plan - List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); - - // creation du plan d'echantillonnage - ObsMerSamplingPlanBuilder builder = new ObsMerSamplingPlanBuilder( - locale, - optionalCompanyId, - sampleRowsFilter); - - // begin of month - Date periodFrom = sampleRowsFilter.getPeriodFrom(); - // end of month - Date periodTo = WaoUtils.getEndOfMonth(sampleRowsFilter.getPeriodTo()); - - for (SampleRow sampleRow : sampleRows) { - - // calcul effort plannifie - Integer observationTimesInDaysExpected = - getObservationTimesInDayExpected(periodFrom, - periodTo, - sampleRow); - - Pair<Long, Long> realAndEstimated = - getSampleRowObservationTimesInDayRealAndEstimated( - sampleRow.getTopiaId(), periodFrom, periodTo); - Long observationTimesInDaysReal = realAndEstimated.getLeft(); - Long observationTimesInDaysEstimated = realAndEstimated.getRight(); - - long sampleRowContactCounts = contactDao.forSampleRowEquals(sampleRow).count(); - - // ajout de la ligne au build de plan - builder.addSampleRow(sampleRow, - observationTimesInDaysExpected, - observationTimesInDaysReal, - observationTimesInDaysEstimated, - sampleRowContactCounts); - } - result = builder.toPlan(); + result = computeSamplingPlan(samplingPlanCacheKey); samplingPlansCache.put(samplingPlanCacheKey.clone(), result); } - return result; + } + + protected ObsMerSamplingPlan computeSamplingPlan(SamplingPlanCacheKey samplingPlanCacheKey) { + + SampleRowsFilter sampleRowsFilter = samplingPlanCacheKey.getSampleRowsFilter(); + SampleRowTopiaDao dao = getSampleRowDao(); + List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); + + // creation du plan d'echantillonnage + ObsMerSamplingPlanBuilder builder = new ObsMerSamplingPlanBuilder( + samplingPlanCacheKey.getLocale(), + samplingPlanCacheKey.getOptionalCompanyId(), + sampleRowsFilter); + + // begin of month + Date periodFrom = sampleRowsFilter.getPeriodFrom(); + // end of month + Date periodTo = WaoUtils.getEndOfMonth(sampleRowsFilter.getPeriodTo()); + + ContactTopiaDao contactDao = getContactDao(); + for (SampleRow sampleRow : sampleRows) { + + // calcul effort plannifie + Integer observationTimesInDaysExpected = + getObservationTimesInDayExpected(periodFrom, + periodTo, + sampleRow); + + Pair<Long, Long> realAndEstimated = + getSampleRowObservationTimesInDayRealAndEstimated( + sampleRow.getTopiaId(), periodFrom, periodTo); + Long observationTimesInDaysReal = realAndEstimated.getLeft(); + Long observationTimesInDaysEstimated = realAndEstimated.getRight(); + + long sampleRowContactCounts = contactDao.forSampleRowEquals(sampleRow).count(); + + // ajout de la ligne au build de plan + builder.addSampleRow(sampleRow, + observationTimesInDaysExpected, + observationTimesInDaysReal, + observationTimesInDaysEstimated, + sampleRowContactCounts); + + } + + ObsMerSamplingPlan result = builder.toPlan(); + + return result; } /** diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java index 085dd66..de55ec5 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanCacheKey.java @@ -41,6 +41,18 @@ public class SamplingPlanCacheKey implements WaoCacheKey { this.sampleRowsFilter = sampleRowsFilter; } + public Locale getLocale() { + return locale; + } + + public Optional<String> getOptionalCompanyId() { + return optionalCompanyId; + } + + public SampleRowsFilter getSampleRowsFilter() { + return sampleRowsFilter; + } + @Override public boolean equals(Object o) { if (this == o) return true; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.