Commit be6e94ba authored by LAVENIER's avatar LAVENIER
Browse files

[fix] TaxonName Repository: fill referenceTaxonId in the TaxonNameVO

parent d4a9b699
......@@ -123,7 +123,9 @@ public class AggregationServiceImpl implements AggregationService {
}
@Override
@Cacheable(cacheNames = ExtractionCacheNames.AGGREGATION_TYPE_BY_FORMAT, condition = " #format != null", unless = "#result == null")
@Cacheable(cacheNames = ExtractionCacheNames.AGGREGATION_TYPE_BY_FORMAT,
key = "#format.category + #format.label + #format.version",
condition = " #format != null", unless = "#result == null")
public AggregationTypeVO getTypeByFormat(IExtractionFormat format) {
return ExtractionFormats.findOneMatch(getAllAggregationTypes(null), format);
}
......
......@@ -101,6 +101,7 @@ public class TaxonNameRepositoryImpl
TaxonNameFilterVO.builder()
.levelIds(new Integer[]{TaxonomicLevelEnum.SPECIES.getId(), TaxonomicLevelEnum.SUBSPECIES.getId()})
.taxonGroupId(taxonGroupId)
.withSynonyms(false)
.build(),
Pageable.unpaged()
);
......@@ -136,4 +137,20 @@ public class TaxonNameRepositoryImpl
.setParameter("id", id)
.getSingleResult();
}
@Override
protected void toVO(TaxonName source, TaxonNameVO target, ReferentialFetchOptions fetchOptions, boolean copyIfNull) {
super.toVO(source, target, fetchOptions, copyIfNull);
// Convert boolean -> Boolean
target.setIsReferent(source.isReferent());
target.setIsNaming(source.isNaming());
target.setIsVirtual(source.isVirtual());
// Reference taxon id
target.setReferenceTaxonId(source.getReferenceTaxon().getId());
// Taxonomic level id
target.setTaxonomicLevelId(source.getTaxonomicLevel().getId());
}
}
......@@ -40,5 +40,5 @@ public interface TaxonNameService {
List<TaxonNameVO> getAll(boolean withSynonyms);
@Transactional(readOnly = true)
List<TaxonNameVO> getAllByTaxonGroup(Integer taxonGroupId);
List<TaxonNameVO> getAllByTaxonGroupId(Integer taxonGroupId);
}
......@@ -52,7 +52,7 @@ public class TaxonNameServiceImpl implements TaxonNameService {
}
@Override
public List<TaxonNameVO> getAllByTaxonGroup(Integer taxonGroupId) {
public List<TaxonNameVO> getAllByTaxonGroupId(Integer taxonGroupId) {
return taxonNameRepository.getAllByTaxonGroupId(taxonGroupId);
}
}
......@@ -27,13 +27,25 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.FieldNameConstants;
import net.sumaris.core.model.referential.taxon.TaxonName;
import java.util.Date;
@Data
@FieldNameConstants
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
public class TaxonNameVO extends ReferentialVO {
private Integer referenceTaxonId;
private String completeName;
private Date startDate;
private Date endDate;
private Boolean isReferent;
private Boolean isNaming;
private Boolean isVirtual;
private Integer upperRank;
private Integer taxonomicLevelId;
public TaxonNameVO() {
this.setEntityName(TaxonName.class.getSimpleName()); // Need by client (e.f. GraphQL cache)
......
......@@ -228,6 +228,10 @@ public class DatabaseFixtures {
return 1001 + index;
}
public Integer getTaxonGroupIdWithManyTaxonName() {
return 1122; // MNZ - Baudroie
}
public ProgramVO getDefaultProgram() {
ProgramVO program = new ProgramVO();
program.setId(1);
......
package net.sumaris.core.service.referential;
/*-
* #%L
* SUMARiS:: Core
* %%
* Copyright (C) 2018 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%
*/
import graphql.Assert;
import net.sumaris.core.dao.DatabaseFixtures;
import net.sumaris.core.dao.DatabaseResource;
import net.sumaris.core.service.AbstractServiceTest;
import net.sumaris.core.service.referential.taxon.TaxonNameService;
import net.sumaris.core.vo.referential.TaxonNameVO;
import org.junit.ClassRule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
public class TaxonNameServiceReadTest extends AbstractServiceTest{
@Autowired
private TaxonNameService service;
@Autowired
protected DatabaseFixtures fixtures;
@ClassRule
public static final DatabaseResource dbResource = DatabaseResource.readDb();
@Test
public void getAllByTaxonGroupId() {
List<TaxonNameVO> result = service.getAllByTaxonGroupId(fixtures.getTaxonGroupIdWithManyTaxonName());
Assert.assertNotNull(result);
Assert.assertTrue(result.size() > 0);
result.forEach(tn -> {
Assert.assertNotNull(tn.getLabel());
Assert.assertNotNull(tn.getName());
// important (nNeed by the App)
Assert.assertNotNull(tn.getReferenceTaxonId());
});
}
}
......@@ -12,7 +12,7 @@ spring.main.banner-mode=off
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
spring.datasource.username=sa
spring.datasource.password=
#spring.datasource.url=jdbc:hsqldb:hsql://localhost/sumaris
spring.datasource.url=jdbc:hsqldb:hsql://localhost/sumaris
spring.datasource.platform=hsqldb
spring.datasource.initialization-mode=always
......@@ -45,7 +45,7 @@ logging.level.net.sf.ehcache=warn
logging.level.net.sf.ehcache.hibernate=info
logging.level.org.apache.commons.beanutils=warn
logging.level.org.hibernate=warn
#logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.SQL=debug
#logging.level.org.hibernate.type.descriptor.sql=trace
logging.level.org.hibernate.spatial=warn
logging.level.org.hibernate.engine.jdbc.spi.SqlExceptionHelper=error
......
......@@ -37,7 +37,6 @@ import net.sumaris.core.service.referential.taxon.TaxonNameService;
import net.sumaris.core.util.StringUtils;
import net.sumaris.core.vo.administration.programStrategy.*;
import net.sumaris.core.vo.filter.ProgramFilterVO;
import net.sumaris.core.vo.filter.ReferentialFilterVO;
import net.sumaris.core.vo.referential.PmfmVO;
import net.sumaris.core.vo.referential.ReferentialVO;
import net.sumaris.core.vo.referential.TaxonGroupVO;
......@@ -115,8 +114,6 @@ public class ProgramGraphQLService {
return referentialService.countByFilter(Program.class.getSimpleName(), filter);
}
@GraphQLQuery(name = "taxonGroupType", description = "Get program's taxon group type")
public ReferentialVO getProgramTaxonGroupType(@GraphQLContext ProgramVO program) {
if (program.getTaxonGroupTypeId() != null && program.getTaxonGroupType() == null) {
......@@ -165,7 +162,7 @@ public class ProgramGraphQLService {
@GraphQLQuery(name = "taxonNames", description = "Get taxon group's taxons")
public List<TaxonNameVO> getTaxonGroupTaxonNames(@GraphQLContext TaxonGroupVO taxonGroup) {
if (taxonGroup.getId() != null) {
return taxonNameService.getAllByTaxonGroup(taxonGroup.getId());
return taxonNameService.getAllByTaxonGroupId(taxonGroup.getId());
}
return null;
}
......
......@@ -485,6 +485,11 @@
<VIRTUAL_COMPONENT TAXON_NAME_FK="1014" REFERENCE_TAXON_FK="1022"/>
<VIRTUAL_COMPONENT TAXON_NAME_FK="1014" REFERENCE_TAXON_FK="1023"/>
<!-- Link between TaxonGroup to ReferenceTaxon -->
<TAXON_GROUP2TAXON_HIERARCHY PARENT_TAXON_GROUP_FK="1122" CHILD_REFERENCE_TAXON_FK="1032" IS_INHERITED="0" START_DATE="1970-01-01"/>
<TAXON_GROUP2TAXON_HIERARCHY PARENT_TAXON_GROUP_FK="1122" CHILD_REFERENCE_TAXON_FK="1033" IS_INHERITED="1" START_DATE="1970-01-01"/>
<TAXON_GROUP2TAXON_HIERARCHY PARENT_TAXON_GROUP_FK="1122" CHILD_REFERENCE_TAXON_FK="1034" IS_INHERITED="1" START_DATE="1970-01-01"/>
<!-- NEW METIER LIST (from metier_gear_species.xlsx)-->
<METIER ID="1" GEAR_FK="89" TAXON_GROUP_FK="2" LABEL="FAG_CAT" NAME="Prawn faggot / Catadromous species (e.g. eel, flounder, thinlip mullet...)" STATUS_FK="1" CREATION_DATE="2018-03-08" UPDATE_DATE="2018-03-08"/>
<METIER ID="2" GEAR_FK="11" TAXON_GROUP_FK="2" LABEL="GNS_CAT" NAME="Set gillnet (anchored) / Catadromous species (e.g. eel, flounder, thinlip mullet...)" STATUS_FK="1" CREATION_DATE="2018-03-08" UPDATE_DATE="2018-03-08"/>
......
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