Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3 Commits: dc65837f by Tony CHEMIT at 2018-02-22T15:32:40+01:00 improve test config - - - - - 16b45393 by Tony CHEMIT at 2018-02-22T21:49:04+01:00 [N0.3] Rendre la conversion des catégories de poids AVDTH->T3 générique (Mise en place de la persistence) (See #244) - - - - - 16 changed files: - pom.xml - t3-domain/pom.xml - t3-domain/src/main/java/fr/ird/t3/entities/conversion/AbstractWeightCategoryLogBookConvertor.java - t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertor.java - t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OABI.java - t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OIBI.java - t3-domain/src/main/java/fr/ird/t3/entities/reference/LengthWeightConversionImpl.java - + t3-domain/src/main/java/fr/ird/t3/entities/reference/WeightCategoryLogBookConversionImpl.java - + t3-domain/src/main/java/fr/ird/t3/entities/reference/WeightCategoryLogBookConversionSpeciesImpl.java - t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java - + t3-domain/src/main/resources/db/migration/V2_1_10_add-WeightCategoryLogBookConversion-table.sql - + t3-domain/src/main/resources/db/migration/V2_1_11_fill-WeightCategoryLogBookConversion-table.sql - t3-domain/src/main/resources/t3-datadb.properties - t3-domain/src/main/xmi/t3-persistence.properties - t3-domain/src/main/xmi/t3-persistence.zargo - t3-domain/src/test/java/fr/ird/t3/services/migration/T3MigrationTest.java Changes: ===================================== pom.xml ===================================== --- a/pom.xml +++ b/pom.xml @@ -431,6 +431,10 @@ <file> <exists>.mvn/load-test-data</exists> </file> + <property> + <name>skipTests</name> + <value>!true</value> + </property> </activation> <build> ===================================== t3-domain/pom.xml ===================================== --- a/t3-domain/pom.xml +++ b/t3-domain/pom.xml @@ -107,6 +107,10 @@ <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> <dependency> <groupId>com.google.auto.service</groupId> ===================================== t3-domain/src/main/java/fr/ird/t3/entities/conversion/AbstractWeightCategoryLogBookConvertor.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/entities/conversion/AbstractWeightCategoryLogBookConvertor.java +++ b/t3-domain/src/main/java/fr/ird/t3/entities/conversion/AbstractWeightCategoryLogBookConvertor.java @@ -20,14 +20,16 @@ */ package fr.ird.t3.entities.conversion; -import com.google.common.collect.Maps; import fr.ird.t3.entities.data.ElementaryCatch; import fr.ird.t3.entities.reference.Ocean; import fr.ird.t3.entities.reference.SchoolType; import fr.ird.t3.entities.reference.WeightCategoryTreatment; +import org.apache.commons.collections.CollectionUtils; + import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; -import org.apache.commons.collections.CollectionUtils; /** * Abstract log book convertor. @@ -122,8 +124,7 @@ public abstract class AbstractWeightCategoryLogBookConvertor implements WeightCa if (CollectionUtils.isNotEmpty(catches)) { for (ElementaryCatch aCatch : catches) { - Integer weightCategoryCode = - aCatch.getWeightCategoryLogBook().getCode(); + Integer weightCategoryCode = aCatch.getWeightCategoryLogBook().getCode(); Float ratio = distribution.get(weightCategoryCode); if (ratio != null) { result += ratio * aCatch.getCatchWeightRf2(); @@ -141,6 +142,7 @@ public abstract class AbstractWeightCategoryLogBookConvertor implements WeightCa * * @return the distributions */ + @Override public Map<WeightCategoryTreatment, Map<Integer, Float>> getDistributions() { if (distributions == null) { distributions = buildDistributions(); @@ -149,6 +151,20 @@ public abstract class AbstractWeightCategoryLogBookConvertor implements WeightCa } @Override + public Map<String, Map<Integer, Float>> getDistributionsByIds() { + Map<String, Map<Integer, Float>> distributionsToSave = new LinkedHashMap<>(); + for (Map.Entry<WeightCategoryTreatment, Map<Integer, Float>> e : getDistributions().entrySet()) { + distributionsToSave.put(e.getKey().getTopiaId(), e.getValue()); + } + return distributionsToSave; + } + + @Override + public Map<Integer, Float> getDistributions(WeightCategoryTreatment treatment) { + return getDistributions().get(treatment); + } + + @Override public final WeightCategoryTreatment getMinus10Category() { return minus10Category; } @@ -165,12 +181,11 @@ public abstract class AbstractWeightCategoryLogBookConvertor implements WeightCa Map<WeightCategoryTreatment, Map<Integer, Float>> distributions, float unknownWeight) { - Map<WeightCategoryTreatment, Float> unknownResult = Maps.newHashMap(); + Map<WeightCategoryTreatment, Float> unknownResult = new HashMap<>(); float totalWeight = 0f; - for (Map.Entry<WeightCategoryTreatment, Map<Integer, Float>> e : - distributions.entrySet()) { + for (Map.Entry<WeightCategoryTreatment, Map<Integer, Float>> e : distributions.entrySet()) { WeightCategoryTreatment category = e.getKey(); @@ -193,7 +208,7 @@ public abstract class AbstractWeightCategoryLogBookConvertor implements WeightCa } else { // there is some unknown weight to redistribute - result = Maps.newHashMap(); + result = new HashMap<>(); if (totalWeight == 0) { @@ -224,9 +239,9 @@ public abstract class AbstractWeightCategoryLogBookConvertor implements WeightCa protected final Map<WeightCategoryTreatment, Float> defaultDistributeForSpecie2( float totalWeight) { - Map<WeightCategoryTreatment, Float> result = Maps.newHashMap(); + Map<WeightCategoryTreatment, Float> result = new HashMap<>(); - // for species SKJ (code 2) : all goes to -10 kg categorie + // for species SKJ (code 2) : all goes to -10 kg category result.put(getMinus10Category(), totalWeight); return result; } @@ -234,9 +249,9 @@ public abstract class AbstractWeightCategoryLogBookConvertor implements WeightCa protected final Map<WeightCategoryTreatment, Float> defaultDistributeForOtherSpecie( float unknownWeight) { - Map<WeightCategoryTreatment, Float> result = Maps.newHashMap(); + Map<WeightCategoryTreatment, Float> result = new HashMap<>(); - // only keep unknown categorie weight + // only keep unknown category weight result.put(getUnkownCategory(), unknownWeight); return result; } ===================================== t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertor.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertor.java +++ b/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertor.java @@ -25,6 +25,7 @@ import fr.ird.t3.entities.reference.Ocean; import fr.ird.t3.entities.reference.SchoolType; import fr.ird.t3.entities.reference.Species; import fr.ird.t3.entities.reference.WeightCategoryTreatment; + import java.util.Collection; import java.util.Map; @@ -39,8 +40,13 @@ public interface WeightCategoryLogBookConvertor { boolean accept(Ocean ocean, SchoolType schoolType); - Map<WeightCategoryTreatment, Float> distribute(Species species, - Collection<ElementaryCatch> catches); + Map<WeightCategoryTreatment, Float> distribute(Species species, Collection<ElementaryCatch> catches); + + Map<String, Map<Integer, Float>> getDistributionsByIds() ; + + Map<WeightCategoryTreatment, Map<Integer, Float>> getDistributions(); + + Map<Integer, Float> getDistributions(WeightCategoryTreatment treatment); WeightCategoryTreatment getMinus10Category(); ===================================== t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OABI.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OABI.java +++ b/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OABI.java @@ -20,12 +20,14 @@ */ package fr.ird.t3.entities.conversion; -import com.google.common.collect.Maps; import fr.ird.t3.entities.data.ElementaryCatch; import fr.ird.t3.entities.reference.Species; import fr.ird.t3.entities.reference.WeightCategoryTreatment; + import java.util.Collection; +import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; /** * To convert weight categories for Atlantic ocean and undetermined school type. @@ -45,19 +47,16 @@ public class WeightCategoryLogBookConvertorFOR_OABI extends AbstractWeightCatego WeightCategoryTreatment plus10Category, WeightCategoryTreatment plus30Category) { - super(WeightCategoryLogBookConvertorProvider.OA, - WeightCategoryLogBookConvertorProvider.BI, - minus10Category, unknownCategory); + super(WeightCategoryLogBookConvertorProvider.OA, WeightCategoryLogBookConvertorProvider.BI, minus10Category, unknownCategory); this.plus10Category = plus10Category; this.plus30Category = plus30Category; } @Override protected Map<WeightCategoryTreatment, Map<Integer, Float>> buildDistributions() { - Map<WeightCategoryTreatment, Map<Integer, Float>> result = - Maps.newHashMap(); + Map<WeightCategoryTreatment, Map<Integer, Float>> result = new HashMap<>(); - Map<Integer, Float> distributionMinus10 = Maps.newTreeMap(); + Map<Integer, Float> distributionMinus10 = new TreeMap<>(); // 1 + 2 + 4*(0.2) + 10 distributionMinus10.put(1, 1f); @@ -68,7 +67,7 @@ public class WeightCategoryLogBookConvertorFOR_OABI extends AbstractWeightCatego result.put(minus10Category, distributionMinus10); // 3 + 4*(0.8) + 6*(0.5) + 11*(0.1) + 12 - Map<Integer, Float> distributionPlus10 = Maps.newTreeMap(); + Map<Integer, Float> distributionPlus10 = new TreeMap<>(); distributionPlus10.put(3, 1f); distributionPlus10.put(4, 0.8f); distributionPlus10.put(6, 0.5f); @@ -78,7 +77,7 @@ public class WeightCategoryLogBookConvertorFOR_OABI extends AbstractWeightCatego result.put(plus10Category, distributionPlus10); // 5 + 6*(0.5) + 7 + 8 + 11*(0.9) + 13 - Map<Integer, Float> distributionPlus30 = Maps.newTreeMap(); + Map<Integer, Float> distributionPlus30 = new TreeMap<>(); distributionPlus30.put(5, 1f); distributionPlus30.put(6, 0.5f); distributionPlus30.put(7, 1f); @@ -92,14 +91,13 @@ public class WeightCategoryLogBookConvertorFOR_OABI extends AbstractWeightCatego } @Override - public final Map<WeightCategoryTreatment, Float> distribute(Species species, - Collection<ElementaryCatch> catches) { + public final Map<WeightCategoryTreatment, Float> distribute(Species species, Collection<ElementaryCatch> catches) { float totalWeight = getTotalWeight(catches); if (totalWeight == 0) { // this means no catches - return Maps.newHashMap(); + return new HashMap<>(); } Map<WeightCategoryTreatment, Float> result; @@ -111,20 +109,22 @@ public class WeightCategoryLogBookConvertorFOR_OABI extends AbstractWeightCatego float unknownWeight = getUnknownWeight(catches); - result = defaultDistributeForSpecie1or3or4(catches, - getDistributions(), - unknownWeight - ); + result = defaultDistributeForSpecie1or3or4(catches, getDistributions(), unknownWeight); break; case 2: - - result = defaultDistributeForSpecie2(totalWeight); - +// result = defaultDistributeForSpecie2(totalWeight); + result = new HashMap<>(); + // for species SKJ (code 2) : all goes to -10 kg category + result.put(getMinus10Category(), totalWeight); break; default: - result = defaultDistributeForOtherSpecie(totalWeight); +// result = defaultDistributeForOtherSpecie(totalWeight); + result = new HashMap<>(); + + // only keep unknown category weight + result.put(getUnkownCategory(), totalWeight); } return result; } ===================================== t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OIBI.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OIBI.java +++ b/t3-domain/src/main/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorFOR_OIBI.java @@ -20,12 +20,14 @@ */ package fr.ird.t3.entities.conversion; -import com.google.common.collect.Maps; import fr.ird.t3.entities.data.ElementaryCatch; import fr.ird.t3.entities.reference.Species; import fr.ird.t3.entities.reference.WeightCategoryTreatment; + import java.util.Collection; +import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; /** * To convert weight categories for Indian ocean and undetermined school type. @@ -50,11 +52,10 @@ public class WeightCategoryLogBookConvertorFOR_OIBI extends AbstractWeightCatego @Override protected Map<WeightCategoryTreatment, Map<Integer, Float>> buildDistributions() { - Map<WeightCategoryTreatment, Map<Integer, Float>> result = - Maps.newHashMap(); + Map<WeightCategoryTreatment, Map<Integer, Float>> result = new HashMap<>(); // 1 + 2 + 4*(0.2) + 10 - Map<Integer, Float> distributionMinus10 = Maps.newTreeMap(); + Map<Integer, Float> distributionMinus10 = new TreeMap<>(); distributionMinus10.put(1, 1f); distributionMinus10.put(2, 1f); distributionMinus10.put(4, 0.2f); @@ -63,7 +64,7 @@ public class WeightCategoryLogBookConvertorFOR_OIBI extends AbstractWeightCatego result.put(minus10Category, distributionMinus10); // 3 + 4*(0.8) + 5 + 6 + 7 + 8 + 11 + 12 + 13 - Map<Integer, Float> distributionPlus10 = Maps.newTreeMap(); + Map<Integer, Float> distributionPlus10 = new TreeMap<>(); distributionPlus10.put(3, 1f); distributionPlus10.put(4, 0.8f); distributionPlus10.put(5, 1f); @@ -79,14 +80,13 @@ public class WeightCategoryLogBookConvertorFOR_OIBI extends AbstractWeightCatego } @Override - public final Map<WeightCategoryTreatment, Float> distribute(Species species, - Collection<ElementaryCatch> catches) { + public final Map<WeightCategoryTreatment, Float> distribute(Species species, Collection<ElementaryCatch> catches) { float totalWeight = getTotalWeight(catches); if (totalWeight == 0) { // this means no catches - return Maps.newHashMap(); + return new HashMap<>(); } Map<WeightCategoryTreatment, Float> result; @@ -95,22 +95,13 @@ public class WeightCategoryLogBookConvertorFOR_OIBI extends AbstractWeightCatego case 1: case 3: case 4: - float unknownWeight = getUnknownWeight(catches); - - result = defaultDistributeForSpecie1or3or4(catches, - getDistributions(), - unknownWeight - ); - + result = defaultDistributeForSpecie1or3or4(catches, getDistributions(), unknownWeight); break; case 2: - result = defaultDistributeForSpecie2(totalWeight); - break; default: - result = defaultDistributeForOtherSpecie(totalWeight); } return result; ===================================== t3-domain/src/main/java/fr/ird/t3/entities/reference/LengthWeightConversionImpl.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/LengthWeightConversionImpl.java +++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/LengthWeightConversionImpl.java @@ -20,29 +20,22 @@ */ package fr.ird.t3.entities.reference; -import com.google.common.collect.Maps; import fr.ird.t3.entities.LengthWeightConversionHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.util.Map; +import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class LengthWeightConversionImpl extends LengthWeightConversionAbstract { - /** Logger. */ - private static final Log log = - LogFactory.getLog(LengthWeightConversionImpl.class); - + private static final Log log = LogFactory.getLog(LengthWeightConversionImpl.class); private static final long serialVersionUID = 1L; - - - private static final Pattern COEFFICIENTS_PATTERN = - Pattern.compile("(.+)=(.+)"); - + private static final Pattern COEFFICIENTS_PATTERN = Pattern.compile("(.+)=(.+)"); /** variable poids à utiliser dans la relation taille */ public static final String VARIABLE_POIDS = "P"; - /** variable taille à utiliser dans la relation poids */ public static final String VARIABLE_TAILLE = "L"; @@ -59,19 +52,19 @@ public class LengthWeightConversionImpl extends LengthWeightConversionAbstract { } @Override - public float computeWeight(float longueur) { + public Float computeWeight(float longueur) { return LengthWeightConversionHelper.computeWeight(this, longueur); } @Override - public float computeWeightFromLFLengthClass(int lengthClass) { + public Float computeWeightFromLFLengthClass(int lengthClass) { Integer lfLengthClassStep = species.getLfLengthClassStep(); float longueur = lengthClass + lfLengthClassStep / 2f; return LengthWeightConversionHelper.computeWeight(this, longueur); } @Override - public float computeLength(float poids) { + public Float computeLength(float poids) { return LengthWeightConversionHelper.computeLength(this, poids); } @@ -92,31 +85,27 @@ public class LengthWeightConversionImpl extends LengthWeightConversionAbstract { @Override public Map<String, Double> getCoefficientValues() { - Map<String, Double> result = Maps.newTreeMap(); + Map<String, Double> result = new TreeMap<>(); String coefficients = getCoefficients(); if (coefficients != null) { for (String coefficientDef : coefficients.split(":")) { - Matcher matcher = - COEFFICIENTS_PATTERN.matcher(coefficientDef.trim()); + Matcher matcher = COEFFICIENTS_PATTERN.matcher(coefficientDef.trim()); if (log.isDebugEnabled()) { - log.debug("constant to test = " + coefficientDef); + log.debug(String.format("constant to test = %s", coefficientDef)); } if (matcher.matches()) { - String key = matcher.group(1); String val = matcher.group(2); try { Double d = Double.valueOf(val); result.put(key, d); if (log.isDebugEnabled()) { - log.debug("detets coefficient " + key + '=' + - val); + log.debug(String.format("detect coefficient %s=%s", key, val)); } } catch (NumberFormatException e) { // pas pu recupere le nombre... if (log.isWarnEnabled()) { - log.warn("could not parse double " + val + - " for coefficient " + key); + log.warn(String.format("could not parse double %s for coefficient %s", val, key)); } } } ===================================== t3-domain/src/main/java/fr/ird/t3/entities/reference/WeightCategoryLogBookConversionImpl.java ===================================== --- /dev/null +++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/WeightCategoryLogBookConversionImpl.java @@ -0,0 +1,49 @@ +package fr.ird.t3.entities.reference; + +/*- + * #%L + * T3 :: Domain + * %% + * Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import java.util.Date; + +public class WeightCategoryLogBookConversionImpl extends WeightCategoryLogBookConversionAbstract { + + private static final long serialVersionUID = 1L; + + @Override + public int getCode() { + return 0; + } + + @Override + public String getLabel1() { + return null; + } + + @Override + public boolean isStatus() { + return true; + } + + @Override + public boolean acceptDate(Date date) { + return !date.before(getBeginDate()) && (getEndDate() == null || !date.after(getEndDate())); + } +} ===================================== t3-domain/src/main/java/fr/ird/t3/entities/reference/WeightCategoryLogBookConversionSpeciesImpl.java ===================================== --- /dev/null +++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/WeightCategoryLogBookConversionSpeciesImpl.java @@ -0,0 +1,59 @@ +package fr.ird.t3.entities.reference; + +/*- + * #%L + * T3 :: Domain + * %% + * Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.util.Map; + +public class WeightCategoryLogBookConversionSpeciesImpl extends WeightCategoryLogBookConversionSpeciesAbstract { + + private static final long serialVersionUID = 1L; + + private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + public static String toString(Map<String, Map<Integer, Float>> distributions) { + return gson.toJson(distributions); + } + + @Override + public int getCode() { + return 0; + } + + @Override + public String getLabel1() { + return null; + } + + @Override + public boolean isStatus() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public Map<String, Map<Integer, Float>> getDistributions2() { + return gson.fromJson(getDistribution(), Map.class); + } +} ===================================== t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java +++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java @@ -123,6 +123,8 @@ public class T3MigrationCallbackV2_1 extends T3MigrationCallbackSupport { addScript("08", "remove-Trip-fields", queries); addScript("09", "fill-Harbour-ocean.sql", queries); + addScript("10", "add-WeightCategoryLogBookConversion-table.sql", queries); + addScript("11", "fill-WeightCategoryLogBookConversion-table.sql", queries); } ===================================== t3-domain/src/main/resources/db/migration/V2_1_10_add-WeightCategoryLogBookConversion-table.sql ===================================== --- /dev/null +++ b/t3-domain/src/main/resources/db/migration/V2_1_10_add-WeightCategoryLogBookConversion-table.sql @@ -0,0 +1,39 @@ +--- +-- #%L +-- T3 :: Domain +-- %% +-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io +-- %% +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero 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 Affero General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. +-- #L% +--- +drop TABLE IF EXISTS weightcategorylogbookconversion CASCADE ; +drop TABLE IF EXISTS weightcategorylogbookconversionspecies CASCADE ; +drop TABLE IF EXISTS weightcategorylogbookconversionspecies_species CASCADE ; + +CREATE TABLE WeightCategoryLogBookConversion( topiaid VARCHAR(255) PRIMARY KEY NOT NULL, topiaversion BIGINT NOT NULL, topiacreatedate TIMESTAMP NOT NULL, ocean VARCHAR(255) NOT NULL, schoolType VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, beginDate DATE NOT NULL, endDate DATE); +CREATE UNIQUE INDEX uk_WeightCategoryLogBookConversion ON WeightCategoryLogBookConversion(version, ocean, schoolType, beginDate); +ALTER TABLE WeightCategoryLogBookConversion ADD CONSTRAINT fk_WeightCategoryLogBookConversion_ocean FOREIGN KEY (ocean) REFERENCES Ocean(topiaid); +ALTER TABLE WeightCategoryLogBookConversion ADD CONSTRAINT fk_WeightCategoryLogBookConversion_schoolType FOREIGN KEY (schoolType) REFERENCES SchoolType(topiaid); +CREATE INDEX idx_WeightCategoryLogBookConversion_ocean ON WeightCategoryLogBookConversion(ocean); +CREATE INDEX idx_WeightCategoryLogBookConversion_schoolType ON WeightCategoryLogBookConversion(schoolType); + +CREATE TABLE WeightCategoryLogBookConversionSpecies( topiaid VARCHAR(255) PRIMARY KEY NOT NULL, topiaversion BIGINT NOT NULL, topiacreatedate TIMESTAMP NOT NULL, parent VARCHAR(255) NOT NULL, parent_idx int, distribution TEXT NOT NULL); +ALTER TABLE WeightCategoryLogBookConversionSpecies ADD CONSTRAINT fk_WeightCategoryLogBookConversionSpecies_parent FOREIGN KEY (parent) REFERENCES WeightCategoryLogBookConversion(topiaid); +CREATE INDEX idx_WeightCategoryLogBookConversion_parent ON WeightCategoryLogBookConversionSpecies(parent); + +CREATE TABLE WeightCategoryLogBookConversionSpecies_Species(weightCategoryLogBookConversionSpecies VARCHAR(255) NOT NULL, species VARCHAR(255) NOT NULL); +ALTER TABLE WeightCategoryLogBookConversionSpecies_Species ADD CONSTRAINT pk_WeightCategoryLogBookConversionS PRIMARY KEY (weightCategoryLogBookConversionSpecies,species); +ALTER TABLE WeightCategoryLogBookConversionSpecies_Species ADD CONSTRAINT fk_WeightCategoryLogBookConversionS_w FOREIGN KEY (weightCategoryLogBookConversionSpecies) REFERENCES WeightCategoryLogBookConversionSpecies(topiaid); +ALTER TABLE WeightCategoryLogBookConversionSpecies_Species ADD CONSTRAINT fk_WeightCategoryLogBookConversionS_s FOREIGN KEY (species) REFERENCES Species(topiaid); \ No newline at end of file ===================================== t3-domain/src/main/resources/db/migration/V2_1_11_fill-WeightCategoryLogBookConversion-table.sql ===================================== --- /dev/null +++ b/t3-domain/src/main/resources/db/migration/V2_1_11_fill-WeightCategoryLogBookConversion-table.sql @@ -0,0 +1,300 @@ +--- +-- #%L +-- T3 :: Domain +-- %% +-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io +-- %% +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero 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 Affero General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. +-- #L% +--- +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#00', 1, '2018-02-22 21:36:22.566000', 'fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.9747685881931636', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#01', 1, '2018-02-22 21:36:22.636000', 'fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.8923578380543445', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#02', 1, '2018-02-22 21:36:22.637000', 'fr.ird.t3.entities.reference.Ocean#1297580528924#0.4917298410119624', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.633774803291473', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#03', 1, '2018-02-22 21:36:22.638000', 'fr.ird.t3.entities.reference.Ocean#1297580528924#0.02462443299831396', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.9747685881931636', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#04', 1, '2018-02-22 21:36:22.638000', 'fr.ird.t3.entities.reference.Ocean#1297580528924#0.02462443299831396', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.8923578380543445', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#05', 1, '2018-02-22 21:36:22.639000', 'fr.ird.t3.entities.reference.Ocean#1297580528924#0.02462443299831396', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.633774803291473', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#06', 1, '2018-02-22 21:36:22.642000', 'fr.ird.t3.entities.reference.Ocean#1297580528925#0.868563686958073', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.9747685881931636', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#07', 1, '2018-02-22 21:36:22.645000', 'fr.ird.t3.entities.reference.Ocean#1297580528925#0.868563686958073', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.8923578380543445', '1.0', '1970-01-01', null); +INSERT INTO weightcategorylogbookconversion (topiaid, topiaversion, topiacreatedate, ocean, schooltype, version, begindate, enddate) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#08', 1, '2018-02-22 21:36:22.645000', 'fr.ird.t3.entities.reference.Ocean#1297580528925#0.868563686958073', 'fr.ird.t3.entities.reference.SchoolType#1297580528908#0.633774803291473', '1.0', '1970-01-01', null); + +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#00', 1, '2018-02-22 21:43:17.758000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#00', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830509#0.5499777108807193": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#01', 1, '2018-02-22 21:43:17.790000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#00', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830509#0.44386731073429053": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#02', 1, '2018-02-22 21:43:17.808000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#00', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830509#0.5237318856431237": { + "3": 1.0, + "4": 0.8, + "6": 0.5, + "11": 0.1, + "12": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830509#0.5499777108807192": { + "5": 1.0, + "6": 0.5, + "7": 1.0, + "8": 1.0, + "11": 0.9, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830509#0.44386731073429053": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#03', 1, '2018-02-22 21:43:17.811000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#01', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830505#0.988038536400382": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#04', 1, '2018-02-22 21:43:17.821000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#01', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830500#0.6310700924396421": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#05', 1, '2018-02-22 21:43:17.826000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#01', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830505#0.988038536400381": { + "3": 1.0, + "4": 0.8, + "5": 1.0, + "6": 1.0, + "7": 1.0, + "8": 1.0, + "11": 1.0, + "12": 1.0, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830500#0.6310700924396421": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#06', 1, '2018-02-22 21:43:17.840000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#02', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830506#0.5499777108807193": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#07', 1, '2018-02-22 21:43:17.843000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#02', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830505#0.44386731073429053": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#08', 1, '2018-02-22 21:43:17.855000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#02', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830506#0.5237318856431237": { + "3": 1.0, + "4": 0.8, + "6": 0.5, + "11": 0.1, + "12": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830506#0.5499777108807192": { + "5": 1.0, + "6": 0.5, + "7": 1.0, + "8": 1.0, + "11": 0.9, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830505#0.44386731073429053": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#017', 1, '2018-02-22 21:43:17.943000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#02', 3, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830508#0.8969775036221255": { + "3": 1.0, + "4": 0.8, + "5": 1.0, + "6": 1.0, + "7": 1.0, + "8": 1.0, + "11": 1.0, + "12": 1.0, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830507#0.6434841998774135": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#09', 1, '2018-02-22 21:43:17.858000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#03', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830510#0.8969775036221247": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#010', 1, '2018-02-22 21:43:17.875000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#03', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830510#0.6434841998774145": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#011', 1, '2018-02-22 21:43:17.891000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#03', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830510#0.8969775036221246": { + "3": 1.0, + "4": 0.8, + "5": 1.0, + "6": 1.0, + "7": 1.0, + "8": 1.0, + "11": 1.0, + "12": 1.0, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830510#0.6434841998774145": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#012', 1, '2018-02-22 21:43:17.897000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#04', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830507#0.14752652961660063": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#013', 1, '2018-02-22 21:43:17.903000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#04', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830506#0.4807760142660965": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#014', 1, '2018-02-22 21:43:17.920000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#04', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830507#0.14752652961660062": { + "3": 1.0, + "4": 0.8, + "5": 1.0, + "6": 1.0, + "7": 1.0, + "8": 1.0, + "11": 1.0, + "12": 1.0, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830506#0.4807760142660965": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#015', 1, '2018-02-22 21:43:17.929000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#05', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830508#0.8969775036221256": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#016', 1, '2018-02-22 21:43:17.939000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#05', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#1308925830507#0.6434841998774135": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#018', 1, '2018-02-22 21:43:17.951000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#06', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830510#0.8969775036221247": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#019', 1, '2018-02-22 21:43:17.956000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#06', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830510#0.6434841998774145": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#020', 1, '2018-02-22 21:43:17.961000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#06', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830510#0.8969775036221246": { + "3": 1.0, + "4": 0.8, + "5": 1.0, + "6": 1.0, + "7": 1.0, + "8": 1.0, + "11": 1.0, + "12": 1.0, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830510#0.6434841998774145": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#021', 1, '2018-02-22 21:43:17.970000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#07', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830507#0.14752652961660063": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#022', 1, '2018-02-22 21:43:17.975000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#07', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830506#0.4807760142660965": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#023', 1, '2018-02-22 21:43:17.988000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#07', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830507#0.14752652961660062": { + "3": 1.0, + "4": 0.8, + "5": 1.0, + "6": 1.0, + "7": 1.0, + "8": 1.0, + "11": 1.0, + "12": 1.0, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830506#0.4807760142660965": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#024', 1, '2018-02-22 21:43:17.991000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#08', 0, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830508#0.8969775036221256": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#025', 1, '2018-02-22 21:43:17.994000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#08', 1, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830507#0.6434841998774135": {} +}'); +INSERT INTO weightcategorylogbookconversionspecies (topiaid, topiaversion, topiacreatedate, parent, parent_idx, distribution) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#026', 1, '2018-02-22 21:43:18.006000', 'fr.ird.t3.entities.reference.WeightCategoryLogBookConversion#1519311532526#08', 2, '{ + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830508#0.8969775036221255": { + "3": 1.0, + "4": 0.8, + "5": 1.0, + "6": 1.0, + "7": 1.0, + "8": 1.0, + "11": 1.0, + "12": 1.0, + "13": 1.0 + }, + "fr.ird.t3.entities.reference.WeightCategoryTreatment#2308925830507#0.6434841998774135": { + "1": 1.0, + "2": 1.0, + "4": 0.2, + "10": 1.0 + } +}'); + +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#01', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#02', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#02', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#02', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#04', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#05', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#05', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#05', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#07', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#08', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#08', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#08', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#010', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#011', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#011', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#011', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#013', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#014', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#014', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#014', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#016', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#017', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#017', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#017', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#019', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#020', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#020', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#020', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#022', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#023', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#023', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#023', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#025', 'fr.ird.t3.entities.reference.Species#1297580528889#0.21694502845340558'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#026', 'fr.ird.t3.entities.reference.Species#1297580528889#0.5520768903332204'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#026', 'fr.ird.t3.entities.reference.Species#1297580528889#0.44612689800927063'); +INSERT INTO weightcategorylogbookconversionspecies_species (weightcategorylogbookconversionspecies, species) VALUES ('fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies#1519311532526#026', 'fr.ird.t3.entities.reference.Species#1297580528889#0.7537605030704515'); ===================================== t3-domain/src/main/resources/t3-datadb.properties ===================================== --- a/t3-domain/src/main/resources/t3-datadb.properties +++ b/t3-domain/src/main/resources/t3-datadb.properties @@ -38,4 +38,5 @@ topia.service.migration=org.nuiton.topia.migration.TopiaMigrationEngine topia.service.migration.callback=fr.ird.t3.services.migration.T3MigrationCallback topia.service.migration.showSql=true topia.service.migration.showProgression=true +topia.persistence.topiaIdFactoryClassName=org.nuiton.topia.persistence.internal.LegacyTopiaIdFactory ===================================== t3-domain/src/main/xmi/t3-persistence.properties ===================================== --- a/t3-domain/src/main/xmi/t3-persistence.properties +++ b/t3-domain/src/main/xmi/t3-persistence.properties @@ -18,7 +18,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # #L% ### -#model.tagValue.i18n=t3.common. model.tagValue.notGenerateToString=true model.tagValue.generateOperatorForDAOHelper=true model.tagValue.constantPrefix=PROPERTY_ @@ -34,6 +33,13 @@ fr.ird.t3.entities.data.Route.attribute.activity.tagvalue.orderBy=date fr.ird.t3.entities.data.Route.attribute.date.tagvalue.hibernateAttributeType.java.util.Date=date fr.ird.t3.entities.data.Activity.attribute.time.tagvalue.hibernateAttributeType.java.util.Date=time +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.beginDate.tagValue.hibernateAttributeType.java.util.Date=date +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.endDate.tagValue.hibernateAttributeType.java.util.Date=date +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.distributions.stereotype=ordered +fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies.attribute.distribution.tagValue.sqlType=text +fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies.attribute.species.stereotype=unique +fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies.attribute.species.tagvalue.manyToManyTableName=WeightCategoryLogBookConversionSpecies_Species + fr.ird.t3.entities.data.Activity.attribute.comment.tagvalue.sqlType=text fr.ird.t3.entities.data.LocalMarketBatch.attribute.origin.tagvalue.sqlType=text fr.ird.t3.entities.data.LocalMarketBatch.attribute.comment.tagvalue.sqlType=text @@ -122,6 +128,21 @@ fr.ird.t3.entities.reference.LengthWeightConversion.attribute.sexe.tagValue.notN fr.ird.t3.entities.reference.LengthWeightConversion.attribute.beginDate.tagValue.naturalId=true fr.ird.t3.entities.reference.LengthWeightConversion.attribute.beginDate.tagValue.notNull=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.ocean.tagValue.notNull=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.schoolType.tagValue.notNull=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.beginDate.tagValue.notNull=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.version.tagValue.notNull=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.class.tagValue.naturalIdMutable=false +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.ocean.tagValue.naturalId=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.schoolType.tagValue.naturalId=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.beginDate.tagValue.naturalId=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversion.attribute.version.tagValue.naturalId=true + +fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies.attribute.distribution.tagValue.notNull=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies.attribute.parent.tagValue.notNull=true +fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies.class.tagValue.naturalIdMutable=false +fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies.attribute.parent.tagValue.naturalId=true + ############################################################################### ### Natural id for data ###################################################### ############################################################################### ===================================== t3-domain/src/main/xmi/t3-persistence.zargo ===================================== Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ ===================================== t3-domain/src/test/java/fr/ird/t3/services/migration/T3MigrationTest.java ===================================== --- a/t3-domain/src/test/java/fr/ird/t3/services/migration/T3MigrationTest.java +++ b/t3-domain/src/test/java/fr/ird/t3/services/migration/T3MigrationTest.java @@ -22,11 +22,49 @@ package fr.ird.t3.services.migration; */ import fr.ird.t3.entities.T3TopiaApplicationContext; +import fr.ird.t3.entities.T3TopiaPersistenceContext; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertor; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OABI; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OABL; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OABO; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OIBI; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OIBL; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OIBO; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OPBI; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OPBL; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorFOR_OPBO; +import fr.ird.t3.entities.conversion.WeightCategoryLogBookConvertorProvider; +import fr.ird.t3.entities.reference.Ocean; +import fr.ird.t3.entities.reference.OceanTopiaDao; +import fr.ird.t3.entities.reference.SchoolType; +import fr.ird.t3.entities.reference.SchoolTypeTopiaDao; +import fr.ird.t3.entities.reference.Species; +import fr.ird.t3.entities.reference.SpeciesTopiaDao; +import fr.ird.t3.entities.reference.WeightCategoryLogBookConversion; +import fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpecies; +import fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpeciesImpl; +import fr.ird.t3.entities.reference.WeightCategoryLogBookConversionSpeciesTopiaDao; +import fr.ird.t3.entities.reference.WeightCategoryLogBookConversionTopiaDao; +import fr.ird.t3.entities.reference.WeightCategoryTreatment; +import fr.ird.t3.entities.reference.WeightCategoryTreatmentTopiaDao; import fr.ird.t3.entities.user.JdbcConfiguration; import fr.ird.t3.entities.user.JdbcConfigurationHelper; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; +import org.nuiton.topia.persistence.BeanTopiaConfiguration; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.internal.LegacyTopiaIdFactory; +import org.nuiton.util.DateUtil; + +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Created by tchemit on 20/02/2018. @@ -36,6 +74,11 @@ import org.junit.Test; @Ignore public class T3MigrationTest { + private int count = 0; + private SpeciesTopiaDao speciesDao; + private WeightCategoryLogBookConversionTopiaDao weightCategoryLogBookConversionDao; + private WeightCategoryLogBookConversionSpeciesTopiaDao weightCategoryLogBookConversionSpeciesDao; + @Test public void migratePostgres() { @@ -52,4 +95,159 @@ public class T3MigrationTest { } } + + @Test + public void generateWeightCategoryLogBookConversions() { + + String url = "jdbc:postgresql:t3"; + String login = "t3-admin"; + String password = "a"; + + JdbcConfiguration jdbcConfiguration = JdbcConfigurationHelper.newJdbcConfiguration(); + jdbcConfiguration.setUrl(url); + jdbcConfiguration.setLogin(login); + jdbcConfiguration.setPassword(password); + try (T3TopiaApplicationContext rootContext = T3TopiaApplicationContext.newDb(jdbcConfiguration)) { + + ((BeanTopiaConfiguration) rootContext.getConfiguration()).setTopiaIdFactory(new LegacyTopiaIdFactory() { + + @Override + public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, TopiaEntity topiaEntity) { + return entityClass.getName() + "#1519311532526#0" + count++; + } + }); + + try (T3TopiaPersistenceContext persistenceContext = rootContext.newPersistenceContext()) { + + WeightCategoryLogBookConvertorProvider convertorProvider = WeightCategoryLogBookConvertorProvider.newInstance(persistenceContext); + + OceanTopiaDao oceanDao = persistenceContext.getOceanDao(); + speciesDao = persistenceContext.getSpeciesDao(); + SchoolTypeTopiaDao schoolTypeDao = persistenceContext.getSchoolTypeDao(); + WeightCategoryTreatmentTopiaDao weightCategoryTreatmentDao = persistenceContext.getWeightCategoryTreatmentDao(); + weightCategoryLogBookConversionDao = persistenceContext.getWeightCategoryLogBookConversionDao(); + weightCategoryLogBookConversionSpeciesDao = persistenceContext.getWeightCategoryLogBookConversionSpeciesDao(); + + weightCategoryLogBookConversionDao.deleteAll(weightCategoryLogBookConversionDao.findAll()); + persistenceContext.getHibernateSupport().getHibernateSession().flush(); + + Date beginDate = DateUtil.createDate(1, 1, 1970); + + Ocean oceanA = oceanDao.forCodeEquals(1).findUnique(); + Ocean oceanI = oceanDao.forCodeEquals(2).findUnique(); + Ocean oceanP = oceanDao.forCodeEquals(5).findUnique(); + SchoolType schoolTypeBo = schoolTypeDao.forCodeEquals(1).findUnique(); + SchoolType schoolTypeBl = schoolTypeDao.forCodeEquals(2).findUnique(); + SchoolType schoolTypeBi = schoolTypeDao.forCodeEquals(3).findUnique(); + + String version = "1.0"; + + this.count = 0; + + // OA + WeightCategoryLogBookConversion oaBi = addConversion(version, beginDate, oceanA, schoolTypeBi); + WeightCategoryLogBookConversion oaBo = addConversion(version, beginDate, oceanA, schoolTypeBo); + WeightCategoryLogBookConversion oaBl = addConversion(version, beginDate, oceanA, schoolTypeBl); + + // OI + WeightCategoryLogBookConversion oiBi = addConversion(version, beginDate, oceanI, schoolTypeBi); + WeightCategoryLogBookConversion oiBo = addConversion(version, beginDate, oceanI, schoolTypeBo); + WeightCategoryLogBookConversion oiBl = addConversion(version, beginDate, oceanI, schoolTypeBl); + + // OP + WeightCategoryLogBookConversion opBi = addConversion(version, beginDate, oceanP, schoolTypeBi); + WeightCategoryLogBookConversion opBo = addConversion(version, beginDate, oceanP, schoolTypeBo); + WeightCategoryLogBookConversion opBl = addConversion(version, beginDate, oceanP, schoolTypeBl); + + persistenceContext.commit(); + + this.count = 0; + + //OA + { + WeightCategoryLogBookConvertorFOR_OABI convertor = getConvertor(convertorProvider, oaBi, WeightCategoryLogBookConvertorFOR_OABI.class); + addEmptyConversionSpecies(oaBi, convertor.getUnkownCategory()); + addEmptyConversionSpecies(oaBi, convertor.getMinus10Category(), 2); + addConversionSpecies(oaBi, convertor, 1, 3, 4); + } + { + WeightCategoryLogBookConvertorFOR_OABO convertor = getConvertor(convertorProvider, oaBo, WeightCategoryLogBookConvertorFOR_OABO.class); + addEmptyConversionSpecies(oaBo, convertor.getUnkownCategory()); + addEmptyConversionSpecies(oaBo, convertor.getMinus10Category(), 2); + addConversionSpecies(oaBo, convertor, 1, 3, 4); + } + { + WeightCategoryLogBookConvertorFOR_OABL convertor = getConvertor(convertorProvider, oaBl, WeightCategoryLogBookConvertorFOR_OABL.class); + addEmptyConversionSpecies(oaBl, convertor.getUnkownCategory()); + addEmptyConversionSpecies(oaBl, convertor.getMinus10Category(), 2); + addConversionSpecies(oaBl, convertor, 1, 3, 4); + } + //OI + { + WeightCategoryLogBookConvertorFOR_OIBI convertor = getConvertor(convertorProvider, oiBi, WeightCategoryLogBookConvertorFOR_OIBI.class); + addEmptyConversionSpecies(oiBi, convertor.getUnkownCategory()); + addEmptyConversionSpecies(oiBi, convertor.getMinus10Category(), 2); + addConversionSpecies(oiBi, convertor, 1, 3, 4); + } + { + WeightCategoryLogBookConvertorFOR_OIBO convertor = getConvertor(convertorProvider, oiBo, WeightCategoryLogBookConvertorFOR_OIBO.class); + addEmptyConversionSpecies(oiBo, convertor.getUnkownCategory()); + addEmptyConversionSpecies(oiBo, convertor.getMinus10Category(), 2); + addConversionSpecies(oiBo, convertor, 1, 3, 4); + } + { + WeightCategoryLogBookConvertorFOR_OIBL convertor = getConvertor(convertorProvider, oiBl, WeightCategoryLogBookConvertorFOR_OIBL.class); + addEmptyConversionSpecies(oiBl, convertor.getUnkownCategory()); + addEmptyConversionSpecies(oiBl, convertor.getMinus10Category(), 2); + addConversionSpecies(oaBl, convertor, 1, 3, 4); + } + //OP + { + WeightCategoryLogBookConvertorFOR_OPBI convertor = getConvertor(convertorProvider, opBi, WeightCategoryLogBookConvertorFOR_OPBI.class); + addEmptyConversionSpecies(opBi, convertor.getUnkownCategory()); + addEmptyConversionSpecies(opBi, convertor.getMinus10Category(), 2); + addConversionSpecies(opBi, convertor, 1, 3, 4); + } + { + WeightCategoryLogBookConvertorFOR_OPBO convertor = getConvertor(convertorProvider, opBo, WeightCategoryLogBookConvertorFOR_OPBO.class); + addEmptyConversionSpecies(opBo, convertor.getUnkownCategory()); + addEmptyConversionSpecies(opBo, convertor.getMinus10Category(), 2); + addConversionSpecies(opBo, convertor, 1, 3, 4); + } + { + WeightCategoryLogBookConvertorFOR_OPBL convertor = getConvertor(convertorProvider, opBl, WeightCategoryLogBookConvertorFOR_OPBL.class); + addEmptyConversionSpecies(opBl, convertor.getUnkownCategory()); + addEmptyConversionSpecies(opBl, convertor.getMinus10Category(), 2); + addConversionSpecies(opBl, convertor, 1, 3, 4); + } + persistenceContext.commit(); + } + } + } + + private void addConversionSpecies(WeightCategoryLogBookConversion conversion, WeightCategoryLogBookConvertor convertor, Integer... speciesCode) { + List<Species> species = speciesDao.forCodeIn(Stream.of(speciesCode).collect(Collectors.toSet())).findAll(); + Map<String, Map<Integer, Float>> distributionsToSave = convertor.getDistributionsByIds(); + WeightCategoryLogBookConversionSpecies conversionSpecies = weightCategoryLogBookConversionSpeciesDao.createByNotNull(WeightCategoryLogBookConversionSpeciesImpl.toString(distributionsToSave), conversion); + conversionSpecies.setSpecies(new HashSet<>(species)); + conversion.addDistributions(conversionSpecies); + } + + private void addEmptyConversionSpecies(WeightCategoryLogBookConversion conversion, WeightCategoryTreatment weightCategoryTreatment, Integer... speciesCode) { + List<Species> species = speciesDao.forCodeIn(Stream.of(speciesCode).collect(Collectors.toSet())).findAll(); + Map<String, Map<Integer, Float>> distributionsToSave = new LinkedHashMap<>(); + distributionsToSave.put(weightCategoryTreatment.getTopiaId(), Collections.emptyMap()); + WeightCategoryLogBookConversionSpecies conversionSpecies = weightCategoryLogBookConversionSpeciesDao.createByNotNull(WeightCategoryLogBookConversionSpeciesImpl.toString(distributionsToSave), conversion); + conversionSpecies.setSpecies(new HashSet<>(species)); + conversion.addDistributions(conversionSpecies); + } + + + private <C extends WeightCategoryLogBookConvertor> C getConvertor(WeightCategoryLogBookConvertorProvider convertorProvider, WeightCategoryLogBookConversion conversion, Class<C> convertorType) { + return convertorType.cast(convertorProvider.getConvertor(conversion.getOcean(), conversion.getSchoolType())); + } + + private WeightCategoryLogBookConversion addConversion(String version, Date beginDate, Ocean ocean, SchoolType schoolType) { + return weightCategoryLogBookConversionDao.createByNotNull(version, beginDate, ocean, schoolType); + } } View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/ea4a2e79d10126ad158b77d01c537933... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/ea4a2e79d10126ad158b77d01c537933... You're receiving this email because of your account on gitlab.com.