Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
0c952acb
by Tony Chemit at 2020-12-18T20:32:47+01:00
-
b2ace90a
by Tony Chemit at 2020-12-18T20:34:52+01:00
-
f11cbc8e
by Tony Chemit at 2020-12-18T20:47:37+01:00
13 changed files:
- − models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/LonglinePositionAware.java
- models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetImpl.java
- models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/LonglineElementAware.java → models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetTopiaDao.java
- models/persistence/src/main/models/Observe-30-data-ll-observation.model
- pom.xml
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocal.java
- services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocalTest.java
- tests/test/src/main/resources/db/8.0/dataForTestLongline.sql.gz
- tests/test/src/main/resources/db/8.0/dataForTestSeine.sql.gz
- tests/test/src/main/resources/db/8.0/empty_h2.sql.gz
- tests/test/src/main/resources/db/8.0/empty_pg.sql.gz
- tests/test/src/main/resources/db/8.0/referentiel.sql.gz
- toolkit/persistence/src/main/java/fr/ird/observe/entities/EntityHelper.java
Changes:
| 1 |
-package fr.ird.observe.entities.data.ll.observation;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe Models :: Persistence
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.dto.data.DataDto;
|
|
| 26 |
-import fr.ird.observe.dto.reference.DataDtoReference;
|
|
| 27 |
-import fr.ird.observe.entities.data.DataEntity;
|
|
| 28 |
- |
|
| 29 |
-/**
|
|
| 30 |
- * Place this contract on any data that use a position on a longline.
|
|
| 31 |
- * Created on 1/6/15.
|
|
| 32 |
- *
|
|
| 33 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 34 |
- * @see Catch
|
|
| 35 |
- * @see Tdr
|
|
| 36 |
- * @see fr.ird.observe.dto.data.ll.observation.LonglinePositionAware
|
|
| 37 |
- * @since 3.11
|
|
| 38 |
- */
|
|
| 39 |
-public interface LonglinePositionAware<Dt extends DataDto, R extends DataDtoReference> extends DataEntity<Dt, R> {
|
|
| 40 |
- |
|
| 41 |
- void setSection(Section section);
|
|
| 42 |
- |
|
| 43 |
- Section getSection();
|
|
| 44 |
- |
|
| 45 |
- void setBasket(Basket basket);
|
|
| 46 |
- |
|
| 47 |
- Basket getBasket();
|
|
| 48 |
- |
|
| 49 |
- void setBranchline(Branchline branchline);
|
|
| 50 |
- |
|
| 51 |
- Branchline getBranchline();
|
|
| 52 |
- |
|
| 53 |
-}
|
| ... | ... | @@ -22,15 +22,12 @@ package fr.ird.observe.entities.data.ll.observation; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import com.google.common.collect.ImmutableMap;
|
|
| 26 |
-import com.google.common.collect.Maps;
|
|
| 27 | 25 |
import fr.ird.observe.dto.CoordinateHelper;
|
| 28 | 26 |
import fr.ird.observe.dto.data.DataDto;
|
| 29 | 27 |
import fr.ird.observe.dto.data.ll.observation.BasketReference;
|
| 30 | 28 |
import fr.ird.observe.dto.data.ll.observation.BranchlineReference;
|
| 31 | 29 |
import fr.ird.observe.dto.data.ll.observation.LonglinePositionContainerAware;
|
| 32 | 30 |
import fr.ird.observe.dto.data.ll.observation.SectionReference;
|
| 33 |
-import fr.ird.observe.dto.data.ll.observation.SetDetailCompositionDto;
|
|
| 34 | 31 |
import fr.ird.observe.dto.data.ll.observation.SetDto;
|
| 35 | 32 |
import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 36 | 33 |
|
| ... | ... | @@ -44,10 +41,6 @@ public class SetImpl extends SetAbstract { |
| 44 | 41 |
@Override
|
| 45 | 42 |
public <D extends DataDto> void toDto(ReferentialLocale referentialLocale, D dto) {
|
| 46 | 43 |
boolean useLonglinePosition = dto instanceof LonglinePositionContainerAware;
|
| 47 |
- boolean detailComposition = dto instanceof SetDetailCompositionDto;
|
|
| 48 |
- if (useLonglinePosition || detailComposition) {
|
|
| 49 |
- loadEntityParents();
|
|
| 50 |
- }
|
|
| 51 | 44 |
super.toDto(referentialLocale, dto);
|
| 52 | 45 |
if (dto instanceof SetDto) {
|
| 53 | 46 |
SetDto dto1 = (SetDto) dto;
|
| ... | ... | @@ -56,62 +49,27 @@ public class SetImpl extends SetAbstract { |
| 56 | 49 |
dto1.setHaulingStartQuadrant(CoordinateHelper.getQuadrant(haulingStartLongitude, haulingStartLatitude));
|
| 57 | 50 |
dto1.setHaulingEndQuadrant(CoordinateHelper.getQuadrant(haulingEndLongitude, haulingEndLatitude));
|
| 58 | 51 |
}
|
| 59 |
- if (detailComposition) {
|
|
| 60 |
- loadDtoParents((SetDetailCompositionDto) dto);
|
|
| 61 |
- }
|
|
| 62 | 52 |
if (useLonglinePosition) {
|
| 63 | 53 |
loadDtoReferenceParents((LonglinePositionContainerAware) dto, referentialLocale);
|
| 64 | 54 |
}
|
| 65 | 55 |
}
|
| 66 | 56 |
|
| 67 |
- private void loadEntityParents() {
|
|
| 68 |
- getSection().forEach(section -> {
|
|
| 69 |
- section.setParentId(getTopiaId());
|
|
| 70 |
- section.getBasket().forEach(basket -> {
|
|
| 71 |
- String sectionId = section.getTopiaId();
|
|
| 72 |
- basket.setParentId(sectionId);
|
|
| 73 |
- String basketId = basket.getTopiaId();
|
|
| 74 |
- basket.getBranchline().forEach(branchline -> branchline.setParentId(basketId));
|
|
| 75 |
- });
|
|
| 76 |
- });
|
|
| 77 |
- }
|
|
| 78 |
- |
|
| 79 |
- private void loadDtoParents(SetDetailCompositionDto dto) {
|
|
| 80 |
- //FIXME If not performant, let's used an optimized dao query
|
|
| 81 |
- ImmutableMap<String, Section> sectionsById = Maps.uniqueIndex(getSection(), Section::getTopiaId);
|
|
| 82 |
- dto.getSection().forEach(section -> {
|
|
| 83 |
- section.setParentId(dto.getId());
|
|
| 84 |
- String sectionId = section.getTopiaId();
|
|
| 85 |
- Section entitySection = sectionsById.get(sectionId);
|
|
| 86 |
- ImmutableMap<String, Basket> basketsById = Maps.uniqueIndex(entitySection.getBasket(), Basket::getTopiaId);
|
|
| 87 |
- section.setNotUsed(entitySection.isNotUsed());
|
|
| 88 |
- section.getBasket().forEach(basket -> {
|
|
| 89 |
- basket.setParentId(sectionId);
|
|
| 90 |
- String basketId = basket.getTopiaId();
|
|
| 91 |
- Basket entityBasket = basketsById.get(basketId);
|
|
| 92 |
- basket.setNotUsed(entityBasket.isNotUsed());
|
|
| 93 |
- ImmutableMap<String, Branchline> branchlinesById = Maps.uniqueIndex(entityBasket.getBranchline(), Branchline::getTopiaId);
|
|
| 94 |
- basket.getBranchline().forEach(branchline -> {
|
|
| 95 |
- String branchlineId = branchline.getId();
|
|
| 96 |
- Branchline entityBranchline = branchlinesById.get(branchlineId);
|
|
| 97 |
- branchline.setParentId(basketId);
|
|
| 98 |
- branchline.setNotUsed(entityBranchline.isNotUsed());
|
|
| 99 |
- });
|
|
| 100 |
- });
|
|
| 101 |
- });
|
|
| 102 |
- }
|
|
| 103 |
- |
|
| 104 | 57 |
private void loadDtoReferenceParents(LonglinePositionContainerAware dto, ReferentialLocale referentialLocale) {
|
| 105 | 58 |
List<SectionReference> sections = new LinkedList<>();
|
| 106 | 59 |
List<BasketReference> baskets = new LinkedList<>();
|
| 107 | 60 |
List<BranchlineReference> branchlines = new LinkedList<>();
|
| 108 | 61 |
getSection().forEach(section -> {
|
| 62 |
+ section.setParentId(getTopiaId());
|
|
| 63 |
+ String sectionId = section.getTopiaId();
|
|
| 109 | 64 |
SectionReference sectionReference = section.toReference(referentialLocale);
|
| 110 | 65 |
sections.add(sectionReference);
|
| 111 | 66 |
section.getBasket().forEach(basket -> {
|
| 67 |
+ String basketId = basket.getTopiaId();
|
|
| 68 |
+ basket.setParentId(sectionId);
|
|
| 112 | 69 |
BasketReference basketReference = basket.toReference(referentialLocale);
|
| 113 | 70 |
baskets.add(basketReference);
|
| 114 | 71 |
basket.getBranchline().forEach(branchline -> {
|
| 72 |
+ branchline.setParentId(basketId);
|
|
| 115 | 73 |
BranchlineReference branchlineReference = branchline.toReference(referentialLocale);
|
| 116 | 74 |
branchlines.add(branchlineReference);
|
| 117 | 75 |
});
|
| 1 | 1 |
package fr.ird.observe.entities.data.ll.observation;
|
| 2 | 2 |
|
| 3 |
-/*
|
|
| 3 |
+/*-
|
|
| 4 | 4 |
* #%L
|
| 5 | 5 |
* ObServe Models :: Persistence
|
| 6 | 6 |
* %%
|
| ... | ... | @@ -22,37 +22,44 @@ package fr.ird.observe.entities.data.ll.observation; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import fr.ird.observe.dto.DtoParentAware;
|
|
| 26 |
-import fr.ird.observe.dto.data.DataDto;
|
|
| 27 |
-import fr.ird.observe.dto.reference.DataDtoReference;
|
|
| 28 |
-import fr.ird.observe.entities.data.DataEntity;
|
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 26 |
+import fr.ird.observe.spi.context.DataDtoEntityContext;
|
|
| 27 |
+ |
|
| 28 |
+import java.util.List;
|
|
| 29 | 29 |
|
| 30 | 30 |
/**
|
| 31 |
- * Place this contract on any element involved in longline definition.
|
|
| 32 |
- * Created on 12/13/14.
|
|
| 31 |
+ * Created on 12/18/2020.
|
|
| 33 | 32 |
*
|
| 34 | 33 |
* @author Tony Chemit - dev@tchemit.fr
|
| 35 |
- * @see Section
|
|
| 36 |
- * @see Basket
|
|
| 37 |
- * @see Branchline
|
|
| 38 |
- * @see fr.ird.observe.dto.data.ll.observation.LonglineElementAware
|
|
| 39 |
- * @since 3.10
|
|
| 34 |
+ * @since 8.0.1
|
|
| 40 | 35 |
*/
|
| 41 |
-public interface LonglineElementAware<Dt extends DataDto, R extends DataDtoReference> extends DataEntity<Dt, R>, DtoParentAware {
|
|
| 42 |
- |
|
| 43 |
- Integer getSettingIdentifier();
|
|
| 44 |
- |
|
| 45 |
- void setSettingIdentifier(Integer settingIdentifier);
|
|
| 36 |
+public class SetTopiaDao extends AbstractSetTopiaDao<Set> {
|
|
| 46 | 37 |
|
| 47 |
- Integer getHaulingIdentifier();
|
|
| 38 |
+ private static final String SQL_PATTERN = "SELECT DISTINCT(%1$s) FROM %2$s WHERE set = '%3$s' AND %1$s IS NOT NULL";
|
|
| 48 | 39 |
|
| 49 |
- void setHaulingIdentifier(Integer haulingIdentifier);
|
|
| 40 |
+ public ImmutableSet<String> getSectionUsed(String setId) {
|
|
| 41 |
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
|
| 42 |
+ getUsages(Tdr.SPI, Tdr.PROPERTY_SECTION, setId, builder);
|
|
| 43 |
+ getUsages(Catch.SPI, Catch.PROPERTY_SECTION, setId, builder);
|
|
| 44 |
+ return builder.build();
|
|
| 45 |
+ }
|
|
| 50 | 46 |
|
| 51 |
- boolean isTdrEmpty();
|
|
| 47 |
+ public ImmutableSet<String> getBasketUsed(String setId) {
|
|
| 48 |
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
|
| 49 |
+ getUsages(Tdr.SPI, Tdr.PROPERTY_BASKET, setId, builder);
|
|
| 50 |
+ getUsages(Catch.SPI, Catch.PROPERTY_BASKET, setId, builder);
|
|
| 51 |
+ return builder.build();
|
|
| 52 |
+ }
|
|
| 52 | 53 |
|
| 53 |
- boolean isCatchesEmpty();
|
|
| 54 |
+ public ImmutableSet<String> getBranchlineUsed(String setId) {
|
|
| 55 |
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
|
| 56 |
+ getUsages(Tdr.SPI, Tdr.PROPERTY_BRANCHLINE, setId, builder);
|
|
| 57 |
+ getUsages(Catch.SPI, Catch.PROPERTY_BRANCHLINE, setId, builder);
|
|
| 58 |
+ return builder.build();
|
|
| 59 |
+ }
|
|
| 54 | 60 |
|
| 55 |
- default boolean isNotUsed() {
|
|
| 56 |
- return isTdrEmpty() && isCatchesEmpty();
|
|
| 61 |
+ protected void getUsages(DataDtoEntityContext<?, ?, ?, ?> spi, String propertyName, String setId, ImmutableSet.Builder<String> ids) {
|
|
| 62 |
+ List<String> newIds = topiaSqlSupport.findMultipleResult(String.format(SQL_PATTERN, propertyName, spi.getEntitySqlDescriptor().getTable().getSchemaAndTableName(), setId), r -> r.getString(1));
|
|
| 63 |
+ ids.addAll(newIds);
|
|
| 57 | 64 |
}
|
| 58 | 65 |
}
|
| 1 | 1 |
package fr.ird.observe.entities.data.ll.observation | dbSchema=ll_observation
|
| 2 | 2 |
|
| 3 |
-interface data.ll.observation.LonglineElementAware > fr.ird.observe.entities.data.DataEntity
|
|
| 4 |
-getSettingIdentifier() Integer
|
|
| 5 |
-setSettingIdentifier(identifier Integer)
|
|
| 6 |
-getHaulingIdentifier() Integer
|
|
| 7 |
-setHaulingIdentifier(identifier Integer)
|
|
| 8 |
- |
|
| 9 |
-interface data.ll.observation.LonglinePositionAware > fr.ird.observe.entities.data.DataEntity
|
|
| 10 |
-getSection() data.ll.observation.Section
|
|
| 11 |
-setSection(section data.ll.observation.Section)
|
|
| 12 |
-getBasket() data.ll.observation.Basket
|
|
| 13 |
-setBasket(basket data.ll.observation.Basket)
|
|
| 14 |
-getBranchline() data.ll.observation.Branchline
|
|
| 15 |
-setBranchline(branchline data.ll.observation.Branchline)
|
|
| 16 |
- |
|
| 17 | 3 |
data.ll.observation.Activity > data.DataEntity | entity constants=date,time
|
| 18 | 4 |
comment + {*:1} String | hibernateAttributeType=text
|
| 19 | 5 |
timeStamp + {*:1} Date
|
| ... | ... | @@ -35,16 +21,14 @@ individualWeight + {*:1} Float |
| 35 | 21 |
baitSettingStatus {*:1} referential.ll.common.BaitSettingStatus
|
| 36 | 22 |
baitType {*:1} referential.ll.common.BaitType
|
| 37 | 23 |
|
| 38 |
-data.ll.observation.Basket > data.DataEntity >> data.ll.observation.LonglineElementAware fr.ird.observe.dto.DtoParentAware | entity
|
|
| 24 |
+data.ll.observation.Basket > data.DataEntity >> fr.ird.observe.dto.DtoParentAware | entity
|
|
| 39 | 25 |
settingIdentifier + {*:1} Integer | notNull
|
| 40 | 26 |
haulingIdentifier + {*:1} Integer
|
| 41 | 27 |
floatline1Length + {*:1} Float
|
| 42 | 28 |
floatline2Length + {*:1} Float
|
| 43 | 29 |
branchline + {*} data.ll.observation.Branchline | unique orderBy=settingIdentifier inverse=false
|
| 44 |
-catches {*} data.ll.observation.Catch | skipModelNavigation inverse
|
|
| 45 |
-tdr {*} data.ll.observation.Tdr | skipModelNavigation inverse
|
|
| 46 | 30 |
|
| 47 |
-data.ll.observation.Branchline > data.DataEntity >> data.ll.observation.LonglineElementAware fr.ird.observe.dto.DtoParentAware | entity constants=timerTimeOnBoardDate,timerTimeOnBoardTime
|
|
| 31 |
+data.ll.observation.Branchline > data.DataEntity >> fr.ird.observe.dto.DtoParentAware | entity constants=timerTimeOnBoardDate,timerTimeOnBoardTime
|
|
| 48 | 32 |
comment + {*:1} String | hibernateAttributeType=text
|
| 49 | 33 |
settingIdentifier + {*:1} Integer | notNull
|
| 50 | 34 |
haulingIdentifier + {*:1} Integer
|
| ... | ... | @@ -62,8 +46,6 @@ tracelineLength + {*:1} Float | sqlType=numeric |
| 62 | 46 |
hookLost + {*:1} Boolean
|
| 63 | 47 |
traceCutOff + {*:1} Boolean
|
| 64 | 48 |
hookType {*:0..1} referential.ll.common.HookType
|
| 65 |
-catches {*} data.ll.observation.Catch | skipModelNavigation inverse
|
|
| 66 |
-tdr {*} data.ll.observation.Tdr | skipModelNavigation inverse
|
|
| 67 | 49 |
baitType {*:0..1} referential.ll.common.BaitType
|
| 68 | 50 |
topType {*:0..1} referential.ll.common.LineType
|
| 69 | 51 |
tracelineType {*:0..1} referential.ll.common.LineType
|
| ... | ... | @@ -78,7 +60,7 @@ tracelineLength + {*:1} Float |
| 78 | 60 |
topType {*:0..1} referential.ll.common.LineType
|
| 79 | 61 |
tracelineType {*:0..1} referential.ll.common.LineType
|
| 80 | 62 |
|
| 81 |
-data.ll.observation.Catch > data.DataEntity >> data.ll.observation.LonglinePositionAware | entity
|
|
| 63 |
+data.ll.observation.Catch > data.DataEntity | entity
|
|
| 82 | 64 |
comment + {*:1} String | hibernateAttributeType=text
|
| 83 | 65 |
count + {*:1} Integer
|
| 84 | 66 |
totalWeight + {*:1} Float | sqlType=numeric
|
| ... | ... | @@ -123,12 +105,10 @@ hookOffset + {*:1} Integer |
| 123 | 105 |
hookType {*:1} referential.ll.common.HookType
|
| 124 | 106 |
hookSize {*:1} referential.ll.common.HookSize
|
| 125 | 107 |
|
| 126 |
-data.ll.observation.Section > data.DataEntity >> data.ll.observation.LonglineElementAware fr.ird.observe.dto.DtoParentAware | entity
|
|
| 108 |
+data.ll.observation.Section > data.DataEntity >> fr.ird.observe.dto.DtoParentAware | entity
|
|
| 127 | 109 |
settingIdentifier + {*:1} Integer | notNull
|
| 128 | 110 |
haulingIdentifier + {*:1} Integer
|
| 129 | 111 |
basket + {*} data.ll.observation.Basket | unique orderBy=settingIdentifier inverse=false
|
| 130 |
-catches {*} data.ll.observation.Catch | skipModelNavigation inverse
|
|
| 131 |
-tdr {*} data.ll.observation.Tdr | skipModelNavigation inverse
|
|
| 132 | 112 |
|
| 133 | 113 |
data.ll.observation.SensorUsed > data.DataEntity >> data.DataFileAware | entity
|
| 134 | 114 |
data + {*:1} !java.sql.Blob
|
| ... | ... | @@ -190,7 +170,7 @@ size + {*:1} Float | sqlType=numeric |
| 190 | 170 |
sizeMeasureType {*:1} referential.common.SizeMeasureType
|
| 191 | 171 |
lengthMeasureMethod {*:0..1} referential.common.LengthMeasureMethod
|
| 192 | 172 |
|
| 193 |
-data.ll.observation.Tdr > data.DataEntity >> data.ll.observation.LonglinePositionAware data.DataFileAware | entity constants=deploymentStartDate,deploymentStartTime,deploymentEndDate,deploymentEndTime,fishingStartDate,fishingStartTime,fishingEndDate,fishingEndTime
|
|
| 173 |
+data.ll.observation.Tdr > data.DataEntity >> data.DataFileAware | entity constants=deploymentStartDate,deploymentStartTime,deploymentEndDate,deploymentEndTime,fishingStartDate,fishingStartTime,fishingEndDate,fishingEndTime
|
|
| 194 | 174 |
floatline1Length + {*:1} Float | sqlType=numeric
|
| 195 | 175 |
floatline2Length + {*:1} Float | sqlType=numeric
|
| 196 | 176 |
serialNo + {*:1} String
|
| ... | ... | @@ -153,7 +153,7 @@ |
| 153 | 153 |
<lib.version.h2>1.4.196</lib.version.h2>
|
| 154 | 154 |
<lib.version.nuiton.utils>3.0</lib.version.nuiton.utils>
|
| 155 | 155 |
|
| 156 |
-<!-- <lib.version.java4all.topia>1.31</lib.version.java4all.topia>-->
|
|
| 156 |
+ <lib.version.java4all.topia>1.32</lib.version.java4all.topia>
|
|
| 157 | 157 |
<!-- <lib.version.java4all.eugene>3.0-alpha-38</lib.version.java4all.eugene>-->
|
| 158 | 158 |
<lib.version.java4all.jaxx>3.0-alpha-85</lib.version.java4all.jaxx>
|
| 159 | 159 |
<!--<lib.version.java4all.application-context>1.0.3-SNAPSHOT</lib.version.java4all.application-context>-->
|
| ... | ... | @@ -22,8 +22,11 @@ package fr.ird.observe.services.local.service.data.ll.observation; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 25 | 26 |
import fr.ird.observe.dto.data.ll.observation.SetDetailCompositionDto;
|
| 27 |
+import fr.ird.observe.dto.form.Form;
|
|
| 26 | 28 |
import fr.ird.observe.entities.data.ll.observation.Set;
|
| 29 |
+import fr.ird.observe.entities.data.ll.observation.SetTopiaDao;
|
|
| 27 | 30 |
import fr.ird.observe.services.local.service.data.Simple2DataServiceLocalSupport;
|
| 28 | 31 |
import fr.ird.observe.services.service.data.ll.observation.SetDetailCompositionService;
|
| 29 | 32 |
|
| ... | ... | @@ -37,4 +40,29 @@ public class SetDetailCompositionServiceLocal extends Simple2DataServiceLocalSup |
| 37 | 40 |
super(Set.SPI, Set.SET_DETAIL_COMPOSITION_SPI, null);
|
| 38 | 41 |
}
|
| 39 | 42 |
|
| 43 |
+ @Override
|
|
| 44 |
+ protected Form<SetDetailCompositionDto> entityToForm(Set entity) {
|
|
| 45 |
+ Form<SetDetailCompositionDto> form = super.entityToForm(entity);
|
|
| 46 |
+ SetDetailCompositionDto dto = form.getObject();
|
|
| 47 |
+ SetTopiaDao dao = Set.SPI.getDao(getTopiaPersistenceContext());
|
|
| 48 |
+ ImmutableSet<String> sectionUsed = dao.getSectionUsed(entity.getTopiaId());
|
|
| 49 |
+ ImmutableSet<String> basketUsed = dao.getBasketUsed(entity.getTopiaId());
|
|
| 50 |
+ ImmutableSet<String> branchlineUsed = dao.getBranchlineUsed(entity.getTopiaId());
|
|
| 51 |
+ dto.getSection().forEach(section -> {
|
|
| 52 |
+ section.setParentId(dto.getId());
|
|
| 53 |
+ String sectionId = section.getTopiaId();
|
|
| 54 |
+ section.setNotUsed(!sectionUsed.contains(sectionId));
|
|
| 55 |
+ section.getBasket().forEach(basket -> {
|
|
| 56 |
+ basket.setParentId(sectionId);
|
|
| 57 |
+ String basketId = basket.getTopiaId();
|
|
| 58 |
+ basket.setNotUsed(!basketUsed.contains(basketId));
|
|
| 59 |
+ basket.getBranchline().forEach(branchline -> {
|
|
| 60 |
+ String branchlineId = branchline.getId();
|
|
| 61 |
+ branchline.setParentId(basketId);
|
|
| 62 |
+ branchline.setNotUsed(!branchlineUsed.contains(branchlineId));
|
|
| 63 |
+ });
|
|
| 64 |
+ });
|
|
| 65 |
+ });
|
|
| 66 |
+ return form;
|
|
| 67 |
+ }
|
|
| 40 | 68 |
}
|
| ... | ... | @@ -79,6 +79,7 @@ public class SetDetailCompositionServiceLocalTest extends ServiceLocalTestSuppor |
| 79 | 79 |
Assert.assertEquals(Integer.valueOf(18), sectionDto.getHaulingIdentifier());
|
| 80 | 80 |
Assert.assertEquals(13, sectionDto.getBasketSize());
|
| 81 | 81 |
Assert.assertNotNull(sectionDto.getParentId());
|
| 82 |
+ Assert.assertTrue(sectionDto.isNotUsed());
|
|
| 82 | 83 |
Assert.assertEquals(compositionDto.getId(), sectionDto.getParentId());
|
| 83 | 84 |
Assert.assertNotNull(sectionDto.toReference(ReferentialLocale.FR));
|
| 84 | 85 |
Assert.assertNotNull(sectionDto.toReference(ReferentialLocale.FR).getParentId());
|
| ... | ... | @@ -88,6 +89,8 @@ public class SetDetailCompositionServiceLocalTest extends ServiceLocalTestSuppor |
| 88 | 89 |
Assert.assertEquals(Integer.valueOf(13), basketDto.getHaulingIdentifier());
|
| 89 | 90 |
Assert.assertEquals(6, basketDto.getBranchlineSize());
|
| 90 | 91 |
Assert.assertNotNull(basketDto.getParentId());
|
| 92 |
+ Assert.assertTrue(basketDto.isNotUsed());
|
|
| 93 |
+ |
|
| 91 | 94 |
Assert.assertEquals(sectionDto.getId(), basketDto.getParentId());
|
| 92 | 95 |
Assert.assertNotNull(basketDto.toReference(ReferentialLocale.FR));
|
| 93 | 96 |
Assert.assertNotNull(basketDto.toReference(ReferentialLocale.FR).getParentId());
|
| ... | ... | @@ -96,9 +99,14 @@ public class SetDetailCompositionServiceLocalTest extends ServiceLocalTestSuppor |
| 96 | 99 |
Assert.assertEquals(Integer.valueOf(1), branchlineDto.getSettingIdentifier());
|
| 97 | 100 |
Assert.assertEquals(Integer.valueOf(6), branchlineDto.getHaulingIdentifier());
|
| 98 | 101 |
Assert.assertNotNull(branchlineDto.getParentId());
|
| 102 |
+ Assert.assertTrue(branchlineDto.isNotUsed());
|
|
| 99 | 103 |
Assert.assertEquals(basketDto.getId(), branchlineDto.getParentId());
|
| 100 | 104 |
Assert.assertNotNull(branchlineDto.toReference(ReferentialLocale.FR));
|
| 101 | 105 |
Assert.assertNotNull(branchlineDto.toReference(ReferentialLocale.FR).getParentId());
|
| 106 |
+ |
|
| 107 |
+ sectionDto = compositionDto.getSection(6);
|
|
| 108 |
+ basketDto = sectionDto.getBasket(8);
|
|
| 109 |
+ Assert.assertFalse(basketDto.isNotUsed());
|
|
| 102 | 110 |
}
|
| 103 | 111 |
|
| 104 | 112 |
@Test
|
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
| ... | ... | @@ -204,18 +204,6 @@ public class EntityHelper { |
| 204 | 204 |
return dtoList;
|
| 205 | 205 |
}
|
| 206 | 206 |
|
| 207 |
- public static <DD extends DataDto, RR extends DataDtoReference, EE extends DataEntity<DD, RR>> LinkedHashSet<RR> toDataReferenceLinkedHashSet(ReferentialLocale referentialLocale, Collection<EE> entities) {
|
|
| 208 |
- LinkedHashSet<RR> result = null;
|
|
| 209 |
- if (entities != null) {
|
|
| 210 |
- result = new LinkedHashSet<>();
|
|
| 211 |
- for (EE entity : entities) {
|
|
| 212 |
- result.add(entity.toReference(referentialLocale));
|
|
| 213 |
- }
|
|
| 214 |
- }
|
|
| 215 |
- return result;
|
|
| 216 |
- }
|
|
| 217 |
- |
|
| 218 |
- |
|
| 219 | 207 |
@SuppressWarnings({"unchecked", "unused"})
|
| 220 | 208 |
public static <DD extends DataDto, RR extends DataDtoReference, EE extends DataEntity<?, ?>, C extends Collection<EE>> C toDataEntityCollectionFromReference(Collection<RR> referencesList, C entities) {
|
| 221 | 209 |
if (entities == null) {
|