Commit 65b89198 authored by PECQUOT's avatar PECQUOT
Browse files

[enh] upgrade quadrige3-core to 3.2.2 : migrate model to manage PMFMU (Mantis #45005)

[enh] change some date properties to LocalDate (java8)

git-svn-id: https://scmforge.ifremer.fr/authscm/lp1ee9d/svn/reefdb/trunk@2375 cd918a83-917d-4a2a-92d7-bc1d03929fc5
parent b08d52e8
......@@ -182,7 +182,8 @@
<maven.compiler.debug>true</maven.compiler.debug>
<!-- Quadrige3 Core version -->
<quadrige3-core.version>3.1.23</quadrige3-core.version>
<!--<quadrige3-core.version>3.1.24-SNAPSHOT</quadrige3-core.version>-->
<quadrige3-core.version>3.2.2-SNAPSHOT</quadrige3-core.version>
<!-- Last ReefDb launcher version -->
<launcherVersion>3.0.3</launcherVersion>
......
......@@ -23,7 +23,6 @@ package fr.ifremer.reefdb.dao.administration.strategy;
* #L%
*/
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
......@@ -31,7 +30,6 @@ import com.google.common.collect.*;
import fr.ifremer.quadrige3.core.dao.administration.program.ProgramImpl;
import fr.ifremer.quadrige3.core.dao.administration.strategy.*;
import fr.ifremer.quadrige3.core.dao.administration.user.DepartmentImpl;
import fr.ifremer.quadrige3.core.dao.administration.user.Quser;
import fr.ifremer.quadrige3.core.dao.administration.user.QuserImpl;
import fr.ifremer.quadrige3.core.dao.referential.AcquisitionLevel;
import fr.ifremer.quadrige3.core.dao.referential.AcquisitionLevelCode;
......@@ -50,7 +48,6 @@ import fr.ifremer.reefdb.dto.ReefDbBeanFactory;
import fr.ifremer.reefdb.dto.ReefDbBeans;
import fr.ifremer.reefdb.dto.configuration.programStrategy.*;
import fr.ifremer.reefdb.dto.referential.DepartmentDTO;
import fr.ifremer.reefdb.dto.referential.PersonDTO;
import fr.ifremer.reefdb.service.ReefDbTechnicalException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
......@@ -233,17 +230,16 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
Preconditions.checkNotNull(date);
List<ProgStratDTO> strategies = getStrategiesByProgramCodeAndMonitoringLocationId(programCode, monitoringLocationId);
Set<PmfmStrategyDTO> pmfms = Sets.newHashSet();
Set<PmfmStrategyDTO> pmfmStrategies = Sets.newHashSet();
for (ProgStratDTO strategy : strategies) {
// also filter pmfm on date
if (strategy.getStartDate() != null && strategy.getEndDate() != null && Dates.isBetween(date, strategy.getStartDate(), strategy.getEndDate())) {
List<PmfmStrategyDTO> pmfmStrategies = getPmfmsAppliedStrategy(strategy.getId());
pmfms.addAll(pmfmStrategies);
pmfmStrategies.addAll(getPmfmsAppliedStrategy(strategy.getId()));
}
}
return pmfms;
return pmfmStrategies;
}
/** {@inheritDoc} */
......@@ -418,7 +414,7 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
}
// build key for applied period
String appliedStrategyKey = buildAppliedStrategyKey(appliedStrategy, dbTimezone);
String appliedStrategyKey = buildAppliedStrategyKey(appliedStrategy);
// get existing applied strategy with applied period
AppliedStrategy existingAppliedStrategy = remainingAppliedStrategyByKey.remove(appliedStrategyKey);
if (existingAppliedStrategy == null && appliedStrategy.getStartDate() != null && appliedStrategy.getEndDate() != null) {
......@@ -435,7 +431,7 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
AppliedPeriod periodToUpdate = null;
for (AppliedPeriod existingPeriod : targetAppliedStrategy.getAppliedPeriods()) {
LocalDate startDate = Dates.convertToLocalDate(existingPeriod.getAppliedPeriodPk().getAppliedPeriodStartDt(), dbTimezone);
if (isSameDay(startDate, appliedStrategy.getStartDate())) {
if (Dates.isSameDay(startDate, appliedStrategy.getStartDate())) {
periodToUpdate = existingPeriod;
break;
}
......@@ -477,7 +473,7 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
AppliedPeriod appliedPeriod = it.next();
LocalDate appliedPeriodStartDate = Dates.convertToLocalDate(appliedPeriod.getAppliedPeriodStartDt(), dbTimezone);
LocalDate appliedPeriodEndDate = Dates.convertToLocalDate(appliedPeriod.getAppliedPeriodEndDt(), dbTimezone);
if (isSameDay(appliedPeriodStartDate, startDate) && isSameDay(appliedPeriodEndDate, endDate)) {
if (Dates.isSameDay(appliedPeriodStartDate, startDate) && Dates.isSameDay(appliedPeriodEndDate, endDate)) {
it.remove();
}
}
......@@ -709,7 +705,7 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
create = true;
} else {
appliedPeriod = appliedPeriods.iterator().next();
if (!isSameDay(Dates.convertToLocalDate(appliedPeriod.getAppliedPeriodStartDt(), dbTimezone), strategy.getStartDate())) {
if (!Dates.isSameDay(Dates.convertToLocalDate(appliedPeriod.getAppliedPeriodStartDt(), dbTimezone), strategy.getStartDate())) {
// update by delete and create, because update start date doesn't work
target.getAppliedPeriods().clear();
create = true;
......@@ -773,7 +769,7 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
return result;
}
private String buildAppliedStrategyKey(AppliedStrategyDTO appliedStrategy, TimeZone dbTimezone) {
private String buildAppliedStrategyKey(AppliedStrategyDTO appliedStrategy) {
Preconditions.checkNotNull(appliedStrategy);
Preconditions.checkNotNull(appliedStrategy.getId());
return Joiner.on('|').useForNull("null").join(
......@@ -783,10 +779,6 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
);
}
private String formatAppliedStrategyDate(Date date) {
return Dates.formatDate(date, DATE_PATTERN);
}
private String formatAppliedStrategyDate(LocalDate date) {
return date.format(DateTimeFormatter.ofPattern(DATE_PATTERN));
}
......@@ -795,12 +787,6 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
return LocalDate.parse(string, DateTimeFormatter.ofPattern(DATE_PATTERN));
}
private boolean isSameDay(LocalDate date1, LocalDate date2) {
if (date1 == null && date2 == null) return true;
if (date1 == null || date2 == null) return false;
return date1.equals(date2);
}
private StrategyDTO toStrategyDTO(Iterator<Object> source) {
StrategyDTO result = ReefDbBeanFactory.newStrategyDTO();
......@@ -954,7 +940,7 @@ public class ReefDbStrategyDaoImpl extends StrategyDaoImpl implements ReefDbStra
Daos.replaceEntities(
target.getQusers(),
program.getManagerPersons(),
(Function<PersonDTO, Quser>) person -> load(QuserImpl.class, person.getId())
person -> load(QuserImpl.class, person.getId())
);
}
}
......
......@@ -29,6 +29,7 @@ import fr.ifremer.quadrige3.core.dao.referential.monitoringLocation.ProjectionSy
import fr.ifremer.quadrige3.core.dao.system.extraction.*;
import fr.ifremer.quadrige3.core.dao.system.filter.Filter;
import fr.ifremer.quadrige3.core.dao.system.filter.FilterTypeId;
import fr.ifremer.quadrige3.core.dao.technical.Dates;
import fr.ifremer.quadrige3.core.service.technical.CacheService;
import fr.ifremer.reefdb.config.ReefDbConfiguration;
import fr.ifremer.reefdb.dao.technical.Daos;
......@@ -273,8 +274,8 @@ public class ReefDbExtractionDaoImpl extends ExtractFilterDaoImpl implements Ree
extractSurveyPeriod.setExtractFilter(entity);
isNew = true;
}
extractSurveyPeriod.setExtractSurveyPeriodStartDt(period.getStartDate());
extractSurveyPeriod.setExtractSurveyPeriodEndDt(period.getEndDate());
extractSurveyPeriod.setExtractSurveyPeriodStartDt(Dates.convertToDate(period.getStartDate(), config.getDbTimezone()));
extractSurveyPeriod.setExtractSurveyPeriodEndDt(Dates.convertToDate(period.getEndDate(), config.getDbTimezone()));
if (isNew) {
getSession().save(extractSurveyPeriod);
......@@ -393,8 +394,8 @@ public class ReefDbExtractionDaoImpl extends ExtractFilterDaoImpl implements Ree
Object[] row = rows.next();
ExtractionPeriodDTO period = ReefDbBeanFactory.newExtractionPeriodDTO();
period.setId((Integer) row[0]);
period.setStartDate(Daos.convertToDate(row[1]));
period.setEndDate(Daos.convertToDate(row[2]));
period.setStartDate(Dates.convertToLocalDate(Daos.convertToDate(row[1]), config.getDbTimezone()));
period.setEndDate(Dates.convertToLocalDate(Daos.convertToDate(row[2]), config.getDbTimezone()));
periods.add(period);
}
return periods;
......
......@@ -6,17 +6,17 @@ package fr.ifremer.reefdb.dao.system.rule;
* %%
* Copyright (C) 2014 - 2018 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
* 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%
*/
......
......@@ -29,6 +29,7 @@ import com.google.common.base.Splitter;
import com.google.common.collect.*;
import fr.ifremer.quadrige3.core.dao.referential.UnitId;
import fr.ifremer.quadrige3.core.dao.technical.Beans;
import fr.ifremer.quadrige3.core.dao.technical.Dates;
import fr.ifremer.quadrige3.core.dao.technical.Times;
import fr.ifremer.quadrige3.synchro.vo.SynchroDateOperatorVO;
import fr.ifremer.reefdb.dao.technical.Daos;
......@@ -488,7 +489,9 @@ public class ReefDbBeans {
} else if (bean instanceof ExtractionPeriodDTO) {
ExtractionPeriodDTO period = (ExtractionPeriodDTO) bean;
return DateUtil.formatDate(period.getStartDate(), DEFAULT_DATE_FORMAT) + " => " + DateUtil.formatDate(period.getEndDate(), DEFAULT_DATE_FORMAT);
return Dates.formatDate(period.getStartDate(), DEFAULT_DATE_FORMAT)
+ " => "
+ Dates.formatDate(period.getEndDate(), DEFAULT_DATE_FORMAT);
}
return bean.toString();
......
......@@ -24,13 +24,12 @@ package fr.ifremer.reefdb.service.extraction;
*/
import au.com.bytecode.opencsv.CSVWriter;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import fr.ifremer.quadrige3.core.dao.technical.Dates;
import fr.ifremer.reefdb.config.ReefDbConfiguration;
import fr.ifremer.reefdb.dao.referential.pmfm.ReefDbPmfmDao;
import fr.ifremer.reefdb.dao.system.extraction.ReefDbExtractionDao;
......@@ -302,7 +301,7 @@ public class ExtractionServiceImpl implements ExtractionService {
progressionModel.increments(1);
// Mantis #29139: remove all individual measurement on survey
pmfmInfos = ReefDbBeans.filterCollection(pmfmInfos, (Predicate<ExtractionPmfmInfoDTO>) input -> !(input.isSurvey() && input.isIndividual()));
pmfmInfos = ReefDbBeans.filterCollection(pmfmInfos, input -> !(input.isSurvey() && input.isIndividual()));
if (CollectionUtils.isEmpty(pmfmInfos)) {
throw new ReefDbBusinessException(t("reefdb.service.extraction.noPmfm.error"));
......@@ -1101,7 +1100,7 @@ public class ExtractionServiceImpl implements ExtractionService {
String commentField = "NULL AS MEAS_CM, ";
// get only individual pmfm info
List<ExtractionPmfmInfoDTO> individualPmfmInfos = ReefDbBeans.filterCollection(context.getPmfmInfos(), (Predicate<ExtractionPmfmInfoDTO>) input -> input.isIndividual());
List<ExtractionPmfmInfoDTO> individualPmfmInfos = ReefDbBeans.filterCollection(context.getPmfmInfos(), ExtractionPmfmInfoDTO::isIndividual);
if (individualPmfmInfos.size() >= 2) {
// must coalesce these fields
......@@ -1332,7 +1331,7 @@ public class ExtractionServiceImpl implements ExtractionService {
private String getAliasedFields(List<ExtractionPmfmInfoDTO> pmfmInfos, final String fieldName) {
return Joiner.on(',').join(ReefDbBeans.transformCollection(pmfmInfos, (Function<ExtractionPmfmInfoDTO, String>) pmfmInfo -> pmfmInfo.getAlias() + "_" + fieldName));
return Joiner.on(',').join(ReefDbBeans.transformCollection(pmfmInfos, pmfmInfo -> pmfmInfo.getAlias() + "_" + fieldName));
}
private Map<String, Object> getQueryBindings(ExtractionDTO extraction) {
......@@ -1340,8 +1339,8 @@ public class ExtractionServiceImpl implements ExtractionService {
FilterDTO periodFilter = getPeriodFilter(extraction);
for (int i = 0; i < periodFilter.getElements().size(); i++) {
ExtractionPeriodDTO period = (ExtractionPeriodDTO) periodFilter.getElements().get(i);
bindings.put(EXTRACTION_START_DATE + i, period.getStartDate());
bindings.put(EXTRACTION_END_DATE + i, period.getEndDate());
bindings.put(EXTRACTION_START_DATE + i, Dates.convertToDate(period.getStartDate(), config.getDbTimezone()));
bindings.put(EXTRACTION_END_DATE + i, Dates.convertToDate(period.getEndDate(), config.getDbTimezone()));
}
return bindings;
}
......
......@@ -811,7 +811,7 @@ public class ControlRuleServiceImpl implements ControlRuleService {
}
/**
* Valid date with rule control.
* Valid local date with rule control.
*
* @param dateValue Date
* @param rule Rule apply
......@@ -1206,7 +1206,8 @@ public class ControlRuleServiceImpl implements ControlRuleService {
return rulesBySurveyMap.computeIfAbsent(survey,
rules -> ruleDao.findActiveControlRules(
Dates.convertToDate(survey.getDate(), configuration.getDbTimezone()),
survey.getProgram().getCode(), survey.getDepartment().getId()));
survey.getProgram().getCode(),
survey.getDepartment().getId()));
}
private ErrorDTO newControlError(ControlElementValues controlElementValue) {
......
......@@ -332,7 +332,8 @@ public class RuleListServiceImpl implements RuleListService {
List<ControlRuleDTO> preconditionedRules = ruleDao.findActivePreconditionedRules(
Dates.convertToDate(survey.getDate(), configuration.getDbTimezone()),
survey.getProgram().getCode(), survey.getDepartment().getId());
survey.getProgram().getCode(),
survey.getDepartment().getId());
buildPmfmInformation(preconditionedRules);
return preconditionedRules;
}
......
......@@ -37,13 +37,11 @@ import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.nuiton.util.DateUtil;
import java.time.LocalDate;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.*;
/**
*
......@@ -162,8 +160,8 @@ public class StrategyDaoReadTest extends AbstractDaoTest {
}
assertEquals((Integer) 1, locations.get(0).getId());
assertEquals(DateUtil.createDate(1, 9, 2004), locations.get(0).getStartDate());
assertEquals(DateUtil.createDate(1, 7, 2010), locations.get(0).getEndDate());
assertEquals(LocalDate.of(2004,9,1), locations.get(0).getStartDate());
assertEquals(LocalDate.of(2010,7,1), locations.get(0).getEndDate());
assertNotNull(locations.get(0).getDepartment());
assertEquals((Integer) 5, locations.get(0).getDepartment().getId());
}
......
......@@ -31,12 +31,12 @@ import fr.ifremer.reefdb.dao.administration.user.ReefDbDepartmentDao;
import fr.ifremer.reefdb.dao.referential.ReefDbReferentialDao;
import fr.ifremer.reefdb.dao.referential.monitoringLocation.ReefDbMonitoringLocationDao;
import fr.ifremer.reefdb.dao.technical.Geometries;
import fr.ifremer.reefdb.dto.CoordinateDTO;
import fr.ifremer.reefdb.dto.ReefDbBeanFactory;
import fr.ifremer.reefdb.dto.ReefDbBeans;
import fr.ifremer.reefdb.dto.data.survey.*;
import fr.ifremer.reefdb.dto.data.survey.SurveyDTO;
import fr.ifremer.reefdb.dto.enums.SynchronizationStatusValues;
import fr.ifremer.reefdb.dto.referential.DepthDTO;
import fr.ifremer.reefdb.dto.CoordinateDTO;
import fr.ifremer.reefdb.service.ReefDbServiceLocator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
......@@ -44,7 +44,6 @@ import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import java.sql.Date;
import java.time.LocalDate;
import java.util.List;
......@@ -92,7 +91,7 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
survey.setPreciseDepth(15.2);
// survey.setControlDate(Date.valueOf("2015-02-06"));
// survey.setValidationDate(Date.valueOf("2015-02-07"));
survey.setValidationComment("validation date comment");
// survey.setValidationComment("validation date comment");
survey.setCampaign(campaignDao.getAllCampaigns().get(0));
survey.setProgram(programDao.getProgramByCode("REMIS"));
survey.setOccasion(null);
......@@ -116,14 +115,14 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
testSurveyId = survey.getId();
// assert all values after save
assertSurveyEquals(surveyBase, survey);
assertSurveyEquals(surveyBase, survey, false);
// reload
survey = getSurveyTest();
assertNotNull(survey);
// assert all values
assertSurveyEquals(surveyBase, survey);
assertSurveyEquals(surveyBase, survey, false);
// modify all values
survey.setName("test survey 2");
......@@ -131,9 +130,9 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
survey.setDate(LocalDate.of(2015,1,1));
survey.setTime(1252d);
survey.setPreciseDepth(15.2);
survey.setControlDate(Date.valueOf("2015-03-08"));
// survey.setControlDate(Date.valueOf("2015-03-08"));
// survey.setValidationDate(Date.valueOf("2015-04-16"));
survey.setValidationComment("validation date comment 2");
// survey.setValidationComment("validation date comment 2");
survey.setCampaign(campaignDao.getAllCampaigns().get(1));
survey.setProgram(programDao.getProgramByCode("REBENT"));
survey.setOccasion(null);
......@@ -161,14 +160,14 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
assertEquals(testSurveyId, survey.getId());
// assert all values before save
assertSurveyEquals(surveyBase, survey);
assertSurveyEquals(surveyBase, survey, false);
// reload
survey = getSurveyTest();
assertNotNull(survey);
// assert all values
assertSurveyEquals(surveyBase, survey);
assertSurveyEquals(surveyBase, survey, true);
/*
* DETAILED PART
......@@ -178,7 +177,7 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
assertEquals(testSurveyId, surveyDetail.getId()); // ça c'est du test ^^
// check base fields
assertSurveyEquals(surveyBase, surveyDetail);
assertSurveyEquals(surveyBase, surveyDetail, true);
// set other detailed fields
surveyDetail.setPositioningComment("positioning comment");
......@@ -200,12 +199,12 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
assertEquals(testSurveyId, surveyDetail.getId());
// compare to base
assertSurveyEquals(surveyDetailBase, surveyDetail);
assertSurveyEquals(surveyDetailBase, surveyDetail, false);
// reload and compare
surveyDetail = surveyDao.getSurveyById(testSurveyId, false);
assertSurveyEquals(surveyDetailBase, surveyDetail);
assertSurveyEquals(surveyDetailBase, surveyDetail, false);
// modify all fields
surveyDetail.setName("test survey 3");
......@@ -213,9 +212,9 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
surveyDetail.setDate(LocalDate.of(2015,4,7));
surveyDetail.setTime(1953d);
surveyDetail.setPreciseDepth(12.90);
surveyDetail.setControlDate(Date.valueOf("2015-05-20"));
// surveyDetail.setControlDate(Date.valueOf("2015-05-20"));
// surveyDetail.setValidationDate(Date.valueOf("2015-05-21"));
surveyDetail.setValidationComment("validation date comment 3");
// surveyDetail.setValidationComment("validation date comment 3");
surveyDetail.setCampaign(campaignDao.getAllCampaigns().get(2));
surveyDetail.setProgram(programDao.getProgramByCode("RNOHYD"));
surveyDetail.setOccasion(null);
......@@ -231,7 +230,7 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
// save, reload and compare
surveyDao.save(surveyDetail);
surveyDetail = surveyDao.getSurveyById(testSurveyId, false);
assertSurveyEquals(surveyDetailBase, surveyDetail);
assertSurveyEquals(surveyDetailBase, surveyDetail, false);
// some nulls
surveyDetail.setControlDate(null);
......@@ -241,7 +240,7 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
surveyDetailBase = ReefDbBeans.clone(surveyDetail);
surveyDao.save(surveyDetail);
surveyDetail = surveyDao.getSurveyById(testSurveyId, false);
assertSurveyEquals(surveyDetailBase, surveyDetail);
assertSurveyEquals(surveyDetailBase, surveyDetail, false);
// delete
surveyDao.remove(Lists.newArrayList(testSurveyId));
......@@ -266,7 +265,7 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
return survey;
}
private void assertSurveyEquals(SurveyDTO surveyBase, SurveyDTO surveyToControl) {
private void assertSurveyEquals(SurveyDTO surveyBase, SurveyDTO surveyToControl, boolean exceptDepartment) {
assertEquals(surveyBase.getName(), surveyToControl.getName());
assertEquals(surveyBase.getComment(), surveyToControl.getComment());
......@@ -284,9 +283,14 @@ public class SurveyDaoWriteTest extends AbstractDaoTest {
assertEquals(surveyBase.getPositioning(), surveyToControl.getPositioning());
assertEquals(surveyBase.getPositioningComment(), surveyToControl.getPositioningComment());
assertCoordinateEquals(surveyBase.getCoordinate(), surveyToControl.getCoordinate());
assertEquals(surveyBase.getDepartment(), surveyToControl.getDepartment());
assertEquals(surveyBase.getSynchronizationStatus(), surveyToControl.getSynchronizationStatus());
if (exceptDepartment) {
assertNotEquals(surveyBase.getDepartment(), surveyToControl.getDepartment());
} else {
assertEquals(surveyBase.getDepartment(), surveyToControl.getDepartment());
}
}
private void assertCoordinateEquals(CoordinateDTO coordinateBase, CoordinateDTO coordinateToControl) {
......
......@@ -64,7 +64,7 @@ public class TaxonGroupDaoReadTest extends AbstractDaoTest {
public void getAllTaxonGroupDTOs() {
List<TaxonGroupDTO> TaxonGroupDTOs = dao.getAllTaxonGroups();
assertNotNull(TaxonGroupDTOs);
assertEquals(12, TaxonGroupDTOs.size());
assertEquals(7, TaxonGroupDTOs.size());
if (log.isDebugEnabled()) {
for (TaxonGroupDTO dto : TaxonGroupDTOs) {
......
......@@ -70,7 +70,7 @@ public class RuleListDaoReadTest extends AbstractDaoTest {
}
// RULELIST1 comes from test dataset only
RuleListDTO ruleList = ruleListDao.getRuleList("RULELIST1");
RuleListDTO ruleList = ruleListDao.getRuleList(dbResource.getFixtures().getRuleListCode(0));
assertNotNull(ruleList);
assertEquals("rule list 1", ruleList.getDescription());
......
......@@ -43,15 +43,13 @@ import fr.ifremer.reefdb.service.referential.ReferentialService;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assume;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.*;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.Assert.*;
......@@ -64,6 +62,8 @@ public class ProgramStrategyServiceWriteTest {
public static final ReefDbDatabaseResource dbResource = ReefDbDatabaseResource.writeDb();
private static final Log log = LogFactory.getLog(ProgramStrategyServiceWriteTest.class);
private static final String PROGRAM_CODE = "TEST";
private static final String STRATEGY_1_NAME = "strategy 1 test";
private static final String STRATEGY_2_NAME = "strategy 2 test";
private ProgramStrategyService service;
private ReferentialService referentialService;
......@@ -95,7 +95,7 @@ public class ProgramStrategyServiceWriteTest {
// create a strategy
StrategyDTO strategy1 = ReefDbBeanFactory.newStrategyDTO();
strategy1.setName("strategy 1 test");
strategy1.setName(STRATEGY_1_NAME);
strategy1.setComment("comment");
for (LocationDTO location : program.getLocations()) {
AppliedStrategyDTO as = ReefDbBeanFactory.newAppliedStrategyDTO();
......@@ -119,10 +119,9 @@ public class ProgramStrategyServiceWriteTest {
// deep compare
assertProgramEquals(program, reloadedProgram);
// Add a strategy with another location list , add applied periods and pmfmStrategy
StrategyDTO strategy2 = ReefDbBeanFactory.newStrategyDTO();
strategy2.setName("strategy 2 test");
strategy2.setName(STRATEGY_2_NAME);
strategy2.setComment("with pmfm strategies");
for (LocationDTO location : program.getLocations()) {
AppliedStrategyDTO as = ReefDbBeanFactory.newAppliedStrategyDTO();
......@@ -136,30 +135,27 @@ public class ProgramStrategyServiceWriteTest {
strategy2.getAppliedStrategies().remove(0);
// add applied period
List<DepartmentDTO> allDepartements = referentialService.getDepartements();
for (AppliedStrategyDTO location : strategy2.getAppliedStrategies()) {
List<DepartmentDTO> allDepartments = referentialService.getDepartements();
for (AppliedStrategyDTO appliedStrategy : strategy2.getAppliedStrategies()) {
LocalDate startDate = LocalDate.of(2014, RandomUtils.nextInt(1, 13), RandomUtils.nextInt(1, 31));
// Date startDate = DateUtil.createDate(RandomUtils.nextInt(1, 31), RandomUtils.nextInt(1, 13), 2014);
// location.setStartDate(startDate);
// location.setEndDate(Dates.addDays(startDate, 40));
location.setStartDate(startDate);
location.setEndDate(startDate.plusDays(40));
location.setDepartment(allDepartements.get(RandomUtils.nextInt(0, allDepartements.size())));
appliedStrategy.setStartDate(startDate);
appliedStrategy.setEndDate(startDate.plusDays(40));
appliedStrategy.setDepartment(allDepartments.get(RandomUtils.nextInt(0, allDepartments.size())));
}
program.addStrategies(strategy2);
// add 10 Pmfm
List<PmfmDTO> allPmfms = ReefDbBeans.getList(referentialService.getPmfms(StatusFilter.ACTIVE));
for (int i = 0; i < 10; i++) {