Commit b2bd4950 authored by LAVENIER's avatar LAVENIER
Browse files

Merge branch 'develop' into feature/imagine

parents 9bfd1b85 92ed6f32
......@@ -133,12 +133,12 @@ public class VesselSnapshotDaoImpl extends HibernateDaoSupport implements Vessel
cb.or(
cb.and(
// if no date in filter, will return only active period
cb.isNull(dateParam),
cb.isNull(dateParam.as(String.class)),
cb.isNull(root.get(VesselFeatures.Fields.END_DATE)),
cb.isNull(vrpJoin.get(VesselRegistrationPeriod.Fields.END_DATE))
),
cb.and(
cb.isNotNull(dateParam),
cb.isNotNull(dateParam.as(String.class)),
cb.and(
cb.or(
cb.isNull(root.get(VesselFeatures.Fields.END_DATE)),
......@@ -171,9 +171,9 @@ public class VesselSnapshotDaoImpl extends HibernateDaoSupport implements Vessel
// Filter: search text (on exterior marking OR id)
cb.or(
cb.isNull(searchNameParam),
cb.like(cb.lower(root.get(VesselFeatures.Fields.NAME)), cb.lower(searchNameParam)),
cb.like(cb.lower(root.get(VesselFeatures.Fields.EXTERIOR_MARKING)), cb.lower(searchExteriorMarkingParam)),
cb.like(cb.lower(vrpJoin.get(VesselRegistrationPeriod.Fields.REGISTRATION_CODE)), cb.lower(searchRegistrationCodeParam))
cb.like(cb.lower(root.get(VesselFeatures.Fields.NAME)), searchNameParam),
cb.like(cb.lower(root.get(VesselFeatures.Fields.EXTERIOR_MARKING)), searchExteriorMarkingParam),
cb.like(cb.lower(vrpJoin.get(VesselRegistrationPeriod.Fields.REGISTRATION_CODE)), searchRegistrationCodeParam)
),
// Status
......@@ -185,6 +185,7 @@ public class VesselSnapshotDaoImpl extends HibernateDaoSupport implements Vessel
String searchTextAsPrefix = Daos.getEscapedSearchText(filter.getSearchText());
searchTextAsPrefix = searchTextAsPrefix != null ? searchTextAsPrefix.toLowerCase() : null;
String searchTextAnyMatch = StringUtils.isNotBlank(searchTextAsPrefix) ? ("%"+searchTextAsPrefix) : null;
TypedQuery<VesselSnapshotResult> q = getEntityManager().createQuery(query)
......
......@@ -86,9 +86,9 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit
ParameterExpression<String> labelParam = criteriaBuilder.parameter(String.class, LABEL_PARAMETER);
return criteriaBuilder.or(
criteriaBuilder.isNull(labelParam),
criteriaBuilder.equal(criteriaBuilder.upper(root.get(IItemReferentialEntity.Fields.LABEL)), criteriaBuilder.upper(labelParam))
criteriaBuilder.equal(criteriaBuilder.upper(root.get(IItemReferentialEntity.Fields.LABEL)), labelParam)
);
}).addBind(LABEL_PARAMETER, label);
}).addBind(LABEL_PARAMETER, label != null ? label.toUpperCase() : label);
}
default Specification<E> inLevelIds(Class<E> entityClass, Integer... levelIds) {
......@@ -146,7 +146,7 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit
);
Arrays.stream(searchAttributes).forEach(searchAttribute ->
predicates.add(
criteriaBuilder.like(criteriaBuilder.upper(Daos.composePath(root, searchAttribute)), criteriaBuilder.upper(searchTextParam))
criteriaBuilder.like(criteriaBuilder.upper(Daos.composePath(root, searchAttribute)),searchTextParam)
));
return criteriaBuilder.or(
// all predicates
......@@ -156,11 +156,11 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit
// Search on label+name only
return criteriaBuilder.or(
criteriaBuilder.isNull(searchTextParam),
criteriaBuilder.like(criteriaBuilder.upper(root.get(IItemReferentialEntity.Fields.LABEL)), criteriaBuilder.upper(searchTextParam)),
criteriaBuilder.like(criteriaBuilder.upper(root.get(IItemReferentialEntity.Fields.NAME)), criteriaBuilder.upper(criteriaBuilder.concat("%", searchTextParam)))
criteriaBuilder.like(criteriaBuilder.upper(root.get(IItemReferentialEntity.Fields.LABEL)), searchTextParam),
criteriaBuilder.like(criteriaBuilder.upper(root.get(IItemReferentialEntity.Fields.NAME)), criteriaBuilder.concat("%", searchTextParam))
);
})
.addBind(SEARCH_TEXT_PARAMETER, Daos.getEscapedSearchText(searchText));
.addBind(SEARCH_TEXT_PARAMETER, Daos.getEscapedSearchText(searchText != null ? searchText.toUpperCase() : null));
}
default Specification<E> joinSearchText(String joinProperty, String searchAttribute, String searchText) {
......@@ -182,17 +182,17 @@ public interface ReferentialSpecifications<E extends IReferentialWithStatusEntit
if (StringUtils.isNotBlank(searchAttribute)) {
return criteriaBuilder.or(
criteriaBuilder.isNull(searchTextParam),
criteriaBuilder.like(criteriaBuilder.upper(join.get(searchAttribute)), criteriaBuilder.upper(searchTextParam)));
criteriaBuilder.like(criteriaBuilder.upper(join.get(searchAttribute)),searchTextParam));
}
// Search on label+name
return criteriaBuilder.or(
criteriaBuilder.isNull(searchTextParam),
criteriaBuilder.like(criteriaBuilder.upper(join.get(IItemReferentialEntity.Fields.LABEL)), criteriaBuilder.upper(searchTextParam)),
criteriaBuilder.like(criteriaBuilder.upper(join.get(IItemReferentialEntity.Fields.NAME)), criteriaBuilder.upper(criteriaBuilder.concat("%", searchTextParam)))
criteriaBuilder.like(criteriaBuilder.upper(join.get(IItemReferentialEntity.Fields.LABEL)),searchTextParam),
criteriaBuilder.like(criteriaBuilder.upper(join.get(IItemReferentialEntity.Fields.NAME)), criteriaBuilder.concat("%", searchTextParam))
);
})
.addBind(SEARCH_TEXT_PARAMETER, Daos.getEscapedSearchText(searchText));
.addBind(SEARCH_TEXT_PARAMETER, Daos.getEscapedSearchText(searchText != null ? searchText.toUpperCase() : null));
}
default Specification<E> includedIds(Integer[] includedIds) {
......
......@@ -40,4 +40,6 @@ public interface TaxonNameRepository extends
List<TaxonName> getAllTaxonNameByParentIdInAndIsReferentTrue(Collection<Integer> parentIds);
Long countByFilter(TaxonNameFilterVO filter);
}
......@@ -197,6 +197,12 @@ public class TaxonNameRepositoryImpl
.getSingleResult();
}
public Long countByFilter(TaxonNameFilterVO filter) {
Preconditions.checkNotNull(filter);
return getCountQuery(toSpecification(filter), TaxonName.class).getSingleResult();
}
@Override
protected void toVO(TaxonName source, TaxonNameVO target, ReferentialFetchOptions fetchOptions, boolean copyIfNull) {
super.toVO(source, target, fetchOptions, copyIfNull);
......
......@@ -47,5 +47,8 @@ public interface TaxonNameService {
@Transactional(readOnly = true)
List<TaxonNameVO> getAllByTaxonGroupId(Integer taxonGroupId);
@Transactional(readOnly = true)
Long countByFilter(TaxonNameFilterVO filter);
TaxonNameVO save(TaxonNameVO taxonName);
}
......@@ -24,10 +24,12 @@ package net.sumaris.core.service.referential.taxon;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.dao.referential.ReferentialDao;
import net.sumaris.core.dao.referential.taxon.ReferenceTaxonRepository;
import net.sumaris.core.dao.referential.taxon.TaxonNameRepository;
import net.sumaris.core.dao.technical.SortDirection;
import net.sumaris.core.model.referential.taxon.ReferenceTaxon;
import net.sumaris.core.model.referential.taxon.TaxonName;
import net.sumaris.core.vo.filter.TaxonNameFilterVO;
import net.sumaris.core.vo.referential.TaxonNameVO;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -45,6 +47,9 @@ public class TaxonNameServiceImpl implements TaxonNameService {
@Autowired
protected ReferenceTaxonRepository referenceTaxonRepository;
@Autowired
protected ReferentialDao referentialDao;
@Override
public TaxonNameVO get(int id) {
return taxonNameRepository.get(id);
......@@ -71,6 +76,14 @@ public class TaxonNameServiceImpl implements TaxonNameService {
return taxonNameRepository.getAllByTaxonGroupId(taxonGroupId);
}
@Override
public Long countByFilter(TaxonNameFilterVO filter) {
if (filter == null) {
return referentialDao.count(TaxonName.class.getSimpleName());
}
return taxonNameRepository.countByFilter(filter);
}
@Override
public TaxonNameVO save(TaxonNameVO source) {
Preconditions.checkNotNull(source);
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
~ #%L
~ SUMARiS
~ %%
~ Copyright (C) 2019 SUMARiS Consortium
~ %%
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU 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 General Public
~ License along with this program. If not, see
~ <http://www.gnu.org/licenses/gpl-3.0.html>.
~ #L%
-->
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"
logicalFilePath="https://github.com/sumaris-net/sumaris-pod/blob/master/sumaris-core/src/main/resources/net/sumaris/core/db/changelog/hsqldb/db-changelog-1.8.7.xml">
<property name="sqlCheck.not_empty.sql" value="SELECT COUNT(*) FROM STATUS WHERE ID=1"/>
<property name="sqlCheck.not_empty.expectedResult" value="1"/>
<!-- update SYSTEM_VERSION -->
<changeSet author="benoit.lavenier@e-is.pro" id="1619445031800-200" runOnChange="true">
<delete tableName="SYSTEM_VERSION">
<where>LABEL='1.8.7'</where>
</delete>
<insert tableName="SYSTEM_VERSION">
<column name="ID" valueComputed="nextval('system_version_seq')"/>
<column name="LABEL">1.8.7</column>
<column name="DESCRIPTION">
</column>
<column name="CREATION_DATE" valueComputed="current_timestamp"/>
<column name="UPDATE_DATE" valueComputed="current_timestamp"/>
<column name="COMMENTS">
</column>
</insert>
</changeSet>
</databaseChangeLog>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
~ #%L
~ SUMARiS
~ %%
~ Copyright (C) 2019 SUMARiS Consortium
~ %%
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU 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 General Public
~ License along with this program. If not, see
~ <http://www.gnu.org/licenses/gpl-3.0.html>.
~ #L%
-->
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"
logicalFilePath="https://github.com/sumaris-net/sumaris-pod/blob/master/sumaris-core/src/main/resources/net/sumaris/core/db/changelog/hsqldb/db-changelog-1.8.8.xml">
<property name="sqlCheck.not_empty.sql" value="SELECT COUNT(*) FROM STATUS WHERE ID=1"/>
<property name="sqlCheck.not_empty.expectedResult" value="1"/>
<changeSet author="ludovic.pecquot@e-is.pro" id="1619445032000-1">
<preConditions onFail="MARK_RAN">
<and>
<not><columnExists tableName="software" columnName="description"/></not>
<not><columnExists tableName="software" columnName="comments"/></not>
</and>
</preConditions>
<addColumn tableName="software">
<column name="description" type="VARCHAR(255)"/>
<column name="comments" type="VARCHAR(2000)"/>
</addColumn>
</changeSet>
<!-- update SYSTEM_VERSION -->
<changeSet author="benoit.lavenier@e-is.pro" id="1619445032000-200" runOnChange="true">
<delete tableName="SYSTEM_VERSION">
<where>LABEL='1.8.8'</where>
</delete>
<insert tableName="SYSTEM_VERSION">
<column name="ID" valueComputed="nextval('system_version_seq')"/>
<column name="LABEL">1.8.8</column>
<column name="DESCRIPTION">
- SOFTWARE: Add columns DESCRIPTION and COMMENTS
</column>
<column name="CREATION_DATE" valueComputed="current_timestamp"/>
<column name="UPDATE_DATE" valueComputed="current_timestamp"/>
<column name="COMMENTS">
</column>
</insert>
</changeSet>
</databaseChangeLog>
......@@ -12,4 +12,8 @@
stripComments="true"/>
</changeSet>
<include relativeToChangelogFile="true" file="db-changelog-1.8.7.xml"/>
<include relativeToChangelogFile="true" file="db-changelog-1.8.8.xml"/>
</databaseChangeLog>
......@@ -159,9 +159,9 @@ BEGIN
decLatitude := FLOOR((absLat - intLatitude) * 60 / square_size);
--SET resultLatitude = LPAD(intLatitude, 2, '0');
IF(square_size >= 10) THEN
resultLatitude := CONCAT(LPAD(intLatitude, 2, '0'), decLatitude);
resultLatitude := CONCAT(LPAD(intLatitude::VARCHAR, 2, '0'), decLatitude);
ELSE
resultLatitude := CONCAT(LPAD(intLatitude, 2, '0'), LPAD(decLatitude, 2, '0'));
resultLatitude := CONCAT(LPAD(intLatitude::VARCHAR, 2, '0'), LPAD(decLatitude::VARCHAR, 2, '0'));
END IF;
-- Longitude
......@@ -169,9 +169,9 @@ BEGIN
intLongitude := FLOOR(absLon);
decLongitude := FLOOR((absLon - intLongitude) * 60 / square_size);
IF(square_size >= 10) THEN
resultLongitude := CONCAT(LPAD(intLongitude, 3, '0'), decLongitude);
resultLongitude := CONCAT(LPAD(intLongitude::VARCHAR, 3, '0'), decLongitude);
ELSE
resultLongitude := CONCAT(LPAD(intLongitude, 3, '0'), LPAD(decLongitude, 2, '0'));
resultLongitude := CONCAT(LPAD(intLongitude::VARCHAR, 3, '0'), LPAD(decLongitude::VARCHAR, 2, '0'));
END IF;
RETURN CONCAT(quadrant, resultLatitude, resultLongitude);
......
......@@ -66,6 +66,11 @@ public class InitTests extends net.sumaris.core.test.InitTests {
super.beforeInsert(conn);
}
@Override
protected String getConfigFileName(){
return TestConfiguration.CONFIG_FILE_PREFIX + "-" + this.datasourcePlatform + ".properties";
}
@Override
protected void afterInsert(Connection conn) throws SQLException {
super.afterInsert(conn);
......
......@@ -37,7 +37,8 @@ import org.springframework.context.annotation.Bean;
public abstract class TestConfiguration extends net.sumaris.core.test.TestConfiguration {
public static final String MODULE_NAME = "sumaris-core";
public static final String CONFIG_FILE_PREFIX = MODULE_NAME + "-test";
// public static final String CONFIG_FILE_PREFIX = MODULE_NAME + "-test";
public static final String CONFIG_FILE_PREFIX = "application";
public static final String DATASOURCE_PLATFORM = "hsqldb";
public static final String CONFIG_FILE_NAME = CONFIG_FILE_PREFIX + ".properties";
public static final String I18N_BUNDLE_NAME = MODULE_NAME + "-i18n";
......
......@@ -52,7 +52,7 @@ import java.util.Properties;
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {DaoTestConfiguration.class})
@TestPropertySource(locations="classpath:sumaris-core-test.properties")
//@TestPropertySource(locations="classpath:sumaris-core-test.properties")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Slf4j
public class AbstractDaoTest extends net.sumaris.core.test.AbstractDaoTest {
......
......@@ -98,7 +98,7 @@ public class LocationRepositoryReadTest extends AbstractDaoTest {
// All countries by search
assertFilterResult(ReferentialFilterVO.builder().searchJoin(Location.Fields.LOCATION_LEVEL).searchAttribute(LocationLevel.Fields.NAME).searchText("Country").build(), 4);
// All countries by level
assertFilterResult(ReferentialFilterVO.builder().levelId(1).build(), 36);
assertFilterResult(ReferentialFilterVO.builder().levelId(1).build(), 4);
// All countries and port by level
assertFilterResult(ReferentialFilterVO.builder().levelIds(new Integer[]{1,2}).build(), 19);
}
......
......@@ -77,7 +77,7 @@ public class MetierRepositoryReadTest extends AbstractDaoTest{
List<MetierVO> metiers = metierRepository.findByFilter(filter, 0, 100, null, null);
Assert.assertNotNull(metiers);
Assert.assertEquals(1, metiers.size());
Assert.assertEquals(2, metiers.size());
}
// With program
......
......@@ -63,10 +63,10 @@ public class TaxonNameRepositoryReadTest extends AbstractDaoTest {
public void getAllSpeciesAndSubSpecies() {
List<TaxonNameVO> taxonNames = taxonNameRepository.getAll(false);
Assert.assertNotNull(taxonNames);
Assert.assertEquals(23, taxonNames.size());
Assert.assertEquals(25, taxonNames.size());
taxonNames = taxonNameRepository.getAll(false);
Assert.assertNotNull(taxonNames);
Assert.assertEquals(23, taxonNames.size());
Assert.assertEquals(25, taxonNames.size());
}
@Test
......@@ -120,11 +120,11 @@ public class TaxonNameRepositoryReadTest extends AbstractDaoTest {
public void findByFilter() {
// no filter
assertFilterResult(TaxonNameFilterVO.builder().build(), 37);
assertFilterResult(TaxonNameFilterVO.builder().build(), 39);
// with synonyms
assertFilterResult(TaxonNameFilterVO.builder().withSynonyms(true).build(), 38);
assertFilterResult(TaxonNameFilterVO.builder().withSynonyms(true).build(), 40);
// with status 0
assertFilterResult(TaxonNameFilterVO.builder().statusIds(new Integer[]{0}).build(), 12);
assertFilterResult(TaxonNameFilterVO.builder().statusIds(new Integer[]{0}).build(), 14);
// with parent taxon group 1014
assertFilterResult(TaxonNameFilterVO.builder().taxonGroupId(1014).build(), 3);
// with parent taxon group 1014 with synonyms
......@@ -137,7 +137,7 @@ public class TaxonNameRepositoryReadTest extends AbstractDaoTest {
assertFilterResult(TaxonNameFilterVO.builder().taxonGroupIds(new Integer[]{1160, 1161}).build(), 2);
// with taxonomic level (species and subspecies)
assertFilterResult(TaxonNameFilterVO.builder()
.levelIds(new Integer[]{TaxonomicLevelEnum.SPECIES.getId(), TaxonomicLevelEnum.SUBSPECIES.getId()}).build(), 23);
.levelIds(new Integer[]{TaxonomicLevelEnum.SPECIES.getId(), TaxonomicLevelEnum.SUBSPECIES.getId()}).build(), 25);
// with label search
assertFilterResult(TaxonNameFilterVO.builder().searchText("raja").build(), 13);
// with exact label
......
......@@ -55,7 +55,7 @@ import java.util.Properties;
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ServiceTestConfiguration.class})
@TestPropertySource(locations="classpath:sumaris-core-test.properties")
//@TestPropertySource(locations="classpath:sumaris-core-test.properties")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Slf4j
public class AbstractServiceTest {
......
......@@ -79,7 +79,7 @@ public class ProgramServiceReadTest extends AbstractServiceTest{
Assert.assertNull(program.getLocations());
Assert.assertNull(program.getLocationIds());
Assert.assertNull(program.getLocationClassifications());
Assert.assertNull(program.getLocationClassificationIds());
Assert.assertEquals(1, program.getLocationClassificationIds().size());
}
@Test
......
......@@ -34,10 +34,7 @@ import net.sumaris.core.vo.administration.programStrategy.*;
import net.sumaris.core.vo.referential.LocationVO;
import net.sumaris.core.vo.referential.ReferentialVO;
import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.*;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -87,6 +84,7 @@ public class ProgramServiceWriteTest extends AbstractServiceTest{
}
@Test
@Ignore
public void saveWithStrategies() {
ProgramVO program = service.getByLabel("PARAM-BIO");
Assert.assertNotNull(program);
......
......@@ -130,7 +130,7 @@ public class StrategyServiceWriteTest extends AbstractServiceTest{
@Test
public void z_delete() {
service.delete(30);
service.delete(32);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment