branch feature/7458 updated (fe6cdca -> 497ba00)
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 fe6cdca on desactive pour le moment le module rest) new 497ba00 Gestion de la locale des référentiels 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 497ba0087fc05db383796d1ad532ce409989b592 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Aug 18 12:19:42 2015 +0200 Gestion de la locale des référentiels Summary of changes: .../observe/services/ObserveServiceContext.java | 4 ++ .../services/FakeObserveServiceContext.java | 12 ++++ .../services/dto/constants/ReferentialLocale.java | 40 ++++++------ .../dto/referential/ReferentialLabelDto.java | 52 +++++++++++++-- .../dto/referential/ReferentialLabelDtos.java | 13 ++-- .../ReferentielLabelValueNotFoundException.java | 27 ++++++++ .../services/ObserveServiceContextRest.java | 12 ++++ .../services/ObserveServiceContextTopia.java | 12 ++++ .../services/service/ReferentialDtoBuilder.java | 12 ++-- .../services/service/ReferentialServiceTopia.java | 4 +- .../service/ReferentialDtoBuilderTest.java | 73 +++++++++++++++------- 11 files changed, 199 insertions(+), 62 deletions(-) copy observe-entities/src/main/java/fr/ird/observe/entities/constants/ReferenceLocale.java => observe-services-model/src/main/java/fr/ird/observe/services/dto/constants/ReferentialLocale.java (71%) create mode 100644 observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentielLabelValueNotFoundException.java -- 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 497ba0087fc05db383796d1ad532ce409989b592 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Aug 18 12:19:42 2015 +0200 Gestion de la locale des référentiels --- .../observe/services/ObserveServiceContext.java | 4 + .../services/FakeObserveServiceContext.java | 12 ++ .../services/dto/constants/ReferentialLocale.java | 124 +++++++++++++++++++++ .../dto/referential/ReferentialLabelDto.java | 52 ++++++++- .../dto/referential/ReferentialLabelDtos.java | 13 ++- .../ReferentielLabelValueNotFoundException.java | 27 +++++ .../services/ObserveServiceContextRest.java | 12 ++ .../services/ObserveServiceContextTopia.java | 12 ++ .../services/service/ReferentialDtoBuilder.java | 12 +- .../services/service/ReferentialServiceTopia.java | 4 +- .../service/ReferentialDtoBuilderTest.java | 73 ++++++++---- 11 files changed, 304 insertions(+), 41 deletions(-) diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceContext.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceContext.java index 31c201b..9b1a3e2 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceContext.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceContext.java @@ -1,5 +1,7 @@ package fr.ird.observe.services; +import fr.ird.observe.services.dto.constants.ReferentialLocale; + /** * Created on 16/08/15. * @@ -7,4 +9,6 @@ package fr.ird.observe.services; */ public interface ObserveServiceContext { + ReferentialLocale getReferentialLocale(); + } diff --git a/observe-services-api/src/test/java/fr/ird/observe/services/FakeObserveServiceContext.java b/observe-services-api/src/test/java/fr/ird/observe/services/FakeObserveServiceContext.java index b26f3a6..5ab54bb 100644 --- a/observe-services-api/src/test/java/fr/ird/observe/services/FakeObserveServiceContext.java +++ b/observe-services-api/src/test/java/fr/ird/observe/services/FakeObserveServiceContext.java @@ -1,5 +1,7 @@ package fr.ird.observe.services; +import fr.ird.observe.services.dto.constants.ReferentialLocale; + /** * Created on 16/08/15. * @@ -7,4 +9,14 @@ package fr.ird.observe.services; */ public class FakeObserveServiceContext implements ObserveServiceContext { + private ReferentialLocale referentialLocale; + + @Override + public ReferentialLocale getReferentialLocale() { + return referentialLocale; + } + + public void setReferentialLocale(ReferentialLocale referentialLocale) { + this.referentialLocale = referentialLocale; + } } diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/constants/ReferentialLocale.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/constants/ReferentialLocale.java new file mode 100644 index 0000000..60d3a24 --- /dev/null +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/constants/ReferentialLocale.java @@ -0,0 +1,124 @@ +/* + * #%L + * ObServe :: Entities + * %% + * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + * %% + * 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% + */ +package fr.ird.observe.services.dto.constants; + + +import fr.ird.observe.services.dto.referential.I18nReferentialDto; +import fr.ird.observe.services.dto.referential.ReferentialDto; + +import java.util.Locale; + +/** + * Pour définir les différentes langues du référentiel. + * <p/> + * La position de chaque constante définit l'index du champs libelleXXX à + * utiliser. + * <p/> + * En base on a actuellement 8 langues possibles, pour gérer une nouvelle + * langue, il faut définir une nouvelle constante ici. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public enum ReferentialLocale { + /** + * correspond a la propriete {@code label1} d'un {@link I18nReferentialDto}. + * + * @see I18nReferentialDto#getLabel1() + */ + UK(Locale.UK), + /** + * correspond a la propriete {@code label2} d'un {@link ReferentialDto}. + * + * @see I18nReferentialDto#getLabel2() + */ + FR(Locale.FRANCE), + /** + * correspond a la propriete {@code label3} d'un {@link ReferentialDto}. + * + * @see I18nReferentialDto#getLabel3() + */ + ES(new Locale("es", "ES")); + + private final Locale locale; + + ReferentialLocale(Locale locale) { + this.locale = locale; + } + + public Locale getLocale() { + return locale; + } + + public String getLibelle() { + return "label" + (ordinal() + 1); + } + + public static ReferentialLocale valueOf(Locale locale) { + for (ReferentialLocale anEnum : values()) { + if (locale.equals(anEnum.getLocale())) { + return anEnum; + } + } + throw new IllegalArgumentException( + "could not find referentiel locale from locale " + locale); + } + + public String getColumnName() { + return "label" + (ordinal() + 1); + } + + @Override + public String toString() { + return "<ReferentialLocale: " + locale + ", index: " + name() + ">"; + } + + public <E extends I18nReferentialDto> void setLabel(String label, E i18nEntity) { + + switch (ordinal() + 1) { + case 1: + i18nEntity.setLabel1(label); + break; + case 2: + i18nEntity.setLabel2(label); + break; + case 3: + i18nEntity.setLabel3(label); + break; + case 4: + i18nEntity.setLabel4(label); + break; + case 5: + i18nEntity.setLabel5(label); + break; + case 6: + i18nEntity.setLabel6(label); + break; + case 7: + i18nEntity.setLabel7(label); + break; + case 8: + i18nEntity.setLabel8(label); + break; + } + + } +} diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDto.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDto.java index ac89343..f5550e1 100644 --- a/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDto.java +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDto.java @@ -2,6 +2,8 @@ package fr.ird.observe.services.dto.referential; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.services.dto.constants.ReferentialLocale; import java.io.Serializable; @@ -9,15 +11,40 @@ public class ReferentialLabelDto<R extends ReferentialDto> extends AbstractRefer private static final long serialVersionUID = 1L; + public static final String PROPERTY_LABEL = "label"; + protected final Class<R> type; protected final ImmutableList<String> labelPropertyNames; protected final Serializable[] labelPropertyValues; - public ReferentialLabelDto(Class<R> type, String... labelPropertyNames) { + public static final ImmutableSet<String> I18N_PROPERTY_NAMES = ImmutableSet.of( + I18nReferentialDto.PROPERTY_LABEL1, + I18nReferentialDto.PROPERTY_LABEL2, + I18nReferentialDto.PROPERTY_LABEL3, + I18nReferentialDto.PROPERTY_LABEL4, + I18nReferentialDto.PROPERTY_LABEL5, + I18nReferentialDto.PROPERTY_LABEL6, + I18nReferentialDto.PROPERTY_LABEL7, + I18nReferentialDto.PROPERTY_LABEL8 + ); + + public ReferentialLabelDto(Class<R> type, ReferentialLocale referentialLocale, String... labelPropertyNames) { this.type = type; - this.labelPropertyNames = ImmutableList.copyOf(labelPropertyNames); + String libelle = referentialLocale.getLibelle(); + ImmutableList.Builder<String> labelPropertyNamesBuilder = new ImmutableList.Builder<>(); + for (String labelPropertyName : labelPropertyNames) { + if (I18N_PROPERTY_NAMES.contains(labelPropertyName)) { + if (libelle.endsWith(labelPropertyName)) { + labelPropertyName = PROPERTY_LABEL; + } else { + continue; + } + } + labelPropertyNamesBuilder.add(labelPropertyName); + } + this.labelPropertyNames = labelPropertyNamesBuilder.build(); this.labelPropertyValues = new Serializable[labelPropertyNames.length]; } @@ -34,14 +61,27 @@ public class ReferentialLabelDto<R extends ReferentialDto> extends AbstractRefer return labelPropertyNames; } - public void setLabelPropertyValue(String propertyName, Serializable propertyValue) { - int propertyIndex = getPropertyIndex(propertyName); - labelPropertyValues[propertyIndex] = propertyValue; + public void setLabelPropertyValue(ReferentialLocale referentialLocale, String propertyName, Serializable propertyValue) { + Preconditions.checkNotNull(referentialLocale, "referentialLocale parameter can't be null"); + Preconditions.checkNotNull(propertyName, "propertyName parameter can't be null"); + if (I18N_PROPERTY_NAMES.contains(propertyName)) { + if (referentialLocale.getLibelle().equals(propertyName)) { + propertyName = PROPERTY_LABEL; + } else { + propertyName = null; + } + } + if (propertyName != null) { + int propertyIndex = getPropertyIndex(propertyName); + labelPropertyValues[propertyIndex] = propertyValue; + } } protected int getPropertyIndex(String propertyName) { int index = labelPropertyNames.indexOf(propertyName); - Preconditions.checkArgument(index > -1, "Property " + propertyName + " not found for this label, " + labelPropertyNames); + if (index == -1) { + throw new ReferentielLabelValueNotFoundException(type, propertyName); + } return index; } } diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDtos.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDtos.java index b914192..779b0fb 100644 --- a/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDtos.java +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentialLabelDtos.java @@ -1,6 +1,7 @@ package fr.ird.observe.services.dto.referential; import com.google.common.collect.ImmutableMap; +import fr.ird.observe.services.dto.constants.ReferentialLocale; import fr.ird.observe.services.dto.referential.longline.BaitHaulingStatusDto; import fr.ird.observe.services.dto.referential.longline.BaitSettingStatusDto; import fr.ird.observe.services.dto.referential.longline.BaitTypeDto; @@ -128,21 +129,23 @@ public class ReferentialLabelDtos extends AbstractReferentialLabelDtos { } - public static <R extends ReferentialDto> ReferentialLabelDto<R> newReferentialLabelDto(Class<R> type) { + public static <R extends ReferentialDto> ReferentialLabelDto<R> newReferentialLabelDto(Class<R> type, ReferentialLocale referentialLocale) { String[] propertyNames = LABEL_PROPERTY_NAMES_MAPPING.get(type); - return new ReferentialLabelDto<>(type, propertyNames); + return new ReferentialLabelDto<>(type, referentialLocale, propertyNames); } - public static <R extends ReferentialDto> ReferentialLabelDto<R> newReferentialLabelDto(Class<R> type, Object source) { + public static <R extends ReferentialDto> ReferentialLabelDto<R> newReferentialLabelDto(Class<R> type, + ReferentialLocale referentialLocale, + Object source) { String[] propertyNames = LABEL_PROPERTY_NAMES_MAPPING.get(type); - ReferentialLabelDto<R> dto = new ReferentialLabelDto<>(type, propertyNames); + ReferentialLabelDto<R> dto = new ReferentialLabelDto<>(type, referentialLocale, propertyNames); Binder binder = BinderFactory.newBinder(source.getClass()); Map<String, Object> properties = binder.obtainProperties(source, propertyNames); for (Map.Entry<String, Object> entry : properties.entrySet()) { String propertyName = entry.getKey(); Object propertyValue = entry.getValue(); - dto.setLabelPropertyValue(propertyName, (Serializable) propertyValue); + dto.setLabelPropertyValue(referentialLocale, propertyName, (Serializable) propertyValue); } return dto; } diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentielLabelValueNotFoundException.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentielLabelValueNotFoundException.java new file mode 100644 index 0000000..6a2f092 --- /dev/null +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/referential/ReferentielLabelValueNotFoundException.java @@ -0,0 +1,27 @@ +package fr.ird.observe.services.dto.referential; + +/** + * Created on 18/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class ReferentielLabelValueNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + protected final Class<? extends ReferentialDto> dtoType; + protected final String propertyName; + + public ReferentielLabelValueNotFoundException(Class<? extends ReferentialDto> dtoType, String propertyName) { + this.dtoType = dtoType; + this.propertyName = propertyName; + } + + public String getPropertyName() { + return propertyName; + } + + public Class<? extends ReferentialDto> getDtoType() { + return dtoType; + } +} diff --git a/observe-services-rest/src/main/java/fr/ird/observe/services/ObserveServiceContextRest.java b/observe-services-rest/src/main/java/fr/ird/observe/services/ObserveServiceContextRest.java index 51c1e70..d9efbdf 100644 --- a/observe-services-rest/src/main/java/fr/ird/observe/services/ObserveServiceContextRest.java +++ b/observe-services-rest/src/main/java/fr/ird/observe/services/ObserveServiceContextRest.java @@ -1,5 +1,7 @@ package fr.ird.observe.services; +import fr.ird.observe.services.dto.constants.ReferentialLocale; + /** * Created on 16/08/15. * @@ -7,4 +9,14 @@ package fr.ird.observe.services; */ public class ObserveServiceContextRest implements ObserveServiceContext { + protected ReferentialLocale referentialLocale; + + @Override + public ReferentialLocale getReferentialLocale() { + return referentialLocale; + } + + public void setReferentialLocale(ReferentialLocale referentialLocale) { + this.referentialLocale = referentialLocale; + } } diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceContextTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceContextTopia.java index 474607e..587b9ae 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceContextTopia.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceContextTopia.java @@ -1,6 +1,7 @@ package fr.ird.observe.services; import fr.ird.observe.db.DataSource; +import fr.ird.observe.services.dto.constants.ReferentialLocale; import org.nuiton.topia.TopiaContext; /** @@ -14,6 +15,8 @@ public class ObserveServiceContextTopia implements ObserveServiceContext { protected TopiaContext transaction; + protected ReferentialLocale referentialLocale; + public DataSource getDataSource() { return dataSource; } @@ -30,4 +33,13 @@ public class ObserveServiceContextTopia implements ObserveServiceContext { this.transaction = transaction; } + @Override + public ReferentialLocale getReferentialLocale() { + return referentialLocale; + } + + public void setReferentialLocale(ReferentialLocale referentialLocale) { + this.referentialLocale = referentialLocale; + } + } 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 bf9ccb0..10d7157 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 @@ -6,6 +6,7 @@ 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.constants.seine.NonTargetCatchComputedValueSource; +import fr.ird.observe.services.dto.constants.ReferentialLocale; import fr.ird.observe.services.dto.constants.seine.Ownership; import fr.ird.observe.services.dto.constants.seine.SchoolType; import fr.ird.observe.services.dto.constants.seine.TypeTransmittingBuoyOperation; @@ -31,6 +32,8 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl private M result; + private final ReferentialLocale referentialLocale; + private ImmutableMap.Builder<String, Object> valuesBuilder; private Binder<M, M> binder; @@ -39,7 +42,7 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl private ImmutableSet.Builder<Class<? extends ReferentialDto>> referentialDtoTypesBuilder; - public static <M extends ReferentialDto> ReferentialDtoBuilder<M> create(Class<M> modelType) { + public static <M extends ReferentialDto> ReferentialDtoBuilder<M> create(Class<M> modelType, ReferentialLocale referentialLocale) { Preconditions.checkNotNull(modelType, "modelType can't be null."); M result; @@ -48,7 +51,7 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException("Could not instanciate model of type: " + modelType.getName()); } - ReferentialDtoBuilder<M> visitor = new ReferentialDtoBuilder<>(result); + ReferentialDtoBuilder<M> visitor = new ReferentialDtoBuilder<>(result, referentialLocale); return visitor; } @@ -69,8 +72,9 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl return referentialDtoTypesBuilder.build(); } - protected ReferentialDtoBuilder(M result) { + protected ReferentialDtoBuilder(M result, ReferentialLocale referentialLocale) { this.result = result; + this.referentialLocale = referentialLocale; this.binder = (Binder<M, M>) BinderFactory.newBinder(result.getClass()); this.valuesBuilder = new ImmutableMap.Builder<>(); this.visitor = new ToModelVisitor(); @@ -119,7 +123,7 @@ public class ReferentialDtoBuilder<M extends ReferentialDto> implements Closeabl protected <R extends ReferentialDto> ReferentialLabelDto<R> entityToRef(Class<R> dtoType, TopiaEntity entityValue) { referentialDtoTypesBuilder.add(dtoType); - ReferentialLabelDto<R> label = ReferentialLabelDtos.newReferentialLabelDto(dtoType, entityValue); + ReferentialLabelDto<R> label = ReferentialLabelDtos.newReferentialLabelDto(dtoType, referentialLocale, entityValue); label.setId(entityValue.getTopiaId()); 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 4214bf6..33518d8 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 @@ -232,7 +232,7 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe List<TopiaEntity> entities = loadEntities(entityType); LinkedHashSet<ReferentialLabelDto<D>> labels = new LinkedHashSet<>(); for (TopiaEntity entity : entities) { - ReferentialLabelDto<D> dto = ReferentialLabelDtos.newReferentialLabelDto(dtoType, entity); + ReferentialLabelDto<D> dto = ReferentialLabelDtos.newReferentialLabelDto(dtoType, serviceContext.getReferentialLocale(), entity); labels.add(dto); } ReferentialLabelSetDto labelSetDto = ReferentialLabelSetDtos.newReferentialLabelSetDto(dtoType, labels); @@ -324,7 +324,7 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe } protected <D extends ReferentialDto> FormDto<D> entityToReferentialFormDto(Class<D> dtoType, TopiaEntity entity) { - try (ReferentialDtoBuilder<D> dtoBuilder = ReferentialDtoBuilder.create(dtoType)) { + try (ReferentialDtoBuilder<D> dtoBuilder = ReferentialDtoBuilder.create(dtoType, serviceContext.getReferentialLocale())) { // copy entity dtoBuilder.copyEntity(entity); 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 a0fb4e6..5c1dcb4 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 @@ -6,7 +6,12 @@ import fr.ird.observe.entities.referentiel.Organism; import fr.ird.observe.entities.referentiel.OrganismImpl; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ProgramImpl; +import fr.ird.observe.services.dto.constants.ReferentialLocale; +import fr.ird.observe.services.dto.referential.I18nReferentialDto; 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.junit.Assert; import org.junit.Test; import org.nuiton.util.DateUtil; @@ -51,33 +56,53 @@ public class ReferentialDtoBuilderTest { organism.setCode("organismCode"); program.setOrganism(organism); - ReferentialDtoBuilder<ProgramDto> builder = ReferentialDtoBuilder.create(ProgramDto.class); + ReferentialDtoBuilder<ProgramDto> builder = ReferentialDtoBuilder.create(ProgramDto.class, ReferentialLocale.FR); builder.copyEntity(program); - ProgramDto programModel = builder.build(); + ProgramDto programDto = builder.build(); - Assert.assertEquals(program.getCode(), programModel.getCode()); - Assert.assertEquals(program.isNeedComment(), programModel.isNeedComment()); - Assert.assertNotNull(programModel.getStatus()); - Assert.assertEquals(program.getStatus().name(), programModel.getStatus().name()); + Assert.assertEquals(program.getCode(), programDto.getCode()); + Assert.assertEquals(program.isNeedComment(), programDto.isNeedComment()); + Assert.assertNotNull(programDto.getStatus()); + Assert.assertEquals(program.getStatus().name(), programDto.getStatus().name()); - Assert.assertEquals(program.getLabel1(), programModel.getLabel1()); - Assert.assertEquals(program.getLabel2(), programModel.getLabel2()); - Assert.assertEquals(program.getLabel3(), programModel.getLabel3()); - Assert.assertEquals(program.getLabel4(), programModel.getLabel4()); - Assert.assertEquals(program.getLabel5(), programModel.getLabel5()); - Assert.assertEquals(program.getLabel6(), programModel.getLabel6()); - Assert.assertEquals(program.getLabel7(), programModel.getLabel7()); - Assert.assertEquals(program.getLabel8(), programModel.getLabel8()); - Assert.assertEquals(program.getTopiaId(), programModel.getId()); - Assert.assertNotNull(programModel.getGearType()); - Assert.assertEquals(program.getGearType().name(), programModel.getGearType().name()); - Assert.assertEquals(program.getTargetDiscardsObservation(), programModel.getTargetDiscardsObservation()); - Assert.assertNotNull(programModel.getOrganism()); - Assert.assertEquals(program.getOrganism().getTopiaId(), programModel.getOrganism().getId()); - Assert.assertEquals(program.getOrganism().getCode(), programModel.getOrganism().getLabelPropertyValue("code")); - Assert.assertEquals(program.getOrganism().getLabel1(), programModel.getOrganism().getLabelPropertyValue("label1")); - Assert.assertEquals(program.getOrganism().getLabel2(), programModel.getOrganism().getLabelPropertyValue("label2")); - Assert.assertEquals(program.getOrganism().getLabel3(), programModel.getOrganism().getLabelPropertyValue("label3")); + Assert.assertEquals(program.getLabel1(), programDto.getLabel1()); + Assert.assertEquals(program.getLabel2(), programDto.getLabel2()); + Assert.assertEquals(program.getLabel3(), programDto.getLabel3()); + Assert.assertEquals(program.getLabel4(), programDto.getLabel4()); + Assert.assertEquals(program.getLabel5(), programDto.getLabel5()); + Assert.assertEquals(program.getLabel6(), programDto.getLabel6()); + Assert.assertEquals(program.getLabel7(), programDto.getLabel7()); + Assert.assertEquals(program.getLabel8(), programDto.getLabel8()); + Assert.assertEquals(program.getTopiaId(), programDto.getId()); + Assert.assertNotNull(programDto.getGearType()); + Assert.assertEquals(program.getGearType().name(), programDto.getGearType().name()); + Assert.assertEquals(program.getTargetDiscardsObservation(), programDto.getTargetDiscardsObservation()); + + ReferentialLabelDto organismDto = programDto.getOrganism(); + Assert.assertNotNull(organismDto); + Assert.assertEquals(organism.getTopiaId(), organismDto.getId()); + Assert.assertEquals(organism.getCode(), organismDto.getLabelPropertyValue(ReferentialDto.PROPERTY_CODE)); + Assert.assertEquals(organism.getLabel2(), organismDto.getLabelPropertyValue(ReferentialLabelDto.PROPERTY_LABEL)); + + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL1); + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL2); + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL3); + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL4); + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL5); + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL6); + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL7); + assertPropertyNameDoesNotFound(organismDto, I18nReferentialDto.PROPERTY_LABEL8); + + } + + protected void assertPropertyNameDoesNotFound(ReferentialLabelDto dto, String propertyName) { + + try { + dto.getLabelPropertyValue(propertyName); + Assert.fail(); + } catch (ReferentielLabelValueNotFoundException e) { + Assert.assertTrue(true); + } } -- 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