Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: d39db83e by Tony Chemit at 2020-09-12T16:46:32+02:00 Use the natural order of attributes declaration to generate the form definition, in ordre to have a deterministic order (some filters may need other ones) - - - - - 28a14073 by Tony Chemit at 2020-09-12T17:11:53+02:00 Insertion du plan de cuves - See #1260 Meilleur filtrage des catégories de poids et espèces - - - - - 460db38a by Tony Chemit at 2020-09-13T21:43:17+02:00 Begin of usage of TopiaMetadataModelPaths - - - - - 28 changed files: - client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUI.jcss - client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUIHandler.java - client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUIModel.java - dto/src/main/models/Observe-23-data-ps-wellplan.model - persistence/pom.xml - persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java - persistence/src/main/models/Observe-21-data-ps-logbook.model - persistence/src/main/models/Observe-23-data-ps-wellplan.model - persistence/src/main/models/Observe-24-data-ps-localmarket.model - persistence/src/main/models/Observe-30-data-ll-observation.model - persistence/src/main/models/Observe-31-data-ll-logbook.model - − persistence/src/test/java/fr/ird/observe/entities/ObserveTopiaMetadataModelSupportTest.java - + persistence/src/test/java/fr/ird/observe/entities/TopiaMetadataModelPathsTest.java - pom.xml - server-core/src/main/filtered-resources/mapping - services-api/src/main/java/fr/ird/observe/services/service/data/ps/common/TripService.java - services-local/src/main/java/fr/ird/observe/services/local/service/data/ps/common/TripServiceLocal.java - services-local/src/test/java/fr/ird/observe/services/local/service/data/TripManagementServiceLocalTest.java - templates/pom.xml - templates/src/main/java/fr/ird/observe/toolkit/templates/GeneratePersistence.java - templates/src/main/java/fr/ird/observe/toolkit/templates/dto/DtoTransformer.java - toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateEntityUpdateSqlFilesMojo.java → templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityLastUpdateDateFieldSqlScriptGenerator.java - + templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityLastUpdateDateTableSqlScriptGenerator.java - persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaMetadataModelSupport.java → templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityPathsGenerator.java - test/src/main/java/fr/ird/observe/test/ObserveFixtures.java - + test/src/main/resources/fixtures/entity-paths.properties - test/src/main/resources/fixtures/global.properties - toolbox-maven-plugin/pom.xml Changes: ===================================== client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUI.jcss ===================================== @@ -18,8 +18,4 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% - */ -#activity { - _listNoLoad:true; - data:{model.getActivities()}; -} + */ \ No newline at end of file ===================================== client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUIHandler.java ===================================== @@ -25,10 +25,13 @@ package fr.ird.observe.client.datasource.editor.content.data.ps.wellplan; import fr.ird.observe.client.datasource.editor.content.data.table.ContentTableUIHandler; import fr.ird.observe.client.datasource.editor.content.data.table.ContentTableUILayoutFocusTraversalPolicy; import fr.ird.observe.client.datasource.editor.content.spi.ContentUIReferenceCache; +import fr.ird.observe.client.datasource.editor.content.spi.ReferentialReferencesFilter; import fr.ird.observe.dto.data.ps.wellplan.TripWellPlanDto; import fr.ird.observe.dto.data.ps.wellplan.WellPlanDto; import fr.ird.observe.dto.form.Form; +import fr.ird.observe.dto.referential.common.SpeciesDto; import fr.ird.observe.dto.referential.common.SpeciesReference; +import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryDto; import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference; import fr.ird.observe.dto.result.SaveResultDto; import org.nuiton.jaxx.runtime.spi.UIHandler; @@ -37,6 +40,7 @@ import java.awt.Component; import java.beans.PropertyChangeListener; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -73,7 +77,8 @@ public class WellPlanUIHandler extends ContentTableUIHandler<TripWellPlanDto, We @Override protected void onAfterInitAddReferentialFilters(ContentUIReferenceCache referenceCache) { - referenceCache.addReferentialFilter(WellPlanDto.PROPERTY_SPECIES, newPsSpeciesList(getClientConfig().getSpeciesListSeineLogbookCatchId())); + referenceCache.addReferentialFilter(WellPlanDto.PROPERTY_WEIGHT_CATEGORY, newPsLogbookWeightCategoryList(getClientConfig().getSpeciesListSeineLogbookCatchId())); + referenceCache.addReferentialFilter(WellPlanDto.PROPERTY_SPECIES, newPsSpeciesList()); } @Override @@ -109,7 +114,7 @@ public class WellPlanUIHandler extends ContentTableUIHandler<TripWellPlanDto, We newCategories = Collections.emptyList(); } else { List<WeightCategoryReference> referentialReferences = getModel().getReferenceCache().getReferentialReferences(WellPlanDto.PROPERTY_WEIGHT_CATEGORY); - newCategories = referentialReferences.stream().filter(r -> r.getSpecies().equals(species)).collect(Collectors.toList()); + newCategories = referentialReferences.stream().filter(r -> Objects.equals(r.getSpecies(), species)).collect(Collectors.toList()); WeightCategoryReference weightCategory = getModel().getTableEditBean().getWeightCategory(); if (weightCategory != null && newCategories.contains(weightCategory)) { newCategory = weightCategory; @@ -119,4 +124,17 @@ public class WellPlanUIHandler extends ContentTableUIHandler<TripWellPlanDto, We ui.getWeightCategory().setSelectedItem(newCategory); } + protected ReferentialReferencesFilter<SpeciesDto, SpeciesReference> newPsSpeciesList() { + return incomingReferences -> { + List<WeightCategoryReference> weightCategories = getModel().getReferenceCache().getReferentialReferences(WellPlanDto.PROPERTY_WEIGHT_CATEGORY); + return weightCategories.stream().map(WeightCategoryReference::getSpecies).collect(Collectors.toList()); + }; + } + + protected ReferentialReferencesFilter<WeightCategoryDto, WeightCategoryReference> newPsLogbookWeightCategoryList(String speciesListId) { + return incomingReferences -> { + String tripId = getClientUIContext().getObserveSelectModel().getSeine().getTrip().getId(); + return getPsCommonTripService().getLogbookWeightCategoryByListAndTrip(tripId, speciesListId).toList(); + }; + } } ===================================== client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUIModel.java ===================================== @@ -29,7 +29,6 @@ import fr.ird.observe.dto.data.ps.wellplan.WellPlanDto; import fr.ird.observe.dto.form.Form; import fr.ird.observe.dto.reference.DataDtoReferenceSet; -import java.util.List; import java.util.stream.Collectors; /** @@ -40,26 +39,15 @@ import java.util.stream.Collectors; */ public class WellPlanUIModel extends ContentTableUIModel<TripWellPlanDto, WellPlanDto> { - private List<ActivityReference> activities; - public WellPlanUIModel() { super(TripWellPlanDto.class, WellPlanDto.class, TripWellPlanDto.PROPERTY_WELL_PLAN); } @Override public void openForm(Form<TripWellPlanDto> form) { - super.openForm(form); - String tripId = getBean().getId(); + String tripId = form.getObject().getId(); DataDtoReferenceSet<ActivityReference> activities = getObserveDataSourcesManager().getMainDataSource().getPsLogbookActivityService().getActivitySeineByTrip(tripId); - setActivities(activities.stream().filter(ActivityReference::isSetOperation).collect(Collectors.toList())); - } - - public List<ActivityReference> getActivities() { - return activities; - } - - public void setActivities(List<ActivityReference> activities) { - this.activities = activities; - firePropertyChange("activities", activities); + getReferenceCache().setDataReferenceSet(WellPlanDto.PROPERTY_ACTIVITY, DataDtoReferenceSet.of(ActivityReference.class, activities.stream().filter(ActivityReference::isSetOperation).collect(Collectors.toList()))); + super.openForm(form); } } ===================================== dto/src/main/models/Observe-23-data-ps-wellplan.model ===================================== @@ -3,8 +3,8 @@ package fr.ird.observe.dto.data.ps.wellplan | form=self packagePriority=23 data.ps.wellplan.WellPlan > data.Data >> data.WellIdAware | references=species,well,weight,weightCategoryLabel activity {*:1} fr.ird.observe.dto.data.ps.logbook.ActivityReference | notNull well + {*:1} String | notNull -species {*:1} fr.ird.observe.dto.referential.common.SpeciesReference | notNull weightCategory {*:1} fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference | notNull +species {*:1} fr.ird.observe.dto.referential.common.SpeciesReference | notNull weight + {*:1} Float | notNull data.ps.wellplan.TripWellPlan > data.Commentable | form=data.ps.wellplan.WellPlan mainDto=data.ps.common.Trip ===================================== persistence/pom.xml ===================================== @@ -391,38 +391,6 @@ </executions> </plugin> - - <plugin> - <groupId>fr.ird.observe.toolkit</groupId> - <artifactId>toolbox-maven-plugin</artifactId> - <version>${project.version}</version> - <executions> - <execution> - <id>generate-entity-update-sql-files</id> - <goals> - <goal>generate-entity-update-sql-files</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>dto</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>fr.ird.observe.toolkit</groupId> - <artifactId>common-persistence</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.javassist</groupId> - <artifactId>javassist</artifactId> - <version>${lib.version.javassist}</version> - </dependency> - </dependencies> - </plugin> - </plugins> </build> </project> ===================================== persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java ===================================== @@ -23,7 +23,6 @@ package fr.ird.observe.entities; */ import com.google.common.collect.ImmutableSet; -import fr.ird.observe.entities.data.DataEntity; import fr.ird.observe.entities.referential.ReferentialEntity; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -33,13 +32,14 @@ import org.hibernate.tool.schema.TargetType; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.jdbc.JdbcHelper; import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPathsBuilder; import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModelPaths; import org.nuiton.topia.persistence.script.SqlScriptReader; import org.nuiton.topia.persistence.script.TopiaSqlScript; import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport; import org.nuiton.topia.service.migration.TopiaMigrationService; import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorService; +import org.nuiton.topia.service.script.table.DefaultTopiaSqlTablesPredicate; import org.nuiton.topia.service.script.table.TopiaSqlTable; import org.nuiton.topia.service.script.table.TopiaSqlTables; import org.nuiton.topia.service.script.table.TopiaSqlTablesFactory; @@ -50,20 +50,19 @@ import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; import java.util.UUID; -import java.util.function.Predicate; import java.util.stream.Collectors; public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicationContext implements TopiaMetadataModelSupport { static final String MIGRATION_SERVICE_NAME = "migration"; static final String SQL_SCRIPT_GENERATOR_BATCH_SERVICE_NAME = "sqlScriptGenerator"; - private static final Set<String> SECTIONS = ImmutableSet.of( - ObserveEntityEnum.ll_observation_Branchline.name(), - ObserveEntityEnum.ll_observation_Basket.name(), - ObserveEntityEnum.ll_observation_Section.name()); - private static final Set<String> SECTIONS_HOLDERS = ImmutableSet.of( - ObserveEntityEnum.ll_observation_Catch.name(), - ObserveEntityEnum.ll_observation_Tdr.name()); + // private static final Set<String> SECTIONS = ImmutableSet.of( +// ObserveEntityEnum.ll_observation_Branchline.name(), +// ObserveEntityEnum.ll_observation_Basket.name(), +// ObserveEntityEnum.ll_observation_Section.name()); +// private static final Set<String> SECTIONS_HOLDERS = ImmutableSet.of( +// ObserveEntityEnum.ll_observation_Catch.name(), +// ObserveEntityEnum.ll_observation_Tdr.name()); private static final Logger log = LogManager.getLogger(ObserveTopiaApplicationContext.class); @SuppressWarnings("SpellCheckingInspection") private static final String INSERT_LAST_UPDATE_PATTERN = "INSERT INTO COMMON.LASTUPDATEDATE (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, TYPE, LASTUPDATEDATE) VALUES ('fr.ird.observe.entities.LastUpdateDate#1236861982132#0.%03d', 0, CURRENT_TIMESTAMP, '%s', CURRENT_TIMESTAMP);"; @@ -90,20 +89,6 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat return new ObserveTopiaMetadataModelSupport(); } - protected static boolean rejectAssociationType0(TopiaMetadataEntity metadataEntity, TopiaMetadataEntity propertyType) { - return (SECTIONS_HOLDERS.contains(propertyType.getType()) && SECTIONS.contains(metadataEntity.getType())) - || (ObserveEntityEnum.ps_logbook_Activity.name().equals(propertyType.getType()) && ObserveEntityEnum.ps_logbook_Sample.name().equals(metadataEntity.getType())) - || (ObserveEntityEnum.ps_localmarket_Survey.name().equals(propertyType.getType()) && ObserveEntityEnum.ps_localmarket_Batch.name().equals(metadataEntity.getType())) - ; - } - - protected static boolean rejectReversedAssociationType0(TopiaMetadataEntity metadataEntity, TopiaMetadataEntity propertyType) { - return (ObserveEntityEnum.ll_observation_Activity.name().equals(propertyType.getType()) && ObserveEntityEnum.ll_logbook_Activity.name().equals(metadataEntity.getType())) - || (ObserveEntityEnum.ps_observation_Activity.name().equals(propertyType.getType()) && ObserveEntityEnum.ps_logbook_Activity.name().equals(metadataEntity.getType())) - || (ObserveEntityEnum.ll_logbook_Sample.name().equals(propertyType.getType()) && ObserveEntityEnum.ll_logbook_Activity.name().equals(metadataEntity.getType())) - ; - } - @Override public ObserveTopiaPersistenceContext newPersistenceContext() { ObserveTopiaPersistenceContext persistenceContext = new ObserveTopiaPersistenceContext( @@ -207,6 +192,11 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat return getTopiaMetadataModelSupport().getMetadataModel(); } + @Override + public TopiaMetadataModelPaths getMetadataModelPaths() { + return getTopiaMetadataModelSupport().getMetadataModelPaths(); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -243,7 +233,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat if (tripSeineTables == null) { log.debug("Loading tripSeineTables."); - tripSeineTables = topiaSqlTablesFactory.newReplicateEntityTables(new TripReplicateTablesPredicate(), ObserveEntityEnum.ps_common_Trip); + tripSeineTables = topiaSqlTablesFactory.newReplicateEntityTables(new DefaultTopiaSqlTablesPredicate(), ObserveEntityEnum.ps_common_Trip); log.info(String.format("For Trip, found %d tables to use.", tripSeineTables.size())); } return tripSeineTables; @@ -253,7 +243,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat if (tripLonglineTables == null) { log.debug("Loading tripLonglineTables."); - tripLonglineTables = topiaSqlTablesFactory.newReplicateEntityTables(new TripReplicateTablesPredicate(), ObserveEntityEnum.ll_common_Trip); + tripLonglineTables = topiaSqlTablesFactory.newReplicateEntityTables(new DefaultTopiaSqlTablesPredicate(), ObserveEntityEnum.ll_common_Trip); log.info(String.format("For Trip, found %d tables to use.", tripLonglineTables.size())); TopiaSqlTable basketTable = tripLonglineTables.getTable(ObserveEntityEnum.ll_observation_Basket); @@ -292,11 +282,10 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat } public TopiaSqlTables getReferentialTables() { - if (referentialTables == null) { log.debug("Loading referentialTables."); referentialTables = topiaSqlTablesFactory.newReplicateEntityTables( - new TripReplicateTablesPredicate(), + new DefaultTopiaSqlTablesPredicate(), Entities.REFERENCE_ENTITIES); } log.info(String.format("For Referential, found %d tables to use.", referentialTables.size())); @@ -305,112 +294,26 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat public <E extends ReferentialEntity<?, ?>> TopiaSqlTables getReferentialTable(Class<E> entityType) { ObserveEntityEnum entityEnum = ObserveEntityEnum.valueOf(entityType); - return referentialTables = topiaSqlTablesFactory.newReplicateEntityTables(new TripReplicateTablesPredicate(), entityEnum); - } - - private TopiaMetadataModelSupport getTopiaMetadataModelSupport() { - return topiaMetadataModelSupport == null ? topiaMetadataModelSupport = newModelSupport() : topiaMetadataModelSupport; + return referentialTables = topiaSqlTablesFactory.newReplicateEntityTables(new DefaultTopiaSqlTablesPredicate(), entityEnum); } public ObserveTopiaUsageModel getTopiaUsageModel() { return topiaUsageModel == null ? topiaUsageModel = new ObserveTopiaUsageModel() : topiaUsageModel; } - private void executeSqlStatements0(TopiaSqlScript content) { - - SqlScriptReader scriptLocation = content.getLocation(); -// if (getConfiguration().isH2Configuration()) { -// -// String protocol = scriptLocation.getProtocol(); -// boolean local = LOCAL_PROTOCOLS.contains(protocol.toLowerCase()); -// -// Path tempFile = null; -// try { -// if (local) { -// tempFile = Paths.get(scriptLocation.toURI()); -// } else { -// tempFile = Files.createTempFile("observeRestoreH2", ".sql"); -// Files.copy(scriptLocation.openStream(), tempFile); -// } -//// log.info(String.format("Restore script size: %s to h2 from file : %s", StringUtil.convertMemory(Files.size(tempFile)), tempFile.toString())); -// JdbcH2Helper2 jdbcH2Helper = new JdbcH2Helper2(configuration); -// -// jdbcH2Helper.restore(tempFile.toFile()); -// } finally { -// if (!local && tempFile != null) { -// Files.delete(tempFile); -// } -// } -// -// } else { - -// log.info(String.format("Load script (size: %s)", StringUtil.convertMemory(content.length))); - - try (ObserveTopiaPersistenceContext persistenceContext = newPersistenceContext()) { - persistenceContext.executeSqlScript(scriptLocation); - persistenceContext.commit(); - } -// } - - } - public BlobIdsIterator newBlobIdsIterator(Path blobIdsPath) { return new BlobIdsIterator(getMetadataModel(), blobIdsPath, this); } - private static class TripReplicateTablesPredicate implements TopiaSqlTablesFactory.TopiaSqlTablesPredicate { - - private final Set<TopiaMetadataEntity> done = new LinkedHashSet<>(); - - @Override - public boolean acceptEntity(TopiaMetadataEntity metadataEntity) { - return done.add(metadataEntity); - } - - @Override - public boolean acceptAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { - return !rejectAssociationType0(metadataEntity, propertyType); - } - - @Override - public boolean acceptReversedAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { - return !rejectReversedAssociationType0(metadataEntity, propertyType); - - } - - @Override - public boolean acceptNmAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { - return !rejectAssociationType0(metadataEntity, propertyType); - } - + private TopiaMetadataModelSupport getTopiaMetadataModelSupport() { + return topiaMetadataModelSupport == null ? topiaMetadataModelSupport = newModelSupport() : topiaMetadataModelSupport; } - public static class ObserveDataEntityPathsBuilder extends TopiaMetadataEntityPathsBuilder { - - public ObserveDataEntityPathsBuilder() { - super(e -> DataEntity.class.isAssignableFrom(ObserveEntityEnum.valueOf(e.getType()).getContract())); - } - - @Override - protected Visitor createVisitor(Predicate<TopiaMetadataEntity> acceptType) { - return new ObServeVisitor(acceptType); - } - - private static class ObServeVisitor extends Visitor { - - public ObServeVisitor(Predicate<TopiaMetadataEntity> acceptType) { - super(acceptType); - } - - @Override - protected boolean rejectReversedAssociationType(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { - return rejectReversedAssociationType0(metadataEntity, propertyType) || super.rejectReversedAssociationType(metadataEntity, propertyName, propertyType); - } - - @Override - protected boolean rejectAssociationType(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { - return rejectAssociationType0(metadataEntity, propertyType) || super.rejectAssociationType(metadataEntity, propertyName, propertyType); - } + private void executeSqlStatements0(TopiaSqlScript content) { + SqlScriptReader scriptLocation = content.getLocation(); + try (ObserveTopiaPersistenceContext persistenceContext = newPersistenceContext()) { + persistenceContext.executeSqlScript(scriptLocation); + persistenceContext.commit(); } } ===================================== persistence/src/main/models/Observe-21-data-ps-logbook.model ===================================== @@ -14,7 +14,7 @@ seaSurfaceTemperature + {*:1} Float | sqlType=numeric windDirection + {*:1} Integer vesselActivity {*:1} referential.ps.common.VesselActivity wind {*:0..1} referential.common.Wind -relatedObservedActivity + {0..1} data.ps.observation.Activity +relatedObservedActivity + {0..1} data.ps.observation.Activity | skipModelNavigation floatingObject + {*} data.ps.logbook.FloatingObject | unique observedSystem {*:*} referential.ps.logbook.ObservedSystem | unique set + {0..1} data.ps.logbook.Set @@ -91,7 +91,7 @@ bigsWeight + {*:1} Float | sqlType=numeric totalWeight + {*:1} Float | sqlType=numeric weightedWeight + {*:1} Float | sqlType=numeric subSampleNumber + {*:1} Integer -activity {*:*} data.ps.logbook.Activity +activity {*:*} data.ps.logbook.Activity | skipModelNavigation sampleSpecies + {*} data.ps.logbook.SampleSpecies | ordered data.ps.logbook.SampleSpecies > data.DataEntity | entity ===================================== persistence/src/main/models/Observe-23-data-ps-wellplan.model ===================================== @@ -1,7 +1,7 @@ package fr.ird.observe.entities.data.ps.wellplan | dbSchema=ps_wellplan data.ps.wellplan.WellPlan > data.DataEntity | entity -activity {*:1} data.ps.logbook.Activity +activity {*:1} data.ps.logbook.Activity | skipModelNavigation well + {*:1} String species {*:1} referential.common.Species weightCategory {*:1} referential.ps.logbook.WeightCategory ===================================== persistence/src/main/models/Observe-24-data-ps-localmarket.model ===================================== @@ -5,7 +5,7 @@ species {*:1} referential.common.Species | notNull packaging {*:1} referential.ps.localmarket.Packaging | notNull count + {*:1} Integer weight + {*:1} Float | sqlType=numeric -survey {*:0..1} data.ps.localmarket.Survey +survey {*:0..1} data.ps.localmarket.Survey | skipModelNavigation origin + {*:1} String | hibernateAttributeType=text comment + {*:1} String | hibernateAttributeType=text ===================================== persistence/src/main/models/Observe-30-data-ll-observation.model ===================================== @@ -44,9 +44,9 @@ haulingIdentifier + {*:1} Integer floatline1Length + {*:1} Float floatline2Length + {*:1} Float branchline + {*} data.ll.observation.Branchline | unique orderBy=settingIdentifier -catches {*} data.ll.observation.Catch -tdr {*} data.ll.observation.Tdr -set {*:1} data.ll.observation.Set +catches {*} data.ll.observation.Catch | skipModelNavigation +tdr {*} data.ll.observation.Tdr | skipModelNavigation +set {*:1} data.ll.observation.Set | skipModelNavigation getSection() data.ll.observation.Section setSection(section data.ll.observation.Section) @@ -68,8 +68,8 @@ tracelineLength + {*:1} Float | sqlType=numeric hookLost + {*:1} Boolean traceCutOff + {*:1} Boolean hookType {*:0..1} referential.ll.common.HookType -tdr {*} data.ll.observation.Tdr -catches {*} data.ll.observation.Catch +tdr {*} data.ll.observation.Tdr | skipModelNavigation +catches {*} data.ll.observation.Catch | skipModelNavigation baitType {*:0..1} referential.ll.common.BaitType topType {*:0..1} referential.ll.common.LineType tracelineType {*:0..1} referential.ll.common.LineType @@ -102,14 +102,14 @@ photoReferences + {*:1} String number + {*:1} Integer acquisitionMode + {*:1} int tagNumber + {*:1} String -basket {*:0..1} data.ll.observation.Basket -branchline {*:0..1} data.ll.observation.Branchline +basket {*:0..1} data.ll.observation.Basket | skipModelNavigation +branchline {*:0..1} data.ll.observation.Branchline | skipModelNavigation catchFate {*:1} referential.ll.common.CatchFate discardHealthStatus {*:1} referential.ll.common.HealthStatus sizeMeasure + {*} data.ll.observation.SizeMeasure | orderBy=topiaCreateDate speciesCatch {*:1} referential.common.Species predator {*:*} referential.common.Species -section {*:0..1} data.ll.observation.Section +section {*:0..1} data.ll.observation.Section | skipModelNavigation maturityStatus {*:0..1} referential.ll.observation.MaturityStatus stomachFullness {*:0..1} referential.ll.observation.StomachFullness hookPosition {*:0..1} referential.ll.observation.HookPosition @@ -138,10 +138,10 @@ hookSize {*:1} referential.ll.common.HookSize data.ll.observation.Section > data.DataEntity >> data.ll.observation.LonglineCompositionAware | entity settingIdentifier + {*:1} Integer | notNull haulingIdentifier + {*:1} Integer -set {*:1} data.ll.observation.Set -basket + {*} data.ll.observation.Basket | unique orderBy=settingIdentifier -tdr {*} data.ll.observation.Tdr -catches {*} data.ll.observation.Catch +set {*:1} data.ll.observation.Set | skipModelNavigation +basket + {*} data.ll.observation.Basket | unique orderBy=settingIdentifier +tdr {*} data.ll.observation.Tdr | skipModelNavigation +catches {*} data.ll.observation.Catch | skipModelNavigation data.ll.observation.SensorUsed > data.DataEntity | entity data + {*:1} !java.sql.Blob @@ -254,11 +254,11 @@ minFishingDepth + {*:1} Float maxFishingDepth + {*:1} Float meanFishingDepth + {*:1} Float medianFishingDepth + {*:1} Float -branchline {*:0..1} data.ll.observation.Branchline +branchline {*:0..1} data.ll.observation.Branchline | skipModelNavigation sensorBrand {*:0..1} referential.ll.observation.SensorBrand species {*:*} referential.common.Species -section {*:0..1} data.ll.observation.Section -basket {*:0..1} data.ll.observation.Basket +section {*:0..1} data.ll.observation.Section | skipModelNavigation +basket {*:0..1} data.ll.observation.Basket | skipModelNavigation itemHorizontalPosition {*:0..1} referential.ll.observation.ItemHorizontalPosition itemVerticalPosition {*:0..1} referential.ll.observation.ItemVerticalPosition getDeploymentStartDate() Date ===================================== persistence/src/main/models/Observe-31-data-ll-logbook.model ===================================== @@ -14,7 +14,7 @@ currentDirection + {*:1} Integer vesselActivity {*:1} referential.ll.common.VesselActivity | lazy=false dataQuality {*:0..1} referential.common.DataQuality fpaZone {*:1} referential.common.FpaZone -relatedObservedActivity + {0..1} data.ll.observation.Activity +relatedObservedActivity + {0..1} data.ll.observation.Activity | skipModelNavigation set + {0..1} data.ll.logbook.Set sample + {0..1} data.ll.logbook.Sample getStartDate() Date ===================================== persistence/src/test/java/fr/ird/observe/entities/ObserveTopiaMetadataModelSupportTest.java deleted ===================================== @@ -1,68 +0,0 @@ -package fr.ird.observe.entities; - -/*- - * #%L - * ObServe :: Persistence - * %% - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io - * %% - * 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 com.google.common.collect.ImmutableMap; -import fr.ird.observe.test.ObserveFixtures; -import org.junit.Assert; -import org.junit.Test; -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath; -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPathsBuilder; -import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; - -public class ObserveTopiaMetadataModelSupportTest { - - @Test - public void testEntityPathsBuilder() { - - TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel(); - - TopiaMetadataEntityPathsBuilder entityPathsBuilder = new ObserveTopiaApplicationContext.ObserveDataEntityPathsBuilder(); - - TopiaMetadataEntity tripPs = model.getEntity(ObserveEntityEnum.ps_common_Trip.name()); - ImmutableMap<TopiaMetadataEntity, TopiaMetadataEntityPath> pathsPs = entityPathsBuilder.build(model, tripPs); - Assert.assertNotNull(pathsPs); - Assert.assertEquals(ObserveFixtures.PERSISTENCE_PS_DATA_PATH, pathsPs.size()); - - TopiaMetadataEntity tripLl = model.getEntity(ObserveEntityEnum.ll_common_Trip.name()); - ImmutableMap<TopiaMetadataEntity, TopiaMetadataEntityPath> pathsLl = entityPathsBuilder.build(model, tripLl); - Assert.assertNotNull(pathsLl); - Assert.assertEquals(ObserveFixtures.PERSISTENCE_LL_DATA_PATH, pathsLl.size()); - } - - @Test - public void getDataEntityPaths() { - - TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel(); - ImmutableMap<TopiaMetadataEntity, TopiaMetadataEntityPath> dataEntityPaths = model.getDataEntityPaths(); - Assert.assertNotNull(dataEntityPaths); - Assert.assertEquals(ObserveFixtures.PERSISTENCE_DATA_PATH, dataEntityPaths.size()); - Assert.assertFalse(model.getDataEntityPath(fr.ird.observe.entities.data.ps.common.Trip.class).isPresent()); - Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ps.common.GearUseFeatures.class).isPresent()); - Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ps.common.GearUseFeaturesMeasurement.class).isPresent()); - Assert.assertFalse(model.getDataEntityPath(fr.ird.observe.entities.data.ll.common.Trip.class).isPresent()); - Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ll.common.GearUseFeatures.class).isPresent()); - Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ll.common.GearUseFeaturesMeasurement.class).isPresent()); - } -} ===================================== persistence/src/test/java/fr/ird/observe/entities/TopiaMetadataModelPathsTest.java ===================================== @@ -0,0 +1,101 @@ +package fr.ird.observe.entities; + +/*- + * #%L + * ObServe :: Persistence + * %% + * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io + * %% + * 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 com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; +import fr.ird.observe.test.ObserveFixtures; +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModelPaths; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * Created on 13/09/2020. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 8.1.0 + */ +public class TopiaMetadataModelPathsTest { + + + @Test + public void getEntityPaths() { + + TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel(); + TopiaMetadataModelPaths paths = TopiaMetadataModelPaths.load(model); + Multimap<TopiaMetadataEntity, TopiaMetadataEntityPath> dataEntityPaths = paths.getEntityPaths(); + Assert.assertNotNull(dataEntityPaths); + Assert.assertEquals(ObserveFixtures.PERSISTENCE_DATA_PATH, dataEntityPaths.asMap().size()); + Assert.assertFalse(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ps.common.Trip.class)).isPresent()); + Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ps.common.GearUseFeatures.class)).isPresent()); + Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ps.common.GearUseFeaturesMeasurement.class)).isPresent()); + Assert.assertFalse(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ll.common.Trip.class)).isPresent()); + Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ll.common.GearUseFeatures.class)).isPresent()); + Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ll.common.GearUseFeaturesMeasurement.class)).isPresent()); + } + + @Test + public void getEntityPathsCount() { + ImmutableMap<String, Long> excepted = ObserveFixtures.PERSISTENCE_ENTITY_PATHS; + TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel(); + + TopiaMetadataModelPaths paths = TopiaMetadataModelPaths.load(model); + Multimap<TopiaMetadataEntity, TopiaMetadataEntityPath> dataEntityPaths = paths.getEntityPaths(); + + Assert.assertNotNull(paths); + for (Map.Entry<TopiaMetadataEntity, Collection<TopiaMetadataEntityPath>> entry : paths.asMap().entrySet()) { + int actualPathsCount = entry.getValue().stream().map(TopiaMetadataEntityPath::getLinks).mapToInt(List::size).sum(); + System.out.printf("%s=%d%n", ObserveEntityEnum.valueOf(entry.getKey().getType()), actualPathsCount); + } + for (Map.Entry<String, Long> entry : excepted.entrySet()) { + String type = entry.getKey(); + Optional<TopiaMetadataEntity> optionalTopiaMetadataEntity = paths.keySet().stream().filter(k -> k.getType().equals(type)).findFirst(); + Assert.assertTrue("Could not find expected type in result: " + type, optionalTopiaMetadataEntity.isPresent()); + TopiaMetadataEntity topiaMetadataEntity = optionalTopiaMetadataEntity.get(); + Collection<TopiaMetadataEntityPath> topiaMetadataLinks = paths.get(topiaMetadataEntity); + int expectedPathsCount = Math.toIntExact(entry.getValue()); + int actualPathsCount = topiaMetadataLinks.stream().map(TopiaMetadataEntityPath::getLinks).mapToInt(List::size).sum(); + Assert.assertEquals(String.format("for type %s, expected links size: %d but was %d", type, expectedPathsCount, actualPathsCount), expectedPathsCount, actualPathsCount); + } + ImmutableSet<String> keys = excepted.keySet(); + for (Map.Entry<TopiaMetadataEntity, Collection<TopiaMetadataEntityPath>> entry : paths.asMap().entrySet()) { + if (!keys.contains(entry.getKey().getType())) { + + int actualPathsCount = entry.getValue().stream().map(TopiaMetadataEntityPath::getLinks).mapToInt(List::size).sum(); + System.err.printf("%s=%d%n", ObserveEntityEnum.valueOf(entry.getKey().getType()), actualPathsCount); + } + } + Assert.assertEquals(excepted.size(), paths.asMap().size()); + // at the moment only two entities with two paths (ll_logbook_Sample and ll_logbook_SamplePart) + Assert.assertEquals(excepted.size() + 2, paths.size()); + } +} ===================================== pom.xml ===================================== @@ -174,7 +174,7 @@ <lib.version.h2>1.4.196</lib.version.h2> <lib.version.nuiton.utils>3.0</lib.version.nuiton.utils> -<!-- <lib.version.java4all.topia>1.26-SNAPSHOT</lib.version.java4all.topia>--> + <lib.version.java4all.topia>1.27-SNAPSHOT</lib.version.java4all.topia> <!-- <lib.version.java4all.eugene>3.0-alpha-34-SNAPSHOT</lib.version.java4all.eugene>--> <!-- <lib.version.java4all.jaxx>3.0-alpha-79-SNAPSHOT</lib.version.java4all.jaxx>--> <!--<lib.version.java4all.application-context>1.0.3-SNAPSHOT</lib.version.java4all.application-context>--> ===================================== server-core/src/main/filtered-resources/mapping ===================================== @@ -192,6 +192,7 @@ POST /api/v1/data/ps/common/TripGearUseFeaturesService/save DELETE /api/v1/data/ps/common/TripService/delete v1.data.ps.common.TripServiceRestApi.delete GET /api/v1/data/ps/common/TripService/exists v1.data.ps.common.TripServiceRestApi.exists GET /api/v1/data/ps/common/TripService/getAllTrip v1.data.ps.common.TripServiceRestApi.getAllTrip +GET /api/v1/data/ps/common/TripService/getLogbookWeightCategoryByListAndTrip v1.data.ps.common.TripServiceRestApi.getLogbookWeightCategoryByListAndTrip GET /api/v1/data/ps/common/TripService/getMatchingTripsVesselWithinDateRange v1.data.ps.common.TripServiceRestApi.getMatchingTripsVesselWithinDateRange GET /api/v1/data/ps/common/TripService/getSpeciesByListAndTrip v1.data.ps.common.TripServiceRestApi.getSpeciesByListAndTrip GET /api/v1/data/ps/common/TripService/getTripMap v1.data.ps.common.TripServiceRestApi.getTripMap ===================================== services-api/src/main/java/fr/ird/observe/services/service/data/ps/common/TripService.java ===================================== @@ -24,10 +24,19 @@ package fr.ird.observe.services.service.data.ps.common; import fr.ird.observe.dto.data.ps.common.TripDto; import fr.ird.observe.dto.data.ps.common.TripReference; +import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet; +import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference; +import fr.ird.observe.services.spi.ReadDataPermission; +import io.ultreia.java4all.http.spi.Get; +import io.ultreia.java4all.http.spi.Nullable; /** * @author Tony Chemit - dev@tchemit.fr */ public interface TripService extends fr.ird.observe.services.service.data.TripService<TripDto, TripReference> { + @Get + @ReadDataPermission + ReferentialDtoReferenceSet<WeightCategoryReference> getLogbookWeightCategoryByListAndTrip(@Nullable String tripId, String speciesListId); + } ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/data/ps/common/TripServiceLocal.java ===================================== @@ -23,6 +23,7 @@ package fr.ird.observe.services.local.service.data.ps.common; */ import com.google.common.collect.ImmutableSet; +import fr.ird.observe.dto.IdDto; import fr.ird.observe.dto.data.TripAware; import fr.ird.observe.dto.data.TripMapConfigDto; import fr.ird.observe.dto.data.TripMapDto; @@ -33,10 +34,13 @@ import fr.ird.observe.dto.form.Form; import fr.ird.observe.dto.reference.DataDtoReferenceSet; import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet; import fr.ird.observe.dto.referential.common.SpeciesReference; +import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference; import fr.ird.observe.dto.result.SaveResultDto; import fr.ird.observe.entities.data.ps.common.Trip; import fr.ird.observe.entities.referential.common.Ocean; import fr.ird.observe.entities.referential.common.Program; +import fr.ird.observe.entities.referential.ps.logbook.WeightCategory; +import fr.ird.observe.entities.referential.ps.logbook.WeightCategoryTopiaDao; import fr.ird.observe.services.local.ObserveServiceContextLocal; import fr.ird.observe.services.local.service.ObserveServiceLocal; import fr.ird.observe.services.service.data.ps.common.TripService; @@ -50,6 +54,7 @@ import java.util.Comparator; import java.util.Date; import java.util.LinkedHashSet; import java.util.List; +import java.util.stream.Collectors; /** * @author Tony Chemit - dev@tchemit.fr @@ -121,6 +126,18 @@ public class TripServiceLocal extends ObserveServiceLocal implements TripService return getSpeciesByListAndOcean(speciesListId, ocean); } + @Override + public ReferentialDtoReferenceSet<WeightCategoryReference> getLogbookWeightCategoryByListAndTrip(String tripId, String speciesListId) { + Ocean ocean = null; + if (tripId != null) { + Trip trip = Trip.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), tripId); + ocean = trip.getOcean(); + } + List<String> speciesByListAndOcean = getSpeciesByListAndOcean(speciesListId, ocean).stream().map(IdDto::getId).collect(Collectors.toList()); + WeightCategoryTopiaDao weightCategoryList = WeightCategory.getDao(getTopiaPersistenceContext()); + return WeightCategory.toReferenceSet(getReferentialLocale(), weightCategoryList.streamAll().filter(c -> c.getSpecies() == null || speciesByListAndOcean.contains(c.getSpecies().getTopiaId())), now()); + } + @Override public Form<TripDto> preCreate(String programId) { Trip trip = Trip.newEntity(now()); ===================================== services-local/src/test/java/fr/ird/observe/services/local/service/data/TripManagementServiceLocalTest.java ===================================== @@ -96,7 +96,7 @@ public class TripManagementServiceLocalTest extends ServiceLocalTestSupport { Assert.assertNotNull(result); DataDtoReferenceSet<TripReference> allTripSeineAfter = tripService.getAllTrip(); - Assert.assertTrue(allTripSeineBefore.size() == allTripSeineAfter.size() + 1); + Assert.assertEquals(allTripSeineBefore.size(), allTripSeineAfter.size() + 1); } @Test ===================================== templates/pom.xml ===================================== @@ -63,7 +63,10 @@ <groupId>org.nuiton</groupId> <artifactId>nuiton-decorator</artifactId> </dependency> - + <dependency> + <groupId>io.ultreia.java4all.topia</groupId> + <artifactId>persistence</artifactId> + </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> ===================================== templates/src/main/java/fr/ird/observe/toolkit/templates/GeneratePersistence.java ===================================== @@ -22,6 +22,9 @@ package fr.ird.observe.toolkit.templates; * #L% */ +import fr.ird.observe.toolkit.templates.entity.EntityLastUpdateDateFieldSqlScriptGenerator; +import fr.ird.observe.toolkit.templates.entity.EntityLastUpdateDateTableSqlScriptGenerator; +import fr.ird.observe.toolkit.templates.entity.EntityPathsGenerator; import fr.ird.observe.toolkit.templates.entity.EntityTransformer; import org.codehaus.plexus.component.annotations.Component; import org.nuiton.eugene.Template; @@ -31,6 +34,7 @@ import org.nuiton.topia.templates.EntityHibernateMappingTransformer; import org.nuiton.topia.templates.TopiaEntityDaoTransformer; import org.nuiton.topia.templates.TopiaEntityEnumTransformer; import org.nuiton.topia.templates.TopiaGenerator; +import org.nuiton.topia.templates.TopiaMetadataModelClassGenerator; import org.nuiton.topia.templates.TopiaMetadataModelGenerator; import org.nuiton.topia.templates.TopiaPersistenceContextTransformer; @@ -55,6 +59,10 @@ public class GeneratePersistence extends TopiaGenerator { ApplicationContextTransformer.class, TopiaPersistenceContextTransformer.class, TopiaEntityDaoTransformer.class, + EntityPathsGenerator.class, + EntityLastUpdateDateFieldSqlScriptGenerator.class, + EntityLastUpdateDateTableSqlScriptGenerator.class, + TopiaMetadataModelClassGenerator.class, TopiaMetadataModelGenerator.class ); } ===================================== templates/src/main/java/fr/ird/observe/toolkit/templates/dto/DtoTransformer.java ===================================== @@ -62,6 +62,7 @@ import org.nuiton.eugene.models.object.xml.ObjectModelParameterImpl; import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; @@ -317,7 +318,7 @@ public class DtoTransformer extends BeanTransformer implements TemplateContract private Map<String, String> getFormProperties(ObjectModelClass input, ObjectModelClass output) { Collection<ObjectModelAttribute> attributes = new LinkedList<>(input.getAttributes()); attributes.addAll(input.getAllOtherAttributes()); - Map<String, String> properties = new TreeMap<>(); + Map<String, String> properties = new LinkedHashMap<>(); for (ObjectModelAttribute attr : attributes) { if (!attr.isNavigable()) { ===================================== toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateEntityUpdateSqlFilesMojo.java → templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityLastUpdateDateFieldSqlScriptGenerator.java ===================================== @@ -1,8 +1,8 @@ -package fr.ird.observe.maven.plugins.toolbox; +package fr.ird.observe.toolkit.templates.entity; /*- * #%L - * ObServe Toolkit :: Maven plugin + * ObServe Toolkit :: Templates * %% * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io * %% @@ -22,129 +22,73 @@ package fr.ird.observe.maven.plugins.toolbox; * #L% */ - import com.google.common.collect.ImmutableList; import fr.ird.observe.spi.context.DtoEntityContext; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.nuiton.topia.persistence.internal.support.TopiaMetadataModelSupportImpl; +import org.codehaus.plexus.component.annotations.Component; +import org.nuiton.eugene.Template; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelClassifier; import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath; import org.nuiton.topia.persistence.metadata.TopiaMetadataLink; -import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; import org.nuiton.topia.persistence.metadata.TopiaMetadataReverseAssociation; -import org.nuiton.topia.persistence.script.SqlScriptWriter; +import org.nuiton.topia.templates.TopiaMetadataModelGeneratorSupport; -import java.io.File; import java.io.IOException; -import java.net.URLClassLoader; -import java.nio.file.Path; +import java.io.Writer; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Optional; -@Mojo(name = "generate-entity-update-sql-files", threadSafe = true, defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE) -public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport { - private static final String UPDATE_LAST_UPDATE_DATE_TABLE_SQL = "UPDATE common.lastUpdateDate SET lastUpdateDate = '%%1$s'::timestamp WHERE type ='%s'"; +/** + * Created on 13/09/2020. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 1.27 + */ +@Component(role = Template.class, hint = "org.nuiton.topia.templates.EntityLastUpdateDateFieldSqlScriptGenerator") +public class EntityLastUpdateDateFieldSqlScriptGenerator extends TopiaMetadataModelGeneratorSupport { + private static final String UPDATE_LAST_UPDATE_DATE_FIELD_SQL_START = "UPDATE %s.%s SET lastUpdateDate = '%%1$s'::timestamp, topiaVersion = topiaVersion + 1"; private static final String UPDATE_LAST_UPDATE_DATE_FIELD_SQL_WHERE_EQUALS = " WHERE %s = '%%2$s'"; private static final String UPDATE_LAST_UPDATE_DATE_FIELD_SQL_WHERE_SELECT = " WHERE topiaId = ( %s )"; private static final String UPDATE_LAST_UPDATE_DATA_FIELD_SQL_SELECT_START = "SELECT %3$s FROM %1$s.%2$s %2$s"; private static final String UPDATE_LAST_UPDATE_DATA_FIELD_SQL_INNER_JOIN_REVERSE = " INNER JOIN %1$s.%2$s %2$s ON %2$s.%3$s = %4$s.%5$s"; private static final String UPDATE_LAST_UPDATE_DATA_FIELD_SQL_INNER_JOIN_SIMPLE = " INNER JOIN %1$s.%2$s %2$s ON %2$s.%3$s = %4$s.topiaId"; - /** - * Verbose flag. - */ - @Parameter(property = "generateEntityUpdateSqlFiles.verbose", defaultValue = "${maven.verbose}") - private boolean verbose; - /** - * Skip flag. - */ - @Parameter(property = "generateEntityUpdateSqlFiles.skip", defaultValue = "false") - private boolean skip; - - /** - * Where to generate files. - */ - @Parameter(property = "generateEntityUpdateSqlFiles.outputDirectory", defaultValue = "${project.build.directory}/classes/", required = true) - private File outputDirectory; - - @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - protected Path createOutputFile() { - return null; - } @Override - public boolean isSkip() { - return skip; + public String getFilenameForClassifier(ObjectModelClassifier classifier) { + return super.getFilenameForClassifier(classifier) + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_FIELD_CLASSIFIER; } @Override - protected void doAction() throws Exception { - URLClassLoader urlClassLoader = initClassLoader(getProject(), outputDirectory, true, false, true, true, true); - - Thread thread = Thread.currentThread(); - ClassLoader contextClassLoader = thread.getContextClassLoader(); - thread.setContextClassLoader(urlClassLoader); - try { - TopiaMetadataModelSupportImpl model = (TopiaMetadataModelSupportImpl) urlClassLoader.loadClass("fr.ird.observe.entities.ObserveTopiaMetadataModelSupport").newInstance(); - TopiaMetadataModel metadataModel = model.getMetadataModel(); - Iterator<TopiaMetadataEntity> iterator = metadataModel.streamWithoutAbstract().iterator(); - while (iterator.hasNext()) { - TopiaMetadataEntity topiaMetadataEntity = iterator.next(); - processEntity(metadataModel, topiaMetadataEntity); - } - } finally { - thread.setContextClassLoader(contextClassLoader); + public void generateFromClass(Writer output, ObjectModelClass input) throws IOException { + TopiaMetadataEntity entity = getEntityEnumName(input); + if (entity != null && !entity.isAbstract()) { + processEntity(entity, output); } } - protected void processEntity(TopiaMetadataModel metadataModel, TopiaMetadataEntity topiaMetadataEntity) throws IOException { - - String fullyQualifiedName = topiaMetadataEntity.getFullyQualifiedName(); - Path directory = outputDirectory.toPath(); - String[] parts = fullyQualifiedName.split("\\."); - String simpleName = parts[parts.length - 1]; - for (int i = 0; i < parts.length - 1; i++) { - directory = directory.resolve(parts[i]); - } - createDirectoryIfNecessary(directory.toFile()); + protected void processEntity(TopiaMetadataEntity entity, Writer output) throws IOException { ImmutableList<TopiaMetadataEntity> types; ImmutableList<TopiaMetadataLink> links; - Optional<TopiaMetadataEntityPath> optionalDataEntityPath = metadataModel.getDataEntityPath(topiaMetadataEntity); - if (optionalDataEntityPath.isPresent()) { - TopiaMetadataEntityPath dataEntityPath = optionalDataEntityPath.get(); - links = dataEntityPath.getLinks(); - types = TopiaMetadataEntityPath.getTypes(dataEntityPath); + Optional<TopiaMetadataEntityPath> optionalPath = getAllPaths(EntityLastUpdateDateTableSqlScriptGenerator::rejectType).getEntityPathsForEntryPoint(entity); + if (optionalPath.isPresent()) { + TopiaMetadataEntityPath path = optionalPath.get(); + links = path.getLinks(); + types = path.getTypes(); } else { // limit case, only one type - types = ImmutableList.of(topiaMetadataEntity); + types = ImmutableList.of(entity); // and no link links = ImmutableList.of(); } - { - ImmutableList<String> requests = generateLastUpdateDateFieldRequests(types, links); - generate(directory.resolve(simpleName + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_FIELD_CLASSIFIER), requests); - } - { - ImmutableList<String> requests = generateLastUpdateDateTableRequests(types); - generate(directory.resolve(simpleName + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_TABLE_CLASSIFIER), requests); - } + ImmutableList<String> requests = generateLastUpdateDateFieldRequests(types, links); + generate(output, requests); + } private ImmutableList<String> generateLastUpdateDateFieldRequests(ImmutableList<TopiaMetadataEntity> types, ImmutableList<TopiaMetadataLink> links) { @@ -170,15 +114,6 @@ public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport { return builder.build(); } - private ImmutableList<String> generateLastUpdateDateTableRequests(ImmutableList<TopiaMetadataEntity> types) { - ImmutableList.Builder<String> builder = ImmutableList.builder(); - for (TopiaMetadataEntity type : types.reverse()) { - String tableSql = String.format(UPDATE_LAST_UPDATE_DATE_TABLE_SQL, type.getFullyQualifiedName()); - builder.add(tableSql + ";"); - } - return builder.build(); - } - private String generateLastUpdateDateFieldRequest(TopiaMetadataEntity type, List<TopiaMetadataLink> inProcess) { String sql = String.format(UPDATE_LAST_UPDATE_DATE_FIELD_SQL_START, type.getDbSchemaName(), type.getDbTableName()); if (inProcess == null) { @@ -223,7 +158,7 @@ public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport { tableOwner = firstLink.getTarget(); selectColumn = firstLink.getTarget().getDbColumnName(firstLink.getOwner().getDbTableName()); } - return String.format(UPDATE_LAST_UPDATE_DATA_FIELD_SQL_SELECT_START, tableOwner.getDbSchemaName(), tableOwner.getDbTableName(), tableOwner.getDbTableName() +"."+ selectColumn); + return String.format(UPDATE_LAST_UPDATE_DATA_FIELD_SQL_SELECT_START, tableOwner.getDbSchemaName(), tableOwner.getDbTableName(), tableOwner.getDbTableName() + "." + selectColumn); } private String appendInnerJoin(TopiaMetadataLink lastLink, TopiaMetadataLink nextLink) { @@ -246,10 +181,4 @@ public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport { return finalizeRequest(targetColumn); } - private void generate(Path file, ImmutableList<String> requests) throws IOException { - getLog().debug(String.format("Will write %d requests in file: %s", requests.size(), file)); - try (SqlScriptWriter sqlScriptWriter = SqlScriptWriter.of(file)) { - requests.forEach(sqlScriptWriter::writeSql); - } - } } ===================================== templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityLastUpdateDateTableSqlScriptGenerator.java ===================================== @@ -0,0 +1,93 @@ +package fr.ird.observe.toolkit.templates.entity; + +/*- + * #%L + * ObServe Toolkit :: Templates + * %% + * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io + * %% + * 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 com.google.common.collect.ImmutableList; +import fr.ird.observe.spi.context.DtoEntityContext; +import org.codehaus.plexus.component.annotations.Component; +import org.nuiton.eugene.Template; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelClassifier; +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath; +import org.nuiton.topia.templates.TopiaMetadataModelGeneratorSupport; + +import java.io.IOException; +import java.io.Writer; +import java.util.Optional; + +/** + * Created on 13/09/2020. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 1.27 + */ +@Component(role = Template.class, hint = "org.nuiton.topia.templates.EntityLastUpdateDateTableSqlScriptGenerator") +public class EntityLastUpdateDateTableSqlScriptGenerator extends TopiaMetadataModelGeneratorSupport { + + private static final String UPDATE_LAST_UPDATE_DATE_TABLE_SQL = "UPDATE common.lastUpdateDate SET lastUpdateDate = '%%1$s'::timestamp WHERE type ='%s'"; + + protected static boolean rejectType(TopiaMetadataEntity entity) { + return entity.isAbstract() || entity.getFullyQualifiedName().contains(".referential"); + } + + @Override + public String getFilenameForClassifier(ObjectModelClassifier classifier) { + return super.getFilenameForClassifier(classifier) + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_TABLE_CLASSIFIER; + } + + @Override + public void generateFromClass(Writer output, ObjectModelClass input) throws IOException { + TopiaMetadataEntity entity = getEntityEnumName(input); + if (entity != null && !entity.isAbstract()) { + processEntity(entity, output); + } + } + + protected void processEntity(TopiaMetadataEntity entity, Writer output) throws IOException { + + ImmutableList<TopiaMetadataEntity> types; + Optional<TopiaMetadataEntityPath> optionalPath = getAllPaths(EntityLastUpdateDateTableSqlScriptGenerator::rejectType).getEntityPathsForEntryPoint(entity); + if (optionalPath.isPresent()) { + TopiaMetadataEntityPath path = optionalPath.get(); + types = path.getTypes(); + } else { + // limit case, only one type + types = ImmutableList.of(entity); + // and no link + } + ImmutableList<String> requests = generateLastUpdateDateTableRequests(types); + generate(output, requests); + + } + + private ImmutableList<String> generateLastUpdateDateTableRequests(ImmutableList<TopiaMetadataEntity> types) { + ImmutableList.Builder<String> builder = ImmutableList.builder(); + for (TopiaMetadataEntity type : types.reverse()) { + String tableSql = String.format(UPDATE_LAST_UPDATE_DATE_TABLE_SQL, type.getFullyQualifiedName()); + builder.add(tableSql + ";"); + } + return builder.build(); + } + +} ===================================== persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaMetadataModelSupport.java → templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityPathsGenerator.java ===================================== @@ -1,8 +1,8 @@ -package fr.ird.observe.entities; +package fr.ird.observe.toolkit.templates.entity; /*- * #%L - * ObServe :: Persistence + * ObServe Toolkit :: Templates * %% * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io * %% @@ -22,10 +22,23 @@ package fr.ird.observe.entities; * #L% */ -import org.nuiton.topia.persistence.internal.support.TopiaMetadataModelSupportImpl; +import org.codehaus.plexus.component.annotations.Component; +import org.nuiton.eugene.Template; +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; +import org.nuiton.topia.templates.TopiaMetadataEntityPathsGeneratorSupport; -public class ObserveTopiaMetadataModelSupport extends TopiaMetadataModelSupportImpl { - public ObserveTopiaMetadataModelSupport() { - super("fr.ird.observe.entities", "Observe", new ObserveTopiaApplicationContext.ObserveDataEntityPathsBuilder()); +/** + * Created on 13/09/2020. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 8.1.0 + */ +@Component(role = Template.class, hint = "org.nuiton.topia.templates.EntityPathsGenerator") +public class EntityPathsGenerator extends TopiaMetadataEntityPathsGeneratorSupport { + + @Override + protected boolean rejectType(TopiaMetadataEntity entity) { + return EntityLastUpdateDateTableSqlScriptGenerator.rejectType(entity); } + } ===================================== test/src/main/java/fr/ird/observe/test/ObserveFixtures.java ===================================== @@ -78,10 +78,10 @@ public class ObserveFixtures { public static final ImmutableMap<String, Long> TRIP_LONGLINE_1_TABLES_COUNT = loadFixturesMapCount("count-data-longline-1"); public static final ImmutableMap<String, Long> TRIP_LONGLINE_2_TABLES_COUNT = loadFixturesMapCount("count-data-longline-2"); public static final ImmutableMap<String, Long> TRIP_LONGLINE_3_TABLES_COUNT = loadFixturesMapCount("count-data-longline-3"); + public static final ImmutableMap<String, Long> PERSISTENCE_ENTITY_PATHS = loadFixturesMapCount("entity-paths"); + private static final ImmutableMap<String, String> GLOBAL = loadFixturesMap("global"); - public static final int PERSISTENCE_PS_DATA_PATH = Integer.parseInt(GLOBAL.get("PERSISTENCE_PS_DATA_PATH")); - public static final int PERSISTENCE_LL_DATA_PATH = Integer.parseInt(GLOBAL.get("PERSISTENCE_LL_DATA_PATH")); - public static final int PERSISTENCE_DATA_PATH = PERSISTENCE_PS_DATA_PATH+PERSISTENCE_LL_DATA_PATH; + public static final int PERSISTENCE_DATA_PATH = PERSISTENCE_ENTITY_PATHS.size(); public static final String TRIP_SEINE_ID_1 = GLOBAL.get("TRIP_SEINE_ID_1"); public static final String TRIP_SEINE_ID_2 = GLOBAL.get("TRIP_SEINE_ID_2"); public static final String TRIP_SEINE_ID_3 = GLOBAL.get("TRIP_SEINE_ID_3"); ===================================== test/src/main/resources/fixtures/entity-paths.properties ===================================== @@ -0,0 +1,81 @@ +### +# #%L +# ObServe :: Test +# %% +# Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io +# %% +# 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% +### +ll_observation_Activity=1 +ll_observation_Set=2 +ll_observation_Encounter=2 +ll_observation_SensorUsed=2 +ll_observation_BaitsComposition=3 +ll_observation_FloatlinesComposition=3 +ll_observation_BranchlinesComposition=3 +ll_observation_HooksComposition=3 +ll_observation_Catch=3 +ll_observation_Section=3 +ll_observation_Tdr=3 +ll_observation_Basket=4 +ll_observation_SizeMeasure=4 +ll_observation_WeightMeasure=4 +ll_observation_Branchline=5 +ll_logbook_Activity=1 +ll_logbook_Set=2 +ll_logbook_BaitsComposition=3 +ll_logbook_FloatlinesComposition=3 +ll_logbook_HooksComposition=3 +ll_logbook_Catch=3 +ll_logbook_BranchlinesComposition=3 +ll_common_GearUseFeatures=1 +ll_common_GearUseFeaturesMeasurement=2 +ll_landing_Landing=1 +ll_landing_LandingPart=2 +ll_logbook_Sample=3 +ll_logbook_SamplePart=5 +ps_observation_Route=1 +ps_observation_Activity=2 +ps_observation_FloatingObject=3 +ps_observation_Set=3 +ps_observation_Catch=4 +ps_observation_Sample=4 +ps_observation_SchoolEstimate=4 +ps_observation_NonTargetCatchRelease=4 +ps_observation_ObjectSchoolEstimate=4 +ps_observation_ObjectObservedSpecies=4 +ps_observation_TransmittingBuoy=4 +ps_observation_FloatingObjectPart=4 +ps_observation_Size=5 +ps_logbook_Route=1 +ps_logbook_Activity=2 +ps_logbook_FloatingObject=3 +ps_logbook_Set=3 +ps_logbook_Catch=4 +ps_logbook_TransmittingBuoy=4 +ps_logbook_FloatingObjectPart=4 +ps_landing_Landing=1 +ps_wellplan_WellPlan=1 +ps_logbook_Sample=1 +ps_logbook_SampleSpecies=2 +ps_logbook_SampleSpeciesSize=3 +ps_localmarket_Batch=1 +ps_localmarket_Survey=1 +ps_localmarket_Sample=1 +ps_localmarket_SurveyPart=2 +ps_localmarket_SamplePart=2 +ps_common_GearUseFeatures=1 +ps_common_GearUseFeaturesMeasurement=2 ===================================== test/src/main/resources/fixtures/global.properties ===================================== @@ -56,7 +56,4 @@ VALIDATOR_CREATE_REFERENTIAL_COUNT_REAL=87 VALIDATOR_UPDATE_REFERENTIAL_COUNT_REAL=87 VALIDATOR_UPDATE_ENTITY_DATA_COUNT=40 -ENTITIES_LIMIT_SIZE=100 -# for fr.ird.observe.entities.ObserveTopiaMetadataModelSupportTest -PERSISTENCE_PS_DATA_PATH=32 -PERSISTENCE_LL_DATA_PATH=28 \ No newline at end of file +ENTITIES_LIMIT_SIZE=100 \ No newline at end of file ===================================== toolbox-maven-plugin/pom.xml ===================================== @@ -86,10 +86,6 @@ <groupId>io.ultreia.java4all</groupId> <artifactId>application-context</artifactId> </dependency> - <dependency> - <groupId>io.ultreia.java4all.topia</groupId> - <artifactId>persistence</artifactId> - </dependency> <dependency> <groupId>com.google.auto.service</groupId> <artifactId>auto-service-annotations</artifactId> View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/afaf0e4f6cb60cc6d0a3de851... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/afaf0e4f6cb60cc6d0a3de851... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT