Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
-
0c634be4
by Tony CHEMIT at 2018-02-21T00:11:54+01:00
7 changed files:
- t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
- t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java
- − t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
- t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql → t3-domain/src/main/resources/db/migration/V2_1_07_add-Route-table.sql
- t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql → t3-domain/src/main/resources/db/migration/V2_1_08_remove-Trip-fields.sql
- t3-domain/src/main/xmi/t3-persistence.properties
- t3-domain/src/main/xmi/t3-persistence.zargo
Changes:
| ... | ... | @@ -59,6 +59,17 @@ public class ActivityImpl extends ActivityAbstract { |
| 59 | 59 |
);
|
| 60 | 60 |
|
| 61 | 61 |
protected Integer quadrant;
|
| 62 |
+ private transient Date date;
|
|
| 63 |
+ |
|
| 64 |
+ @Override
|
|
| 65 |
+ public Date getDate() {
|
|
| 66 |
+ return date != null ? date : getRoute().getDate();
|
|
| 67 |
+ }
|
|
| 68 |
+ |
|
| 69 |
+ @Override
|
|
| 70 |
+ public void setDate(Date date) {
|
|
| 71 |
+ this.date = date;
|
|
| 72 |
+ }
|
|
| 62 | 73 |
|
| 63 | 74 |
@Override
|
| 64 | 75 |
public Trip getTrip() {
|
| ... | ... | @@ -22,12 +22,24 @@ package fr.ird.t3.services.migration; |
| 22 | 22 |
*/
|
| 23 | 23 |
|
| 24 | 24 |
import com.google.auto.service.AutoService;
|
| 25 |
+import org.apache.commons.logging.Log;
|
|
| 26 |
+import org.apache.commons.logging.LogFactory;
|
|
| 25 | 27 |
import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
|
| 26 | 28 |
import org.nuiton.topia.persistence.TopiaException;
|
| 29 |
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
|
|
| 27 | 30 |
import org.nuiton.topia.persistence.support.TopiaSqlSupport;
|
| 31 |
+import org.nuiton.util.DateUtil;
|
|
| 28 | 32 |
import org.nuiton.version.Versions;
|
| 29 | 33 |
|
| 34 |
+import java.sql.Connection;
|
|
| 35 |
+import java.sql.PreparedStatement;
|
|
| 36 |
+import java.sql.ResultSet;
|
|
| 37 |
+import java.sql.SQLException;
|
|
| 38 |
+import java.text.SimpleDateFormat;
|
|
| 39 |
+import java.util.Date;
|
|
| 40 |
+import java.util.LinkedHashSet;
|
|
| 30 | 41 |
import java.util.List;
|
| 42 |
+import java.util.Set;
|
|
| 31 | 43 |
|
| 32 | 44 |
/**
|
| 33 | 45 |
* Created by tchemit on 18/02/2018.
|
| ... | ... | @@ -37,6 +49,8 @@ import java.util.List; |
| 37 | 49 |
@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
|
| 38 | 50 |
public class T3MigrationCallbackV2_1 extends T3MigrationCallbackSupport {
|
| 39 | 51 |
|
| 52 |
+ private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_1.class);
|
|
| 53 |
+ |
|
| 40 | 54 |
public T3MigrationCallbackV2_1() {
|
| 41 | 55 |
super(Versions.valueOf("2.1"));
|
| 42 | 56 |
}
|
| ... | ... | @@ -49,6 +63,76 @@ public class T3MigrationCallbackV2_1 extends T3MigrationCallbackSupport { |
| 49 | 63 |
addScript("04", "rename-SampleWell-table", queries);
|
| 50 | 64 |
addScript("05", "rename-SampleSpecies-fields", queries);
|
| 51 | 65 |
addScript("06", "referential-i18n", queries);
|
| 66 |
+ addScript("07", "add-Route-table", queries);
|
|
| 67 |
+ |
|
| 68 |
+ |
|
| 69 |
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
| 70 |
+ |
|
| 71 |
+ List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
|
|
| 72 |
+ @Override
|
|
| 73 |
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 74 |
+ return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
|
|
| 75 |
+ }
|
|
| 76 |
+ |
|
| 77 |
+ @Override
|
|
| 78 |
+ public String prepareResult(ResultSet set) throws SQLException {
|
|
| 79 |
+ return set.getString(1);
|
|
| 80 |
+ }
|
|
| 81 |
+ });
|
|
| 82 |
+ |
|
| 83 |
+ for (String tripId : tripList) {
|
|
| 84 |
+ |
|
| 85 |
+ int i = tripId.indexOf('#');
|
|
| 86 |
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1).replace(".", "").replace("#", "") + "#";
|
|
| 87 |
+ |
|
| 88 |
+ log.info("Route prefix: " + routeIdPrefix);
|
|
| 89 |
+ List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
|
|
| 90 |
+ @Override
|
|
| 91 |
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 92 |
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ? ORDER BY date");
|
|
| 93 |
+ preparedStatement.setString(1, tripId);
|
|
| 94 |
+ return preparedStatement;
|
|
| 95 |
+ }
|
|
| 96 |
+ |
|
| 97 |
+ @Override
|
|
| 98 |
+ public TripActivity prepareResult(ResultSet set) throws SQLException {
|
|
| 99 |
+ return new TripActivity(set.getString(1), set.getDate(2));
|
|
| 100 |
+ }
|
|
| 101 |
+ });
|
|
| 102 |
+ |
|
| 103 |
+ int activityIndex = 0;
|
|
| 104 |
+ Set<Date> days = new LinkedHashSet<>();
|
|
| 105 |
+ for (TripActivity activity : activityList) {
|
|
| 106 |
+ |
|
| 107 |
+ String dayDateStr = df.format(activity.date);
|
|
| 108 |
+ String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
|
|
| 109 |
+ |
|
| 110 |
+ if (days.add(activity.date)) {
|
|
| 111 |
+ |
|
| 112 |
+ log.info(String.format("[%s] new Route: %s", tripId, routeId));
|
|
| 113 |
+ activityIndex = 0;
|
|
| 114 |
+ queries.add(String.format("INSERT INTO Route(topiaId, topiaVersion, topiaCreateDate, trip, trip_idx, date) VALUES('%s', 0, CURRENT_TIMESTAMP, '%s', %d, to_date('%s', 'YYY-MM-DD'));", routeId, tripId, days.size() - 1, dayDateStr));
|
|
| 115 |
+ }
|
|
| 116 |
+ queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, activityIndex++, activity.activity));
|
|
| 117 |
+ }
|
|
| 118 |
+ |
|
| 119 |
+ if (!activityList.isEmpty()) {
|
|
| 120 |
+ queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
|
|
| 121 |
+ }
|
|
| 122 |
+ }
|
|
| 123 |
+ |
|
| 124 |
+ addScript("08", "remove-Trip-fields", queries);
|
|
| 52 | 125 |
}
|
| 53 | 126 |
|
| 127 |
+ |
|
| 128 |
+ private static class TripActivity {
|
|
| 129 |
+ |
|
| 130 |
+ private final String activity;
|
|
| 131 |
+ private final Date date;
|
|
| 132 |
+ |
|
| 133 |
+ private TripActivity(String activity, Date date) {
|
|
| 134 |
+ this.activity = activity;
|
|
| 135 |
+ this.date = DateUtil.getDay(date);
|
|
| 136 |
+ }
|
|
| 137 |
+ }
|
|
| 54 | 138 |
}
|
| 1 |
-package fr.ird.t3.services.migration;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * T3 :: Domain
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2010 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU Affero General Public License as published by
|
|
| 11 |
- * the Free Software Foundation, either version 3 of the License, or
|
|
| 12 |
- * (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU Affero General Public License
|
|
| 20 |
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
| 21 |
- * #L%
|
|
| 22 |
- */
|
|
| 23 |
- |
|
| 24 |
-import com.google.auto.service.AutoService;
|
|
| 25 |
-import org.apache.commons.logging.Log;
|
|
| 26 |
-import org.apache.commons.logging.LogFactory;
|
|
| 27 |
-import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
|
|
| 28 |
-import org.nuiton.topia.persistence.TopiaException;
|
|
| 29 |
-import org.nuiton.topia.persistence.support.TopiaSqlQuery;
|
|
| 30 |
-import org.nuiton.topia.persistence.support.TopiaSqlSupport;
|
|
| 31 |
-import org.nuiton.util.DateUtil;
|
|
| 32 |
-import org.nuiton.version.Versions;
|
|
| 33 |
- |
|
| 34 |
-import java.sql.Connection;
|
|
| 35 |
-import java.sql.PreparedStatement;
|
|
| 36 |
-import java.sql.ResultSet;
|
|
| 37 |
-import java.sql.SQLException;
|
|
| 38 |
-import java.text.SimpleDateFormat;
|
|
| 39 |
-import java.util.Date;
|
|
| 40 |
-import java.util.LinkedHashSet;
|
|
| 41 |
-import java.util.List;
|
|
| 42 |
-import java.util.Set;
|
|
| 43 |
- |
|
| 44 |
-/**
|
|
| 45 |
- * Created by tchemit on 18/02/2018.
|
|
| 46 |
- *
|
|
| 47 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 48 |
- */
|
|
| 49 |
-@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
|
|
| 50 |
-public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
|
|
| 51 |
- |
|
| 52 |
- private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_2.class);
|
|
| 53 |
- |
|
| 54 |
- public T3MigrationCallbackV2_2() {
|
|
| 55 |
- super(Versions.valueOf("2.2"));
|
|
| 56 |
- }
|
|
| 57 |
- |
|
| 58 |
- @Override
|
|
| 59 |
- protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
|
|
| 60 |
- addScript("07", "add-Route-table", queries);
|
|
| 61 |
- |
|
| 62 |
- |
|
| 63 |
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
| 64 |
- |
|
| 65 |
- List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
|
|
| 66 |
- @Override
|
|
| 67 |
- public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 68 |
- return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
|
|
| 69 |
- }
|
|
| 70 |
- |
|
| 71 |
- @Override
|
|
| 72 |
- public String prepareResult(ResultSet set) throws SQLException {
|
|
| 73 |
- return set.getString(1);
|
|
| 74 |
- }
|
|
| 75 |
- });
|
|
| 76 |
- |
|
| 77 |
- for (String tripId : tripList) {
|
|
| 78 |
- |
|
| 79 |
- int i = tripId.indexOf('#');
|
|
| 80 |
- String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
|
|
| 81 |
- |
|
| 82 |
- log.info("Route prefix: " + routeIdPrefix);
|
|
| 83 |
- List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
|
|
| 84 |
- @Override
|
|
| 85 |
- public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 86 |
- PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
|
|
| 87 |
- preparedStatement.setString(1, tripId);
|
|
| 88 |
- return preparedStatement;
|
|
| 89 |
- }
|
|
| 90 |
- |
|
| 91 |
- @Override
|
|
| 92 |
- public TripActivity prepareResult(ResultSet set) throws SQLException {
|
|
| 93 |
- return new TripActivity(set.getString(1), set.getDate(2));
|
|
| 94 |
- }
|
|
| 95 |
- });
|
|
| 96 |
- |
|
| 97 |
- |
|
| 98 |
- Set<Date> days = new LinkedHashSet<>();
|
|
| 99 |
- int activityIndex = 0;
|
|
| 100 |
- for (TripActivity activity : activityList) {
|
|
| 101 |
- |
|
| 102 |
- String dayDateStr = df.format(activity.date);
|
|
| 103 |
- String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
|
|
| 104 |
- |
|
| 105 |
- if (days.add(activity.date)) {
|
|
| 106 |
- |
|
| 107 |
- log.info(String.format("[%s] new Route: %s", tripId, routeId));
|
|
| 108 |
- // create new route
|
|
| 109 |
- queries.add(String.format("INSERT INTO Route(topiaId, topiaVersion, topiaCreateDate, trip, trip_idx, date) VALUES('%s', 0, CURRENT_TIMESTAMP, '%s', %d, to_date('%s', 'YYY-MM-DD'));", routeId, tripId, days.size() - 1, dayDateStr));
|
|
| 110 |
- }
|
|
| 111 |
- queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
|
|
| 112 |
- }
|
|
| 113 |
- |
|
| 114 |
- if (!activityList.isEmpty()) {
|
|
| 115 |
- queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
|
|
| 116 |
- }
|
|
| 117 |
- }
|
|
| 118 |
- |
|
| 119 |
- addScript("08", "remove-Trip-fields", queries);
|
|
| 120 |
- }
|
|
| 121 |
- |
|
| 122 |
- private static class TripActivity {
|
|
| 123 |
- |
|
| 124 |
- private final String activity;
|
|
| 125 |
- private final Date date;
|
|
| 126 |
- |
|
| 127 |
- private TripActivity(String activity, Date date) {
|
|
| 128 |
- this.activity = activity;
|
|
| 129 |
- this.date = DateUtil.getDay(date);
|
|
| 130 |
- }
|
|
| 131 |
- }
|
|
| 132 |
- |
|
| 133 |
-}
|
| ... | ... | @@ -22,7 +22,7 @@ |
| 22 | 22 |
model.tagValue.notGenerateToString=true
|
| 23 | 23 |
model.tagValue.generateOperatorForDAOHelper=true
|
| 24 | 24 |
model.tagValue.constantPrefix=PROPERTY_
|
| 25 |
-model.tagValue.version=2.2
|
|
| 25 |
+model.tagValue.version=2.1
|
|
| 26 | 26 |
model.tagValue.indexForeignKeys=true
|
| 27 | 27 |
|
| 28 | 28 |
fr.ird.t3.entities.data.Trip.attribute.route.stereotype=ordered
|
No preview for this file type