branch feature/7458 updated (c6e7300 -> 6e008ba)
This is an automated email from the git hooks/post-receive script. New change to branch feature/7458 in repository observe. See http://git.codelutin.com/observe.git from c6e7300 Correction des liens sur certains référentiels + tester le chargement de tous les référentiels new 6e008ba Pour les référentiels en lecture seule, on ne prend que la label des références rencontrées The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 6e008ba2a5289fe5b65130cb15598b8bbebe6dae Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Aug 18 13:36:19 2015 +0200 Pour les référentiels en lecture seule, on ne prend que la label des références rencontrées Summary of changes: .../services/service/ReferentialDtoBuilder.java | 13 ++++-- .../services/service/ReferentialServiceTopia.java | 54 ++++++++++++++++++---- .../service/ReferentialDtoBuilderTest.java | 11 +++-- .../service/ReferentialServiceTopiaTest.java | 13 ++++++ 4 files changed, 72 insertions(+), 19 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7458 in repository observe. See http://git.codelutin.com/observe.git commit 6e008ba2a5289fe5b65130cb15598b8bbebe6dae Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Aug 18 13:36:19 2015 +0200 Pour les référentiels en lecture seule, on ne prend que la label des références rencontrées --- .../services/service/ReferentialDtoBuilder.java | 13 ++++-- .../services/service/ReferentialServiceTopia.java | 54 ++++++++++++++++++---- .../service/ReferentialDtoBuilderTest.java | 11 +++-- .../service/ReferentialServiceTopiaTest.java | 13 ++++++ 4 files changed, 72 insertions(+), 19 deletions(-) diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialDtoBuilder.java b/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialDtoBuilder.java index 3bf82d3..726663c 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialDtoBuilder.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialDtoBuilder.java @@ -13,6 +13,7 @@ import fr.ird.observe.services.dto.constants.ReferentialLocale; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.ReferentialLabelDto; import fr.ird.observe.services.dto.referential.ReferentialLabelDtos; +import org.apache.commons.lang3.tuple.Pair; import org.nuiton.topia.persistence.EntityVisitor; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.beans.Binder; @@ -21,7 +22,6 @@ import org.nuiton.util.beans.BinderFactory; import java.io.Closeable; import java.util.Collection; import java.util.LinkedHashSet; -import java.util.Set; /** * Created on 16/08/15. @@ -40,7 +40,7 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl private final EntityVisitor visitor; - private ImmutableSet.Builder<Class<? extends ReferentialDto>> referentialDtoTypesBuilder; + private ImmutableSet.Builder<Pair<Class<? extends ReferentialDto>, String>> referentialDtoTypesBuilder; public static <M extends ReferentialDto> ReferentialDtoBuilder<M> create(Class<M> modelType, ReferentialLocale referentialLocale) { @@ -68,7 +68,7 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl } - public Set<Class<? extends ReferentialDto>> getReferentialDtoTypes() { + public ImmutableSet<Pair<Class<? extends ReferentialDto>, String>> getReferentialDtoTypes() { return referentialDtoTypesBuilder.build(); } @@ -122,9 +122,12 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl } protected <R extends ReferentialDto> ReferentialLabelDto<R> entityToRef(Class<R> dtoType, TopiaEntity entityValue) { - referentialDtoTypesBuilder.add(dtoType); + + String id = entityValue.getTopiaId(); + Pair<Class<R>, String> ref = Pair.of(dtoType, id); + referentialDtoTypesBuilder.add((Pair) ref); ReferentialLabelDto<R> label = ReferentialLabelDtos.newReferentialLabelDto(dtoType, referentialLocale, entityValue); - label.setId(entityValue.getTopiaId()); + label.setId(id); return label; } diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialServiceTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialServiceTopia.java index 33518d8..ce04fb3 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialServiceTopia.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/service/ReferentialServiceTopia.java @@ -129,6 +129,7 @@ import fr.ird.observe.services.dto.referential.seine.TransmittingBuoyTypeDto; import fr.ird.observe.services.dto.referential.seine.VesselActivitySeineDto; import fr.ird.observe.services.dto.referential.seine.WeightCategoryDto; import fr.ird.observe.services.dto.referential.seine.WindDto; +import org.apache.commons.lang3.tuple.Pair; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; @@ -138,7 +139,6 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Set; /** * Created on 16/08/15. @@ -239,11 +239,21 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe return labelSetDto; } + public <D extends ReferentialDto> ReferentialLabelSetDto getReferentialLabelSet(Class<D> dtoType, String id) { + Class<TopiaEntity> entityType = getEntityType(dtoType); + TopiaEntity entity = loadEntity(entityType, id); + LinkedHashSet<ReferentialLabelDto<D>> labels = new LinkedHashSet<>(1); + ReferentialLabelDto<D> dto = ReferentialLabelDtos.newReferentialLabelDto(dtoType, serviceContext.getReferentialLocale(), entity); + labels.add(dto); + ReferentialLabelSetDto labelSetDto = ReferentialLabelSetDtos.newReferentialLabelSetDto(dtoType, labels); + return labelSetDto; + } + @Override public <D extends ReferentialDto> FormDto<D> loadToRead(Class<D> dtoType, String id) { Class<? extends TopiaEntity> entityType = getEntityType(dtoType); TopiaEntity entity = loadEntity(entityType, id); - FormDto<D> form = entityToReferentialFormDto(dtoType, entity); + FormDto<D> form = entityToReadReferentialFormDto(dtoType, entity); return form; } @@ -251,7 +261,7 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe public <D extends ReferentialDto> FormDto<D> loadToEdit(Class<D> dtoType, String id) { Class<? extends TopiaEntity> entityType = getEntityType(dtoType); TopiaEntity entity = loadEntity(entityType, id); - FormDto<D> form = entityToReferentialFormDto(dtoType, entity); + FormDto<D> form = entityToEditReferentialFormDto(dtoType, entity); return form; } @@ -260,7 +270,7 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe Class<? extends TopiaEntity> entityType = getEntityType(dtoType); TopiaEntity entity = newEntity(entityType); //TODO Voir selon le type d'entité si il y a des valeurs par défaut à utiliser - FormDto<D> form = entityToReferentialFormDto(dtoType, entity); + FormDto<D> form = entityToEditReferentialFormDto(dtoType, entity); return form; } @@ -270,7 +280,7 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe TopiaEntity entity = referentialDtoToEntity(form.getForm()); Class<TopiaEntity> entityType = getEntityType(dtoType); entity = saveEntity(entityType, entity); - FormDto<D> model = entityToReferentialFormDto(dtoType, entity); + FormDto<D> model = entityToEditReferentialFormDto(dtoType, entity); return model.getForm().getId(); } @@ -323,7 +333,7 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe } } - protected <D extends ReferentialDto> FormDto<D> entityToReferentialFormDto(Class<D> dtoType, TopiaEntity entity) { + protected <D extends ReferentialDto> FormDto<D> entityToEditReferentialFormDto(Class<D> dtoType, TopiaEntity entity) { try (ReferentialDtoBuilder<D> dtoBuilder = ReferentialDtoBuilder.create(dtoType, serviceContext.getReferentialLocale())) { // copy entity @@ -331,10 +341,10 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe D dto = dtoBuilder.build(); // build label sets detected while copy - Set<Class<? extends ReferentialDto>> referentialDtoTypes = dtoBuilder.getReferentialDtoTypes(); + ImmutableSet<Pair<Class<? extends ReferentialDto>, String>> referentialDtoTypes = dtoBuilder.getReferentialDtoTypes(); ImmutableSet.Builder<ReferentialLabelSetDto> labels = new ImmutableSet.Builder<>(); - for (Class<? extends ReferentialDto> referentialDtoType : referentialDtoTypes) { - ReferentialLabelSetDto referentialLabelSet = getReferentialLabelSet(referentialDtoType); + for (Pair<Class<? extends ReferentialDto>, String> ref : referentialDtoTypes) { + ReferentialLabelSetDto referentialLabelSet = getReferentialLabelSet(ref.getKey()); labels.add(referentialLabelSet); } FormDto<D> form = FormDtos.newFormDto(dtoType, dto, labels.build()); @@ -343,6 +353,32 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe } } + protected <D extends ReferentialDto> FormDto<D> entityToReadReferentialFormDto(Class<D> dtoType, TopiaEntity entity) { + try (ReferentialDtoBuilder<D> dtoBuilder = ReferentialDtoBuilder.create(dtoType, serviceContext.getReferentialLocale())) { + + // copy entity + dtoBuilder.copyEntity(entity); + D dto = dtoBuilder.build(); + + // build label sets detected while copy (keep the reference for each label, or nothing if value not set) + ImmutableSet<Pair<Class<? extends ReferentialDto>, String>> referentialDtoTypes = dtoBuilder.getReferentialDtoTypes(); + ImmutableSet.Builder<ReferentialLabelSetDto> labels = new ImmutableSet.Builder<>(); + for (Pair<Class<? extends ReferentialDto>, String> ref : referentialDtoTypes) { + String id = ref.getRight(); + if (id != null) { + + ReferentialLabelSetDto referentialLabelSet = getReferentialLabelSet(ref.getLeft(), id); + labels.add(referentialLabelSet); + + } + + } + FormDto<D> form = FormDtos.newFormDto(dtoType, dto, labels.build()); + return form; + + } + } + protected <D extends ReferentialDto, E extends TopiaEntity> E referentialDtoToEntity(D dto) { Class<D> aClass = (Class<D>) dto.getClass(); Class<TopiaEntity> entityType = getEntityType(aClass); diff --git a/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialDtoBuilderTest.java b/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialDtoBuilderTest.java index 78bba4a..169ba30 100644 --- a/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialDtoBuilderTest.java +++ b/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialDtoBuilderTest.java @@ -1,5 +1,6 @@ package fr.ird.observe.services.service; +import com.google.common.collect.ImmutableSet; import fr.ird.observe.entities.constants.GearType; import fr.ird.observe.entities.constants.ReferenceStatus; import fr.ird.observe.entities.referentiel.Organism; @@ -13,12 +14,11 @@ import fr.ird.observe.services.dto.referential.ProgramDto; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.ReferentialLabelDto; import fr.ird.observe.services.dto.referential.ReferentielLabelValueNotFoundException; +import org.apache.commons.lang3.tuple.Pair; import org.junit.Assert; import org.junit.Test; import org.nuiton.util.DateUtil; -import java.util.Set; - /** * Created on 17/08/15. * @@ -47,7 +47,7 @@ public class ReferentialDtoBuilderTest { program.setGearType(GearType.seine); program.setTargetDiscardsObservation(1); Organism organism = new OrganismImpl(); - organism.setTopiaId("Oraganism1"); + organism.setTopiaId("Organism1"); organism.setLabel1("organism1"); organism.setLabel2("organism2"); organism.setLabel3("organism3"); @@ -62,12 +62,13 @@ public class ReferentialDtoBuilderTest { ReferentialDtoBuilder<ProgramDto> builder = ReferentialDtoBuilder.create(ProgramDto.class, ReferentialLocale.FR); builder.copyEntity(program); ProgramDto programDto = builder.build(); - Set<Class<? extends ReferentialDto>> referentialDtoTypes = builder.getReferentialDtoTypes(); + ImmutableSet<Pair<Class<? extends ReferentialDto>, String>> referentialDtoTypes = builder.getReferentialDtoTypes(); // On verifie les types de listes de labels détectées Assert.assertNotNull(referentialDtoTypes); Assert.assertEquals(1, referentialDtoTypes.size()); - Assert.assertTrue(referentialDtoTypes.contains(OrganismDto.class)); + + Assert.assertTrue(referentialDtoTypes.contains(Pair.of(OrganismDto.class,"Organism1"))); // On vérife que le program a bien été copié Assert.assertEquals(program.getCode(), programDto.getCode()); diff --git a/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialServiceTopiaTest.java b/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialServiceTopiaTest.java index 9947348..df8c676 100644 --- a/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialServiceTopiaTest.java +++ b/observe-services-topia/src/test/java/fr/ird/observe/services/service/ReferentialServiceTopiaTest.java @@ -129,6 +129,11 @@ public class ReferentialServiceTopiaTest { Assert.assertNotNull(form); Assert.assertEquals(o.getTopiaId(), form.getId()); + for (ReferentialLabelSetDto labelSetDto : formDto.getLabels()) { + Assert.assertTrue(0 <= labelSetDto.sizeReferentialLabel()); + Assert.assertTrue(labelSetDto.sizeReferentialLabel() < 2); + } + } } @@ -154,6 +159,14 @@ public class ReferentialServiceTopiaTest { Assert.assertNotNull(form); Assert.assertEquals(o.getTopiaId(), form.getId()); + for (ReferentialLabelSetDto labelSetDto : formDto.getLabels()) { + + Class refEntityType = ReferentialServiceTopia.modelToEntityTypeCache.get(labelSetDto.getType()); + long refExpected = dataSourceResource.getDataSource().getDAO(tx, refEntityType).count(); + Assert.assertEquals(refExpected, labelSetDto.sizeReferentialLabel()); + + } + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm