Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3

Commits:

8 changed files:

Changes:

  • t3-actions/src/main/java/fr/ird/t3/actions/io/input/ImportInputSourceAction.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -24,9 +24,14 @@ import fr.ird.t3.actions.T3Action;
    24 24
     import fr.ird.t3.entities.T3EntityEnum;
    
    25 25
     import fr.ird.t3.entities.T3TopiaApplicationContext;
    
    26 26
     import fr.ird.t3.entities.T3TopiaPersistenceContext;
    
    27
    +import fr.ird.t3.entities.data.Activity;
    
    28
    +import fr.ird.t3.entities.data.ActivityTopiaDao;
    
    27 29
     import fr.ird.t3.entities.data.T3DataEntity;
    
    28 30
     import fr.ird.t3.entities.data.Trip;
    
    29 31
     import fr.ird.t3.entities.data.TripTopiaDao;
    
    32
    +import fr.ird.t3.entities.data.TripType;
    
    33
    +import fr.ird.t3.entities.reference.Ocean;
    
    34
    +import fr.ird.t3.entities.reference.OceanTopiaDao;
    
    30 35
     import fr.ird.t3.entities.reference.Vessel;
    
    31 36
     import fr.ird.t3.entities.reference.VesselTopiaDao;
    
    32 37
     import fr.ird.t3.services.ioc.InjectDAO;
    
    ... ... @@ -58,12 +63,16 @@ public class ImportInputSourceAction extends T3Action<ImportInputSourceConfigura
    58 63
         //    public static final String PARAM_TRIPS_TO_IMPORT = "tripsToImport";
    
    59 64
     //    public static final String PARAM_TRIPS_TO_DELETE = "tripsToDelete";
    
    60 65
         private static final Log log = LogFactory.getLog(ImportInputSourceAction.class);
    
    61
    -    protected Set<Trip> trips;
    
    62 66
         @InjectDAO(entityType = Trip.class)
    
    63
    -    protected TripTopiaDao tripDAO;
    
    64
    -    private Set<Trip> tripToDelete;
    
    67
    +    private TripTopiaDao tripDAO;
    
    65 68
         @InjectDAO(entityType = Vessel.class)
    
    66 69
         private VesselTopiaDao vesselDAO;
    
    70
    +    @InjectDAO(entityType = Activity.class)
    
    71
    +    private ActivityTopiaDao activityDAO;
    
    72
    +    @InjectDAO(entityType = Ocean.class)
    
    73
    +    private OceanTopiaDao oceanDAO;
    
    74
    +    private Set<Trip> tripToDelete;
    
    75
    +    private Set<Trip> trips;
    
    67 76
     
    
    68 77
         @Override
    
    69 78
         protected void prepareAction() throws Exception {
    
    ... ... @@ -109,7 +118,7 @@ public class ImportInputSourceAction extends T3Action<ImportInputSourceConfigura
    109 118
                     addInfoMessage(message);
    
    110 119
                 }
    
    111 120
             }
    
    112
    -
    
    121
    +        boolean logbookMissing = TripType.LOGBOOKMISSING == getConfiguration().getTripType();
    
    113 122
             boolean createVirtualVessel = getConfiguration().isCreateVirtualVessel();
    
    114 123
             BuildVisitor builder = new BuildVisitor(getActionContext().getApplicationContext(), getT3TopiaPersistenceContext().get());
    
    115 124
             for (Trip trip : trips) {
    
    ... ... @@ -130,6 +139,9 @@ public class ImportInputSourceAction extends T3Action<ImportInputSourceConfigura
    130 139
                 String message = l(locale, "t3.message.trip.was.imported", tripLabel);
    
    131 140
                 addInfoMessage(message);
    
    132 141
     
    
    142
    +            if (logbookMissing) {
    
    143
    +                fillActivityOcean(builder.activitiesWithNoOcean);
    
    144
    +            }
    
    133 145
                 // clean the builder after each entity (since each entity is
    
    134 146
                 // standalone and does not share data with other trips)
    
    135 147
                 builder.clear();
    
    ... ... @@ -138,13 +150,26 @@ public class ImportInputSourceAction extends T3Action<ImportInputSourceConfigura
    138 150
             return true;
    
    139 151
         }
    
    140 152
     
    
    153
    +    private void fillActivityOcean(Set<Activity> ids) {
    
    154
    +
    
    155
    +        // Need to flush as we are going to query new data
    
    156
    +        getT3TopiaPersistenceContext().get().getHibernateSupport().getHibernateSession().flush();
    
    157
    +
    
    158
    +        String prefix = Activity.class.getName() + "#";
    
    159
    +        for (Activity activity : ids) {
    
    160
    +            Ocean ocean = oceanDAO.findOceanByActivity(activity);
    
    161
    +            activity.setOcean(ocean);
    
    162
    +        }
    
    163
    +    }
    
    164
    +
    
    141 165
         protected static class BuildVisitor implements TopiaEntityVisitor {
    
    142 166
     
    
    167
    +        protected final Set<String> ids = new HashSet<>();
    
    168
    +        final Set<Activity> activitiesWithNoOcean = new HashSet<>();
    
    143 169
             final T3TopiaPersistenceContext tx;
    
    144 170
             final T3TopiaApplicationContext rootTx;
    
    145
    -        protected final Set<String> ids = new HashSet<>();
    
    146
    -        protected TopiaEntity current;
    
    147 171
             final Stack<TopiaEntity> stack = new Stack<>();
    
    172
    +        protected TopiaEntity current;
    
    148 173
     
    
    149 174
             BuildVisitor(T3TopiaApplicationContext rootTx, T3TopiaPersistenceContext tx) {
    
    150 175
                 this.tx = tx;
    
    ... ... @@ -189,6 +214,12 @@ public class ImportInputSourceAction extends T3Action<ImportInputSourceConfigura
    189 214
                     @SuppressWarnings("unchecked")
    
    190 215
                     TopiaDao<TopiaEntity> dao = tx.getDao(T3EntityEnum.getContractClass((Class) entity.getClass()));
    
    191 216
                     dao.update(entity);
    
    217
    +                if (entity instanceof Activity) {
    
    218
    +                    Activity activity = (Activity) entity;
    
    219
    +                    if (activity.getOcean() == null) {
    
    220
    +                        activitiesWithNoOcean.add(activity);
    
    221
    +                    }
    
    222
    +                }
    
    192 223
                 } catch (TopiaException e) {
    
    193 224
                     throw new IllegalStateException("Could not get dao for entity " + entity, e);
    
    194 225
                 }
    
    ... ... @@ -224,6 +255,7 @@ public class ImportInputSourceAction extends T3Action<ImportInputSourceConfigura
    224 255
             @Override
    
    225 256
             public void clear() {
    
    226 257
                 ids.clear();
    
    258
    +            activitiesWithNoOcean.clear();
    
    227 259
             }
    
    228 260
         }
    
    229 261
     
    

  • t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractOceanTopiaDao.java
    ... ... @@ -20,8 +20,14 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.entities.reference;
    
    22 22
     
    
    23
    +import fr.ird.t3.entities.data.Activity;
    
    23 24
     import fr.ird.t3.entities.data.Trip;
    
    25
    +import org.nuiton.topia.persistence.support.TopiaSqlQuery;
    
    24 26
     
    
    27
    +import java.sql.Connection;
    
    28
    +import java.sql.PreparedStatement;
    
    29
    +import java.sql.ResultSet;
    
    30
    +import java.sql.SQLException;
    
    25 31
     import java.util.Collection;
    
    26 32
     import java.util.HashSet;
    
    27 33
     import java.util.Set;
    
    ... ... @@ -51,4 +57,33 @@ public class AbstractOceanTopiaDao<E extends Ocean> extends GeneratedOceanTopiaD
    51 57
             String hql = "SELECT DISTINCT(o) FROM OceanImpl o, ActivityImpl a WHERE a.ocean = o.id";
    
    52 58
             return new HashSet<>(findAll(hql));
    
    53 59
         }
    
    60
    +
    
    61
    +    public E findOceanByActivity(Activity activity) {
    
    62
    +        GetOceanIdByActivityCoordinateQuery query = new GetOceanIdByActivityCoordinateQuery(activity.getTopiaId());
    
    63
    +        String oceanId = topiaSqlSupport.findSingleResult(query);
    
    64
    +        return forTopiaIdEquals(oceanId).findUnique();
    
    65
    +    }
    
    66
    +
    
    67
    +    private static class GetOceanIdByActivityCoordinateQuery extends TopiaSqlQuery<String> {
    
    68
    +
    
    69
    +        private final String activity;
    
    70
    +
    
    71
    +        GetOceanIdByActivityCoordinateQuery(String activity) {
    
    72
    +            this.activity = activity;
    
    73
    +        }
    
    74
    +
    
    75
    +        @Override
    
    76
    +        public PreparedStatement prepareQuery(Connection connection) throws SQLException {
    
    77
    +            @SuppressWarnings("SqlResolve")
    
    78
    +            PreparedStatement ps = connection.prepareStatement(
    
    79
    +                    "SELECT o.topiaid FROM activity a, ocean o  WHERE a.topiaId = ? AND ST_Contains(o.the_geom, a.the_geom)");
    
    80
    +            ps.setString(1, activity);
    
    81
    +            return ps;
    
    82
    +        }
    
    83
    +
    
    84
    +        @Override
    
    85
    +        public String prepareResult(ResultSet set) throws SQLException {
    
    86
    +            return set.getString(1);
    
    87
    +        }
    
    88
    +    }
    
    54 89
     }

  • t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AccessDataSource.java
    ... ... @@ -144,14 +144,6 @@ public class T3AccessDataSource extends AbstractAccessDataSource<T3EntityEnum, T
    144 144
                     // on ne veut charger que les données observateurs, pas le referentiel
    
    145 145
                     continue;
    
    146 146
                 }
    
    147
    -            if (TripType.LOGBOOKMISSING == tripType && meta.getType() == T3EntityEnum.Activity) {
    
    148
    -                //FIXME-116 Just to test remove this ASAP
    
    149
    -                cache.put(meta, new Map[]{});
    
    150
    -            }
    
    151
    -            if (TripType.LOGBOOKMISSING == tripType && meta.getType() == T3EntityEnum.WellPlan) {
    
    152
    -                //FIXME-116 Just to test remove this ASAP
    
    153
    -                cache.put(meta, new Map[]{});
    
    154
    -            }
    
    155 147
                 Map<String, Object>[] data = getTableData(meta);
    
    156 148
                 if (hits != null) {
    
    157 149
                     long hit = hits.getHit(meta.getType());
    

  • t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AvdthDataEntityVisitor.java
    ... ... @@ -76,10 +76,6 @@ public abstract class T3AvdthDataEntityVisitor extends T3DataEntityVisitor {
    76 76
                         activity.setLatitude(Objects.requireNonNull(sampleSet.getActivityLatitude()));
    
    77 77
                         activity.setLongitude(Objects.requireNonNull(sampleSet.getActivityLongitude()));
    
    78 78
                         activity.setSchoolType(Objects.requireNonNull(sampleSet.getActivitySchoolType()));
    
    79
    -
    
    80
    -                    //FIXME-116 Get ocean from coordinates
    
    81
    -                    activity.setOcean(parent.getDepartureHarbour().getOcean());
    
    82
    -
    
    83 79
                         sampleSet.setActivity(endActivity(activity));
    
    84 80
                         parent.addActivity(activity);
    
    85 81
                     }
    

  • t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_3.java
    ... ... @@ -48,6 +48,7 @@ public class T3MigrationCallbackV2_3 extends T3MigrationCallbackSupport {
    48 48
         @Override
    
    49 49
         protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
    
    50 50
             addScript("01", "add-Trip-tripType", queries);
    
    51
    +        addScript("03", "spatialize-ocean", queries);
    
    51 52
         }
    
    52 53
     
    
    53 54
     }

  • t3-domain/src/main/resources/db/migration/V_2_3_03-spatialize-ocean.sql The diff for this file was not included because it is too large.
  • t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionTest.java
    ... ... @@ -10,12 +10,12 @@ package fr.ird.t3.actions.io.input;
    10 10
      * it under the terms of the GNU Affero General Public License as published by
    
    11 11
      * the Free Software Foundation, either version 3 of the License, or
    
    12 12
      * (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU Affero General Public License
    
    20 20
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    21 21
      * #L%
    
    ... ... @@ -40,7 +40,6 @@ public class AnalyzeInputSourceActionTest extends AnalyzeInputSourceActionTestSu
    40 40
             return new MSAccessTestConfiguration("testExecute_([^_]*)_(\\d+)(_.+)*", "%s_%s_V35.mdb", T3InputProviderAvdth35.ID);
    
    41 41
         }
    
    42 42
     
    
    43
    -    @Ignore
    
    44 43
         @Test
    
    45 44
         public void testExecute_OA_2000() throws Exception {
    
    46 45
             testExecute(AtlanticOceanFixtures.OA_2000);
    
    ... ... @@ -51,16 +50,4 @@ public class AnalyzeInputSourceActionTest extends AnalyzeInputSourceActionTestSu
    51 50
             testExecute(IndianOceanFixtures.OI_2000);
    
    52 51
         }
    
    53 52
     
    
    54
    -    @Ignore
    
    55
    -    @Test
    
    56
    -    public void testExecute_OA_2000_withoutLogbook() throws Exception {
    
    57
    -        testExecute(AtlanticOceanFixtures.OA_2000, TripType.LOGBOOKMISSING);
    
    58
    -    }
    
    59
    -
    
    60
    -    @Ignore
    
    61
    -    @Test
    
    62
    -    public void testExecute_OI_2002_withoutLogbook() throws Exception {
    
    63
    -        testExecute(IndianOceanFixtures.OI_2002,TripType.LOGBOOKMISSING);
    
    64
    -    }
    
    65
    -
    
    66 53
     }

  • t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionTest.java
    ... ... @@ -23,9 +23,7 @@ package fr.ird.t3.actions.io.input;
    23 23
     
    
    24 24
     import fr.ird.t3.actions.io.input.test.ImportInputSourceActionTestSupport;
    
    25 25
     import fr.ird.t3.actions.io.input.test.MSAccessTestConfiguration;
    
    26
    -import fr.ird.t3.entities.data.TripType;
    
    27 26
     import fr.ird.t3.io.input.avdth.v35.T3InputProviderAvdth35;
    
    28
    -import org.junit.Ignore;
    
    29 27
     import org.junit.Test;
    
    30 28
     
    
    31 29
     /**
    
    ... ... @@ -50,16 +48,4 @@ public class ImportInputSourceActionTest extends ImportInputSourceActionTestSupp
    50 48
             testExecute(IndianOceanFixtures.OI_2000);
    
    51 49
         }
    
    52 50
     
    
    53
    -    @Ignore
    
    54
    -    @Test
    
    55
    -    public void testExecute_OA_2000_withoutLogbook() throws Exception {
    
    56
    -        testExecute(AtlanticOceanFixtures.OA_2000, TripType.LOGBOOKMISSING);
    
    57
    -    }
    
    58
    -
    
    59
    -    @Ignore
    
    60
    -    @Test
    
    61
    -    public void testExecute_OI_2002_withoutLogbook() throws Exception {
    
    62
    -        testExecute(IndianOceanFixtures.OI_2002, TripType.LOGBOOKMISSING);
    
    63
    -    }
    
    64
    -
    
    65 51
     }