branch feature/7017 updated (42d8855 -> f50756a)
This is an automated email from the git hooks/post-receive script. New change to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git discards 42d8855 les dcp et les callées ne sont plus supprimées discards fdfb7ba correction de la recherche du sex indeterminé, ne pas crééer de service proxifié dans un service. discards 234da16 vérifie si le bean dans le validateur parent est bien présent. discards 2c13b5d remplacé l'utilisation des lists singlonton car elle doivent être triées, filtré les element de list a enregistrés, ajout d'un chans dans un binder discards 27e86cb mise en place du cache sur les listes de référentiels (refs #7017) discards 0fa7542 correction sur la sauvegarde d'une entite du referentiel (refs #7017) discards 42d7e97 Capture : enregistrement de l'avançon, désactivation du champs "santé au rejet", Enregistrement des profondeur : erreur au changement de ligne, Estimation banc : affectation de la seine au estimation des banc avant l'enregistrement. discards 45d847c correction de la validation des onglets (refs #7017) discards e886294 Amélioration du code pour créer des entities (on passe toujours par un binder.obtainProperties) (refs #7017) discards 56ed66e fix propriété des equipements discards a8e1073 - suppression commons.collections - ajout Sylvain en tant que développeur - observe-validation est en dépendances sur observe-service-api - optimisation des dépendances - deplacement model discards 2bbe067 demander l'enregistrement du detail de l'avançon modifié avant l'enregistrement de la composition de la palangre discards f79c35b - Amélioration du cache de services - Ajout API pour créer un modèle de sélection discards 1ca68ba correction initStorage, toujour utilisé les valeurs des combobox pour la positiond'une ligne discards bff6cb7 correction de la sauvegarde sur le détail de composition de la palangure (refs #7017) discards 87de065 add missing files + fix API discards 82fd5ba add missing files + fix API discards dcc1d1b - creation du module observe-services-api - amélioration de la service factory pour ne plus utiliser la datasource en état refs #7017 discards edb7f25 remove EntityAssociation (refs #7017) discards ed69714 reformat code + improve TransmittingBuoyOperation api (refs #7017) discards 55f7dc0 amélioration de l'algorithme de sauvegarde (refs #7017) discards a469bb2 suppression de tout le code utilisant des transactions sur module swing (refs #7017) discards 52294bf - suppression de tout code utilisant des transaction du module swing (refs #7017) discards 7354d7a reorganisation des controleurs des ecrans de type tableaux + correction des sauvegardes des echantillons seine discards 9959d33 debut de revue des ecrans de type tableau (refs #7017) discards 67b1d74 revue des écrans de type list (refs #7017) discards 4f5f524 - Amélioration de la validation des activités - Revue de la cinématiques pour les écrans de type Open (ajout méthode onOpenUI) - implantation du service pour les TargetCatch - ménache! discards 7b6c125 - Suppression dans les handlers to code avec les transactions - Amélioration du code dans les services - faire fonctionner la sauvegarde de CatchLongine refs #7017 discards 42c1b49 correction sauvegarde équipement, sauvegarde composition discards 90ff5b0 fix measurement save code discards 9dd0367 add not null constrainst on gear use features discards 4762be6 deplacement du traitement après enregistrement dans les services. discards bc1adbe mise en place des binders pour les référentiels et adaptation des ui (refs #7017) discards e5c82ef savegarde des caractéristiques des équipements pour la palangre. fix npe discards a0cad76 savegarde des caractéristiques des équipements discards da39110 faunes accesoires et équipements discards fbd9693 utilisation des binders venant du service BinderService (sauf pour les referentiels) (refs #7017) discards b694f31 échantillon acessoire capturé. discards 5a03db7 supression de mauvaise saisie discards 8ee7320 desciption des binder seine dans binder service, échantillon capturé discards 4229b1f amélioration du contrat pour enregistrer les collections + application sur le modèle ll (refs #7017) discards d284576 fix sur le service des binders (refs #7017) discards 97ed503 utilisation des binders depuis le binserService pour le moèdle LL (refs #7017) discards 1573007 refactor save action for table entities (in ObjectObservedSpecies) discards 9f63563 ajout des binders (longline model) dans le binder service (refs #7017) discards 8ef6168 refactor save action for table entities (in ObjectSchoolEstimate) discards d8e7ac2 refactor save action for table entities (in schoolEstimate) discards f3e984a debut d'implantation pour les ecrans de type tableau (refs #7017) discards d34cd1e refactor save action for table entities discards 02aea27 refactor delete action for seine and longline discards 04bf64e refactor save action for longline discards 0e5d70b refactor save action for seine discards a6d9341 do the math for lists-like ui (refs #7017) discards aeddf1e load programs (refs #7017) discards e5d591a add binderService in serviceContext (refs #7017) discards 5ec61f5 correction de la mise à jour du context openable (refs #7017) discards a6ee25e correction de la méthode onCreate (refs #7017) discards 1557801 correction de la méthode onCreate (refs #7017) discards 6550165 amélioration des erreurs sur le proxy (refs #7017) discards 4a54a88 mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) discards 39408ec mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) discards 7f3c078 ne pas mettre une transaction si l'annoation NoTransaction is présente sur une méthode de service (refs #7017) discards 30a186b refactor save action discards 1d3e4d3 continue les écrans simples sur le modèle seine (refs #7017) discards db5dcd0 ajout de premiers services et d'une usine de services discards a2cc54f ajout d'une usine à service + amélioration de l'abstraction (refs #7017) discards cd63a89 add some first service stubs for seine model (refs #7017) discards 3e059c0 fix module name discards fe178e6 mise en place des services adds 118a665 renommage clef i18n (refs #7043) adds 84aaeac fixes #7043: [ObserveLL] libellé position verticale d'un tdr Merge branch 'feature/7043' into develop adds 8ee21b6 suppression du controle entre section sur la longeur d'orin (refs #7044) adds 8df17ed fixes #7044: [ObserveLL] Contrôle abusif longueur orin entre sections Merge branch 'feature/7044' into develop adds 14d6d78 correction du controle sur la durée minimale d'une calée (refsc #7070) adds a3812fb fixes #7070: [ObservePS] Le controle sur la durée d'une calée ne fonctionne pas Merge branch 'feature/7070' into develop new 5ba3b66 mise en place des services new 1406b4a fix module name new 11bb74e add some first service stubs for seine model (refs #7017) new 8bccff0 ajout d'une usine à service + amélioration de l'abstraction (refs #7017) new af40530 ajout de premiers services et d'une usine de services new c455e5c continue les écrans simples sur le modèle seine (refs #7017) new 2202b5e refactor save action new f4493d9 ne pas mettre une transaction si l'annoation NoTransaction is présente sur une méthode de service (refs #7017) new 2e0a250 mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) new b1c6d98 mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) new 731d1ab amélioration des erreurs sur le proxy (refs #7017) new fca87fc correction de la méthode onCreate (refs #7017) new 48b4dca correction de la méthode onCreate (refs #7017) new 14088bf correction de la mise à jour du context openable (refs #7017) new 4799c9b add binderService in serviceContext (refs #7017) new 4bec0c4 load programs (refs #7017) new 57ceac3 do the math for lists-like ui (refs #7017) new c98c3c3 refactor save action for seine new 0e668f8 refactor save action for longline new bdeaecf refactor delete action for seine and longline new ea291d3 refactor save action for table entities new c9f41f3 debut d'implantation pour les ecrans de type tableau (refs #7017) new 276980c refactor save action for table entities (in schoolEstimate) new ff7b0c0 refactor save action for table entities (in ObjectSchoolEstimate) new 38b1f3c ajout des binders (longline model) dans le binder service (refs #7017) new 2d648bf refactor save action for table entities (in ObjectObservedSpecies) new acd6e76 utilisation des binders depuis le binserService pour le moèdle LL (refs #7017) new ed3eb1f fix sur le service des binders (refs #7017) new d2fcd82 amélioration du contrat pour enregistrer les collections + application sur le modèle ll (refs #7017) new 7965267 desciption des binder seine dans binder service, échantillon capturé new 7dfb645 supression de mauvaise saisie new 2bb8a87 échantillon acessoire capturé. new 7b30af9 utilisation des binders venant du service BinderService (sauf pour les referentiels) (refs #7017) new c5ffd2d faunes accesoires et équipements new 74147e4 savegarde des caractéristiques des équipements new cc28455 savegarde des caractéristiques des équipements pour la palangre. fix npe new d35ba0b mise en place des binders pour les référentiels et adaptation des ui (refs #7017) new 85e84bf deplacement du traitement après enregistrement dans les services. new d115489 add not null constrainst on gear use features new f6d0a5e fix measurement save code new 0c7e4f8 correction sauvegarde équipement, sauvegarde composition new 785c857 - Suppression dans les handlers to code avec les transactions - Amélioration du code dans les services - faire fonctionner la sauvegarde de CatchLongine refs #7017 new b820d62 - Amélioration de la validation des activités - Revue de la cinématiques pour les écrans de type Open (ajout méthode onOpenUI) - implantation du service pour les TargetCatch - ménache! new 8903221 revue des écrans de type list (refs #7017) new 6711f3f debut de revue des ecrans de type tableau (refs #7017) new 010d21d reorganisation des controleurs des ecrans de type tableaux + correction des sauvegardes des echantillons seine new 9683356 - suppression de tout code utilisant des transaction du module swing (refs #7017) new 39cf9b8 suppression de tout le code utilisant des transactions sur module swing (refs #7017) new d6dae38 amélioration de l'algorithme de sauvegarde (refs #7017) new e9061e9 reformat code + improve TransmittingBuoyOperation api (refs #7017) new 4b770be remove EntityAssociation (refs #7017) new a17990f - creation du module observe-services-api - amélioration de la service factory pour ne plus utiliser la datasource en état refs #7017 new e310616 add missing files + fix API new dcdc613 add missing files + fix API new 18e070f correction de la sauvegarde sur le détail de composition de la palangure (refs #7017) new 5e692f7 correction initStorage, toujour utilisé les valeurs des combobox pour la positiond'une ligne new d36d5fe - Amélioration du cache de services - Ajout API pour créer un modèle de sélection new 54f59c0 demander l'enregistrement du detail de l'avançon modifié avant l'enregistrement de la composition de la palangre new f8957ff - suppression commons.collections - ajout Sylvain en tant que développeur - observe-validation est en dépendances sur observe-service-api - optimisation des dépendances - deplacement model new 83ebc2c fix propriété des equipements new bfd370b Amélioration du code pour créer des entities (on passe toujours par un binder.obtainProperties) (refs #7017) new 4aab2fd correction de la validation des onglets (refs #7017) new 5277cd7 Capture : enregistrement de l'avançon, désactivation du champs "santé au rejet", Enregistrement des profondeur : erreur au changement de ligne, Estimation banc : affectation de la seine au estimation des banc avant l'enregistrement. new 6ae8805 correction sur la sauvegarde d'une entite du referentiel (refs #7017) new 6dd624e mise en place du cache sur les listes de référentiels (refs #7017) new 748ea80 remplacé l'utilisation des lists singlonton car elle doivent être triées, filtré les element de list a enregistrés, ajout d'un chans dans un binder new ed66b0e vérifie si le bean dans le validateur parent est bien présent. new 9840500 correction de la recherche du sex indeterminé, ne pas crééer de service proxifié dans un service. new f50756a les dcp et les callées ne sont plus supprimées This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (42d8855) \ N -- N -- N refs/heads/feature/7017 (f50756a) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omits" are not gone; other references still refer to them. Any revisions marked "discards" are gone forever. The 69 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit f50756a17f635648eee057b654c9d545930062ce Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed May 6 09:41:27 2015 +0200 les dcp et les callées ne sont plus supprimées commit 9840500cf667dabbaf4010e87a50dcdb7b37474f Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 17:53:08 2015 +0200 correction de la recherche du sex indeterminé, ne pas crééer de service proxifié dans un service. commit ed66b0ebeaa52573a57947cede1305722e543e7f Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 16:22:40 2015 +0200 vérifie si le bean dans le validateur parent est bien présent. commit 748ea80260ecce2c1060b0add3cf427b64c90ef9 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 16:20:41 2015 +0200 remplacé l'utilisation des lists singlonton car elle doivent être triées, filtré les element de list a enregistrés, ajout d'un chans dans un binder commit 6dd624e73ffe037bf5d06d354f306c4d0d00044c Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 15:27:29 2015 +0200 mise en place du cache sur les listes de référentiels (refs #7017) commit 6ae8805caca7eae804cf5c1bc417c8019fde5afa Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 15:27:08 2015 +0200 correction sur la sauvegarde d'une entite du referentiel (refs #7017) commit 5277cd7e1b9812eb98537e1ff990ce6585461a84 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 14:26:45 2015 +0200 Capture : enregistrement de l'avançon, désactivation du champs "santé au rejet", Enregistrement des profondeur : erreur au changement de ligne, Estimation banc : affectation de la seine au estimation des banc avant l'enregistrement. commit 4aab2fdd4a75587f7c1cdd19bb7ca0d39076b747 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 09:05:51 2015 +0200 correction de la validation des onglets (refs #7017) commit bfd370b71e70860cecef055036fb34557cb8de70 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 08:37:08 2015 +0200 Amélioration du code pour créer des entities (on passe toujours par un binder.obtainProperties) (refs #7017) commit 83ebc2c82bf27e38ad3ead3216f84f32490f5683 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 4 18:12:07 2015 +0200 fix propriété des equipements commit f8957ffbf6cf2e9a0dfbb492048c67bed28a067a Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 17:56:03 2015 +0200 - suppression commons.collections - ajout Sylvain en tant que développeur - observe-validation est en dépendances sur observe-service-api - optimisation des dépendances - deplacement model commit 54f59c05abba19bb548b24c08dba60e5ee13d817 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 4 17:24:38 2015 +0200 demander l'enregistrement du detail de l'avançon modifié avant l'enregistrement de la composition de la palangre commit d36d5fe7421014f7cb95a5e8772f4974c8d69ba6 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 15:55:19 2015 +0200 - Amélioration du cache de services - Ajout API pour créer un modèle de sélection refs #7017 commit 5e692f74bcbfac64660c606a611e1dac881db457 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 4 15:26:42 2015 +0200 correction initStorage, toujour utilisé les valeurs des combobox pour la positiond'une ligne commit 18e070f1cf5ce4e089268788d2a6b3fcee8a1836 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 13:56:24 2015 +0200 correction de la sauvegarde sur le détail de composition de la palangure (refs #7017) commit dcdc613b854f3dbc2e45c2bc4def6368bdd7d0d0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 09:38:28 2015 +0200 add missing files + fix API commit e31061633ca6b01bcf8a6b72cbcb7022ea035023 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 09:33:39 2015 +0200 add missing files + fix API commit a17990fd553f7992ff9f207699cce52a62a0e460 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 09:20:35 2015 +0200 - creation du module observe-services-api - amélioration de la service factory pour ne plus utiliser la datasource en état refs #7017 commit 4b770be9c4b6fd62e2ab78cb8e383dd07a852a7e Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 07:58:07 2015 +0200 remove EntityAssociation (refs #7017) commit e9061e9f103a620be13a3ce800a7bc0bc6d19c86 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 07:55:23 2015 +0200 reformat code + improve TransmittingBuoyOperation api (refs #7017) commit d6dae3857b5806453d14c22941d88d16609d025e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun May 3 17:35:04 2015 +0200 amélioration de l'algorithme de sauvegarde (refs #7017) commit 39cf9b8cbbd4d54d6464f6e2ac0a074c56c94cbb Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun May 3 17:22:18 2015 +0200 suppression de tout le code utilisant des transactions sur module swing (refs #7017) commit 9683356ba63aa405c2df81ec3f665c13350f79a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun May 3 17:21:07 2015 +0200 - suppression de tout code utilisant des transaction du module swing (refs #7017) commit 010d21dbbd6827d701b89c6e9a8dc0228ce9e271 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 19:01:14 2015 +0200 reorganisation des controleurs des ecrans de type tableaux + correction des sauvegardes des echantillons seine commit 6711f3ff5f05e50e3aeb0225719205f002e9fb6f Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 17:15:18 2015 +0200 debut de revue des ecrans de type tableau (refs #7017) commit 89032218320002c3eb42cb5d29f91ff3ff28ab64 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 15:50:00 2015 +0200 revue des écrans de type list (refs #7017) commit b820d62b094ae70913ca6c95ccfe31f257a57672 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 15:16:21 2015 +0200 - Amélioration de la validation des activités - Revue de la cinématiques pour les écrans de type Open (ajout méthode onOpenUI) - implantation du service pour les TargetCatch - ménache! refs #7017 commit 785c85708d6a2d2bec8ae81da90bcb4c6411e12a Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 00:14:16 2015 +0200 - Suppression dans les handlers to code avec les transactions - Amélioration du code dans les services - faire fonctionner la sauvegarde de CatchLongine refs #7017 commit 0c7e4f80cb5130bbe3ec21420752ca276cd740de Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 18:19:57 2015 +0200 correction sauvegarde équipement, sauvegarde composition commit f6d0a5e02e1d33c306f8c287cadcf02c178c4fb9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 30 18:03:33 2015 +0200 fix measurement save code commit d11548946d5ce3603c0b5d108cee140cac3ef1c8 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 30 17:59:41 2015 +0200 add not null constrainst on gear use features commit 85e84bfdec44e9e39ecdfb72d6b939c5fe8a1a36 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 16:49:58 2015 +0200 deplacement du traitement après enregistrement dans les services. commit d35ba0b59e83d735cf23d1259f3c5355c409ed52 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 30 16:37:00 2015 +0200 mise en place des binders pour les référentiels et adaptation des ui (refs #7017) commit cc28455d329cec7d3074777404b6c7e57f2522c3 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 15:37:37 2015 +0200 savegarde des caractéristiques des équipements pour la palangre. fix npe commit 74147e48119cf5d3648db7a5a06f4e1082825051 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 11:25:00 2015 +0200 savegarde des caractéristiques des équipements commit c5ffd2deed422fbbe4726d550f06c7ce7c400a76 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 09:45:46 2015 +0200 faunes accesoires et équipements commit 7b30af9618610b61ff151933645fa2f60bc2d426 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 21:04:42 2015 +0200 utilisation des binders venant du service BinderService (sauf pour les referentiels) (refs #7017) commit 2bb8a87be5471ec217f018dbe473c72b6f5d7967 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 17:39:28 2015 +0200 échantillon acessoire capturé. commit 7dfb645d04e6361f461d56bbff2e8f199ee0d85b Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 16:08:02 2015 +0200 supression de mauvaise saisie commit 796526754295a8fe6f58b86222984dc417179d6d Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 15:49:26 2015 +0200 desciption des binder seine dans binder service, échantillon capturé commit d2fcd82c2ca700c2911668e2f89375b70510985b Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 15:44:32 2015 +0200 amélioration du contrat pour enregistrer les collections + application sur le modèle ll (refs #7017) commit ed3eb1f296730ba08f07738322930f182065911e Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 15:43:59 2015 +0200 fix sur le service des binders (refs #7017) commit acd6e76a9a408631b82a4bc6c2e82597b79985f2 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 12:07:17 2015 +0200 utilisation des binders depuis le binserService pour le moèdle LL (refs #7017) commit 2d648bff15cef6ba75509db9c37741dc5f41a998 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 11:23:26 2015 +0200 refactor save action for table entities (in ObjectObservedSpecies) commit 38b1f3c4eddeb63e06378d10324625c953e45a34 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 11:22:11 2015 +0200 ajout des binders (longline model) dans le binder service (refs #7017) commit ff7b0c06ba01573f013cf7fb764597ea858ec94e Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 11:09:26 2015 +0200 refactor save action for table entities (in ObjectSchoolEstimate) commit 276980ce4bd35b799b8d67023d2ecc3f2062e5a4 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 10:16:15 2015 +0200 refactor save action for table entities (in schoolEstimate) commit c9f41f3ef9d469475c65be764d6a63d0b41e39ec Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 08:49:43 2015 +0200 debut d'implantation pour les ecrans de type tableau (refs #7017) commit ea291d359521f79ccea2bdc89c0d357fe4c3b0f4 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Apr 28 17:34:37 2015 +0200 refactor save action for table entities commit bdeaecf4a0ecd57cffb2829a3df40acf877fb1ba Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Apr 28 08:29:47 2015 +0200 refactor delete action for seine and longline commit 0e668f8f23b68adad801c0411fb54598a3ab8315 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Apr 27 17:15:40 2015 +0200 refactor save action for longline Conflicts: observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java commit c98c3c3387e40c9dfaa5b777e56cdef36a00ad83 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Apr 27 15:40:56 2015 +0200 refactor save action for seine Conflicts: observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java commit 57ceac33855494c42362a2e02d3ae1e80198f7d5 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 09:50:26 2015 +0200 do the math for lists-like ui (refs #7017) commit 4bec0c4a881253593ea34f58dae17ed1d412461a Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 09:50:07 2015 +0200 load programs (refs #7017) commit 4799c9b21b016fd77b3444040432fd1d676eaf7d Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 09:49:49 2015 +0200 add binderService in serviceContext (refs #7017) commit 14088bfd008c7f595e63d090d3f1f148c8ea4640 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 08:47:48 2015 +0200 correction de la mise à jour du context openable (refs #7017) commit 48b4dcab39405c0fffbeb177310aee42a2e022a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 15:39:42 2015 +0200 correction de la méthode onCreate (refs #7017) commit fca87fcdd5ccbe4db4af65e09176aaf1e0efdd0d Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 15:39:20 2015 +0200 correction de la méthode onCreate (refs #7017) commit 731d1aba7422e475f71f0b1a325300a27eacb815 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 15:38:55 2015 +0200 amélioration des erreurs sur le proxy (refs #7017) commit b1c6d984f0c17942eb42eaff8420f70685cd3510 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 14:57:30 2015 +0200 mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) commit 2e0a250caf9f96f6282759ef45c45cbee129fc74 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 14:55:57 2015 +0200 mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) commit f4493d9da71be443e4174a8e56f3efd368d0c289 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 12:17:43 2015 +0200 ne pas mettre une transaction si l'annoation NoTransaction is présente sur une méthode de service (refs #7017) commit 2202b5eeadf13a04b417408e307e94f3d5abeab4 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Apr 27 11:48:38 2015 +0200 refactor save action commit c455e5c04b3b588e1f86726373b239ebe9302224 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 09:11:20 2015 +0200 continue les écrans simples sur le modèle seine (refs #7017) commit af4053010d25755bc855f6aa1740cc3f6342c9b9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Apr 26 21:11:27 2015 +0200 ajout de premiers services et d'une usine de services commit 8bccff039aae053b3864bd17928ee6b66ee0b86f Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 24 10:05:34 2015 +0200 ajout d'une usine à service + amélioration de l'abstraction (refs #7017) commit 11bb74ef36bbdbfffd713cac1316994a7051b579 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 24 09:45:50 2015 +0200 add some first service stubs for seine model (refs #7017) commit 1406b4a2fcf717f06a3afe6781a816361f69549e Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 24 09:43:41 2015 +0200 fix module name commit 5ba3b6636baeb8bb91738b3c97750776b21ecd61 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri Apr 24 08:59:28 2015 +0200 mise en place des services Summary of changes: ...onglineDetailCompositionUIValidationHelper.java | 22 ---------------------- .../resources/i18n/observe-swing_en_GB.properties | 1 - .../resources/i18n/observe-swing_es_ES.properties | 1 - .../resources/i18n/observe-swing_fr_FR.properties | 3 +-- .../seine/SetSeine-n1-create-error-validation.xml | 2 +- .../i18n/observe-validation_fr_FR.properties | 2 +- 6 files changed, 3 insertions(+), 28 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 5ba3b6636baeb8bb91738b3c97750776b21ecd61 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri Apr 24 08:59:28 2015 +0200 mise en place des services --- observe-services/LICENSE.txt | 674 +++++++++++++++++++++ observe-services/README.txt | 2 + observe-services/pom.xml | 125 ++++ .../observe/services/AbstractObserveService.java | 49 ++ .../services/Longline/TripLonglineServiceImp.java | 56 ++ observe-swing/pom.xml | 5 + .../open/impl/longline/TripLonglineUIHandler.java | 3 + pom.xml | 1 + 8 files changed, 915 insertions(+) diff --git a/observe-services/LICENSE.txt b/observe-services/LICENSE.txt new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/observe-services/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/observe-services/README.txt b/observe-services/README.txt new file mode 100644 index 0000000..d2e50d3 --- /dev/null +++ b/observe-services/README.txt @@ -0,0 +1,2 @@ +To deploy new version of pom: mvn deploy +To install localy: mvn install diff --git a/observe-services/pom.xml b/observe-services/pom.xml new file mode 100644 index 0000000..f4cd418 --- /dev/null +++ b/observe-services/pom.xml @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>fr.ird.observe</groupId> + <artifactId>observe</artifactId> + <version>4.0-RC5-SNAPSHOT</version> + </parent> + + <artifactId>observe-services</artifactId> + + <name>ObServe :: Servicess</name> + <description>ObServe services module</description> + + <dependencies> + + <!-- sibling dependencies --> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>observe-entities</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>observe-business</artifactId> + <version>${project.version}</version> + </dependency> + + + <!-- commons dependencies --> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> + <groupId>commons-primitives</groupId> + <artifactId>commons-primitives</artifactId> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-collections4</artifactId> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + </dependency> + <dependency> + <groupId>commons-jxpath</groupId> + <artifactId>commons-jxpath</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + + <!-- Nuiton --> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> + <dependency> + <groupId>org.nuiton.i18n</groupId> + <artifactId>nuiton-i18n</artifactId> + </dependency> + + <!-- persistence --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + </dependency> + <dependency> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-persistence</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + <scope>runtime</scope> + </dependency> + + <!-- Logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jcl</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>runtime</scope> + </dependency> + + <!-- test dependencies --> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + + </dependencies> + + +</project> \ No newline at end of file diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java new file mode 100644 index 0000000..e41299a --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -0,0 +1,49 @@ +package fr.ird.observe.services; + +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public abstract class AbstractObserveService<E extends TopiaEntity> { + + protected DataSource dataSource; + + protected Class<E> entityClass; + + protected TopiaDAO<E> dao; + + + public E create(E entity) { + try { + TopiaContext topiaContext = dataSource.beginTransaction("create entity"); + + TopiaDAO<E> dao = ObserveDAOHelper.getDAO(topiaContext, entityClass); + + topiaContext.commitTransaction(); + + } catch (DataSourceException e) { + e.printStackTrace(); + } catch (TopiaException e) { + e.printStackTrace(); + } finally { + + } + + }; + + public abstract void update(E entity); + + public abstract E findById(String id); + + public abstract void delete(E entity); + + + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java b/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java new file mode 100644 index 0000000..1f1c312 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java @@ -0,0 +1,56 @@ +package fr.ird.observe.services.Longline; + +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.TripLonglineDAO; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class TripLonglineServiceImp extends AbstractObserveService<TripLongline> { + + @Override + public TripLongline create(TripLongline entity) { + try { + TopiaContext topiaContext = dataSource.beginTransaction("create TripLongline"); + + TripLonglineDAO dao = ObserveDAOHelper.getTripLonglineDAO(topiaContext); + + entity = dao.create(entity); + + } catch (DataSourceException e) { + throw new ObserveTechnicalException("unable to create tripLongLine", e); + } catch (TopiaException e) { + throw new ObserveTechnicalException("unable to create tripLongLine", e); + } + + return entity; + } + + @Override + public void update(TripLongline entity) { + + getLoadBinder().copyExcluding(getBean(), beanToSave, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + + return beanToSave; + + } + + @Override + public TripLongline findById(String id) { + return null; + } + + @Override + public void delete(TripLongline entity) { + TopiaDAO<TripLongline> dao = getDataSource().getDAO(tx, TripLongline.class); + dao.delete(beanToDelete); + + } +} diff --git a/observe-swing/pom.xml b/observe-swing/pom.xml index a26a84b..652d1ca 100644 --- a/observe-swing/pom.xml +++ b/observe-swing/pom.xml @@ -92,6 +92,11 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>observe-services</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>observe-validation</artifactId> <version>${project.version}</version> <scope>runtime</scope> diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java index 8b9e83e..bcf6157 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java @@ -32,6 +32,7 @@ import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.longline.ActivityLonglines; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.Longline.TripLonglineServiceImp; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; @@ -65,6 +66,8 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline /** Logger */ static private final Log log = LogFactory.getLog(TripLonglineUIHandler.class); + protected TripLonglineServiceImp service; + protected boolean buildTripMap = true; public TripLonglineUIHandler(TripLonglineUI ui) { diff --git a/pom.xml b/pom.xml index f0fdbf7..ce2cc68 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,7 @@ <modules> <module>observe-entities</module> <module>observe-business</module> + <module>observe-services</module> <module>observe-validation</module> <module>observe-swing</module> </modules> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 1406b4a2fcf717f06a3afe6781a816361f69549e Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 24 09:43:41 2015 +0200 fix module name --- observe-services/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/observe-services/pom.xml b/observe-services/pom.xml index f4cd418..1b85d2d 100644 --- a/observe-services/pom.xml +++ b/observe-services/pom.xml @@ -12,7 +12,7 @@ <artifactId>observe-services</artifactId> - <name>ObServe :: Servicess</name> + <name>ObServe :: Services</name> <description>ObServe services module</description> <dependencies> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 11bb74ef36bbdbfffd713cac1316994a7051b579 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 24 09:45:50 2015 +0200 add some first service stubs for seine model (refs #7017) --- .../services/seine/ActivitySeineServiceImpl.java | 50 ++++++++++++++++++++++ .../services/seine/FloatingObjectServiceImpl.java | 43 +++++++++++++++++++ .../observe/services/seine/RouteServiceImpl.java | 41 ++++++++++++++++++ .../services/seine/SetSeineServiceImpl.java | 43 +++++++++++++++++++ .../services/seine/TripSeineServiceImpl.java | 41 ++++++++++++++++++ 5 files changed, 218 insertions(+) diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java new file mode 100644 index 0000000..3386194 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java @@ -0,0 +1,50 @@ +package fr.ird.observe.services.seine; + +import fr.ird.observe.entities.seine.ActivitySeine; + +import java.util.List; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ActivitySeineServiceImpl { + + public List<ActivitySeine> loadAllByRouteForDisplay(String routeId) { + List<ActivitySeine> loaded = null; + return loaded; + } + + public ActivitySeine loadForEdit(String activitySeineId) { + ActivitySeine loaded = null; + return loaded; + } + + public ActivitySeine loadForEditObservedSystem(String activitySeineId) { + ActivitySeine loaded = null; + return loaded; + } + + public ActivitySeine preCreate(String routeId) { + ActivitySeine result = null; + return result; + } + + public ActivitySeine create(ActivitySeine toCreate) { + ActivitySeine created = null; + return created; + } + + public void update(ActivitySeine toUpdate) { + } + + public void updateObservedSystem(ActivitySeine toUpdate) { + + } + + public void delete(String activitySeineId) { + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java new file mode 100644 index 0000000..a15b529 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java @@ -0,0 +1,43 @@ +package fr.ird.observe.services.seine; + +import fr.ird.observe.entities.seine.FloatingObject; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class FloatingObjectServiceImpl { + + public FloatingObject loadForEdit(String floatingObjectId) { + FloatingObject loaded = null; + return loaded; + } + + public FloatingObject loadForEditTransmittingBuoy(String floatingObjectId) { + FloatingObject loaded = null; + return loaded; + } + + public FloatingObject preCreate(String routeId) { + FloatingObject result = null; + return result; + } + + public FloatingObject create(FloatingObject toCreate) { + FloatingObject created = null; + return created; + } + + public void update(FloatingObject toUpdate) { + } + + public void updateTransmittingBuoy(FloatingObject toUpdate) { + + } + + public void delete(String floatingObjectId) { + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java new file mode 100644 index 0000000..f75dd75 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java @@ -0,0 +1,41 @@ +package fr.ird.observe.services.seine; + +import fr.ird.observe.entities.seine.Route; + +import java.util.List; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class RouteServiceImpl { + + public List<Route> loadAllByTripForDisplay(String tripSeineId) { + List<Route> loaded = null; + return loaded; + } + + public Route loadForEdit(String routeId) { + Route loaded = null; + return loaded; + } + + public Route preCreate(String tripSeineId) { + Route preCreated = null; + return preCreated; + } + + public Route create(Route toCreate) { + Route created = null; + return created; + } + + public void update(Route toUpdate) { + } + + public void delete(String routeId) { + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java new file mode 100644 index 0000000..d4100d0 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java @@ -0,0 +1,43 @@ +package fr.ird.observe.services.seine; + +import fr.ird.observe.entities.seine.SetSeine; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class SetSeineServiceImpl { + + public SetSeine loadForEdit(String setSeineId) { + SetSeine loaded = null; + return loaded; + } + + public SetSeine loadForEditObservedSystem(String setSeineId) { + SetSeine loaded = null; + return loaded; + } + + public SetSeine preCreate(String routeId) { + SetSeine result = null; + return result; + } + + public SetSeine create(SetSeine toCreate) { + SetSeine created = null; + return created; + } + + public void update(SetSeine toUpdate) { + } + + public void updateObservedSystem(SetSeine toUpdate) { + + } + + public void delete(String setSeineId) { + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java new file mode 100644 index 0000000..e1b5a04 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java @@ -0,0 +1,41 @@ +package fr.ird.observe.services.seine; + +import fr.ird.observe.entities.seine.TripSeine; + +import java.util.List; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TripSeineServiceImpl { + + public List<TripSeine> loadAllByProgramForDisplay(String programId) { + List<TripSeine> loaded = null; + return loaded; + } + + public TripSeine loadForEdit(String tripSeineId) { + TripSeine loaded = null; + return loaded; + } + + public TripSeine preCreate(String programId) { + TripSeine preCreated = null; + return preCreated; + } + + public TripSeine create(TripSeine toCreate) { + TripSeine created = null; + return created; + } + + public void update(TripSeine toUpdate) { + } + + public void delete(String tripSeineId) { + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 8bccff039aae053b3864bd17928ee6b66ee0b86f Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 24 10:05:34 2015 +0200 ajout d'une usine à service + amélioration de l'abstraction (refs #7017) --- .../observe/services/AbstractObserveService.java | 66 +++++++++++----------- .../services/Longline/TripLonglineServiceImp.java | 16 +++++- .../observe/services/ObserveServiceFactory.java | 47 +++++++++++++++ .../services/seine/ActivitySeineServiceImpl.java | 17 +++++- .../services/seine/FloatingObjectServiceImpl.java | 17 +++++- .../observe/services/seine/RouteServiceImpl.java | 17 +++++- .../services/seine/SetSeineServiceImpl.java | 17 +++++- .../services/seine/TripSeineServiceImpl.java | 17 +++++- 8 files changed, 174 insertions(+), 40 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index e41299a..cadd7ac 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -1,8 +1,6 @@ package fr.ird.observe.services; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaDAO; @@ -13,36 +11,40 @@ import org.nuiton.topia.persistence.TopiaEntity; */ public abstract class AbstractObserveService<E extends TopiaEntity> { - protected DataSource dataSource; - - protected Class<E> entityClass; - - protected TopiaDAO<E> dao; - - - public E create(E entity) { - try { - TopiaContext topiaContext = dataSource.beginTransaction("create entity"); - - TopiaDAO<E> dao = ObserveDAOHelper.getDAO(topiaContext, entityClass); - - topiaContext.commitTransaction(); - - } catch (DataSourceException e) { - e.printStackTrace(); - } catch (TopiaException e) { - e.printStackTrace(); - } finally { - - } - - }; - - public abstract void update(E entity); - - public abstract E findById(String id); - - public abstract void delete(E entity); + protected final DataSource dataSource; + + protected final Class<E> entityClass; + + protected abstract TopiaDAO<E> getDao(TopiaContext tx) throws TopiaException; + + protected AbstractObserveService(Class<E> entityClass, DataSource dataSource) { + this.dataSource = dataSource; + this.entityClass = entityClass; + } + +// public E create(E entity) { +// try { +// TopiaContext topiaContext = dataSource.beginTransaction("create entity"); +// +// TopiaDAO<E> dao = ObserveDAOHelper.getDAO(topiaContext, entityClass); +// +// topiaContext.commitTransaction(); +// +// } catch (DataSourceException e) { +// e.printStackTrace(); +// } catch (TopiaException e) { +// e.printStackTrace(); +// } finally { +// +// } +// +// }; +// +// public abstract void update(E entity); +// +// public abstract E findById(String id); +// +// public abstract void delete(E entity); diff --git a/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java b/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java index 1f1c312..1c03529 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java +++ b/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.Longline; import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.TripLonglineDAO; @@ -15,7 +16,16 @@ import org.nuiton.topia.persistence.TopiaDAO; */ public class TripLonglineServiceImp extends AbstractObserveService<TripLongline> { + public TripLonglineServiceImp(DataSource dataSource) { + super(TripLongline.class, dataSource); + } + @Override + protected TopiaDAO<TripLongline> getDao(TopiaContext tx) throws TopiaException { + return ObserveDAOHelper.getTripLonglineDAO(tx); + } + +// @Override public TripLongline create(TripLongline entity) { try { TopiaContext topiaContext = dataSource.beginTransaction("create TripLongline"); @@ -33,7 +43,7 @@ public class TripLonglineServiceImp extends AbstractObserveService<TripLongline> return entity; } - @Override +// @Override public void update(TripLongline entity) { getLoadBinder().copyExcluding(getBean(), beanToSave, TripLongline.PROPERTY_ACTIVITY_LONGLINE); @@ -42,12 +52,12 @@ public class TripLonglineServiceImp extends AbstractObserveService<TripLongline> } - @Override +// @Override public TripLongline findById(String id) { return null; } - @Override +// @Override public void delete(TripLongline entity) { TopiaDAO<TripLongline> dao = getDataSource().getDAO(tx, TripLongline.class); dao.delete(beanToDelete); diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java new file mode 100644 index 0000000..af151ad --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -0,0 +1,47 @@ +package fr.ird.observe.services; + +import com.google.common.base.Preconditions; +import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.event.DataSourceEvent; +import fr.ird.observe.db.event.DataSourceListenerAdapter; +import org.apache.commons.lang3.reflect.ConstructorUtils; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ObserveServiceFactory { + + public static <S> S createService(Class<S> serviceType, DataSource dataSource) { + + Preconditions.checkNotNull(serviceType, "serviceType can't be null"); + Preconditions.checkNotNull(dataSource, "dataSource can't be null"); + + try { + + S service = ConstructorUtils.invokeConstructor(serviceType, dataSource); + + //FIXME On peut ajouter un état au service pour savoir si la dataSource est encore accessible... + dataSource.addDataSourceListener(new DataSourceListenerAdapter() { + @Override + public void onClosed(DataSourceEvent event) { + + } + + @Override + public void onOpened(DataSourceEvent event) { + + } + }); + + return service; + + } catch (Exception e) { + throw new ObserveTechnicalException("Could not create service: " + serviceType, e); + } + + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java index 3386194..05dbef3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java @@ -1,6 +1,12 @@ package fr.ird.observe.services.seine; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; import java.util.List; @@ -10,7 +16,16 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class ActivitySeineServiceImpl { +public class ActivitySeineServiceImpl extends AbstractObserveService<ActivitySeine> { + + public ActivitySeineServiceImpl(DataSource dataSource) { + super(ActivitySeine.class, dataSource); + } + + @Override + protected TopiaDAO<ActivitySeine> getDao(TopiaContext tx) throws TopiaException { + return ObserveDAOHelper.getActivitySeineDAO(tx); + } public List<ActivitySeine> loadAllByRouteForDisplay(String routeId) { List<ActivitySeine> loaded = null; diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java index a15b529..676b33a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java @@ -1,6 +1,12 @@ package fr.ird.observe.services.seine; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; /** * Created on 4/24/15. @@ -8,7 +14,16 @@ import fr.ird.observe.entities.seine.FloatingObject; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class FloatingObjectServiceImpl { +public class FloatingObjectServiceImpl extends AbstractObserveService<FloatingObject> { + + public FloatingObjectServiceImpl(DataSource dataSource) { + super(FloatingObject.class, dataSource); + } + + @Override + protected TopiaDAO<FloatingObject> getDao(TopiaContext tx) throws TopiaException { + return ObserveDAOHelper.getFloatingObjectDAO(tx); + } public FloatingObject loadForEdit(String floatingObjectId) { FloatingObject loaded = null; diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java index f75dd75..5dbbee4 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java @@ -1,6 +1,12 @@ package fr.ird.observe.services.seine; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; import java.util.List; @@ -10,7 +16,16 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class RouteServiceImpl { +public class RouteServiceImpl extends AbstractObserveService<Route> { + + public RouteServiceImpl(DataSource dataSource) { + super(Route.class,dataSource); + } + + @Override + protected TopiaDAO<Route> getDao(TopiaContext tx) throws TopiaException { + return ObserveDAOHelper.getRouteDAO(tx); + } public List<Route> loadAllByTripForDisplay(String tripSeineId) { List<Route> loaded = null; diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java index d4100d0..33208ac 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java @@ -1,6 +1,12 @@ package fr.ird.observe.services.seine; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; /** * Created on 4/24/15. @@ -8,7 +14,16 @@ import fr.ird.observe.entities.seine.SetSeine; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class SetSeineServiceImpl { +public class SetSeineServiceImpl extends AbstractObserveService<SetSeine> { + + public SetSeineServiceImpl(DataSource dataSource) { + super(SetSeine.class, dataSource); + } + + @Override + protected TopiaDAO<SetSeine> getDao(TopiaContext tx) throws TopiaException { + return ObserveDAOHelper.getSetSeineDAO(tx); + } public SetSeine loadForEdit(String setSeineId) { SetSeine loaded = null; diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java index e1b5a04..86035ba 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java @@ -1,6 +1,12 @@ package fr.ird.observe.services.seine; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; import java.util.List; @@ -10,7 +16,16 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class TripSeineServiceImpl { +public class TripSeineServiceImpl extends AbstractObserveService<TripSeine> { + + public TripSeineServiceImpl(DataSource dataSource) { + super(TripSeine.class,dataSource); + } + + @Override + protected TopiaDAO<TripSeine> getDao(TopiaContext tx) throws TopiaException { + return ObserveDAOHelper.getTripSeineDAO(tx); + } public List<TripSeine> loadAllByProgramForDisplay(String programId) { List<TripSeine> loaded = null; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit af4053010d25755bc855f6aa1740cc3f6342c9b9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Apr 26 21:11:27 2015 +0200 ajout de premiers services et d'une usine de services --- .../src/main/java/fr/ird/observe/DataService.java | 3181 ++++++++++---------- .../fr/ird/observe/ObserveApplicationContext.java | 2 +- .../entities/longline/ActivityLonglineDAOImpl.java | 9 + .../entities/seine/ActivitySeineDAOImpl.java | 9 + .../observe/entities/seine/ActivitySeineImpl.java | 15 +- .../ird/observe/entities/seine/RouteDAOImpl.java | 10 + .../observe/services/AbstractObserveService.java | 223 +- .../main/java/fr/ird/observe/services/Commit.java | 19 + .../services/Longline/TripLonglineServiceImp.java | 66 - .../fr/ird/observe/services/NoTransaction.java | 19 + .../fr/ird/observe/services/ObserveService.java | 27 + .../observe/services/ObserveServiceContext.java | 76 + .../observe/services/ObserveServiceFactory.java | 227 +- .../ird/observe/services/data/OpenableService.java | 25 + .../observe/services/data/OpenableServiceImpl.java | 157 + .../fr/ird/observe/services/data/TripService.java | 31 + .../ird/observe/services/data/TripServiceImpl.java | 134 + .../data/longline/ActivityLonglineService.java | 41 + .../data/longline/ActivityLonglineServiceImpl.java | 206 ++ .../data/longline/CatchLonglineService.java | 42 + .../data/longline/CatchLonglineServiceImpl.java | 136 + .../longline/GearUseFeaturesLonglineService.java | 25 + .../GearUseFeaturesLonglineServiceImpl.java | 92 + .../longline/LonglineDetailCompositionService.java | 12 + .../LonglineDetailCompositionServiceImpl.java | 13 + .../services/data/longline/SensorUsedService.java | 37 + .../data/longline/SensorUsedServiceImpl.java | 84 + .../services/data/longline/SetLonglineService.java | 21 + .../data/longline/SetLonglineServiceImpl.java | 71 + .../observe/services/data/longline/TdrService.java | 37 + .../services/data/longline/TdrServiceImpl.java | 83 + .../data/longline/TripLonglineService.java | 42 + .../data/longline/TripLonglineServiceImpl.java | 201 ++ .../services/data/seine/ActivitySeineService.java | 47 + .../data/seine/ActivitySeineServiceImpl.java | 255 ++ .../services/data/seine/FloatingObjectService.java | 38 + .../seine/FloatingObjectServiceImpl.java | 41 +- .../data/seine/GearUseFeaturesSeineService.java | 25 + .../seine/GearUseFeaturesSeineServiceImpl.java | 90 + .../data/seine/NonTargetSampleService.java | 28 + .../data/seine/NonTargetSampleServiceImpl.java | 116 + .../observe/services/data/seine/RouteService.java | 40 + .../services/data/seine/RouteServiceImpl.java | 237 ++ .../services/data/seine/SetSeineService.java | 38 + .../services/data/seine/SetSeineServiceImpl.java | 206 ++ .../services/data/seine/TargetSampleService.java | 30 + .../data/seine/TargetSampleServiceImpl.java | 142 + .../services/data/seine/TripSeineService.java | 42 + .../services/data/seine/TripSeineServiceImpl.java | 203 ++ .../services}/model/DataSelectionModel.java | 24 +- .../services/referential/ReferentialService.java | 32 + .../referential/ReferentialServiceImpl.java | 103 + .../services/seine/ActivitySeineServiceImpl.java | 65 - .../observe/services/seine/RouteServiceImpl.java | 56 - .../services/seine/SetSeineServiceImpl.java | 58 - .../services/seine/TripSeineServiceImpl.java | 56 - .../main/java/fr/ird/observe/ObserveContext.java | 28 +- .../ird/observe/ui/actions/ShowConfigAction.java | 27 +- .../fr/ird/observe/ui/admin/AdminTabUIHandler.java | 2 +- .../java/fr/ird/observe/ui/admin/AdminUIModel.java | 28 +- .../ird/observe/ui/admin/config/SelectDataUI.jaxx | 2 +- .../ui/admin/consolidate/ConsolidateUIHandler.java | 2 +- .../ird/observe/ui/admin/export/ExportModel.java | 2 +- .../observe/ui/admin/export/ExportUIHandler.java | 18 +- .../observe/ui/admin/report/ReportUIHandler.java | 2 +- .../ui/admin/validate/ValidateUIHandler.java | 2 +- .../ird/observe/ui/content/ContentUIHandler.java | 79 +- .../observe/ui/content/ContentUIInitializer.java | 109 +- .../LonglineDetailCompositionUIHandler.java | 76 +- .../LonglineDetailCompositionUIInitializer.java | 6 +- .../ui/content/impl/seine/SetSeineUIHandler.java | 173 +- .../impl/longline/ActivityLonglinesUIHandler.java | 9 +- .../list/impl/longline/TripLonglinesUIHandler.java | 10 +- .../list/impl/seine/ActivitySeinesUIHandler.java | 9 +- .../content/list/impl/seine/RoutesUIHandler.java | 9 +- .../list/impl/seine/TripSeinesUIHandler.java | 11 +- .../ui/content/open/ContentOpenableUIHandler.java | 80 +- .../impl/longline/ActivityLonglineUIHandler.java | 165 +- .../open/impl/longline/TripLonglineUIHandler.java | 152 +- .../open/impl/seine/ActivitySeineUIHandler.java | 188 +- .../ui/content/open/impl/seine/RouteUIHandler.java | 231 +- .../open/impl/seine/TripSeineUIHandler.java | 150 +- .../ui/content/ref/ContentReferenceUIHandler.java | 36 +- .../ui/content/table/ContentTableUIHandler.java | 8 +- .../content/table/ContentTableUIInitializer.java | 11 +- .../impl/longline/CatchLonglineUIHandler.java | 116 +- .../table/impl/longline/CatchLonglineUIModel.java | 34 - .../GearUseFeaturesLonglineTableModel.java | 7 +- .../longline/GearUseFeaturesLonglineUIHandler.java | 43 +- .../table/impl/longline/SensorUsedUIHandler.java | 10 +- .../content/table/impl/longline/TdrUIHandler.java | 12 +- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 45 +- .../table/impl/seine/NonTargetCatchUIHandler.java | 19 +- .../table/impl/seine/NonTargetSampleUIHandler.java | 31 +- .../table/impl/seine/SchoolEstimateUIHandler.java | 8 +- .../table/impl/seine/TargetCatchUIHandler.java | 17 +- .../impl/seine/TargetDiscardCatchUIHandler.java | 21 +- .../table/impl/seine/TargetSampleUIHandler.java | 22 +- .../ird/observe/ui/storage/ObstunaAdminAction.java | 2 +- .../ui/storage/StorageBackupUILauncher.java | 2 +- .../ird/observe/ui/storage/StorageUIHandler.java | 7 +- .../fr/ird/observe/ui/storage/StorageUIModel.java | 2 +- .../ui/storage/tabs/StorageTabUIHandler.java | 3 +- .../ui/tree/AbstractObserveTreeCellRenderer.java | 2 +- .../ird/observe/ui/tree/ActivityLonglineNode.java | 13 +- .../fr/ird/observe/ui/tree/ActivitySeineNode.java | 13 +- .../ui/tree/DataSelectionTreeSelectionModel.java | 2 +- .../fr/ird/observe/ui/tree/EntityNodeSupport.java | 30 +- .../observe/ui/tree/FloatingObjectSeineNode.java | 14 +- .../ird/observe/ui/tree/ObserveDataProvider.java | 41 +- .../tree/ObserveNavigationTreeShowPopupAction.java | 32 +- .../fr/ird/observe/ui/tree/ObserveTreeHelper.java | 63 +- .../ird/observe/ui/tree/ProgramLonglineNode.java | 14 +- .../fr/ird/observe/ui/tree/ProgramSeineNode.java | 13 +- .../fr/ird/observe/ui/tree/RouteSeineNode.java | 14 +- .../fr/ird/observe/ui/tree/SetLonglineNode.java | 14 +- .../java/fr/ird/observe/ui/tree/SetSeineNode.java | 14 +- .../fr/ird/observe/ui/tree/TripLonglineNode.java | 14 +- .../java/fr/ird/observe/ui/tree/TripSeineNode.java | 14 +- .../actions/ChangeTripProgramActionListener.java | 34 +- .../ui/tree/loadors/AbstractNodeChildLoador.java | 11 +- .../loadors/ActivityLonglineNodeChildLoador.java | 12 +- .../loadors/ActivityLonglinesNodeChildLoador.java | 13 +- .../tree/loadors/ActivitySeineNodeChildLoador.java | 18 +- .../loadors/ActivitySeinesNodeChildLoador.java | 12 +- .../loadors/FloatingObjectNodeChildLoador.java | 5 +- .../loadors/ProgramLonglineNodeChildLoador.java | 17 +- .../tree/loadors/ProgramSeineNodeChildLoador.java | 17 +- .../loadors/ReferenceCommonNodeChildLoador.java | 7 +- .../loadors/ReferenceLonglineNodeChildLoador.java | 5 +- .../loadors/ReferenceSeineNodeChildLoador.java | 5 +- .../ui/tree/loadors/RootNodeChildLoador.java | 19 +- .../ui/tree/loadors/RoutesNodeChildLoador.java | 12 +- .../tree/loadors/SetLonglineNodeChildLoador.java | 5 +- .../ui/tree/loadors/SetSeineNodeChildLoador.java | 5 +- .../observe/ui/util/tripMap/TripMapUIHandler.java | 39 +- .../field/VesselActivityFieldValidator.java | 16 +- pom.xml | 2 +- 138 files changed, 6305 insertions(+), 3627 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/DataService.java b/observe-business/src/main/java/fr/ird/observe/DataService.java index 6c13752..aee4dc3 100644 --- a/observe-business/src/main/java/fr/ird/observe/DataService.java +++ b/observe-business/src/main/java/fr/ird/observe/DataService.java @@ -24,7 +24,6 @@ package fr.ird.observe; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; @@ -32,64 +31,12 @@ import fr.ird.observe.db.constants.DataSourceState; import fr.ird.observe.db.util.TopiaExecutor; import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.EntityMap; -import fr.ird.observe.entities.OpenableEntities; -import fr.ird.observe.entities.OpenableEntity; -import fr.ird.observe.entities.Trip; -import fr.ird.observe.entities.constants.GearType; -import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.entities.longline.ActivityLonglineDAO; -import fr.ird.observe.entities.longline.ActivityLonglines; -import fr.ird.observe.entities.longline.Basket; -import fr.ird.observe.entities.longline.Branchline; -import fr.ird.observe.entities.longline.CatchLongline; -import fr.ird.observe.entities.longline.GearUseFeaturesLongline; -import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; -import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLonglineImpl; -import fr.ird.observe.entities.longline.Section; -import fr.ird.observe.entities.longline.SensorUsed; -import fr.ird.observe.entities.longline.SizeMeasure; -import fr.ird.observe.entities.longline.SizeMeasureImpl; -import fr.ird.observe.entities.longline.Tdr; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglineDAO; -import fr.ird.observe.entities.longline.WeightMeasure; -import fr.ird.observe.entities.longline.WeightMeasureImpl; -import fr.ird.observe.entities.referentiel.Gear; -import fr.ird.observe.entities.referentiel.GearCaracteristic; import fr.ird.observe.entities.referentiel.LengthWeightParameter; import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; import fr.ird.observe.entities.referentiel.Ocean; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.referentiel.ProgramDAO; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Sex; import fr.ird.observe.entities.referentiel.Species; -import fr.ird.observe.entities.referentiel.SpeciesList; -import fr.ird.observe.entities.referentiel.SpeciesListDAO; -import fr.ird.observe.entities.referentiel.longline.SensorType; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.ActivitySeineDAO; -import fr.ird.observe.entities.seine.ActivitySeines; -import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.FloatingObjectDAO; -import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; -import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineImpl; -import fr.ird.observe.entities.seine.GearUseFeaturesSeine; -import fr.ird.observe.entities.seine.NonTargetCatch; -import fr.ird.observe.entities.seine.NonTargetLength; -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.RouteDAO; -import fr.ird.observe.entities.seine.Routes; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TargetCatch; -import fr.ird.observe.entities.seine.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.entities.seine.TripSeineDAO; -import fr.ird.observe.tripMap.TripMapPoint; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -101,7 +48,6 @@ import org.nuiton.topia.event.TopiaTransactionListener; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaId; import org.nuiton.topia.persistence.util.DiffState; import org.nuiton.topia.persistence.util.EntityOperator; import org.nuiton.topia.persistence.util.Loador; @@ -112,11 +58,8 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListenerProxy; import java.beans.PropertyChangeSupport; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.EnumSet; import java.util.HashSet; @@ -145,15 +88,15 @@ public class DataService { protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - private boolean skipTransactionListener; +// private boolean skipTransactionListener; private TopiaTransactionListener transactionListener = new TopiaTransactionListener() { public void commit(TopiaTransactionEvent event) { - if (skipTransactionListener) { - return; - } +// if (skipTransactionListener) { +// return; +// } java.util.Set<TopiaEntity> entities = event.getEntities(); @@ -162,7 +105,7 @@ public class DataService { EnumSet.noneOf(ObserveEntityEnum.class); // pour referencer les types openables modifies - boolean touchOpenContext = false; +// boolean touchOpenContext = false; // pour referencer les donnees observers modifiees java.util.Set<TopiaEntity> data = new HashSet<TopiaEntity>(); @@ -217,9 +160,9 @@ public class DataService { // il s'agit d'une donnée utilisateur data.add(entity); - if (OpenableEntities.isOpenable(entity)) { - touchOpenContext = true; - } +// if (OpenableEntities.isOpenable(entity)) { +// touchOpenContext = true; +// } } DataSource source = ObserveServiceHelper.get().getDataSource(); @@ -246,36 +189,35 @@ public class DataService { ); } - if (touchOpenContext) { - fireOpenChanged(source); - } +// if (touchOpenContext) { +// fireOpenChanged(source); +// } } - public void rollback(TopiaTransactionEvent event) { } }; - protected PropertyChangeListener openListener = new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - DataService source = (DataService) evt.getSource(); - DataContext dataContext = source.getDataContext(); - String[] value = (String[]) evt.getNewValue(); - if (log.isDebugEnabled()) { - log.debug("open context changed in data service, will propagate it to " + dataContext); - log.debug("new open ids : " + Arrays.toString(value)); - } - dataContext.populateOpens(value); - } - }; +// protected PropertyChangeListener openListener = new PropertyChangeListener() { +// +// public void propertyChange(PropertyChangeEvent evt) { +// DataService source = (DataService) evt.getSource(); +// DataContext dataContext = source.getDataContext(); +// String[] value = (String[]) evt.getNewValue(); +// if (log.isDebugEnabled()) { +// log.debug("open context changed in data service, will propagate it to " + dataContext); +// log.debug("new open ids : " + Arrays.toString(value)); +// } +// dataContext.populateOpens(value); +// } +// }; public void registerDataSource(DataSource source) { ObserveServiceHelper.get().setDataSource(source); - addPropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); +// addPropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); } @@ -283,7 +225,7 @@ public class DataService { ObserveServiceHelper.get().setDataSource(null); - removePropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); +// removePropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); // remove all listeners for the referentiel //FIXMe tchemit 2010-11-30 Perharps we should remove all listeners ? @@ -367,32 +309,30 @@ public class DataService { // ------------------------------------------------------------------------ - public String[] getOpenIds(DataSource source) throws DataSourceException { - - String[] result = null; - TopiaContext tx = beginTransaction(source, "getOpenIds"); - try { - - result = source.getOpenIds(tx); - } finally { - closeTransaction(source, tx, "getOpenIds"); - } - return result; - } +// public String[] getOpenIds(DataSource source) throws DataSourceException { +// +// String[] result = null; +// TopiaContext tx = beginTransaction(source, "getOpenIds"); +// try { +// +// result = source.getOpenIds(tx); +// } finally { +// closeTransaction(source, tx, "getOpenIds"); +// } +// return result; +// } - public <E extends TopiaEntity> List<E> getList(DataSource source, - Class<E> klass) throws DataSourceException { + public <E extends TopiaEntity> List<E> getList(DataSource source, Class<E> klass) throws DataSourceException { List<E> list = getList(source, klass, null, null); return list; } - - public <E extends TopiaEntity> List<E> getList(DataSource source, Class<E> klass, Predicate<E> predicate) throws DataSourceException { - List<E> result = getList(source, klass, predicate, null); - return result; - } +// public <E extends TopiaEntity> List<E> getList(DataSource source, Class<E> klass, Predicate<E> predicate) throws DataSourceException { +// List<E> result = getList(source, klass, predicate, null); +// return result; +// } public <E extends TopiaEntity> List<E> getList(DataSource source, @@ -441,1262 +381,1251 @@ public class DataService { } } +// public <E extends TopiaEntity> EntityMap findAllUsages(DataSource source, +// E entity) throws DataSourceException { +// +// String txName = "findAllUsages"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaDAO<E> dao; +// dao = source.getDAO(tx, entity); +// +// // always get a fresh version of object +// entity = dao.findByTopiaId(entity.getTopiaId()); +// EntityMap result; +// result = new EntityMap(dao.findAllUsages(entity)); +// if (decoratorService != null) { +// // on charge les entites +// for (Class<? extends TopiaEntity> aClass : result.keySet()) { +// Decorator<? extends TopiaEntity> decorator = +// decoratorService.getDecoratorByType(aClass); +// for (TopiaEntity e : result.get(aClass)) { +// decorator.toString(e); +// } +// } +// } +// return result; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + + +// public <E extends OpenableEntity & TopiaEntity> E getOpen(DataSource source, +// Class<E> klass) throws DataSourceException { +// +// if (!source.canReadData()) { +// if (log.isInfoEnabled()) { +// log.info("Can not read data!"); +// } +// return null; +// } +// String txName = "getOpen"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// E result = source.getOpen(tx, klass); +// if (result != null && klass.equals(TripSeine.class)) { +// ((TripSeine) result).getProgram(); +// } +// return result; +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<Program> getAllProgramStub(DataSource source) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return Collections.emptyList(); +// } +// +// String txName = "getAllProgramStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// List<Program> result = dao.findAllStub(referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// public Program getProgramStub(DataSource source, String programId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "getProgramStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// Program result = dao.findStubByTopiaId(programId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<TripSeine> getTripSeineStubByProgram(DataSource source, String programId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return Collections.emptyList(); +// } +// +// String txName = "getTripSeineStubByProgram"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// List<TripSeine> result = dao.findAllStubByProgramId(programId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// public TripSeine getTripSeineStub(DataSource source, String tripId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "getTripSeineStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// TripSeine result = dao.findStubByTopiaId(tripId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + + +// public List<Route> getRouteStubByTrip(DataSource source, String tripSeineId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return Collections.emptyList(); +// } +// +// String txName = "getRouteStubByTrip"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); +// List<Route> result = dao.findAllStubByTripId(tripSeineId); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// public Route getRouteStub(DataSource source, String routeId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "getRouteStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); +// Route result = dao.findStubByTopiaId(routeId); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<ActivitySeine> getActivitySeineStubByRoute(DataSource source, String routeId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return Collections.emptyList(); +// } +// +// String txName = "getActivitySeineStubByRoute"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// List<ActivitySeine> result = dao.findAllStubByRouteId(routeId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public ActivitySeine getActivitySeineStub(DataSource source, String activityId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "getActivitySeineStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// ActivitySeine result = dao.findStubByTopiaId(activityId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<FloatingObject> getFloatinObjectStubByActivitySeine(DataSource source, String activitySeineId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return Collections.emptyList(); +// } +// +// String txName = "getFloatinObjectStubByActivitySeine"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// List<FloatingObject> result = dao.findAllStubByActivityId(activitySeineId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public FloatingObject getFloatinObjectStub(DataSource source, String floatingObjectId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "getFloatinObjectStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// FloatingObject result = dao.findStubByTopiaId(floatingObjectId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<TripLongline> getTripLonglineStubByProgram(DataSource source, String programId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return Collections.emptyList(); +// } +// +// String txName = "getTripLonglineStubByProgram"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// List<TripLongline> result = dao.findAllStubByProgramId(programId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// +// } + +// public TripLongline getTripLonglineStub(DataSource source, String tripId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "getTripLonglineStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// TripLongline result = dao.findStubByTopiaId(tripId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// +// } + +// public List<ActivityLongline> getActivityLonglineStubByTrip(DataSource source, String tripId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return Collections.emptyList(); +// } +// +// String txName = "getActivityLonglineStubByTrip"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// List<ActivityLongline> result = dao.findAllStubByTripId(tripId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public ActivityLongline getActivityLonglineStub(DataSource source, String activityId) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "getActivityLonglineStub"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); +// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); +// ActivityLongline result = dao.findStubByTopiaId(activityId, referentielLocale); +// return result; +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public Ocean getTripOcean(DataSource source, String tripId) throws DataSourceException { +// +// String txName = "getTripOcean"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); +// TripSeine result = dao.findByTopiaId(tripId); +// return result.getOcean(); +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } - public <E extends TopiaEntity> EntityMap findAllUsages(DataSource source, - E entity) throws DataSourceException { - - String txName = "findAllUsages"; - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<E> dao; - dao = source.getDAO(tx, entity); - - // always get a fresh version of object - entity = dao.findByTopiaId(entity.getTopiaId()); - EntityMap result; - result = new EntityMap(dao.findAllUsages(entity)); - if (decoratorService != null) { - // on charge les entites - for (Class<? extends TopiaEntity> aClass : result.keySet()) { - Decorator<? extends TopiaEntity> decorator = - decoratorService.getDecoratorByType(aClass); - for (TopiaEntity e : result.get(aClass)) { - decorator.toString(e); - } - } - } - return result; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public <E extends OpenableEntity & TopiaEntity> E getOpen(DataSource source, - Class<E> klass) throws DataSourceException { - - if (!source.canReadData()) { - if (log.isInfoEnabled()) { - log.info("Can not read data!"); - } - return null; - } - String txName = "getOpen"; - TopiaContext tx = beginTransaction(source, txName); - try { - E result = source.getOpen(tx, klass); - if (result != null && klass.equals(TripSeine.class)) { - ((TripSeine) result).getProgram(); - } - return result; - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<Program> getAllProgramStub(DataSource source) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return Collections.emptyList(); - } - - String txName = "getAllProgramStub"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - List<Program> result = dao.findAllStub(referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public Program getProgramStub(DataSource source, String programId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return null; - } - - String txName = "getProgramStub"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - Program result = dao.findStubByTopiaId(programId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<TripSeine> getTripSeineStubByProgram(DataSource source, String programId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return Collections.emptyList(); - } - - String txName = "getTripSeineStubByProgram"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - List<TripSeine> result = dao.findAllStubByProgramId(programId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public TripSeine getTripSeineStub(DataSource source, String tripId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return null; - } - - String txName = "getTripSeineStub"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - TripSeine result = dao.findStubByTopiaId(tripId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public List<Route> getRouteStubByTrip(DataSource source, String tripSeineId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return Collections.emptyList(); - } - - String txName = "getRouteStubByTrip"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); - List<Route> result = dao.findAllStubByTripId(tripSeineId); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public Route getRouteStub(DataSource source, String routeId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return null; - } - - String txName = "getRouteStub"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); - Route result = dao.findStubByTopiaId(routeId); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<ActivitySeine> getActivitySeineStubByRoute(DataSource source, String routeId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return Collections.emptyList(); - } - - String txName = "getActivitySeineStubByRoute"; - TopiaContext tx = beginTransaction(source, txName); + /** + * Recherche d'un {@link LengthWeightParameter} à partir des paramètres donnés. + * <p/> + * La recherche peut ne peut être aussi exacte que les paramètres donnés : + * <p/> + * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son + * speciesGroup d'espèce. + * <p/> + * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on + * recherche avec un ocean vide. + * <p/> + * Si non trouvé sur le gender (et que le gender n'est pas indéterminé) , alors + * on recherche avec le gender indéterminé (gender=0). + * + * @param tx la transaction en cours d'utilisation + * @param species l'espèce sur lequel on recherche le paramétrage + * @param ocean l'ocean recherché (peut être null) + * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) + * @param date le jour recherché + * @return le paramétrage adéquate + * @throws DataSourceException pour toute erreur + * @since 1.5 + */ + public <P extends LengthWeightParameter> P findLengthWeightParameter( + TopiaContext tx, + Species species, + Ocean ocean, + Sex sex, + Date date) throws DataSourceException { try { - ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - List<ActivitySeine> result = dao.findAllStubByRouteId(routeId, referentielLocale); - return result; + List<P> list = LengthWeightParemeterHelper.findBySpecies( + (TopiaContextImplementor) tx, + species + ); - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } + if (CollectionUtils.isEmpty(list)) { - public ActivitySeine getActivitySeineStub(DataSource source, String activityId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); + // aucun parametrage pour le type donne + return null; } - return null; - } - - String txName = "getActivitySeineStub"; - TopiaContext tx = beginTransaction(source, txName); - - try { - ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - ActivitySeine result = dao.findStubByTopiaId(activityId, referentielLocale); - return result; + // filtrage par ocean + list = LengthWeightParemeterHelper.filterByOcean(list, ocean); - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } + if (CollectionUtils.isEmpty(list) && ocean != null) { - public List<FloatingObject> getFloatinObjectStubByActivitySeine(DataSource source, String activitySeineId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); + // filtre par ocean null + list = LengthWeightParemeterHelper.filterByOcean(list, null); } - return Collections.emptyList(); - } - - String txName = "getFloatinObjectStubByActivitySeine"; - TopiaContext tx = beginTransaction(source, txName); - try { - - FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - List<FloatingObject> result = dao.findAllStubByActivityId(activitySeineId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } + if (CollectionUtils.isEmpty(list)) { - public FloatingObject getFloatinObjectStub(DataSource source, String floatingObjectId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); + // pas d'ocean adequate + return null; } - return null; - } - - String txName = "getFloatinObjectStub"; - TopiaContext tx = beginTransaction(source, txName); - try { + // filtrage par sexe + list = LengthWeightParemeterHelper.filterBySexe(list, sex); - FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - FloatingObject result = dao.findStubByTopiaId(floatingObjectId, referentielLocale); - return result; + if (CollectionUtils.isEmpty(list)) { - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } + Sex unkwonSex = ObserveDAOHelper.getSexDAO(tx).findByCode("0"); - public List<TripLongline> getTripLonglineStubByProgram(DataSource source, String programId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return Collections.emptyList(); - } - - String txName = "getTripLonglineStubByProgram"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - List<TripLongline> result = dao.findAllStubByProgramId(programId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - - } - - public TripLongline getTripLonglineStub(DataSource source, String tripId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return null; - } - - String txName = "getTripLonglineStub"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - TripLongline result = dao.findStubByTopiaId(tripId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - - } - - public List<ActivityLongline> getActivityLonglineStubByTrip(DataSource source, String tripId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return Collections.emptyList(); - } - - String txName = "getActivityLonglineStubByTrip"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - List<ActivityLongline> result = dao.findAllStubByTripId(tripId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public ActivityLongline getActivityLonglineStub(DataSource source, String activityId) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return null; - } - - String txName = "getActivityLonglineStub"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); - ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); - ActivityLongline result = dao.findStubByTopiaId(activityId, referentielLocale); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public Ocean getTripOcean(DataSource source, String tripId) throws DataSourceException { - - String txName = "getTripOcean"; - TopiaContext tx = beginTransaction(source, txName); - try { - TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); - TripSeine result = dao.findByTopiaId(tripId); - return result.getOcean(); - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - /** - * Recherche d'un {@link LengthWeightParameter} à partir des paramètres donnés. - * <p/> - * La recherche peut ne peut être aussi exacte que les paramètres donnés : - * <p/> - * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son - * speciesGroup d'espèce. - * <p/> - * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on - * recherche avec un ocean vide. - * <p/> - * Si non trouvé sur le gender (et que le gender n'est pas indéterminé) , alors - * on recherche avec le gender indéterminé (gender=0). - * - * @param tx la transaction en cours d'utilisation - * @param species l'espèce sur lequel on recherche le paramétrage - * @param ocean l'ocean recherché (peut être null) - * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) - * @param date le jour recherché - * @return le paramétrage adéquate - * @throws DataSourceException pour toute erreur - * @since 1.5 - */ - public <P extends LengthWeightParameter> P findLengthWeightParameter( - TopiaContext tx, - Species species, - Ocean ocean, - Sex sex, - Date date) throws DataSourceException { - - try { - - List<P> list = LengthWeightParemeterHelper.findBySpecies( - (TopiaContextImplementor) tx, - species - ); - - if (CollectionUtils.isEmpty(list)) { - - // aucun parametrage pour le type donne - return null; - } - - // filtrage par ocean - list = LengthWeightParemeterHelper.filterByOcean(list, ocean); - - if (CollectionUtils.isEmpty(list) && ocean != null) { - - // filtre par ocean null - list = LengthWeightParemeterHelper.filterByOcean(list, null); - } - - if (CollectionUtils.isEmpty(list)) { - - // pas d'ocean adequate - return null; - } - - // filtrage par sexe - list = LengthWeightParemeterHelper.filterBySexe(list, sex); - - if (CollectionUtils.isEmpty(list)) { - - Sex unkwonSex = getUnknownSex(tx); - - if (unkwonSex.equals(sex)) { + if (unkwonSex.equals(sex)) { // filtrage par sexe indetermine list = LengthWeightParemeterHelper.filterBySexe(list, unkwonSex); - } - - - } - - if (CollectionUtils.isEmpty(list)) { - - // pas de sexe adequate - return null; - } - - // filtrage par startDate de validite - list = LengthWeightParemeterHelper.filterByDateDebutValidite(list, - date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de debut adequate - return null; - } - - // filtrage par endDate de validite - list = LengthWeightParemeterHelper.filterByDateFinValidite(list, - date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de fin adequate - return null; - } - - // au final il ne devrait en rester qu'un - - if (list.size() > 1) { - StringBuilder sb = new StringBuilder("Il existe plusieurs paramétrages possibles pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(getDecoratorService().decorate(species)); - sb.append("\nOcean : "); - sb.append(getDecoratorService().decorate(ocean)); - sb.append("\nSex : "); - sb.append(getDecoratorService().decorate(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrages trouvés : "); - for (P p : list) { - sb.append("\n - ").append(getDecoratorService().decorate(p)); - } - throw new DataSourceException(sb.toString(), "findLengthWeightParameter"); - } - - P result = list.get(0); - if (log.isDebugEnabled()) { - StringBuilder sb = new StringBuilder("Paramétrage trouvé pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(getDecoratorService().decorate(species)); - sb.append("\nOcean : "); - sb.append(getDecoratorService().decorate(ocean)); - sb.append("\nSex : "); - sb.append(getDecoratorService().decorate(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrage: ").append(getDecoratorService().decorate(result)); - log.debug(sb.toString()); - } - return result; - - } catch (Exception e) { - throw new DataSourceException(e, "findLengthWeightParameter"); - } - } - - protected Sex getUnknownSex(TopiaContext tx) throws TopiaException { - return ObserveDAOHelper.getSexDAO(tx).findByCode("0"); - } - - public int getOpenablePosition(DataSource source, - String containerId, - String childId) throws DataSourceException { - if (childId.startsWith(TripSeine.class.getName())) { - return getTripSeinePosition(source, containerId, childId); - } - if (childId.startsWith(TripLongline.class.getName())) { - return getTripLonglinePosition(source, containerId, childId); - } - if (childId.startsWith(Route.class.getName())) { - return getRoutePosition(source, containerId, childId); - } - if (childId.startsWith(ActivitySeine.class.getName())) { - return getActivitySeinePosition(source, containerId, childId); - } - if (childId.startsWith(ActivityLongline.class.getName())) { - return getActivityLonglinePosition(source, containerId, childId); - } - throw new IllegalStateException("Can not come here!"); - } - - protected int getTripSeinePosition(DataSource source, - String programId, - String tripId) throws DataSourceException { - - String txName = "getTripSeinePosition [" + tripId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); - int pos = dao.findPositionByProgramId(programId, tripId); - return pos; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - protected int getTripLonglinePosition(DataSource source, - String programId, - String tripId) throws DataSourceException { - - String txName = "getTripLonglinePosition [" + tripId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); - int pos = dao.findPositionByProgramId(programId, tripId); - return pos; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - protected int getRoutePosition(DataSource source, - String tripId, - String routeId) throws DataSourceException { - - String txName = "getRoutePosition [" + tripId + "/" + routeId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - TripSeine maree = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); - Route route = maree.getRouteByTopiaId(routeId); - List<Route> routes = maree.getRoute(); - Routes.sort(routes); - return routes.indexOf(route); - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - protected int getActivitySeinePosition(DataSource source, - String routeId, - String activityId) throws DataSourceException { - - String txName = "getActivitySeinePosition [" + routeId + "/" + activityId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - Route route = source.getDAO(tx, Route.class).findByTopiaId(routeId); - ActivitySeine activitySeine = route.getActivitySeineByTopiaId(activityId); - List<ActivitySeine> activitySeines = route.getActivitySeine(); - ActivitySeines.sort(activitySeines); - return activitySeines.indexOf(activitySeine); - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - protected int getActivityLonglinePosition(DataSource source, - String tripId, - String activityId) throws DataSourceException { - - String txName = "getActivityLonglinePosition [" + tripId + "/" + activityId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - TripLongline trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); - ActivityLongline activity = trip.getActivityLonglineByTopiaId(activityId); - List<ActivityLongline> activities = trip.getActivityLongline(); - ActivityLonglines.sort(activities); - return activities.indexOf(activity); - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public String getTargetSampleId(DataSource source, - String setId, - boolean discarded) throws DataSourceException { - - String txName = "getTargetSampleId [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - List<TargetSample> list = set.getTargetSample(); - if (list == null || list.isEmpty()) { - return null; - } - for (TargetSample targetSample : list) { - if (discarded) { - if (targetSample.getDiscarded() != null && - targetSample.getDiscarded()) { - return targetSample.getTopiaId(); - } - } else if (targetSample.getDiscarded() == null || - !targetSample.getDiscarded()) { - return targetSample.getTopiaId(); - } - } - return null; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public String getNonTargetSampleId(DataSource source, - String setId) throws DataSourceException { - - String txName = "getNonTargetSampleId [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - List<NonTargetSample> list = set.getNonTargetSample(); - if (list == null || list.isEmpty()) { - return null; - } - return list.get(0).getTopiaId(); - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public List<Species> getAvailableEspeceForTargetSample(DataSource source, - String setId, - boolean discarded) throws DataSourceException { - - String txName = "getAvailableEspeceForTargetSample [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - List<Species> speciess = new ArrayList<Species>(); - - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - - // on recupere la liste des species thon utilisees dans le rejet - Collection<TargetCatch> discardeds = set.getTargetCatch(); - - // on filtre sur les speciess monté sur le pont et rejetée - - if (discardeds != null) { - for (TargetCatch discardedt : discardeds) { - boolean keep; - - if (discarded) { - - // on ne conserve que les speciess des discardeds montees sur le pont et discardedes - keep = discardedt.isDiscarded() && discardedt.getBroughtOnDeck(); - - } else { - - // on ne conserve que les species des discardeds - keep = !discardedt.isDiscarded(); - } - - if (keep && - !speciess.contains(discardedt.getWeightCategory().getSpecies())) { - speciess.add(discardedt.getWeightCategory().getSpecies()); - } - } - } - return speciess; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public List<Species> getAvailableEspeceForNonTargetSample(DataSource source, - String setId) throws DataSourceException { - - String txName = "getAvailableEspeceForNonTargetSample [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - List<Species> speciess = new ArrayList<Species>(); - - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - - // on recupere la liste des species faune utilisees dans le rejet - Collection<NonTargetCatch> discardeds = set.getNonTargetCatch(); - - if (discardeds != null) { - for (NonTargetCatch discarded : discardeds) { - // on retient toute les speciess (capturées ou rejetées) - if (!speciess.contains(discarded.getSpecies())) { - speciess.add(discarded.getSpecies()); - } - } - } - - return speciess; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<Section> getSections(DataSource source, String setLonglineId) throws DataSourceException { - String txName = "getSections [" + setLonglineId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - TopiaDAO<Section> dao = source.getDAO(tx, Section.class); - - List<Section> sections = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); - - if (!sections.isEmpty()) { - - Decorator<Section> sectionDecorator = getDecoratorService().getDecoratorByType(Section.class); - Decorator<Basket> basketDecorator = getDecoratorService().getDecoratorByType(Basket.class); - Decorator<Branchline> branchlineDecorator = getDecoratorService().getDecoratorByType(Branchline.class); - - for (Section section : sections) { - - sectionDecorator.toString(section); - - if (!section.isBasketEmpty()) { - - for (Basket basket : section.getBasket()) { - - basketDecorator.toString(basket); - - if (!basket.isBranchlineEmpty()) { - - for (Branchline branchline : basket.getBranchline()) { - - branchlineDecorator.toString(branchline); - - } - } - - } - } - } - } - - return sections; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - - } - - - public List<Species> loadDecoratedSpecies(DataSource source, String speciesListCode) throws DataSourceException { - String txName = "loadDecoratedSpecies [" + speciesListCode + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - List<Species> speciess = new ArrayList<Species>(); - - SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); - SpeciesList speciesList = dao.findByTopiaId(speciesListCode); - - speciess.addAll(speciesList.getSpecies()); - - Decorator<Species> decorator = getDecoratorService().getDecoratorByType(Species.class); - - for (Species species : speciess) { - decorator.toString(species); - } - - return speciess; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public java.util.Set<String> getSpeciesListSpeciesIds(DataSource source, String speciesListId) throws DataSourceException { - String txName = "getSpeciesListSpeciesIds [" + speciesListId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - - SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); - SpeciesList speciesList = dao.findByTopiaId(speciesListId); - - java.util.Set<String> ids = - Sets.newHashSet( - TopiaEntityHelper.getTopiaIdList( - speciesList.getSpecies())); - - return ids; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public boolean canUseNonTargetSample(DataSource source, - String setId) throws DataSourceException { - - String txName = "canUseNonTargetSample [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - - return set.canUseNonTargetSample(); - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public boolean canUseTargetSample(DataSource source, - String setId, - boolean discarded) throws DataSourceException { - - String txName = "canUseTargetSample [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - - return set.canUseTargetSample(discarded); - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public void getObsoleteEspeceForNonTargetSample(DataSource source, - String setId, - List<Species> speciessUsed, - Collection<Species> speciessToDelete, - List<NonTargetLength> tailleToDelete) throws DataSourceException { - - String txName = "getObsoleteEspeceForNonTargetSample [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - - - if (set.isNonTargetSampleEmpty()) { - return; - } - - NonTargetSample echantillon = set.getNonTargetSample().get(0); - - if (echantillon.isNonTargetLengthEmpty()) { - return; - } - - for (NonTargetLength taille : echantillon.getNonTargetLength()) { - Species tailleEspece = taille.getSpecies(); - if (!speciessUsed.contains(tailleEspece)) { - // l'species n'existe plus dans les rejet faune, - // on doit le supprimer - tailleToDelete.add(taille); - speciessToDelete.add(tailleEspece); - if (log.isDebugEnabled()) { - log.debug("remove obsolote echantillon " + taille + - " for species " + tailleEspece); - } - } - } - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - - } - - - public void getObsoleteEspeceForTargetSample(DataSource source, - String setId, - Collection<Species> speciessUsed, - Collection<Species> speciessToDelete, - List<TargetLength> tailleToDelete, boolean discarded) throws DataSourceException { - - String txName = "getObsoleteEspeceForTargetSample [" + setId + "]"; - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); - SetSeine set = dao.findByTopiaId(setId); - - if (set.isTargetSampleEmpty()) { - return; - } - - TargetSample echantillon = set.getTargetSample(discarded); - - if (echantillon == null || echantillon.isTargetLengthEmpty()) { - return; - } - - for (TargetLength taille : echantillon.getTargetLength()) { - Species tailleEspece = taille.getSpecies(); - if (!speciessUsed.contains(tailleEspece)) { - // l'species n'existe plus dans les rejet faune, - // on doit le supprimer - tailleToDelete.add(taille); - speciessToDelete.add(tailleEspece); - if (log.isDebugEnabled()) { - log.debug("remove obsolote echantillon " + taille + - " for species " + tailleEspece); - } - } - } - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<Program> getPossibleProgramsForTrip(DataSource source, String tripId) throws DataSourceException { - - final GearType gearType; - - String txName = "getPossibleProgramsForTrip : " + tripId; - TopiaContext tx = beginTransaction(source, txName); - try { - - Trip trip; - - if (tripId.contains(TripSeine.class.getSimpleName())) { - trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); - } else { - trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); - } - - gearType = trip.getProgram().getGearType(); - - ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); - - List<Program> programs = dao.findAllByGearType(gearType); - - for (Program program : programs) { - decoratorService.decorate(program); - } - - return programs; - - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - - } - - public void moveTripToProgram(DataSource source, String tripId, String programId) throws DataSourceException { - - String txName = "moveTripToProgram : " + tripId + " :: " + programId; - TopiaContext tx = beginTransaction(source, txName); - try { - - Trip trip; - - if (tripId.contains(TripSeine.class.getSimpleName())) { - trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); - } else { - trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); - } - - ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); - - Program program = dao.findByTopiaId(programId); - - trip.setProgram(program); - - tx.commitTransaction(); - - if (trip.isOpen()) { - - // refresh the dataContext - dataContext.setOpenProgramId(programId); - - } - - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - - } - - public List<SizeMeasure> getCatchLonglineSizeMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<SizeMeasure> binder) throws DataSourceException { - - String txName = "getSections : " + bean.getTopiaId(); - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); - CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); - List<SizeMeasure> result = new ArrayList<SizeMeasure>(); - for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { - SizeMeasure target = new SizeMeasureImpl(); - binder.load(sizeSource, target, true); - result.add(target); - } - return result; - - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<WeightMeasure> getCatchLonglineWeightMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<WeightMeasure> binder) throws DataSourceException { - - String txName = "getSections : " + bean.getTopiaId(); - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); - CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); - List<WeightMeasure> result = new ArrayList<WeightMeasure>(); - for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { - WeightMeasure target = new WeightMeasureImpl(); - binder.load(weightSource, target, true); - result.add(target); - } - return result; - - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } + } - public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(DataSource source, String gearId) throws DataSourceException { - String txName = "getDefaultGearUseFeaturesMeasurementSeine : " + gearId; - TopiaContext tx = beginTransaction(source, txName); - try { + } - TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); - Gear gear = gearDao.findByTopiaId(gearId); + if (CollectionUtils.isEmpty(list)) { - Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); - List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - for (GearCaracteristic caracteristic : gearCaracteristic) { - GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); - target.setGearCaracteristic(caracteristic); - result.add(target); + // pas de sexe adequate + return null; } - return result; - - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } + // filtrage par startDate de validite + list = LengthWeightParemeterHelper.filterByDateDebutValidite(list, + date); - public List<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeine(DataSource source, GearUseFeaturesSeine bean, final TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder) throws DataSourceException { + if (CollectionUtils.isEmpty(list)) { - String txName = "getGearUseFeaturesMeasurementSeine : " + bean.getTopiaId(); - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<GearUseFeaturesSeine> dao = source.getDAO(tx, GearUseFeaturesSeine.class); - GearUseFeaturesSeine gearUseFeaturesSeine = dao.findByTopiaId(bean.getTopiaId()); - List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { - GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); + // pas de date de debut adequate + return null; } - return result; - - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(DataSource source, String gearId) throws DataSourceException { - String txName = "getDefaultGearUseFeaturesMeasurementLongline : " + gearId; - TopiaContext tx = beginTransaction(source, txName); - try { + // filtrage par endDate de validite + list = LengthWeightParemeterHelper.filterByDateFinValidite(list, + date); - TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); - Gear gear = gearDao.findByTopiaId(gearId); + if (CollectionUtils.isEmpty(list)) { - Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); - List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - for (GearCaracteristic caracteristic : gearCaracteristic) { - GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); - target.setGearCaracteristic(caracteristic); - result.add(target); + // pas de date de fin adequate + return null; } - return result; + // au final il ne devrait en rester qu'un - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - public List<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLongline(DataSource source, GearUseFeaturesLongline bean, final TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder) throws DataSourceException { + if (list.size() > 1) { + StringBuilder sb = new StringBuilder("Il existe plusieurs paramétrages possibles pour les données suivantes :"); + sb.append("\nEspece : "); + sb.append(getDecoratorService().decorate(species)); + sb.append("\nOcean : "); + sb.append(getDecoratorService().decorate(ocean)); + sb.append("\nSex : "); + sb.append(getDecoratorService().decorate(sex)); + sb.append("\nDate : ").append(date); + sb.append("\nParamétrages trouvés : "); + for (P p : list) { + sb.append("\n - ").append(getDecoratorService().decorate(p)); + } + throw new DataSourceException(sb.toString(), "findLengthWeightParameter"); + } - String txName = "getGearUseFeaturesMeasurementLongline : " + bean.getTopiaId(); - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<GearUseFeaturesLongline> dao = source.getDAO(tx, GearUseFeaturesLongline.class); - GearUseFeaturesLongline gearUseFeaturesLongline = dao.findByTopiaId(bean.getTopiaId()); - List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { - GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); + P result = list.get(0); + if (log.isDebugEnabled()) { + StringBuilder sb = new StringBuilder("Paramétrage trouvé pour les données suivantes :"); + sb.append("\nEspece : "); + sb.append(getDecoratorService().decorate(species)); + sb.append("\nOcean : "); + sb.append(getDecoratorService().decorate(ocean)); + sb.append("\nSex : "); + sb.append(getDecoratorService().decorate(sex)); + sb.append("\nDate : ").append(date); + sb.append("\nParamétrage: ").append(getDecoratorService().decorate(result)); + log.debug(sb.toString()); } return result; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); + } catch (Exception e) { + throw new DataSourceException(e, "findLengthWeightParameter"); } } - public <E extends TopiaEntity> List<String> getEntityIds(DataSource source, - Class<E> refClass) +// protected Sex getUnknownSex(TopiaContext tx) throws TopiaException { +// return ObserveDAOHelper.getSexDAO(tx).findByCode("0"); +// } + +// public int getOpenablePosition(DataSource source, +// String containerId, +// String childId) throws DataSourceException { +// if (childId.startsWith(TripSeine.class.getName())) { +// return getTripSeinePosition(source, containerId, childId); +// } +// if (childId.startsWith(TripLongline.class.getName())) { +// return getTripLonglinePosition(source, containerId, childId); +// } +// if (childId.startsWith(Route.class.getName())) { +// return getRoutePosition(source, containerId, childId); +// } +// if (childId.startsWith(ActivitySeine.class.getName())) { +// return getActivitySeinePosition(source, containerId, childId); +// } +// if (childId.startsWith(ActivityLongline.class.getName())) { +// return getActivityLonglinePosition(source, containerId, childId); +// } +// throw new IllegalStateException("Can not come here!"); +// } + +// protected int getTripSeinePosition(DataSource source, +// String programId, +// String tripId) throws DataSourceException { +// +// String txName = "getTripSeinePosition [" + tripId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); +// int pos = dao.findPositionByProgramId(programId, tripId); +// return pos; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// protected int getTripLonglinePosition(DataSource source, +// String programId, +// String tripId) throws DataSourceException { +// +// String txName = "getTripLonglinePosition [" + tripId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); +// int pos = dao.findPositionByProgramId(programId, tripId); +// return pos; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// protected int getRoutePosition(DataSource source, +// String tripId, +// String routeId) throws DataSourceException { +// +// String txName = "getRoutePosition [" + tripId + "/" + routeId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TripSeine maree = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); +// Route route = maree.getRouteByTopiaId(routeId); +// List<Route> routes = maree.getRoute(); +// Routes.sort(routes); +// return routes.indexOf(route); +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// protected int getActivitySeinePosition(DataSource source, +// String routeId, +// String activityId) throws DataSourceException { +// +// String txName = "getActivitySeinePosition [" + routeId + "/" + activityId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// Route route = source.getDAO(tx, Route.class).findByTopiaId(routeId); +// ActivitySeine activitySeine = route.getActivitySeineByTopiaId(activityId); +// List<ActivitySeine> activitySeines = route.getActivitySeine(); +// ActivitySeines.sort(activitySeines); +// return activitySeines.indexOf(activitySeine); +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// protected int getActivityLonglinePosition(DataSource source, +// String tripId, +// String activityId) throws DataSourceException { +// +// String txName = "getActivityLonglinePosition [" + tripId + "/" + activityId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TripLongline trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); +// ActivityLongline activity = trip.getActivityLonglineByTopiaId(activityId); +// List<ActivityLongline> activities = trip.getActivityLongline(); +// ActivityLonglines.sort(activities); +// return activities.indexOf(activity); +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public String getTargetSampleId(DataSource source, +// String setId, +// boolean discarded) throws DataSourceException { +// +// String txName = "getTargetSampleId [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// List<TargetSample> list = set.getTargetSample(); +// if (list == null || list.isEmpty()) { +// return null; +// } +// for (TargetSample targetSample : list) { +// if (discarded) { +// if (targetSample.getDiscarded() != null && +// targetSample.getDiscarded()) { +// return targetSample.getTopiaId(); +// } +// } else if (targetSample.getDiscarded() == null || +// !targetSample.getDiscarded()) { +// return targetSample.getTopiaId(); +// } +// } +// return null; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public String getNonTargetSampleId(DataSource source, +// String setId) throws DataSourceException { +// +// String txName = "getNonTargetSampleId [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// List<NonTargetSample> list = set.getNonTargetSample(); +// if (list == null || list.isEmpty()) { +// return null; +// } +// return list.get(0).getTopiaId(); +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<Species> getAvailableEspeceForTargetSample(DataSource source, +// String setId, +// boolean discarded) throws DataSourceException { +// +// String txName = "getAvailableEspeceForTargetSample [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// List<Species> speciess = new ArrayList<Species>(); +// +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// +// // on recupere la liste des species thon utilisees dans le rejet +// Collection<TargetCatch> discardeds = set.getTargetCatch(); +// +// // on filtre sur les speciess monté sur le pont et rejetée +// +// if (discardeds != null) { +// for (TargetCatch discardedt : discardeds) { +// boolean keep; +// +// if (discarded) { +// +// // on ne conserve que les speciess des discardeds montees sur le pont et discardedes +// keep = discardedt.isDiscarded() && discardedt.getBroughtOnDeck(); +// +// } else { +// +// // on ne conserve que les species des discardeds +// keep = !discardedt.isDiscarded(); +// } +// +// if (keep && +// !speciess.contains(discardedt.getWeightCategory().getSpecies())) { +// speciess.add(discardedt.getWeightCategory().getSpecies()); +// } +// } +// } +// return speciess; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<Species> getAvailableEspeceForNonTargetSample(DataSource source, +// String setId) throws DataSourceException { +// +// String txName = "getAvailableEspeceForNonTargetSample [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// List<Species> speciess = new ArrayList<Species>(); +// +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// +// // on recupere la liste des species faune utilisees dans le rejet +// Collection<NonTargetCatch> discardeds = set.getNonTargetCatch(); +// +// if (discardeds != null) { +// for (NonTargetCatch discarded : discardeds) { +// // on retient toute les speciess (capturées ou rejetées) +// if (!speciess.contains(discarded.getSpecies())) { +// speciess.add(discarded.getSpecies()); +// } +// } +// } +// +// return speciess; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<Section> getSections(DataSource source, String setLonglineId) throws DataSourceException { +// String txName = "getSections [" + setLonglineId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// TopiaDAO<Section> dao = source.getDAO(tx, Section.class); +// +// List<Section> sections = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); +// +// if (!sections.isEmpty()) { +// +// Decorator<Section> sectionDecorator = getDecoratorService().getDecoratorByType(Section.class); +// Decorator<Basket> basketDecorator = getDecoratorService().getDecoratorByType(Basket.class); +// Decorator<Branchline> branchlineDecorator = getDecoratorService().getDecoratorByType(Branchline.class); +// +// for (Section section : sections) { +// +// sectionDecorator.toString(section); +// +// if (!section.isBasketEmpty()) { +// +// for (Basket basket : section.getBasket()) { +// +// basketDecorator.toString(basket); +// +// if (!basket.isBranchlineEmpty()) { +// +// for (Branchline branchline : basket.getBranchline()) { +// +// branchlineDecorator.toString(branchline); +// +// } +// } +// +// } +// } +// } +// } +// +// return sections; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// +// } + +// public List<Species> loadDecoratedSpecies(DataSource source, String speciesListCode) throws DataSourceException { +// String txName = "loadDecoratedSpecies [" + speciesListCode + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// List<Species> speciess = new ArrayList<Species>(); +// +// SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); +// SpeciesList speciesList = dao.findByTopiaId(speciesListCode); +// +// speciess.addAll(speciesList.getSpecies()); +// +// Decorator<Species> decorator = getDecoratorService().getDecoratorByType(Species.class); +// +// for (Species species : speciess) { +// decorator.toString(species); +// } +// +// return speciess; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + + +// public java.util.Set<String> getSpeciesListSpeciesIds(DataSource source, String speciesListId) throws DataSourceException { +// String txName = "getSpeciesListSpeciesIds [" + speciesListId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// +// SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); +// SpeciesList speciesList = dao.findByTopiaId(speciesListId); +// +// java.util.Set<String> ids = +// Sets.newHashSet( +// TopiaEntityHelper.getTopiaIdList( +// speciesList.getSpecies())); +// +// return ids; +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public boolean canUseNonTargetSample(DataSource source, +// String setId) throws DataSourceException { +// +// String txName = "canUseNonTargetSample [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// +// return set.canUseNonTargetSample(); +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public boolean canUseTargetSample(DataSource source, +// String setId, +// boolean discarded) throws DataSourceException { +// +// String txName = "canUseTargetSample [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// +// return set.canUseTargetSample(discarded); +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public void getObsoleteEspeceForNonTargetSample(DataSource source, +// String setId, +// List<Species> speciessUsed, +// Collection<Species> speciessToDelete, +// List<NonTargetLength> tailleToDelete) throws DataSourceException { +// +// String txName = "getObsoleteEspeceForNonTargetSample [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// +// +// if (set.isNonTargetSampleEmpty()) { +// return; +// } +// +// NonTargetSample echantillon = set.getNonTargetSample().get(0); +// +// if (echantillon.isNonTargetLengthEmpty()) { +// return; +// } +// +// for (NonTargetLength taille : echantillon.getNonTargetLength()) { +// Species tailleEspece = taille.getSpecies(); +// if (!speciessUsed.contains(tailleEspece)) { +// // l'species n'existe plus dans les rejet faune, +// // on doit le supprimer +// tailleToDelete.add(taille); +// speciessToDelete.add(tailleEspece); +// if (log.isDebugEnabled()) { +// log.debug("remove obsolote echantillon " + taille + +// " for species " + tailleEspece); +// } +// } +// } +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// +// } + +// public void getObsoleteEspeceForTargetSample(DataSource source, +// String setId, +// Collection<Species> speciessUsed, +// Collection<Species> speciessToDelete, +// List<TargetLength> tailleToDelete, boolean discarded) throws DataSourceException { +// +// String txName = "getObsoleteEspeceForTargetSample [" + setId + "]"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); +// SetSeine set = dao.findByTopiaId(setId); +// +// if (set.isTargetSampleEmpty()) { +// return; +// } +// +// TargetSample echantillon = set.getTargetSample(discarded); +// +// if (echantillon == null || echantillon.isTargetLengthEmpty()) { +// return; +// } +// +// for (TargetLength taille : echantillon.getTargetLength()) { +// Species tailleEspece = taille.getSpecies(); +// if (!speciessUsed.contains(tailleEspece)) { +// // l'species n'existe plus dans les rejet faune, +// // on doit le supprimer +// tailleToDelete.add(taille); +// speciessToDelete.add(tailleEspece); +// if (log.isDebugEnabled()) { +// log.debug("remove obsolote echantillon " + taille + +// " for species " + tailleEspece); +// } +// } +// } +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<Program> getPossibleProgramsForTrip(DataSource source, String tripId) throws DataSourceException { +// +// final GearType gearType; +// +// String txName = "getPossibleProgramsForTrip : " + tripId; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// Trip trip; +// +// if (tripId.contains(TripSeine.class.getSimpleName())) { +// trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); +// } else { +// trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); +// } +// +// gearType = trip.getProgram().getGearType(); +// +// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); +// +// List<Program> programs = dao.findAllByGearType(gearType); +// +// for (Program program : programs) { +// decoratorService.decorate(program); +// } +// +// return programs; +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// +// } + +// public void moveTripToProgram(DataSource source, String tripId, String programId) throws DataSourceException { +// +// String txName = "moveTripToProgram : " + tripId + " :: " + programId; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// Trip trip; +// +// if (tripId.contains(TripSeine.class.getSimpleName())) { +// trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); +// } else { +// trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); +// } +// +// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); +// +// Program program = dao.findByTopiaId(programId); +// +// trip.setProgram(program); +// +// tx.commitTransaction(); +// +// if (trip.isOpen()) { +// +// // refresh the dataContext +// dataContext.setOpenProgramId(programId); +// +// } +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// +// } + +// public List<SizeMeasure> getCatchLonglineSizeMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<SizeMeasure> binder) throws DataSourceException { +// +// String txName = "getSections : " + bean.getTopiaId(); +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); +// CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); +// List<SizeMeasure> result = new ArrayList<SizeMeasure>(); +// for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { +// SizeMeasure target = new SizeMeasureImpl(); +// binder.load(sizeSource, target, true); +// result.add(target); +// } +// return result; +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } +// +// public List<WeightMeasure> getCatchLonglineWeightMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<WeightMeasure> binder) throws DataSourceException { +// +// String txName = "getSections : " + bean.getTopiaId(); +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); +// CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); +// List<WeightMeasure> result = new ArrayList<WeightMeasure>(); +// for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { +// WeightMeasure target = new WeightMeasureImpl(); +// binder.load(weightSource, target, true); +// result.add(target); +// } +// return result; +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(DataSource source, String gearId) throws DataSourceException { +// +// String txName = "getDefaultGearUseFeaturesMeasurementSeine : " + gearId; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); +// Gear gear = gearDao.findByTopiaId(gearId); +// +// Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); +// List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); +// for (GearCaracteristic caracteristic : gearCaracteristic) { +// GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); +// target.setGearCaracteristic(caracteristic); +// result.add(target); +// } +// +// return result; +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeine(DataSource source, GearUseFeaturesSeine bean, final TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder) throws DataSourceException { +// +// String txName = "getGearUseFeaturesMeasurementSeine : " + bean.getTopiaId(); +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaDAO<GearUseFeaturesSeine> dao = source.getDAO(tx, GearUseFeaturesSeine.class); +// GearUseFeaturesSeine gearUseFeaturesSeine = dao.findByTopiaId(bean.getTopiaId()); +// List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); +// for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { +// GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); +// measurementSource.getGearCaracteristic().getGearCaracteristicType(); +// binder.load(measurementSource, target, true); +// result.add(target); +// } +// return result; +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(DataSource source, String gearId) throws DataSourceException { +// +// String txName = "getDefaultGearUseFeaturesMeasurementLongline : " + gearId; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); +// Gear gear = gearDao.findByTopiaId(gearId); +// +// Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); +// List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); +// for (GearCaracteristic caracteristic : gearCaracteristic) { +// GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); +// target.setGearCaracteristic(caracteristic); +// result.add(target); +// } +// +// return result; +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + +// public List<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLongline(DataSource source, GearUseFeaturesLongline bean, final TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder) throws DataSourceException { +// +// String txName = "getGearUseFeaturesMeasurementLongline : " + bean.getTopiaId(); +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaDAO<GearUseFeaturesLongline> dao = source.getDAO(tx, GearUseFeaturesLongline.class); +// GearUseFeaturesLongline gearUseFeaturesLongline = dao.findByTopiaId(bean.getTopiaId()); +// List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); +// for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { +// GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); +// measurementSource.getGearCaracteristic().getGearCaracteristicType(); +// binder.load(measurementSource, target, true); +// result.add(target); +// } +// return result; +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } + + public <E extends TopiaEntity> List<String> getEntityIds(DataSource source, Class<E> refClass) throws DataSourceException { String txName = "getEntityIds : " + refClass; @@ -1712,42 +1641,42 @@ public class DataService { } } - public List<TripMapPoint> loadTripMapActivityPoints(DataSource source, String id) throws DataSourceException { - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data!"); - } - return null; - } - - String txName = "loadTrip"; - TopiaContext tx = beginTransaction(source, txName); - - List<TripMapPoint> tripMapPoints; - - try { - if (Entities.isSeineId(id)) { - TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); - - tripMapPoints = dao.extractTripMapActivityPoints(id); - - } else if (Entities.isLonglineId(id)) { - - TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); - - tripMapPoints = dao.extractTripMapActivityPoints(id); - - } else { - throw new ObserveTechnicalException(String.format("id '%s' is not seine id or longe line id", id)); - } - - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally{ - closeTransaction(source, tx, txName); - } - return tripMapPoints; - } +// public List<TripMapPoint> loadTripMapActivityPoints(DataSource source, String id) throws DataSourceException { +// if (!source.canReadData()) { +// if (log.isDebugEnabled()) { +// log.debug("Can not read data!"); +// } +// return null; +// } +// +// String txName = "loadTrip"; +// TopiaContext tx = beginTransaction(source, txName); +// +// List<TripMapPoint> tripMapPoints; +// +// try { +// if (Entities.isSeineId(id)) { +// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); +// +// tripMapPoints = dao.extractTripMapActivityPoints(id); +// +// } else if (Entities.isLonglineId(id)) { +// +// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); +// +// tripMapPoints = dao.extractTripMapActivityPoints(id); +// +// } else { +// throw new ObserveTechnicalException(String.format("id '%s' is not seine id or longe line id", id)); +// } +// +// } catch (TopiaException e) { +// throw new DataSourceException(e, txName); +// } finally{ +// closeTransaction(source, tx, txName); +// } +// return tripMapPoints; +// } // ------------------------------------------------------------------------ @@ -1755,43 +1684,43 @@ public class DataService { // ------------------------------------------------------------------------ - public TopiaEntity loadEntity(DataSource source, - String id, - boolean decorate) throws DataSourceException { - - String txName = "loadEntity : " + id; - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaEntity result = tx.findByTopiaId(id); - //FIXME Find a better way to do this... - if (result instanceof ActivitySeine) { - - // on charge toujours sa calée - ((ActivitySeine) result).getSetSeine(); - } - if (result instanceof ActivityLongline) { - - // on charge toujours sa calée - ((ActivityLongline) result).getSetLongline(); - } - if (decorate) { - Decorator<TopiaEntity> decorator = - getDecoratorService().getDecorator(result); - if (decorator == null) { - if (log.isWarnEnabled()) { - log.warn("Decorateur non trouvé pour l'objet " + result); - } - } else { - decorator.toString(result); - } - } - return result; - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } +// public TopiaEntity loadEntity(DataSource source, +// String id, +// boolean decorate) throws DataSourceException { +// +// String txName = "loadEntity : " + id; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// TopiaEntity result = tx.findByTopiaId(id); +// //FIXME Find a better way to do this... +// if (result instanceof ActivitySeine) { +// +// // on charge toujours sa calée +// ((ActivitySeine) result).getSetSeine(); +// } +// if (result instanceof ActivityLongline) { +// +// // on charge toujours sa calée +// ((ActivityLongline) result).getSetLongline(); +// } +// if (decorate) { +// Decorator<TopiaEntity> decorator = +// getDecoratorService().getDecorator(result); +// if (decorator == null) { +// if (log.isWarnEnabled()) { +// log.warn("Decorateur non trouvé pour l'objet " + result); +// } +// } else { +// decorator.toString(result); +// } +// } +// return result; +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } public <E extends TopiaEntity> void loadEditEntity(DataSource source, @@ -1811,48 +1740,48 @@ public class DataService { } - public <E extends TopiaEntity> List<E> loadEntityAssociation(DataSource source, - Class<E> entityClass, - String property, - String parentId) throws DataSourceException { - - TopiaContext tx = beginTransaction(source, "loadEntitiesWithProperties"); - try { - - Class<TopiaEntity> parentclass = TopiaId.getClassName(parentId); - - TopiaDAO<?> parentDao = source.getDAO(tx, parentclass); - - // get parent entity - TopiaEntity parent = parentDao.findByTopiaId(parentId); - - // get parent operator - EntityOperator<TopiaEntity> operator = - ObserveDAOHelper.getOperator(parentclass); - - // get property from parent - List<E> result = (List<E>) operator.get(property, parent); - - DecoratorService decoratorService = getDecoratorService(); - - if (decoratorService != null) { - - // chargement des rendus - Decorator<E> decorator = - decoratorService.getDecoratorByType(entityClass); - for (E e : result) { - decorator.toString(e); - } - } - return result; - } catch (TopiaException e) { - throw new DataSourceException( - "Can not obtain topiaentity " + - parentId, e, "loadEntitiesWithProperties"); - } finally { - closeTransaction(source, tx, "loadEntitiesWithProperties"); - } - } +// public <E extends TopiaEntity> List<E> loadEntityAssociation(DataSource source, +// Class<E> entityClass, +// String property, +// String parentId) throws DataSourceException { +// +// TopiaContext tx = beginTransaction(source, "loadEntitiesWithProperties"); +// try { +// +// Class<TopiaEntity> parentclass = TopiaId.getClassName(parentId); +// +// TopiaDAO<?> parentDao = source.getDAO(tx, parentclass); +// +// // get parent entity +// TopiaEntity parent = parentDao.findByTopiaId(parentId); +// +// // get parent operator +// EntityOperator<TopiaEntity> operator = +// ObserveDAOHelper.getOperator(parentclass); +// +// // get property from parent +// List<E> result = (List<E>) operator.get(property, parent); +// +// DecoratorService decoratorService = getDecoratorService(); +// +// if (decoratorService != null) { +// +// // chargement des rendus +// Decorator<E> decorator = +// decoratorService.getDecoratorByType(entityClass); +// for (E e : result) { +// decorator.toString(e); +// } +// } +// return result; +// } catch (TopiaException e) { +// throw new DataSourceException( +// "Can not obtain topiaentity " + +// parentId, e, "loadEntitiesWithProperties"); +// } finally { +// closeTransaction(source, tx, "loadEntitiesWithProperties"); +// } +// } public <E extends TopiaEntity, C extends TopiaEntity> void copyAssociation(Class<E> entityType, Class<C> childEntityType, @@ -1877,96 +1806,96 @@ public class DataService { } - public String getSensorUsedDataFilename(DataSource source, SensorUsed sensorUSed) throws DataSourceException { - - String txName = "getSensorUsedDataFilename"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - TripLongline tripLongline = source.getOpen(tx, TripLongline.class); - - StringBuilder filenameBuilder = new StringBuilder("sensorData"); - String code = tripLongline.getVessel().getCode(); - filenameBuilder.append("-").append(code); - - Date startDate = tripLongline.getStartDate(); - filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); - - SensorType sensorType = sensorUSed.getSensorType(); - if (sensorType != null && sensorType.getCode() != null) { - filenameBuilder.append("-").append(sensorType.getCode()); - } - - String sensorSerialNo = sensorUSed.getSensorSerialNo(); - if (sensorSerialNo != null) { - filenameBuilder.append("-").append(sensorSerialNo); - } - filenameBuilder.append("-").append(sensorUSed.getDataFilename()); - - String filename = filenameBuilder.toString(); - return filename; - - } finally { - - closeTransaction(source, tx, txName); - - } - - } - - public String getTdrDataFilename(DataSource source, Tdr tdr) throws DataSourceException { - - String txName = "getTdrDataFilename"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - TripLongline tripLongline = source.getOpen(tx, TripLongline.class); - - StringBuilder filenameBuilder = new StringBuilder("tdr"); - String code = tripLongline.getVessel().getCode(); - filenameBuilder.append("-").append(code); - - Date startDate = tripLongline.getStartDate(); - filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); - - String homeId = tdr.getHomeId(); - if (homeId != null) { - filenameBuilder.append("-").append(homeId); - } - - String serialNo = tdr.getSerialNo(); - if (serialNo != null) { - filenameBuilder.append("-").append(serialNo); - } - filenameBuilder.append("-").append(tdr.getDataFilename()); - - String filename = filenameBuilder.toString(); - return filename; - - } finally { - - closeTransaction(source, tx, txName); - - } - - } - - public <E extends TopiaEntity> List<E> loadDecoratedEntities(DataSource source, - Class<E> entityClass) throws DataSourceException { - - String txName = "loadEntities :: " + entityClass.getName(); - TopiaContext tx = beginTransaction(source, txName); - Decorator<E> decorator = getDecoratorService().getDecoratorByType(entityClass); - try { - List<E> result = - source.loadDecoratedEntities(tx, entityClass, decorator); - return result; - } finally { - closeTransaction(source, tx, txName); - } - } +// public String getSensorUsedDataFilename(DataSource source, SensorUsed sensorUSed) throws DataSourceException { +// +// String txName = "getSensorUsedDataFilename"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// TripLongline tripLongline = source.getOpen(tx, TripLongline.class); +// +// StringBuilder filenameBuilder = new StringBuilder("sensorData"); +// String code = tripLongline.getVessel().getCode(); +// filenameBuilder.append("-").append(code); +// +// Date startDate = tripLongline.getStartDate(); +// filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); +// +// SensorType sensorType = sensorUSed.getSensorType(); +// if (sensorType != null && sensorType.getCode() != null) { +// filenameBuilder.append("-").append(sensorType.getCode()); +// } +// +// String sensorSerialNo = sensorUSed.getSensorSerialNo(); +// if (sensorSerialNo != null) { +// filenameBuilder.append("-").append(sensorSerialNo); +// } +// filenameBuilder.append("-").append(sensorUSed.getDataFilename()); +// +// String filename = filenameBuilder.toString(); +// return filename; +// +// } finally { +// +// closeTransaction(source, tx, txName); +// +// } +// +// } + +// public String getTdrDataFilename(DataSource source, Tdr tdr) throws DataSourceException { +// +// String txName = "getTdrDataFilename"; +// TopiaContext tx = beginTransaction(source, txName); +// +// try { +// +// TripLongline tripLongline = source.getOpen(tx, TripLongline.class); +// +// StringBuilder filenameBuilder = new StringBuilder("tdr"); +// String code = tripLongline.getVessel().getCode(); +// filenameBuilder.append("-").append(code); +// +// Date startDate = tripLongline.getStartDate(); +// filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); +// +// String homeId = tdr.getHomeId(); +// if (homeId != null) { +// filenameBuilder.append("-").append(homeId); +// } +// +// String serialNo = tdr.getSerialNo(); +// if (serialNo != null) { +// filenameBuilder.append("-").append(serialNo); +// } +// filenameBuilder.append("-").append(tdr.getDataFilename()); +// +// String filename = filenameBuilder.toString(); +// return filename; +// +// } finally { +// +// closeTransaction(source, tx, txName); +// +// } +// +// } + +// public <E extends TopiaEntity> List<E> loadDecoratedEntities(DataSource source, +// Class<E> entityClass) throws DataSourceException { +// +// String txName = "loadEntities :: " + entityClass.getName(); +// TopiaContext tx = beginTransaction(source, txName); +// Decorator<E> decorator = getDecoratorService().getDecoratorByType(entityClass); +// try { +// List<E> result = +// source.loadDecoratedEntities(tx, entityClass, decorator); +// return result; +// } finally { +// closeTransaction(source, tx, txName); +// } +// } public <E extends TopiaEntity> List<E> loadDecoratedEntities(DataSource source, @@ -2171,30 +2100,30 @@ public class DataService { } - public void updateOpenProperty(DataSource source, - String id, - boolean newValue) throws DataSourceException { - - if (!source.canWriteData()) { - - // pas autorisé à écrire des données observer - return; - } - - String txName = "updateOpenProperty :: " + id + " - " + newValue; - TopiaContext tx = null; - try { - tx = beginTransaction(source, txName); - OpenableEntity beanToSave = source.findByTopiaId(tx, id); - beanToSave.setOpen(newValue); - commitTransaction(source, tx, txName); - } catch (TopiaException e) { - throw new DataSourceException( - "Can not update open state for " + id, e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } +// public void updateOpenProperty(DataSource source, +// String id, +// boolean newValue) throws DataSourceException { +// +// if (!source.canWriteData()) { +// +// // pas autorisé à écrire des données observer +// return; +// } +// +// String txName = "updateOpenProperty :: " + id + " - " + newValue; +// TopiaContext tx = null; +// try { +// tx = beginTransaction(source, txName); +// OpenableEntity beanToSave = source.findByTopiaId(tx, id); +// beanToSave.setOpen(newValue); +// commitTransaction(source, tx, txName); +// } catch (TopiaException e) { +// throw new DataSourceException( +// "Can not update open state for " + id, e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// } @SuppressWarnings({"unchecked"}) @@ -2347,11 +2276,11 @@ public class DataService { pcs.removePropertyChangeListener(propertyName, listener); } - public void removePropertyChangeListeners() { - for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) { - removePropertyChangeListener(listener); - } - } +// public void removePropertyChangeListeners() { +// for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) { +// removePropertyChangeListener(listener); +// } +// } public <E extends TopiaEntity> void addReferentielPropertyChangeListener(Class<E> entitClass, PropertyChangeListener listener) { ObserveEntityEnum constant = ObserveEntityEnum.valueOf(entitClass); @@ -2360,11 +2289,11 @@ public class DataService { addPropertyChangeListener(propertyName, listener); } - public <E extends TopiaEntity> void addDataPropertyChangeListener(Class<E> entitClass, PropertyChangeListener listener) { - ObserveEntityEnum constant = ObserveEntityEnum.valueOf(entitClass); - String propertyName = getDataPropertyName(constant); - addPropertyChangeListener(propertyName, listener); - } +// public <E extends TopiaEntity> void addDataPropertyChangeListener(Class<E> entitClass, PropertyChangeListener listener) { +// ObserveEntityEnum constant = ObserveEntityEnum.valueOf(entitClass); +// String propertyName = getDataPropertyName(constant); +// addPropertyChangeListener(propertyName, listener); +// } public void removeReferentielPropertyChangeListeners() { for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { @@ -2417,41 +2346,41 @@ public class DataService { return result.toArray(new PropertyChangeListener[result.size()]); } - protected void fireOpenChanged(DataSource source) { - - String propertyName = DataSource.OPEN_PROPERTY_KEY; - - if (log.isInfoEnabled()) { - log.info("Open context changed, will notifiy listeners [" + propertyName + "]..."); - } - - // obtain all opens ids - try { - - String[] ids = getOpenIds(source); - - String message = Arrays.toString(ids); - - PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); - if (listeners.length == 0) { - // pas de listener, on ne fait rien - - - if (log.isInfoEnabled()) { - log.info("Open context " + message + ", No listener, skip"); - } - return; - } - - PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, ids); - firePropertyChangedEvent(event, "Open context " + message + " changed", listeners); - - } catch (DataSourceException e) { - if (log.isErrorEnabled()) { - log.error("Could not fire open changed", e); - } - } - } +// public void fireOpenChanged(DataSource source) { +// +// String propertyName = DataSource.OPEN_PROPERTY_KEY; +// +// if (log.isInfoEnabled()) { +// log.info("Open context changed, will notifiy listeners [" + propertyName + "]..."); +// } +// +// // obtain all opens ids +// try { +// +// String[] ids = getOpenIds(source); +// +// String message = Arrays.toString(ids); +// +// PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); +// if (listeners.length == 0) { +// // pas de listener, on ne fait rien +// +// +// if (log.isInfoEnabled()) { +// log.info("Open context " + message + ", No listener, skip"); +// } +// return; +// } +// +// PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, ids); +// firePropertyChangedEvent(event, "Open context " + message + " changed", listeners); +// +// } catch (DataSourceException e) { +// if (log.isErrorEnabled()) { +// log.error("Could not fire open changed", e); +// } +// } +// } protected void fireReferentielChanged(DataSource source, ObserveEntityEnum... types) { for (ObserveEntityEnum constant : types) { @@ -2515,40 +2444,40 @@ public class DataService { } } - public void deleteTrip(DataSource source, String tripId) throws DataSourceException { - - String txName = "deleteTrip"; - TopiaContext tx = beginTransaction(source, txName); - try { - - if (Entities.isSeineId(tripId)) { - - TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); - TripSeine result = dao.findByTopiaId(tripId); - dao.delete(result); - - } else { - - TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); - TripLongline result = dao.findByTopiaId(tripId); - dao.delete(result); - - } - - skipTransactionListener = true; - try { - - commitTransaction(source, tx, txName); - - } finally { - skipTransactionListener = false; - } - - } catch (Exception e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - - } +// public void deleteTrip(DataSource source, String tripId) throws DataSourceException { +// +// String txName = "deleteTrip"; +// TopiaContext tx = beginTransaction(source, txName); +// try { +// +// if (Entities.isSeineId(tripId)) { +// +// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); +// TripSeine result = dao.findByTopiaId(tripId); +// dao.delete(result); +// +// } else { +// +// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); +// TripLongline result = dao.findByTopiaId(tripId); +// dao.delete(result); +// +// } +// +// skipTransactionListener = true; +// try { +// +// commitTransaction(source, tx, txName); +// +// } finally { +// skipTransactionListener = false; +// } +// +// } catch (Exception e) { +// throw new DataSourceException(e, txName); +// } finally { +// closeTransaction(source, tx, txName); +// } +// +// } } diff --git a/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java b/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java index dccc397..1e92b58 100644 --- a/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java +++ b/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java @@ -108,7 +108,7 @@ public class ObserveApplicationContext extends DefaultApplicationContext { return dataSource; } - public final void setDataSource(DataSource source) { + public void setDataSource(DataSource source) { if (source == null) { DATA_SOURCE_ENTRY_DEF.removeContextValue(this); } else { diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineDAOImpl.java index b3877f7..5b32193 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineDAOImpl.java @@ -37,6 +37,15 @@ import java.util.List; public class ActivityLonglineDAOImpl<E extends ActivityLongline> extends ActivityLonglineDAOAbstract<E> { + public int getActivityLonglinePosition(String tripId, String activityId) throws TopiaException { + + //FIXME Search direclty in the return list to avoid a sql query + E activity = findByTopiaId(activityId); + List<E> activities = findAllStubByTripId(tripId, ReferenceLocale.FR); + return activities.indexOf(activity); + + } + public List<E> findAllStubByTripId(String tripId, ReferenceLocale referenceLocale) throws TopiaException { List<E> result = StubSqlQuery.findAll(context, tripId, referenceLocale); diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineDAOImpl.java index 0d81ecf..fc50d37 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineDAOImpl.java @@ -37,6 +37,15 @@ import java.util.List; public class ActivitySeineDAOImpl<E extends ActivitySeine> extends ActivitySeineDAOAbstract<E> { + public int getActivitySeinePosition(String routeId, String activityId) throws TopiaException { + + //FIXME Search direclty in the return list to avoid a sql query + E activity = findByTopiaId(activityId); + List<E> activities = findAllStubByRouteId(routeId, ReferenceLocale.FR); + return activities.indexOf(activity); + + } + public List<E> findAllStubByRouteId(String routeId, ReferenceLocale referenceLocale) throws TopiaException { List<E> result = StubSqlQuery.findAll(context, routeId, referenceLocale); diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java index 7093c52..7bfed7a 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -44,13 +45,15 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { public static final String ACTIVITY_FIN_DE_VEILLE = "16"; - public static final String ACTIVITY_DEBUT_DE_PECHE = "7"; + public static final String ACTIVITY_DEBUT_DE_PECHE = "6"; - public static final String ACTIVITY_FIN_DE_PECHE = "6"; + public static final String ACTIVITY_DEBUT_DE_PECHE_ID = "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675369#0.027011527426829218"; + + public static final String ACTIVITY_FIN_DE_PECHE = "7"; public static final String ACTIVITY_CHANGED_ZONE = "21"; - private static final List<String> CALEE_OPERATIONS = Arrays.asList(ACTIVITY_FIN_DE_PECHE); + private static final List<String> CALEE_OPERATIONS = Collections.singletonList(ACTIVITY_DEBUT_DE_PECHE_ID); private static final List<String> DCP_OPERATIONS = Arrays.asList("13", "14", "15"); @@ -58,7 +61,7 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { public static final String PROPERTY_CHANGED_ZONE_OPERATION = "changedZoneOperation"; - public static final String PROPERTY_SET_OPERATION = "setOperation"; +// public static final String PROPERTY_SET_OPERATION = "setOperation"; /** * La valeur du quadrant (utilisé uniquement dans l'interface graphique) : @@ -90,7 +93,7 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { /** @return {@code true} si l'activite concerne une calée */ @Override public boolean isSetOperation() { - return vesselActivitySeine != null && CALEE_OPERATIONS.contains(vesselActivitySeine.getCode()); + return vesselActivitySeine != null && CALEE_OPERATIONS.contains(vesselActivitySeine.getTopiaId()); } /** @return {@code true} si l'activite concerne un système observé */ @@ -148,7 +151,7 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { @Override public boolean isActivityFinDePeche() { - return vesselActivitySeine != null && ACTIVITY_DEBUT_DE_PECHE.equals(vesselActivitySeine.getCode()); + return vesselActivitySeine != null && ACTIVITY_FIN_DE_PECHE.equals(vesselActivitySeine.getCode()); } @Override diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/RouteDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/RouteDAOImpl.java index 0858904..8c16e1c 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/RouteDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/RouteDAOImpl.java @@ -34,6 +34,16 @@ import java.util.List; public class RouteDAOImpl<E extends Route> extends RouteDAOAbstract<E> { + public int getRoutePosition(String tripId, String routeId) throws TopiaException { + + TripSeine maree = context.getDAO(TripSeine.class).findByTopiaId(tripId); + Route route = maree.getRouteByTopiaId(routeId); + List<Route> routes = maree.getRoute(); + Routes.sort(routes); + return routes.indexOf(route); + + } + public List<E> findAllStubByTripId(String tripSeineId) throws TopiaException { List<E> result = StubSqlQuery.findAll(context, tripSeineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index cadd7ac..b15a574 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -1,51 +1,198 @@ package fr.ird.observe.services; -import fr.ird.observe.db.DataSource; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; +import fr.ird.observe.IObserveConfig; +import fr.ird.observe.ObserveEntityEnum; +import fr.ird.observe.ObserveServiceHelper; +import fr.ird.observe.entities.Entities; +import fr.ird.observe.entities.EntityMap; +import fr.ird.observe.entities.constants.ReferenceLocale; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.decorator.Decorator; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com + * @since 4.0 */ -public abstract class AbstractObserveService<E extends TopiaEntity> { - - protected final DataSource dataSource; - - protected final Class<E> entityClass; - - protected abstract TopiaDAO<E> getDao(TopiaContext tx) throws TopiaException; - - protected AbstractObserveService(Class<E> entityClass, DataSource dataSource) { - this.dataSource = dataSource; - this.entityClass = entityClass; - } - -// public E create(E entity) { -// try { -// TopiaContext topiaContext = dataSource.beginTransaction("create entity"); -// -// TopiaDAO<E> dao = ObserveDAOHelper.getDAO(topiaContext, entityClass); -// -// topiaContext.commitTransaction(); -// -// } catch (DataSourceException e) { -// e.printStackTrace(); -// } catch (TopiaException e) { -// e.printStackTrace(); -// } finally { -// -// } -// -// }; -// -// public abstract void update(E entity); -// -// public abstract E findById(String id); -// -// public abstract void delete(E entity); +public abstract class AbstractObserveService implements ObserveService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(AbstractObserveService.class); + + protected ObserveServiceContext serviceContext; + + @Override + public void setServiceContext(ObserveServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + @Override + public <E extends TopiaEntity> EntityMap findAllUsages(E entity) { + + Class<E> entityType = (Class<E>) ObserveEntityEnum.valueOf(entity).getContract(); + + TopiaDAO<E> dao = getDao(entityType); + + // always get a fresh version of object + entity = dao.findByTopiaId(entity.getTopiaId()); + EntityMap result; + result = new EntityMap(dao.findAllUsages(entity)); + // on charge les entites + for (Class<? extends TopiaEntity> aClass : result.keySet()) { + + List topiaEntities = result.get(aClass); + decorate(aClass, topiaEntities); + + } + return result; + + } + + @Override + public <E extends TopiaEntity> List<E> getList(Class<E> klass) { + + List<E> list = getList(klass, null); + return list; + } + + @Override + public <E extends TopiaEntity> List<E> getList(Class<E> klass, Predicate<E> predicate) { + + if (Entities.isDataClass(klass)) { + // on verifie que l'on a le droit de lire la donnee + if (!serviceContext.getDataSource().canReadData()) { + if (log.isDebugEnabled()) { + log.debug("Can not read data, no read credential"); + } + return new ArrayList<E>(); + } + } + + if (Entities.isReferentielClass(klass)) { + // on verifie que l'on a le droit de lire la donnee + if (!serviceContext.getDataSource().canReadReferentiel()) { + if (log.isDebugEnabled()) { + log.debug("Can not read referentiel, no read credential"); + } + return new ArrayList<E>(); + } + } + + List<E> result = getList0(klass, predicate); + + //TC-20100208 : on peut modifier la liste (pour supprimer par + // exemple les entites non active), on doit donc toujours travailler + // sur une copie de la liste + return new ArrayList<E>(result); + + } + + @Override + public void close() { + //TODO + } + + public TopiaContext getTransaction() { + return serviceContext.getTransaction(); + } + + public IObserveConfig getConfig() { + return serviceContext.getConfig(); + } + + public ReferenceLocale getReferentielLocale() { + return serviceContext.getReferentielLocale(); + } + + public Date now() { + return serviceContext.now(); + } + + protected <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityType) { + return serviceContext.getDataSource().getDAO(getTransaction(), entityType); + } + protected <E extends TopiaEntity> E findByTopiaId(Class<E> entityType, String topiaId) { + TopiaDAO<E> dao = serviceContext.getDataSource().getDAO(getTransaction(), entityType); + return dao.findByTopiaId(topiaId); + + } + + protected <O> Decorator<O> getDecoratorByType(Class<O> entityType, String context) { + return serviceContext.getDecoratorService().getDecoratorByType(entityType, context); + } + + + protected <O> void decorate(Class<O> objectType, Collection<O> objects) { + + Decorator<O> decorator = getDecoratorByType(objectType, null); + for (Object object : objects) { + decorator.toString(object); + } + + } + + protected <O> void decorate(Class<O> objectType, O object) { + + Decorator<O> decorator = getDecoratorByType(objectType, null); + decorator.toString(object); + + } + + protected <E extends TopiaEntity> List<E> getList0(Class<E> klass, Predicate<E> predicate) { + + TopiaDAO<E> dao = getDao(klass); + List<E> result = dao.findAll(); + + if (predicate != null) { + + // use a filter + result = Lists.newArrayList(Iterables.filter(result, predicate)); + + } + + return result; + + } + + + protected <E extends TopiaEntity> TopiaEntityBinder<E> loadBinder(String suffix, Class<E> entityType, CreateBinder<E> createBinder) { + + BinderService binderService = ObserveServiceHelper.get().getBinderService(); + + String binderName = getClass().getName() + suffix; + TopiaEntityBinder<E> r = binderService.getTopiaBinder(entityType, binderName); + + if (r == null) { + + BinderModelBuilder<E, E> builder = createBinder.createBinderBuilder(binderService, binderName); + r = binderService.registerTopiaBinder(entityType, builder, binderName); + + } + + return r; + + } + + protected interface CreateBinder<E extends TopiaEntity> { + + BinderModelBuilder<E, E> createBinderBuilder(BinderService binderService, String name); + + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/Commit.java b/observe-services/src/main/java/fr/ird/observe/services/Commit.java new file mode 100644 index 0000000..f99b536 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/Commit.java @@ -0,0 +1,19 @@ +package fr.ird.observe.services; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Place this on every method that need a commit. + * + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Commit { +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java b/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java deleted file mode 100644 index 1c03529..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/Longline/TripLonglineServiceImp.java +++ /dev/null @@ -1,66 +0,0 @@ -package fr.ird.observe.services.Longline; - -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglineDAO; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class TripLonglineServiceImp extends AbstractObserveService<TripLongline> { - - public TripLonglineServiceImp(DataSource dataSource) { - super(TripLongline.class, dataSource); - } - - @Override - protected TopiaDAO<TripLongline> getDao(TopiaContext tx) throws TopiaException { - return ObserveDAOHelper.getTripLonglineDAO(tx); - } - -// @Override - public TripLongline create(TripLongline entity) { - try { - TopiaContext topiaContext = dataSource.beginTransaction("create TripLongline"); - - TripLonglineDAO dao = ObserveDAOHelper.getTripLonglineDAO(topiaContext); - - entity = dao.create(entity); - - } catch (DataSourceException e) { - throw new ObserveTechnicalException("unable to create tripLongLine", e); - } catch (TopiaException e) { - throw new ObserveTechnicalException("unable to create tripLongLine", e); - } - - return entity; - } - -// @Override - public void update(TripLongline entity) { - - getLoadBinder().copyExcluding(getBean(), beanToSave, TripLongline.PROPERTY_ACTIVITY_LONGLINE); - - return beanToSave; - - } - -// @Override - public TripLongline findById(String id) { - return null; - } - -// @Override - public void delete(TripLongline entity) { - TopiaDAO<TripLongline> dao = getDataSource().getDAO(tx, TripLongline.class); - dao.delete(beanToDelete); - - } -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java b/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java new file mode 100644 index 0000000..fc34b8e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java @@ -0,0 +1,19 @@ +package fr.ird.observe.services; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Place this on every method that do not need a transaction. + * + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface NoTransaction { +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java new file mode 100644 index 0000000..27e9ac4 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java @@ -0,0 +1,27 @@ +package fr.ird.observe.services; + + +import com.google.common.base.Predicate; +import fr.ird.observe.entities.EntityMap; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.io.Closeable; +import java.util.List; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ObserveService extends Closeable { + + <E extends TopiaEntity> EntityMap findAllUsages(E entity); + + <E extends TopiaEntity> List<E> getList(Class<E> klass) ; + + <E extends TopiaEntity> List<E> getList(Class<E> klass, Predicate<E> predicate) ; + + void setServiceContext(ObserveServiceContext serviceContext); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java new file mode 100644 index 0000000..a837b4c --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java @@ -0,0 +1,76 @@ +package fr.ird.observe.services; + +import fr.ird.observe.DecoratorService; +import fr.ird.observe.IObserveConfig; +import fr.ird.observe.ObserveApplicationContext; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.entities.constants.ReferenceLocale; +import org.nuiton.topia.TopiaContext; + +import java.util.Date; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ObserveServiceContext { + + /** + * Configuration. + */ + protected final IObserveConfig config; + + /** + * Data Source. + */ + protected final DataSource dataSource; + + protected final DecoratorService decoratorService; + + /** + * Current transaction. + */ + protected TopiaContext transaction; + + /** + * Application context. + */ + protected ObserveApplicationContext applicationContext; + + public ObserveServiceContext(ObserveApplicationContext applicationContext, DataSource dataSource) { + this.applicationContext=applicationContext; + this.config = applicationContext.getConfig(); + this.dataSource = dataSource; + this.decoratorService = applicationContext.getDecoratorService(); + } + + public TopiaContext getTransaction() { + return transaction; + } + + public IObserveConfig getConfig() { + return config; + } + + public ReferenceLocale getReferentielLocale() { + return applicationContext.getDecoratorService().getReferentielLocale(); + } + + public Date now() { + return new Date(); + } + + public DecoratorService getDecoratorService() { + return decoratorService; + } + + protected void setTransaction(TopiaContext transaction) { + this.transaction = transaction; + } + + protected DataSource getDataSource() { + return dataSource; + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index af151ad..fc2b3b5 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -1,11 +1,27 @@ package fr.ird.observe.services; import com.google.common.base.Preconditions; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.Sets; +import fr.ird.observe.ObserveApplicationContext; import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.event.DataSourceEvent; -import fr.ird.observe.db.event.DataSourceListenerAdapter; +import fr.ird.observe.db.DataSourceException; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.reflect.ConstructorUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; + +import java.io.Closeable; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Set; +import java.util.concurrent.ExecutionException; /** * Created on 4/24/15. @@ -13,35 +29,214 @@ import org.apache.commons.lang3.reflect.ConstructorUtils; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class ObserveServiceFactory { +public class ObserveServiceFactory implements Closeable { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ObserveServiceFactory.class); + + protected final ObserveApplicationContext applicationContext; + + protected DataSource dataSource; + + protected final LoadingCache<Class<? extends ObserveService>, ObserveService> services; + + public static ObserveServiceFactory newFactory(ObserveApplicationContext applicationContext) { + return new ObserveServiceFactory(applicationContext); + } + + public static ObserveServiceFactory newFactory(ObserveApplicationContext applicationContext, DataSource dataSource) { + ObserveServiceFactory factory = newFactory(applicationContext); + factory.setDataSource(dataSource); + return factory; + } + + protected ObserveServiceFactory(ObserveApplicationContext applicationContext) { + this.applicationContext = applicationContext; + this.services = CacheBuilder.newBuilder().build(new CacheLoader<Class<? extends ObserveService>, ObserveService>() { + @Override + public ObserveService load(Class<? extends ObserveService> key) throws Exception { + Preconditions.checkNotNull(key, "service key can't be null"); + Preconditions.checkNotNull(dataSource, "can't ask a service if not datasource is setted"); + ObserveService service = createService(key, ObserveServiceFactory.this.applicationContext, ObserveServiceFactory.this.dataSource); + if (log.isDebugEnabled()) { + log.debug("New service " + service); + } + + return service; + } + }); + } + + public DataSource getDataSource() { + return dataSource; + } + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + public <S extends ObserveService> S getService(Class<S> serviceType) { + if (serviceType == null) { + return null; + } + try { + S s = (S) services.get(serviceType); + return s; + } catch (ExecutionException e) { + throw new ObserveTechnicalException("Could not get service: " + serviceType, e); + } + } + + public void clear() { + services.invalidateAll(); + } - public static <S> S createService(Class<S> serviceType, DataSource dataSource) { + @Override + public void close() { + + for (ObserveService service : services.asMap().values()) { + if (log.isDebugEnabled()) { + log.debug("Close service " + service); + } + IOUtils.closeQuietly(service); + } + services.invalidateAll(); + } + + protected <S extends ObserveService> S createService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { Preconditions.checkNotNull(serviceType, "serviceType can't be null"); - Preconditions.checkNotNull(dataSource, "dataSource can't be null"); + Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); + Preconditions.checkNotNull(applicationContext, "applicationContext can't be null"); + + ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); + + S service = newService(serviceType, serviceContext); + return service; + + } + + protected <S extends ObserveService> S createService(Class<S> serviceType, ObserveServiceContext serviceContext) { + + Preconditions.checkNotNull(serviceType, "serviceType can't be null"); + Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); + Preconditions.checkNotNull(serviceContext, "serviceContext can't be null"); + + S service = newService(serviceType, serviceContext); + return service; + + } + + protected <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { + + Class<S> serviceImpl; + try { + //FIXME Cela devrait dépendre de la datasource ? + serviceImpl = (Class<S>) Class.forName(serviceType.getName() + "Impl"); + } catch (ClassNotFoundException e) { + throw new IllegalStateException("Could not find implementation class for " + serviceType); + } try { - S service = ConstructorUtils.invokeConstructor(serviceType, dataSource); + // Instanciate concrete service + S service = ConstructorUtils.invokeConstructor(serviceImpl); + service.setServiceContext(serviceContext); - //FIXME On peut ajouter un état au service pour savoir si la dataSource est encore accessible... - dataSource.addDataSourceListener(new DataSourceListenerAdapter() { - @Override - public void onClosed(DataSourceEvent event) { + // Instanciate transactional proxied service + ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); + S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); + + return proxyService; + + } catch (Exception e) { + throw new ObserveTechnicalException("Could not create service: " + serviceType, e); + } + + } + + protected static class ServiceInvocationHandler implements InvocationHandler { + + private final ObserveServiceContext serviceContext; + + private final ObserveService target; + + private final Set<String> methodNamesToByPass; + + protected ServiceInvocationHandler(ObserveServiceContext serviceContext, ObserveService target) { + this.serviceContext = serviceContext; + this.target = target; + this.methodNamesToByPass = Sets.newHashSet( + "equals", + "hashCode", + "finalize", + "toString", + "clone", + "getClass" + ); + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + + Object result; + + if (methodNamesToByPass.contains(method.getName())) { + + result = method.invoke(target, args); + + } else { + + result = invokeMethodWithTransaction(method, args); + + } + + return result; + + } + + protected Object invokeMethodWithTransaction(Method method, Object... args) throws DataSourceException, IllegalAccessException, InvocationTargetException { + + String methodName = method.getName(); + + DataSource source = serviceContext.getDataSource(); + + TopiaContext tx = source.beginTransaction(methodName); + + try { + + serviceContext.setTransaction(tx); + + Object invoke = method.invoke(target, args); + + if (method.isAnnotationPresent(Commit.class)) { + + // do commit + source.commitTransaction(tx, methodName); } - @Override - public void onOpened(DataSourceEvent event) { + return invoke; + + } finally { + + try { + + // always rollback transaction to avoid dirty transactions + source.rollbackTransaction(tx, methodName); + + + } finally { + + serviceContext.setTransaction(null); + source.closeTransaction(tx, methodName); } - }); - return service; + } - } catch (Exception e) { - throw new ObserveTechnicalException("Could not create service: " + serviceType, e); } } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/OpenableService.java b/observe-services/src/main/java/fr/ird/observe/services/data/OpenableService.java new file mode 100644 index 0000000..01bef8c --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/OpenableService.java @@ -0,0 +1,25 @@ +package fr.ird.observe.services.data; + +import fr.ird.observe.entities.OpenableEntity; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface OpenableService extends ObserveService { + + String[] getOpenIds(); + + <E extends OpenableEntity & TopiaEntity> E getOpen(Class<E> klass); + + @Commit + void updateOpenState(String topiaId, boolean openState); + + int getOpenablePosition(String containerId, String childId); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/OpenableServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/OpenableServiceImpl.java new file mode 100644 index 0000000..ec1f06f --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/OpenableServiceImpl.java @@ -0,0 +1,157 @@ +package fr.ird.observe.services.data; + +import fr.ird.observe.entities.OpenableEntity; +import fr.ird.observe.entities.OpenableEntityDAOImpl; +import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.entities.longline.ActivityLonglineDAO; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.TripLonglineDAO; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.ActivitySeineDAO; +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.RouteDAO; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.entities.seine.TripSeineDAO; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class OpenableServiceImpl extends AbstractObserveService implements OpenableService { + + @Override + public String[] getOpenIds() { + + List<String> result = new ArrayList<String>(); + + { + TripSeine trip = getOpen(TripSeine.class); + if (trip != null) { + if (trip.getProgram() != null) { + result.add(trip.getProgram().getTopiaId()); + } + result.add(trip.getTopiaId()); + Route route = getOpen(Route.class); + if (route != null) { + result.add(route.getTopiaId()); + ActivitySeine activity = getOpen(ActivitySeine.class); + if (activity != null) { + result.add(activity.getTopiaId()); + SetSeine set = activity.getSetSeine(); + if (set != null) { + result.add(set.getTopiaId()); + } + } + } + } + } + + { + TripLongline trip = getOpen(TripLongline.class); + if (trip != null) { + if (trip.getProgram() != null) { + result.add(trip.getProgram().getTopiaId()); + } + result.add(trip.getTopiaId()); + ActivityLongline activity = getOpen(ActivityLongline.class); + if (activity != null) { + result.add(activity.getTopiaId()); + SetLongline set = activity.getSetLongline(); + if (set != null) { + result.add(set.getTopiaId()); + } + } + } + } + + return result.toArray(new String[result.size()]); + + } + + @Override + public <E extends OpenableEntity & TopiaEntity> E getOpen(Class<E> klass) { + + OpenableEntityDAOImpl dao = (OpenableEntityDAOImpl) getDao(klass); + E result = (E) dao.findByOpen(true); + return result; + + } + + @Override + public void updateOpenState(String topiaId, boolean openState) { + + OpenableEntity entity = findByTopiaId(OpenableEntity.class, topiaId); + entity.setOpen(openState); + + } + + public int getOpenablePosition(String containerId, String childId) { + if (childId.startsWith(TripSeine.class.getName())) { + return getTripSeinePosition(containerId, childId); + } + if (childId.startsWith(TripLongline.class.getName())) { + return getTripLonglinePosition(containerId, childId); + } + if (childId.startsWith(Route.class.getName())) { + return getRoutePosition(containerId, childId); + } + if (childId.startsWith(ActivitySeine.class.getName())) { + return getActivitySeinePosition(containerId, childId); + } + if (childId.startsWith(ActivityLongline.class.getName())) { + return getActivityLonglinePosition(containerId, childId); + } + throw new IllegalStateException("Can not come here!"); + } + + protected int getTripLonglinePosition(String programId, String tripLonglineId) { + + TripLonglineDAO dao = (TripLonglineDAO) getDao(TripLongline.class); + int pos = dao.findPositionByProgramId(programId, tripLonglineId); + return pos; + + } + + protected int getActivityLonglinePosition(String tripLonglineId, String activityLonglineId) { + + ActivityLonglineDAO dao = (ActivityLonglineDAO) getDao(ActivityLongline.class); + int pos = dao.getActivityLonglinePosition(tripLonglineId, activityLonglineId); + return pos; + + } + + protected int getTripSeinePosition(String programId, String tripSeineId) { + + TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); + int pos = dao.findPositionByProgramId(programId, tripSeineId); + return pos; + + } + + protected int getRoutePosition(String tripSeineId, String routeId) { + + RouteDAO dao = (RouteDAO) getDao(Route.class); + int position = dao.getRoutePosition(tripSeineId, routeId); + return position; + + } + + + protected int getActivitySeinePosition(String routeId, String activitySeineId) { + + ActivitySeineDAO dao = (ActivitySeineDAO) getDao(ActivitySeine.class); + int pos = dao.getActivitySeinePosition(routeId, activitySeineId); + return pos; + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java new file mode 100644 index 0000000..9595f78 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java @@ -0,0 +1,31 @@ +package fr.ird.observe.services.data; + +import fr.ird.observe.entities.referentiel.Ocean; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; +import fr.ird.observe.tripMap.TripMapPoint; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface TripService extends ObserveService { + + List<Program> getPossibleProgramsForTrip(String tripId); + + Ocean getTripOcean(String tripId); + + List<TripMapPoint> loadTripMapActivityPoints(String tripId); + + @Commit + void moveTripToProgram(String tripId, String programId); + + @Commit + void deleteTrip(String tripId); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java new file mode 100644 index 0000000..e50203d --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java @@ -0,0 +1,134 @@ +package fr.ird.observe.services.data; + +import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.entities.Entities; +import fr.ird.observe.entities.Trip; +import fr.ird.observe.entities.constants.GearType; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.TripLonglineDAO; +import fr.ird.observe.entities.referentiel.Ocean; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.entities.referentiel.ProgramDAO; +import fr.ird.observe.entities.referentiel.Programs; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.entities.seine.TripSeineDAO; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.tripMap.TripMapPoint; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TripServiceImpl extends AbstractObserveService implements TripService { + + @Override + public List<Program> getPossibleProgramsForTrip(String tripId) { + + Trip trip; + + if (tripId.startsWith(TripSeine.class.getSimpleName())) { + trip = findByTopiaId(TripSeine.class, tripId); + } else { + trip = findByTopiaId(TripLongline.class, tripId); + } + + GearType gearType = trip.getProgram().getGearType(); + + ProgramDAO dao = (ProgramDAO) getDao(Program.class); + + List<Program> programs = dao.findAllByGearType(gearType); + + decorate(Program.class, programs); + + Programs.sort(programs); + + return programs; + + } + + @Override + public Ocean getTripOcean(String tripId) { + + Trip trip; + + if (tripId.startsWith(TripSeine.class.getSimpleName())) { + trip = findByTopiaId(TripSeine.class, tripId); + } else { + trip = findByTopiaId(TripLongline.class, tripId); + } + + return trip.getOcean(); + + } + + @Override + public void moveTripToProgram(String tripId, String programId) { + + Trip trip; + + if (tripId.startsWith(TripSeine.class.getSimpleName())) { + trip = findByTopiaId(TripSeine.class, tripId); + } else { + trip = findByTopiaId(TripLongline.class, tripId); + } + + Program program = findByTopiaId(Program.class, programId); + + trip.setProgram(program); + +// if (trip.isOpen()) { +// +// // refresh the dataContext +// dataContext.setOpenProgramId(programId); +// +// } + + } + + @Override + public List<TripMapPoint> loadTripMapActivityPoints(String tripId) { + + List<TripMapPoint> tripMapPoints; + + if (Entities.isSeineId(tripId)) { + TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); + + tripMapPoints = dao.extractTripMapActivityPoints(tripId); + + } else if (Entities.isLonglineId(tripId)) { + + TripLonglineDAO dao = (TripLonglineDAO) getDao(TripLongline.class); + + tripMapPoints = dao.extractTripMapActivityPoints(tripId); + + } else { + throw new ObserveTechnicalException(String.format("id '%s' is not seine id or longe line id", tripId)); + } + + return tripMapPoints; + + } + + @Override + public void deleteTrip(String tripId) { + + if (Entities.isSeineId(tripId)) { + + TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); + TripSeine result = dao.findByTopiaId(tripId); + dao.delete(result); + + } else { + + TripLonglineDAO dao = (TripLonglineDAO) getDao(TripLongline.class); + TripLongline result = dao.findByTopiaId(tripId); + dao.delete(result); + + } + + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java new file mode 100644 index 0000000..ed6fbfa --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java @@ -0,0 +1,41 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ActivityLonglineService extends ObserveService { + + ActivityLongline getActivityLonglineStub(String activityId); + + List<ActivityLongline> getActivityLonglineStubByTrip(String tripId); + + ActivityLongline loadForDisplay(String activityLonglineId); + + ActivityLongline loadForEdit(String activityLonglineId); + + ActivityLongline preCreate(String tripLonglineId); + + @Commit + ActivityLongline save(String tripLonglineId, ActivityLongline toSave); + + @Commit + void delete(String tripLonglineId, String activityLonglineId); + + @NoTransaction + TopiaEntityBinder<ActivityLongline> getBinderForEdit(); + + @NoTransaction + void copyForEdit(ActivityLongline source, ActivityLongline target); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java new file mode 100644 index 0000000..d25a0e2 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -0,0 +1,206 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.entities.longline.ActivityLonglineDAO; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ActivityLonglineServiceImpl extends AbstractObserveService implements ActivityLonglineService { + + @Override + public List<ActivityLongline> getActivityLonglineStubByTrip(String tripId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + List<ActivityLongline> result = getDao().findAllStubByTripId(tripId, referentielLocale); + return result; + + } + + @Override + public ActivityLongline getActivityLonglineStub(String activityId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + ActivityLongline result = getDao().findStubByTopiaId(activityId, referentielLocale); + return result; + + } + + @Override + public ActivityLongline loadForDisplay(String activityLonglineId) { + + ActivityLongline loaded = getDao().newInstance(); + ActivityLongline toLoad = getDao().findByTopiaId(activityLonglineId); + copyForEdit(toLoad, loaded); + + return loaded; + + } + + @Override + public ActivityLongline loadForEdit(String activityLonglineId) { + return loadForDisplay(activityLonglineId); + } + + + + @Override + public ActivityLongline preCreate(String tripLonglineId) { + + TripLongline tripLongline = findByTopiaId(TripLongline.class, tripLonglineId); + + ActivityLongline preCreated = getDao().newInstance(); + + preCreated.setOpen(true); + + ActivityLongline lastActivityLongline = tripLongline.getLastActivity(); + + Date timestamp; + + if (lastActivityLongline == null) { + + // première activité, on utilise la date de début de marée (voir http://forge.codelutin.com/issues/6777) + Calendar calendar = Calendar.getInstance(); + calendar.setTime(tripLongline.getStartDate()); + timestamp = calendar.getTime(); + + } else { + + // passage en coordonnées absolue + quadrant + lastActivityLongline.initCoordinates(); + + // on recupère le quadrant de cette activity + // et on l'affecte à la nouvelle activity + Integer quadrant = lastActivityLongline.getQuadrant(); + + preCreated.setQuadrant(quadrant); + + // on reprend la date et l'heure de la dernière activité + timestamp = lastActivityLongline.getTimeStamp(); + } + + preCreated.setTimeStamp(timestamp); + + + return preCreated; + + } + + @Override + public ActivityLongline save(String tripLonglineId, ActivityLongline toSave) { + + ActivityLongline saved; + + if (toSave.getTopiaId() == null) { + + // create + saved = create(tripLonglineId, toSave); + + } else { + + // update + saved = update(toSave); + + } + + return saved; + + } + + @Override + public void delete(String tripLonglineId, String activityLonglineId) { + + ActivityLonglineDAO dao = getDao(); + ActivityLongline toDelete = dao.findByTopiaId(activityLonglineId); + + TripLongline tripLongline = findByTopiaId(TripLongline.class, tripLonglineId); + tripLongline.removeActivityLongline(toDelete); + + } + + @Override + public TopiaEntityBinder<ActivityLongline> getBinderForEdit() { + + TopiaEntityBinder<ActivityLongline> binder = loadBinder("-forEdit", ActivityLongline.class, new CreateBinder<ActivityLongline>() { + + @Override + public BinderModelBuilder<ActivityLongline, ActivityLongline> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = binderService.newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_QUADRANT, + ActivityLongline.PROPERTY_LATITUDE, + ActivityLongline.PROPERTY_LONGITUDE, + ActivityLongline.PROPERTY_TIME_STAMP, + ActivityLongline.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivityLongline.PROPERTY_COMMENT, + ActivityLongline.PROPERTY_SET_LONGLINE, + ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, + ActivityLongline.PROPERTY_FPA_ZONE, + ActivityLongline.PROPERTY_OPEN, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_SENSOR_USED); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_ENCOUNTER); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_SENSOR_USED); + + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEdit(ActivityLongline source, ActivityLongline target) { + + getBinderForEdit().load(source, target, true); + + } + + protected ActivityLongline create(String tripLonglineId, ActivityLongline toCreate) { + + ActivityLonglineDAO dao = getDao(); + ActivityLongline created = dao.create(toCreate); + + TripLongline tripLongline = findByTopiaId(TripLongline.class, tripLonglineId); + tripLongline.addActivityLongline(created); + + return created; + + } + + protected ActivityLongline update(ActivityLongline toUpdate) { + + ActivityLonglineDAO dao = getDao(); + ActivityLongline updated = dao.findByTopiaId(toUpdate.getTopiaId()); + getBinderForEdit().copyExcluding(toUpdate, updated, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_SENSOR_USED); + return updated; + + } + + protected ActivityLonglineDAO getDao() { + return (ActivityLonglineDAO) getDao(ActivityLongline.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java new file mode 100644 index 0000000..a3cb5bc --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java @@ -0,0 +1,42 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.Branchline; +import fr.ird.observe.entities.longline.SizeMeasure; +import fr.ird.observe.entities.longline.WeightMeasure; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface CatchLonglineService extends ObserveService { + + Branchline loadBranchlineForEdit(String branchelineId); + + @Commit + Branchline saveBranchline(Branchline toSave); + + List<SizeMeasure> getCatchLonglineSizeMeasures(String catchLonglineId); + + List<WeightMeasure> getCatchLonglineWeightMeasures(String catchLonglineId); + + @NoTransaction + TopiaEntityBinder<WeightMeasure> getWeightMeasureBinderForEdit(); + + @NoTransaction + TopiaEntityBinder<SizeMeasure> getSizeMeasureBinderForEdit(); + + @NoTransaction + TopiaEntityBinder<Branchline> getBranchlineBinderForEdit(); + + @NoTransaction + void copyBranchlineForEdit(Branchline source, Branchline target); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java new file mode 100644 index 0000000..e5777f6 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -0,0 +1,136 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.ObserveBinderHelper; +import fr.ird.observe.entities.longline.Branchline; +import fr.ird.observe.entities.longline.BranchlineDAO; +import fr.ird.observe.entities.longline.CatchLongline; +import fr.ird.observe.entities.longline.CatchLonglineDAO; +import fr.ird.observe.entities.longline.SizeMeasure; +import fr.ird.observe.entities.longline.SizeMeasureImpl; +import fr.ird.observe.entities.longline.WeightMeasure; +import fr.ird.observe.entities.longline.WeightMeasureImpl; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class CatchLonglineServiceImpl extends AbstractObserveService implements CatchLonglineService { + + @Override + public Branchline loadBranchlineForEdit(String branchelineId) { + + BranchlineDAO dao = (BranchlineDAO) getDao(Branchline.class); + Branchline toLoad = dao.findByTopiaId(branchelineId); + Branchline loaded = dao.newInstance(); + getBranchlineBinderForEdit().load(toLoad, loaded, true); + return loaded; + + } + + @Override + public Branchline saveBranchline(Branchline toSave) { + + BranchlineDAO dao = (BranchlineDAO) getDao(Branchline.class); + Branchline saved = dao.findByTopiaId(toSave.getTopiaId()); + getBranchlineBinderForEdit().load(toSave, saved, true); + return saved; + + } + + @Override + public void copyBranchlineForEdit(Branchline source, Branchline target) { + + getBranchlineBinderForEdit().load(source, target, true); + + } + + @Override + public List<SizeMeasure> getCatchLonglineSizeMeasures(String catchLonglineId) { + + TopiaEntityBinder<SizeMeasure> binder = getSizeMeasureBinderForEdit(); + + CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); + List<SizeMeasure> result = new ArrayList<SizeMeasure>(); + for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { + SizeMeasure target = new SizeMeasureImpl(); + binder.load(sizeSource, target, true); + result.add(target); + } + return result; + + } + + @Override + public List<WeightMeasure> getCatchLonglineWeightMeasures(String catchLonglineId) { + + TopiaEntityBinder<WeightMeasure> binder = getWeightMeasureBinderForEdit(); + + CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); + List<WeightMeasure> result = new ArrayList<WeightMeasure>(); + for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { + WeightMeasure target = new WeightMeasureImpl(); + binder.load(weightSource, target, true); + result.add(target); + } + + return result; + + } + + @Override + public TopiaEntityBinder<WeightMeasure> getWeightMeasureBinderForEdit() { + + TopiaEntityBinder<WeightMeasure> r = ObserveBinderHelper.getSimpleTopiaBinder(WeightMeasure.class); + return r; + + } + + @Override + public TopiaEntityBinder<SizeMeasure> getSizeMeasureBinderForEdit() { + + TopiaEntityBinder<SizeMeasure> r = ObserveBinderHelper.getSimpleTopiaBinder(SizeMeasure.class); + return r; + + } + + @Override + public TopiaEntityBinder<Branchline> getBranchlineBinderForEdit() { + + TopiaEntityBinder<Branchline> r = loadBinder("-forEdit", Branchline.class, new CreateBinder<Branchline>() { + + @Override + public BinderModelBuilder<Branchline, Branchline> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<Branchline, Branchline> builder = + binderService.newBinderBuilder(Branchline.class, + Branchline.PROPERTY_DEPTH_RECORDER, + Branchline.PROPERTY_HOOK_LOST, + Branchline.PROPERTY_TRACE_CUT_OFF, + Branchline.PROPERTY_TIMER, + Branchline.PROPERTY_TIME_SINCE_CONTACT, + Branchline.PROPERTY_TIMER_TIME_ON_BOARD, + Branchline.PROPERTY_BAIT_HAULING_STATUS); + + return builder; + } + + }); + + return r; + + } + + protected CatchLonglineDAO getDao() { + return (CatchLonglineDAO) getDao(CatchLongline.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java new file mode 100644 index 0000000..6e69121 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java @@ -0,0 +1,25 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface GearUseFeaturesLonglineService extends ObserveService { + + List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(String gearId); + + List<GearUseFeaturesMeasurementLongline> loadGearUseFeaturesMeasurementLonglineForEdit(String gearUseFeaturesLonglineId); + + @NoTransaction + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLonglineBinderForEdit(); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java new file mode 100644 index 0000000..f5bb483 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -0,0 +1,92 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.GearUseFeaturesLongline; +import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; +import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLonglineDAO; +import fr.ird.observe.entities.referentiel.Gear; +import fr.ird.observe.entities.referentiel.GearCaracteristic; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService implements GearUseFeaturesLonglineService { + + @Override + public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(String gearId) { + + GearUseFeaturesMeasurementLonglineDAO dao = getDao(); + + Gear gear = findByTopiaId(Gear.class, gearId); + + Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); + List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); + for (GearCaracteristic caracteristic : gearCaracteristic) { + GearUseFeaturesMeasurementLongline target = dao.newInstance(); + target.setGearCaracteristic(caracteristic); + result.add(target); + } + + return result; + + } + + @Override + public List<GearUseFeaturesMeasurementLongline> loadGearUseFeaturesMeasurementLonglineForEdit(String gearUseFeaturesLonglineId) { + + GearUseFeaturesMeasurementLonglineDAO dao = getDao(); + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getGearUseFeaturesMeasurementLonglineBinderForEdit(); + + GearUseFeaturesLongline gearUseFeaturesLongline = findByTopiaId(GearUseFeaturesLongline.class, gearUseFeaturesLonglineId); + List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); + + for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { + GearUseFeaturesMeasurementLongline target = dao.newInstance(); + measurementSource.getGearCaracteristic().getGearCaracteristicType(); + binder.load(measurementSource, target, true); + result.add(target); + } + + return result; + + } + + @Override + public TopiaEntityBinder<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLonglineBinderForEdit() { + + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> r = loadBinder("-forEdit", GearUseFeaturesMeasurementLongline.class, new CreateBinder<GearUseFeaturesMeasurementLongline>() { + + @Override + public BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> createBinderBuilder(BinderService binderService, String name) { + + + BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> builder = + binderService.newBinderBuilder(GearUseFeaturesMeasurementLongline.class, + GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, + GearUseFeaturesMeasurementLongline.PROPERTY_MEASUREMENT_VALUE); + + return builder; + + } + + }); + + return r; + + } + + protected GearUseFeaturesMeasurementLonglineDAO getDao() { + return (GearUseFeaturesMeasurementLonglineDAO) getDao(GearUseFeaturesMeasurementLongline.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java new file mode 100644 index 0000000..f9891f9 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java @@ -0,0 +1,12 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.services.ObserveService; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface LonglineDetailCompositionService extends ObserveService { +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java new file mode 100644 index 0000000..63fa0f9 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java @@ -0,0 +1,13 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.services.AbstractObserveService; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class LonglineDetailCompositionServiceImpl extends AbstractObserveService implements LonglineDetailCompositionService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java new file mode 100644 index 0000000..af2b697 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java @@ -0,0 +1,37 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.SensorUsed; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface SensorUsedService extends ObserveService { + + String getSensorUsedDataFilename(SensorUsed sensorUsed); + + SensorUsed loadForDisplay(String sensorUsedId); + + SensorUsed loadForEdit(String sensorUsedId); + + SensorUsed preCreate(String setLonglineId); + + @Commit + SensorUsed save(String setLonglineId, SensorUsed toSave); + + @Commit + void delete(String setLonglineId, String sensorUsedId); + + @NoTransaction + TopiaEntityBinder<SensorUsed> getBinderForEdit(); + + @NoTransaction + void copyForEdit(SensorUsed source, SensorUsed target); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java new file mode 100644 index 0000000..eb6aa2d --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java @@ -0,0 +1,84 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.SensorUsed; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.TripLonglineDAO; +import fr.ird.observe.entities.referentiel.longline.SensorType; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class SensorUsedServiceImpl extends AbstractObserveService implements SensorUsedService { + + @Override + public String getSensorUsedDataFilename(SensorUsed sensorUsed) { + + TripLonglineDAO tripDao = (TripLonglineDAO) getDao(TripLongline.class); + TripLongline tripLongline = tripDao.findByOpen(true); + + StringBuilder filenameBuilder = new StringBuilder("sensorData"); + String code = tripLongline.getVessel().getCode(); + filenameBuilder.append("-").append(code); + + Date startDate = tripLongline.getStartDate(); + filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); + + SensorType sensorType = sensorUsed.getSensorType(); + if (sensorType != null && sensorType.getCode() != null) { + filenameBuilder.append("-").append(sensorType.getCode()); + } + + String sensorSerialNo = sensorUsed.getSensorSerialNo(); + if (sensorSerialNo != null) { + filenameBuilder.append("-").append(sensorSerialNo); + } + filenameBuilder.append("-").append(sensorUsed.getDataFilename()); + + String filename = filenameBuilder.toString(); + return filename; + + } + + @Override + public SensorUsed loadForDisplay(String sensorUsedId) { + return null; + } + + @Override + public SensorUsed loadForEdit(String sensorUsedId) { + return null; + } + + @Override + public SensorUsed preCreate(String setLonglineId) { + return null; + } + + @Override + public SensorUsed save(String setLonglineId, SensorUsed toSave) { + return null; + } + + @Override + public void delete(String setLonglineId, String sensorUsedId) { + + } + + @Override + public TopiaEntityBinder<SensorUsed> getBinderForEdit() { + return null; + } + + @Override + public void copyForEdit(SensorUsed source, SensorUsed target) { + + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java new file mode 100644 index 0000000..6e28f73 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java @@ -0,0 +1,21 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.Section; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.ObserveService; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface SetLonglineService extends ObserveService { + + SetLongline loadSet(String setLonglineId); + + List<Section> getSections(String setLonglineId); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java new file mode 100644 index 0000000..c02e1bb --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -0,0 +1,71 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.Basket; +import fr.ird.observe.entities.longline.Branchline; +import fr.ird.observe.entities.longline.Section; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.entities.longline.SetLonglineDAO; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.decorator.Decorator; +import org.nuiton.topia.persistence.TopiaDAO; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class SetLonglineServiceImpl extends AbstractObserveService implements SetLonglineService { + + @Override + public SetLongline loadSet(String setLonglineId) { + return null; + } + + public List<Section> getSections(String setLonglineId) { + + TopiaDAO<Section> dao = getDao(Section.class); + + List<Section> sections = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); + + if (!sections.isEmpty()) { + + Decorator<Section> sectionDecorator = getDecoratorByType(Section.class, null); + Decorator<Basket> basketDecorator = getDecoratorByType(Basket.class, null); + Decorator<Branchline> branchlineDecorator = getDecoratorByType(Branchline.class, null); + + for (Section section : sections) { + + sectionDecorator.toString(section); + + if (!section.isBasketEmpty()) { + + for (Basket basket : section.getBasket()) { + + basketDecorator.toString(basket); + + if (!basket.isBranchlineEmpty()) { + + for (Branchline branchline : basket.getBranchline()) { + + branchlineDecorator.toString(branchline); + + } + } + + } + } + } + } + + return sections; + + } + + protected SetLonglineDAO getDao() { + return (SetLonglineDAO) getDao(SetLongline.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java new file mode 100644 index 0000000..afbee3d --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java @@ -0,0 +1,37 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.Tdr; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface TdrService extends ObserveService { + + String getTdrDataFilename(Tdr tdr); + + Tdr loadForDisplay(String tdrId); + + Tdr loadForEdit(String tdrId); + + Tdr preCreate(String tripLonglineId); + + @Commit + Tdr save(String setLonglineId, Tdr toSave); + + @Commit + void delete(String setLonglineId, String tdrId); + + @NoTransaction + TopiaEntityBinder<Tdr> getBinderForEdit(); + + @NoTransaction + void copyForEdit(Tdr source, Tdr target); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java new file mode 100644 index 0000000..fa6ae63 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java @@ -0,0 +1,83 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.Tdr; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.TripLonglineDAO; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TdrServiceImpl extends AbstractObserveService implements TdrService { + + public String getTdrDataFilename(Tdr tdr) { + + TripLonglineDAO tripDao = (TripLonglineDAO) getDao(TripLongline.class); + TripLongline tripLongline = tripDao.findByOpen(true); + + StringBuilder filenameBuilder = new StringBuilder("tdr"); + String code = tripLongline.getVessel().getCode(); + filenameBuilder.append("-").append(code); + + Date startDate = tripLongline.getStartDate(); + filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); + + String homeId = tdr.getHomeId(); + if (homeId != null) { + filenameBuilder.append("-").append(homeId); + } + + String serialNo = tdr.getSerialNo(); + if (serialNo != null) { + filenameBuilder.append("-").append(serialNo); + } + filenameBuilder.append("-").append(tdr.getDataFilename()); + + String filename = filenameBuilder.toString(); + return filename; + + + } + + @Override + public Tdr loadForDisplay(String tdrId) { + return null; + } + + @Override + public Tdr loadForEdit(String tdrId) { + return null; + } + + @Override + public Tdr preCreate(String tripLonglineId) { + return null; + } + + @Override + public Tdr save(String setLonglineId, Tdr toSave) { + return null; + } + + @Override + public void delete(String setLonglineId, String tdrId) { + + } + + @Override + public TopiaEntityBinder<Tdr> getBinderForEdit() { + return null; + } + + @Override + public void copyForEdit(Tdr source, Tdr target) { + + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java new file mode 100644 index 0000000..b39e076 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java @@ -0,0 +1,42 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface TripLonglineService extends ObserveService { + + List<TripLongline> getTripLonglineStubByProgram(String programId); + + TripLongline getTripLonglineStub(String tripId); + + List<TripLongline> loadAllByProgramForDisplay(String programId); + + TripLongline loadForDisplay(String tripLonglineId); + + TripLongline loadForEdit(String tripLonglineId); + + TripLongline preCreate(String programId); + + @Commit + TripLongline save(TripLongline toSave); + + @Commit + void delete(String tripLonglineId); + + @NoTransaction + TopiaEntityBinder<TripLongline> getBinderForEdit(); + + @NoTransaction + void copyForEdit(TripLongline source, TripLongline target); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java new file mode 100644 index 0000000..7a93264 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -0,0 +1,201 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.longline.ActivityLonglines; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.TripLonglineDAO; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.DateUtil; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.Date; +import java.util.List; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class TripLonglineServiceImpl extends AbstractObserveService implements TripLonglineService { + + @Override + public List<TripLongline> getTripLonglineStubByProgram(String programId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + List<TripLongline> result = getDao().findAllStubByProgramId(programId, referentielLocale); + return result; + + } + + @Override + public TripLongline getTripLonglineStub(String tripId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + TripLongline result = getDao().findStubByTopiaId(tripId, referentielLocale); + return result; + + } + + @Override + public List<TripLongline> loadAllByProgramForDisplay(String programId) { + + ReferenceLocale referenceLocale = getReferentielLocale(); + List<TripLongline> loaded = getDao().findAllStubByProgramId(programId, referenceLocale); + return loaded; + + } + + @Override + public TripLongline loadForDisplay(String tripLonglineId) { + + TripLongline loaded = getDao().newInstance(); + TripLongline toLoad = getDao().findByTopiaId(tripLonglineId); + copyForEdit(toLoad, loaded); + + if (!loaded.isActivityLonglineEmpty()) { + + // on force le trie des routes + ActivityLonglines.sort(loaded.getActivityLongline()); + + } + + return loaded; + + } + + @Override + public TripLongline loadForEdit(String tripLonglineId) { + + TripLongline loaded = loadForDisplay(tripLonglineId); + + if (loaded.getEndDate() == null) { + Date date = DateUtil.getEndOfDay(now()); + loaded.setEndDate(date); + } + + return loaded; + + } + + @Override + public TripLongline preCreate(String programId) { + + Program program = findByTopiaId(Program.class, programId); + + TripLongline preCreated = getDao().newInstance(); + + Date date = DateUtil.getDay(now()); + preCreated.setStartDate(date); + preCreated.setEndDate(date); + preCreated.setProgram(program); + + return preCreated; + + } + + @Override + public TripLongline save(TripLongline toSave) { + + Date startDate = DateUtil.getDay(toSave.getStartDate()); + toSave.setStartDate(startDate); + + // mise a jour de la date de fin + toSave.updateDateFin(); + + TripLongline saved; + + if (toSave.getTopiaId() == null) { + + // create + saved = create(toSave); + + } else { + + // update + saved = update(toSave); + + } + + return saved; + + } + + @Override + public void delete(String tripLonglineId) { + + TripLonglineDAO dao = getDao(); + TripLongline toDelete = dao.findByTopiaId(tripLonglineId); + dao.delete(toDelete); + + } + + @Override + public TopiaEntityBinder<TripLongline> getBinderForEdit() { + + TopiaEntityBinder<TripLongline> r = loadBinder("-forEdit", TripLongline.class, new CreateBinder<TripLongline>() { + + @Override + public BinderModelBuilder<TripLongline, TripLongline> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<TripLongline, TripLongline> builder = binderService.newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_START_DATE, + TripLongline.PROPERTY_END_DATE, + TripLongline.PROPERTY_TRIP_TYPE, + TripLongline.PROPERTY_HOME_ID, + TripLongline.PROPERTY_COMMENT, + TripLongline.PROPERTY_VESSEL, + TripLongline.PROPERTY_OBSERVER, + TripLongline.PROPERTY_CAPTAIN, + TripLongline.PROPERTY_DATA_ENTRY_OPERATOR, + TripLongline.PROPERTY_TOTAL_FISHING_OPERATIONS_NUMBER, + TripLongline.PROPERTY_OCEAN, + TripLongline.PROPERTY_DEPARTURE_HARBOUR, + TripLongline.PROPERTY_LANDING_HARBOUR, + TripLongline.PROPERTY_PROGRAM, + TripLongline.PROPERTY_ACTIVITY_LONGLINE, + TripLongline.PROPERTY_OPEN); + + // on ajoute la recopie de l'association route + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + + return builder; + } + + }); + + return r; + + } + + @Override + public void copyForEdit(TripLongline source, TripLongline target) { + + getBinderForEdit().load(source, target, true); + + } + + protected TripLongline create(TripLongline toCreate) { + + TripLonglineDAO dao = getDao(); + TripLongline created = dao.create(toCreate); + return created; + + } + + protected TripLongline update(TripLongline toUpdate) { + + TripLonglineDAO dao = getDao(); + TripLongline updated = dao.findByTopiaId(toUpdate.getTopiaId()); + getBinderForEdit().copyExcluding(toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + return updated; + + } + + protected TripLonglineDAO getDao() { + return (TripLonglineDAO) getDao(TripLongline.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java new file mode 100644 index 0000000..e000e6e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java @@ -0,0 +1,47 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ActivitySeineService extends ObserveService { + + ActivitySeine getActivitySeineStub(String activitySeineId); + + List<ActivitySeine> getActivitySeineStubByRoute(String routeId); + + List<ActivitySeine> loadAllByRouteForDisplay(String routeId); + + ActivitySeine loadForDisplay(String activitySeineId); + + ActivitySeine loadForEdit(String activitySeineId); + + ActivitySeine loadForEditObservedSystem(String activitySeineId); + + ActivitySeine preCreate(String tripLonglineId); + + @Commit + ActivitySeine save(String routeId, ActivitySeine toSave); + + @Commit + void updateObservedSystem(ActivitySeine toUpdate); + + @Commit + void delete(String routeId, String activitySeineId); + + @NoTransaction + TopiaEntityBinder<ActivitySeine> getBinderForEdit(); + + @NoTransaction + void copyForEdit(ActivitySeine source, ActivitySeine target); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java new file mode 100644 index 0000000..7478d41 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -0,0 +1,255 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.FpaZone; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.ActivitySeineDAO; +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.DateUtil; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.Date; +import java.util.List; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ActivitySeineServiceImpl extends AbstractObserveService implements ActivitySeineService { + + @Override + public List<ActivitySeine> getActivitySeineStubByRoute(String routeId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + List<ActivitySeine> result = getDao().findAllStubByRouteId(routeId, referentielLocale); + return result; + + } + + @Override + public ActivitySeine getActivitySeineStub(String activityId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + ActivitySeine result = getDao().findStubByTopiaId(activityId, referentielLocale); + return result; + + } + + @Override + public List<ActivitySeine> loadAllByRouteForDisplay(String routeId) { + + List<ActivitySeine> loaded = getDao().findAllStubByRouteId(routeId, getReferentielLocale()); + return loaded; + + } + + @Override + public ActivitySeine loadForDisplay(String activitySeineId) { + + ActivitySeine loaded = getDao().newInstance(); + ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); + copyForEdit(toLoad, loaded); + + return loaded; + + } + + @Override + public ActivitySeine loadForEdit(String activitySeineId) { + + ActivitySeine loaded = loadForDisplay(activitySeineId); + return loaded; + + } + + @Override + public ActivitySeine loadForEditObservedSystem(String activitySeineId) { + + ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); + ActivitySeine loaded = getDao().newInstance(); + //TODO + return loaded; + } + + @Override + public ActivitySeine preCreate(String routeId) { + + Route tripLongline = findByTopiaId(Route.class, routeId); + + ActivitySeine preCreated = getDao().newInstance(); + + preCreated.setOpen(true); + + ActivitySeine lastActivitySeine = tripLongline.getLastActivity(); + + Date time; + + FpaZone currentFpaZone = null; + + if (lastActivitySeine == null) { + + // première activité, on utilise l'heure courante + time = new Date(); + + } else { + + // passage en coordonnées absolue + quadrant + lastActivitySeine.initCoordinates(); + + // on recupère le quadrant de cette activity + // et on l'affecte à la nouvelle activity + Integer quadrant = lastActivitySeine.getQuadrant(); + if (quadrant != null) { + + preCreated.setQuadrant(quadrant); + + } + + // on reprend l'heure de la dernière activité + time = lastActivitySeine.getTime(); + + // utilisation des zones fpa de la dernière activité + currentFpaZone = lastActivitySeine.getNextFpaZone(); + if (currentFpaZone == null) { + currentFpaZone = lastActivitySeine.getCurrentFpaZone(); + } + + } + + preCreated.setTime(DateUtil.getTime(time, false, false)); + preCreated.setCurrentFpaZone(currentFpaZone); + + return preCreated; + + } + + @Override + public void updateObservedSystem(ActivitySeine toUpdate) { + + //TODO + } + + @Override + public ActivitySeine save(String routeId, ActivitySeine toSave) { + + ActivitySeine saved; + + if (toSave.getTopiaId() == null) { + + // create + saved = create(routeId, toSave); + + } else { + + // update + saved = update(routeId, toSave); + + } + + return saved; + + } + + @Override + public void delete(String routeId, String activitySeineId) { + + ActivitySeineDAO dao = getDao(); + ActivitySeine toDelete = dao.findByTopiaId(activitySeineId); + + Route route = findByTopiaId(Route.class, routeId); + route.removeActivitySeine(toDelete); + + } + + @Override + public TopiaEntityBinder<ActivitySeine> getBinderForEdit() { + + TopiaEntityBinder<ActivitySeine> binder = loadBinder("-forEdit", ActivitySeine.class, new CreateBinder<ActivitySeine>() { + + @Override + public BinderModelBuilder<ActivitySeine, ActivitySeine> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_QUADRANT, + ActivitySeine.PROPERTY_LATITUDE, + ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_ERS_ID, + ActivitySeine.PROPERTY_TIME, + ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_COMMENT, + ActivitySeine.PROPERTY_VESSEL_SPEED, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, + ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, + ActivitySeine.PROPERTY_WIND, + ActivitySeine.PROPERTY_DETECTION_MODE, + ActivitySeine.PROPERTY_SET_SEINE, + ActivitySeine.PROPERTY_FLOATING_OBJECT, + ActivitySeine.PROPERTY_OPEN, + ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, + ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, + ActivitySeine.PROPERTY_NEXT_FPA_ZONE); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); + + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEdit(ActivitySeine source, ActivitySeine target) { + + getBinderForEdit().load(source, target, true); + + } + + protected ActivitySeine create(String routeId, ActivitySeine toCreate) { + + ActivitySeineDAO dao = getDao(); + ActivitySeine created = dao.create(toCreate); + + Route route = findByTopiaId(Route.class, routeId); + route.addActivitySeine(created); + + return created; + + } + + protected ActivitySeine update(String routeId, ActivitySeine toUpdate) { + + Route route = findByTopiaId(Route.class, routeId); + Date d = DateUtil.getDateAndTime(route.getDate(), toUpdate.getTime(), false, false); + + toUpdate.setTime(d); + + ActivitySeineDAO dao = getDao(); + ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); + getBinderForEdit().copyExcluding(toUpdate, updated, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_FLOATING_OBJECT); + return updated; + + } + + protected ActivitySeineDAO getDao() { + return (ActivitySeineDAO) getDao(ActivitySeine.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java new file mode 100644 index 0000000..8e9d42a --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java @@ -0,0 +1,38 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface FloatingObjectService extends ObserveService { + + List<FloatingObject> getFloatinObjectStubByActivitySeine(String activitySeineId); + + FloatingObject getFloatinObjectStub(String id); + + FloatingObject loadForEdit(String floatingObjectId); + + FloatingObject loadForEditTransmittingBuoy(String floatingObjectId); + + FloatingObject preCreate(String routeId); + + @Commit + FloatingObject create(FloatingObject toCreate); + + @Commit + void update(FloatingObject toUpdate); + + @Commit + void updateTransmittingBuoy(FloatingObject toUpdate); + + @Commit + void delete(String floatingObjectId); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java similarity index 50% rename from observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java rename to observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index 676b33a..bc1f78f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -1,12 +1,11 @@ -package fr.ird.observe.services.seine; +package fr.ird.observe.services.data.seine; -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataSource; +import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.FloatingObjectDAO; import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; + +import java.util.List; /** * Created on 4/24/15. @@ -14,45 +13,65 @@ import org.nuiton.topia.persistence.TopiaDAO; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class FloatingObjectServiceImpl extends AbstractObserveService<FloatingObject> { +public class FloatingObjectServiceImpl extends AbstractObserveService implements FloatingObjectService { + + @Override + public List<FloatingObject> getFloatinObjectStubByActivitySeine(String activitySeineId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + List<FloatingObject> result = getDao().findAllStubByActivityId(activitySeineId, referentielLocale); + return result; - public FloatingObjectServiceImpl(DataSource dataSource) { - super(FloatingObject.class, dataSource); } @Override - protected TopiaDAO<FloatingObject> getDao(TopiaContext tx) throws TopiaException { - return ObserveDAOHelper.getFloatingObjectDAO(tx); + public FloatingObject getFloatinObjectStub(String floatingObjectId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + FloatingObject result = getDao().findStubByTopiaId(floatingObjectId, referentielLocale); + return result; + } + @Override public FloatingObject loadForEdit(String floatingObjectId) { FloatingObject loaded = null; return loaded; } + @Override public FloatingObject loadForEditTransmittingBuoy(String floatingObjectId) { FloatingObject loaded = null; return loaded; } + @Override public FloatingObject preCreate(String routeId) { FloatingObject result = null; return result; } + @Override public FloatingObject create(FloatingObject toCreate) { FloatingObject created = null; return created; } + @Override public void update(FloatingObject toUpdate) { } + @Override public void updateTransmittingBuoy(FloatingObject toUpdate) { } + @Override public void delete(String floatingObjectId) { } + protected FloatingObjectDAO getDao() { + return (FloatingObjectDAO) getDao(FloatingObject.class); + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java new file mode 100644 index 0000000..23a4565 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java @@ -0,0 +1,25 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface GearUseFeaturesSeineService extends ObserveService { + + List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(String gearId); + + List<GearUseFeaturesMeasurementSeine> loadGearUseFeaturesMeasurementSeineForEdit(String gearUseFeaturesSeineId); + + @NoTransaction + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeineBinderForEdit(); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java new file mode 100644 index 0000000..ecb28cd --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -0,0 +1,90 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.referentiel.Gear; +import fr.ird.observe.entities.referentiel.GearCaracteristic; +import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; +import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineDAO; +import fr.ird.observe.entities.seine.GearUseFeaturesSeine; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService implements GearUseFeaturesSeineService { + + @Override + public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(String gearId) { + + GearUseFeaturesMeasurementSeineDAO dao = getDao(); + Gear gear = findByTopiaId(Gear.class, gearId); + + Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); + List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); + for (GearCaracteristic caracteristic : gearCaracteristic) { + GearUseFeaturesMeasurementSeine target = dao.newInstance(); + target.setGearCaracteristic(caracteristic); + result.add(target); + } + + return result; + + } + + @Override + public List<GearUseFeaturesMeasurementSeine> loadGearUseFeaturesMeasurementSeineForEdit(String gearUseFeaturesSeineId) { + + GearUseFeaturesMeasurementSeineDAO dao = getDao(); + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getGearUseFeaturesMeasurementSeineBinderForEdit(); + + GearUseFeaturesSeine gearUseFeaturesSeine = findByTopiaId(GearUseFeaturesSeine.class, gearUseFeaturesSeineId); + List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); + + for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { + GearUseFeaturesMeasurementSeine target = dao.newInstance(); + measurementSource.getGearCaracteristic().getGearCaracteristicType(); + binder.load(measurementSource, target, true); + result.add(target); + } + + return result; + + } + + @Override + public TopiaEntityBinder<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeineBinderForEdit() { + + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> r = loadBinder("-forEdit", GearUseFeaturesMeasurementSeine.class, new CreateBinder<GearUseFeaturesMeasurementSeine>() { + + @Override + public BinderModelBuilder<GearUseFeaturesMeasurementSeine, GearUseFeaturesMeasurementSeine> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<GearUseFeaturesMeasurementSeine, GearUseFeaturesMeasurementSeine> builder = + binderService.newBinderBuilder(GearUseFeaturesMeasurementSeine.class, + GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, + GearUseFeaturesMeasurementSeine.PROPERTY_MEASUREMENT_VALUE); + + return builder; + + } + + }); + + return r; + + } + + protected GearUseFeaturesMeasurementSeineDAO getDao() { + return (GearUseFeaturesMeasurementSeineDAO) getDao(GearUseFeaturesMeasurementSeine.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java new file mode 100644 index 0000000..6464335 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java @@ -0,0 +1,28 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.services.ObserveService; + +import java.util.Collection; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface NonTargetSampleService extends ObserveService { + + List<Species> getAvailableEspeceForNonTargetSample(String setSeineId); + + String getNonTargetSampleId(String setSeineId); + + boolean canUseNonTargetSample(String setSeineId); + + void getObsoleteEspeceForNonTargetSample(String setSeineId, + List<Species> speciessUsed, + Collection<Species> speciessToDelete, + List<NonTargetLength> tailleToDelete); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java new file mode 100644 index 0000000..d3c700a --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -0,0 +1,116 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.seine.NonTargetCatch; +import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.entities.seine.NonTargetSample; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class NonTargetSampleServiceImpl extends AbstractObserveService implements NonTargetSampleService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(NonTargetSampleServiceImpl.class); + + @Override + public List<Species> getAvailableEspeceForNonTargetSample(String setSeineId) { + + List<Species> speciesList = new ArrayList<Species>(); + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + + // on recupere la liste des espèces faune utilisees dans le rejet + Collection<NonTargetCatch> nonTargetCatches = setSeine.getNonTargetCatch(); + + if (nonTargetCatches != null) { + + for (NonTargetCatch nonTargetCatch : nonTargetCatches) { + // on retient toute les espèces (capturées ou rejetées) + if (!speciesList.contains(nonTargetCatch.getSpecies())) { + speciesList.add(nonTargetCatch.getSpecies()); + } + } + + } + + return speciesList; + + } + + @Override + public String getNonTargetSampleId(String setSeineId) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + + String nonTargetSampleId; + + if (setSeine.isNonTargetSampleEmpty()) { + + nonTargetSampleId = null; + + } else { + + List<NonTargetSample> nonTargetSamples = setSeine.getNonTargetSample(); + nonTargetSampleId = nonTargetSamples.get(0).getTopiaId(); + + } + + return nonTargetSampleId; + + } + + @Override + public boolean canUseNonTargetSample(String setSeineId) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + return setSeine.canUseNonTargetSample(); + + } + + @Override + public void getObsoleteEspeceForNonTargetSample(String setSeineId, + List<Species> speciessUsed, + Collection<Species> speciessToDelete, + List<NonTargetLength> tailleToDelete) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + + if (setSeine.isNonTargetSampleEmpty()) { + return; + } + + NonTargetSample echantillon = setSeine.getNonTargetSample().get(0); + + if (echantillon.isNonTargetLengthEmpty()) { + return; + } + + for (NonTargetLength taille : echantillon.getNonTargetLength()) { + Species tailleEspece = taille.getSpecies(); + if (!speciessUsed.contains(tailleEspece)) { + // l'species n'existe plus dans les rejet faune, + // on doit le supprimer + tailleToDelete.add(taille); + speciessToDelete.add(tailleEspece); + if (log.isDebugEnabled()) { + log.debug("remove obsolote echantillon " + taille + " for species " + tailleEspece); + } + } + } + + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java new file mode 100644 index 0000000..af91248 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java @@ -0,0 +1,40 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface RouteService extends ObserveService { + + List<Route> getRouteStubByTrip(String tripSeineId); + + Route getRouteStub(String routeId); + + Route loadForDisplay(String routeId); + + Route loadForEdit(String routeId); + + Route preCreate(String tripSeineId); + + @Commit + Route save(String tripSeineId, Route toSave); + + @Commit + void delete(String tripSeineId, String routeId); + + @NoTransaction + TopiaEntityBinder<Route> getBinderForEdit(); + + @NoTransaction + void copyForEdit(Route source, Route target); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java new file mode 100644 index 0000000..fc6a459 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -0,0 +1,237 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.ActivitySeines; +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.RouteDAO; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.lang3.time.DateUtils; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.DateUtil; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.Date; +import java.util.List; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class RouteServiceImpl extends AbstractObserveService implements RouteService { + + @Override + public List<Route> getRouteStubByTrip(String tripSeineId) { + + List<Route> result = getDao().findAllStubByTripId(tripSeineId); + return result; + + } + + @Override + public Route getRouteStub(String routeId) { + + Route result = getDao().findStubByTopiaId(routeId); + return result; + + } + + @Override + public Route loadForDisplay(String routeId) { + + Route loaded = getDao().newInstance(); + Route toLoad = getDao().findByTopiaId(routeId); + copyForEdit(toLoad, loaded); + + if (!loaded.isActivitySeineEmpty()) { + + // on force le trie des activites + ActivitySeines.sort(loaded.getActivitySeine()); + } + + return loaded; + + } + + @Override + public Route loadForEdit(String routeId) { + Route loaded = loadForDisplay(routeId); + return loaded; + } + + @Override + public Route preCreate(String tripSeineId) { + + TripSeine tripLongline = findByTopiaId(TripSeine.class, tripSeineId); + + Route preCreated = getDao().newInstance(); + + preCreated.setOpen(true); + + Route lastRoute = tripLongline.getLastRoute(); + + Date date; + if (lastRoute == null) { + + // aucune route defini, on utilise la date courante + date = now(); + + } else { + + // une route precedente est definie sur la maree + // le jour d'observation est le jour suivant celui de la + // derniere route + date = DateUtils.addDays(lastRoute.getDate(), 1); + + // le loch du matin est le loch du soir de la derniere route + preCreated.setStartLogValue(lastRoute.getEndLogValue()); + } + + preCreated.setDate(DateUtil.getDay(date)); + + return preCreated; + + } + + @Override + public Route save(String tripSeineId, Route toSave) { + + Route saved; + + // on sauvegarde toujours en debut de jour + Date date = DateUtil.getDay(toSave.getDate()); + toSave.setDate(date); + + if (toSave.getTopiaId() == null) { + + // create + saved = create(tripSeineId, toSave); + + } else { + + // update + saved = update(tripSeineId, toSave); + + } + + return saved; + + } + + @Override + public void delete(String tripSeineId, String routeId) { + + RouteDAO dao = getDao(); + Route toDelete = dao.findByTopiaId(routeId); + + TripSeine tripSeine = findByTopiaId(TripSeine.class, tripSeineId); + tripSeine.removeRoute(toDelete); + tripSeine.updateDateFin(); + + dao.delete(toDelete); + + } + + @Override + public TopiaEntityBinder<Route> getBinderForEdit() { + + TopiaEntityBinder<Route> binder = loadBinder("-forEdit", Route.class, new CreateBinder<Route>() { + + @Override + public BinderModelBuilder<Route, Route> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<Route, Route> builder = binderService.newBinderBuilder( + Route.class, + Route.PROPERTY_DATE, + Route.PROPERTY_START_LOG_VALUE, + Route.PROPERTY_END_LOG_VALUE, + Route.PROPERTY_CHECK_LEVEL, + Route.PROPERTY_ACTIVITY_SEINE, + Route.PROPERTY_OPEN, + Route.PROPERTY_COMMENT); + + BinderModelBuilder<ActivitySeine, ActivitySeine> builder2 = binderService.newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_QUADRANT, + ActivitySeine.PROPERTY_LATITUDE, + ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_TIME, + ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_WIND, + ActivitySeine.PROPERTY_OPEN); + + TopiaEntityBinder<ActivitySeine> binder2 = + binderService.registerTopiaBinder(ActivitySeine.class, builder2, name); + + builder.addCollectionBinder(binder2, Route.PROPERTY_ACTIVITY_SEINE); + + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEdit(Route source, Route target) { + + getBinderForEdit().load(source, target, true); + + } + + protected Route create(String tripSeineId, Route toCreate) { + + RouteDAO dao = getDao(); + Route created = dao.create(toCreate); + + TripSeine tripSeine = findByTopiaId(TripSeine.class, tripSeineId); + tripSeine.addRoute(created); + + // on met a jour si necessaire la date de fin de la maree + tripSeine.updateDateFin(); + + return created; + + } + + protected Route update(String tripSeineId, Route toUpdate) { + + RouteDAO dao = getDao(); + Route updated = dao.findByTopiaId(toUpdate.getTopiaId()); + + // on conserve l'ancienne date d'observation + Date oldDate = DateUtil.getDay(toUpdate.getDate()); + + // recopie des propriétés vers le bean a sauver + getBinderForEdit().copyExcluding(toUpdate, updated, Route.PROPERTY_ACTIVITY_SEINE); + + if (!oldDate.equals(toUpdate.getDate())) { + + //FIXME Faire cela avec une requete sql, sinon ca charge trop de données + // le jour a change, il faut mettre à jour les dates des activites et des calees + updated.updateDates(); + + } + + TripSeine tripSeine = findByTopiaId(TripSeine.class, tripSeineId); + + // on met a jour si necessaire la date de fin de la maree + tripSeine.updateDateFin(); + + return updated; + + } + + protected RouteDAO getDao() { + return (RouteDAO) getDao(Route.class); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java new file mode 100644 index 0000000..b646c2e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java @@ -0,0 +1,38 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.Date; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface SetSeineService extends ObserveService { + + SetSeine loadSet(String setSeineId); + + Date getRouteDate(String routeId); + + SetSeine loadForEdit(String setSeineId); + + SetSeine preCreate(String routeId, String activitySeineId); + + @Commit + SetSeine save(String activitySeineId, SetSeine toSave); + + @Commit + void delete(String activitySeineId, String setSeineId); + + @NoTransaction + TopiaEntityBinder<SetSeine> getBinderForEdit(); + + @NoTransaction + void copyForEdit(SetSeine source, SetSeine target); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java new file mode 100644 index 0000000..e012079 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java @@ -0,0 +1,206 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.constants.seine.SchoolType; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.NonTargetSample; +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.SetSeineDAO; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.DateUtil; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.Date; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class SetSeineServiceImpl extends AbstractObserveService implements SetSeineService { + + @Override + public SetSeine loadSet(String setSeineId) { + return null; + } + + @Override + public Date getRouteDate(String routeId) { + + Route route = findByTopiaId(Route.class, routeId); + Date date = route.getDate(); + return date; + + } + + @Override + public SetSeine loadForEdit(String setSeineId) { + + SetSeine loaded = getDao().newInstance(); + SetSeine toLoad = getDao().findByTopiaId(setSeineId); + copyForEdit(toLoad, loaded); + + //FIXME See why need this ? + if (!loaded.isTargetSampleEmpty()) { + for (TargetSample e : loaded.getTargetSample()) { + e.isTargetLengthEmpty(); + } + } + + //FIXME See why need this ? + if (!loaded.isNonTargetSampleEmpty()) { + for (NonTargetSample e : loaded.getNonTargetSample()) { + e.isNonTargetLengthEmpty(); + } + } + + return loaded; + + } + + + @Override + public SetSeine preCreate(String routeId, String activitySeineId) { + + ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); + + // on utilise l'heure de l'activité comme début de calée + Date date = DateUtil.getTime(activitySeine.getTime(), false, false); + + SetSeine preCreated = getDao().newInstance(); + + preCreated.setStartTime(date); + + // pour les dates de fin on utilise la date de la route + Date routeDate = getRouteDate(routeId); + + preCreated.setEndSetTimeStamp(date); + preCreated.setEndPursingTimeStamp(date); + + preCreated.setEndSetDate(routeDate); + preCreated.setEndPursingDate(routeDate); + + // recuperation du type de set a partir de l'activity + SchoolType schoolType = activitySeine.getSchoolType(); + preCreated.setSchoolType(schoolType); + + return preCreated; + + } + + @Override + public SetSeine save(String activitySeineId, SetSeine toSave) { + + SetSeine saved; + + if (toSave.getTopiaId() == null) { + + // create + saved = create(activitySeineId, toSave); + + } else { + + // update + saved = update(toSave); + + } + + return saved; + + } + + + @Override + public void delete(String activitySeineId, String setSeineId) { + + // on doit supprimer physiquement la set + // car il n'y a pas de delete-orphan sur une telle + // relation + SetSeineDAO dao = getDao(); + SetSeine setSeine = dao.findByTopiaId(setSeineId); + dao.delete(setSeine); + + // supprime la reference sur l'activity + ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); + activitySeine.setSetSeine(null); + + } + + @Override + public TopiaEntityBinder<SetSeine> getBinderForEdit() { + + TopiaEntityBinder<SetSeine> binder = loadBinder("-forEdit", SetSeine.class, new CreateBinder<SetSeine>() { + + @Override + public BinderModelBuilder<SetSeine, SetSeine> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<SetSeine, SetSeine> builder = binderService.newBinderBuilder( + SetSeine.class, + SetSeine.PROPERTY_COMMENT, + SetSeine.PROPERTY_SUPPORT_VESSEL_NAME, + SetSeine.PROPERTY_START_TIME, + SetSeine.PROPERTY_END_SET_TIME_STAMP, + SetSeine.PROPERTY_END_PURSING_TIME_STAMP, + SetSeine.PROPERTY_CURRENT_DIRECTION, + SetSeine.PROPERTY_CURRENT_SPEED, + SetSeine.PROPERTY_REASON_FOR_NULL_SET, + SetSeine.PROPERTY_SCHOOL_THICKNESS, + SetSeine.PROPERTY_MAX_GEAR_DEPTH, + SetSeine.PROPERTY_SCHOOL_MEAN_DEPTH, + SetSeine.PROPERTY_SCHOOL_TOP_DEPTH, + SetSeine.PROPERTY_CURRENT_MEASURE_DEPTH, + SetSeine.PROPERTY_TARGET_DISCARDED, + SetSeine.PROPERTY_NON_TARGET_DISCARDED, + SetSeine.PROPERTY_SCHOOL_TYPE, + SetSeine.PROPERTY_SONAR_USED, + SetSeine.PROPERTY_TARGET_SAMPLE, + SetSeine.PROPERTY_NON_TARGET_SAMPLE); + + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEdit(SetSeine source, SetSeine target) { + + getBinderForEdit().load(source, target, true); + + } + + protected SetSeineDAO getDao() { + return (SetSeineDAO) getDao(SetSeine.class); + } + + protected SetSeine create(String activitySeineId, SetSeine toCreate) { + + SetSeineDAO dao = getDao(); + SetSeine created = dao.create(toCreate); + + ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); + activitySeine.setSetSeine(created); + + return created; + + } + + protected SetSeine update(SetSeine toUpdate) { + + SetSeine updated = getDao().findByTopiaId(toUpdate.getTopiaId()); + getBinderForEdit().copyExcluding(toUpdate, updated, + SetSeine.PROPERTY_TARGET_SAMPLE, + SetSeine.PROPERTY_NON_TARGET_SAMPLE); + return updated; + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java new file mode 100644 index 0000000..84fb0e4 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java @@ -0,0 +1,30 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.services.ObserveService; + +import java.util.Collection; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface TargetSampleService extends ObserveService { + + List<Species> getAvailableEspeceForTargetSample(String setSeineId, boolean discarded); + + String getTargetSampleId(String setSeineId, boolean discarded); + + boolean canUseTargetSample(String setSeineId, boolean discarded); + + void getObsoleteEspeceForTargetSample(String setSeineId, + Collection<Species> speciessUsed, + Collection<Species> speciessToDelete, + List<TargetLength> tailleToDelete, + boolean discarded); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java new file mode 100644 index 0000000..b9d8aaa --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -0,0 +1,142 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.TargetCatch; +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Created on 4/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TargetSampleServiceImpl extends AbstractObserveService implements TargetSampleService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(TargetSampleServiceImpl.class); + + @Override + public List<Species> getAvailableEspeceForTargetSample(String setSeineId, boolean discarded) { + + List<Species> speciesList = new ArrayList<Species>(); + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + + // on recupere la liste des espèces thon utilisees dans le rejet + Collection<TargetCatch> targetCatches = setSeine.getTargetCatch(); + + // on filtre sur les espèces montées sur le pont et rejetées + + if (targetCatches != null) { + + for (TargetCatch targetCatch : targetCatches) { + + boolean keep; + + if (discarded) { + + // on ne conserve que les espèces rejectées montées sur le pont + keep = targetCatch.isDiscarded() && targetCatch.getBroughtOnDeck(); + + } else { + + // on ne conserve que les espèces rejectées + keep = !targetCatch.isDiscarded(); + } + + if (keep && + !speciesList.contains(targetCatch.getWeightCategory().getSpecies())) { + speciesList.add(targetCatch.getWeightCategory().getSpecies()); + } + + } + + } + + return speciesList; + + } + + + @Override + public String getTargetSampleId(String setSeineId, boolean discarded) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + + String targetSampleId = null; + + if (!setSeine.isNonTargetSampleEmpty()) { + + List<TargetSample> targetSamples = setSeine.getTargetSample(); + for (TargetSample targetSample : targetSamples) { + + Boolean isDiscarded = targetSample.getDiscarded(); + + if (discarded) { + if (isDiscarded != null && isDiscarded) { + targetSampleId = targetSample.getTopiaId(); + } + } else if (isDiscarded == null || !isDiscarded) { + targetSampleId = targetSample.getTopiaId(); + } + + } + + } + + return targetSampleId; + + } + + @Override + public boolean canUseTargetSample(String setSeineId, boolean discarded) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + return setSeine.canUseTargetSample(discarded); + + } + + @Override + public void getObsoleteEspeceForTargetSample(String setSeineId, + Collection<Species> speciessUsed, + Collection<Species> speciessToDelete, + List<TargetLength> tailleToDelete, + boolean discarded) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); + + if (setSeine.isTargetSampleEmpty()) { + return; + } + + TargetSample echantillon = setSeine.getTargetSample(discarded); + + if (echantillon == null || echantillon.isTargetLengthEmpty()) { + return; + } + + for (TargetLength taille : echantillon.getTargetLength()) { + Species tailleEspece = taille.getSpecies(); + if (!speciessUsed.contains(tailleEspece)) { + // l'species n'existe plus dans les rejet faune, + // on doit le supprimer + tailleToDelete.add(taille); + speciessToDelete.add(tailleEspece); + if (log.isDebugEnabled()) { + log.debug("remove obsolote echantillon " + taille + " for species " + tailleEspece); + } + } + } + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java new file mode 100644 index 0000000..bd16f3e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java @@ -0,0 +1,42 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface TripSeineService extends ObserveService { + + List<TripSeine> getTripSeineStubByProgram(String programId); + + TripSeine getTripSeineStub(String tripSeineId); + + List<TripSeine> loadAllByProgramForDisplay(String programId); + + TripSeine loadForDisplay(String tripSeineId); + + TripSeine loadForEdit(String tripSeineId); + + TripSeine preCreate(String programId); + + @Commit + TripSeine save(TripSeine toSave); + + @Commit + void delete(String tripSeineId); + + @NoTransaction + TopiaEntityBinder<TripSeine> getBinderForEdit(); + + @NoTransaction + void copyForEdit(TripSeine source, TripSeine target); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java new file mode 100644 index 0000000..0d99d82 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -0,0 +1,203 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.entities.seine.Routes; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.entities.seine.TripSeineDAO; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.DateUtil; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.Date; +import java.util.List; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TripSeineServiceImpl extends AbstractObserveService implements TripSeineService { + + protected TripSeineDAO getDao() { + return (TripSeineDAO) getDao(TripSeine.class); + } + + @Override + public List<TripSeine> getTripSeineStubByProgram(String programId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + List<TripSeine> result = getDao().findAllStubByProgramId(programId, referentielLocale); + return result; + + } + + @Override + public TripSeine getTripSeineStub(String tripId) { + + ReferenceLocale referentielLocale = getReferentielLocale(); + TripSeine result = getDao().findStubByTopiaId(tripId, referentielLocale); + return result; + + } + + @Override + public List<TripSeine> loadAllByProgramForDisplay(String programId) { + + ReferenceLocale referenceLocale = getReferentielLocale(); + List<TripSeine> loaded = getDao().findAllStubByProgramId(programId, referenceLocale); + return loaded; + + } + + @Override + public TripSeine loadForDisplay(String tripSeineId) { + + TripSeine loaded = getDao().newInstance(); + TripSeine toLoad = getDao().findByTopiaId(tripSeineId); + copyForEdit(toLoad, loaded); + + if (!loaded.isRouteEmpty()) { + + // on force le trie des routes + Routes.sort(loaded.getRoute()); + } + + return loaded; + + } + + @Override + public TripSeine loadForEdit(String tripSeineId) { + + TripSeine loaded = loadForDisplay(tripSeineId); + if (loaded.getEndDate() == null) { + Date date = DateUtil.getEndOfDay(now()); + loaded.setEndDate(date); + } + + return loaded; + + } + + @Override + public TripSeine preCreate(String programId) { + + Program program = findByTopiaId(Program.class, programId); + + TripSeine preCreated = getDao().newInstance(); + + Date date = DateUtil.getDay(now()); + preCreated.setStartDate(date); + preCreated.setEndDate(date); + preCreated.setProgram(program); + + return preCreated; + + } + + @Override + public TripSeine save(TripSeine toSave) { + + // on force toujours la date a etre sans heure, minute,... + Date startDate = DateUtil.getDay(toSave.getStartDate()); + toSave.setStartDate(startDate); + + // mise a jour de la date de fin + toSave.updateDateFin(); + + TripSeine saved; + + if (toSave.getTopiaId() == null) { + + // create + saved = create(toSave); + + } else { + + // update + saved = update(toSave); + + } + + return saved; + + } + + @Override + public void delete(String tripSeineId) { + + TripSeineDAO dao = getDao(); + TripSeine toDelete = dao.findByTopiaId(tripSeineId); + dao.delete(toDelete); + + } + + @Override + public TopiaEntityBinder<TripSeine> getBinderForEdit() { + + TopiaEntityBinder<TripSeine> r = loadBinder("-forEdit", TripSeine.class, new CreateBinder<TripSeine>() { + + @Override + public BinderModelBuilder<TripSeine, TripSeine> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<TripSeine, TripSeine> builder = binderService.newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_START_DATE, + TripSeine.PROPERTY_END_DATE, + TripSeine.PROPERTY_FORMS_URL, + TripSeine.PROPERTY_REPORTS_URL, + TripSeine.PROPERTY_COMMENT, + TripSeine.PROPERTY_VESSEL, + TripSeine.PROPERTY_OBSERVER, + TripSeine.PROPERTY_CAPTAIN, + TripSeine.PROPERTY_DATA_ENTRY_OPERATOR, + TripSeine.PROPERTY_OCEAN, + TripSeine.PROPERTY_DEPARTURE_HARBOUR, + TripSeine.PROPERTY_LANDING_HARBOUR, + TripSeine.PROPERTY_PROGRAM, + TripSeine.PROPERTY_ROUTE, + TripSeine.PROPERTY_ERS_ID, + TripSeine.PROPERTY_OPEN); + + // on ajoute la recopie de l'association route + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); + + return builder; + } + + }); + + return r; + + } + + @Override + public void copyForEdit(TripSeine source, TripSeine target) { + + getBinderForEdit().load(source, target, true); + + } + + protected TripSeine create(TripSeine toCreate) { + + TripSeineDAO dao = getDao(); + TripSeine created = dao.create(toCreate); + return created; + + } + + protected TripSeine update(TripSeine toUpdate) { + + TripSeineDAO dao = getDao(); + TripSeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); + getBinderForEdit().copyExcluding(toUpdate, updated, TripSeine.PROPERTY_ROUTE); + return updated; + + } + +} diff --git a/observe-business/src/main/java/fr/ird/observe/db/model/DataSelectionModel.java b/observe-services/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java similarity index 94% rename from observe-business/src/main/java/fr/ird/observe/db/model/DataSelectionModel.java rename to observe-services/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java index 5877ba4..abb314a 100644 --- a/observe-business/src/main/java/fr/ird/observe/db/model/DataSelectionModel.java +++ b/observe-services/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java @@ -19,11 +19,8 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -package fr.ird.observe.db.model; +package fr.ird.observe.services.model; -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.constants.DataSourceState; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.Trips; @@ -31,6 +28,10 @@ import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.Programs; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.longline.TripLonglineService; +import fr.ird.observe.services.data.seine.TripSeineService; +import fr.ird.observe.services.referential.ReferentialService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -58,24 +59,25 @@ import java.util.TreeMap; */ public class DataSelectionModel implements Serializable { - public static void populate(DataSelectionModel model, - DataService service, - DataSource source) throws Exception { + public static void populate(DataSelectionModel model, ObserveServiceFactory services) throws Exception { - source.checkState(DataSourceState.OPEN); +// source.checkState(DataSourceState.OPEN); Map<String, List<String>> datas = new HashMap<String, List<String>>(); - List<Program> programs = service.getAllProgramStub(source); + TripSeineService tripSeineService = services.getService(TripSeineService.class); + TripLonglineService tripLonglineService = services.getService(TripLonglineService.class); + + List<Program> programs = services.getService(ReferentialService.class).getAllProgramStub(); for (Program program : programs) { if (Programs.isProgramSeine(program)) { - List<TripSeine> trips = service.getTripSeineStubByProgram(source, program.getTopiaId()); + List<TripSeine> trips = tripSeineService.getTripSeineStubByProgram(program.getTopiaId()); populate(model, program, trips, datas); } if (Programs.isProgramLongline(program)) { - List<TripLongline> trips = service.getTripLonglineStubByProgram(source, program.getTopiaId()); + List<TripLongline> trips = tripLonglineService.getTripLonglineStubByProgram(program.getTopiaId()); populate(model, program, trips, datas); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java new file mode 100644 index 0000000..c00066a --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java @@ -0,0 +1,32 @@ +package fr.ird.observe.services.referential; + +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.services.ObserveService; + +import java.util.List; +import java.util.Set; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ReferentialService extends ObserveService { + + List<Program> getAllProgramStub(); + + int getProgramPosition(String programId); + + Program getProgramStub(String programId); + + <E extends ReferenceEntity> List<E> loadAndDecorateList(Class<E> entityType); + + <E extends ReferenceEntity> E loadAndDecorate(Class<E> entityType, String topiaId); + + List<Species> loadDecoratedSpecies(String speciesListCode); + + Set<String> getSpeciesListSpeciesIds(String speciesListId); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java new file mode 100644 index 0000000..99edc58 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -0,0 +1,103 @@ +package fr.ird.observe.services.referential; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.entities.referentiel.ProgramDAO; +import fr.ird.observe.entities.referentiel.Programs; +import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.referentiel.SpeciesList; +import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections.CollectionUtils; +import org.nuiton.topia.persistence.util.TopiaEntityHelper; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Created on 4/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ReferentialServiceImpl extends AbstractObserveService implements ReferentialService { + + @Override + public List<Program> getAllProgramStub() { + + ProgramDAO dao = (ProgramDAO) getDao(Program.class); + ReferenceLocale referentielLocale = getReferentielLocale(); + List<Program> result = dao.findAllStub(referentielLocale); + return result; + + } + + @Override + public int getProgramPosition(String programId) { + + List<Program> allProgramStub = getAllProgramStub(); + Program programStub = getProgramStub(programId); + int result=0; + if (CollectionUtils.isNotEmpty(allProgramStub)) { + Programs.sort(allProgramStub); + result= allProgramStub.indexOf(programStub); + } + return result; + } + + @Override + public Program getProgramStub(String programId) { + + ProgramDAO dao = (ProgramDAO) getDao(Program.class); + ReferenceLocale referentielLocale = getReferentielLocale(); + Program result = dao.findStubByTopiaId(programId, referentielLocale); + return result; + + } + + @Override + public <E extends ReferenceEntity> List<E> loadAndDecorateList(Class<E> entityType) { + + List<E> entities = getDao(entityType).findAll(); + decorate(entityType, entities); + return Lists.newArrayList(entities); + + } + + @Override + public <E extends ReferenceEntity> E loadAndDecorate(Class<E> entityType, String topiaId) { + + E entity = findByTopiaId(entityType, topiaId); + decorate(entityType, entity); + return entity; + + } + + public List<Species> loadDecoratedSpecies(String speciesListCode) { + + List<Species> speciess = new ArrayList<Species>(); + + SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListCode); + + speciess.addAll(speciesList.getSpecies()); + + decorate(Species.class, speciess); + + return speciess; + + } + + + public Set<String> getSpeciesListSpeciesIds(String speciesListId) { + + SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListId); + + Set<String> ids = Sets.newHashSet(TopiaEntityHelper.getTopiaIdList(speciesList.getSpecies())); + + return ids; + + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java deleted file mode 100644 index 05dbef3..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/ActivitySeineServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package fr.ird.observe.services.seine; - -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.util.List; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ActivitySeineServiceImpl extends AbstractObserveService<ActivitySeine> { - - public ActivitySeineServiceImpl(DataSource dataSource) { - super(ActivitySeine.class, dataSource); - } - - @Override - protected TopiaDAO<ActivitySeine> getDao(TopiaContext tx) throws TopiaException { - return ObserveDAOHelper.getActivitySeineDAO(tx); - } - - public List<ActivitySeine> loadAllByRouteForDisplay(String routeId) { - List<ActivitySeine> loaded = null; - return loaded; - } - - public ActivitySeine loadForEdit(String activitySeineId) { - ActivitySeine loaded = null; - return loaded; - } - - public ActivitySeine loadForEditObservedSystem(String activitySeineId) { - ActivitySeine loaded = null; - return loaded; - } - - public ActivitySeine preCreate(String routeId) { - ActivitySeine result = null; - return result; - } - - public ActivitySeine create(ActivitySeine toCreate) { - ActivitySeine created = null; - return created; - } - - public void update(ActivitySeine toUpdate) { - } - - public void updateObservedSystem(ActivitySeine toUpdate) { - - } - - public void delete(String activitySeineId) { - } - -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java deleted file mode 100644 index 5dbbee4..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/RouteServiceImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -package fr.ird.observe.services.seine; - -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.util.List; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class RouteServiceImpl extends AbstractObserveService<Route> { - - public RouteServiceImpl(DataSource dataSource) { - super(Route.class,dataSource); - } - - @Override - protected TopiaDAO<Route> getDao(TopiaContext tx) throws TopiaException { - return ObserveDAOHelper.getRouteDAO(tx); - } - - public List<Route> loadAllByTripForDisplay(String tripSeineId) { - List<Route> loaded = null; - return loaded; - } - - public Route loadForEdit(String routeId) { - Route loaded = null; - return loaded; - } - - public Route preCreate(String tripSeineId) { - Route preCreated = null; - return preCreated; - } - - public Route create(Route toCreate) { - Route created = null; - return created; - } - - public void update(Route toUpdate) { - } - - public void delete(String routeId) { - } - -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java deleted file mode 100644 index 33208ac..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/SetSeineServiceImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package fr.ird.observe.services.seine; - -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SetSeineServiceImpl extends AbstractObserveService<SetSeine> { - - public SetSeineServiceImpl(DataSource dataSource) { - super(SetSeine.class, dataSource); - } - - @Override - protected TopiaDAO<SetSeine> getDao(TopiaContext tx) throws TopiaException { - return ObserveDAOHelper.getSetSeineDAO(tx); - } - - public SetSeine loadForEdit(String setSeineId) { - SetSeine loaded = null; - return loaded; - } - - public SetSeine loadForEditObservedSystem(String setSeineId) { - SetSeine loaded = null; - return loaded; - } - - public SetSeine preCreate(String routeId) { - SetSeine result = null; - return result; - } - - public SetSeine create(SetSeine toCreate) { - SetSeine created = null; - return created; - } - - public void update(SetSeine toUpdate) { - } - - public void updateObservedSystem(SetSeine toUpdate) { - - } - - public void delete(String setSeineId) { - } - -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java deleted file mode 100644 index 86035ba..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/seine/TripSeineServiceImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -package fr.ird.observe.services.seine; - -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.util.List; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TripSeineServiceImpl extends AbstractObserveService<TripSeine> { - - public TripSeineServiceImpl(DataSource dataSource) { - super(TripSeine.class,dataSource); - } - - @Override - protected TopiaDAO<TripSeine> getDao(TopiaContext tx) throws TopiaException { - return ObserveDAOHelper.getTripSeineDAO(tx); - } - - public List<TripSeine> loadAllByProgramForDisplay(String programId) { - List<TripSeine> loaded = null; - return loaded; - } - - public TripSeine loadForEdit(String tripSeineId) { - TripSeine loaded = null; - return loaded; - } - - public TripSeine preCreate(String programId) { - TripSeine preCreated = null; - return preCreated; - } - - public TripSeine create(TripSeine toCreate) { - TripSeine created = null; - return created; - } - - public void update(TripSeine toUpdate) { - } - - public void delete(String tripSeineId) { - } - -} diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java index da6a48f..750762e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java @@ -28,11 +28,14 @@ import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListenerAdapter; import fr.ird.observe.db.impl.H2DataSource; -import fr.ird.observe.ui.actions.ChangeStorageAction; +import fr.ird.observe.services.ObserveService; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.OpenableService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.ObserveMainUIHandler; import fr.ird.observe.ui.ObserveUIMode; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.actions.ChangeStorageAction; import fr.ird.observe.ui.actions.shared.AbstractUIAction; import fr.ird.observe.ui.actions.shared.CancelCreateUIAction; import fr.ird.observe.ui.actions.shared.CloseAndCreateUIAction; @@ -233,6 +236,19 @@ public class ObserveContext extends ObserveApplicationContext { ObserveRunner.getRunner().setReload(true); } + public static ObserveServiceFactory newServiceFactory(DataSource dataSource) { + return ObserveServiceFactory.newFactory(get(), dataSource); + } + + public <S extends ObserveService> S getService(Class<S> serviceType) { + S service = services.getService(serviceType); + return service; + } + + public ObserveServiceFactory getServices() { + return services; + } + public void initStorage(ObserveConfig config, ObserveMainUI mainUI, boolean askToCreate) { @@ -501,7 +517,7 @@ public class ObserveContext extends ObserveApplicationContext { treeHelper.cleanNavigationUI(mainUI); - String[] openIds = getDataService().getOpenIds(source); + String[] openIds = getService(OpenableService.class).getOpenIds(); mainUI.getDataContext().populateOpens(openIds); treeHelper.loadNavigationUI(source, mainUI); @@ -591,4 +607,12 @@ public class ObserveContext extends ObserveApplicationContext { // return on; // } + private final ObserveServiceFactory services = ObserveServiceFactory.newFactory(this); + + @Override + public void setDataSource(DataSource dataSource) { + super.setDataSource(dataSource); + services.close(); + services.setDataSource(dataSource); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java b/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java index 95fcad1..5b1e2cf 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.actions; * #L% */ -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveConfigOption; import fr.ird.observe.ObserveContext; @@ -31,6 +30,7 @@ import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.SpeciesList; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.ObserveMainUIHandler; import fr.ird.observe.ui.ObserveUICallback; @@ -98,14 +98,12 @@ public class ShowConfigAction extends AbstractAction { boolean canContinue = ObserveContext.get().closeSelectedContentUI(ui); if (canContinue) { - DataSource dataSource = ObserveContext.get().getDataSource(); - ObserveConfig config = ui.getConfig(); ObserveConfigUIBuilder helper; try { - helper = buildUI(config, dataSource); + helper = buildUI(config); } catch (DataSourceException e) { throw new ObserveTechnicalException("Could not load some data", e); } @@ -118,11 +116,15 @@ public class ShowConfigAction extends AbstractAction { } - protected ObserveConfigUIBuilder buildUI(ObserveConfig config, DataSource dataSource) throws DataSourceException { + protected ObserveConfigUIBuilder buildUI(ObserveConfig config) throws DataSourceException { SpeciesListTableCellEditor editor; SpeciesListsTableCellRenderer renderer; + ObserveContext observeContext = ObserveContext.get(); + + DataSource dataSource = observeContext.getDataSource(); + if (dataSource == null) { editor = null; @@ -130,12 +132,11 @@ public class ShowConfigAction extends AbstractAction { } else { - DataService dataService = ObserveContext.get().getDataService(); - - Decorator<SpeciesList> speciesListDecorator = dataService.getDecoratorService().getDecoratorByType(SpeciesList.class); + Decorator<SpeciesList> speciesListDecorator = observeContext.getDecoratorService().getDecoratorByType(SpeciesList.class); // load species lists - List<SpeciesList> speciesLists = dataService.loadDecoratedEntities(dataSource, SpeciesList.class); + ReferentialService referentialService = observeContext.getService(ReferentialService.class); + List<SpeciesList> speciesLists = referentialService.loadAndDecorateList(SpeciesList.class); Map<String, SpeciesList> speciesListMap = Entities.toIdMap(speciesLists); @@ -222,7 +223,7 @@ public class ShowConfigAction extends AbstractAction { protected void addH2Options(ObserveConfigUIBuilder helper) { helper.addCategory(n("observe.config.category.h2"), - n("observe.config.category.h2.description")); + n("observe.config.category.h2.description")); helper.addOption(ObserveConfigOption.H2_LOGIN); helper.addOption(ObserveConfigOption.H2_PASSWORD); @@ -234,7 +235,7 @@ public class ShowConfigAction extends AbstractAction { protected void addObstunaOptions(ObserveConfigUIBuilder helper) { helper.addCategory(n("observe.config.category.obstuna"), - n("observe.config.category.obstuna.description")); + n("observe.config.category.obstuna.description")); helper.addOption(ObserveConfigOption.OBSTUNA_URL); helper.addOption(ObserveConfigOption.OBSTUNA_LOGIN); @@ -263,7 +264,7 @@ public class ShowConfigAction extends AbstractAction { protected void addGpsOptions(ObserveConfigUIBuilder helper) { helper.addCategory(n("observe.config.category.gps"), - n("observe.config.category.gps.description")); + n("observe.config.category.gps.description")); helper.addOption(ObserveConfigOption.DEFAULT_GPS_MAX_DELAY); helper.addOption(ObserveConfigOption.DEFAULT_GPS_MAX_SPEED); @@ -273,7 +274,7 @@ public class ShowConfigAction extends AbstractAction { protected void addSynchroOptions(ObserveConfigUIBuilder helper) { helper.addCategory(n("observe.config.category.synchro"), - n("observe.config.category.synchro.description")); + n("observe.config.category.synchro.description")); helper.addOption(ObserveConfigOption.CHANGE_SYNCHRO_SRC); helper.addOption(ObserveConfigOption.H2_CAN_MIGRATE); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java index 7dc1127..e5f1f1f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java @@ -35,7 +35,7 @@ import fr.ird.observe.db.ReplicationService; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListener; import fr.ird.observe.db.event.DataSourceListenerAdapter; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.gps.GPSService; import fr.ird.observe.ui.admin.config.SelectDataUI; import fr.ird.observe.ui.admin.resume.ShowResumeUI; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java index ebbe452..823288e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.admin; import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; +import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceConfig; @@ -30,10 +31,11 @@ import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.H2DataSource; import fr.ird.observe.db.impl.PGDataSource; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.Trips; import fr.ird.observe.report.model.Report; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.admin.consolidate.ConsolidateModel; import fr.ird.observe.ui.admin.export.ExportModel; import fr.ird.observe.ui.admin.gps.ImportGPSModel; @@ -180,7 +182,13 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (containsOperation(AdminStep.EXPORT_DATA)) { // on doit aussi calculer les ids des marées distantes - computeExistingTrips(dataService, getSafeCentralSource(true)); + DataSource safeCentralSource = getSafeCentralSource(true); + ObserveServiceFactory services = ObserveContext.newServiceFactory(safeCentralSource); + try { + computeExistingTrips(services); + } finally { + services.close(); + } } @@ -189,7 +197,13 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { log.debug("Will refill selectionModel [" + newStep + "] : " + selectModel); } DataSource dataSource = getSafeLocalSource(true); - populateSelectionModel(dataService, dataSource); + + ObserveServiceFactory services = ObserveContext.newServiceFactory(dataSource); + try { + populateSelectionModel(services); + } finally { + services.close(); + } } }; @@ -1265,9 +1279,9 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } } - public void populateSelectionModel(DataService dataService, DataSource source) { + public void populateSelectionModel(ObserveServiceFactory services) { try { - DataSelectionModel.populate(getSelectionDataModel(), dataService, source); + DataSelectionModel.populate(getSelectionDataModel(), services); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("could not populate selected model", e); @@ -1280,12 +1294,12 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } } - protected void computeExistingTrips(DataService dataService, DataSource source) { + protected void computeExistingTrips(ObserveServiceFactory services) { DataSelectionModel selectionModel = new DataSelectionModel(); selectionModel.setUseOpenData(true); try { - DataSelectionModel.populate(selectionModel, dataService, source); + DataSelectionModel.populate(selectionModel, services); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("could not populate selected model", e); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx b/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx index c275b5b..f55f2c7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx @@ -27,7 +27,7 @@ <fr.ird.observe.ui.admin.AdminTabUI> <import> - fr.ird.observe.db.model.DataSelectionModel + fr.ird.observe.services.model.DataSelectionModel fr.ird.observe.ui.UIHelper fr.ird.observe.ui.admin.AdminUI fr.ird.observe.ui.admin.AdminStep diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java index ba8e371..be55ccb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java @@ -26,7 +26,7 @@ import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.ActivitySeine; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java index 97e2ca6..29ee79a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.admin.export; import com.google.common.collect.ImmutableList; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java index 7f76253..c47c714 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java @@ -22,12 +22,15 @@ package fr.ird.observe.ui.admin.export; import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUI; @@ -249,12 +252,18 @@ public class ExportUIHandler extends AdminTabUIHandler { ExportModel stepModel = model.getExportModel(); + DataSource centralSource = stepModel.getCentralSource(); + DataSource localSource = stepModel.getSource(); + + ObserveServiceFactory centralServices = ObserveContext.newServiceFactory(centralSource); + ObserveServiceFactory localServices = ObserveContext.newServiceFactory(localSource ); + // on filtre les marées sélectionnées pour export List<TripEntry> tripEntries = stepModel.getSelectedTrips(); for (TripEntry tripEntry : tripEntries) { - processTrip(stepModel, tripEntry); + processTrip(stepModel, tripEntry,localServices, centralServices); } @@ -263,7 +272,7 @@ public class ExportUIHandler extends AdminTabUIHandler { return WizardState.SUCCESSED; } - protected void processTrip(ExportModel stepModel, TripEntry tripEntry) throws Exception { + protected void processTrip(ExportModel stepModel, TripEntry tripEntry, ObserveServiceFactory localServices, ObserveServiceFactory centralServices) throws Exception { DataSource centralSource = stepModel.getCentralSource(); DataSource source = stepModel.getSource(); @@ -284,7 +293,8 @@ public class ExportUIHandler extends AdminTabUIHandler { } sendMessage(t("observe.message.exportData.delete.remote.maree", tripDecorated, programDecorated)); - getDataService().deleteTrip(centralSource, tripId); + TripService service = centralServices.getService(TripService.class); + service.deleteTrip(tripId); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java index bef7919..1f62ecb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.admin.report; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.report.model.DataMatrix; import fr.ird.observe.report.model.Report; import fr.ird.observe.report.model.ReportExecute; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java index 82005cb..f6b84da 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java @@ -27,7 +27,7 @@ import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.ui.UIHelper; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 05f636a..3fcbcca 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -33,13 +33,13 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.db.util.TopiaExecutor; import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.services.ObserveService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.actions.shared.AbstractUIAction; import fr.ird.observe.ui.content.ref.ContentReferenceUIHandler; import fr.ird.observe.ui.tree.AbstractObserveTreeCellRenderer; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; -import fr.ird.observe.util.DBHelper; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.JAXXButtonGroup; @@ -56,7 +56,6 @@ import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaEntityAbstract; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; @@ -164,9 +163,9 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } - protected static void attachTopiaContext(DataSource service, TopiaEntityAbstract entity) { - DBHelper.attachTopiaContext(service.getRootCtxt(), entity); - } +// protected static void attachTopiaContext(DataSource service, TopiaEntityAbstract entity) { +// DBHelper.attachTopiaContext(service.getRootCtxt(), entity); +// } public static ObserveTreeHelper getTreeHelper(JAXXContext context) { return context.getContextValue(ObserveTreeHelper.class); @@ -278,10 +277,10 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { model.addMessages((JComponent) ui, fieldName, scope, message); } - public static void removeAllMessages(ContentUI<?> ui, NuitonValidatorScope scope, String fieldName) { - SwingValidatorMessageTableModel model = ui.getErrorTableModel(); - model.removeMessages(ui, fieldName, scope); - } +// public static void removeAllMessages(ContentUI<?> ui, NuitonValidatorScope scope, String fieldName) { +// SwingValidatorMessageTableModel model = ui.getErrorTableModel(); +// model.removeMessages(ui, fieldName, scope); +// } public static void removeAllMessages(ObserveContentUI<?> ui) { SwingValidatorMessageTableModel model = ui.getErrorTableModel(); @@ -361,7 +360,7 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { public void initUI() throws Exception { ContentUIInitializer<E, ObserveContentUI<E>> uiInitializer = new ContentUIInitializer<E, ObserveContentUI<E>>(ui); - uiInitializer.initUI(getDataSource()); + uiInitializer.initUI(ObserveContext.get().getServices()); } @@ -490,11 +489,9 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { // on ne peut redemarrer une edition que si la donnee // est exactement une entites (pas possible sur une liste) ObserveTreeHelper treeHelper = getTreeHelper(ui); -// ObserveNode node = treeHelper.getSelectedNode(); removeAllMessages(ui); -// treeHelper.refreshNode(node, true); treeHelper.reloadSelectedNode(false, true); model.setMode(ContentMode.UPDATE); @@ -505,7 +502,8 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { updateActions(); } - public final void saveUI(boolean refresh) { + //TODO a remplacer par saveUI2 + public void saveUI(boolean refresh) { boolean ok = false; try { ok = doSave(getBean(), @@ -525,6 +523,23 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } } + public void saveUI2(boolean refresh) { + boolean ok = false; + try { + ok = doSave(getBean()); + } catch (Exception e) { + ErrorDialogUI.showError(e); + if (log.isErrorEnabled()) { + log.error(e); + } + } finally { + if (ok) { + afterSave(refresh); + } + } + } + + //TODO a remplacer par doSave simple protected boolean doSave(E bean, DataService dataService, DataSource dataSource, @@ -532,6 +547,10 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return false; } + protected boolean doSave(E bean) throws Exception { + return false; + } + protected void afterSave(boolean refresh) { // mettre les validateurs en mode non modifié @@ -570,7 +589,8 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } - public final void deleteUI() { + //TODO a remplacer par deleteUI2 + public void deleteUI() { boolean ok = false; ui.stopEdit(); removeAllMessages(ui); @@ -591,6 +611,7 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } } + //TODO a remplacer par doDelete simple protected boolean doDelete(E bean, DataService dataService, DataSource dataSource, @@ -598,10 +619,30 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return false; } - protected boolean askToDelete(E bean) { - boolean accept = - UIHelper.confirmForEntityDelete(ui, getBeanType(), bean); + public void deleteUI2() { + boolean ok = false; + ui.stopEdit(); + removeAllMessages(ui); + try { + ok = doDelete(getBean()); + } catch (Exception e) { + ErrorDialogUI.showError(e); + if (log.isErrorEnabled()) { + log.error(e); + } + } finally { + if (ok) { + afterDelete(); + } + } + } + + protected boolean doDelete(E bean) { + return false; + } + protected boolean askToDelete(E bean) { + boolean accept = UIHelper.confirmForEntityDelete(ui, getBeanType(), bean); return !accept; } @@ -751,6 +792,10 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return ObserveContext.get().getDataService(); } + protected final <S extends ObserveService> S getService(Class<S> serviceType) { + return ObserveContext.get().getService(serviceType); + } + protected void updateActions() { updateToolbarActions(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java index aad26b8..7d426a0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java @@ -27,11 +27,12 @@ import com.google.common.collect.Lists; import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.constants.ReferenceStatus; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.actions.shared.AbstractUIAction; import fr.ird.observe.ui.util.BooleanEditor; @@ -133,9 +134,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte this.ui = ui; } - protected static void attachTopiaContext(DataSource service, - TopiaEntityAbstract entity) { - DBHelper.attachTopiaContext(service.getRootCtxt(), entity); + protected static void attachTopiaContext(ObserveServiceFactory serviceFactory, TopiaEntityAbstract entity) { + DBHelper.attachTopiaContext(serviceFactory.getDataSource().getRootCtxt(), entity); } public static TableCellEditor newFloatColumnEditor(JTable table) { @@ -197,7 +197,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } - public void initUI(DataSource dataSource) throws Exception { + public void initUI(ObserveServiceFactory serviceFactory) throws Exception { if (log.isDebugEnabled()) { log.debug("ui " + getClass()); @@ -207,7 +207,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte // initialisation des éditeurs - init(dataSource); + init(serviceFactory); Set<String> doNotBlockComponentIds = new HashSet<String>(); @@ -221,7 +221,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } if (o instanceof TopiaEntityAbstract) { - init(dataSource, (TopiaEntityAbstract) o); + init(serviceFactory, (TopiaEntityAbstract) o); continue; } @@ -245,17 +245,17 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } if (o instanceof BeanComboBox<?>) { - init(dataSource, (BeanComboBox<?>) o); + init(serviceFactory, (BeanComboBox<?>) o); continue; } if (o instanceof BeanListHeader<?>) { - init(dataSource, decoratorService, (BeanListHeader<?>) o); + init(serviceFactory, decoratorService, (BeanListHeader<?>) o); continue; } if (o instanceof FilterableDoubleList<?>) { - init(dataSource, (FilterableDoubleList<?>) o); + init(serviceFactory, (FilterableDoubleList<?>) o); continue; } @@ -323,13 +323,13 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte ); } - protected void init(DataSource service) throws DataSourceException { + protected void init(ObserveServiceFactory serviceFactory) { - init(service, (TopiaEntityAbstract) getBean()); + init(serviceFactory, (TopiaEntityAbstract) getBean()); } - protected void init(DataSource service, TopiaEntityAbstract bean) throws DataSourceException { + protected void init(ObserveServiceFactory serviceFactory, TopiaEntityAbstract bean) { if (bean == null) { return; @@ -337,10 +337,10 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte if (log.isDebugEnabled()) { log.debug("init entity " + bean.getClass()); } - attachTopiaContext(service, bean); + attachTopiaContext(serviceFactory, bean); } - protected void init(ActionMap actionMap, AbstractButton editor) throws DataSourceException { + protected void init(ActionMap actionMap, AbstractButton editor) { String actionId = (String) editor.getClientProperty(OBSERVE_ACTION); if (actionId == null) { // le boutton n'est pas commun @@ -376,7 +376,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte action.initAction(null, editor); } - protected void init(NumberEditor editor) throws DataSourceException { + protected void init(NumberEditor editor) { if (log.isDebugEnabled()) { log.debug("init number editor " + editor.getName()); } @@ -384,19 +384,18 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } @SuppressWarnings("unchecked") - protected void init(DataSource dataSource, BeanComboBox beanComboBox) throws DataSourceException { - Class<ReferenceEntity> klass = (Class<ReferenceEntity>) - beanComboBox.getHandler().getBeanType(); + protected void init(ObserveServiceFactory serviceFactory, BeanComboBox beanComboBox) { + Class<ReferenceEntity> klass = (Class<ReferenceEntity>) beanComboBox.getHandler().getBeanType(); if (log.isDebugEnabled()) { log.debug("init combobox for " + klass); } beanComboBox.setI18nPrefix("observe.common."); beanComboBox.setMinimumSize(new Dimension(0, 24)); - prepareBeanComboBox(dataSource, klass, beanComboBox); + prepareBeanComboBox(serviceFactory, klass, beanComboBox); } @SuppressWarnings("unchecked") - protected void init(DataSource dataSource, DecoratorService decoratorService, BeanListHeader beanList) throws DataSourceException { + protected void init(ObserveServiceFactory serviceFactory, DecoratorService decoratorService, BeanListHeader beanList) { beanList.setI18nPrefix("observe.common."); @@ -404,7 +403,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte log.info("init list for " + beanList.getBeanType()); } - prepareEntityList(dataSource, beanList.getBeanType(), beanList); + prepareEntityList(serviceFactory, beanList.getBeanType(), beanList); JList jlist = beanList.getList(); @@ -430,7 +429,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } @SuppressWarnings("unchecked") - protected void init(DataSource dataSource, FilterableDoubleList beanList) throws DataSourceException { + protected void init(ObserveServiceFactory serviceFactory, FilterableDoubleList beanList) throws DataSourceException { beanList.setI18nPrefix("observe.common."); @@ -438,7 +437,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte log.info("init list for " + beanList.getBeanType()); } - prepareEntityList(dataSource, beanList.getBeanType(), beanList); + prepareEntityList(serviceFactory, beanList.getBeanType(), beanList); } @@ -630,22 +629,19 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param storageService le service de persistance à utiliser pour + * @param serviceFactory le service de persistance à utiliser pour * récupérer les entités * @param entityClass le type de l'entité * @param list le component graphique à initialiser - * @throws DataSourceException si un problème lors de la récupération - * des entités * @since 1.5 */ - protected <E extends TopiaEntity> void prepareEntityList(DataSource storageService, - Class<E> entityClass, - FilterableDoubleList<E> list) throws DataSourceException { + @SuppressWarnings("unchecked") + protected <E extends TopiaEntity> void prepareEntityList(ObserveServiceFactory serviceFactory, Class<E> entityClass, FilterableDoubleList<E> list) { - ObserveContext tx = ObserveContext.get(); + ObserveContext context = ObserveContext.get(); // init list - Decorator<E> decorator = tx.getDecorator(entityClass); + Decorator<E> decorator = context.getDecorator(entityClass); if (log.isDebugEnabled()) { log.debug("Will use decorator " + decorator); } @@ -656,7 +652,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte if (ReferenceEntity.class.isAssignableFrom(entityClass)) { Predicate<E> predicate = (Predicate<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - data = tx.getDataService().getList(storageService, entityClass, predicate); + ReferentialService service = serviceFactory.getService(ReferentialService.class); + data = service.getList(entityClass, predicate); } else { data = new ArrayList<E>(); @@ -680,7 +677,9 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte // listen on cache modification EntityDoubleListPropertyChangeListener<E> listener = new EntityDoubleListPropertyChangeListener<E>(entityClass, list); - DataService service = ObserveContext.get().getDataService(); + + //FIXME Remove this + DataService service = context.getDataService(); service.addReferentielPropertyChangeListener(entityClass, listener); } @@ -688,22 +687,19 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param storageService le service de persistance à utiliser pour + * @param serviceFactory le service de persistance à utiliser pour * récupérer les entités * @param entityClass le type de l'entité * @param list le component graphique à initialiser - * @throws DataSourceException si un problème lors de la récupération - * des entités * @since 1.5 */ - protected <E extends TopiaEntity> void prepareEntityList(DataSource storageService, - Class<E> entityClass, - BeanListHeader<E> list) throws DataSourceException { + @SuppressWarnings("unchecked") + protected <E extends TopiaEntity> void prepareEntityList(ObserveServiceFactory serviceFactory, Class<E> entityClass, BeanListHeader<E> list) { - ObserveContext tx = ObserveContext.get(); + ObserveContext context = ObserveContext.get(); // init list - Decorator<E> decorator = tx.getDecorator(entityClass); + Decorator<E> decorator = context.getDecorator(entityClass); if (log.isDebugEnabled()) { log.debug("Will use decorator " + decorator); } @@ -714,7 +710,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte if (ReferenceEntity.class.isAssignableFrom(entityClass)) { Predicate<E> predicate = (Predicate<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - data = tx.getDataService().getList(storageService, entityClass, predicate); + ReferentialService service = serviceFactory.getService(ReferentialService.class); + data = service.getList(entityClass, predicate); } else { data = new ArrayList<E>(); @@ -735,9 +732,10 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte list.putClientProperty("data", data); // listen on cache modification - EntityListPropertyChangeListener<E> listener = - new EntityListPropertyChangeListener<E>(entityClass, list); - DataService service = ObserveContext.get().getDataService(); + EntityListPropertyChangeListener<E> listener = new EntityListPropertyChangeListener<E>(entityClass, list); + + //FIXME Remove this!!! + DataService service = context.getDataService(); service.addReferentielPropertyChangeListener(entityClass, listener); } @@ -746,25 +744,19 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte * pour un service de persistance donné. * * @param <E> le type de l'entité - * @param storageService le service de persistance à utiliser pour récupérer + * @param serviceFactory le service de persistance à utiliser pour récupérer * les entités * @param entityClass le type de l'entité * @param comboBox le component graphique à initialiser - * @throws DataSourceException si un pb pendant la récupération des - * entités */ - protected <E extends TopiaEntity> void prepareBeanComboBox( - DataSource storageService, - Class<E> entityClass, - BeanComboBox<E> comboBox) throws DataSourceException { + @SuppressWarnings("unchecked") + protected <E extends TopiaEntity> void prepareBeanComboBox(ObserveServiceFactory serviceFactory, Class<E> entityClass, BeanComboBox<E> comboBox) { ObserveContext context = ObserveContext.get(); // init combobox Decorator<E> decorator = context.getDecorator(entityClass); - DataService service = context.getDataService(); - Boolean noLoad = (Boolean) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_NO_LOAD); List<E> data; @@ -780,7 +772,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte // get complete data list from service Predicate<E> predicate = (Predicate<E>) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - data = service.getList(storageService, entityClass, predicate); + ReferentialService service = serviceFactory.getService(ReferentialService.class); + data = service.getList(entityClass, predicate); } @@ -843,7 +836,9 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte super.propertyChange(evt); } }; - service.addReferentielPropertyChangeListener(entityClass, listener); + + //FIXME Remove this + context.getDataService().addReferentielPropertyChangeListener(entityClass, listener); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java index ac01be8..2227310 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java @@ -24,10 +24,8 @@ package fr.ird.observe.ui.content.impl.longline; import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; @@ -39,6 +37,7 @@ import fr.ird.observe.entities.longline.SectionTemplate; import fr.ird.observe.entities.longline.SectionWithTemplate; import fr.ird.observe.entities.longline.SectionWithTemplates; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.data.longline.LonglineDetailCompositionService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -321,7 +320,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong this.branchlineDecorator = getDecoratorService().getDecoratorByType(Branchline.class); LonglineDetailCompositionUIInitializer uiInitializer = new LonglineDetailCompositionUIInitializer(getUi()); - uiInitializer.initUI(getDataSource()); + uiInitializer.initUI(ObserveContext.get().getServices()); LonglineDetailCompositionUI ui1 = getUi(); @@ -1478,36 +1477,33 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong boolean canDelete = true; if (section.getTopiaId() != null) { - try { - - EntityMap allUsages = getDataService().findAllUsages(getDataSource(), section); - allUsages.remove(SetLongline.class); - if (!allUsages.isEmpty()) { + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + EntityMap allUsages = service.findAllUsages(section); + allUsages.remove(SetLongline.class); - canDelete = false; + if (!allUsages.isEmpty()) { - } else { + canDelete = false; - if (!section.isBasketEmpty()) { + } else { - for (Basket basket : section.getBasket()) { + if (!section.isBasketEmpty()) { - if (!canDeleteBasket(basket)) { + for (Basket basket : section.getBasket()) { - canDelete = false; - break; + if (!canDeleteBasket(basket)) { - } + canDelete = false; + break; } - } + } } - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not find all usage of selected section", e); } + } return canDelete; @@ -1519,27 +1515,25 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong boolean canDelete = true; if (basket.getTopiaId() != null) { - try { - - EntityMap allUsages = getDataService().findAllUsages(getDataSource(), basket); - allUsages.remove(Section.class); - if (!allUsages.isEmpty()) { + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + EntityMap allUsages = service.findAllUsages(basket); + allUsages.remove(Section.class); - canDelete = false; + if (!allUsages.isEmpty()) { - } else { + canDelete = false; - if (!basket.isBranchlineEmpty()) { + } else { - for (Branchline branchline : basket.getBranchline()) { + if (!basket.isBranchlineEmpty()) { - if (!canDeleteBranchline(branchline)) { + for (Branchline branchline : basket.getBranchline()) { - canDelete = false; - break; + if (!canDeleteBranchline(branchline)) { - } + canDelete = false; + break; } @@ -1547,9 +1541,8 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not find all usage of selected section", e); } + } return canDelete; @@ -1561,20 +1554,17 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong boolean canDelete = true; if (branchline.getTopiaId() != null) { - try { - - EntityMap allUsages = getDataService().findAllUsages(getDataSource(), branchline); - allUsages.remove(Basket.class); - if (!allUsages.isEmpty()) { + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + EntityMap allUsages = service.findAllUsages(branchline); + allUsages.remove(Basket.class); - canDelete = false; + if (!allUsages.isEmpty()) { - } + canDelete = false; - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not find all usage of selected branchline", e); } + } return canDelete; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java index 1dec3b2..9e40047 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java @@ -23,9 +23,9 @@ package fr.ird.observe.ui.content.impl.longline; */ import fr.ird.observe.DecoratorService; -import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.longline.SectionTemplate; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentUIInitializer; import fr.ird.observe.ui.util.table.AutotSelectRowAndShowPopupActionSupport; @@ -58,8 +58,8 @@ public class LonglineDetailCompositionUIInitializer extends ContentUIInitializer } @Override - public void initUI(DataSource dataSource) throws Exception { - super.initUI(dataSource); + public void initUI(ObserveServiceFactory serviceFactory) throws Exception { + super.initUI(serviceFactory); LonglineDetailCompositionUIModel model = ui.getModel(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java index 5a71b4f..4bb3643 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java @@ -21,19 +21,13 @@ */ package fr.ird.observe.ui.content.impl.seine; -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.constants.seine.SchoolType; import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.data.seine.SetSeineService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; @@ -46,10 +40,6 @@ import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import jaxx.runtime.validator.swing.SwingValidatorUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; import org.nuiton.validator.NuitonValidatorScope; @@ -138,6 +128,7 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { getEntityLabel(ActivitySeine.class), t("observe.activitySeine.message.not.open")); return ContentMode.READ; + } @Override @@ -169,33 +160,38 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { } ContentMode mode = computeContentMode(); - DataService dataService = getDataService(); + SetSeine loaded; - SetSeine bean = getBean(); + SetSeineService service = getService(SetSeineService.class); + + String routeId = getDataContext().getSelectedRouteId(); - TopiaEntityBinder<SetSeine> binder = getLoadBinder(); - DataSource source = getDataSource(); if (setId == null) { // creation mode - dataService.preCreate(source, activityId, bean, binder, getPreCreateExecutor()); + loaded = service.preCreate(routeId, activityId); } else { // update mode - dataService.loadEditEntity(source, setId, getLoadExecutor()); + loaded = service.loadForEdit(setId); + } - Route route = (Route) getDataService().loadEntity(source, getDataContext().getSelectedRouteId(), false); + SetSeine bean = getBean(); + service.copyForEdit(loaded, bean); + Date date = service.getRouteDate(routeId); Date time = bean.getStartTime(); - Date date = route.getDate(); - Date dateAndTime = DateUtil.getDateAndTime(date, time, false, false); getUi().getStartTime().setDate(dateAndTime); + UIHelper.processDataBinding(getUi(), + SetSeineUI.BINDING_END_SET_TIME_STAMP_DATE, + SetSeineUI.BINDING_END_PURSING_TIME_STAMP_DATE); + // utilisation du mode requis setContentMode(mode); @@ -208,59 +204,6 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { } @Override - protected SetSeine onPreCreate(TopiaContext tx, Object parent, SetSeine bean) throws TopiaException { - - ActivitySeine parentBean = (ActivitySeine) parent; - - // on utilise l'heure de l'activité comme début de calée - Date date = DateUtil.getTime(parentBean.getTime(), false, false); - - bean.setStartTime(date); - - try { - - // pour les dates de fin on utilise la date de la route - Route route = (Route) getDataService().loadEntity( - getDataSource(), getDataContext().getSelectedRouteId(), false); - - bean.setEndSetTimeStamp(date); - bean.setEndPursingTimeStamp(date); - - bean.setEndSetDate(route.getDate()); - bean.setEndPursingDate(route.getDate()); - - } catch (DataSourceException e) { - throw new TopiaException("Could not obtain route", e); - } - - // recuperation du type de set a partir de l'activity - SchoolType schoolType = parentBean.getSchoolType(); - bean.setSchoolType(schoolType); - return bean; - } - - @Override - protected void onLoad(TopiaContext tx, SetSeine bean) throws TopiaException { - super.onLoad(tx, bean); - SetSeine editBean = getBean(); - getDataContext().getOpenRouteId(); - if (!editBean.isTargetSampleEmpty()) { - for (TargetSample e : editBean.getTargetSample()) { - e.isTargetLengthEmpty(); - } - } - if (!editBean.isNonTargetSampleEmpty()) { - for (NonTargetSample e : editBean.getNonTargetSample()) { - e.isNonTargetLengthEmpty(); - } - } - - UIHelper.processDataBinding(getUi(), - SetSeineUI.BINDING_END_SET_TIME_STAMP_DATE, - SetSeineUI.BINDING_END_PURSING_TIME_STAMP_DATE); - } - - @Override public void startEditUI(String... binding) { ContentUIModel<SetSeine> model = getModel(); boolean create = model.getMode() == ContentMode.CREATE; @@ -294,40 +237,15 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { } @Override - protected boolean doSave(SetSeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetSeine> binder) throws Exception { + protected boolean doSave(SetSeine bean) { String activityId = getSelectedParentId(); - if (bean.getTopiaId() == null) { - - dataService.create(dataSource, activityId, bean, binder, getCreateExecutor()); - } else { - - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - } + SetSeineService service = getService(SetSeineService.class); + SetSeine saved = service.save(activityId, bean); + bean.setTopiaId(saved.getTopiaId()); return true; - } - - @Override - protected SetSeine onCreate(TopiaContext tx, Object parent, SetSeine editBean) throws TopiaException { - ActivitySeine parentBean = (ActivitySeine) parent; - SetSeine beanToSave = ObserveDAOHelper.getSetSeineDAO(tx).create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - parentBean.setSetSeine(beanToSave); - return beanToSave; - } - - @Override - protected SetSeine onUpdate(TopiaContext tx, Object parentBean, SetSeine beanToSave) throws TopiaException { - getLoadBinder().copyExcluding(getBean(), beanToSave, - SetSeine.PROPERTY_TARGET_SAMPLE, - SetSeine.PROPERTY_NON_TARGET_SAMPLE); - return beanToSave; } @Override @@ -345,6 +263,7 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { boolean create = node.getId() == null; if (create) { + getModel().setMode(ContentMode.UPDATE); // remove old node and recreate new node @@ -353,38 +272,34 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { stopEditUI(); treeHelper.selectNode(node); + } else { + // select ancestor node -// treeHelper.refreshNode(node, false); treeHelper.reloadSelectedNode(false, false); + } + } @Override - protected boolean doDelete(SetSeine bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, SetSeine> deletor) throws Exception { + protected boolean doDelete(SetSeine bean) { + + boolean result; + if (!askToDelete(bean)) { + + result = false; + + } else { + + String activityId = getSelectedParentId(); + getService(SetSeineService.class).delete(activityId, bean.getTopiaId()); + result = true; - if (askToDelete(bean)) { - return false; } - String activityId = getSelectedParentId(); - dataService.delete(dataSource, activityId, bean, deletor); - return true; - } + return result; - @Override - protected void onDelete(TopiaContext tx, Object parent, SetSeine beanToDelete) throws TopiaException { - ActivitySeine parentBean = (ActivitySeine) parent; - - // on doit supprimer physiquement la set - // car il n'y a pas de delete-orphan sur une telle - // relation - ObserveDAOHelper.getSetSeineDAO(tx).delete(parentBean.getSetSeine()); - // supprime la reference sur l'activity - parentBean.setSetSeine(null); } protected void computeTabValidState(SwingValidatorMessageTableModel errorTableModel) { @@ -435,4 +350,16 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { } + //TODO Supprimer deleteUI et mettre deleteUI2 a la place + @Override + public final void deleteUI() { + deleteUI2(); + } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java index 9112209..adc7da6 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java @@ -22,13 +22,12 @@ package fr.ird.observe.ui.content.list.impl.longline; * #L% */ -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.services.data.longline.ActivityLonglineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -111,10 +110,8 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin @Override protected List<ActivityLongline> getChilds(TripLongline bean) throws DataSourceException { - DataSource source = getDataSource(); - DataService dataService = getDataService(); - - List<ActivityLongline> list = dataService.getActivityLonglineStubByTrip(source, bean.getTopiaId()); + ActivityLonglineService service = getService(ActivityLonglineService.class); + List<ActivityLongline> list = service.getActivityLonglineStubByTrip(bean.getTopiaId()); if (log.isDebugEnabled()) { log.debug("Will use " + list.size() + " activities."); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java index 7cbc914..0c2e8b9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java @@ -22,13 +22,12 @@ package fr.ird.observe.ui.content.list.impl.longline; * #L% */ -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.data.longline.TripLonglineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -94,10 +93,8 @@ public class TripLonglinesUIHandler extends ContentListUIHandler<Program, TripLo @Override protected List<TripLongline> getChilds(Program bean) throws DataSourceException { - DataSource source = getDataSource(); - DataService dataService = getDataService(); - - List<TripLongline> list = dataService.getTripLonglineStubByProgram(source, bean.getTopiaId()); + TripLonglineService service = getService(TripLonglineService.class); + List<TripLongline> list = service.getTripLonglineStubByProgram(bean.getTopiaId()); if (log.isDebugEnabled()) { log.debug("Will use " + list.size() + " trips."); @@ -106,5 +103,6 @@ public class TripLonglinesUIHandler extends ContentListUIHandler<Program, TripLo return list; } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java index 2a1aab7..619cf3e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java @@ -21,13 +21,12 @@ */ package fr.ird.observe.ui.content.list.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.services.data.seine.ActivitySeineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -109,10 +108,8 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit @Override protected List<ActivitySeine> getChilds(Route bean) throws DataSourceException { - DataSource source = getDataSource(); - DataService dataService = getDataService(); - - List<ActivitySeine> list = dataService.getActivitySeineStubByRoute(source, bean.getTopiaId()); + ActivitySeineService service = getService(ActivitySeineService.class); + List<ActivitySeine> list = service.getActivitySeineStubByRoute(bean.getTopiaId()); if (log.isDebugEnabled()) { log.debug("Will use " + list.size() + " activities."); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java index 3a33ceb..29c1fe2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java @@ -21,13 +21,12 @@ */ package fr.ird.observe.ui.content.list.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.data.seine.RouteService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -106,10 +105,8 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { @Override protected List<Route> getChilds(TripSeine bean) throws DataSourceException { - DataSource source = getDataSource(); - DataService dataService = getDataService(); - - List<Route> list = dataService.getRouteStubByTrip(source, bean.getTopiaId()); + RouteService service = getService(RouteService.class); + List<Route> list = service.getRouteStubByTrip(bean.getTopiaId()); if (log.isDebugEnabled()) { log.debug("Will use " + list.size() + " routes."); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java index 7eb1ee1..149a47a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java @@ -21,13 +21,12 @@ */ package fr.ird.observe.ui.content.list.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.data.seine.TripSeineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -91,16 +90,14 @@ public class TripSeinesUIHandler extends ContentListUIHandler<Program, TripSeine @Override protected List<TripSeine> getChilds(Program bean) throws DataSourceException { - DataSource source = getDataSource(); - DataService dataService = getDataService(); - - List<TripSeine> list = dataService.getTripSeineStubByProgram(source, bean.getTopiaId()); + TripSeineService service = getService(TripSeineService.class); + List<TripSeine> list = service.getTripSeineStubByProgram(bean.getTopiaId()); if (log.isDebugEnabled()) { log.debug("Will use " + list.size() + " trips."); } return list; - + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java index 3755f64..38138e3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java @@ -21,13 +21,13 @@ */ package fr.ird.observe.ui.content.open; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.OpenableEntity; import fr.ird.observe.entities.Trip; +import fr.ird.observe.services.data.OpenableService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.tree.ObserveNode; @@ -38,6 +38,8 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.validator.NuitonValidatorScope; +import java.util.Arrays; + import static org.nuiton.i18n.I18n.t; /** @@ -53,16 +55,40 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE protected final String closeMessage; - public ContentOpenableUIHandler(ContentOpenableUI<E> ui, - DataContextType parentType, - DataContextType type, - String closeMessage) { + protected ContentOpenableUIHandler(ContentOpenableUI<E> ui, + DataContextType parentType, + DataContextType type, + String closeMessage) { + super(ui, parentType, type); this.closeMessage = closeMessage; + } protected abstract boolean obtainCanReopen(boolean create); + protected void updateOpenState(String beanId, boolean openState) { + OpenableService service = getService(OpenableService.class); + service.updateOpenState(beanId, openState); + } + + protected int getOpenablePosition(String containerId, String beanId) { + OpenableService service = getService(OpenableService.class); + return service.getOpenablePosition(containerId, beanId); + } + + //TODO Supprimer deleteUI et mettre deleteUI2 a la place + @Override + public final void deleteUI() { + deleteUI2(); + } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + @Override public ContentOpenableUI<E> getUi() { return (ContentOpenableUI<E>) super.getUi(); @@ -98,18 +124,18 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE public final void doOpenData() throws Exception { String id = getBean().getTopiaId(); - getDataService().updateOpenProperty(getDataSource(), id, true); + updateOpenState(id, true); } public final void afterOpenData() { + reloadOpenContext(); + ContentOpenableUI<E> ui = getUi(); // on repaint le parent (le program devient alors ouvert) ObserveTreeHelper treeHelper = getTreeHelper(ui); treeHelper.reloadSelectedNode(true, true); -// ObserveNode node = treeHelper.getSelectedNode(); -// treeHelper.refreshNode(node.getParent(), true); // on chage l'état 'canReopen' du model ui.getModel().setCanReopen(false); @@ -141,12 +167,14 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE } public final boolean doCloseData(String id) throws Exception { - getDataService().updateOpenProperty(getDataSource(), id, false); + updateOpenState(id, false); return true; } public final void afterCloseData() { + reloadOpenContext(); + ContentOpenableUI<E> ui = getUi(); ContentOpenableUIModel<E> model = getModel(); @@ -162,16 +190,22 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE getEntityLabel(bean.getClass()), t(closeMessage)); ObserveTreeHelper treeHelper = getTreeHelper(ui); -// ObserveNode selectedNode = treeHelper.getSelectedNode(); -// if (bean instanceof Trip) { -// // le program peut change d'etat open -// selectedNode = selectedNode.getParent(); -// } -// treeHelper.refreshNode(selectedNode, true); treeHelper.reloadSelectedNode(bean instanceof Trip, true); updateActions(); } + protected void reloadOpenContext() { + + String[] openIds = getService(OpenableService.class).getOpenIds(); + + if (log.isDebugEnabled()) { + log.debug("open context changed in data service, will propagate it to " + getDataContext()); + log.debug("new open ids : " + Arrays.toString(openIds)); + } + getDataContext().populateOpens(openIds); + + } + @Override protected void afterSave(boolean refresh) { @@ -227,11 +261,8 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE treeHelper.selectNode(node); } - // on repaint le noeud et ses enfants -// treeHelper.refreshNode(node, true); + // on reselectionne le noeud et ses enfants treeHelper.reloadSelectedNode(false, true); - -// treeHelper.refreshNode(node, false); } } @@ -262,6 +293,8 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE stopEditUI(); + reloadOpenContext(); + // création d'une nouvelle donnée ObserveTreeHelper treeHelper = getTreeHelper(getUi()); @@ -275,16 +308,11 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE treeHelper.addUnsavedNode(parentNode, getBeanType()); } - protected final void obtainChildPosition(E bean, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected final void obtainChildPosition(E bean) throws DataSourceException { String containerId = getSelectedParentId(); - int position = dataService.getOpenablePosition(dataSource, - containerId, - bean.getTopiaId() - ); + int position = getOpenablePosition(containerId, bean.getTopiaId()); if (log.isDebugEnabled()) { log.debug("Position of child : " + position); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java index b41a7c2..7938b31 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java @@ -22,29 +22,18 @@ package fr.ird.observe.ui.content.open.impl.longline; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.services.data.longline.ActivityLonglineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIModel; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.Loador; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; -import java.util.Calendar; -import java.util.Date; - import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -139,33 +128,31 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity if (log.isInfoEnabled()) { log.info(prefix + "content mode " + mode); } - ActivityLongline bean = getBean(); - - DataService dataService = getDataService(); boolean create = activityId == null; - Loador<ActivityLongline> binder = getLoadBinder(); - - DataSource source = getDataSource(); - + ActivityLongline loaded; + ActivityLonglineService service = getService(ActivityLonglineService.class); if (create) { // create mode - dataService.preCreate(source, tripId, bean, binder, getPreCreateExecutor()); + loaded = service.preCreate(tripId); } else { // update mode - dataService.loadEditEntity(source, activityId, getLoadExecutor()); + if (mode == ContentMode.UPDATE) { + loaded = service.loadForEdit(activityId); + } else { + loaded = service.loadForDisplay(activityId); + } } - if (log.isDebugEnabled()) { - log.debug(" long - lat = " + bean.getLongitude() + - " - " + bean.getLatitude()); - } + ActivityLongline bean = getBean(); + service.copyForEdit(loaded, bean); + finalizeOpenUI(mode, create); getUi().getCoordinatesEditor().setLatitudeAndLongitude(bean.getLatitude(), bean.getLongitude()); @@ -180,49 +167,6 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity } @Override - protected ActivityLongline onPreCreate(TopiaContext tx, Object parent, ActivityLongline bean) throws TopiaException { - TripLongline parentBean = (TripLongline) parent; - - bean.setOpen(true); - bean.setLatitude(null); - bean.setLongitude(null); - - Date timestamp; - - ActivityLongline lastActivityLongline = parentBean.getLastActivity(); - if (lastActivityLongline == null) { - - // première activité, on utilise la date de début de marée (voir http://forge.codelutin.com/issues/6777) - Calendar calendar = Calendar.getInstance(); - calendar.setTime(parentBean.getStartDate()); - timestamp = calendar.getTime(); - - } else { - - // passage en coordonnées absolue + quadrant - lastActivityLongline.initCoordinates(); - - // on recupère le quadrant de cette activity - // et on l'affecte à la nouvelle activity - Integer quadrant = lastActivityLongline.getQuadrant(); - if (log.isDebugEnabled()) { - log.debug("use quadrant of previous activity [" + quadrant + "]"); - } - bean.setQuadrant(quadrant); - - // on reprend la date et l'heure de la dernière activité - timestamp = lastActivityLongline.getTimeStamp(); - } - - bean.setTimeStamp(timestamp); - - if (log.isDebugEnabled()) { - log.debug("has pre-created : " + bean); - } - return bean; - } - - @Override public void startEditUI(String... binding) { ActivityLonglineUI ui = getUi(); @@ -255,88 +199,47 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity } @Override - protected boolean doSave(ActivityLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<ActivityLongline> binder) throws Exception { + protected boolean doSave(ActivityLongline bean) throws Exception { - if (log.isDebugEnabled()) { - log.debug(" long - lat = " + bean.getLongitude() + " - " + bean.getLatitude()); - } - boolean create = bean.getTopiaId() == null; - - String routeId = getSelectedParentId(); + String tripId = getSelectedParentId(); bean.setOpen(true); - if (create) { - bean = dataService.create(dataSource, routeId, bean, binder, getCreateExecutor()); - - } else { - - dataService.update(dataSource, routeId, bean, getUpdateExecutor()); - } + ActivityLonglineService service = getService(ActivityLonglineService.class); + ActivityLongline saved = service.save(tripId, bean); + bean.setTopiaId(saved.getTopiaId()); - obtainChildPosition(bean, dataService, dataSource); + obtainChildPosition(bean); return true; - } - @Override - protected ActivityLongline onCreate(TopiaContext tx, Object parent, ActivityLongline editBean) throws TopiaException { - TripLongline parentBean = (TripLongline) parent; - ActivityLongline beanToSave = ObserveDAOHelper.getActivityLonglineDAO(tx).create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - parentBean.addActivityLongline(beanToSave); - return beanToSave; } @Override - protected ActivityLongline onUpdate(TopiaContext tx, Object parentBean, ActivityLongline beanToSave) throws TopiaException { + protected boolean doDelete(ActivityLongline bean) { - ActivityLongline editBean = getBean(); + boolean result; - if (log.isInfoEnabled()) { - log.info("Final time to use : " + editBean.getTimeStamp()); - } - - getLoadBinder().copyExcluding(editBean, beanToSave, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); - - if (log.isInfoEnabled()) { - log.info("Is activity open ? : " + beanToSave.isOpen()); - } - return beanToSave; - } + if (askToDelete(bean)) { + result = false; + } else { - @Override - protected boolean doDelete(ActivityLongline bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, ActivityLongline> deletor) throws Exception { + if (log.isInfoEnabled()) { + log.info("Will delete Activity " + bean.getTopiaId()); + } - if (askToDelete(bean)) { - return false; - } - if (log.isInfoEnabled()) { - log.info("Will delete Activity " + bean.getTopiaId()); - } + ActivityLonglineService service = getService(ActivityLonglineService.class); + String tripId = getSelectedParentId(); + service.delete(tripId, bean.getTopiaId()); + if (log.isInfoEnabled()) { + log.info("Delete done for Activity " + bean.getTopiaId()); + } + result = true; - String tripId = getSelectedParentId(); - dataService.delete(dataSource, tripId, bean, deletor); - if (log.isInfoEnabled()) { - log.info("Delete done for Activity " + bean.getTopiaId()); } - return true; - - } + return result; - @Override - protected void onDelete(TopiaContext tx, Object parent, ActivityLongline beanToDelete) { - TripLongline parentBean = (TripLongline) parent; - parentBean.removeActivityLongline(beanToDelete); } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java index bcf6157..83985f0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java @@ -22,35 +22,23 @@ package fr.ird.observe.ui.content.open.impl.longline; * #L% */ -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; -import fr.ird.observe.entities.longline.ActivityLonglines; import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.services.Longline.TripLonglineServiceImp; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.longline.TripLonglineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; import fr.ird.observe.ui.util.tripMap.TripMapUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.DateUtil; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.util.Date; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -66,8 +54,6 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline /** Logger */ static private final Log log = LogFactory.getLog(TripLonglineUIHandler.class); - protected TripLonglineServiceImp service; - protected boolean buildTripMap = true; public TripLonglineUIHandler(TripLonglineUI ui) { @@ -127,10 +113,9 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline @Override public void run() { - TripLonglineUI ui = getUi(); - TripMapUI tripMap = ui.getTripMap(); - - tripMap.getHandler().doOpenMap(ui.getDataSource(), ui.getDataService(), getSelectedId()); + TripService service = getService(TripService.class); + TripMapUI tripMap = getUi().getTripMap(); + tripMap.getHandler().doOpenMap(service, getSelectedId()); } }); buildTripMap = false; @@ -159,12 +144,12 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline log.info(prefix + "mode = " + mode); } - DataService dataService = getDataService(); - - TripLongline bean = getBean(); + TripLongline loaded; - DataSource source = getDataSource(); boolean create = tripId == null; + + TripLonglineService service = getService(TripLonglineService.class); + if (create) { // create mode @@ -172,7 +157,8 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline if (log.isInfoEnabled()) { log.info(prefix + "create a new trip"); } - dataService.preCreate(source, programId, bean, getLoadBinder(), getPreCreateExecutor()); + + loaded = service.preCreate(programId); } else { @@ -180,15 +166,17 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline if (log.isInfoEnabled()) { log.info(prefix + "using existing trip " + tripId); } - dataService.loadEditEntity(source, tripId, getLoadExecutor()); - - if (!bean.isActivityLonglineEmpty()) { - // on force le trie des routes - ActivityLonglines.sort(bean.getActivityLongline()); + if (mode == ContentMode.UPDATE) { + loaded = service.loadForEdit(tripId); + } else { + loaded = service.loadForDisplay(tripId); } + } + TripLongline bean = getBean(); + service.copyForEdit(loaded, bean); getUi().getTripLonglineTabPane().setSelectedIndex(0); buildTripMap = true; @@ -196,21 +184,6 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline } @Override - protected TripLongline onPreCreate(TopiaContext tx, Object parent, TripLongline bean) throws TopiaException { - - Program parentBean = (Program) parent; - Date date = DateUtil.getDay(new Date()); - bean.setStartDate(date); - bean.setEndDate(date); - if (log.isDebugEnabled()) { - log.debug("start date : " + date); - log.debug("program : " + parentBean); - } - bean.setProgram(parentBean); - return bean; - } - - @Override public void startEditUI(String... binding) { TripLonglineUI ui = getUi(); @@ -233,16 +206,6 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline addInfoMessage(t("observe.message.historical.data")); } } - // date is current day - if (model.getMode() == ContentMode.UPDATE) { - if (getBean().getEndDate() == null) { - Date date = DateUtil.getEndOfDay(new Date()); - getBean().setEndDate(date); - if (log.isDebugEnabled()) { - log.debug("date fin " + date); - } - } - } super.startEditUI(TripLonglineUI.BINDING_VESSEL_SELECTED_ITEM, TripLonglineUI.BINDING_OBSERVER_SELECTED_ITEM, @@ -261,85 +224,43 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline } @Override - protected boolean doSave(TripLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<TripLongline> binder) throws Exception { - - String programId = getDataContext().getSelectedProgramId(); - - // on force toujours la date a etre sans heure, minute,... - Date startDate = DateUtil.getDay(bean.getStartDate()); - if (log.isDebugEnabled()) { - log.debug("startDate = " + startDate); - } - bean.setStartDate(startDate); - - // mise a jour de la date de fin - bean.updateDateFin(); - Date endDate = bean.getEndDate(); - if (log.isDebugEnabled()) { - log.debug("endDate = " + endDate); - } + protected boolean doSave(TripLongline bean) throws Exception { bean.setOpen(true); - if (bean.getTopiaId() == null) { - - dataService.create(dataSource, programId, bean, binder, getCreateExecutor()); - - } else { - - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - } + TripLonglineService service = getService(TripLonglineService.class); + TripLongline saved = service.save(bean); + bean.setTopiaId(saved.getTopiaId()); // recuperation de la position de la maree dans le program - obtainChildPosition(bean, dataService, dataSource); + obtainChildPosition(bean); return true; } @Override - protected TripLongline onCreate(TopiaContext tx, Object parent, TripLongline editBean) throws TopiaException { - TripLongline beanToSave = ObserveDAOHelper.getTripLonglineDAO(tx).create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - return beanToSave; - } + protected boolean doDelete(TripLongline bean) { - @Override - protected TripLongline onUpdate(TopiaContext tx, Object parentBean, TripLongline beanToSave) throws TopiaException { + boolean result; - getLoadBinder().copyExcluding(getBean(), beanToSave, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + if (askToDelete(bean)) { - return beanToSave; - } + result = false; - @Override - protected boolean doDelete(TripLongline bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, TripLongline> deletor) throws Exception { + } else { - if (askToDelete(bean)) { - return false; - } - if (log.isInfoEnabled()) { - log.info("Will delete Trip " + bean.getTopiaId()); - } + if (log.isInfoEnabled()) { + log.info("Will delete Trip " + bean.getTopiaId()); + } + + TripLonglineService service = getService(TripLonglineService.class); + service.delete(bean.getTopiaId()); + result = true; - dataService.delete(dataSource, null, bean, deletor); - if (log.isInfoEnabled()) { - log.info("Delete done for Trip " + bean.getTopiaId()); } - return true; - } - @Override - protected void onDelete(TopiaContext tx, Object parentBean, TripLongline beanToDelete) throws TopiaException { + return result; - TopiaDAO<TripLongline> dao = getDataSource().getDAO(tx, TripLongline.class); - dao.delete(beanToDelete); } @Override @@ -349,4 +270,5 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline return !create && !dataContext.isOpenTrip(); } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java index 933982b..9641102 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java @@ -21,40 +21,27 @@ */ package fr.ird.observe.ui.content.open.impl.seine; -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; -import fr.ird.observe.entities.referentiel.FpaZone; import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeineImpl; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.referential.ReferentialService; +import fr.ird.observe.services.data.seine.ActivitySeineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIModel; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; -import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.validator.swing.SwingValidatorMessage; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.Loador; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.DateUtil; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; -import java.util.Date; import java.util.HashSet; -import java.util.List; import java.util.Set; import static org.nuiton.i18n.I18n.n; @@ -173,31 +160,30 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei if (log.isInfoEnabled()) { log.info(prefix + "content mode " + mode); } - ActivitySeine bean = getBean(); - - DataService dataService = getDataService(); boolean create = activityId == null; - Loador<ActivitySeine> binder = getLoadBinder(); - - DataSource source = getDataSource(); + ActivitySeine loaded; + ActivitySeineService service = getService(ActivitySeineService.class); if (create) { // create mode - dataService.preCreate(source, routeId, bean, binder, getPreCreateExecutor()); + loaded = service.preCreate(routeId); } else { // update mode - dataService.loadEditEntity(source, activityId, getLoadExecutor()); + if (mode == ContentMode.UPDATE) { + loaded = service.loadForEdit(activityId); + } else { + loaded = service.loadForDisplay(activityId); + } } - if (log.isDebugEnabled()) { - log.debug(prefix + "long - lat = " + bean.getLongitude() + " - " + bean.getLatitude()); - } + ActivitySeine bean = getBean(); + service.copyForEdit(loaded, bean); SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); @@ -213,62 +199,7 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei // on annule la modification engendree par ce binding getModel().setModified(create); - } - - @Override - protected ActivitySeine onPreCreate(TopiaContext tx, - Object parent, - ActivitySeine bean) throws TopiaException { - Route parentBean = (Route) parent; - - bean.setOpen(true); - bean.setLatitude(null); - bean.setLongitude(null); - - Date time; - - FpaZone currentFpaZone = null; - - ActivitySeine lastActivitySeine = parentBean.getLastActivity(); - if (lastActivitySeine == null) { - // première activité, on utilise l'heure courante - time = new Date(); - - } else { - - // passage en coordonnées absolue + quadrant - lastActivitySeine.initCoordinates(); - - // on recupère le quadrant de cette activity - // et on l'affecte à la nouvelle activity - Integer quadrant = lastActivitySeine.getQuadrant(); - if (quadrant != null) { - - if (log.isDebugEnabled()) { - log.debug("use quadrant of previous activity [" + quadrant + "]"); - } - bean.setQuadrant(quadrant); - } - - // on reprend l'heure de la dernière activité - time = lastActivitySeine.getTime(); - - // utilisation des zones fpa de la dernière activité - currentFpaZone = lastActivitySeine.getNextFpaZone(); - if (currentFpaZone == null) { - currentFpaZone = lastActivitySeine.getCurrentFpaZone(); - } - - } - - bean.setTime(DateUtil.getTime(time, false, false)); - bean.setCurrentFpaZone(currentFpaZone); - - if (log.isDebugEnabled()) { - log.debug("has pre-created : " + bean); - } - return bean; } @Override @@ -308,92 +239,50 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei } @Override - protected boolean doSave(ActivitySeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<ActivitySeine> binder) throws Exception { + protected boolean doSave(ActivitySeine bean) throws Exception { if (log.isDebugEnabled()) { log.debug(" long - lat = " + bean.getLongitude() + " - " + bean.getLatitude()); } - boolean create = bean.getTopiaId() == null; String routeId = getSelectedParentId(); bean.setOpen(true); - if (create) { - bean = dataService.create(dataSource, routeId, bean, binder, getCreateExecutor()); - - } else { - - dataService.update(dataSource, routeId, bean, getUpdateExecutor()); - } + ActivitySeineService service = getService(ActivitySeineService.class); + ActivitySeine saved = service.save(routeId, bean); + bean.setTopiaId(saved.getTopiaId()); - obtainChildPosition(bean, dataService, dataSource); + obtainChildPosition(bean); return true; } @Override - protected ActivitySeine onCreate(TopiaContext tx, Object parent, ActivitySeine editBean) throws TopiaException { - Route parentBean = (Route) parent; - ActivitySeine beanToSave = ObserveDAOHelper.getActivitySeineDAO(tx).create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - parentBean.addActivitySeine(beanToSave); - return beanToSave; - } - - @Override - protected ActivitySeine onUpdate(TopiaContext tx, Object parentBean, ActivitySeine beanToSave) throws TopiaException { + protected boolean doDelete(ActivitySeine bean) { - ActivitySeine editBean = getBean(); + boolean result; - Route route = (Route) parentBean; - - Date d = DateUtil.getDateAndTime(route.getDate(), editBean.getTime(), false, false); - editBean.setTime(d); + if (askToDelete(bean)) { - if (log.isInfoEnabled()) { - log.info("Final time to use : " + d); - } + result = false; - getLoadBinder().copyExcluding(editBean, beanToSave, - ActivitySeine.PROPERTY_FLOATING_OBJECT, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM); + } else { - if (log.isInfoEnabled()) { - log.info("Is activity open ? : " + beanToSave.isOpen()); - } - return beanToSave; - } + if (log.isInfoEnabled()) { + log.info("Will delete Activity " + bean.getTopiaId()); + } - @Override - protected boolean doDelete(ActivitySeine bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, ActivitySeine> deletor) throws Exception { + String routeId = getSelectedParentId(); + ActivitySeineService service = getService(ActivitySeineService.class); + service.delete(routeId, bean.getTopiaId()); - if (askToDelete(bean)) { - return false; - } - if (log.isInfoEnabled()) { - log.info("Will delete Activity " + bean.getTopiaId()); - } + result = true; - String routeId = getSelectedParentId(); - dataService.delete(dataSource, routeId, bean, deletor); - if (log.isInfoEnabled()) { - log.info("Delete done for Activity " + bean.getTopiaId()); } - return true; - } + return result; - @Override - protected void onDelete(TopiaContext tx, Object parent, ActivitySeine beanToDelete) { - Route parentBean = (Route) parent; - parentBean.removeActivitySeine(beanToDelete); } @Override @@ -412,18 +301,11 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei public String getActivity6Label() { - try { - List<VesselActivitySeine> activitys = getDataService().getList(getDataSource(), VesselActivitySeine.class); - for (VesselActivitySeine a : activitys) { - if (ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE.equals(a.getCode())) { - String label = getDecoratorService().decorate(a); - return label; - } - } - } catch (DataSourceException ex) { - ErrorDialogUI.showError(ex); - } - throw new IllegalStateException(t("observe.error.no.activity.6")); + ReferentialService service = getService(ReferentialService.class); + VesselActivitySeine vesselActivitySeine = service.loadAndDecorate(VesselActivitySeine.class, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE_ID); + String label = getDecoratorService().decorate(vesselActivitySeine); + return label; + } protected void computeTabValidState(SwingValidatorMessageTableModel errorTableModel) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java index a2d8cd4..6bbbcc9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java @@ -21,32 +21,22 @@ */ package fr.ird.observe.ui.content.open.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeineImpl; -import fr.ird.observe.entities.seine.ActivitySeines; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.data.seine.RouteService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; -import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.DateUtil; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JOptionPane; @@ -61,7 +51,7 @@ import static org.nuiton.i18n.I18n.t; */ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { - public static final String UPDATE_MAREE_NODE = "updateTripNode"; + public static final String UPDATE_TRIP_NODE = "updateTripNode"; /** Logger */ static private Log log = LogFactory.getLog(RouteUIHandler.class); @@ -134,62 +124,32 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { log.info(prefix + "content mode = " + mode); } - DataService dataService = getDataService(); - - Route editBean = getBean(); + Route loaded; boolean create = routeId == null; + RouteService service = getService(RouteService.class); if (create) { // create mode - dataService.preCreate(getDataSource(), tripId, editBean, getLoadBinder(), getPreCreateExecutor()); + loaded = service.preCreate(tripId); } else { // update mode - dataService.loadEditEntity(getDataSource(), routeId, getLoadExecutor()); - - if (!editBean.isActivitySeineEmpty()) { - - // on force le trie des activitys - ActivitySeines.sort(editBean.getActivitySeine()); + if (mode == ContentMode.UPDATE) { + loaded = service.loadForEdit(routeId); + } else { + loaded = service.loadForDisplay(routeId); } - } - - finalizeOpenUI(mode, create); - } - - @Override - protected Route onPreCreate(TopiaContext tx, Object parent, Route bean) throws TopiaException { - - TripSeine parentBean = (TripSeine) parent; - Route lastRoute = parentBean.getLastRoute(); - - Date date; - if (lastRoute == null) { - - // aucune route defini, on utilise la date courante - date = new Date(); - - } else { - - // une route precedente est definie sur la maree - // le jour d'observation est le jour suivant celui de la - // derniere route - date = DateUtils.addDays(lastRoute.getDate(), 1); - // le loch du matin est le loch du soir de la derniere route - bean.setStartLogValue(lastRoute.getEndLogValue()); } - bean.setDate(DateUtil.getDay(date)); + Route bean = getBean(); + service.copyForEdit(loaded, bean); + + finalizeOpenUI(mode, create); - if (log.isInfoEnabled()) { - log.info("Will use date : " + bean.getDate()); - log.info("Will loch matin ast last loch soir : " + bean.getStartLogValue()); - } - return bean; } @Override @@ -231,31 +191,22 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { } @Override - protected boolean doSave(Route bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<Route> binder) throws Exception { + protected boolean doSave(Route bean) throws Exception { - String mareeId = getSelectedParentId(); + String tripId = getSelectedParentId(); if (log.isInfoEnabled()) { log.info("will save route " + bean.getTopiaId()); } - // on sauvegarde toujours en debut de jour - Date date = DateUtil.getDay(bean.getDate()); - bean.setDate(date); - bean.setOpen(true); - - if (bean.getTopiaId() == null) { - dataService.create(dataSource, mareeId, bean, binder, getCreateExecutor()); - } else { + bean.setOpen(true); - dataService.update(dataSource, mareeId, bean, getUpdateExecutor()); - } + RouteService service = getService(RouteService.class); + Route saved = service.save(tripId, bean); + bean.setTopiaId(saved.getTopiaId()); - obtainChildPosition(bean, dataService, dataSource); + obtainChildPosition(bean); return true; } @@ -272,84 +223,79 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { repaintTripNode(); } - @Override - protected Route onCreate(TopiaContext tx, Object parent, Route editBean) throws TopiaException { - - TripSeine parentBean = (TripSeine) parent; - - // creation de la route - Route beanToSave = ObserveDAOHelper.getRouteDAO(tx).create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - - // ajout de la route dans la amree - parentBean.addRoute(beanToSave); - - // on renseigne le jour d'observation car on en a besoin pour - // mettre la date de fin de la maree - beanToSave.setDate(editBean.getDate()); - - // on met a jour si necessaire la date de fin de la maree - updateDateFin(parentBean); - - return beanToSave; - } +// @Override +// protected Route onCreate(TopiaContext tx, Object parent, Route editBean) throws TopiaException { +// +// TripSeine parentBean = (TripSeine) parent; +// +// // creation de la route +// Route beanToSave = ObserveDAOHelper.getRouteDAO(tx).create(); +// editBean.setTopiaId(beanToSave.getTopiaId()); +// +// // ajout de la route dans la amree +// parentBean.addRoute(beanToSave); +// +// // on renseigne le jour d'observation car on en a besoin pour +// // mettre la date de fin de la maree +// beanToSave.setDate(editBean.getDate()); +// +// // on met a jour si necessaire la date de fin de la maree +// updateDateFin(parentBean); +// +// return beanToSave; +// } +// +// @Override +// protected Route onUpdate(TopiaContext tx, Object parent, Route beanToSave) throws TopiaException { +// +// TripSeine parentBean = (TripSeine) parent; +// +// Route editBean = getBean(); +// +// // on conserve l'ancienne date d'observation +// Date oldDate = DateUtil.getDay(beanToSave.getDate()); +// +// // recopie des propriétés vers le bean a sauver +// getLoadBinder().copyExcluding(editBean, beanToSave, Route.PROPERTY_ACTIVITY_SEINE); +// +// if (!oldDate.equals(editBean.getDate())) { +// +// // le jour a change, il faut mettre à jour les dates des activitys +// // et des sets +// beanToSave.updateDates(); +// } +// +// // on met a jour si necessaire la date de fin de la maree +// updateDateFin(parentBean); +// +// return beanToSave; +// } @Override - protected Route onUpdate(TopiaContext tx, Object parent, Route beanToSave) throws TopiaException { + protected boolean doDelete(Route bean) { - TripSeine parentBean = (TripSeine) parent; + boolean result; - Route editBean = getBean(); - - // on conserve l'ancienne date d'observation - Date oldDate = DateUtil.getDay(beanToSave.getDate()); - - // recopie des propriétés vers le bean a sauver - getLoadBinder().copyExcluding(editBean, beanToSave, Route.PROPERTY_ACTIVITY_SEINE); + if (askToDelete(bean)) { - if (!oldDate.equals(editBean.getDate())) { + result = false; - // le jour a change, il faut mettre à jour les dates des activitys - // et des sets - beanToSave.updateDates(); - } + } else { - // on met a jour si necessaire la date de fin de la maree - updateDateFin(parentBean); + if (log.isInfoEnabled()) { + log.info("Will delete Route " + bean.getTopiaId()); + } - return beanToSave; - } + RouteService service = getService(RouteService.class); + String tripId = getSelectedParentId(); + service.delete(tripId, bean.getTopiaId()); - @Override - protected boolean doDelete(Route bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, Route> deletor) throws Exception { + result = true; - if (askToDelete(bean)) { - return false; } - if (log.isInfoEnabled()) { - log.info("Will delete Route " + bean.getTopiaId()); - } - - String mareeId = getSelectedParentId(); - dataService.delete(dataSource, mareeId, bean, deletor); - if (log.isInfoEnabled()) { - log.info("Delete done for Route " + bean.getTopiaId()); - } - return true; - } - - @Override - protected void onDelete(TopiaContext tx, Object parent, Route beanToDelete) { - TripSeine parentBean = (TripSeine) parent; - // suppression de la route - parentBean.removeRoute(beanToDelete); + return result; - // mise à jour de la date de fin de marée - updateDateFin(parentBean); } @Override @@ -507,9 +453,14 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { } protected void repaintTripNode() { - Boolean updateTripNode = getUi().getContextValue(Boolean.class, UPDATE_MAREE_NODE); - getUi().removeContextValue(Boolean.class, UPDATE_MAREE_NODE); + // on met a jour si necessaire la date de fin de la maree + //FIXME Remettre ça en place +// updateDateFin(parentBean); + + Boolean updateTripNode = getUi().getContextValue(Boolean.class, UPDATE_TRIP_NODE); + + getUi().removeContextValue(Boolean.class, UPDATE_TRIP_NODE); if (updateTripNode == null || !updateTripNode) { return; @@ -522,10 +473,11 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { log.info("Refresh trip node : " + tripNode); } treeHelper.reloadNode(tripNode, false); -// treeHelper.refreshNode(tripNode, false); + } protected void updateDateFin(TripSeine parentBean) { + Date endDate = parentBean.getEndDate(); // on met a jour si necessaire la date de fin de la maree @@ -536,10 +488,11 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { // la date de fin a ete modifiee, il faut : // redessiner le noeud de la maree // le repositionner - getUi().setContextValue(Boolean.TRUE, UPDATE_MAREE_NODE); + getUi().setContextValue(Boolean.TRUE, UPDATE_TRIP_NODE); } else { - getUi().removeContextValue(Boolean.class, UPDATE_MAREE_NODE); + getUi().removeContextValue(Boolean.class, UPDATE_TRIP_NODE); } + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java index 0a59641..234ab99 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java @@ -21,34 +21,23 @@ */ package fr.ird.observe.ui.content.open.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.seine.Routes; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.TripSeineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; import fr.ird.observe.ui.util.tripMap.TripMapUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.DateUtil; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.util.Date; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -71,8 +60,6 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { n("observe.tripSeine.message.not.open")); } - - @Override public TripSeineUI getUi() { return (TripSeineUI) super.getUi(); @@ -124,10 +111,10 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { @Override public void run() { - TripSeineUI ui = getUi(); - TripMapUI tripMap = ui.getTripMap(); - tripMap.getHandler().doOpenMap(ui.getDataSource(), ui.getDataService(), getSelectedId()); + TripService service = getService(TripService.class); + TripMapUI tripMap = getUi().getTripMap(); + tripMap.getHandler().doOpenMap(service, getSelectedId()); } }); buildTripMap = false; @@ -156,11 +143,10 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { log.info(prefix + "mode = " + mode); } - DataService dataService = getDataService(); + TripSeineService service = getService(TripSeineService.class); - TripSeine bean = getBean(); + TripSeine loaded; - DataSource source = getDataSource(); boolean create = tripId == null; if (create) { @@ -169,23 +155,27 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { if (log.isInfoEnabled()) { log.info(prefix + "create a new trip"); } - dataService.preCreate(source, programId, bean, getLoadBinder(), getPreCreateExecutor()); + + + loaded = service.preCreate(programId); + } else { // update mode if (log.isInfoEnabled()) { log.info(prefix + "using existing trip " + tripId); } - dataService.loadEditEntity(source, tripId, getLoadExecutor()); - if (!bean.isRouteEmpty()) { - - // on force le trie des routes - Routes.sort(bean.getRoute()); + if (mode == ContentMode.UPDATE) { + loaded = service.loadForEdit(tripId); + } else { + loaded = service.loadForDisplay(tripId); } } + TripSeine bean = getBean(); + service.copyForEdit(loaded, bean); getUi().getTripSeineTabPane().setSelectedIndex(0); buildTripMap = true; @@ -193,21 +183,6 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { } @Override - protected TripSeine onPreCreate(TopiaContext tx, Object parent, TripSeine bean) throws TopiaException { - - Program parentBean = (Program) parent; - Date date = DateUtil.getDay(new Date()); - bean.setStartDate(date); - bean.setEndDate(date); - if (log.isDebugEnabled()) { - log.debug("start date : " + date); - log.debug("program : " + parentBean); - } - bean.setProgram(parentBean); - return bean; - } - - @Override public void startEditUI(String... binding) { TripSeineUI ui = getUi(); @@ -232,17 +207,6 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { } } - // date is current day - if (model.getMode() == ContentMode.UPDATE) { - if (getBean().getEndDate() == null) { - Date date = DateUtil.getEndOfDay(new Date()); - getBean().setEndDate(date); - if (log.isDebugEnabled()) { - log.debug("end date : " + date); - } - } - } - super.startEditUI(TripSeineUI.BINDING_VESSEL_SELECTED_ITEM, TripSeineUI.BINDING_OBSERVER_SELECTED_ITEM, TripSeineUI.BINDING_CAPTAIN_SELECTED_ITEM, @@ -258,85 +222,41 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { } @Override - protected boolean doSave(TripSeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<TripSeine> binder) throws Exception { - - String programId = getDataContext().getSelectedProgramId(); - - // on force toujours la date a etre sans heure, minute,... - Date startDate = DateUtil.getDay(bean.getStartDate()); - if (log.isDebugEnabled()) { - log.debug("startDate = " + startDate); - } - bean.setStartDate(startDate); - - // mise a jour de la date de fin - bean.updateDateFin(); - Date endDate = bean.getEndDate(); - if (log.isDebugEnabled()) { - log.debug("endDate = " + endDate); - } + protected boolean doSave(TripSeine bean) throws Exception { bean.setOpen(true); - if (bean.getTopiaId() == null) { - - dataService.create(dataSource, programId, bean, binder, getCreateExecutor()); - - } else { - - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - } + TripSeineService service = getService(TripSeineService.class); + TripSeine saved = service.save(bean); + bean.setTopiaId(saved.getTopiaId()); // recuperation de la position de la maree dans le program - obtainChildPosition(bean, dataService, dataSource); + obtainChildPosition(bean); return true; } @Override - protected TripSeine onCreate(TopiaContext tx, Object parent, TripSeine editBean) throws TopiaException { - TripSeine beanToSave = ObserveDAOHelper.getTripSeineDAO(tx).create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - return beanToSave; - } - - @Override - protected TripSeine onUpdate(TopiaContext tx, Object parentBean, TripSeine beanToSave) throws TopiaException { + protected boolean doDelete(TripSeine bean) { - getLoadBinder().copyExcluding(getBean(), beanToSave, TripSeine.PROPERTY_ROUTE, TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); + boolean result; - return beanToSave; - } + if (askToDelete(bean)) { - @Override - protected boolean doDelete(TripSeine bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, TripSeine> deletor) throws Exception { + result = false; - if (askToDelete(bean)) { - return false; - } - if (log.isInfoEnabled()) { - log.info("Will delete Trip " + bean.getTopiaId()); - } + } else { - dataService.delete(dataSource, null, bean, deletor); - if (log.isInfoEnabled()) { - log.info("Delete done for Trip " + bean.getTopiaId()); - } - return true; - } + if (log.isInfoEnabled()) { + log.info("Will delete Trip " + bean.getTopiaId()); + } - @Override - protected void onDelete(TopiaContext tx, Object parentBean, TripSeine beanToDelete) throws TopiaException { + TripSeineService service = getService(TripSeineService.class); + service.delete(bean.getTopiaId()); + result = true; - TopiaDAO<TripSeine> dao = getDataSource().getDAO(tx, TripSeine.class); - dao.delete(beanToDelete); + } + return result; } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java index d0a9398..378451f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java @@ -36,6 +36,7 @@ import fr.ird.observe.entities.referentiel.I18nReferenceEntity; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.entities.referentiel.VesselSizeCategory; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; @@ -229,18 +230,11 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten * @param button le boutton qui a declanche l'action */ public void showUniqueKeys(JButton button) { - List<E> entities; Class<E> beanType = getBeanType(); - try { - entities = getDataService().loadDecoratedEntities(getDataSource(), - beanType); - - } catch (DataSourceException e) { - ErrorDialogUI.showError(e); - return; - } + ReferentialService service = getService(ReferentialService.class); + List<E> entities = service.loadAndDecorateList(beanType); List<Object[]> datas = new ArrayList<Object[]>(entities.size()); @@ -333,22 +327,13 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } // recherche des utilisation du bean dans la base - EntityMap usages; - try { - usages = getDataService().findAllUsages(getDataSource(), bean); - } catch (DataSourceException e) { - ErrorDialogUI.showError(e); - if (log.isErrorEnabled()) { - log.error(e); - } - return; - } + ReferentialService service = getService(ReferentialService.class); + EntityMap usages = service.findAllUsages(bean); DecoratorService dService = ObserveContext.get().getDecoratorService(); Decorator<?> decorator = dService.getDecoratorByType(bean.getClass()); String type = DecoratorService.getEntityLabel(bean.getClass()); type = t(type); - String message = t("observe.message.show.usages", type, - decorator.toString(bean)); + String message = t("observe.message.show.usages", type, decorator.toString(bean)); ContentReferenceUI<E> ui = getUi(); @@ -407,7 +392,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten public void initUI() throws Exception { ReferentialContentUIInitializer<E, ContentReferenceUI<E>> uiInitializer = new ReferentialContentUIInitializer<E, ContentReferenceUI<E>>(getUi()); - uiInitializer.initUI(getDataSource()); + uiInitializer.initUI(ObserveContext.get().getServices()); ContentReferenceUI<E> ui = getUi(); @@ -679,7 +664,8 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten log.debug("entity status was desactivated, looking " + "for usage"); } - EntityMap usages = dataService.findAllUsages(dataSource, bean); + ReferentialService service = getService(ReferentialService.class); + EntityMap usages = service.findAllUsages(bean); if (usages.isEmpty()) { if (log.isInfoEnabled()) { @@ -738,7 +724,9 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } // recherche des utilisation du bean dans la base - EntityMap usages = dataService.findAllUsages(getDataSource(), bean); + + ReferentialService service = getService(ReferentialService.class); + EntityMap usages = service.findAllUsages(bean); if (usages.isEmpty()) { if (log.isDebugEnabled()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index 1c6c060..76e2783 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -29,6 +29,7 @@ import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species2; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; @@ -258,7 +259,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>> uiInitializer = new ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>>(getUi()); - uiInitializer.initUI(getDataSource()); + uiInitializer.initUI(ObserveContext.get().getServices()); } @@ -266,7 +267,10 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top Set<String> speciesIds; try { - speciesIds = getDataService().getSpeciesListSpeciesIds(getDataSource(), speciesListId); + + ReferentialService service = getService(ReferentialService.class); + speciesIds = service.getSpeciesListSpeciesIds(speciesListId); + } catch (Exception e) { UIHelper.displayWarning(t("observe.title.speciesList.not.found"), t(errorMessage)); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java index f510997..879e5e0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java @@ -22,8 +22,8 @@ package fr.ird.observe.ui.content.table; * #L% */ -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.content.ContentUIInitializer; import fr.ird.observe.ui.util.BooleanEditor; import jaxx.runtime.SwingUtil; @@ -84,11 +84,11 @@ public class ContentTableUIInitializer<E extends TopiaEntity, D extends TopiaEnt } @Override - public void initUI(DataSource dataSource) throws Exception { + public void initUI(ObserveServiceFactory serviceFactory) throws Exception { - attachTopiaContext(dataSource, (TopiaEntityAbstract) getTableEditBean()); + attachTopiaContext(serviceFactory, (TopiaEntityAbstract) getTableEditBean()); - super.initUI(dataSource); + super.initUI(serviceFactory); ContentTableModel<?, ?> tableModel = ui.getTableModel(); ui.setContextValue(tableModel); @@ -185,8 +185,7 @@ public class ContentTableUIInitializer<E extends TopiaEntity, D extends TopiaEnt } @Override - protected void init(ActionMap actionMap, - AbstractButton editor) throws DataSourceException { + protected void init(ActionMap actionMap, AbstractButton editor) { super.init(actionMap, editor); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index ae4a399..37a84b4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -27,13 +27,10 @@ import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.CatchLongline; @@ -48,6 +45,9 @@ import fr.ird.observe.entities.referentiel.longline.CatchFateLongline; import fr.ird.observe.entities.referentiel.longline.Healthness; import fr.ird.observe.entities.referentiel.longline.SizeMeasureType; import fr.ird.observe.entities.referentiel.longline.WeightMeasureType; +import fr.ird.observe.services.data.longline.CatchLonglineService; +import fr.ird.observe.services.data.longline.SetLonglineService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIInitializer; @@ -63,7 +63,6 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; @@ -145,10 +144,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C JAXXContextEntryDef<LonglinePositionHelper<CatchLongline>> POSITION_HELPER_ENTRY = UIHelper.newContextEntryDef("CatchLonglineUI-positionHelper", LonglinePositionHelper.class); - private TopiaExecutor<? extends TopiaEntity> branchlineUpdator; - - private TopiaExecutor2<TopiaEntity, Branchline> branchlineUpdateExecutor; - public CatchLonglineUIHandler(CatchLonglineUI ui) { super(ui, DataContextType.SetLongline); } @@ -180,6 +175,8 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C boolean emptySelection = editingRow == -1; + CatchLonglineService service = getService(CatchLonglineService.class); + // load size measures SizeMeasuresTableModel sizeMeasuresTableModel = model.getSizeMeasuresTableModel(); @@ -204,16 +201,12 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } else { // updating mode: loading from db - try { - - sizes = getDataService().getCatchLonglineSizeMeasures(getDataSource(), bean, sizeMeasuresTableModel.getLoader()); - if (log.isInfoEnabled()) { - log.info("Loaded sizes (" + bean.getTopiaId() + "): " + sizes.size()); - } - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not load size measures", e); + sizes = service.getCatchLonglineSizeMeasures(bean.getTopiaId()); + if (log.isInfoEnabled()) { + log.info("Loaded sizes (" + bean.getTopiaId() + "): " + sizes.size()); } + } // init size measures @@ -243,15 +236,10 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } else { // updating mode: loading from db - try { - - weights = getDataService().getCatchLonglineWeightMeasures(getDataSource(), bean, weightMeasuresTableModel.getLoader()); - if (log.isInfoEnabled()) { - log.info("Loaded weights (" + bean.getTopiaId() + "): " + weights.size()); - } - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not load weight measures", e); + weights = service.getCatchLonglineWeightMeasures(bean.getTopiaId()); + if (log.isInfoEnabled()) { + log.info("Loaded weights (" + bean.getTopiaId() + "): " + weights.size()); } } @@ -378,6 +366,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } + ReferentialService service = getService(ReferentialService.class); { // init size measures table JTable table = getUi().getSizeMeasuresTable(); @@ -393,12 +382,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C Decorator<SizeMeasureType> decorator = ObserveContext.get().getDecorator(SizeMeasureType.class); - List<SizeMeasureType> list; - try { - list = getDataService().getList(getDataSource(), SizeMeasureType.class); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not get size measure types", e); - } + List<SizeMeasureType> list = service.loadAndDecorateList(SizeMeasureType.class); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); @@ -423,12 +407,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C Decorator<WeightMeasureType> decorator = ObserveContext.get().getDecorator(WeightMeasureType.class); - List<WeightMeasureType> list; - try { - list = getDataService().getList(getDataSource(), WeightMeasureType.class); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not get size measure types", e); - } + List<WeightMeasureType> list = service.loadAndDecorateList(WeightMeasureType.class); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); @@ -469,9 +448,8 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C prepareSpeciesList(speciesListId, getUi().getPredator(), n("observe.error.speciesList.longline.depredator.notFound")); } - CatchLonglineContentTableUIInitializer uiInitializer = new CatchLonglineContentTableUIInitializer(getUi()); - uiInitializer.initUI(getDataSource()); + uiInitializer.initUI(ObserveContext.get().getServices()); getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_SHOW_INDIVIDUAL_TABS, new PropertyChangeListener() { @Override @@ -516,7 +494,8 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C getModel().getWeightMeasuresTableModel().clear(); // load sections (and baskets and branchlines) - List<Section> sections = dataService.getSections(dataSource, setLongline.getTopiaId()); + SetLonglineService service = getService(SetLonglineService.class); + List<Section> sections = service.getSections(setLongline.getTopiaId()); LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); positionHelper.initSections(sections, getTableModel().getData()); @@ -685,17 +664,13 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C log.info("Saved modified branchline"); } - try { - - Branchline branchline = getTableEditBean().getBranchline(); - Branchline beanSaved = getDataService().update(getDataSource(), null, branchline, getBranchlineUpdateExecutor()); - getTableEditBean().setBranchline(beanSaved); - getUi().getBranchlineValidator().setChanged(false); + Branchline branchline = getTableEditBean().getBranchline(); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not save branchline", e); - } + CatchLonglineService service = getService(CatchLonglineService.class); + Branchline beanSaved = service.saveBranchline(branchline); + getTableEditBean().setBranchline(beanSaved); + getUi().getBranchlineValidator().setChanged(false); } @@ -856,11 +831,9 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C branchlineValidator.setBean(branchline); - try { - getDataService().loadEditEntity(getDataSource(), newValue.getTopiaId(), getBranchlineUpdator()); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not load branchline", e); - } + CatchLonglineService service = getService(CatchLonglineService.class); + Branchline loadedBranchline = service.loadBranchlineForEdit(newValue.getTopiaId()); + service.copyBranchlineForEdit(loadedBranchline, getUi().getBranchlineBean()); } @@ -951,41 +924,4 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C return (CatchLonglineTableModel) super.getTableModel(); } - protected TopiaExecutor<? extends TopiaEntity> getBranchlineUpdator() { - if (branchlineUpdator == null) { - branchlineUpdator = new TopiaExecutor<Branchline>() { - - private final TopiaEntityBinder<Branchline> branchlineLoador = getModel().getBranchlineLoador(); - - @Override - public void execute(TopiaContext tx, Branchline newValue) throws TopiaException { - - Branchline editBean = getUi().getBranchlineBean(); - branchlineLoador.load(newValue, editBean, false); - - } - }; - } - return branchlineUpdator; - } - - protected TopiaExecutor2<TopiaEntity, Branchline> getBranchlineUpdateExecutor() { - if (branchlineUpdateExecutor == null) { - branchlineUpdateExecutor = new TopiaExecutor2<TopiaEntity, Branchline>() { - - private final TopiaEntityBinder<Branchline> branchlineLoador = getModel().getBranchlineLoador(); - - @Override - public Branchline execute(TopiaContext tx, TopiaEntity parentBean, Branchline beanToSave) throws TopiaException { - - Branchline editBean = getUi().getBranchlineBean(); - branchlineLoador.load(editBean, beanToSave, false); - return beanToSave; - - } - }; - } - return branchlineUpdateExecutor; - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java index aa35ae2..6e15270 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.table.impl.longline; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.CatchLongline; import fr.ird.observe.entities.longline.SetLongline; @@ -33,7 +32,6 @@ import fr.ird.observe.ui.content.table.ContentTableMeta; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIModel; import fr.ird.observe.ui.content.table.ObserveContentTableUI; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderModelBuilder; @@ -113,8 +111,6 @@ public class CatchLonglineUIModel extends ContentTableUIModel<SetLongline, Catch protected boolean branchlineTabValid; - private TopiaEntityBinder<Branchline> branchlineLoador; - public CatchLonglineUIModel(CatchLonglineUI ui) { super(SetLongline.class, CatchLongline.class, @@ -233,34 +229,4 @@ public class CatchLonglineUIModel extends ContentTableUIModel<SetLongline, Catch } - @Override - public void initModel(ObserveContentTableUI<SetLongline, CatchLongline> ui, List<ContentTableMeta<CatchLongline>> contentTableMetas) { - super.initModel(ui, contentTableMetas); - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - - String binderName = getClass().getName() + "-open"; - - branchlineLoador = binderService.getTopiaBinder(Branchline.class, binderName); - - if (branchlineLoador == null) { - - BinderModelBuilder<Branchline, Branchline> builder = - binderService.newBinderBuilder(Branchline.class, - Branchline.PROPERTY_DEPTH_RECORDER, - Branchline.PROPERTY_HOOK_LOST, - Branchline.PROPERTY_TRACE_CUT_OFF, - Branchline.PROPERTY_TIMER, - Branchline.PROPERTY_TIME_SINCE_CONTACT, - Branchline.PROPERTY_TIMER_TIME_ON_BOARD, - Branchline.PROPERTY_BAIT_HAULING_STATUS); - - branchlineLoador = binderService.registerTopiaBinder(Branchline.class, builder, binderName); - - } - } - - public TopiaEntityBinder<Branchline> getBranchlineLoador() { - return branchlineLoador; - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineTableModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineTableModel.java index 6cb4dba..c869ab1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineTableModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineTableModel.java @@ -22,16 +22,13 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ -import fr.ird.observe.entities.referentiel.Gear; -import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; +import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.ui.content.table.ContentTableMeta; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ObserveContentTableUI; -import fr.ird.observe.ui.content.table.impl.longline.GearUseFeaturesMeasurementLonglinesTableModel; -import fr.ird.observe.ui.content.table.impl.longline.GearUseFeaturesLonglineUIHandler; -import fr.ird.observe.ui.content.table.impl.longline.GearUseFeaturesLonglineUIModel; import org.apache.commons.collections4.CollectionUtils; import java.util.List; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 5380406..dfce5c6 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -25,17 +25,17 @@ package fr.ird.observe.ui.content.table.impl.longline; import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.entities.referentiel.Gear; -import fr.ird.observe.entities.referentiel.GearCaracteristic; +import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLonglineDAO; -import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.referentiel.Gear; +import fr.ird.observe.entities.referentiel.GearCaracteristic; +import fr.ird.observe.services.data.longline.GearUseFeaturesLonglineService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -164,16 +164,13 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } else { // updating mode: loading from db - try { - - measurements = getDataService().getGearUseFeaturesMeasurementLongline(getDataSource(), bean, measurementsTableModel.getLoader()); - if (log.isInfoEnabled()) { - log.info("Loaded measurements (" + bean.getTopiaId() + "): " + measurements.size()); - } - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not load measurements", e); + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); + measurements = service.loadGearUseFeaturesMeasurementLonglineForEdit(bean.getTopiaId()); + if (log.isInfoEnabled()) { + log.info("Loaded measurements (" + bean.getTopiaId() + "): " + measurements.size()); } + } // init measurements @@ -253,12 +250,8 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip Decorator<GearCaracteristic> decorator = ObserveContext.get().getDecorator(GearCaracteristic.class); - List<GearCaracteristic> list; - try { - list = getDataService().getList(getDataSource(), GearCaracteristic.class); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not get gear caracteristics", e); - } + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); + List<GearCaracteristic> list = service.getList(GearCaracteristic.class); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); UIHelper.setTableColumnEditor(table, 1, new GearUseFeatureMeasurementCellEditor(0)); @@ -369,7 +362,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip if (!selectionEmpty) { - GearUseFeaturesMeasurementLongline data = tableModel.getSelectedRow(); + GearUseFeaturesMeasurementLongline data = tableModel.getSelectedRow(); if (log.isInfoEnabled()) { log.info("Delete: " + data); @@ -540,15 +533,11 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(String gearId) { - try { - List<GearUseFeaturesMeasurementLongline> measurements = getDataService().getDefaultGearUseFeaturesMeasurementLongline(getDataSource(), gearId); - if (log.isInfoEnabled()) { - log.info("Create mode, use default measurements: " + measurements.size()); - } - return measurements; - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not create default measurements", e); + List<GearUseFeaturesMeasurementLongline> measurements = getService(GearUseFeaturesLonglineService.class).getDefaultGearUseFeaturesMeasurementLongline(gearId); + if (log.isInfoEnabled()) { + log.info("Create mode, use default measurements: " + measurements.size()); } + return measurements; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java index 1a65d27..f261ed5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java @@ -30,13 +30,13 @@ import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SensorUsed; import fr.ird.observe.entities.referentiel.longline.SensorBrand; import fr.ird.observe.entities.referentiel.longline.SensorDataFormat; import fr.ird.observe.entities.referentiel.longline.SensorType; +import fr.ird.observe.services.data.longline.SensorUsedService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; @@ -186,12 +186,8 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, public void exportData() { - String filename; - try { - filename = getDataService().getSensorUsedDataFilename(getDataSource(), getTableEditBean()); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not obtain sensorUser data export filename", e); - } + SensorUsedService service = getService(SensorUsedService.class); + String filename = service.getSensorUsedDataFilename(getTableEditBean()); File file = JaxxFileChooser .forSaving() diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java index f01592f..f2400fe 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java @@ -37,6 +37,8 @@ import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.entities.referentiel.longline.SensorBrand; +import fr.ird.observe.services.data.longline.SetLonglineService; +import fr.ird.observe.services.data.longline.TdrService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -268,7 +270,8 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { SetLongline setLongline = super.loadEditBean(mode, dataContext, dataService, dataSource); // load sections (and baskets and branchlines) - List<Section> sections = dataService.getSections(dataSource, setLongline.getTopiaId()); + SetLonglineService service = getService(SetLonglineService.class); + List<Section> sections = service.getSections(setLongline.getTopiaId()); LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); positionHelper.initSections(sections, getTableModel().getData()); @@ -366,12 +369,7 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { public void exportData() { - String filename; - try { - filename = getDataService().getTdrDataFilename(getDataSource(), getTableEditBean()); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not obtain tdr data export filename", e); - } + String filename = getService(TdrService.class).getTdrDataFilename(getTableEditBean()); File file = JaxxFileChooser .forSaving() diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index 5fa35cc..08161ec 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; @@ -36,6 +35,7 @@ import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineDAO; import fr.ird.observe.entities.seine.GearUseFeaturesSeine; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.data.seine.GearUseFeaturesSeineService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -162,16 +162,12 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } else { // updating mode: loading from db - try { - - measurements = getDataService().getGearUseFeaturesMeasurementSeine(getDataSource(), bean, measurementsTableModel.getLoader()); - if (log.isInfoEnabled()) { - log.info("Loaded measurements (" + bean.getTopiaId() + "): " + measurements.size()); - } - - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not load measurements", e); + GearUseFeaturesSeineService service = getService(GearUseFeaturesSeineService.class); + measurements = service.loadGearUseFeaturesMeasurementSeineForEdit(bean.getTopiaId()); + if (log.isInfoEnabled()) { + log.info("Loaded measurements (" + bean.getTopiaId() + "): " + measurements.size()); } + } // init measurements @@ -251,12 +247,8 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei Decorator<GearCaracteristic> decorator = ObserveContext.get().getDecorator(GearCaracteristic.class); - List<GearCaracteristic> list; - try { - list = getDataService().getList(getDataSource(), GearCaracteristic.class); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not get gear caracteristics", e); - } + GearUseFeaturesSeineService service = getService(GearUseFeaturesSeineService.class); + List<GearCaracteristic> list = service.getList(GearCaracteristic.class); UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); UIHelper.setTableColumnEditor(table, 1, new GearUseFeatureMeasurementCellEditor(0)); @@ -367,7 +359,7 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei if (!selectionEmpty) { - GearUseFeaturesMeasurementSeine data = tableModel.getSelectedRow(); + GearUseFeaturesMeasurementSeine data = tableModel.getSelectedRow(); if (log.isInfoEnabled()) { log.info("Delete: " + data); @@ -394,12 +386,6 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } - - @Override - protected TripSeine onCreate(TopiaContext tx, Object parentBean, TripSeine editBean) throws TopiaException { - return super.onCreate(tx, parentBean, editBean); - } - @Override protected void onUpdateFinalize(TopiaContext tx, TripSeine bean, Collection<GearUseFeaturesSeine> oldChilds) throws TopiaException { @@ -539,15 +525,12 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(String gearId) { - try { - List<GearUseFeaturesMeasurementSeine> measurements = getDataService().getDefaultGearUseFeaturesMeasurementSeine(getDataSource(), gearId); - if (log.isInfoEnabled()) { - log.info("Create mode, use default measurements: " + measurements.size()); - } - return measurements; - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Could not create default measurements", e); + GearUseFeaturesSeineService service = getService(GearUseFeaturesSeineService.class); + List<GearUseFeaturesMeasurementSeine> measurements = service.getDefaultGearUseFeaturesMeasurementSeine(gearId); + if (log.isInfoEnabled()) { + log.info("Create mode, use default measurements: " + measurements.size()); } + return measurements; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 34d7a16..417e8fc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -38,6 +38,9 @@ import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.NonTargetSampleService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -230,15 +233,13 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non if (mode == ContentMode.UPDATE) { // get current ocean - Ocean ocean = dataService.getTripOcean( - dataSource, dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineNonTargetCatchId(); // get all species - List<Species> allSpecies = - dataService.loadDecoratedSpecies(dataSource, speciesListId); + List<Species> allSpecies = getService(ReferentialService.class).loadDecoratedSpecies(speciesListId); // filtre par status actif ReferenceEntities.filterReferentielListByStatus(allSpecies); @@ -365,11 +366,11 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non Collection<Species> speciessToDelete = new HashSet<Species>(); List<NonTargetLength> tailleToDelete = new ArrayList<NonTargetLength>(); - getDataService().getObsoleteEspeceForNonTargetSample(getDataSource(), - editBean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete); + NonTargetSampleService service = getService(NonTargetSampleService.class); + service.getObsoleteEspeceForNonTargetSample(editBean.getTopiaId(), + speciessUsed, + speciessToDelete, + tailleToDelete); if (!tailleToDelete.isEmpty()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index a78c28e..7d3cd34 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -32,6 +32,7 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.data.seine.NonTargetSampleService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -120,10 +121,14 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) throws DataSourceException { + String setId = dataContext.getSelectedSetId(); + // on doit récupérer l'unique échantillonThon de la calée - String id = dataService.getNonTargetSampleId(dataSource, setId); + NonTargetSampleService service = getService(NonTargetSampleService.class); + String id = service.getNonTargetSampleId(setId); return id; + } @Override @@ -132,19 +137,20 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam DataService dataService, DataSource dataSource) throws DataSourceException { - List<Species> speciess; + List<Species> speciesList; String setId = dataContext.getSelectedSetId(); if (mode == ContentMode.UPDATE) { - - speciess = dataService.getAvailableEspeceForNonTargetSample(dataSource, setId); + NonTargetSampleService service = getService(NonTargetSampleService.class); + speciesList = service.getAvailableEspeceForNonTargetSample(setId); } else { - speciess = new ArrayList<Species>(); + speciesList = new ArrayList<Species>(); } - ALL_ESPECES_ENTRY.setContextValue(getUi(), speciess); + + ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); // on doit récupérer l'unique échantillonThon de la calée String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); @@ -340,16 +346,9 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam protected ContentMode getContentMode(DataContext dataContext) { ContentMode mode = super.getContentMode(dataContext); - boolean showData = false; - - try { - String setId = getDataContext().getSelectedSetId(); - showData = getDataService().canUseNonTargetSample(getDataSource(), setId); - } catch (DataSourceException e) { - if (log.isErrorEnabled()) { - log.error(e); - } - } + String setId = getDataContext().getSelectedSetId(); + NonTargetSampleService service = getService(NonTargetSampleService.class); + boolean showData = service.canUseNonTargetSample(setId); getUi().getModel().setShowData(showData); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index b6ae93a..4cc82df 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -33,6 +33,8 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.Species2; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -84,15 +86,13 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch if (mode == ContentMode.UPDATE) { // get current ocean - Ocean ocean = dataService.getTripOcean( - dataSource, dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); // get all species from the configured speciesList ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineSchoolEstimateId(); - List<Species> allSpecies = - dataService.loadDecoratedSpecies(dataSource, speciesListId); + List<Species> allSpecies = getService(ReferentialService.class).loadDecoratedSpecies(speciesListId); // filtre par status actif ReferenceEntities.filterReferentielListByStatus(allSpecies); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java index 2068cda..6d0361c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java @@ -38,6 +38,8 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.TargetSampleService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -175,8 +177,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target ReferenceEntities.filterReferentielListByStatus(categorieList); // get current ocean - Ocean ocean = dataService.getTripOcean( - dataSource, dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); // filtre par ocean categorieList = Species2.filterWeightCategoryByOcean(categorieList, ocean); @@ -258,12 +259,12 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); Collection<Species> speciessToDelete = new HashSet<Species>(); - getDataService().getObsoleteEspeceForTargetSample(getDataSource(), - bean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete, - false); + TargetSampleService service = getService(TargetSampleService.class); + service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), + speciessUsed, + speciessToDelete, + tailleToDelete, + false); if (!tailleToDelete.isEmpty()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java index d9a1ae5..22bd908 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java @@ -39,6 +39,9 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.TargetSampleService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -230,13 +233,13 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, ReferenceEntities.filterReferentielListByStatus(categorieList); // get current ocean - Ocean ocean = dataService.getTripOcean(dataSource, dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); // filtre par ocean categorieList = Species2.filterWeightCategoryByOcean(categorieList, ocean); - reasonForDiscardList = new ArrayList<ReasonForDiscard>( - dataService.loadDecoratedEntities(dataSource, ReasonForDiscard.class)); + ReferentialService service = getService(ReferentialService.class); + reasonForDiscardList = service.loadAndDecorateList(ReasonForDiscard.class); // filtre par status actif ReferenceEntities.filterReferentielListByStatus(reasonForDiscardList); @@ -324,12 +327,12 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); java.util.Set<Species> speciessToDelete = new HashSet<Species>(); - getDataService().getObsoleteEspeceForTargetSample(getDataSource(), - bean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete, - true); + TargetSampleService service = getService(TargetSampleService.class); + service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), + speciessUsed, + speciessToDelete, + tailleToDelete, + true); if (!tailleToDelete.isEmpty()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index 449f10c..b1cbfb3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -31,6 +31,7 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.data.seine.TargetSampleService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -127,7 +128,8 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T DataSource dataSource) throws DataSourceException { String setId = dataContext.getSelectedSetId(); // on doit récupérer l'unique échantillonThon de la calée - String id = dataService.getTargetSampleId(dataSource, setId, discarded); + + String id = getService(TargetSampleService.class).getTargetSampleId(setId, discarded); return id; } @@ -142,10 +144,10 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T if (mode == ContentMode.UPDATE) { // on ne charge les speciess uniquement si on est en mode édition - List<Species> speciess = - dataService.getAvailableEspeceForTargetSample(dataSource, setId, discarded); + TargetSampleService service = getService(TargetSampleService.class); + List<Species> speciesList = service.getAvailableEspeceForTargetSample(setId, discarded); - getUi().getSpecies().setData(speciess); + getUi().getSpecies().setData(speciesList); } // on doit récupérer l'unique échantillonThon de la calée @@ -353,16 +355,10 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T protected ContentMode getContentMode(DataContext dataContext) { ContentMode mode = super.getContentMode(dataContext); - boolean showData = false; - try { - String setId = getDataContext().getSelectedSetId(); - showData = getDataService().canUseTargetSample(getDataSource(), setId, discarded); - } catch (DataSourceException e) { - if (log.isErrorEnabled()) { - log.error(e); - } - } + String setId = getDataContext().getSelectedSetId(); + TargetSampleService service = getService(TargetSampleService.class); + boolean showData = service.canUseTargetSample(setId, discarded); getModel().setShowData(showData); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java index 4832fcb..c46692a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java @@ -28,7 +28,7 @@ import fr.ird.observe.db.DataSourceFactory; import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.impl.PGDataSource; import fr.ird.observe.db.impl.PGDataSourceConfig; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.db.util.PGInstall; import jaxx.runtime.JAXXContext; import org.apache.commons.logging.Log; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java index 0993cf8..5983460 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java @@ -26,7 +26,7 @@ import fr.ird.observe.DataService; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.H2DataSource; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import jaxx.runtime.JAXXContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java index 06ea88c..e34ad30 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java @@ -41,11 +41,12 @@ import fr.ird.observe.db.impl.H2DataSource; import fr.ird.observe.db.impl.H2DataSourceConfig; import fr.ird.observe.db.impl.PGDataSource; import fr.ird.observe.db.impl.PGDataSourceConfig; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.db.util.PGInstall; import fr.ird.observe.db.util.SecurityModel; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.storage.tabs.RolesTableModel; @@ -1187,8 +1188,8 @@ public class StorageUIHandler { dataModel.setUseData(true); dataModel.setUseOpenData(true); dataModel.setUseReferentiel(false); - - DataSelectionModel.populate(dataModel, ObserveContext.get().getDataService(), source); + ObserveServiceFactory services = ObserveContext.newServiceFactory(source); + DataSelectionModel.populate(dataModel,services); // positionnement du model de selection de données // dans le model du wizard diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java index 5b1a8af..e2ba79f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java @@ -32,7 +32,7 @@ import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.H2DataSourceConfig; import fr.ird.observe.db.impl.PGDataSourceConfig; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.db.util.PGInstall; import fr.ird.observe.db.util.SecurityModel; import jaxx.runtime.JAXXContext; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java index 8c58a17..7883989 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java @@ -23,14 +23,13 @@ package fr.ird.observe.ui.storage.tabs; import com.google.common.base.Preconditions; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceConfig; import fr.ird.observe.db.constants.ConnexionStatus; import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.PGDataSourceConfig; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.storage.StorageStep; import fr.ird.observe.ui.storage.StorageUIHandler; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java index 0886000..fba1ddb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java @@ -112,7 +112,7 @@ public abstract class AbstractObserveTreeCellRenderer extends AbstractNavTreeCel if (provider == null) { DataSource source = ObserveContext.get().getDataSource(); if (source != null) { - provider = new ObserveDataProvider(source); + provider = new ObserveDataProvider(ObserveContext.get().getServices()); setDataProvider(provider); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java index e5aa254..c1b7181 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java @@ -22,10 +22,10 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.longline.ActivityLonglineService; import fr.ird.observe.ui.tree.loadors.ActivityLonglineNodeChildLoador; /** @@ -38,13 +38,14 @@ public class ActivityLonglineNode extends EntityNodeSupport<ActivityLongline> { private static final long serialVersionUID = 1L; - public ActivityLonglineNode(ActivityLongline entity) { - super(ActivityLongline.class, entity, ObserveTreeHelper.getChildLoador(ActivityLonglineNodeChildLoador.class)); + public ActivityLonglineNode(ObserveDataProvider dataProvider, ActivityLongline entity) { + super(dataProvider, ActivityLongline.class, entity, ObserveTreeHelper.getChildLoador(ActivityLonglineNodeChildLoador.class)); } @Override - protected ActivityLongline getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getActivityLonglineStub(source, id); + protected ActivityLongline getEntity(ObserveServiceFactory services) throws DataSourceException { + ActivityLonglineService service = services.getService(ActivityLonglineService.class); + return service.getActivityLonglineStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java index bf12f1a..90949a4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java @@ -22,10 +22,10 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.seine.ActivitySeineService; import fr.ird.observe.ui.tree.loadors.ActivitySeineNodeChildLoador; /** @@ -38,13 +38,14 @@ public class ActivitySeineNode extends EntityNodeSupport<ActivitySeine> { private static final long serialVersionUID = 1L; - public ActivitySeineNode(ActivitySeine entity) { - super(ActivitySeine.class, entity, ObserveTreeHelper.getChildLoador(ActivitySeineNodeChildLoador.class)); + public ActivitySeineNode(ObserveDataProvider dataProvider, ActivitySeine entity) { + super(dataProvider, ActivitySeine.class, entity, ObserveTreeHelper.getChildLoador(ActivitySeineNodeChildLoador.class)); } @Override - protected ActivitySeine getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getActivitySeineStub(source, id); + protected ActivitySeine getEntity(ObserveServiceFactory services) throws DataSourceException { + ActivitySeineService service = services.getService(ActivitySeineService.class); + return service.getActivitySeineStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java index 93684d4..003fcdc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java @@ -21,9 +21,9 @@ */ package fr.ird.observe.ui.tree; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.model.DataSelectionModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java index 123e944..01bcd73 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java @@ -22,11 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.OpenableEntity; +import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.tree.loadors.AbstractNodeChildLoador; import jaxx.runtime.swing.nav.NavBridge; import jaxx.runtime.swing.nav.NavDataProvider; @@ -57,22 +55,23 @@ public abstract class EntityNodeSupport<E extends TopiaEntity> extends ObserveNo */ protected transient E entity; - protected transient DataService dataService; + protected transient ObserveDataProvider dataProvider; private boolean reloadEntity; - protected abstract E getEntity(DataService dataService, DataSource source) throws DataSourceException; + protected abstract E getEntity(ObserveServiceFactory services) throws DataSourceException; - protected EntityNodeSupport(Class<E> internalClass, E entity) { - this(internalClass, entity, null); + protected EntityNodeSupport(ObserveDataProvider dataProvider, Class<E> internalClass, E entity) { + this(dataProvider, internalClass, entity, null); } - protected EntityNodeSupport(Class<E> type, E entity, AbstractNodeChildLoador<?> childLoador) { - this(type, entity, null, childLoador); + protected EntityNodeSupport(ObserveDataProvider dataProvider, Class<E> type, E entity, AbstractNodeChildLoador<?> childLoador) { + this(dataProvider, type, entity, null, childLoador); } - protected EntityNodeSupport(Class<E> type, E entity, String context, AbstractNodeChildLoador<?> childLoador) { + protected EntityNodeSupport(ObserveDataProvider dataProvider, Class<E> type, E entity, String context, AbstractNodeChildLoador<?> childLoador) { super(type, entity.getTopiaId(), context, childLoador, false); + this.dataProvider = dataProvider; setEntity(entity); } @@ -145,8 +144,8 @@ public abstract class EntityNodeSupport<E extends TopiaEntity> extends ObserveNo } try { - entity = getEntity(getDataService(), oProvider.getDataSource()); - } catch (DataSourceException e) { + entity = getEntity(oProvider.getServices()); + } catch (Exception e) { throw new RuntimeException(e); } @@ -154,13 +153,6 @@ public abstract class EntityNodeSupport<E extends TopiaEntity> extends ObserveNo } - private DataService getDataService() { - if (dataService == null) { - dataService = ObserveContext.get().getDataService(); - } - return dataService; - } - public void setReloadEntity(boolean reloadEntity) { this.reloadEntity = reloadEntity; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java index bd90005..3471e0b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java @@ -22,10 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.seine.FloatingObjectService; import fr.ird.observe.ui.tree.loadors.FloatingObjectNodeChildLoador; /** @@ -38,13 +37,14 @@ public class FloatingObjectSeineNode extends EntityNodeSupport<FloatingObject> { private static final long serialVersionUID = 1L; - public FloatingObjectSeineNode(FloatingObject entity) { - super(FloatingObject.class, entity, ObserveTreeHelper.getChildLoador(FloatingObjectNodeChildLoador.class)); + public FloatingObjectSeineNode(ObserveDataProvider dataProvider, FloatingObject entity) { + super(dataProvider, FloatingObject.class, entity, ObserveTreeHelper.getChildLoador(FloatingObjectNodeChildLoador.class)); } @Override - protected FloatingObject getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getFloatinObjectStub(source, id); + protected FloatingObject getEntity(ObserveServiceFactory services) { + FloatingObjectService service = services.getService(FloatingObjectService.class); + return service.getFloatinObjectStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java index 0df4adf..53839b4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java @@ -21,10 +21,10 @@ */ package fr.ird.observe.ui.tree; -import fr.ird.observe.ObserveServiceHelper; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.ObserveService; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.model.DataSelectionModel; import jaxx.runtime.swing.nav.NavDataProvider; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,20 +40,14 @@ public class ObserveDataProvider implements NavDataProvider { /** Logger */ static private final Log log = LogFactory.getLog(ObserveDataProvider.class); - protected DataSource dataSource; - - protected DataService dataService; + protected final ObserveServiceFactory services; protected DataSelectionModel selectionModel; private boolean creating; - public ObserveDataProvider(DataSource dataSource) { - this.dataSource = dataSource; - } - - public void setSource(DataSource dataSource) { - this.dataSource = dataSource; + public ObserveDataProvider(ObserveServiceFactory services) { + this.services = services; } public void setSelectionModel(DataSelectionModel selectionModel) { @@ -65,24 +59,14 @@ public class ObserveDataProvider implements NavDataProvider { @Override public boolean isEnabled() { + DataSource dataSource = services.getDataSource(); return dataSource != null && dataSource.isOpen() || selectionModel != null; } - public DataSource getDataSource() { - return dataSource; - } - public DataSelectionModel getSelectionModel() { return selectionModel; } - protected DataService getDataService() { - if (dataService == null) { - dataService = ObserveServiceHelper.getDataService(); - } - return dataService; - } - public boolean isCreating() { return creating; } @@ -91,4 +75,15 @@ public class ObserveDataProvider implements NavDataProvider { this.creating = creating; } + public ObserveServiceFactory getServices() { + return services; + } + + public <S extends ObserveService> S getService(Class<S> serviceType) { + return services.getService(serviceType); + } + + public DataSource getDataSource() { + return services.getDataSource(); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java index c2e5607..cc11922 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java @@ -23,12 +23,10 @@ package fr.ird.observe.ui.tree; */ import com.google.common.base.Preconditions; -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.ObserveContext; import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.referentiel.Programs; +import fr.ird.observe.services.data.OpenableService; +import fr.ird.observe.services.data.TripService; import fr.ird.observe.ui.tree.actions.ChangeTripProgramActionListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -220,25 +218,17 @@ public class ObserveNavigationTreeShowPopupAction { moveTripPopup.removeAll(); - DataService dataService = treeHelper.getDataService(); - DataSource dataSource = treeHelper.getDataProvider().getDataSource(); + ObserveContext observeContext = ObserveContext.get(); + OpenableService openableService = observeContext.getService(OpenableService.class); + TripService tripService = observeContext.getService(TripService.class); String tripId = selectedNode.getId(); - List<Program> programs; + List<Program> programs = tripService.getPossibleProgramsForTrip(tripId); - try { + String openProgramId = observeContext.getDataContext().getOpenProgramId(); - programs = dataService.getPossibleProgramsForTrip(dataSource, tripId); - Programs.sort(programs); - - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Can't get possible programs for trip " + tripId, e); - } - - String openProgramId = dataService.getDataContext().getOpenProgramId(); - - Decorator<Program> programDecorator = dataService.getDecoratorService().getDecoratorByType(Program.class); + Decorator<Program> programDecorator = observeContext.getDecoratorService().getDecoratorByType(Program.class); for (Program program : programs) { String programId = program.getTopiaId(); @@ -248,8 +238,8 @@ public class ObserveNavigationTreeShowPopupAction { JMenuItem item = new JMenuItem(programDecorator.toString(program)); item.setName(programId); item.addActionListener(new ChangeTripProgramActionListener(treeHelper, - dataService, - dataSource, + openableService, + tripService, tripId, programId)); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java index f334560..765efa8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java @@ -22,23 +22,23 @@ package fr.ird.observe.ui.tree; import com.google.common.base.Preconditions; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.entities.OpenableEntity; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.referentiel.Programs; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.tree.loadors.AbstractNodeChildLoador; import fr.ird.observe.ui.tree.loadors.ActivityLonglineNodeChildLoador; @@ -50,7 +50,6 @@ import fr.ird.observe.ui.tree.loadors.ProgramSeineNodeChildLoador; import fr.ird.observe.ui.tree.loadors.RootNodeChildLoador; import fr.ird.observe.ui.tree.loadors.RoutesNodeChildLoador; import jaxx.runtime.JAXXContext; -import jaxx.runtime.swing.nav.NavDataProvider; import jaxx.runtime.swing.nav.tree.NavTreeHelper; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import org.apache.commons.collections.CollectionUtils; @@ -81,9 +80,6 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { /** Logger. */ static private final Log log = LogFactory.getLog(ObserveTreeHelper.class); - /** le service de récupération de données. */ - protected DataService dataService; - private boolean createUnsaved; public ObserveTreeHelper() { @@ -111,20 +107,14 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { } - protected DataService getDataService() { - if (dataService == null) { - dataService = ObserveContext.get().getDataService(); - } - return dataService; - } - @Override protected ObserveDataProvider getDataProvider() { ObserveDataProvider provider = (ObserveDataProvider) super.getDataProvider(); if (provider == null) { DataSource source = ObserveContext.get().getDataSource(); if (source != null) { - provider = new ObserveDataProvider(source); + + provider = new ObserveDataProvider(ObserveContext.get().getServices()); setDataProvider(provider); } } @@ -427,78 +417,65 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { } public ObserveNode addTrip(ObserveNode parentNode, TripSeine bean) { - ProgramSeineNodeChildLoador loador = - getChildLoador(ProgramSeineNodeChildLoador.class); + ProgramSeineNodeChildLoador loador = getChildLoador(ProgramSeineNodeChildLoador.class); ObserveNode result = loador.createNode(bean, dataProvider); insertNode(parentNode, result); return result; } public ObserveNode addTrip(ObserveNode parentNode, TripLongline bean) { - ProgramLonglineNodeChildLoador loador = - getChildLoador(ProgramLonglineNodeChildLoador.class); + ProgramLonglineNodeChildLoador loador = getChildLoador(ProgramLonglineNodeChildLoador.class); ObserveNode result = loador.createNode(bean, dataProvider); insertNode(parentNode, result); return result; } public ObserveNode addRoute(ObserveNode parentNode, Route bean) { - RoutesNodeChildLoador loador = - getChildLoador(RoutesNodeChildLoador.class); + RoutesNodeChildLoador loador = getChildLoador(RoutesNodeChildLoador.class); ObserveNode result = loador.createNode(bean, dataProvider); insertNode(parentNode, result); return result; } public ObserveNode addActivity(ObserveNode parentNode, ActivitySeine bean) { - ActivitySeinesNodeChildLoador loador = - getChildLoador(ActivitySeinesNodeChildLoador.class); + ActivitySeinesNodeChildLoador loador = getChildLoador(ActivitySeinesNodeChildLoador.class); ObserveNode result = loador.createNode(bean, dataProvider); insertNode(parentNode, result); return result; } public ObserveNode addActivity(ObserveNode parentNode, ActivityLongline bean) { - ActivityLonglinesNodeChildLoador loador = - getChildLoador(ActivityLonglinesNodeChildLoador.class); + ActivityLonglinesNodeChildLoador loador = getChildLoador(ActivityLonglinesNodeChildLoador.class); ObserveNode result = loador.createNode(bean, dataProvider); insertNode(parentNode, result); return result; } public ObserveNode addFloatingObject(ObserveNode parentNode, FloatingObject bean) { - ActivitySeineNodeChildLoador loador = - getChildLoador(ActivitySeineNodeChildLoador.class); + ActivitySeineNodeChildLoador loador = getChildLoador(ActivitySeineNodeChildLoador.class); ObserveNode result = loador.createNode(bean, dataProvider); insertNode(parentNode, result); return result; } public ObserveNode addSet(ObserveNode parentNode, SetSeine bean) { - ActivitySeineNodeChildLoador loador = - getChildLoador(ActivitySeineNodeChildLoador.class); - ObserveNode result = loador.createSetNode(bean); + ActivitySeineNodeChildLoador loador = getChildLoador(ActivitySeineNodeChildLoador.class); + ObserveNode result = loador.createSetNode(getDataProvider(), bean); insertNode(parentNode, result); return result; } public ObserveNode addSet(ObserveNode parentNode, SetLongline bean) { - ActivityLonglineNodeChildLoador loador = - getChildLoador(ActivityLonglineNodeChildLoador.class); - ObserveNode result = loador.createSetNode(bean); + ActivityLonglineNodeChildLoador loador = getChildLoador(ActivityLonglineNodeChildLoador.class); + ObserveNode result = loador.createSetNode(getDataProvider(), bean); insertNode(parentNode, result); return result; } public ObserveNode addProgram(Program bean) throws Exception { - List<Program> data = getDataService().getList( - getDataProvider().getDataSource(), Program.class); - int newIndex = 0; - if (CollectionUtils.isNotEmpty(data)) { - Programs.sort(data); - newIndex = data.indexOf(bean); - } + ReferentialService service = getDataProvider().getService(ReferentialService.class); + int newIndex = service.getProgramPosition(bean.getTopiaId()); RootNodeChildLoador loador = getChildLoador(RootNodeChildLoador.class); ObserveNode result = loador.createNode(bean, dataProvider); insertNode(getRootNode(), result, newIndex); @@ -517,7 +494,6 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { ObserveNode result = rootNode.getChild(bean.getTopiaId(), getBridge(), dataProvider); Preconditions.checkNotNull(result, "Could not find program node with id: " + bean.getTopiaId()); reloadNode(result, false); -// refreshNode(result, false); } public void reloadSelectedNode(boolean refreshFromParent, boolean refreshChilds) { @@ -537,9 +513,10 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { void setDataSource(DataSource source) { - NavDataProvider provider = null; + ObserveDataProvider provider = null; if (source != null) { - provider = new ObserveDataProvider(source); + ObserveServiceFactory services = ObserveContext.newServiceFactory(source); + provider = new ObserveDataProvider(services); } setDataProvider(provider); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java index 813e1b8..c49db36 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java @@ -22,10 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.tree.loadors.ProgramLonglineNodeChildLoador; /** @@ -38,14 +37,15 @@ public class ProgramLonglineNode extends EntityNodeSupport<Program> { private static final long serialVersionUID = 1L; - public ProgramLonglineNode(Program entity) { - super(Program.class, entity, entity.getGearType().name(), ObserveTreeHelper.getChildLoador(ProgramLonglineNodeChildLoador.class)); + public ProgramLonglineNode(ObserveDataProvider dataProvider, Program entity) { + super(dataProvider, Program.class, entity, entity.getGearType().name(), ObserveTreeHelper.getChildLoador(ProgramLonglineNodeChildLoador.class)); setEntity(entity); } @Override - protected Program getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getProgramStub(source, id); + protected Program getEntity(ObserveServiceFactory services) { + ReferentialService service = services.getService(ReferentialService.class); + return service.getProgramStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java index 5954d1b..5eb32b3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java @@ -22,10 +22,10 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.tree.loadors.ProgramSeineNodeChildLoador; /** @@ -38,13 +38,14 @@ public class ProgramSeineNode extends EntityNodeSupport<Program> { private static final long serialVersionUID = 1L; - public ProgramSeineNode(Program entity) { - super(Program.class, entity, entity.getGearType().name(), ObserveTreeHelper.getChildLoador(ProgramSeineNodeChildLoador.class)); + public ProgramSeineNode(ObserveDataProvider dataProvider, Program entity) { + super(dataProvider, Program.class, entity, entity.getGearType().name(), ObserveTreeHelper.getChildLoador(ProgramSeineNodeChildLoador.class)); } @Override - protected Program getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getProgramStub(source, id); + protected Program getEntity(ObserveServiceFactory services) throws DataSourceException { + ReferentialService service = services.getService(ReferentialService.class); + return service.getProgramStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java index ab5d772..4c76293 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java @@ -22,10 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.seine.RouteService; /** * Created on 4/9/15. @@ -37,13 +36,14 @@ public class RouteSeineNode extends EntityNodeSupport<Route> { private static final long serialVersionUID = 1L; - public RouteSeineNode(Route entity) { - super(Route.class, entity); + public RouteSeineNode(ObserveDataProvider dataProvider, Route entity) { + super(dataProvider, Route.class, entity); } @Override - protected Route getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getRouteStub(source, id); + protected Route getEntity(ObserveServiceFactory services) { + RouteService service = services.getService(RouteService.class); + return service.getRouteStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java index 871c539..4b0fb0c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java @@ -22,10 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.ui.tree.loadors.SetLonglineNodeChildLoador; /** @@ -38,13 +37,14 @@ public class SetLonglineNode extends EntityNodeSupport<SetLongline> { private static final long serialVersionUID = 1L; - public SetLonglineNode(SetLongline entity) { - super(SetLongline.class, entity, ObserveTreeHelper.getChildLoador(SetLonglineNodeChildLoador.class)); + public SetLonglineNode(ObserveDataProvider dataProvider, SetLongline entity) { + super(dataProvider, SetLongline.class, entity, ObserveTreeHelper.getChildLoador(SetLonglineNodeChildLoador.class)); } @Override - protected SetLongline getEntity(DataService dataService, DataSource source) throws DataSourceException { - return (SetLongline) dataService.loadEntity(source, id, true); + protected SetLongline getEntity(ObserveServiceFactory services) { + SetLonglineService service = services.getService(SetLonglineService.class); + return service.loadSet(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java index 52fcd2f..25df6af 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java @@ -22,10 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.seine.SetSeineService; import fr.ird.observe.ui.tree.loadors.SetSeineNodeChildLoador; /** @@ -38,13 +37,14 @@ public class SetSeineNode extends EntityNodeSupport<SetSeine> { private static final long serialVersionUID = 1L; - public SetSeineNode(SetSeine entity) { - super(SetSeine.class, entity, ObserveTreeHelper.getChildLoador(SetSeineNodeChildLoador.class)); + public SetSeineNode(ObserveDataProvider dataProvider, SetSeine entity) { + super(dataProvider, SetSeine.class, entity, ObserveTreeHelper.getChildLoador(SetSeineNodeChildLoador.class)); } @Override - protected SetSeine getEntity(DataService dataService, DataSource source) throws DataSourceException { - return (SetSeine) dataService.loadEntity(source, id, true); + protected SetSeine getEntity(ObserveServiceFactory services) { + SetSeineService service = services.getService(SetSeineService.class); + return service.loadSet(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java index d68a8c6..22469d3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java @@ -22,10 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.longline.TripLonglineService; /** * Created on 4/9/15. @@ -37,13 +36,14 @@ public class TripLonglineNode extends EntityNodeSupport<TripLongline> { private static final long serialVersionUID = 1L; - public TripLonglineNode(TripLongline entity) { - super(TripLongline.class, entity); + public TripLonglineNode(ObserveDataProvider dataProvider, TripLongline entity) { + super(dataProvider, TripLongline.class, entity); } @Override - protected TripLongline getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getTripLonglineStub(source, id); + protected TripLongline getEntity(ObserveServiceFactory services) { + TripLonglineService service = services.getService(TripLonglineService.class); + return service.getTripLonglineStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java index 0d62950..101b50a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java @@ -22,10 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.data.seine.TripSeineService; /** * Created on 4/9/15. @@ -37,13 +36,14 @@ public class TripSeineNode extends EntityNodeSupport<TripSeine> { private static final long serialVersionUID = 1L; - public TripSeineNode(TripSeine entity) { - super(TripSeine.class, entity); + public TripSeineNode(ObserveDataProvider dataProvider, TripSeine entity) { + super(dataProvider, TripSeine.class, entity); } @Override - protected TripSeine getEntity(DataService dataService, DataSource source) throws DataSourceException { - return dataService.getTripSeineStub(source, id); + protected TripSeine getEntity(ObserveServiceFactory services) { + TripSeineService service = services.getService(TripSeineService.class); + return service.getTripSeineStub(id); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java index 766e3d3..5fb89a7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java @@ -22,10 +22,8 @@ package fr.ird.observe.ui.tree.actions; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.services.data.OpenableService; +import fr.ird.observe.services.data.TripService; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import org.apache.commons.logging.Log; @@ -45,26 +43,26 @@ public class ChangeTripProgramActionListener implements ActionListener { /** Logger. */ private static final Log log = LogFactory.getLog(ChangeTripProgramActionListener.class); + private final TripService tripService; + private final String tripId; private final String programId; private final ObserveTreeHelper treeHelper; - private final DataService dataService; - - private final DataSource dataSource; + protected final OpenableService openableService; public ChangeTripProgramActionListener(ObserveTreeHelper treeHelper, - DataService dataService, - DataSource dataSource, + OpenableService openableService, + TripService tripService, String tripId, String programId) { + this.tripService = tripService; this.tripId = tripId; this.programId = programId; this.treeHelper = treeHelper; - this.dataService = dataService; - this.dataSource = dataSource; + this.openableService = openableService; } @Override @@ -75,19 +73,9 @@ public class ChangeTripProgramActionListener implements ActionListener { ObserveNode newProgramNode = treeHelper.getChild(rootNode, programId); ObserveNode oldProgramNode = treeHelper.getChild(rootNode, tripNode.getParent().getId()); - try { - dataService.moveTripToProgram(dataSource, tripId, programId); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Can't change trip " + tripId + " to program " + programId, e); - } + tripService.moveTripToProgram(tripId, programId); - int position; - - try { - position = dataService.getOpenablePosition(dataSource, programId, tripId); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Can't get trip " + tripId + " position for program " + programId, e); - } + int position = openableService.getOpenablePosition(programId, tripId); treeHelper.removeNode(tripNode); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java index acece19..489e9c4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java @@ -21,11 +21,10 @@ */ package fr.ird.observe.ui.tree.loadors; +import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import jaxx.runtime.swing.nav.NavDataProvider; @@ -47,12 +46,6 @@ public abstract class AbstractNodeChildLoador<O> extends NavTreeNodeChildLoador< super(beanType); } - protected DataSource getDataSource(NavDataProvider dataProvider) { - ObserveDataProvider provider = (ObserveDataProvider) dataProvider; - DataSource result = provider.getDataSource(); - return result; - } - protected DataSelectionModel getSelectionModel(NavDataProvider dataProvider) { ObserveDataProvider provider = (ObserveDataProvider) dataProvider; DataSelectionModel result = provider.getSelectionModel(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java index 205c074..4e70b81 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java @@ -22,10 +22,10 @@ package fr.ird.observe.ui.tree.loadors; * #L% */ -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.tree.ActivityLonglineNode; +import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import fr.ird.observe.ui.tree.SetLonglineNode; @@ -76,7 +76,7 @@ public class ActivityLonglineNodeChildLoador extends AbstractNodeChildLoador<Str if (setLongline != null) { // si set present, ajout d'un noeud - ObserveNode child = createSetNode(setLongline); + ObserveNode child = createSetNode((ObserveDataProvider) dataProvider, setLongline); parentNode.add(child); } @@ -88,9 +88,7 @@ public class ActivityLonglineNodeChildLoador extends AbstractNodeChildLoador<Str } @Override - public List<String> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataService) throws DataSourceException { + public List<String> getData(Class<?> parentClass, String parentId, NavDataProvider dataService) { List<String> result = new ArrayList<String>(); result.add(ActivityLongline.PROPERTY_ENCOUNTER); @@ -107,12 +105,12 @@ public class ActivityLonglineNodeChildLoador extends AbstractNodeChildLoador<Str } - public ObserveNode createSetNode(SetLongline data) { + public ObserveNode createSetNode(ObserveDataProvider dataProvider, SetLongline data) { if (data == null) { throw new NullPointerException("Ne peut pas ajouter un objet null"); } - ObserveNode child = new SetLonglineNode(data); + ObserveNode child = new SetLonglineNode(dataProvider, data); return child; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglinesNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglinesNodeChildLoador.java index f58994d..bb310ad 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglinesNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglinesNodeChildLoador.java @@ -22,8 +22,8 @@ package fr.ird.observe.ui.tree.loadors; * #L% */ -import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.services.data.longline.ActivityLonglineService; import fr.ird.observe.ui.tree.ActivityLonglineNode; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; @@ -43,15 +43,14 @@ public class ActivityLonglinesNodeChildLoador extends AbstractNodeChildLoador<Ac public ActivityLonglinesNodeChildLoador() { super(ActivityLongline.class); + } @Override - public List<ActivityLongline> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { + public List<ActivityLongline> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - DataSource dataSource = ((ObserveDataProvider) dataProvider).getDataSource(); - List<ActivityLongline> data = getDataService().getActivityLonglineStubByTrip(dataSource, parentId); + ActivityLonglineService service = ((ObserveDataProvider) dataProvider).getService(ActivityLonglineService.class); + List<ActivityLongline> data = service.getActivityLonglineStubByTrip(parentId); return data; } @@ -62,7 +61,7 @@ public class ActivityLonglinesNodeChildLoador extends AbstractNodeChildLoador<Ac throw new NullPointerException("Ne peut pas ajouter un objet null"); } - ObserveNode result = new ActivityLonglineNode(data); + ObserveNode result = new ActivityLonglineNode((ObserveDataProvider) dataProvider, data); return result; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java index 2144200..3eb0898 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java @@ -21,10 +21,10 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.data.seine.FloatingObjectService; import fr.ird.observe.ui.tree.ActivitySeineNode; import fr.ird.observe.ui.tree.FloatingObjectSeineNode; import fr.ird.observe.ui.tree.ObserveDataProvider; @@ -80,7 +80,7 @@ public class ActivitySeineNodeChildLoador extends AbstractNodeChildLoador<Floati if (set != null) { // si set present, ajout d'un noeud - child = createSetNode(set); + child = createSetNode((ObserveDataProvider) dataProvider, set); parentNode.add(child); } @@ -88,12 +88,12 @@ public class ActivitySeineNodeChildLoador extends AbstractNodeChildLoador<Floati super.loadChilds(model, parentNode, dataProvider); } - public ObserveNode createSetNode(SetSeine data) { + public ObserveNode createSetNode(ObserveDataProvider dataProvider, SetSeine data) { if (data == null) { throw new NullPointerException("Ne peut pas ajouter un objet null"); } - SetSeineNode child = new SetSeineNode(data); + SetSeineNode child = new SetSeineNode(dataProvider, data); return child; } @@ -104,18 +104,16 @@ public class ActivitySeineNodeChildLoador extends AbstractNodeChildLoador<Floati throw new NullPointerException("Ne peut pas ajouter un objet null"); } - FloatingObjectSeineNode result = new FloatingObjectSeineNode(data); + FloatingObjectSeineNode result = new FloatingObjectSeineNode((ObserveDataProvider) dataProvider, data); return result; } @Override - public List<FloatingObject> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { + public List<FloatingObject> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - DataSource dataSource = ((ObserveDataProvider) dataProvider).getDataSource(); - List<FloatingObject> data = getDataService().getFloatinObjectStubByActivitySeine(dataSource, parentId); + FloatingObjectService service = ((ObserveDataProvider) dataProvider).getService(FloatingObjectService.class); + List<FloatingObject> data = service.getFloatinObjectStubByActivitySeine(parentId); return data; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeinesNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeinesNodeChildLoador.java index e4891d8..7a01995 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeinesNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeinesNodeChildLoador.java @@ -21,8 +21,8 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.services.data.seine.ActivitySeineService; import fr.ird.observe.ui.tree.ActivitySeineNode; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; @@ -45,12 +45,10 @@ public class ActivitySeinesNodeChildLoador extends AbstractNodeChildLoador<Activ } @Override - public List<ActivitySeine> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { + public List<ActivitySeine> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - DataSource dataSource = ((ObserveDataProvider) dataProvider).getDataSource(); - List<ActivitySeine> data = getDataService().getActivitySeineStubByRoute(dataSource, parentId); + ActivitySeineService service = ((ObserveDataProvider) dataProvider).getService(ActivitySeineService.class); + List<ActivitySeine> data = service.getActivitySeineStubByRoute(parentId); return data; } @@ -61,7 +59,7 @@ public class ActivitySeinesNodeChildLoador extends AbstractNodeChildLoador<Activ throw new NullPointerException("Ne peut pas ajouter un objet null"); } - ActivitySeineNode result = new ActivitySeineNode(data); + ActivitySeineNode result = new ActivitySeineNode((ObserveDataProvider) dataProvider, data); return result; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/FloatingObjectNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/FloatingObjectNodeChildLoador.java index 0b23ea8..9566e31 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/FloatingObjectNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/FloatingObjectNodeChildLoador.java @@ -21,7 +21,6 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; @@ -53,9 +52,7 @@ public class FloatingObjectNodeChildLoador extends AbstractNodeChildLoador<Strin } @Override - public List<String> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataService) throws DataSourceException { + public List<String> getData(Class<?> parentClass, String parentId, NavDataProvider dataService) { List<String> result = new ArrayList<String>(); result.add(FloatingObject.PROPERTY_OBJECT_OPERATION); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java index 5c30a30..41a85e7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java @@ -22,10 +22,10 @@ package fr.ird.observe.ui.tree.loadors; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.services.data.longline.TripLonglineService; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import fr.ird.observe.ui.tree.TripLonglineNode; @@ -76,12 +76,8 @@ public class ProgramLonglineNodeChildLoador extends AbstractNodeChildLoador<Trip } @Override - public List<TripLongline> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { + public List<TripLongline> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - DataSource dataSource = getDataSource(dataProvider); - DataService service = getDataService(); DataSelectionModel selectionModel = getSelectionModel(dataProvider); List<TripLongline> result; @@ -98,7 +94,8 @@ public class ProgramLonglineNodeChildLoador extends AbstractNodeChildLoador<Trip } else { - result = service.getTripLonglineStubByProgram(dataSource, parentId); + TripLonglineService service = ((ObserveDataProvider) dataProvider).getService(TripLonglineService.class); + result = service.getTripLonglineStubByProgram(parentId); } @@ -113,7 +110,7 @@ public class ProgramLonglineNodeChildLoador extends AbstractNodeChildLoador<Trip throw new NullPointerException("Ne peut pas ajouter un objet null"); } - ObserveNode result = new TripLonglineNode(data); + ObserveNode result = new TripLonglineNode((ObserveDataProvider) dataProvider, data); if (addChilds) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java index 5409fdd..edd8dae 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java @@ -21,10 +21,10 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.data.seine.TripSeineService; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import fr.ird.observe.ui.tree.TripSeineNode; @@ -73,12 +73,8 @@ public class ProgramSeineNodeChildLoador extends AbstractNodeChildLoador<TripSei } @Override - public List<TripSeine> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { + public List<TripSeine> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - DataSource dataSource = getDataSource(dataProvider); - DataService service = getDataService(); DataSelectionModel selectionModel = getSelectionModel(dataProvider); List<TripSeine> result; @@ -93,7 +89,8 @@ public class ProgramSeineNodeChildLoador extends AbstractNodeChildLoador<TripSei } } else { - result = service.getTripSeineStubByProgram(dataSource, parentId); + TripSeineService service = ((ObserveDataProvider) dataProvider).getService(TripSeineService.class); + result = service.getTripSeineStubByProgram(parentId); } return result; @@ -107,7 +104,7 @@ public class ProgramSeineNodeChildLoador extends AbstractNodeChildLoador<TripSei throw new NullPointerException("Ne peut pas ajouter un objet null"); } - ObserveNode result = new TripSeineNode(data); + ObserveNode result = new TripSeineNode((ObserveDataProvider) dataProvider, data); if (addChilds) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceCommonNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceCommonNodeChildLoador.java index 1c704db..b35dadb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceCommonNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceCommonNodeChildLoador.java @@ -21,9 +21,8 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.entities.Entities; import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.entities.Entities; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.tree.ObserveNode; import jaxx.runtime.swing.nav.NavDataProvider; @@ -71,9 +70,7 @@ public class ReferenceCommonNodeChildLoador extends AbstractNodeChildLoador<Clas } @Override - public List<Class> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws DataSourceException { + public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { List<Class> result = new ArrayList<Class>(); for (ObserveEntityEnum anEnum : Entities.REFERENCE_COMMON_ENTITIES_LIST) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceLonglineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceLonglineNodeChildLoador.java index 8181f95..44034aa 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceLonglineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceLonglineNodeChildLoador.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.tree.loadors; import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.Entities; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.tree.ObserveNode; @@ -77,9 +76,7 @@ public class ReferenceLonglineNodeChildLoador extends AbstractNodeChildLoador<Cl } @Override - public List<Class> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws DataSourceException { + public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { List<Class> result = new ArrayList<Class>(); for (ObserveEntityEnum anEnum : Entities.REFERENCE_LONGLINE_ENTITIES_LIST) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceSeineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceSeineNodeChildLoador.java index 3db8f30..a126561 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceSeineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ReferenceSeineNodeChildLoador.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.tree.loadors; import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.Entities; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.tree.ObserveNode; @@ -69,9 +68,7 @@ public class ReferenceSeineNodeChildLoador extends AbstractNodeChildLoador<Class } @Override - public List<Class> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws DataSourceException { + public List<Class> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { List<Class> result = new ArrayList<Class>(); for (ObserveEntityEnum anEnum : Entities.REFERENCE_SEINE_ENTITIES_LIST) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java index 7c8ec84..6b19743 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java @@ -21,11 +21,11 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.model.DataSelectionModel; import fr.ird.observe.entities.constants.GearType; import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.referential.ReferentialService; +import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import fr.ird.observe.ui.tree.ProgramLonglineNode; @@ -71,12 +71,8 @@ public class RootNodeChildLoador extends AbstractNodeChildLoador<Program> { } @Override - public List<Program> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { + public List<Program> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - DataSource dataSource = getDataSource(dataProvider); - DataService service = getDataService(); DataSelectionModel selectionModel = getSelectionModel(dataProvider); List<Program> data; @@ -88,7 +84,8 @@ public class RootNodeChildLoador extends AbstractNodeChildLoador<Program> { data.add((Program) selectionModel.getEntityCache(programId)); } } else { - data = service.getAllProgramStub(dataSource); + ReferentialService service = ((ObserveDataProvider) dataProvider).getService(ReferentialService.class); + data = service.getAllProgramStub(); } } else { @@ -148,12 +145,12 @@ public class RootNodeChildLoador extends AbstractNodeChildLoador<Program> { case seine: - result = new ProgramSeineNode(data); + result = new ProgramSeineNode((ObserveDataProvider) dataProvider, data); break; case longline: - result = new ProgramLonglineNode(data); + result = new ProgramLonglineNode((ObserveDataProvider) dataProvider, data); break; default: diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RoutesNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RoutesNodeChildLoador.java index 3b1125d..bc7f3db 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RoutesNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RoutesNodeChildLoador.java @@ -21,8 +21,8 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.services.data.seine.RouteService; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; @@ -52,12 +52,10 @@ public class RoutesNodeChildLoador extends AbstractNodeChildLoador<Route> { } @Override - public List<Route> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws Exception { + public List<Route> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { - DataSource dataSource = ((ObserveDataProvider) dataProvider).getDataSource(); - List<Route> data = getDataService().getRouteStubByTrip(dataSource, parentId); + RouteService service = ((ObserveDataProvider) dataProvider).getService(RouteService.class); + List<Route> data = service.getRouteStubByTrip(parentId); return data; } @@ -69,7 +67,7 @@ public class RoutesNodeChildLoador extends AbstractNodeChildLoador<Route> { throw new NullPointerException("Ne peut pas ajouter un objet null"); } - ObserveNode result = new RouteSeineNode(data); + ObserveNode result = new RouteSeineNode((ObserveDataProvider) dataProvider, data); // Creation d'un node activites ObserveNode child = ObserveTreeHelper.createStringNode(Route.PROPERTY_ACTIVITY_SEINE, ActivitySeinesNodeChildLoador.class); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetLonglineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetLonglineNodeChildLoador.java index 698f66e..bc68c1e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetLonglineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetLonglineNodeChildLoador.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.tree.loadors; * #L% */ -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; @@ -55,9 +54,7 @@ public class SetLonglineNodeChildLoador extends AbstractNodeChildLoador<String> } @Override - public List<String> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws DataSourceException { + public List<String> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { List<String> result = new ArrayList<String>(); result.add("longlineGlobalComposition"); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetSeineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetSeineNodeChildLoador.java index 2085dc1..57a1483 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetSeineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/SetSeineNodeChildLoador.java @@ -21,7 +21,6 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; @@ -57,9 +56,7 @@ public class SetSeineNodeChildLoador extends AbstractNodeChildLoador<String> { } @Override - public List<String> getData(Class<?> parentClass, - String parentId, - NavDataProvider dataProvider) throws DataSourceException { + public List<String> getData(Class<?> parentClass, String parentId, NavDataProvider dataProvider) { List<String> result = new ArrayList<String>(); result.add(SetSeine.PROPERTY_SCHOOL_ESTIMATE); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/util/tripMap/TripMapUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/util/tripMap/TripMapUIHandler.java index df1a9d1..33343b5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/util/tripMap/TripMapUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/util/tripMap/TripMapUIHandler.java @@ -32,11 +32,9 @@ import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.MultiPoint; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.services.data.TripService; import fr.ird.observe.tripMap.TripMapPoint; import fr.ird.observe.tripMap.TripMapPointType; import fr.ird.observe.ui.UIHelper; @@ -101,7 +99,9 @@ import static org.nuiton.i18n.I18n.t; public class TripMapUIHandler { public static final String TRIP_LINES_LAYER_NAME = "Trip lines"; + public static final String TRIP_POINTS_LAYER_NAME = "Trip points"; + public static final double ZOOM_STEP_RATIO = 0.1; protected static final Set<TripMapPointType> TRIP_MAP_POINT_TYPES_IN_LEGEND = ImmutableSet.of( @@ -121,6 +121,7 @@ public class TripMapUIHandler { protected TripMapUI view; private ObserveConfig config; + protected ReferencedEnvelope tripArea; protected boolean rendererRunning; @@ -156,15 +157,9 @@ public class TripMapUIHandler { return view.getObserveMapPane(); } - public void doOpenMap(DataSource dataSource, DataService dataService, String tripId) { + public void doOpenMap(TripService tripService, String tripId) { - List<TripMapPoint> tripMapPoints; - - try { - tripMapPoints = dataService.loadTripMapActivityPoints(dataSource, tripId); - } catch (DataSourceException e) { - throw new ObserveTechnicalException("Unable to load trip map activity points", e); - } + List<TripMapPoint> tripMapPoints = tripService.loadTripMapActivityPoints(tripId); ObserveMapPane mapPane = getObserveMapPane(); Pair<MapContent, List<ObserveMapPaneLegendItem>> buildMapContent = buildMapContent(tripMapPoints); @@ -194,7 +189,7 @@ public class TripMapUIHandler { t("observe.map.export.overwrite.title"), t("observe.map.export.overwrite"), JOptionPane.OK_CANCEL_OPTION, - new Object[] { + new Object[]{ t("observe.map.export.overwrite.ok"), t("observe.map.export.overwrite.cancel")}, 1) == 0; @@ -214,7 +209,6 @@ public class TripMapUIHandler { } - protected Pair<MapContent, List<ObserveMapPaneLegendItem>> buildMapContent(List<TripMapPoint> tripMapPoints) { MapContent mapContent = new MapContent(); @@ -356,7 +350,7 @@ public class TripMapUIHandler { }); ArrayList<Coordinate> coordinatesArray = Lists.newArrayList(coordinates); - if (! coordinatesArray.isEmpty()) { + if (!coordinatesArray.isEmpty()) { MultiPoint points = geometryFactory.createMultiPoint(coordinatesArray.toArray(new Coordinate[0])); pointBuilder.add(points); pointBuilder.add(type.name()); @@ -447,7 +441,7 @@ public class TripMapUIHandler { for (Style styleTmp : styles) { if (StringUtils.isBlank(styleName) && styleTmp.isDefault() - || styleTmp.getName().equals(styleName)) { + || styleTmp.getName().equals(styleName)) { style = styleTmp; } @@ -471,22 +465,23 @@ public class TripMapUIHandler { } protected double zoomRatio = 1; + protected Point zoomCenter; protected void zoomApply() { - if (zoomRatio != 1 && ! rendererRunning) { + if (zoomRatio != 1 && !rendererRunning) { JMapPane mapPane = getObserveMapPane(); ReferencedEnvelope displayArea = mapPane.getDisplayArea(); - double deltaWidth = displayArea.getWidth() * (zoomRatio -1); + double deltaWidth = displayArea.getWidth() * (zoomRatio - 1); double deltaHeight = displayArea.getHeight() * (zoomRatio - 1); - double ratioLeft = zoomCenter.getX() * 1d / mapPane.getWidth(); + double ratioLeft = zoomCenter.getX() * 1d / mapPane.getWidth(); // l'axe de Y est inversé entre le référentiel du composant swing et le référentiel géographique - double ratioTop = 1 - (zoomCenter.getY() * 1d / mapPane.getHeight()); + double ratioTop = 1 - (zoomCenter.getY() * 1d / mapPane.getHeight()); double deltaLeft = deltaWidth * ratioLeft; double deltaRight = deltaLeft - deltaWidth; @@ -496,7 +491,7 @@ public class TripMapUIHandler { if (log.isDebugEnabled()) { log.debug(String.format("Map mouse zoom (zoom ratio : %s, deltaLeft : %s, deltaRight : %s, deltaTop : %s, deltaBottom : %s)", - zoomRatio, deltaLeft, deltaRight, deltaRight, deltaBottom)); + zoomRatio, deltaLeft, deltaRight, deltaRight, deltaBottom)); } ReferencedEnvelope newDisplayArea = new ReferencedEnvelope( @@ -518,8 +513,6 @@ public class TripMapUIHandler { } - - private class MouseMapListener implements MouseWheelListener, MouseListener, MouseMotionListener { @Override @@ -536,7 +529,9 @@ public class TripMapUIHandler { } protected Point2D startPointInWorld; + protected AffineTransform startScreenToWorldTransform; + protected ReferencedEnvelope startDisplayArea; @Override diff --git a/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java b/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java index 83872ba..191eab6 100644 --- a/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java +++ b/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java @@ -154,12 +154,12 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { switch (Integer.valueOf(code)) { case 6: - if (activityCode.equals(ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE)) { + if (activityCode.equals(ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE)) { valid = validate_6(activitySeine, maree, route, nbActivitys); } break; case 7: - if (activityCode.equals(ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE)) { + if (activityCode.equals(ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE)) { valid = validate_7(activitySeine, maree, route, nbActivitys); } break; @@ -223,8 +223,8 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { //FIXME: sinon on verifier que l'activity qu'on veut créer n'est pas //FIXME: dans un intervalle (debut-fin) List<ActivitySeine> activitySeines = route.getActivitySeine(); - Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); - Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); + Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); + Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); int nbDebutReal = 0; int lastDebutReal = 0; for (Integer i : detectDebutSet) { @@ -273,8 +273,8 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { return false; } List<ActivitySeine> activitySeines = route.getActivitySeine(); - Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); - Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); + Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); + Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); Integer lastFinSet = null; if (detectFinSet.length > 0) { lastFinSet = detectFinSet[detectFinSet.length - 1]; @@ -380,8 +380,8 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { // } // il ne peut pas rester une activity de debut de peche sans fin // de set (sauf si non coup de senne ?) - Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); - Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); + Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); + Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); int nbDebutReal = 0; for (Integer i : detectDebutSet) { ActivitySeine bActivitySeine = activitySeines.get(i); diff --git a/pom.xml b/pom.xml index ce2cc68..5971a43 100644 --- a/pom.xml +++ b/pom.xml @@ -111,7 +111,7 @@ <eugenePluginVersion>2.14</eugenePluginVersion> - <topiaVersion>2.9.5.3</topiaVersion> + <topiaVersion>2.10-SNAPSHOT</topiaVersion> <jaxxVersion>2.24</jaxxVersion> <nuitonI18nVersion>3.3</nuitonI18nVersion> <nuitonValidatorVersion>3.0</nuitonValidatorVersion> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit c455e5c04b3b588e1f86726373b239ebe9302224 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 09:11:20 2015 +0200 continue les écrans simples sur le modèle seine (refs #7017) --- .../observe/services/AbstractObserveService.java | 10 +- .../services/data/seine/ActivitySeineService.java | 8 +- .../data/seine/ActivitySeineServiceImpl.java | 60 +++++- .../services/data/seine/FloatingObjectService.java | 35 +++- .../data/seine/FloatingObjectServiceImpl.java | 221 +++++++++++++++++++-- .../ActivitySeineObservedSystemUIHandler.java | 47 ++--- ...ngObjectTransmittingBuoyOperationUIHandler.java | 121 +++++------ ...tingObjectTransmittingBuoyOperationUIModel.java | 58 +++--- .../impl/seine/FloatingObjectUIHandler.java | 96 ++++----- 9 files changed, 447 insertions(+), 209 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index b15a574..b0a0c17 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -181,7 +181,7 @@ public abstract class AbstractObserveService implements ObserveService { if (r == null) { BinderModelBuilder<E, E> builder = createBinder.createBinderBuilder(binderService, binderName); - r = binderService.registerTopiaBinder(entityType, builder, binderName); + r = createBinder.registerTopiaBinder(binderService, entityType, builder, binderName); } @@ -189,9 +189,13 @@ public abstract class AbstractObserveService implements ObserveService { } - protected interface CreateBinder<E extends TopiaEntity> { + protected abstract class CreateBinder<E extends TopiaEntity> { - BinderModelBuilder<E, E> createBinderBuilder(BinderService binderService, String name); + public abstract BinderModelBuilder<E, E> createBinderBuilder(BinderService binderService, String name); + + public TopiaEntityBinder<E> registerTopiaBinder(BinderService binderService, Class<E> entityType, BinderModelBuilder<E, E> builder, String name) { + return binderService.registerTopiaBinder(entityType, builder, name); + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java index e000e6e..113d897 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java @@ -34,7 +34,7 @@ public interface ActivitySeineService extends ObserveService { ActivitySeine save(String routeId, ActivitySeine toSave); @Commit - void updateObservedSystem(ActivitySeine toUpdate); + ActivitySeine updateObservedSystem(ActivitySeine toUpdate); @Commit void delete(String routeId, String activitySeineId); @@ -43,5 +43,11 @@ public interface ActivitySeineService extends ObserveService { TopiaEntityBinder<ActivitySeine> getBinderForEdit(); @NoTransaction + TopiaEntityBinder<ActivitySeine> getBinderForEditObservedSystem() ; + + @NoTransaction void copyForEdit(ActivitySeine source, ActivitySeine target); + + @NoTransaction + void copyForEditObservedSystem(ActivitySeine source, ActivitySeine target); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 7478d41..5fe7977 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -2,10 +2,12 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.constants.seine.SchoolType; import fr.ird.observe.entities.referentiel.FpaZone; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeineDAO; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; @@ -130,9 +132,31 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } @Override - public void updateObservedSystem(ActivitySeine toUpdate) { + public ActivitySeine updateObservedSystem(ActivitySeine toUpdate) { + + ActivitySeineDAO dao = getDao(); + + boolean needUpdateSet = false; + SchoolType newTypeBanc = toUpdate.getSchoolType(); + SetSeine set = toUpdate.getSetSeine(); + if (set != null) { + // on regarde si le type de banc de la calée a changé + + SchoolType oldTypeBanc = set.getSchoolType(); + needUpdateSet = oldTypeBanc == null || newTypeBanc != oldTypeBanc; + } + + ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); + getBinderForEditObservedSystem().copyExcluding(toUpdate, updated, ActivitySeine.PROPERTY_SET_SEINE); + + if (needUpdateSet) { + + // mise à jour de la propriété schoolType dans la set + updated.getSetSeine().setSchoolType(newTypeBanc); + } + + return updated; - //TODO } @Override @@ -168,6 +192,31 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } @Override + public TopiaEntityBinder<ActivitySeine> getBinderForEditObservedSystem() { + + TopiaEntityBinder<ActivitySeine> binder = loadBinder("-forEditObservedSystem", ActivitySeine.class, new CreateBinder<ActivitySeine>() { + + @Override + public BinderModelBuilder<ActivitySeine, ActivitySeine> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_SET_SEINE, + ActivitySeine.PROPERTY_COMMENT, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE); + + return builder; + + } + + }); + + return binder; + + } + + @Override public TopiaEntityBinder<ActivitySeine> getBinderForEdit() { TopiaEntityBinder<ActivitySeine> binder = loadBinder("-forEdit", ActivitySeine.class, new CreateBinder<ActivitySeine>() { @@ -220,6 +269,13 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } + @Override + public void copyForEditObservedSystem(ActivitySeine source, ActivitySeine target) { + + getBinderForEditObservedSystem().load(source, target, true); + + } + protected ActivitySeine create(String routeId, ActivitySeine toCreate) { ActivitySeineDAO dao = getDao(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java index 8e9d42a..80e7225 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java @@ -1,8 +1,11 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.TransmittingBuoy; import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -16,23 +19,39 @@ public interface FloatingObjectService extends ObserveService { List<FloatingObject> getFloatinObjectStubByActivitySeine(String activitySeineId); - FloatingObject getFloatinObjectStub(String id); + FloatingObject getFloatinObjectStub(String floatingObjectId); FloatingObject loadForEdit(String floatingObjectId); - FloatingObject loadForEditTransmittingBuoy(String floatingObjectId); + FloatingObject loadForEditTransmittingBuoyOperation(String floatingObjectId); - FloatingObject preCreate(String routeId); + FloatingObject preCreate(String activitySeineId); @Commit - FloatingObject create(FloatingObject toCreate); + FloatingObject save(String activitySeineId, FloatingObject toSave); @Commit - void update(FloatingObject toUpdate); + FloatingObject updateTransmittingBuoyOperation(FloatingObject toUpdate); @Commit - void updateTransmittingBuoy(FloatingObject toUpdate); + void delete(String activitySeineId, String floatingObjectId); + + @NoTransaction + TopiaEntityBinder<FloatingObject> getBinderForEdit(); + + @NoTransaction + TopiaEntityBinder<FloatingObject> getBinderForEditTransmittingBuoyOperation(); + + @NoTransaction + TopiaEntityBinder<TransmittingBuoy> getBinderForEditTransmittingBuoy(); + + @NoTransaction + void copyForEdit(FloatingObject source, FloatingObject target); + + @NoTransaction + void copyForEditTransmittingBuoyOperation(FloatingObject source, FloatingObject target); + + @NoTransaction + void copyForEditTransmittingBuoy(TransmittingBuoy source, TransmittingBuoy target); - @Commit - void delete(String floatingObjectId); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index bc1f78f..ef466ec 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -1,11 +1,18 @@ package fr.ird.observe.services.data.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.FloatingObjectDAO; +import fr.ird.observe.entities.seine.TransmittingBuoy; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; import java.util.List; +import java.util.Map; /** * Created on 4/24/15. @@ -35,39 +42,229 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject loadForEdit(String floatingObjectId) { - FloatingObject loaded = null; + + FloatingObject loaded = getDao().newInstance(); + FloatingObject toLoad = getDao().findByTopiaId(floatingObjectId); + copyForEdit(toLoad, loaded); + return loaded; + } @Override - public FloatingObject loadForEditTransmittingBuoy(String floatingObjectId) { - FloatingObject loaded = null; + public FloatingObject loadForEditTransmittingBuoyOperation(String floatingObjectId) { + + FloatingObject loaded = getDao().newInstance(); + FloatingObject toLoad = getDao().findByTopiaId(floatingObjectId); + copyForEditTransmittingBuoyOperation(toLoad, loaded); + return loaded; + } @Override - public FloatingObject preCreate(String routeId) { - FloatingObject result = null; - return result; + public FloatingObject preCreate(String activitySeineId) { + + FloatingObject preCreated = getDao().newInstance(); + return preCreated; + } @Override - public FloatingObject create(FloatingObject toCreate) { - FloatingObject created = null; - return created; + public FloatingObject save(String activitySeineId, FloatingObject toSave) { + + FloatingObject saved; + + if (toSave.getTopiaId() == null) { + + // create + saved = create(activitySeineId, toSave); + + } else { + + // update + saved = update(toSave); + + } + + return saved; + } @Override - public void update(FloatingObject toUpdate) { + public FloatingObject updateTransmittingBuoyOperation(FloatingObject toUpdate) { + + FloatingObject updated = getDao().findByTopiaId(toUpdate.getTopiaId()); + updated.setComment(toUpdate.getComment()); + updated.clearTransmittingBuoy(); + + TopiaEntityBinder<TransmittingBuoy> childLoador = getBinderForEditTransmittingBuoy(); + + TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = getDao(TransmittingBuoy.class); + + for (TransmittingBuoy transmittingBuoy : toUpdate.getTransmittingBuoy()) { + + TransmittingBuoy newTransmittingBuoy; + + if (transmittingBuoy.getTopiaId() == null) { + + // creation de la balise + + Map<String, Object> map = childLoador.obtainProperties(transmittingBuoy); + newTransmittingBuoy = transmittingBuoyDAO.create(map); + + } else { + + // mise a jour de la balise + + newTransmittingBuoy = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); + childLoador.load(transmittingBuoy, newTransmittingBuoy, false); + + } + + updated.addTransmittingBuoy(newTransmittingBuoy); + + } + return updated; + } @Override - public void updateTransmittingBuoy(FloatingObject toUpdate) { + public void delete(String activitySeineId, String floatingObjectId) { + + FloatingObjectDAO dao = getDao(); + FloatingObject toDelete = dao.findByTopiaId(floatingObjectId); + + ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); + activitySeine.removeFloatingObject(toDelete); } @Override - public void delete(String floatingObjectId) { + public TopiaEntityBinder<FloatingObject> getBinderForEdit() { + + TopiaEntityBinder<FloatingObject> binder = loadBinder("-forEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { + + @Override + public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_TYPE, + FloatingObject.PROPERTY_OBJECT_FATE, + FloatingObject.PROPERTY_OBJECT_OPERATION, + FloatingObject.PROPERTY_COMMENT, + FloatingObject.PROPERTY_SUPPORT_VESSEL_NAME, + FloatingObject.PROPERTY_DAYS_AT_SEA_COUNT); + + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEdit(FloatingObject source, FloatingObject target) { + + getBinderForEdit().load(source, target, true); + + } + + @Override + public TopiaEntityBinder<FloatingObject> getBinderForEditTransmittingBuoyOperation() { + + TopiaEntityBinder<FloatingObject> binder = loadBinder("-forEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { + + @Override + public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_COMMENT, + FloatingObject.PROPERTY_OBJECT_OPERATION + ); + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEditTransmittingBuoyOperation(FloatingObject source, FloatingObject target) { + + getBinderForEditTransmittingBuoyOperation().load(source, target, true); + + } + + @Override + public TopiaEntityBinder<TransmittingBuoy> getBinderForEditTransmittingBuoy() { + + TopiaEntityBinder<TransmittingBuoy> binder = loadBinder("-forEdit", TransmittingBuoy.class, new CreateBinder<TransmittingBuoy>() { + + @Override + public BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = binderService.newBinderBuilder( + TransmittingBuoy.class, + TransmittingBuoy.PROPERTY_CODE, + TransmittingBuoy.PROPERTY_OWNERSHIP, + TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, + TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, + TransmittingBuoy.PROPERTY_BRAND, + TransmittingBuoy.PROPERTY_COUNTRY); + + return builder; + + } + + @Override + public TopiaEntityBinder<TransmittingBuoy> registerTopiaBinder(BinderService binderService, Class<TransmittingBuoy> entityType, BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder, String name) { + + TopiaEntityBinder<TransmittingBuoy> binder = super.registerTopiaBinder(binderService, entityType, builder, name); + binder.setEmpty(getDao(TransmittingBuoy.class).newInstance()); + return binder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEditTransmittingBuoy(TransmittingBuoy source, TransmittingBuoy target) { + + getBinderForEditTransmittingBuoy().load(source, target, true); + + } + + protected FloatingObject create(String activitySeineId, FloatingObject toCreate) { + + FloatingObjectDAO dao = getDao(); + FloatingObject created = dao.create(toCreate); + + ActivitySeine route = findByTopiaId(ActivitySeine.class, activitySeineId); + route.addFloatingObject(created); + + return created; + + } + + protected FloatingObject update(FloatingObject toUpdate) { + + FloatingObject updated = getDao().findByTopiaId(toUpdate.getTopiaId()); + copyForEdit(toUpdate, updated); + return updated; + } protected FloatingObjectDAO getDao() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java index 51d13ad..58214c3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java @@ -21,20 +21,15 @@ */ package fr.ird.observe.ui.content.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.entities.constants.seine.SchoolType; import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.data.seine.ActivitySeineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import static org.nuiton.i18n.I18n.t; @@ -88,7 +83,9 @@ public class ActivitySeineObservedSystemUIHandler extends ContentUIHandler<Activ ContentMode mode = computeContentMode(); - getDataService().loadEditEntity(getDataSource(), activityId, getLoadExecutor()); + ActivitySeineService service = getService(ActivitySeineService.class); + ActivitySeine activitySeine = service.loadForEditObservedSystem(activityId); + service.copyForEditObservedSystem(activitySeine, getBean()); getModel().setMode(mode); @@ -104,39 +101,19 @@ public class ActivitySeineObservedSystemUIHandler extends ContentUIHandler<Activ } @Override - protected boolean doSave(ActivitySeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<ActivitySeine> binder) throws Exception { + protected boolean doSave(ActivitySeine bean) throws Exception { + + ActivitySeineService service = getService(ActivitySeineService.class); + ActivitySeine saved = service.updateObservedSystem(getBean()); + service.copyForEditObservedSystem(saved, bean); - // on sauvegarde l'activity (mais pas la set) - dataService.update(dataSource, null, bean, getUpdateExecutor()); return true; } + //TODO Supprimer saveUI et mettre saveUI2 a la place @Override - protected ActivitySeine onUpdate(TopiaContext tx, Object parentBean, ActivitySeine beanToSave) throws TopiaException { - - ActivitySeine bean = getBean(); - boolean needUpdateSet = false; - SchoolType newTypeBanc = bean.getSchoolType(); - SetSeine set = bean.getSetSeine(); - if (set != null) { - // on regarde si le type de banc de la calée a changé - - SchoolType oldTypeBanc = set.getSchoolType(); - needUpdateSet = oldTypeBanc == null || newTypeBanc != oldTypeBanc; - } - - getLoadBinder().copyExcluding(getBean(), beanToSave, ActivitySeine.PROPERTY_SET_SEINE); - - if (needUpdateSet) { - - // mise à jour de la propriété schoolType dans la set - beanToSave.getSetSeine().setSchoolType(newTypeBanc); - } - - return beanToSave; + public final void saveUI(boolean refresh) { + saveUI2(refresh); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java index 3db1541..21c72a3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java @@ -21,9 +21,7 @@ */ package fr.ird.observe.ui.content.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -35,6 +33,7 @@ import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.TransmittingBuoy; +import fr.ird.observe.services.data.seine.FloatingObjectService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; @@ -43,8 +42,6 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JPanel; @@ -52,7 +49,6 @@ import javax.swing.SwingUtilities; import java.awt.GridLayout; import java.util.ArrayList; import java.util.List; -import java.util.Map; import static org.nuiton.i18n.I18n.t; @@ -108,10 +104,10 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH ContentMode mode = computeContentMode(); - String dcpId = getSelectedParentId(); + String floatingObjectId = getSelectedParentId(); if (log.isInfoEnabled()) { - log.info("dcpId = " + dcpId); + log.info("floatingObjectId = " + floatingObjectId); } FloatingObject bean = getBean(); @@ -123,13 +119,13 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH getModel().setEditing(false); - getDataService().loadEditEntity(getDataSource(), dcpId, getLoadExecutor()); + FloatingObjectService service = getService(FloatingObjectService.class); + FloatingObject loaded = service.loadForEditTransmittingBuoyOperation(floatingObjectId); + service.copyForEditTransmittingBuoyOperation(loaded, getBean()); - getUi().processDataBinding( - FloatingObjectTransmittingBuoyOperationUI.BINDING_TYPE_OPERATION_SELECTED_ITEM); + getUi().processDataBinding(FloatingObjectTransmittingBuoyOperationUI.BINDING_TYPE_OPERATION_SELECTED_ITEM); - TypeTransmittingBuoyOperation typeOperation = - getUi().getTypeOperation().getSelectedItem(); + TypeTransmittingBuoyOperation typeOperation = getUi().getTypeOperation().getSelectedItem(); changeTypeOperation(typeOperation, false); getModel().setMode(mode); @@ -240,57 +236,57 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH } @Override - protected boolean doSave(FloatingObject bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<FloatingObject> binder) throws Exception { + protected boolean doSave(FloatingObject bean) { + + FloatingObjectService service = getService(FloatingObjectService.class); + FloatingObject saved = service.updateTransmittingBuoyOperation(bean); + service.copyForEditTransmittingBuoyOperation(saved, bean); - dataService.update(dataSource, null, bean, getUpdateExecutor()); //FIXME, il faut declancher un evenement dans le cache du storage pour pouvoir redessiner le noeud return true; } - @Override - protected FloatingObject onUpdate(TopiaContext tx, - Object parentBean, - FloatingObject beanToSave) throws TopiaException { - - FloatingObject editBean = getBean(); - - List<TransmittingBuoy> objets = editBean.getTransmittingBuoy(); - - beanToSave.setComment(editBean.getComment()); - - beanToSave.clearTransmittingBuoy(); - - TopiaEntityBinder<TransmittingBuoy> childLoador = getModel().getChildLoador(); - - TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = ObserveDAOHelper.getTransmittingBuoyDAO(tx); - - for (TransmittingBuoy transmittingBuoy : objets) { - TransmittingBuoy newBalise; - - if (transmittingBuoy.getTopiaId() == null) { - - // creation de la balise - - Map<String, Object> map = childLoador.obtainProperties(transmittingBuoy); - - newBalise = transmittingBuoyDAO.create(map); - - } else { - - // mise a jour de la balise - - newBalise = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); - - childLoador.load(transmittingBuoy, newBalise, false); - } - - beanToSave.addTransmittingBuoy(newBalise); - } - return beanToSave; - } +// @Override +// protected FloatingObject onUpdate(TopiaContext tx, +// Object parentBean, +// FloatingObject beanToSave) throws TopiaException { +// +// FloatingObject editBean = getBean(); +// +// List<TransmittingBuoy> objets = editBean.getTransmittingBuoy(); +// +// beanToSave.setComment(editBean.getComment()); +// +// beanToSave.clearTransmittingBuoy(); +// +// TopiaEntityBinder<TransmittingBuoy> childLoador = getModel().getChildLoador(); +// +// TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = ObserveDAOHelper.getTransmittingBuoyDAO(tx); +// +// for (TransmittingBuoy transmittingBuoy : objets) { +// TransmittingBuoy newBalise; +// +// if (transmittingBuoy.getTopiaId() == null) { +// +// // creation de la balise +// +// Map<String, Object> map = childLoador.obtainProperties(transmittingBuoy); +// +// newBalise = transmittingBuoyDAO.create(map); +// +// } else { +// +// // mise a jour de la balise +// +// newBalise = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); +// +// childLoador.load(transmittingBuoy, newBalise, false); +// } +// +// beanToSave.addTransmittingBuoy(newBalise); +// } +// return beanToSave; +// } @Override protected void afterSave(boolean refresh) { @@ -392,7 +388,8 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH TransmittingBuoyOperation transmittingBuoyOperation, TransmittingBuoy transmittingBuoy) { - getModel().getChildLoador().load(transmittingBuoy, editBean, false); + FloatingObjectService service = getService(FloatingObjectService.class); + service.copyForEditTransmittingBuoy(transmittingBuoy, editBean); if (transmittingBuoy == null) { @@ -436,4 +433,10 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH return objectOperation; } + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java index 0888a16..3fe2242 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java @@ -23,12 +23,8 @@ package fr.ird.observe.ui.content.impl.seine; */ import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.TransmittingBuoy; -import fr.ird.observe.entities.seine.TransmittingBuoyImpl; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.beans.BinderModelBuilder; /** @@ -41,40 +37,40 @@ public class FloatingObjectTransmittingBuoyOperationUIModel extends ContentUIMod private static final long serialVersionUID = 1L; - protected TopiaEntityBinder<TransmittingBuoy> childLoador; +// protected TopiaEntityBinder<TransmittingBuoy> childLoador; public FloatingObjectTransmittingBuoyOperationUIModel() { super(FloatingObject.class); - String binderName = getClass().getName() + "-open"; - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - - childLoador = binderService.getTopiaBinder(TransmittingBuoy.class, binderName); - - if (childLoador == null) { - - BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = binderService.newBinderBuilder( - TransmittingBuoy.class, - TransmittingBuoy.PROPERTY_CODE, - TransmittingBuoy.PROPERTY_OWNERSHIP, - TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, - TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, - TransmittingBuoy.PROPERTY_BRAND, - TransmittingBuoy.PROPERTY_COUNTRY); - - // enregistrement du binder - childLoador = binderService.registerTopiaBinder(TransmittingBuoy.class, builder, binderName); - - // positionnement de l'entite empty - childLoador.setEmpty(new TransmittingBuoyImpl()); - } +// String binderName = getClass().getName() + "-open"; +// +// BinderService binderService = ObserveServiceHelper.get().getBinderService(); + +// childLoador = binderService.getTopiaBinder(TransmittingBuoy.class, binderName); +// +// if (childLoador == null) { +// +// BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = binderService.newBinderBuilder( +// TransmittingBuoy.class, +// TransmittingBuoy.PROPERTY_CODE, +// TransmittingBuoy.PROPERTY_OWNERSHIP, +// TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, +// TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, +// TransmittingBuoy.PROPERTY_BRAND, +// TransmittingBuoy.PROPERTY_COUNTRY); +// +// // enregistrement du binder +// childLoador = binderService.registerTopiaBinder(TransmittingBuoy.class, builder, binderName); +// +// // positionnement de l'entite empty +// childLoador.setEmpty(new TransmittingBuoyImpl()); +// } } - public TopiaEntityBinder<TransmittingBuoy> getChildLoador() { - return childLoador; - } +// public TopiaEntityBinder<TransmittingBuoy> getChildLoador() { +// return childLoador; +// } @Override protected BinderModelBuilder<FloatingObject, FloatingObject> createOpeningBinder(BinderService binderService, String binderName) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java index 6787aa7..0ef7e26 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java @@ -21,15 +21,12 @@ */ package fr.ird.observe.ui.content.impl.seine; -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.FloatingObjectDAO; +import fr.ird.observe.services.data.seine.FloatingObjectService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.content.ContentUIModel; @@ -37,10 +34,6 @@ import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import static org.nuiton.i18n.I18n.t; @@ -102,30 +95,34 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { super.openUI(); String activityId = getSelectedParentId(); - String dcpId = getSelectedId(); + String floatingObjectId = getSelectedId(); if (log.isInfoEnabled()) { - log.info("activityId = " + activityId); - log.info("dcpId = " + dcpId); + log.info("activityId = " + activityId); + log.info("floatingObjectId = " + floatingObjectId); } ContentMode mode = computeContentMode(); - FloatingObject bean = getBean(); + FloatingObjectService service = getService(FloatingObjectService.class); - DataService dataService = getDataService(); - if (dcpId == null) { + FloatingObject loaded; + + if (floatingObjectId == null) { // creation mode + loaded = service.preCreate(activityId); - dataService.preCreate(getDataSource(), activityId, bean, getLoadBinder(), getPreCreateExecutor()); } else { // update mode + loaded = service.loadForEdit(floatingObjectId); - dataService.loadEditEntity(getDataSource(), dcpId, getLoadExecutor()); } + FloatingObject bean = getBean(); + service.copyForEdit(loaded, bean); + // utilisation du mode requis setContentMode(mode); @@ -160,42 +157,18 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { } @Override - protected boolean doSave(FloatingObject bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<FloatingObject> binder) throws Exception { + protected boolean doSave(FloatingObject bean) { String activityId = getSelectedParentId(); - if (bean.getTopiaId() == null) { - - dataService.create(dataSource, activityId, bean, binder, getCreateExecutor()); - } else { + FloatingObjectService service = getService(FloatingObjectService.class); + FloatingObject saved = service.save(activityId, bean); + service.copyForEdit(saved, bean); - dataService.update(dataSource, null, bean, getUpdateExecutor()); - } return true; } @Override - protected FloatingObject onCreate(TopiaContext tx, Object parent, FloatingObject editBean) throws TopiaException { - ActivitySeine parentBean = (ActivitySeine) parent; - FloatingObjectDAO dao = ObserveDAOHelper.getFloatingObjectDAO(tx); - FloatingObject beanToSave = dao.create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - parentBean.addFloatingObject(beanToSave); - return beanToSave; - } - - @Override - protected FloatingObject onUpdate(TopiaContext tx, Object parentBean, FloatingObject beanToSave) throws TopiaException { - - getLoadBinder().copy(getBean(), beanToSave); - - return beanToSave; - } - - @Override protected void afterSave(boolean refresh) { super.afterSave(refresh); FloatingObject bean = getBean(); @@ -219,33 +192,40 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { } else { // select ancestor node -// treeHelper.refreshNode(node, false); treeHelper.reloadSelectedNode(false, false); } } @Override - protected boolean doDelete(FloatingObject bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, FloatingObject> deletor) throws Exception { + protected boolean doDelete(FloatingObject bean) { - if (askToDelete(bean)) { - return false; - } + boolean result; - if (bean.getTopiaId() != null) { + if (!askToDelete(bean)) { + + result = false; + + } else { String activityId = getSelectedParentId(); - dataService.delete(dataSource, activityId, bean, deletor); + getService(FloatingObjectService.class).delete(activityId, bean.getTopiaId()); + result = true; + } - return true; + + return result; + } + //TODO Supprimer saveUI et mettre saveUI2 a la place @Override - protected void onDelete(TopiaContext tx, Object parent, FloatingObject beanToDelete) { - ActivitySeine parentBean = (ActivitySeine) parent; - parentBean.removeFloatingObject(beanToDelete); + public final void saveUI(boolean refresh) { + saveUI2(refresh); } + //TODO Supprimer deleteUI et mettre deleteUI2 a la place + @Override + public final void deleteUI() { + deleteUI2(); + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 2202b5eeadf13a04b417408e307e94f3d5abeab4 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Apr 27 11:48:38 2015 +0200 refactor save action --- .../observe/services/AbstractObserveService.java | 88 ++++++++++++++++++++++ .../services/data/seine/TripSeineService.java | 2 +- .../services/data/seine/TripSeineServiceImpl.java | 54 +++++-------- .../open/impl/seine/TripSeineUIHandler.java | 4 +- 4 files changed, 108 insertions(+), 40 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index b0a0c17..4870d6a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -17,6 +17,7 @@ import org.nuiton.topia.TopiaContext; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; @@ -33,6 +34,10 @@ public abstract class AbstractObserveService implements ObserveService { /** Logger. */ private static final Log log = LogFactory.getLog(AbstractObserveService.class); + String PARENT_BEAN = "parentBean"; + + String BEAN = "bean"; + protected ObserveServiceContext serviceContext; @Override @@ -199,4 +204,87 @@ public abstract class AbstractObserveService implements ObserveService { } + public <P extends TopiaEntity, E extends TopiaEntity> String doSave(String parentId, E toSave, SaveAction<P, E> saveAction) { + E saved; + + saveAction.beforeSave(parentId, toSave); + + P parent = null; + + if (parentId != null) { + + parent = findByTopiaId(saveAction.parentClass, parentId); + + checkNotNullAndExistingEntity(PARENT_BEAN, parent); + } + + if (toSave.getTopiaId() == null) { + + checkNotNullAndNoneExistingEntity(BEAN, toSave); + + saved = saveAction.onCreate(parent, toSave); + + } else { + + checkNotNullAndExistingEntity(BEAN, toSave); + + saved = findByTopiaId(saveAction.entityClass, toSave.getTopiaId()); + + checkNotNullAndExistingEntity(BEAN, saved); + + saved = saveAction.onUpdate(parent, toSave, saved); + } + + if (parent == null) { + + // sauvegarde de l'entité + getDao(saveAction.entityClass).update(saved); + + } else { + + // sauvegarde du père de l'entité + getDao(saveAction.parentClass).update(parent); + + } + + return saved.getTopiaId(); + + + } + + protected abstract class SaveAction<P extends TopiaEntity, E extends TopiaEntity> { + + protected final Class<P> parentClass; + + protected final Class<E> entityClass; + + public SaveAction(Class<P> parentClass, Class<E> entityClass) { + this.parentClass = parentClass; + this.entityClass = entityClass; + } + + public void beforeSave(String parentId, E toSave) { + + } + + public E onCreate(P parent, E toCreate) { + return getDao(entityClass).update(toCreate); + }; + + public abstract E onUpdate(P parentBean, E toSave, E beanToSave); + } + + + public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { + TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); + } + + + public <E extends TopiaEntity> void checkNotNullAndExistingEntity(String variableName, E entity) { + TopiaEntityHelper.checkNotNullAndExistingEntity(variableName, entity); + } + + + + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java index bd16f3e..924ea39 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java @@ -29,7 +29,7 @@ public interface TripSeineService extends ObserveService { TripSeine preCreate(String programId); @Commit - TripSeine save(TripSeine toSave); + String save(TripSeine toSave); @Commit void delete(String tripSeineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index 0d99d82..46fb48d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -101,30 +101,27 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip } @Override - public TripSeine save(TripSeine toSave) { + public String save(TripSeine toSave) { + String tripSeineId = doSave(null, toSave, new SaveAction<Program, TripSeine>(Program.class, TripSeine.class) { - // on force toujours la date a etre sans heure, minute,... - Date startDate = DateUtil.getDay(toSave.getStartDate()); - toSave.setStartDate(startDate); - - // mise a jour de la date de fin - toSave.updateDateFin(); - - TripSeine saved; - - if (toSave.getTopiaId() == null) { - - // create - saved = create(toSave); - - } else { + @Override + public void beforeSave(String parentId, TripSeine toSave) { + super.beforeSave(parentId, toSave); + Date startDate = DateUtil.getDay(toSave.getStartDate()); + toSave.setStartDate(startDate); - // update - saved = update(toSave); + // mise a jour de la date de fin + toSave.updateDateFin(); + } - } + @Override + public TripSeine onUpdate(Program parentBean, TripSeine toUpdate, TripSeine updated) { + getBinderForEdit().copyExcluding(toUpdate, updated, TripSeine.PROPERTY_ROUTE); + return updated; + } + }); - return saved; + return tripSeineId; } @@ -183,21 +180,4 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip } - protected TripSeine create(TripSeine toCreate) { - - TripSeineDAO dao = getDao(); - TripSeine created = dao.create(toCreate); - return created; - - } - - protected TripSeine update(TripSeine toUpdate) { - - TripSeineDAO dao = getDao(); - TripSeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); - getBinderForEdit().copyExcluding(toUpdate, updated, TripSeine.PROPERTY_ROUTE); - return updated; - - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java index 234ab99..27ca6a9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java @@ -227,8 +227,8 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { bean.setOpen(true); TripSeineService service = getService(TripSeineService.class); - TripSeine saved = service.save(bean); - bean.setTopiaId(saved.getTopiaId()); + String saveId = service.save(bean); + bean.setTopiaId(saveId); // recuperation de la position de la maree dans le program obtainChildPosition(bean); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit f4493d9da71be443e4174a8e56f3efd368d0c289 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 12:17:43 2015 +0200 ne pas mettre une transaction si l'annoation NoTransaction is présente sur une méthode de service (refs #7017) --- .../src/main/java/fr/ird/observe/services/ObserveServiceFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index fc2b3b5..74bbd77 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -181,7 +181,7 @@ public class ObserveServiceFactory implements Closeable { Object result; - if (methodNamesToByPass.contains(method.getName())) { + if (methodNamesToByPass.contains(method.getName()) || !method.isAnnotationPresent(NoTransaction.class)) { result = method.invoke(target, args); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 2e0a250caf9f96f6282759ef45c45cbee129fc74 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 14:55:57 2015 +0200 mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) --- .../java/fr/ird/observe/services/data/TripServiceImpl.java | 7 ------- .../ui/tree/ObserveNavigationTreeShowPopupAction.java | 5 ++++- .../ui/tree/actions/ChangeTripProgramActionListener.java | 14 +++++++++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java index e50203d..4a7e2c9 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java @@ -80,13 +80,6 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi trip.setProgram(program); -// if (trip.isOpen()) { -// -// // refresh the dataContext -// dataContext.setOpenProgramId(programId); -// -// } - } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java index cc11922..ba2630a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java @@ -223,6 +223,8 @@ public class ObserveNavigationTreeShowPopupAction { OpenableService openableService = observeContext.getService(OpenableService.class); TripService tripService = observeContext.getService(TripService.class); String tripId = selectedNode.getId(); + String openTripId = observeContext.getDataContext().getOpenTripId(); + boolean tripOpen = openTripId!=null && openTripId.equals(tripId); List<Program> programs = tripService.getPossibleProgramsForTrip(tripId); @@ -241,7 +243,8 @@ public class ObserveNavigationTreeShowPopupAction { openableService, tripService, tripId, - programId)); + programId, + tripOpen)); moveTripPopup.add(item); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java index 5fb89a7..225d893 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/actions/ChangeTripProgramActionListener.java @@ -22,6 +22,7 @@ package fr.ird.observe.ui.tree.actions; * #L% */ +import fr.ird.observe.ObserveContext; import fr.ird.observe.services.data.OpenableService; import fr.ird.observe.services.data.TripService; import fr.ird.observe.ui.tree.ObserveNode; @@ -53,16 +54,20 @@ public class ChangeTripProgramActionListener implements ActionListener { protected final OpenableService openableService; + private final boolean tripOpen; + public ChangeTripProgramActionListener(ObserveTreeHelper treeHelper, OpenableService openableService, TripService tripService, String tripId, - String programId) { + String programId, + boolean tripOpen) { this.tripService = tripService; this.tripId = tripId; this.programId = programId; this.treeHelper = treeHelper; this.openableService = openableService; + this.tripOpen = tripOpen; } @Override @@ -75,6 +80,13 @@ public class ChangeTripProgramActionListener implements ActionListener { tripService.moveTripToProgram(tripId, programId); + if (tripOpen) { + + // refresh the dataContext + ObserveContext.get().getDataContext().setOpenProgramId(programId); + + } + int position = openableService.getOpenablePosition(programId, tripId); treeHelper.removeNode(tripNode); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit b1c6d984f0c17942eb42eaff8420f70685cd3510 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 14:57:30 2015 +0200 mise à jour du programme ouvert lors du déplacement d'une marée (ref #7017) --- .../fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java index ba2630a..78712a2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveNavigationTreeShowPopupAction.java @@ -223,8 +223,7 @@ public class ObserveNavigationTreeShowPopupAction { OpenableService openableService = observeContext.getService(OpenableService.class); TripService tripService = observeContext.getService(TripService.class); String tripId = selectedNode.getId(); - String openTripId = observeContext.getDataContext().getOpenTripId(); - boolean tripOpen = openTripId!=null && openTripId.equals(tripId); + boolean tripOpen = selectedNode.isOpen(); List<Program> programs = tripService.getPossibleProgramsForTrip(tripId); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 731d1aba7422e475f71f0b1a325300a27eacb815 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 15:38:55 2015 +0200 amélioration des erreurs sur le proxy (refs #7017) --- .../ird/observe/services/ObserveServiceFactory.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index 74bbd77..79f76ef 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -8,7 +8,6 @@ import com.google.common.collect.Sets; import fr.ird.observe.ObserveApplicationContext; import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.reflect.ConstructorUtils; import org.apache.commons.logging.Log; @@ -181,9 +180,9 @@ public class ObserveServiceFactory implements Closeable { Object result; - if (methodNamesToByPass.contains(method.getName()) || !method.isAnnotationPresent(NoTransaction.class)) { + if (methodNamesToByPass.contains(method.getName()) || method.isAnnotationPresent(NoTransaction.class)) { - result = method.invoke(target, args); + result = invokeMethod(method, args); } else { @@ -195,7 +194,17 @@ public class ObserveServiceFactory implements Closeable { } - protected Object invokeMethodWithTransaction(Method method, Object... args) throws DataSourceException, IllegalAccessException, InvocationTargetException { + protected Object invokeMethod(Method method, Object... args) throws Throwable { + try { + Object result = method.invoke(target, args); + return result; + } catch (InvocationTargetException e) { + throw e.getCause(); + } + } + + + protected Object invokeMethodWithTransaction(Method method, Object... args) throws Throwable { String methodName = method.getName(); @@ -207,7 +216,7 @@ public class ObserveServiceFactory implements Closeable { serviceContext.setTransaction(tx); - Object invoke = method.invoke(target, args); + Object invoke = invokeMethod(method, args); if (method.isAnnotationPresent(Commit.class)) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit fca87fcdd5ccbe4db4af65e09176aaf1e0efdd0d Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 15:39:20 2015 +0200 correction de la méthode onCreate (refs #7017) --- .../src/main/java/fr/ird/observe/services/AbstractObserveService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 4870d6a..7af5a7a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -267,9 +267,7 @@ public abstract class AbstractObserveService implements ObserveService { } - public E onCreate(P parent, E toCreate) { - return getDao(entityClass).update(toCreate); - }; + public abstract E onCreate(P parent, E toCreate); public abstract E onUpdate(P parentBean, E toSave, E beanToSave); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 48b4dcab39405c0fffbeb177310aee42a2e022a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 15:39:42 2015 +0200 correction de la méthode onCreate (refs #7017) --- .../fr/ird/observe/services/data/seine/TripSeineServiceImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index 46fb48d..2935943 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -115,6 +115,13 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip } @Override + public TripSeine onCreate(Program parent, TripSeine toCreate) { + TripSeine created = getDao().create(); + getBinderForEdit().copy(toCreate, created); + return created; + } + + @Override public TripSeine onUpdate(Program parentBean, TripSeine toUpdate, TripSeine updated) { getBinderForEdit().copyExcluding(toUpdate, updated, TripSeine.PROPERTY_ROUTE); return updated; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 14088bfd008c7f595e63d090d3f1f148c8ea4640 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 08:47:48 2015 +0200 correction de la mise à jour du context openable (refs #7017) --- .../ird/observe/ui/content/open/ContentOpenableUIHandler.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java index 38138e3..acc0335 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java @@ -224,6 +224,9 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE int oldPosition; if (create) { + + reloadOpenContext(); + oldPosition = parentNode.getChildCount(); } else { oldPosition = parentNode.getIndex(node); @@ -359,4 +362,12 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE } } + @Override + protected void afterDelete() { + + reloadOpenContext(); + + super.afterDelete(); + + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 4799c9b21b016fd77b3444040432fd1d676eaf7d Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 09:49:49 2015 +0200 add binderService in serviceContext (refs #7017) --- .../main/java/fr/ird/observe/services/ObserveServiceContext.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java index a837b4c..cba9e5d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java @@ -1,5 +1,6 @@ package fr.ird.observe.services; +import fr.ird.observe.BinderService; import fr.ird.observe.DecoratorService; import fr.ird.observe.IObserveConfig; import fr.ird.observe.ObserveApplicationContext; @@ -29,6 +30,8 @@ public class ObserveServiceContext { protected final DecoratorService decoratorService; + private final BinderService binderService; + /** * Current transaction. */ @@ -44,6 +47,7 @@ public class ObserveServiceContext { this.config = applicationContext.getConfig(); this.dataSource = dataSource; this.decoratorService = applicationContext.getDecoratorService(); + this.binderService = applicationContext.getBinderService(); } public TopiaContext getTransaction() { @@ -66,6 +70,10 @@ public class ObserveServiceContext { return decoratorService; } + public BinderService getBinderService() { + return binderService; + } + protected void setTransaction(TopiaContext transaction) { this.transaction = transaction; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 4bec0c4a881253593ea34f58dae17ed1d412461a Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 09:50:07 2015 +0200 load programs (refs #7017) --- .../observe/services/referential/ReferentialService.java | 3 +++ .../services/referential/ReferentialServiceImpl.java | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java index c00066a..4646e30 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java @@ -29,4 +29,7 @@ public interface ReferentialService extends ObserveService { List<Species> loadDecoratedSpecies(String speciesListCode); Set<String> getSpeciesListSpeciesIds(String speciesListId); + + void copyProgramForDisplay(Program source, Program target); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 99edc58..3e1e86e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.referential; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ProgramDAO; @@ -40,10 +41,10 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re List<Program> allProgramStub = getAllProgramStub(); Program programStub = getProgramStub(programId); - int result=0; + int result = 0; if (CollectionUtils.isNotEmpty(allProgramStub)) { Programs.sort(allProgramStub); - result= allProgramStub.indexOf(programStub); + result = allProgramStub.indexOf(programStub); } return result; } @@ -100,4 +101,12 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re return ids; } + + @Override + public void copyProgramForDisplay(Program source, Program target) { + + BinderService binderService = serviceContext.getBinderService(); + binderService.simpleCopy(source, target, true); + + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 57ceac33855494c42362a2e02d3ae1e80198f7d5 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 28 09:50:26 2015 +0200 do the math for lists-like ui (refs #7017) --- .../data/longline/TripLonglineService.java | 8 +++-- .../data/longline/TripLonglineServiceImpl.java | 42 +++++++++++++++++----- .../observe/services/data/seine/RouteService.java | 7 ++++ .../services/data/seine/RouteServiceImpl.java | 30 ++++++++++++++++ .../services/data/seine/TripSeineService.java | 9 +++-- .../services/data/seine/TripSeineServiceImpl.java | 42 +++++++++++++++++----- .../ui/content/list/ContentListUIHandler.java | 18 +++------- .../impl/longline/ActivityLonglinesUIHandler.java | 19 +++++++--- .../list/impl/longline/TripLonglinesUIHandler.java | 16 ++++++--- .../list/impl/seine/ActivitySeinesUIHandler.java | 22 ++++++++---- .../content/list/impl/seine/RoutesUIHandler.java | 19 +++++++--- .../list/impl/seine/TripSeinesUIHandler.java | 17 ++++++--- 12 files changed, 187 insertions(+), 62 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java index b39e076..28b8255 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java @@ -20,8 +20,6 @@ public interface TripLonglineService extends ObserveService { TripLongline getTripLonglineStub(String tripId); - List<TripLongline> loadAllByProgramForDisplay(String programId); - TripLongline loadForDisplay(String tripLonglineId); TripLongline loadForEdit(String tripLonglineId); @@ -38,5 +36,11 @@ public interface TripLonglineService extends ObserveService { TopiaEntityBinder<TripLongline> getBinderForEdit(); @NoTransaction + TopiaEntityBinder<TripLongline> getBinderStubForDisplay(); + + @NoTransaction void copyForEdit(TripLongline source, TripLongline target); + + @NoTransaction + void copyStubForDisplay(TripLongline source, TripLongline target); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index 7a93264..215c5d8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -39,15 +39,6 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T } @Override - public List<TripLongline> loadAllByProgramForDisplay(String programId) { - - ReferenceLocale referenceLocale = getReferentielLocale(); - List<TripLongline> loaded = getDao().findAllStubByProgramId(programId, referenceLocale); - return loaded; - - } - - @Override public TripLongline loadForDisplay(String tripLonglineId) { TripLongline loaded = getDao().newInstance(); @@ -171,12 +162,45 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T } @Override + public TopiaEntityBinder<TripLongline> getBinderStubForDisplay() { + + TopiaEntityBinder<TripLongline> r = loadBinder("-stubFordisplay", TripLongline.class, new CreateBinder<TripLongline>() { + + @Override + public BinderModelBuilder<TripLongline, TripLongline> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<TripLongline, TripLongline> builder = binderService.newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_START_DATE, + TripLongline.PROPERTY_END_DATE, + TripLongline.PROPERTY_OPEN, + TripLongline.PROPERTY_OBSERVER, + TripLongline.PROPERTY_VESSEL, + TripLongline.PROPERTY_PROGRAM); + + return builder; + } + + }); + + return r; + + } + + @Override public void copyForEdit(TripLongline source, TripLongline target) { getBinderForEdit().load(source, target, true); } + @Override + public void copyStubForDisplay(TripLongline source, TripLongline target) { + + getBinderStubForDisplay().load(source, target, true); + + } + protected TripLongline create(TripLongline toCreate) { TripLonglineDAO dao = getDao(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java index af91248..b968807 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java @@ -36,5 +36,12 @@ public interface RouteService extends ObserveService { TopiaEntityBinder<Route> getBinderForEdit(); @NoTransaction + TopiaEntityBinder<Route> getBinderStubForDisplay(); + + @NoTransaction void copyForEdit(Route source, Route target); + + @NoTransaction + void copyStubForDisplay(Route source, Route target); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index fc6a459..0333785 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -181,12 +181,42 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer } @Override + public TopiaEntityBinder<Route> getBinderStubForDisplay() { + + TopiaEntityBinder<Route> binder = loadBinder("-stubForDisplay", Route.class, new CreateBinder<Route>() { + + @Override + public BinderModelBuilder<Route, Route> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<Route, Route> builder = binderService.newBinderBuilder( + Route.class, + Route.PROPERTY_DATE, + Route.PROPERTY_OPEN); + + return builder; + + } + + }); + + return binder; + + } + + @Override public void copyForEdit(Route source, Route target) { getBinderForEdit().load(source, target, true); } + @Override + public void copyStubForDisplay(Route source, Route target) { + + getBinderStubForDisplay().load(source, target, true); + + } + protected Route create(String tripSeineId, Route toCreate) { RouteDAO dao = getDao(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java index 924ea39..bbc6fd1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java @@ -20,8 +20,6 @@ public interface TripSeineService extends ObserveService { TripSeine getTripSeineStub(String tripSeineId); - List<TripSeine> loadAllByProgramForDisplay(String programId); - TripSeine loadForDisplay(String tripSeineId); TripSeine loadForEdit(String tripSeineId); @@ -38,5 +36,12 @@ public interface TripSeineService extends ObserveService { TopiaEntityBinder<TripSeine> getBinderForEdit(); @NoTransaction + TopiaEntityBinder<TripSeine> getBinderStubForDisplay(); + + @NoTransaction void copyForEdit(TripSeine source, TripSeine target); + + @NoTransaction + void copyStubForDisplay(TripSeine source, TripSeine target); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index 2935943..985bd35 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -46,15 +46,6 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip } @Override - public List<TripSeine> loadAllByProgramForDisplay(String programId) { - - ReferenceLocale referenceLocale = getReferentielLocale(); - List<TripSeine> loaded = getDao().findAllStubByProgramId(programId, referenceLocale); - return loaded; - - } - - @Override public TripSeine loadForDisplay(String tripSeineId) { TripSeine loaded = getDao().newInstance(); @@ -181,10 +172,43 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip } @Override + public TopiaEntityBinder<TripSeine> getBinderStubForDisplay() { + + TopiaEntityBinder<TripSeine> r = loadBinder("-stubForDisplay", TripSeine.class, new CreateBinder<TripSeine>() { + + @Override + public BinderModelBuilder<TripSeine, TripSeine> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<TripSeine, TripSeine> builder = binderService.newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_START_DATE, + TripSeine.PROPERTY_END_DATE, + TripSeine.PROPERTY_OPEN, + TripSeine.PROPERTY_OBSERVER, + TripSeine.PROPERTY_VESSEL, + TripSeine.PROPERTY_PROGRAM); + + return builder; + } + + }); + + return r; + + } + + @Override public void copyForEdit(TripSeine source, TripSeine target) { getBinderForEdit().load(source, target, true); } + @Override + public void copyStubForDisplay(TripSeine source, TripSeine target) { + + getBinderStubForDisplay().load(source, target, true); + + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java index 46fa00a..c086ec2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.content.list; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.ui.actions.shared.SelectNodeUIAction; import fr.ird.observe.ui.content.ContentMode; @@ -64,14 +63,12 @@ public abstract class ContentListUIHandler<E extends TopiaEntity, C extends Topi } /** - * Obtain the list of entities to display on ui from his container - * {@code bean}. + * Load data (the main bean + the data list) in model. * - * @param bean the container of entities to display - * @return the list of entities to display - * @throws DataSourceException if a pb while grabbing data + * @param selectedId id of the entity to load + * @since 4.0 */ - protected abstract List<C> getChilds(E bean) throws DataSourceException; + protected abstract void loadDataInModel(String selectedId); @Override protected boolean computeCanWrite(DataSource source) { @@ -134,12 +131,7 @@ public abstract class ContentListUIHandler<E extends TopiaEntity, C extends Topi } model.setCanReopen(canReopen); - E bean = getBean(); - getDataService().loadEditEntity(getDataSource(), selectedId, getLoadExecutor()); - - List<C> data = getChilds(bean); - - model.setData(data); + loadDataInModel(selectedId); if (!model.isEmpty()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java index adc7da6..0e02043 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java @@ -28,6 +28,7 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.services.data.longline.ActivityLonglineService; +import fr.ird.observe.services.data.longline.TripLonglineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -108,16 +109,24 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin } @Override - protected List<ActivityLongline> getChilds(TripLongline bean) throws DataSourceException { + protected void loadDataInModel(String selectedId) { - ActivityLonglineService service = getService(ActivityLonglineService.class); - List<ActivityLongline> list = service.getActivityLonglineStubByTrip(bean.getTopiaId()); + TripLonglineService tripService = getService(TripLonglineService.class); + TripLongline loaded = tripService.getTripLonglineStub(selectedId); + + TripLongline bean = getBean(); + tripService.copyStubForDisplay(loaded, bean); + + ActivityLonglineService routeService = getService(ActivityLonglineService.class); + List<ActivityLongline> activityLonglines = routeService.getActivityLonglineStubByTrip(selectedId); if (log.isDebugEnabled()) { - log.debug("Will use " + list.size() + " activities."); + log.debug("Will use " + activityLonglines.size() + " activities."); } - return list; + bean.setActivityLongline(activityLonglines); + + getModel().setData(activityLonglines); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java index 0c2e8b9..b5f58bc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java @@ -28,6 +28,7 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.services.data.longline.TripLonglineService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -91,16 +92,21 @@ public class TripLonglinesUIHandler extends ContentListUIHandler<Program, TripLo } @Override - protected List<TripLongline> getChilds(Program bean) throws DataSourceException { + protected void loadDataInModel(String selectedId) { - TripLonglineService service = getService(TripLonglineService.class); - List<TripLongline> list = service.getTripLonglineStubByProgram(bean.getTopiaId()); + ReferentialService service = getService(ReferentialService.class); + Program loaded = service.loadAndDecorate(Program.class, selectedId); + Program bean = getBean(); + service.copyProgramForDisplay(loaded, bean); + + TripLonglineService tripService = getService(TripLonglineService.class); + List<TripLongline> tripLonglines = tripService.getTripLonglineStubByProgram(bean.getTopiaId()); if (log.isDebugEnabled()) { - log.debug("Will use " + list.size() + " trips."); + log.debug("Will use " + tripLonglines.size() + " trips."); } - return list; + getModel().setData(tripLonglines); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java index 619cf3e..5b866ce 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java @@ -22,11 +22,11 @@ package fr.ird.observe.ui.content.list.impl.seine; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.services.data.seine.ActivitySeineService; +import fr.ird.observe.services.data.seine.RouteService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -106,17 +106,25 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit } @Override - protected List<ActivitySeine> getChilds(Route bean) throws DataSourceException { + protected void loadDataInModel(String selectedId) { - ActivitySeineService service = getService(ActivitySeineService.class); - List<ActivitySeine> list = service.getActivitySeineStubByRoute(bean.getTopiaId()); + RouteService routeService = getService(RouteService.class); + + Route loaded = routeService.getRouteStub(selectedId); + Route bean = getBean(); + routeService.copyStubForDisplay(loaded, bean); + + ActivitySeineService activityService = getService(ActivitySeineService.class); + List<ActivitySeine> activitySeines = activityService.getActivitySeineStubByRoute(selectedId); if (log.isDebugEnabled()) { - log.debug("Will use " + list.size() + " activities."); + log.debug("Will use " + activitySeines.size() + " activities."); } - return list; - + bean.setActivitySeine(activitySeines); + + getModel().setData(activitySeines); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java index 29c1fe2..d8276b9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java @@ -27,6 +27,7 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.data.seine.RouteService; +import fr.ird.observe.services.data.seine.TripSeineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -103,16 +104,24 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { } @Override - protected List<Route> getChilds(TripSeine bean) throws DataSourceException { + protected void loadDataInModel(String selectedId) { - RouteService service = getService(RouteService.class); - List<Route> list = service.getRouteStubByTrip(bean.getTopiaId()); + TripSeineService tripService = getService(TripSeineService.class); + TripSeine loaded = tripService.getTripSeineStub(selectedId); + TripSeine bean = getBean(); + tripService.copyStubForDisplay(loaded, bean); + + RouteService routeService = getService(RouteService.class); + List<Route> routes = routeService.getRouteStubByTrip(selectedId); if (log.isDebugEnabled()) { - log.debug("Will use " + list.size() + " routes."); + log.debug("Will use " + routes.size() + " routes."); } - return list; + bean.setRoute(routes); + + getModel().setData(routes); } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java index 149a47a..3802775 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java @@ -27,6 +27,7 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.data.seine.TripSeineService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; import org.apache.commons.logging.Log; @@ -88,16 +89,22 @@ public class TripSeinesUIHandler extends ContentListUIHandler<Program, TripSeine } @Override - protected List<TripSeine> getChilds(Program bean) throws DataSourceException { + protected void loadDataInModel(String selectedId) { - TripSeineService service = getService(TripSeineService.class); - List<TripSeine> list = service.getTripSeineStubByProgram(bean.getTopiaId()); + ReferentialService service = getService(ReferentialService.class); + Program loaded = service.loadAndDecorate(Program.class, selectedId); + Program bean = getBean(); + service.copyProgramForDisplay(loaded, bean); + + TripSeineService tripService = getService(TripSeineService.class); + List<TripSeine> tripSeines = tripService.getTripSeineStubByProgram(bean.getTopiaId()); if (log.isDebugEnabled()) { - log.debug("Will use " + list.size() + " trips."); + log.debug("Will use " + tripSeines.size() + " trips."); } - return list; + getModel().setData(tripSeines); } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit c98c3c3387e40c9dfaa5b777e56cdef36a00ad83 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Apr 27 15:40:56 2015 +0200 refactor save action for seine Conflicts: observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java --- .../services/data/seine/ActivitySeineService.java | 2 +- .../data/seine/ActivitySeineServiceImpl.java | 60 ++++++-------- .../services/data/seine/FloatingObjectService.java | 2 +- .../data/seine/FloatingObjectServiceImpl.java | 47 ++++------- .../observe/services/data/seine/RouteService.java | 2 +- .../services/data/seine/RouteServiceImpl.java | 92 +++++++++------------- .../services/data/seine/SetSeineService.java | 2 +- .../services/data/seine/SetSeineServiceImpl.java | 51 +++++------- .../impl/seine/FloatingObjectUIHandler.java | 4 +- .../ui/content/impl/seine/SetSeineUIHandler.java | 4 +- .../open/impl/seine/ActivitySeineUIHandler.java | 10 +-- .../ui/content/open/impl/seine/RouteUIHandler.java | 4 +- 12 files changed, 109 insertions(+), 171 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java index 113d897..6278b0b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java @@ -31,7 +31,7 @@ public interface ActivitySeineService extends ObserveService { ActivitySeine preCreate(String tripLonglineId); @Commit - ActivitySeine save(String routeId, ActivitySeine toSave); + String save(String routeId, ActivitySeine toSave); @Commit ActivitySeine updateObservedSystem(ActivitySeine toUpdate); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 5fe7977..59e4265 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -159,24 +159,36 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } + @Override - public ActivitySeine save(String routeId, ActivitySeine toSave) { + public String save(String routeId, ActivitySeine toSave) { + String activitySeineId = doSave(routeId, toSave, new SaveAction<Route, ActivitySeine>(Route.class, ActivitySeine.class) { - ActivitySeine saved; + @Override + public ActivitySeine onCreate(Route parent, ActivitySeine toCreate) { - if (toSave.getTopiaId() == null) { + ActivitySeine created = getDao().create(); + getBinderForEdit().copy(toCreate, created); - // create - saved = create(routeId, toSave); + parent.addActivitySeine(created); + return created; + } - } else { + @Override + public ActivitySeine onUpdate(Route parent, ActivitySeine toUpdate, ActivitySeine updated) { + Date d = DateUtil.getDateAndTime(parent.getDate(), toUpdate.getTime(), false, false); - // update - saved = update(routeId, toSave); + toUpdate.setTime(d); - } + getBinderForEdit().copyExcluding(toUpdate, updated, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_FLOATING_OBJECT); - return saved; + return updated; + } + }); + + return activitySeineId; } @@ -276,34 +288,6 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } - protected ActivitySeine create(String routeId, ActivitySeine toCreate) { - - ActivitySeineDAO dao = getDao(); - ActivitySeine created = dao.create(toCreate); - - Route route = findByTopiaId(Route.class, routeId); - route.addActivitySeine(created); - - return created; - - } - - protected ActivitySeine update(String routeId, ActivitySeine toUpdate) { - - Route route = findByTopiaId(Route.class, routeId); - Date d = DateUtil.getDateAndTime(route.getDate(), toUpdate.getTime(), false, false); - - toUpdate.setTime(d); - - ActivitySeineDAO dao = getDao(); - ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); - getBinderForEdit().copyExcluding(toUpdate, updated, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_FLOATING_OBJECT); - return updated; - - } - protected ActivitySeineDAO getDao() { return (ActivitySeineDAO) getDao(ActivitySeine.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java index 80e7225..c9dec98 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java @@ -28,7 +28,7 @@ public interface FloatingObjectService extends ObserveService { FloatingObject preCreate(String activitySeineId); @Commit - FloatingObject save(String activitySeineId, FloatingObject toSave); + String save(String activitySeineId, FloatingObject toSave); @Commit FloatingObject updateTransmittingBuoyOperation(FloatingObject toUpdate); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index ef466ec..f4e9fa4 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -71,23 +71,30 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements } @Override - public FloatingObject save(String activitySeineId, FloatingObject toSave) { + public String save(String activitySeineId, FloatingObject toSave) { - FloatingObject saved; + String floatingObjectId = doSave(activitySeineId, toSave, new SaveAction<ActivitySeine, FloatingObject>(ActivitySeine.class, FloatingObject.class) { - if (toSave.getTopiaId() == null) { + @Override + public FloatingObject onCreate(ActivitySeine parent, FloatingObject toCreate) { - // create - saved = create(activitySeineId, toSave); + FloatingObject created = getDao().create(); + getBinderForEdit().copy(toCreate, created); - } else { + parent.addFloatingObject(created); - // update - saved = update(toSave); + return created; - } + } + + @Override + public FloatingObject onUpdate(ActivitySeine parent, FloatingObject toUpdate, FloatingObject updated) { + copyForEdit(toUpdate, updated); + return updated; + } + }); - return saved; + return floatingObjectId; } @@ -247,26 +254,6 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements } - protected FloatingObject create(String activitySeineId, FloatingObject toCreate) { - - FloatingObjectDAO dao = getDao(); - FloatingObject created = dao.create(toCreate); - - ActivitySeine route = findByTopiaId(ActivitySeine.class, activitySeineId); - route.addFloatingObject(created); - - return created; - - } - - protected FloatingObject update(FloatingObject toUpdate) { - - FloatingObject updated = getDao().findByTopiaId(toUpdate.getTopiaId()); - copyForEdit(toUpdate, updated); - return updated; - - } - protected FloatingObjectDAO getDao() { return (FloatingObjectDAO) getDao(FloatingObject.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java index b968807..6dbd6ff 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java @@ -27,7 +27,7 @@ public interface RouteService extends ObserveService { Route preCreate(String tripSeineId); @Commit - Route save(String tripSeineId, Route toSave); + String save(String tripSeineId, Route toSave); @Commit void delete(String tripSeineId, String routeId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index 0333785..a7f832b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -97,27 +97,50 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer } @Override - public Route save(String tripSeineId, Route toSave) { + public String save(String tripSeineId, Route toSave) { - Route saved; + String routeId = doSave(tripSeineId, toSave, new SaveAction<TripSeine, Route>(TripSeine.class, Route.class) { - // on sauvegarde toujours en debut de jour - Date date = DateUtil.getDay(toSave.getDate()); - toSave.setDate(date); + @Override + public Route onCreate(TripSeine parent, Route toCreate) { - if (toSave.getTopiaId() == null) { + Route created = getDao().create(); + getBinderForEdit().copy(toCreate, created); - // create - saved = create(tripSeineId, toSave); + parent.addRoute(created); - } else { + // on met a jour si necessaire la date de fin de la maree + parent.updateDateFin(); + + return created; + } - // update - saved = update(tripSeineId, toSave); + @Override + public Route onUpdate(TripSeine parent, Route toUpdate, Route updated) { - } + // on conserve l'ancienne date d'observation + Date oldDate = DateUtil.getDay(toUpdate.getDate()); + + // recopie des propriétés vers le bean a sauver + getBinderForEdit().copyExcluding(toUpdate, updated, Route.PROPERTY_ACTIVITY_SEINE); + + if (!oldDate.equals(toUpdate.getDate())) { + + //FIXME Faire cela avec une requete sql, sinon ca charge trop de données + // le jour a change, il faut mettre à jour les dates des activites et des calees + updated.updateDates(); + + } + + // on met a jour si necessaire la date de fin de la maree + parent.updateDateFin(); - return saved; + return updated; + + } + }); + + return routeId; } @@ -217,49 +240,6 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer } - protected Route create(String tripSeineId, Route toCreate) { - - RouteDAO dao = getDao(); - Route created = dao.create(toCreate); - - TripSeine tripSeine = findByTopiaId(TripSeine.class, tripSeineId); - tripSeine.addRoute(created); - - // on met a jour si necessaire la date de fin de la maree - tripSeine.updateDateFin(); - - return created; - - } - - protected Route update(String tripSeineId, Route toUpdate) { - - RouteDAO dao = getDao(); - Route updated = dao.findByTopiaId(toUpdate.getTopiaId()); - - // on conserve l'ancienne date d'observation - Date oldDate = DateUtil.getDay(toUpdate.getDate()); - - // recopie des propriétés vers le bean a sauver - getBinderForEdit().copyExcluding(toUpdate, updated, Route.PROPERTY_ACTIVITY_SEINE); - - if (!oldDate.equals(toUpdate.getDate())) { - - //FIXME Faire cela avec une requete sql, sinon ca charge trop de données - // le jour a change, il faut mettre à jour les dates des activites et des calees - updated.updateDates(); - - } - - TripSeine tripSeine = findByTopiaId(TripSeine.class, tripSeineId); - - // on met a jour si necessaire la date de fin de la maree - tripSeine.updateDateFin(); - - return updated; - - } - protected RouteDAO getDao() { return (RouteDAO) getDao(Route.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java index b646c2e..9d86f50 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java @@ -25,7 +25,7 @@ public interface SetSeineService extends ObserveService { SetSeine preCreate(String routeId, String activitySeineId); @Commit - SetSeine save(String activitySeineId, SetSeine toSave); + String save(String activitySeineId, SetSeine toSave); @Commit void delete(String activitySeineId, String setSeineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java index e012079..cc31a3d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java @@ -93,24 +93,33 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe } @Override - public SetSeine save(String activitySeineId, SetSeine toSave) { + public String save(String activitySeineId, SetSeine toSave) { - SetSeine saved; + String setSeineId = doSave(activitySeineId, toSave, new SaveAction<ActivitySeine, SetSeine>(ActivitySeine.class, SetSeine.class) { - if (toSave.getTopiaId() == null) { + @Override + public SetSeine onCreate(ActivitySeine parent, SetSeine toCreate) { - // create - saved = create(activitySeineId, toSave); + SetSeine created = getDao().create(); + getBinderForEdit().copy(toCreate, created); - } else { + parent.setSetSeine(created); - // update - saved = update(toSave); + return created; + } - } + @Override + public SetSeine onUpdate(ActivitySeine parent, SetSeine toUpdate, SetSeine updated) { - return saved; + getBinderForEdit().copyExcluding(toUpdate, updated, + SetSeine.PROPERTY_TARGET_SAMPLE, + SetSeine.PROPERTY_NON_TARGET_SAMPLE); + return updated; + } + }); + + return setSeineId; } @@ -181,26 +190,4 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe return (SetSeineDAO) getDao(SetSeine.class); } - protected SetSeine create(String activitySeineId, SetSeine toCreate) { - - SetSeineDAO dao = getDao(); - SetSeine created = dao.create(toCreate); - - ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); - activitySeine.setSetSeine(created); - - return created; - - } - - protected SetSeine update(SetSeine toUpdate) { - - SetSeine updated = getDao().findByTopiaId(toUpdate.getTopiaId()); - getBinderForEdit().copyExcluding(toUpdate, updated, - SetSeine.PROPERTY_TARGET_SAMPLE, - SetSeine.PROPERTY_NON_TARGET_SAMPLE); - return updated; - - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java index 0ef7e26..cec5c6c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java @@ -162,8 +162,8 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { String activityId = getSelectedParentId(); FloatingObjectService service = getService(FloatingObjectService.class); - FloatingObject saved = service.save(activityId, bean); - service.copyForEdit(saved, bean); + String savedId = service.save(activityId, bean); + bean.setTopiaId(savedId); return true; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java index 4bb3643..904c177 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java @@ -242,8 +242,8 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { String activityId = getSelectedParentId(); SetSeineService service = getService(SetSeineService.class); - SetSeine saved = service.save(activityId, bean); - bean.setTopiaId(saved.getTopiaId()); + String savedId = service.save(activityId, bean); + bean.setTopiaId(savedId); return true; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java index 9641102..10cf6ab 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java @@ -218,9 +218,9 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei t("observe.activitySeine.message.creating")); } else { addMessage(ui, - NuitonValidatorScope.INFO, - getEntityLabel(ActivitySeine.class), - t("observe.activitySeine.message.updating")); + NuitonValidatorScope.INFO, + getEntityLabel(ActivitySeine.class), + t("observe.activitySeine.message.updating")); } super.startEditUI(ActivitySeineUI.BINDING_TIME_TIME, @@ -250,8 +250,8 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei bean.setOpen(true); ActivitySeineService service = getService(ActivitySeineService.class); - ActivitySeine saved = service.save(routeId, bean); - bean.setTopiaId(saved.getTopiaId()); + String savedId = service.save(routeId, bean); + bean.setTopiaId(savedId); obtainChildPosition(bean); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java index 6bbbcc9..5f58080 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java @@ -203,8 +203,8 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { bean.setOpen(true); RouteService service = getService(RouteService.class); - Route saved = service.save(tripId, bean); - bean.setTopiaId(saved.getTopiaId()); + String savedId = service.save(tripId, bean); + bean.setTopiaId(savedId); obtainChildPosition(bean); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 0e668f8f23b68adad801c0411fb54598a3ab8315 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Apr 27 17:15:40 2015 +0200 refactor save action for longline Conflicts: observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java --- .../data/longline/ActivityLonglineService.java | 2 +- .../data/longline/ActivityLonglineServiceImpl.java | 29 ++++-- .../services/data/longline/SetLonglineService.java | 8 ++ .../data/longline/SetLonglineServiceImpl.java | 114 +++++++++++++++++++++ .../data/longline/TripLonglineService.java | 2 +- .../data/longline/TripLonglineServiceImpl.java | 56 +++++----- .../impl/longline/SetLonglineUIHandler.java | 45 +------- .../impl/longline/ActivityLonglineUIHandler.java | 4 +- .../open/impl/longline/TripLonglineUIHandler.java | 4 +- 9 files changed, 174 insertions(+), 90 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java index ed6fbfa..cebe40e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java @@ -27,7 +27,7 @@ public interface ActivityLonglineService extends ObserveService { ActivityLongline preCreate(String tripLonglineId); @Commit - ActivityLongline save(String tripLonglineId, ActivityLongline toSave); + String save(String tripLonglineId, ActivityLongline toSave); @Commit void delete(String tripLonglineId, String activityLonglineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index d25a0e2..14a8e39 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -101,23 +101,32 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } @Override - public ActivityLongline save(String tripLonglineId, ActivityLongline toSave) { + public String save(String tripLonglineId, ActivityLongline toSave) { - ActivityLongline saved; + String activityLonglineId = doSave(tripLonglineId, toSave, new SaveAction<TripLongline, ActivityLongline>(TripLongline.class, ActivityLongline.class) { - if (toSave.getTopiaId() == null) { + @Override + public ActivityLongline onCreate(TripLongline parent, ActivityLongline toCreate) { - // create - saved = create(tripLonglineId, toSave); + ActivityLongline created = getDao().create(); + getBinderForEdit().copy(toCreate, created); - } else { + parent.addActivityLongline(created); + return created; + } - // update - saved = update(toSave); + @Override + public ActivityLongline onUpdate(TripLongline parent, ActivityLongline toUpdate, ActivityLongline updated) { - } + getBinderForEdit().copyExcluding(toUpdate, updated, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_SENSOR_USED); + + return updated; + } + }); - return saved; + return activityLonglineId; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java index 6e28f73..38f574b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java @@ -2,7 +2,9 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -18,4 +20,10 @@ public interface SetLonglineService extends ObserveService { List<Section> getSections(String setLonglineId); + String save(String activityId, SetLongline bean); + + @NoTransaction + TopiaEntityBinder<SetLongline> getBinderForEdit(); + + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index c02e1bb..e432560 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -1,13 +1,19 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SetLonglineDAO; +import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderModelBuilder; import java.util.List; @@ -64,6 +70,114 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se } + @Override + public String save(String activityLonglineId, SetLongline toSave) { + String setLonglineId = doSave(activityLonglineId, toSave, new SaveAction<ActivityLongline, SetLongline>(ActivityLongline.class, SetLongline.class) { + + @Override + public SetLongline onCreate(ActivityLongline parent, SetLongline toCreate) { + + SetLongline created = getDao().create(); + getBinderForEdit().copy(toCreate, created); + + parent.setSetLongline(created); + + return created; + } + + @Override + public SetLongline onUpdate(ActivityLongline parent, SetLongline toUpdate, SetLongline updated) { + + getBinderForEdit().copyExcluding(toUpdate, updated, + SetLongline.PROPERTY_BAITS_COMPOSITION, + SetLongline.PROPERTY_FLOATLINES_COMPOSITION, + SetLongline.PROPERTY_HOOKS_COMPOSITION, + SetLongline.PROPERTY_BRANCHLINES_COMPOSITION, + SetLongline.PROPERTY_SECTION, + SetLongline.PROPERTY_CATCH_LONGLINE, + SetLongline.PROPERTY_MITIGATION_TYPE, + SetLongline.PROPERTY_TDR); + return updated; + + } + }); + + return setLonglineId; + } + + @Override + public TopiaEntityBinder<SetLongline> getBinderForEdit() { + TopiaEntityBinder<SetLongline> r = loadBinder("-forEdit", SetLongline.class, new CreateBinder<SetLongline>() { + + @Override + public BinderModelBuilder<SetLongline, SetLongline> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<SetLongline, SetLongline> builder = binderService.newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_COMMENT, + + // setting tab + SetLongline.PROPERTY_HOME_ID, + SetLongline.PROPERTY_NUMBER, + + SetLongline.PROPERTY_SETTING_START_TIME_STAMP, + SetLongline.PROPERTY_SETTING_START_QUADRANT, + SetLongline.PROPERTY_SETTING_START_LATITUDE, + SetLongline.PROPERTY_SETTING_START_LONGITUDE, + + SetLongline.PROPERTY_SETTING_END_TIME_STAMP, + SetLongline.PROPERTY_SETTING_END_QUADRANT, + SetLongline.PROPERTY_SETTING_END_LATITUDE, + SetLongline.PROPERTY_SETTING_END_LONGITUDE, + + // setting caracteristics tab + SetLongline.PROPERTY_SETTING_SHAPE, + SetLongline.PROPERTY_LINE_TYPE, + SetLongline.PROPERTY_LIGHTSTICKS_TYPE, + SetLongline.PROPERTY_LIGHTSTICKS_COLOR, + SetLongline.PROPERTY_SETTING_VESSEL_SPEED, + SetLongline.PROPERTY_MAX_DEPTH_TARGETED, + SetLongline.PROPERTY_SHOOTER_USED, + SetLongline.PROPERTY_SHOOTER_SPEED, + SetLongline.PROPERTY_WEIGHTED_SWIVEL, + SetLongline.PROPERTY_SWIVEL_WEIGHT, + SetLongline.PROPERTY_WEIGHTED_SNAP, + SetLongline.PROPERTY_SNAP_WEIGHT, + SetLongline.PROPERTY_MONITORED, + SetLongline.PROPERTY_TIME_BETWEEN_HOOKS, + SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, + SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT, + SetLongline.PROPERTY_LIGHTSTICKS_PER_BASKET_COUNT, + SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, + SetLongline.PROPERTY_TOTAL_BASKETS_COUNT, + SetLongline.PROPERTY_TOTAL_HOOKS_COUNT, + + // hauling tab + SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, + + SetLongline.PROPERTY_HAULING_START_QUADRANT, + SetLongline.PROPERTY_HAULING_START_LATITUDE, + SetLongline.PROPERTY_HAULING_START_LONGITUDE, + SetLongline.PROPERTY_HAULING_START_TIME_STAMP, + + SetLongline.PROPERTY_HAULING_END_QUADRANT, + SetLongline.PROPERTY_HAULING_END_LATITUDE, + SetLongline.PROPERTY_HAULING_END_LONGITUDE, + SetLongline.PROPERTY_HAULING_END_TIME_STAMP, + + SetLongline.PROPERTY_HAULING_BREAKS); + + // on ajoute la recopie de l'association route + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); + + return builder; + } + + }); + + return r; + } + protected SetLonglineDAO getDao() { return (SetLonglineDAO) getDao(SetLongline.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java index 28b8255..510b6ac 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java @@ -27,7 +27,7 @@ public interface TripLonglineService extends ObserveService { TripLongline preCreate(String programId); @Commit - TripLongline save(TripLongline toSave); + String save(TripLongline toSave); @Commit void delete(String tripLonglineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index 215c5d8..5a6501d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -87,29 +87,36 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T } @Override - public TripLongline save(TripLongline toSave) { + public String save(TripLongline toSave) { - Date startDate = DateUtil.getDay(toSave.getStartDate()); - toSave.setStartDate(startDate); + String tripLonglineId = doSave(null, toSave, new SaveAction<Program, TripLongline>(Program.class, TripLongline.class) { - // mise a jour de la date de fin - toSave.updateDateFin(); - - TripLongline saved; - - if (toSave.getTopiaId() == null) { + @Override + public void beforeSave(String parentId, TripLongline toSave) { + super.beforeSave(parentId, toSave); + Date startDate = DateUtil.getDay(toSave.getStartDate()); + toSave.setStartDate(startDate); - // create - saved = create(toSave); + // mise a jour de la date de fin + toSave.updateDateFin(); - } else { + } - // update - saved = update(toSave); + @Override + public TripLongline onCreate(Program parent, TripLongline toCreate) { + TripLongline created = getDao().create(); + getBinderForEdit().copy(toCreate, created); + return created; + } - } + @Override + public TripLongline onUpdate(Program parentBean, TripLongline toUpdate, TripLongline updated) { + getBinderForEdit().copyExcluding(toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + return updated; + } + }); - return saved; + return tripLonglineId; } @@ -201,23 +208,6 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T } - protected TripLongline create(TripLongline toCreate) { - - TripLonglineDAO dao = getDao(); - TripLongline created = dao.create(toCreate); - return created; - - } - - protected TripLongline update(TripLongline toUpdate) { - - TripLonglineDAO dao = getDao(); - TripLongline updated = dao.findByTopiaId(toUpdate.getTopiaId()); - getBinderForEdit().copyExcluding(toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); - return updated; - - } - protected TripLonglineDAO getDao() { return (TripLonglineDAO) getDao(TripLongline.class); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java index 54f8c65..11414a1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java @@ -30,6 +30,7 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.content.ContentUIModel; @@ -374,48 +375,10 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { String activityId = getSelectedParentId(); - if (bean.getTopiaId() == null) { - - dataService.create(dataSource, activityId, bean, binder, getCreateExecutor()); - - } else { - - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - } - + SetLonglineService service = getService(SetLonglineService.class); + String savedId = service.save(activityId, bean); + bean.setTopiaId(savedId); return true; - - } - - @Override - protected SetLongline onCreate(TopiaContext tx, Object parent, SetLongline editBean) throws TopiaException { - - ActivityLongline parentBean = (ActivityLongline) parent; - SetLongline beanToSave = ObserveDAOHelper.getSetLonglineDAO(tx).create(); - editBean.setTopiaId(beanToSave.getTopiaId()); - parentBean.setSetLongline(beanToSave); - return beanToSave; - - } - - @Override - protected SetLongline onUpdate(TopiaContext tx, - Object parentBean, - SetLongline beanToSave) throws TopiaException { - - getLoadBinder().copyExcluding(getBean(), - beanToSave, - SetLongline.PROPERTY_BAITS_COMPOSITION, - SetLongline.PROPERTY_FLOATLINES_COMPOSITION, - SetLongline.PROPERTY_HOOKS_COMPOSITION, - SetLongline.PROPERTY_BRANCHLINES_COMPOSITION, - SetLongline.PROPERTY_SECTION, - SetLongline.PROPERTY_CATCH_LONGLINE, - SetLongline.PROPERTY_MITIGATION_TYPE, - SetLongline.PROPERTY_TDR); - return beanToSave; - } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java index 7938b31..ef7ce2c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java @@ -206,8 +206,8 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity bean.setOpen(true); ActivityLonglineService service = getService(ActivityLonglineService.class); - ActivityLongline saved = service.save(tripId, bean); - bean.setTopiaId(saved.getTopiaId()); + String savedId = service.save(tripId, bean); + bean.setTopiaId(savedId); obtainChildPosition(bean); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java index 83985f0..0bbc283 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java @@ -229,8 +229,8 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline bean.setOpen(true); TripLonglineService service = getService(TripLonglineService.class); - TripLongline saved = service.save(bean); - bean.setTopiaId(saved.getTopiaId()); + String savedId = service.save(bean); + bean.setTopiaId(savedId); // recuperation de la position de la maree dans le program obtainChildPosition(bean); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit bdeaecf4a0ecd57cffb2829a3df40acf877fb1ba Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Apr 28 08:29:47 2015 +0200 refactor delete action for seine and longline --- .../observe/services/AbstractObserveService.java | 43 ++++++++++++++++++++++ .../data/longline/ActivityLonglineServiceImpl.java | 13 ++++--- .../data/longline/TripLonglineServiceImpl.java | 6 +-- .../data/seine/ActivitySeineServiceImpl.java | 12 +++--- .../services/data/seine/RouteServiceImpl.java | 18 +++++---- .../services/data/seine/TripSeineService.java | 2 +- .../services/data/seine/TripSeineServiceImpl.java | 8 +--- 7 files changed, 71 insertions(+), 31 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 7af5a7a..0e6e506 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -273,6 +273,49 @@ public abstract class AbstractObserveService implements ObserveService { } + public <P extends TopiaEntity, E extends TopiaEntity> void doDelete(String parentId, String idToDelete, DeleteAction<P, E> deleteAction) { + + P parent = null; + + if (parentId != null) { + + parent = findByTopiaId(deleteAction.parentClass, parentId); + + checkNotNullAndExistingEntity(PARENT_BEAN, parent); + } + + E toDelete = findByTopiaId(deleteAction.entityClass, idToDelete); + + checkNotNullAndExistingEntity(BEAN, toDelete); + + deleteAction.onDelete(parent, toDelete); + + if (parentId != null) { + + getDao(deleteAction.parentClass).update(parent); + } + + + } + + protected class DeleteAction<P extends TopiaEntity, E extends TopiaEntity> { + + protected final Class<P> parentClass; + + protected final Class<E> entityClass; + + public DeleteAction(Class<P> parentClass, Class<E> entityClass) { + this.parentClass = parentClass; + this.entityClass = entityClass; + } + + public void onDelete(P parent, E toDelete) { + getDao(entityClass).delete(toDelete); + } + + } + + public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index 14a8e39..8e992bc 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -132,12 +132,13 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen @Override public void delete(String tripLonglineId, String activityLonglineId) { - - ActivityLonglineDAO dao = getDao(); - ActivityLongline toDelete = dao.findByTopiaId(activityLonglineId); - - TripLongline tripLongline = findByTopiaId(TripLongline.class, tripLonglineId); - tripLongline.removeActivityLongline(toDelete); + doDelete(tripLonglineId, activityLonglineId, new DeleteAction<TripLongline, ActivityLongline>(TripLongline.class, ActivityLongline.class) { + @Override + public void onDelete(TripLongline parent, ActivityLongline toDelete) { + super.onDelete(parent, toDelete); + parent.removeActivityLongline(toDelete); + } + }); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index 5a6501d..d832799 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -122,11 +122,7 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T @Override public void delete(String tripLonglineId) { - - TripLonglineDAO dao = getDao(); - TripLongline toDelete = dao.findByTopiaId(tripLonglineId); - dao.delete(toDelete); - + doDelete(null, tripLonglineId, new DeleteAction<Program, TripLongline>(Program.class, TripLongline.class)); } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 59e4265..2dea317 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -194,12 +194,14 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements @Override public void delete(String routeId, String activitySeineId) { + doDelete(routeId, activitySeineId, new DeleteAction<Route, ActivitySeine>(Route.class, ActivitySeine.class) { + @Override + public void onDelete(Route parent, ActivitySeine toDelete) { + super.onDelete(parent, toDelete); + parent.removeActivitySeine(toDelete); - ActivitySeineDAO dao = getDao(); - ActivitySeine toDelete = dao.findByTopiaId(activitySeineId); - - Route route = findByTopiaId(Route.class, routeId); - route.removeActivitySeine(toDelete); + } + }); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index a7f832b..7fde18e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -146,16 +146,18 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer @Override public void delete(String tripSeineId, String routeId) { + doDelete(tripSeineId, routeId, new DeleteAction<TripSeine, Route>(TripSeine.class, Route.class) { + @Override + public void onDelete(TripSeine parent, Route toDelete) { + super.onDelete(parent, toDelete); - RouteDAO dao = getDao(); - Route toDelete = dao.findByTopiaId(routeId); - - TripSeine tripSeine = findByTopiaId(TripSeine.class, tripSeineId); - tripSeine.removeRoute(toDelete); - tripSeine.updateDateFin(); - - dao.delete(toDelete); + // suppression de la route + parent.removeRoute(toDelete); + // mise à jour de la date de fin de marée + parent.updateDateFin(); + } + }); } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java index bbc6fd1..4ba8a05 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java @@ -30,7 +30,7 @@ public interface TripSeineService extends ObserveService { String save(TripSeine toSave); @Commit - void delete(String tripSeineId); + void delete(String idToDelete); @NoTransaction TopiaEntityBinder<TripSeine> getBinderForEdit(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index 985bd35..b092415 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -124,12 +124,8 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip } @Override - public void delete(String tripSeineId) { - - TripSeineDAO dao = getDao(); - TripSeine toDelete = dao.findByTopiaId(tripSeineId); - dao.delete(toDelete); - + public void delete(String idtoDelete) { + doDelete(null, idtoDelete, new DeleteAction<Program, TripSeine>(Program.class, TripSeine.class)); } @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit ea291d359521f79ccea2bdc89c0d357fe4c3b0f4 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Apr 28 17:34:37 2015 +0200 refactor save action for table entities --- .../observe/services/AbstractObserveService.java | 74 ++++++++- .../ird/observe/services/data/TripServiceImpl.java | 4 +- .../services/data/seine/TargetSampleService.java | 12 +- .../data/seine/TargetSampleServiceImpl.java | 176 +++++++++++++++++++-- .../table/impl/seine/TargetSampleUIHandler.java | 99 ++---------- 5 files changed, 270 insertions(+), 95 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 0e6e506..807403a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -14,6 +14,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -272,7 +273,6 @@ public abstract class AbstractObserveService implements ObserveService { public abstract E onUpdate(P parentBean, E toSave, E beanToSave); } - public <P extends TopiaEntity, E extends TopiaEntity> void doDelete(String parentId, String idToDelete, DeleteAction<P, E> deleteAction) { P parent = null; @@ -315,6 +315,78 @@ public abstract class AbstractObserveService implements ObserveService { } + public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, Collection<E> childrentoSave, SaveCollectionAction<P, E> saveCollectionAction ) { + + saveCollectionAction.prepareSave(parentToSave, childrentoSave); + + P parentSaved = getDao(saveCollectionAction.parentClass).findByTopiaId(parentToSave.getTopiaId()); + + List<E> oldChilds = new ArrayList<E>(saveCollectionAction.getChildren(parentSaved)); + + saveCollectionAction.clearChildren(parentSaved); + + TopiaDAO<E> dao = getDao(saveCollectionAction.entityClass); + + for (E childToSave : childrentoSave) { + + E childSaved; + + if (childToSave.getTopiaId() == null) { + + // creation du fils + childSaved = saveCollectionAction.onCreateChild(childToSave); + + } else { + + // mise a jour du fils + childSaved = dao.findByTopiaId(childToSave.getTopiaId()); + + childSaved = saveCollectionAction.onUpdateChild(childToSave, childSaved); + } + + saveCollectionAction.addChild(parentSaved, childSaved); + } + + // on donne la main aux implantations pour faire des traitements + // supplémentaires + saveCollectionAction.onUpdateFinalize(parentToSave, oldChilds); + + + } + + + protected abstract class SaveCollectionAction<P extends TopiaEntity, E extends TopiaEntity> { + + protected final Class<P> parentClass; + + protected final Class<E> entityClass; + + public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass) { + this.parentClass = parentClass; + this.entityClass = entityClass; + } + + public void prepareSave(P parent, Collection<E> tosaves) { + // par defaut, rien de specifique a faire avant de faire la sauvegarde + } + + public void onUpdateFinalize(P parent, Collection<E> oldChilds) throws TopiaException { + // par défaut, rien à faire + } + + + public abstract Collection<E> getChildren(P parent); + + public abstract void clearChildren(P parent); + + public abstract E onCreateChild(E childToSave); + + public abstract E onUpdateChild(E childToSave, E childSaved); + + public abstract void addChild(P parent, E child); + + } + public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java index 4a7e2c9..96a740b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java @@ -55,7 +55,7 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi Trip trip; - if (tripId.startsWith(TripSeine.class.getSimpleName())) { + if (tripId.startsWith(TripSeine.class.getName())) { trip = findByTopiaId(TripSeine.class, tripId); } else { trip = findByTopiaId(TripLongline.class, tripId); @@ -70,7 +70,7 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi Trip trip; - if (tripId.startsWith(TripSeine.class.getSimpleName())) { + if (tripId.startsWith(TripSeine.class.getName())) { trip = findByTopiaId(TripSeine.class, tripId); } else { trip = findByTopiaId(TripLongline.class, tripId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java index 84fb0e4..82fe30f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java @@ -2,7 +2,10 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.Collection; import java.util.List; @@ -17,7 +20,7 @@ public interface TargetSampleService extends ObserveService { List<Species> getAvailableEspeceForTargetSample(String setSeineId, boolean discarded); - String getTargetSampleId(String setSeineId, boolean discarded); + TargetSample getTargetSample(String setSeineId, boolean discarded); boolean canUseTargetSample(String setSeineId, boolean discarded); @@ -26,5 +29,12 @@ public interface TargetSampleService extends ObserveService { Collection<Species> speciessToDelete, List<TargetLength> tailleToDelete, boolean discarded); + @Commit + void delete(String setId, TargetSample bean); + String save(String setSeineId, TargetSample toSave, Collection<TargetLength> childrenToSave); + + TopiaEntityBinder<TargetLength> getChildBinderForEdit(); + + TopiaEntityBinder<TargetSample> getBinderForEdit(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index b9d8aaa..4b8021c 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -1,13 +1,18 @@ package fr.ird.observe.services.data.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetLengthDAO; import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.entities.seine.TargetSampleDAO; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.Collection; @@ -24,6 +29,14 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T /** Logger. */ private static final Log log = LogFactory.getLog(TargetSampleServiceImpl.class); + protected TargetSampleDAO getDao() { + return (TargetSampleDAO) getDao(TargetSample.class); + } + + protected TargetLengthDAO getChildDao() { + return (TargetLengthDAO) getDao(TargetLength.class); + } + @Override public List<Species> getAvailableEspeceForTargetSample(String setSeineId, boolean discarded) { @@ -68,11 +81,11 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T @Override - public String getTargetSampleId(String setSeineId, boolean discarded) { + public TargetSample getTargetSample(String setSeineId, boolean discarded) { SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - String targetSampleId = null; + TargetSample toLoad = null; if (!setSeine.isNonTargetSampleEmpty()) { @@ -81,19 +94,33 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T Boolean isDiscarded = targetSample.getDiscarded(); - if (discarded) { - if (isDiscarded != null && isDiscarded) { - targetSampleId = targetSample.getTopiaId(); - } - } else if (isDiscarded == null || !isDiscarded) { - targetSampleId = targetSample.getTopiaId(); + if (discarded == (isDiscarded != null && isDiscarded)) { + toLoad = targetSample; } } } - return targetSampleId; + TargetSample loaded = getDao().newInstance(); + + if (toLoad != null) { + + getBinderForEdit().copy(toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); + + for (TargetLength childToLoad : toLoad.getTargetLength()) { + + TargetLength childLoaded = getChildDao().newInstance(); + + getChildBinderForEdit().copy(childToLoad, childLoaded); + + loaded.addTargetLength(childLoaded); + + } + } + + + return loaded; } @@ -139,4 +166,135 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } + @Override + public void delete(String setId, TargetSample bean) { + doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { + @Override + public void onDelete(SetSeine parent, TargetSample toDelete) { + super.onDelete(parent, toDelete); + parent.removeTargetSample(toDelete); + } + }); + + } + + @Override + public String save(String setSeineId, TargetSample toSave, Collection<TargetLength> childrenToSave) { + + String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { + @Override + public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { + + TargetSample created = getDao().create(); + getBinderForEdit().copyExcluding(toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); + parent.addTargetSample(created); + getDao().update(created); + return created; + } + + @Override + public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { + getBinderForEdit().copyExcluding(toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); + getDao().update(beanToSave); + return beanToSave; + } + }); + + toSave.setTopiaId(savedId); + + doSaveList(toSave, childrenToSave, new SaveCollectionAction<TargetSample, TargetLength>(TargetSample.class, TargetLength.class) { + + @Override + public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { + + for (TargetLength targetLength : tosaves) { + + // on attache a l'echantillon + targetLength.setTargetSample(parent); + } + + } + + @Override + public Collection<TargetLength> getChildren(TargetSample parent) { + return parent.getTargetLength(); + } + + @Override + public void clearChildren(TargetSample parent) { + parent.clearTargetLength(); + } + + @Override + public TargetLength onCreateChild(TargetLength childToSave) { + TargetLength childSaved = getChildDao().create(); + getChildBinderForEdit().copy(childToSave, childSaved); + getChildDao().update(childSaved); + return childSaved; + } + + @Override + public TargetLength onUpdateChild(TargetLength childToSave, TargetLength childSaved) { + getChildBinderForEdit().copy(childToSave, childSaved); + getChildDao().update(childSaved); + return childSaved; + } + + @Override + public void addChild(TargetSample parent, TargetLength child) { + parent.addTargetLength(child); + } + }); + + return savedId; + + } + + @Override + public TopiaEntityBinder<TargetLength> getChildBinderForEdit() { + TopiaEntityBinder<TargetLength> r = loadBinder("-forEdit", TargetLength.class, new CreateBinder<TargetLength>() { + + @Override + public BinderModelBuilder<TargetLength, TargetLength> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<TargetLength, TargetLength> builder = binderService.newBinderBuilder( + TargetLength.class, + TargetLength.PROPERTY_TARGET_SAMPLE, + TargetLength.PROPERTY_SPECIES, + TargetLength.PROPERTY_LENGTH, + TargetLength.PROPERTY_LENGTH_SOURCE, + TargetLength.PROPERTY_WEIGHT, + TargetLength.PROPERTY_WEIGHT_SOURCE, + TargetLength.PROPERTY_COUNT, + TargetLength.PROPERTY_MEASURE_TYPE, + TargetLength.PROPERTY_ACQUISITION_MODE); + + return builder; + } + + }); + + return r; + } + + @Override + public TopiaEntityBinder<TargetSample> getBinderForEdit() { + TopiaEntityBinder<TargetSample> r = loadBinder("-forEdit", TargetSample.class, new CreateBinder<TargetSample>() { + + @Override + public BinderModelBuilder<TargetSample, TargetSample> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<TargetSample, TargetSample> builder = binderService.newBinderBuilder( + TargetSample.class, + TargetSample.PROPERTY_TARGET_LENGTH, + TargetSample.PROPERTY_COMMENT); + + return builder; + } + + }); + + return r; + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index b1cbfb3..098aafe 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.DataService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; @@ -39,8 +38,6 @@ import fr.ird.observe.ui.content.table.ContentTableUI; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -48,7 +45,6 @@ import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -129,7 +125,8 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T String setId = dataContext.getSelectedSetId(); // on doit récupérer l'unique échantillonThon de la calée - String id = getService(TargetSampleService.class).getTargetSampleId(setId, discarded); + TargetSample targetSample = getService(TargetSampleService.class).getTargetSample(setId, discarded); + String id = targetSample == null ? null : targetSample.getTopiaId(); return id; } @@ -141,37 +138,24 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T String setId = dataContext.getSelectedSetId(); + TargetSampleService service = getService(TargetSampleService.class); + if (mode == ContentMode.UPDATE) { // on ne charge les speciess uniquement si on est en mode édition - TargetSampleService service = getService(TargetSampleService.class); + List<Species> speciesList = service.getAvailableEspeceForTargetSample(setId, discarded); getUi().getSpecies().setData(speciesList); } - // on doit récupérer l'unique échantillonThon de la calée - String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); + TargetSample beanToLoad = getService(TargetSampleService.class).getTargetSample(setId, discarded); TargetSample editBean = getBean(); - if (log.isInfoEnabled()) { - log.info(prefix + " - set id : " + setId); - log.info(prefix + " - echantillon thon id : " + id); - log.info(prefix + " - edit bean id : " + editBean.getTopiaId()); - } - - if (id == null) { + service.getBinderForEdit().copy(beanToLoad, editBean); - // l'échantillon n'existe pas encore, donc rien a faire - getLoadBinder().load(null, editBean, true); - - getModel().getChildsUpdator().setChilds(editBean, new ArrayList<TargetLength>()); - } else { - - // preparation du bean d'édition - dataService.loadEditEntity(dataSource, id, getLoadExecutor()); - } + getModel().getChildsUpdator().setChilds(editBean, beanToLoad.getTargetLength()); getModel().setMode(mode); @@ -181,80 +165,31 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T return editBean; } - @Override - protected boolean prepareSave(TargetSample bean, List<TargetLength> objets) throws DataSourceException { - - boolean withLengths = !objets.isEmpty(); - - if (withLengths) { - - if (bean.getTopiaId() == null) { - - String setId = getDataContext().getSelectedSetId(); - - // l'échantillon n'existe pas encore, il faut le créer - - if (log.isDebugEnabled()) { - log.debug("Will create targetSample " + bean + " for " + setId); - } - - getDataService().create(getDataSource(), setId, bean, null, getCreateExecutor()); - - } - - for (TargetLength targetLength : objets) { - - // on attache a l'echantillon - targetLength.setTargetSample(bean); - } - - } - return true; - - } @Override protected void doPersist(TargetSample bean, DataService dataService, DataSource dataSource) throws DataSourceException { + TargetSampleService service = getService(TargetSampleService.class); + + String setId = getDataContext().getSelectedSetId(); + if (bean.getTopiaId() != null && bean.isTargetLengthEmpty()) { // remove orphan target sample - - String setId = getDataContext().getSelectedSetId(); if (log.isInfoEnabled()) { log.info("Remove obsolete targetSample " + bean.getTopiaId() + " from Set: " + setId); } - getDataService().delete(getDataSource(), setId, bean, getDeleteExecutor()); - - } else { - // normal persist - super.doPersist(bean, dataService, dataSource); + service.delete(setId, bean); - } + } else { - } + String savedId = service.save(setId, bean, bean.getTargetLength()); - @Override - protected TargetSample onCreate(TopiaContext tx, - Object parent, - TargetSample editBean) throws TopiaException { - SetSeine parentBean = (SetSeine) parent; - TargetSample beanToSave = - ObserveDAOHelper.getTargetSampleDAO(tx).create(); - beanToSave.setDiscarded(discarded); - editBean.setTopiaId(beanToSave.getTopiaId()); - editBean.setTopiaCreateDate(beanToSave.getTopiaCreateDate()); - editBean.setTopiaVersion(beanToSave.getTopiaVersion()); - parentBean.addTargetSample(beanToSave); - return beanToSave; - } + bean.setTopiaId(savedId); - @Override - protected void onDelete(TopiaContext tx, Object parent, TargetSample beanToDelete) throws TopiaException { - SetSeine parentBean = (SetSeine) parent; - parentBean.removeTargetSample(beanToDelete); + } } @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit c9f41f3ef9d469475c65be764d6a63d0b41e39ec Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 08:49:43 2015 +0200 debut d'implantation pour les ecrans de type tableau (refs #7017) --- .../fr/ird/observe/services/EntityAssociation.java | 39 +++++++ .../data/seine/ObjectObservedSpeciesService.java | 34 ++++++ .../data/seine/ObjectSchoolEstimateService.java | 34 ++++++ .../services/data/seine/SchoolEstimateService.java | 36 +++++++ .../data/seine/SchoolEstimateServiceImpl.java | 120 +++++++++++++++++++++ .../ui/content/table/ContentTableUIHandler.java | 57 +++++++--- .../impl/seine/ObjectObservedSpeciesUIHandler.java | 22 +++- .../impl/seine/ObjectSchoolEstimateUIHandler.java | 27 +++-- .../table/impl/seine/SchoolEstimateUIHandler.java | 22 ++-- 9 files changed, 359 insertions(+), 32 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/EntityAssociation.java b/observe-services/src/main/java/fr/ird/observe/services/EntityAssociation.java new file mode 100644 index 0000000..bac1fa9 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/EntityAssociation.java @@ -0,0 +1,39 @@ +package fr.ird.observe.services; + +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Represents an entity with one of his association. + * + * Created on 4/28/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class EntityAssociation<P extends TopiaEntity, C extends TopiaEntity> { + + protected final P parentEntity; + + protected final Collection<C> childEntities; + + public EntityAssociation(P parentEntity) { + this.parentEntity = parentEntity; + this.childEntities = new ArrayList<C>(); + } + + public P getParentEntity() { + return parentEntity; + } + + public Collection<C> getChildEntities() { + return childEntities; + } + + public void addChildEntity(C entity) { + childEntities.add(entity); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java new file mode 100644 index 0000000..4d50592 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java @@ -0,0 +1,34 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.ObjectObservedSpecies; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +/** + * Created on 4/28/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ObjectObservedSpeciesService extends ObserveService { + + FloatingObject loadForEdit(String floatingObjectId); + + @Commit + void save(FloatingObject floatingObject); + + @NoTransaction + TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit(); + + @NoTransaction + void copyForEdit(FloatingObject source, FloatingObject target); + + @NoTransaction + TopiaEntityBinder<ObjectObservedSpecies> getBinderForObjectObservedSpeciesEdit(); + + @NoTransaction + void copyForEdit(ObjectObservedSpecies source, ObjectObservedSpecies target); +} \ No newline at end of file diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java new file mode 100644 index 0000000..afc6127 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java @@ -0,0 +1,34 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.ObjectSchoolEstimate; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +/** + * Created on 4/28/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ObjectSchoolEstimateService extends ObserveService { + + FloatingObject loadForEdit(String floatingObjectId); + + @Commit + void save(FloatingObject floatingObject); + + @NoTransaction + TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit(); + + @NoTransaction + void copyForEdit(FloatingObject source, FloatingObject target); + + @NoTransaction + TopiaEntityBinder<ObjectSchoolEstimate> getBinderForObjectSchoolEstimateEdit(); + + @NoTransaction + void copyForEdit(ObjectSchoolEstimate source, ObjectSchoolEstimate target); +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java new file mode 100644 index 0000000..ce72a1b --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java @@ -0,0 +1,36 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.SchoolEstimate; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.EntityAssociation; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +/** + * Created on 4/28/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface SchoolEstimateService extends ObserveService { + + SetSeine loadForEdit(String setSeineId); + + @Commit + void save(EntityAssociation<SetSeine, SchoolEstimate> setSeine); + + @NoTransaction + TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit(); + + @NoTransaction + void copyForEdit(SetSeine source, SetSeine target); + + @NoTransaction + TopiaEntityBinder<SchoolEstimate> getBinderForSchoolEstimateEdit(); + + @NoTransaction + void copyForEdit(SchoolEstimate source, SchoolEstimate target); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java new file mode 100644 index 0000000..fa2da33 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -0,0 +1,120 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.seine.SchoolEstimate; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.EntityAssociation; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/28/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class SchoolEstimateServiceImpl extends AbstractObserveService implements SchoolEstimateService { + + @Override + public SetSeine loadForEdit(String setSeineId) { + + SetSeine parentToLoad = findByTopiaId(SetSeine.class, setSeineId); + + SetSeine parentLoaded = getDao(SetSeine.class).newInstance(); + copyForEdit(parentToLoad, parentLoaded); + + if (!parentToLoad.isSchoolEstimateEmpty()) { + + TopiaDAO<SchoolEstimate> childDao = getDao(SchoolEstimate.class); + + List<SchoolEstimate> childs = new ArrayList<SchoolEstimate>(); + + for (SchoolEstimate sourceChild : parentToLoad.getSchoolEstimate()) { + + SchoolEstimate targetChild = childDao.newInstance(); + copyForEdit(sourceChild, targetChild); + childs.add(targetChild); + + } + + parentLoaded.setSchoolEstimate(childs); + + } + + return parentLoaded; + + } + + @Override + public void save(EntityAssociation<SetSeine, SchoolEstimate> setSeine) { + + } + + @Override + public TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit() { + + + TopiaEntityBinder<SetSeine> binder = loadBinder("-forSchoolEstimateEdit", SetSeine.class, new CreateBinder<SetSeine>() { + + @Override + public BinderModelBuilder<SetSeine, SetSeine> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<SetSeine, SetSeine> builder = binderService.newBinderBuilder( + SetSeine.class, + SetSeine.PROPERTY_COMMENT, SetSeine.PROPERTY_SCHOOL_ESTIMATE); + + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEdit(SetSeine source, SetSeine target) { + + getBinderForSetSeineEdit().load(source, target, true); + + } + + @Override + public TopiaEntityBinder<SchoolEstimate> getBinderForSchoolEstimateEdit() { + + TopiaEntityBinder<SchoolEstimate> binder = loadBinder("-forEdit", SchoolEstimate.class, new CreateBinder<SchoolEstimate>() { + + @Override + public BinderModelBuilder<SchoolEstimate, SchoolEstimate> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<SchoolEstimate, SchoolEstimate> builder = binderService.newBinderBuilder( + SchoolEstimate.class, + SchoolEstimate.PROPERTY_SET_SEINE, + SchoolEstimate.PROPERTY_SPECIES, + SchoolEstimate.PROPERTY_TOTAL_WEIGHT, + SchoolEstimate.PROPERTY_MEAN_WEIGHT); + + return builder; + + } + + }); + + return binder; + + } + + @Override + public void copyForEdit(SchoolEstimate source, SchoolEstimate target) { + + getBinderForSchoolEstimateEdit().load(source, target, true); + + } + +} diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index 76e2783..bd2bb30 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -193,34 +193,53 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top protected abstract void initTableUI(DefaultTableCellRenderer renderer); - protected abstract String getEditBeanIdToLoad(DataContext dataContext, + protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, - DataSource dataSource) throws DataSourceException; + DataSource dataSource) throws DataSourceException { + throw new IllegalStateException("Do NOT USE ME!!!"); + } protected E loadEditBean(ContentMode mode, DataContext dataContext, DataService dataService, DataSource dataSource) throws DataSourceException { - String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); + loadEditBean(); - if (id == null) { - throw new IllegalStateException("Could not find id form " + this); - } +// String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); +// +// if (id == null) { +// throw new IllegalStateException("Could not find id form " + this); +// } +// +// // preparation du bean d'édition +// dataService.loadEditEntity(dataSource, id, getLoadExecutor()); + +// getModel().setMode(mode); +// +// // initialisation du modèle du tableau +// getUi().getTableModel().attachModel(); E editBean = getBean(); + return editBean; - // preparation du bean d'édition - dataService.loadEditEntity(dataSource, id, getLoadExecutor()); + } - getModel().setMode(mode); + //FIXME Rendre cette methode abstract + protected void loadEditBean() throws DataSourceException { - // initialisation du modèle du tableau - getUi().getTableModel().attachModel(); + String id = getEditBeanIdToLoad(getDataContext(), getDataService(), getDataSource()); + + if (id == null) { + throw new IllegalStateException("Could not find id form " + this); + } + + // preparation du bean d'édition + getDataService().loadEditEntity(getDataSource(), id, getLoadExecutor()); - return editBean; } + //FIXME A supprimer @Override protected final void onLoad(TopiaContext tx, E bean) throws TopiaException { super.onLoad(tx, bean); @@ -234,6 +253,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top getModel().getChildsUpdator().setChilds(editBean, data); } + //FIXME A supprimer protected Collection<D> loadChilds(TopiaContext tx, E bean) throws TopiaException { Collection<D> childs = getModel().getChildsUpdator().getChilds(bean); Collection<D> data = new ArrayList<D>(); @@ -290,6 +310,10 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top Species2.newSpeciesByIdPredicate(speciesIds)); } + protected void loadTableEditBeanForm(ContentMode mode) { + // par defaut, rien à faire + } + @Override public void openUI() throws Exception { @@ -307,6 +331,15 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top // chargement du bean d'édition loadEditBean(mode, getDataContext(), getDataService(), getDataSource()); + // chargement de l'écran d'édition + loadTableEditBeanForm(mode); + + // enregistrement du mode de l'écran + getModel().setMode(mode); + + // initialisation du modèle du tableau + getUi().getTableModel().attachModel(); + boolean canEdit = mode == ContentMode.UPDATE; if (canEdit) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index 9bbbd05..e1e7460 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -21,15 +21,14 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.seine.SpeciesStatus; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectObservedSpecies; +import fr.ird.observe.services.data.seine.ObjectObservedSpeciesService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; @@ -60,10 +59,23 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedFloatingObjectId(); + protected void loadEditBean() throws DataSourceException { + + String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); + + ObjectObservedSpeciesService service = getService(ObjectObservedSpeciesService.class); + + FloatingObject loaded = service.loadForEdit(floatingObjectId); + + service.copyForEdit(loaded, getBean()); + } +// @Override +// protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { +// return dataContext.getSelectedFloatingObjectId(); +// } + @Override protected void onSelectedRowChanged(int editingRow, ObjectObservedSpecies bean, boolean create) { if (log.isDebugEnabled()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java index 4823b5e..542486d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java @@ -21,14 +21,13 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectSchoolEstimate; +import fr.ird.observe.services.data.seine.ObjectSchoolEstimateService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; @@ -58,6 +57,20 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin return (ObjectSchoolEstimateUI) super.getUi(); } + + @Override + protected void loadEditBean() throws DataSourceException { + + String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); + + ObjectSchoolEstimateService service = getService(ObjectSchoolEstimateService.class); + + FloatingObject loaded = service.loadForEdit(floatingObjectId); + + service.copyForEdit(loaded, getBean()); + + } + @Override protected void onSelectedRowChanged(int editingRow, ObjectSchoolEstimate bean, boolean create) { if (getTableModel().isEditable()) { @@ -68,10 +81,10 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin } } - @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedFloatingObjectId(); - } +// @Override +// protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { +// return dataContext.getSelectedFloatingObjectId(); +// } @Override protected void initTableUI(DefaultTableCellRenderer renderer) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index 4cc82df..43a449c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -21,10 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Ocean; @@ -34,6 +31,7 @@ import fr.ird.observe.entities.referentiel.Species2; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.SchoolEstimateService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -74,19 +72,27 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); + protected void loadEditBean() throws DataSourceException { + + String setSeineId = getDataContext().getSelectedSetId(); + + SchoolEstimateService service = getService(SchoolEstimateService.class); + + SetSeine loaded = service.loadForEdit(setSeineId); + + service.copyForEdit(loaded, getBean()); + } @Override - protected SetSeine loadEditBean(ContentMode mode, DataContext dataContext, DataService dataService, DataSource dataSource) throws DataSourceException { + protected void loadTableEditBeanForm(ContentMode mode) { List<Species> speciesList; if (mode == ContentMode.UPDATE) { // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); // get all species from the configured speciesList ObserveConfig config = getUi().getContextValue(ObserveConfig.class); @@ -109,7 +115,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch if (log.isDebugEnabled()) { log.debug("speciesList = " + speciesList.size()); } - return super.loadEditBean(mode, dataContext, dataService, dataSource); + } @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 276980ce4bd35b799b8d67023d2ecc3f2062e5a4 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 10:16:15 2015 +0200 refactor save action for table entities (in schoolEstimate) --- .../observe/services/AbstractObserveService.java | 32 ++--- .../services/data/seine/SchoolEstimateService.java | 3 +- .../data/seine/SchoolEstimateServiceImpl.java | 46 ++++++- .../data/seine/TargetSampleServiceImpl.java | 132 ++++++++++----------- .../ui/content/table/ContentTableUIHandler.java | 33 ++++++ .../table/impl/seine/SchoolEstimateUIHandler.java | 14 +-- 6 files changed, 167 insertions(+), 93 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 807403a..c887367 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -17,6 +17,7 @@ import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.util.beans.BinderModelBuilder; @@ -315,19 +316,23 @@ public abstract class AbstractObserveService implements ObserveService { } - public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, Collection<E> childrentoSave, SaveCollectionAction<P, E> saveCollectionAction ) { + public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction ) { - saveCollectionAction.prepareSave(parentToSave, childrentoSave); + Collection<E> childrenToSave = saveCollectionAction.listUpdator.getChilds(parentToSave); + + saveCollectionAction.prepareSave(parentToSave, childrenToSave); P parentSaved = getDao(saveCollectionAction.parentClass).findByTopiaId(parentToSave.getTopiaId()); - List<E> oldChilds = new ArrayList<E>(saveCollectionAction.getChildren(parentSaved)); + saveCollectionAction.onUpdateParent(parentToSave, parentSaved); + + List<E> oldChilds = new ArrayList<E>(saveCollectionAction.listUpdator.getChilds(parentSaved)); - saveCollectionAction.clearChildren(parentSaved); + saveCollectionAction.listUpdator.removeAll(parentSaved); TopiaDAO<E> dao = getDao(saveCollectionAction.entityClass); - for (E childToSave : childrentoSave) { + for (E childToSave : childrenToSave) { E childSaved; @@ -344,7 +349,7 @@ public abstract class AbstractObserveService implements ObserveService { childSaved = saveCollectionAction.onUpdateChild(childToSave, childSaved); } - saveCollectionAction.addChild(parentSaved, childSaved); + saveCollectionAction.listUpdator.addToList(parentSaved, childSaved); } // on donne la main aux implantations pour faire des traitements @@ -361,12 +366,15 @@ public abstract class AbstractObserveService implements ObserveService { protected final Class<E> entityClass; - public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass) { + protected final EntityListUpdator<P, E> listUpdator; + + public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass, EntityListUpdator<P, E> listUpdator) { this.parentClass = parentClass; this.entityClass = entityClass; + this.listUpdator = listUpdator; } - public void prepareSave(P parent, Collection<E> tosaves) { + public void prepareSave(P parent, Collection<E> toSaves) { // par defaut, rien de specifique a faire avant de faire la sauvegarde } @@ -374,17 +382,11 @@ public abstract class AbstractObserveService implements ObserveService { // par défaut, rien à faire } - - public abstract Collection<E> getChildren(P parent); - - public abstract void clearChildren(P parent); + public abstract P onUpdateParent(P parentToSave, P parentSaved); public abstract E onCreateChild(E childToSave); public abstract E onUpdateChild(E childToSave, E childSaved); - - public abstract void addChild(P parent, E child); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java index ce72a1b..2b4f831 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java @@ -3,7 +3,6 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.EntityAssociation; import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -19,7 +18,7 @@ public interface SchoolEstimateService extends ObserveService { SetSeine loadForEdit(String setSeineId); @Commit - void save(EntityAssociation<SetSeine, SchoolEstimate> setSeine); + void save(SetSeine parent); @NoTransaction TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java index fa2da33..a7b0afa 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -4,12 +4,13 @@ import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.EntityAssociation; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -51,14 +52,44 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements } @Override - public void save(EntityAssociation<SetSeine, SchoolEstimate> setSeine) { + public void save(SetSeine parent) { + doSaveList(parent, new SaveCollectionAction<SetSeine, SchoolEstimate>(SetSeine.class, SchoolEstimate.class, getListUpdator()) { + + @Override + public void prepareSave(SetSeine parent, Collection<SchoolEstimate> toSaves) { + for (SchoolEstimate child : toSaves) { + child.setSetSeine(parent); + } + } + + @Override + public SetSeine onUpdateParent(SetSeine parentToSave, SetSeine parentSaved) { + getBinderForSetSeineEdit().copyExcluding(parentToSave, parentSaved, SetSeine.PROPERTY_SCHOOL_ESTIMATE); + getDao(SetSeine.class).update(parentSaved); + return parentSaved; + } + + @Override + public SchoolEstimate onCreateChild(SchoolEstimate childToSave) { + SchoolEstimate childSaved = getDao(SchoolEstimate.class).newInstance(); + getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); + getDao(SchoolEstimate.class).create(childSaved); + return childSaved; + } + + @Override + public SchoolEstimate onUpdateChild(SchoolEstimate childToSave, SchoolEstimate childSaved) { + getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); + getDao(SchoolEstimate.class).update(childSaved); + return childSaved; + } + }); } @Override public TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit() { - TopiaEntityBinder<SetSeine> binder = loadBinder("-forSchoolEstimateEdit", SetSeine.class, new CreateBinder<SetSeine>() { @Override @@ -117,4 +148,13 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements } + public EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + SetSeine.class, + SchoolEstimate.class, + SetSeine.PROPERTY_SCHOOL_ESTIMATE); + } + + + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 4b8021c..5fd0a8f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -181,72 +181,72 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T @Override public String save(String setSeineId, TargetSample toSave, Collection<TargetLength> childrenToSave) { - String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { - @Override - public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { - - TargetSample created = getDao().create(); - getBinderForEdit().copyExcluding(toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); - parent.addTargetSample(created); - getDao().update(created); - return created; - } - - @Override - public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { - getBinderForEdit().copyExcluding(toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); - getDao().update(beanToSave); - return beanToSave; - } - }); - - toSave.setTopiaId(savedId); - - doSaveList(toSave, childrenToSave, new SaveCollectionAction<TargetSample, TargetLength>(TargetSample.class, TargetLength.class) { - - @Override - public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { - - for (TargetLength targetLength : tosaves) { - - // on attache a l'echantillon - targetLength.setTargetSample(parent); - } - - } - - @Override - public Collection<TargetLength> getChildren(TargetSample parent) { - return parent.getTargetLength(); - } - - @Override - public void clearChildren(TargetSample parent) { - parent.clearTargetLength(); - } - - @Override - public TargetLength onCreateChild(TargetLength childToSave) { - TargetLength childSaved = getChildDao().create(); - getChildBinderForEdit().copy(childToSave, childSaved); - getChildDao().update(childSaved); - return childSaved; - } - - @Override - public TargetLength onUpdateChild(TargetLength childToSave, TargetLength childSaved) { - getChildBinderForEdit().copy(childToSave, childSaved); - getChildDao().update(childSaved); - return childSaved; - } - - @Override - public void addChild(TargetSample parent, TargetLength child) { - parent.addTargetLength(child); - } - }); - - return savedId; +// String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { +// @Override +// public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { +// +// TargetSample created = getDao().create(); +// getBinderForEdit().copyExcluding(toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); +// parent.addTargetSample(created); +// getDao().update(created); +// return created; +// } +// +// @Override +// public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { +// getBinderForEdit().copyExcluding(toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); +// getDao().update(beanToSave); +// return beanToSave; +// } +// }); +// +// toSave.setTopiaId(savedId); +// +// doSaveList(toSave, childrenToSave, new SaveCollectionAction<TargetSample, TargetLength>(TargetSample.class, TargetLength.class) { +// +// @Override +// public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { +// +// for (TargetLength targetLength : tosaves) { +// +// // on attache a l'echantillon +// targetLength.setTargetSample(parent); +// } +// +// } +// +// @Override +// public Collection<TargetLength> getChildren(TargetSample parent) { +// return parent.getTargetLength(); +// } +// +// @Override +// public void clearChildren(TargetSample parent) { +// parent.clearTargetLength(); +// } +// +// @Override +// public TargetLength onCreateChild(TargetLength childToSave) { +// TargetLength childSaved = getChildDao().create(); +// getChildBinderForEdit().copy(childToSave, childSaved); +// getChildDao().update(childSaved); +// return childSaved; +// } +// +// @Override +// public TargetLength onUpdateChild(TargetLength childToSave, TargetLength childSaved) { +// getChildBinderForEdit().copy(childToSave, childSaved); +// getChildDao().update(childSaved); +// return childSaved; +// } +// +// @Override +// public void addChild(TargetSample parent, TargetLength child) { +// parent.addTargetLength(child); +// } +// }); + + return null; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index bd2bb30..0d2093d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -427,11 +427,44 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top return true; } + @Override + protected boolean doSave(E bean) { + + ObserveContentTableUI<E, D> ui = getUi(); + + List<D> objets = ui.getTableModel().getData(); + + boolean canContinue; + try { + canContinue = prepareSave(bean, objets); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error(e); + } + ErrorDialogUI.showError(e); + canContinue = false; + } + if (!canContinue) { + + // l'utilisateur a choisi de ne pas sauvegarder + return false; + } + doPersist(bean); + + + return true; + } + + protected void doPersist(E bean, DataService dataService, DataSource dataSource) throws DataSourceException { // sauvegarde du bean en base dataService.update(dataSource, null, bean, getUpdateExecutor()); } + protected void doPersist(E editBean) { + + } + @Override protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index 43a449c..01b461d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -170,14 +170,14 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } @Override - protected boolean prepareSave(SetSeine editBean, List<SchoolEstimate> objets) { - - for (SchoolEstimate schoolEstimate : objets) { + protected void doPersist(SetSeine editBean) { + getService(SchoolEstimateService.class).save(editBean); + } - // on attache la set - schoolEstimate.setSetSeine(editBean); - } - return true; + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit ff7b0c06ba01573f013cf7fb764597ea858ec94e Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 11:09:26 2015 +0200 refactor save action for table entities (in ObjectSchoolEstimate) --- .../data/seine/ObjectSchoolEstimateService.java | 3 + .../seine/ObjectSchoolEstimateServiceImpl.java | 137 +++++++++++++++++++++ .../services/data/seine/SchoolEstimateService.java | 3 + .../data/seine/SchoolEstimateServiceImpl.java | 1 + .../impl/seine/ObjectSchoolEstimateUIHandler.java | 15 +++ 5 files changed, 159 insertions(+) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java index afc6127..a1e079d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.services.Commit; import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** @@ -31,4 +32,6 @@ public interface ObjectSchoolEstimateService extends ObserveService { @NoTransaction void copyForEdit(ObjectSchoolEstimate source, ObjectSchoolEstimate target); + + EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java new file mode 100644 index 0000000..34b8409 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java @@ -0,0 +1,137 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.ObjectSchoolEstimate; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService implements ObjectSchoolEstimateService { + + @Override + public FloatingObject loadForEdit(String floatingObjectId) { + + FloatingObject parentToLoad = findByTopiaId(FloatingObject.class, floatingObjectId); + + FloatingObject parentLoaded = getDao(FloatingObject.class).newInstance(); + + copyForEdit(parentToLoad, parentLoaded); + + if (!parentToLoad.isObjectSchoolEstimateEmpty()) { + + TopiaDAO<ObjectSchoolEstimate> childDao = getDao(ObjectSchoolEstimate.class); + + List<ObjectSchoolEstimate> childs = new ArrayList<ObjectSchoolEstimate>(); + + for (ObjectSchoolEstimate sourceChild : parentToLoad.getObjectSchoolEstimate()) { + + ObjectSchoolEstimate targetChild = childDao.newInstance(); + copyForEdit(sourceChild, targetChild); + childs.add(targetChild); + + } + + parentLoaded.setObjectSchoolEstimate(childs); + + } + + return parentLoaded; + } + + @Override + public void save(FloatingObject floatingObject) { + doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectSchoolEstimate>(FloatingObject.class, ObjectSchoolEstimate.class, getListUpdator()) { + + @Override + public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { + getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); + getDao(FloatingObject.class).update(parentSaved); + return parentSaved; + } + + @Override + public ObjectSchoolEstimate onCreateChild(ObjectSchoolEstimate childToSave) { + ObjectSchoolEstimate childSaved = getDao(ObjectSchoolEstimate.class).newInstance(); + getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); + getDao(ObjectSchoolEstimate.class).create(childSaved); + return childSaved; + } + + @Override + public ObjectSchoolEstimate onUpdateChild(ObjectSchoolEstimate childToSave, ObjectSchoolEstimate childSaved) { + getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); + getDao(ObjectSchoolEstimate.class).update(childSaved); + return childSaved; + } + }); + } + + @Override + public TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit() { + TopiaEntityBinder<FloatingObject> binder = loadBinder("-forObjectSchoolEstimateEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { + + @Override + public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE, + FloatingObject.PROPERTY_COMMENT); + + return builder; + + } + + }); + + return binder; + } + + @Override + public void copyForEdit(FloatingObject source, FloatingObject target) { + getBinderForFloatingObjectEdit().load(source, target, true); + } + + @Override + public TopiaEntityBinder<ObjectSchoolEstimate> getBinderForObjectSchoolEstimateEdit() { + TopiaEntityBinder<ObjectSchoolEstimate> binder = loadBinder("-forEdit", ObjectSchoolEstimate.class, new CreateBinder<ObjectSchoolEstimate>() { + + @Override + public BinderModelBuilder<ObjectSchoolEstimate, ObjectSchoolEstimate> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<ObjectSchoolEstimate, ObjectSchoolEstimate> builder = binderService.newBinderBuilder( + ObjectSchoolEstimate.class, + ObjectSchoolEstimate.PROPERTY_SPECIES, + ObjectSchoolEstimate.PROPERTY_TOTAL_WEIGHT); + + return builder; + + } + + }); + + return binder; + } + + @Override + public void copyForEdit(ObjectSchoolEstimate source, ObjectSchoolEstimate target) { + getBinderForObjectSchoolEstimateEdit().load(source, target, true); + } + + @Override + public EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + FloatingObject.class, + ObjectSchoolEstimate.class, + FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java index 2b4f831..9be981c 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** @@ -32,4 +33,6 @@ public interface SchoolEstimateService extends ObserveService { @NoTransaction void copyForEdit(SchoolEstimate source, SchoolEstimate target); + EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator(); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java index a7b0afa..9509a8d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -148,6 +148,7 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements } + @Override public EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { return EntityListUpdator.newEntityListUpdator( SetSeine.class, diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java index 542486d..853fb15 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java @@ -111,4 +111,19 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin super.initUI(); } + + @Override + protected void doPersist(FloatingObject editBean) { + getService(ObjectSchoolEstimateService.class).save(editBean); + } + + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + + + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 38b1f3c4eddeb63e06378d10324625c953e45a34 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 11:22:11 2015 +0200 ajout des binders (longline model) dans le binder service (refs #7017) --- .../main/java/fr/ird/observe/BinderService.java | 543 ++++++++++++++++++++- .../observe/services/AbstractObserveService.java | 20 + .../ird/observe/ui/content/ContentUIHandler.java | 16 + 3 files changed, 575 insertions(+), 4 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index ec23806..30579ea 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -21,9 +21,25 @@ */ package fr.ird.observe; +import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.entities.longline.BaitsComposition; +import fr.ird.observe.entities.longline.Branchline; +import fr.ird.observe.entities.longline.BranchlinesComposition; +import fr.ird.observe.entities.longline.CatchLongline; +import fr.ird.observe.entities.longline.Encounter; +import fr.ird.observe.entities.longline.FloatlinesComposition; +import fr.ird.observe.entities.longline.GearUseFeaturesLongline; +import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; +import fr.ird.observe.entities.longline.HooksComposition; +import fr.ird.observe.entities.longline.SensorUsed; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.entities.longline.Tdr; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.seine.TripSeine; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; +import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderModelBuilder; /** @@ -34,7 +50,526 @@ import org.nuiton.util.beans.BinderModelBuilder; */ public class BinderService { - public <E extends TopiaEntity> BinderModelBuilder<E, E> newBinderBuilder(Class<E> type, String... properties) { + public static final String DISPLAY = "display"; + + public static final String EDIT = "edit"; + + public static final String EDIT_BAITS_COMPOSITION = "editBaitsComposition"; + + public static final String EDIT_CATCH_LONGLINE = "editCatchLongline"; + + public static final String EDIT_BRANCHLINES_COMPOSITION = "editBranchlinesComposition"; + + public static final String EDIT_ENCOUNTER = "editEncounter"; + + public static final String EDIT_FLOATLINES_COMPOSITION = "editFloatlinesComposition"; + + public static final String EDIT_GEAR_USE_FEATURES_LONGLINE = "editGearUseFeaturesLongline"; + + public static final String EDIT_HOOKS_COMPOSITION = "editHooksComposition"; + + public static final String EDIT_SENSOR_USED = "editSensorUsed"; + + public static final String EDIT_TDR = "editTdr"; + + + static { + + registerBinders(); + + } + + private static void registerBinders() { + + { + + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_QUADRANT, + ActivityLongline.PROPERTY_LATITUDE, + ActivityLongline.PROPERTY_LONGITUDE, + ActivityLongline.PROPERTY_TIME_STAMP, + ActivityLongline.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivityLongline.PROPERTY_COMMENT, + ActivityLongline.PROPERTY_SET_LONGLINE, + ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, + ActivityLongline.PROPERTY_FPA_ZONE, + ActivityLongline.PROPERTY_OPEN, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_SENSOR_USED); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_ENCOUNTER); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_SENSOR_USED); + + registerTopiaBinder(ActivityLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_BAITS_COMPOSITION); + + registerTopiaBinder(SetLongline.class, builder, EDIT_BAITS_COMPOSITION); + + } + + { + + BinderModelBuilder<BaitsComposition, BaitsComposition> builder = newBinderBuilder( + BaitsComposition.class, + BaitsComposition.PROPERTY_BAIT_TYPE, + BaitsComposition.PROPERTY_BAIT_SETTING_STATUS, + BaitsComposition.PROPERTY_INDIVIDUAL_SIZE, + BaitsComposition.PROPERTY_INDIVIDUAL_WEIGHT, + BaitsComposition.PROPERTY_PROPORTION); + + registerTopiaBinder(BaitsComposition.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_BRANCHLINES_COMPOSITION); + + registerTopiaBinder(SetLongline.class, builder, EDIT_BRANCHLINES_COMPOSITION); + + } + + { + + BinderModelBuilder<BranchlinesComposition, BranchlinesComposition> builder = newBinderBuilder( + BranchlinesComposition.class, + BranchlinesComposition.PROPERTY_TOP_TYPE, + BranchlinesComposition.PROPERTY_TRACELINE_TYPE, + BranchlinesComposition.PROPERTY_LENGTH, + BranchlinesComposition.PROPERTY_PROPORTION); + + registerTopiaBinder(BranchlinesComposition.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_CATCH_LONGLINE); + + registerTopiaBinder(SetLongline.class, builder, EDIT_CATCH_LONGLINE); + + } + + + { + + BinderModelBuilder<CatchLongline, CatchLongline> builder = newBinderBuilder( + CatchLongline.class, + CatchLongline.PROPERTY_SPECIES_CATCH, + CatchLongline.PROPERTY_ACQUISITION_MODE, + CatchLongline.PROPERTY_COUNT, + CatchLongline.PROPERTY_CATCH_HEALTHNESS, + CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, + CatchLongline.PROPERTY_DISCARD_HEALTHNESS, + CatchLongline.PROPERTY_DEPREDATED, + CatchLongline.PROPERTY_NUMBER, + CatchLongline.PROPERTY_HOME_ID, + CatchLongline.PROPERTY_HOOK_POSITION, + CatchLongline.PROPERTY_HOOK_WHEN_DISCARDED, + CatchLongline.PROPERTY_MATURITY_STATUS, + CatchLongline.PROPERTY_PHOTO_REFERENCES, + CatchLongline.PROPERTY_SEX, + CatchLongline.PROPERTY_PREDATOR, + CatchLongline.PROPERTY_STOMAC_FULLNESS, + CatchLongline.PROPERTY_TOTAL_WEIGHT, + CatchLongline.PROPERTY_BEAT_DIAMETER, + CatchLongline.PROPERTY_GONADE_WEIGHT, + CatchLongline.PROPERTY_SECTION, + CatchLongline.PROPERTY_BASKET, + CatchLongline.PROPERTY_BRANCHLINE, + CatchLongline.PROPERTY_COMMENT); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, CatchLongline.PROPERTY_PREDATOR); + + registerTopiaBinder(CatchLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<Branchline, Branchline> builder = newBinderBuilder(Branchline.class, + Branchline.PROPERTY_DEPTH_RECORDER, + Branchline.PROPERTY_HOOK_LOST, + Branchline.PROPERTY_TRACE_CUT_OFF, + Branchline.PROPERTY_TIMER, + Branchline.PROPERTY_TIME_SINCE_CONTACT, + Branchline.PROPERTY_TIMER_TIME_ON_BOARD, + Branchline.PROPERTY_BAIT_HAULING_STATUS); + + registerTopiaBinder(Branchline.class, builder, EDIT_CATCH_LONGLINE); + + } + + { + + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_COMMENT, + ActivityLongline.PROPERTY_ENCOUNTER); + + registerTopiaBinder(ActivityLongline.class, builder, EDIT_ENCOUNTER); + + } + + { + + BinderModelBuilder<Encounter, Encounter> builder = newBinderBuilder( + Encounter.class, + Encounter.PROPERTY_SPECIES, + Encounter.PROPERTY_DISTANCE, + Encounter.PROPERTY_COUNT, + Encounter.PROPERTY_ENCOUNTER_TYPE); + + registerTopiaBinder(Encounter.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_FLOATLINES_COMPOSITION); + + registerTopiaBinder(SetLongline.class, builder, EDIT_FLOATLINES_COMPOSITION); + + } + + { + + BinderModelBuilder<FloatlinesComposition, FloatlinesComposition> builder = newBinderBuilder( + FloatlinesComposition.class, + FloatlinesComposition.PROPERTY_LINE_TYPE, + FloatlinesComposition.PROPERTY_LENGTH, + FloatlinesComposition.PROPERTY_PROPORTION); + + + registerTopiaBinder(FloatlinesComposition.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE); + + registerTopiaBinder(TripLongline.class, builder, EDIT_GEAR_USE_FEATURES_LONGLINE); + + } + + { + + BinderModelBuilder<GearUseFeaturesLongline, GearUseFeaturesLongline> builder = newBinderBuilder( + GearUseFeaturesLongline.class, + GearUseFeaturesLongline.PROPERTY_COMMENT, + GearUseFeaturesLongline.PROPERTY_GEAR, + GearUseFeaturesLongline.PROPERTY_NUMBER, + GearUseFeaturesLongline.PROPERTY_USED_IN_TRIP); + + registerTopiaBinder(GearUseFeaturesLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> builder = + newBinderBuilder(GearUseFeaturesMeasurementLongline.class, + GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, + GearUseFeaturesMeasurementLongline.PROPERTY_MEASUREMENT_VALUE); + + registerTopiaBinder(GearUseFeaturesMeasurementLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_HOOKS_COMPOSITION); + + registerTopiaBinder(SetLongline.class, builder, EDIT_HOOKS_COMPOSITION); + + } + + { + + BinderModelBuilder<HooksComposition, HooksComposition> builder = newBinderBuilder( + HooksComposition.class, + HooksComposition.PROPERTY_HOOK_TYPE, + HooksComposition.PROPERTY_HOOK_SIZE, + HooksComposition.PROPERTY_HOOK_OFFSET, + HooksComposition.PROPERTY_PROPORTION); + + registerTopiaBinder(HooksComposition.class, builder, EDIT); + + } + + { + + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_SENSOR_USED, ActivityLongline.PROPERTY_COMMENT); + + registerTopiaBinder(ActivityLongline.class, builder, EDIT_SENSOR_USED); + + } + + { + + BinderModelBuilder<SensorUsed, SensorUsed> builder = newBinderBuilder( + SensorUsed.class, + SensorUsed.PROPERTY_DATA, + SensorUsed.PROPERTY_DATA_FILENAME, + SensorUsed.PROPERTY_DATA_LOCATION, + SensorUsed.PROPERTY_SENSOR_SERIAL_NO, + SensorUsed.PROPERTY_SENSOR_TYPE, + SensorUsed.PROPERTY_SENSOR_BRAND, + SensorUsed.PROPERTY_SENSOR_DATA_FORMAT); + + registerTopiaBinder(SensorUsed.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_COMMENT, + + // setting tab + SetLongline.PROPERTY_HOME_ID, + SetLongline.PROPERTY_NUMBER, + + SetLongline.PROPERTY_SETTING_START_TIME_STAMP, + SetLongline.PROPERTY_SETTING_START_QUADRANT, + SetLongline.PROPERTY_SETTING_START_LATITUDE, + SetLongline.PROPERTY_SETTING_START_LONGITUDE, + + SetLongline.PROPERTY_SETTING_END_TIME_STAMP, + SetLongline.PROPERTY_SETTING_END_QUADRANT, + SetLongline.PROPERTY_SETTING_END_LATITUDE, + SetLongline.PROPERTY_SETTING_END_LONGITUDE, + + // setting caracteristics tab + SetLongline.PROPERTY_SETTING_SHAPE, + SetLongline.PROPERTY_LINE_TYPE, + SetLongline.PROPERTY_LIGHTSTICKS_TYPE, + SetLongline.PROPERTY_LIGHTSTICKS_COLOR, + SetLongline.PROPERTY_SETTING_VESSEL_SPEED, + SetLongline.PROPERTY_MAX_DEPTH_TARGETED, + SetLongline.PROPERTY_SHOOTER_USED, + SetLongline.PROPERTY_SHOOTER_SPEED, + SetLongline.PROPERTY_WEIGHTED_SWIVEL, + SetLongline.PROPERTY_SWIVEL_WEIGHT, + SetLongline.PROPERTY_WEIGHTED_SNAP, + SetLongline.PROPERTY_SNAP_WEIGHT, + SetLongline.PROPERTY_MONITORED, + SetLongline.PROPERTY_TIME_BETWEEN_HOOKS, + SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, + SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT, + SetLongline.PROPERTY_LIGHTSTICKS_PER_BASKET_COUNT, + SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, + SetLongline.PROPERTY_TOTAL_BASKETS_COUNT, + SetLongline.PROPERTY_TOTAL_HOOKS_COUNT, + + // hauling tab + SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, + + SetLongline.PROPERTY_HAULING_START_QUADRANT, + SetLongline.PROPERTY_HAULING_START_LATITUDE, + SetLongline.PROPERTY_HAULING_START_LONGITUDE, + SetLongline.PROPERTY_HAULING_START_TIME_STAMP, + + SetLongline.PROPERTY_HAULING_END_QUADRANT, + SetLongline.PROPERTY_HAULING_END_LATITUDE, + SetLongline.PROPERTY_HAULING_END_LONGITUDE, + SetLongline.PROPERTY_HAULING_END_TIME_STAMP, + + SetLongline.PROPERTY_HAULING_BREAKS); + + // on ajoute la recopie de l'association route + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); + + registerTopiaBinder(SetLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_TDR, + SetLongline.PROPERTY_SETTING_START_TIME_STAMP, + SetLongline.PROPERTY_SETTING_END_TIME_STAMP, + SetLongline.PROPERTY_HAULING_START_TIME_STAMP, + SetLongline.PROPERTY_HAULING_END_TIME_STAMP); + + registerTopiaBinder(SetLongline.class, builder, EDIT_TDR); + + } + + { + + BinderModelBuilder<Tdr, Tdr> builder = newBinderBuilder( + Tdr.class, + // caracteristics tab + Tdr.PROPERTY_HOME_ID, + Tdr.PROPERTY_SERIAL_NO, + Tdr.PROPERTY_SENSOR_BRAND, + Tdr.PROPERTY_DATA, + Tdr.PROPERTY_DATA_FILENAME, + Tdr.PROPERTY_DATA_LOCATION, + + // localisation tab + Tdr.PROPERTY_SECTION, + Tdr.PROPERTY_BASKET, + Tdr.PROPERTY_BRANCHLINE, + Tdr.PROPERTY_ITEM_HORIZONTAL_POSITION, + Tdr.PROPERTY_ITEM_VERTICAL_POSITION, + Tdr.PROPERTY_FLOATLINE1_LENGTH, + Tdr.PROPERTY_FLOATLINE2_LENGTH, + + // timestamp tab + Tdr.PROPERTY_DEPLOYEMENT_START, + Tdr.PROPERTY_DEPLOYEMENT_START_DATE, + Tdr.PROPERTY_DEPLOYEMENT_START_TIME, + Tdr.PROPERTY_DEPLOYEMENT_END, + Tdr.PROPERTY_DEPLOYEMENT_END_DATE, + Tdr.PROPERTY_DEPLOYEMENT_END_TIME, + Tdr.PROPERTY_FISHING_START, + Tdr.PROPERTY_FISHING_START_DATE, + Tdr.PROPERTY_FISHING_START_TIME, + Tdr.PROPERTY_FISHING_END, + Tdr.PROPERTY_FISHING_END_DATE, + Tdr.PROPERTY_FISHING_END_TIME, + + // key data tab + Tdr.PROPERTY_FISHING_START_DEPTH, + Tdr.PROPERTY_FISHING_END_DEPTH, + Tdr.PROPERTY_MEAN_DEPLOYEMENT_DEPTH, + Tdr.PROPERTY_MEDIAN_DEPLOYEMENT_DEPTH, + Tdr.PROPERTY_MEAN_FISHING_DEPTH, + Tdr.PROPERTY_MEDIAN_FISHING_DEPTH, + Tdr.PROPERTY_MIN_FISHING_DEPTH, + Tdr.PROPERTY_MAX_FISHING_DEPTH, + + // species tab + Tdr.PROPERTY_SPECIES); + + registerTopiaBinder(Tdr.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_START_DATE, + TripLongline.PROPERTY_END_DATE, + TripLongline.PROPERTY_TRIP_TYPE, + TripLongline.PROPERTY_HOME_ID, + TripLongline.PROPERTY_COMMENT, + TripLongline.PROPERTY_VESSEL, + TripLongline.PROPERTY_OBSERVER, + TripLongline.PROPERTY_CAPTAIN, + TripLongline.PROPERTY_DATA_ENTRY_OPERATOR, + TripLongline.PROPERTY_TOTAL_FISHING_OPERATIONS_NUMBER, + TripLongline.PROPERTY_OCEAN, + TripLongline.PROPERTY_DEPARTURE_HARBOUR, + TripLongline.PROPERTY_LANDING_HARBOUR, + TripLongline.PROPERTY_PROGRAM, + TripLongline.PROPERTY_ACTIVITY_LONGLINE, + TripLongline.PROPERTY_OPEN); + + // on ajoute la recopie de l'association route + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + + registerTopiaBinder(TripLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_START_DATE, + TripLongline.PROPERTY_END_DATE, + TripLongline.PROPERTY_OPEN, + TripLongline.PROPERTY_OBSERVER, + TripLongline.PROPERTY_VESSEL, + TripLongline.PROPERTY_PROGRAM); + + registerTopiaBinder(TripLongline.class, builder, DISPLAY); + + } + + { + + } + + { + + } + + { + + } + + { + + } + + { + + } + + } + + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { + + copy(type, context, source, target, true); + + } + + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { + + TopiaEntityBinder<E> binder = getBinder(type, context); + + binder.copyExcluding(source, target, propertyNames); + + } + + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { + + TopiaEntityBinder<E> binder = getBinder(type, context); + + binder.load(source, target, bindTechnical); + + } + + public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> type, String context) { + TopiaEntityBinder<E> binder = getTopiaBinder(type, context); + if (binder == null) { + throw new IllegalArgumentException("Could not find binder for " + type.getName() + "::" + context); + } + return binder; + } + + + public static <E extends TopiaEntity> BinderModelBuilder<E, E> newBinderBuilder(Class<E> type, String... properties) { BinderModelBuilder<E, E> builder = BinderModelBuilder.newEmptyBuilder(type); builder.addSimpleProperties(properties); return builder; @@ -50,9 +585,9 @@ public class BinderService { return (TopiaEntityBinder<E>) ObserveBinderHelper.newBinder(entityClass, entityClass, contextName, TopiaEntityBinder.class); } - public <E extends TopiaEntity> TopiaEntityBinder<E> registerTopiaBinder(Class<E> entityClass, - BinderModelBuilder<E, E> builder, - String contextName) { + public static <E extends TopiaEntity> TopiaEntityBinder<E> registerTopiaBinder(Class<E> entityClass, + BinderModelBuilder<E, E> builder, + String contextName) { return ObserveBinderHelper.registerTopiaBinder(entityClass, builder, contextName); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index c887367..ed7492b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -129,6 +129,26 @@ public abstract class AbstractObserveService implements ObserveService { return serviceContext.now(); } + public BinderService getBinderService() { + return serviceContext.getBinderService(); + } + + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { + getBinderService().copy(type, context, source, target); + } + + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { + getBinderService().copyExcluding(type, context, source, target, propertyNames); + } + + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { + getBinderService().copy(type, context, source, target, bindTechnical); + } + + public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> entityClass, String contextName) { + return getBinderService().getBinder(entityClass, contextName); + } + protected <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityType) { return serviceContext.getDataSource().getDAO(getTransaction(), entityType); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 3fcbcca..1354ecd 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -353,6 +353,22 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return ObserveContext.get().getBinderService(); } + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { + getBinderService().copy(type, context, source, target); + } + + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { + getBinderService().copyExcluding(type, context, source, target, propertyNames); + } + + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { + getBinderService().copy(type, context, source, target, bindTechnical); + } + + public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> type, String context) { + return getBinderService().getBinder(type, context); + } + protected DataSource getDataSource() { return ui.getDataSource(); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 2d648bff15cef6ba75509db9c37741dc5f41a998 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 11:23:26 2015 +0200 refactor save action for table entities (in ObjectObservedSpecies) --- .../data/seine/ObjectObservedSpeciesService.java | 3 + .../seine/ObjectObservedSpeciesServiceImpl.java | 138 +++++++++++++++++++++ .../impl/seine/ObjectObservedSpeciesUIHandler.java | 13 ++ 3 files changed, 154 insertions(+) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java index 4d50592..cf46428 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.services.Commit; import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** @@ -31,4 +32,6 @@ public interface ObjectObservedSpeciesService extends ObserveService { @NoTransaction void copyForEdit(ObjectObservedSpecies source, ObjectObservedSpecies target); + + EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator(); } \ No newline at end of file diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java new file mode 100644 index 0000000..e7d37c2 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java @@ -0,0 +1,138 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.ObjectObservedSpecies; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.util.beans.BinderModelBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService implements ObjectObservedSpeciesService { + @Override + public FloatingObject loadForEdit(String floatingObjectId) { + + FloatingObject parentToLoad = findByTopiaId(FloatingObject.class, floatingObjectId); + + FloatingObject parentLoaded = getDao(FloatingObject.class).newInstance(); + + copyForEdit(parentToLoad, parentLoaded); + + if (!parentToLoad.isObjectObservedSpeciesEmpty()) { + + TopiaDAO<ObjectObservedSpecies> childDao = getDao(ObjectObservedSpecies.class); + + List<ObjectObservedSpecies> childs = new ArrayList<ObjectObservedSpecies>(); + + for (ObjectObservedSpecies sourceChild : parentToLoad.getObjectObservedSpecies()) { + + ObjectObservedSpecies targetChild = childDao.newInstance(); + copyForEdit(sourceChild, targetChild); + childs.add(targetChild); + + } + + parentLoaded.setObjectObservedSpecies(childs); + + } + + return parentLoaded; + } + + @Override + public void save(FloatingObject floatingObject) { + doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectObservedSpecies>(FloatingObject.class, ObjectObservedSpecies.class, getListUpdator()) { + + @Override + public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { + getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); + getDao(FloatingObject.class).update(parentSaved); + return parentSaved; + } + + @Override + public ObjectObservedSpecies onCreateChild(ObjectObservedSpecies childToSave) { + ObjectObservedSpecies childSaved = getDao(ObjectObservedSpecies.class).newInstance(); + getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); + getDao(ObjectObservedSpecies.class).create(childSaved); + return childSaved; + } + + @Override + public ObjectObservedSpecies onUpdateChild(ObjectObservedSpecies childToSave, ObjectObservedSpecies childSaved) { + getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); + getDao(ObjectObservedSpecies.class).update(childSaved); + return childSaved; + } + }); + + } + + @Override + public TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit() { + TopiaEntityBinder<FloatingObject> binder = loadBinder("-forObjectObservedSpeciesEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { + + @Override + public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES, + FloatingObject.PROPERTY_COMMENT); + + return builder; + + } + + }); + + return binder; + } + + @Override + public void copyForEdit(FloatingObject source, FloatingObject target) { + getBinderForFloatingObjectEdit().load(source, target, true); + } + + @Override + public TopiaEntityBinder<ObjectObservedSpecies> getBinderForObjectObservedSpeciesEdit() { + TopiaEntityBinder<ObjectObservedSpecies> binder = loadBinder("-forEdit", ObjectObservedSpecies.class, new CreateBinder<ObjectObservedSpecies>() { + + @Override + public BinderModelBuilder<ObjectObservedSpecies, ObjectObservedSpecies> createBinderBuilder(BinderService binderService, String name) { + + BinderModelBuilder<ObjectObservedSpecies, ObjectObservedSpecies> builder = binderService.newBinderBuilder( + ObjectObservedSpecies.class, + ObjectObservedSpecies.PROPERTY_SPECIES, + ObjectObservedSpecies.PROPERTY_SPECIES_STATUS, + ObjectObservedSpecies.PROPERTY_COUNT); + + return builder; + + } + + }); + + return binder; + } + + @Override + public void copyForEdit(ObjectObservedSpecies source, ObjectObservedSpecies target) { + getBinderForObjectObservedSpeciesEdit().load(source, target, true); + } + + @Override + public EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + FloatingObject.class, + ObjectObservedSpecies.class, + FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); + } +} diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index e1e7460..771e474 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -115,4 +115,17 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati } + @Override + protected void doPersist(FloatingObject editBean) { + getService(ObjectObservedSpeciesService.class).save(editBean); + } + + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit acd6e76a9a408631b82a4bc6c2e82597b79985f2 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 12:07:17 2015 +0200 utilisation des binders depuis le binserService pour le moèdle LL (refs #7017) --- .../main/java/fr/ird/observe/BinderService.java | 28 ++++++- .../data/longline/ActivityLonglineService.java | 8 -- .../data/longline/ActivityLonglineServiceImpl.java | 66 +++------------ .../data/longline/BaitsCompositionService.java | 20 +++++ .../data/longline/BaitsCompositionServiceImpl.java | 61 ++++++++++++++ .../longline/BranchlinesCompositionService.java | 20 +++++ .../BranchlinesCompositionServiceImpl.java | 56 +++++++++++++ .../data/longline/CatchLonglineService.java | 20 ++--- .../data/longline/CatchLonglineServiceImpl.java | 90 +++++++++----------- .../services/data/longline/EncounterService.java | 20 +++++ .../data/longline/EncounterServiceImpl.java | 58 +++++++++++++ .../longline/FloatlinesCompositionService.java | 20 +++++ .../longline/FloatlinesCompositionServiceImpl.java | 57 +++++++++++++ .../longline/GearUseFeaturesLonglineService.java | 10 ++- .../GearUseFeaturesLonglineServiceImpl.java | 40 ++++++--- .../data/longline/HooksCompositionService.java | 20 +++++ .../data/longline/HooksCompositionServiceImpl.java | 56 +++++++++++++ .../services/data/longline/SensorUsedService.java | 20 +---- .../data/longline/SensorUsedServiceImpl.java | 55 +++++++----- .../services/data/longline/SetLonglineService.java | 6 -- .../data/longline/SetLonglineServiceImpl.java | 98 +++------------------- .../observe/services/data/longline/TdrService.java | 20 +---- .../services/data/longline/TdrServiceImpl.java | 52 +++++++----- .../data/longline/TripLonglineService.java | 13 --- .../data/longline/TripLonglineServiceImpl.java | 88 +------------------ .../ird/observe/ui/content/ContentUIHandler.java | 4 + .../impl/longline/ActivityLonglinesUIHandler.java | 4 +- .../impl/longline/ActivityLonglineUIHandler.java | 3 +- .../open/impl/longline/TripLonglineUIHandler.java | 3 +- .../impl/longline/BaitsCompositionUIHandler.java | 24 ++++-- .../longline/BranchlinesCompositionUIHandler.java | 18 ++-- .../impl/longline/CatchLonglineUIHandler.java | 63 +++++++------- .../table/impl/longline/EncounterUIHandler.java | 26 ++++-- .../longline/FloatlinesCompositionUIHandler.java | 16 ++++ .../longline/GearUseFeaturesLonglineUIHandler.java | 44 +++++----- .../longline/GearUseFeaturesLonglineUIModel.java | 5 +- .../impl/longline/HooksCompositionUIHandler.java | 16 ++++ .../table/impl/longline/SensorUsedUIHandler.java | 25 +++--- .../content/table/impl/longline/TdrUIHandler.java | 47 +++++------ 39 files changed, 755 insertions(+), 545 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 30579ea..31c1fd5 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -33,8 +33,10 @@ import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.HooksComposition; import fr.ird.observe.entities.longline.SensorUsed; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.WeightMeasure; import fr.ird.observe.entities.seine.TripSeine; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -158,9 +160,9 @@ public class BinderService { BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( SetLongline.class, SetLongline.PROPERTY_CATCH_LONGLINE); - + registerTopiaBinder(SetLongline.class, builder, EDIT_CATCH_LONGLINE); - + } @@ -215,6 +217,26 @@ public class BinderService { { + BinderModelBuilder<WeightMeasure, WeightMeasure> builder = newBinderBuilder(WeightMeasure.class, + WeightMeasure.PROPERTY_WEIGHT, + WeightMeasure.PROPERTY_WEIGHT_MEASURE_TYPE); + + registerTopiaBinder(WeightMeasure.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SizeMeasure, SizeMeasure> builder = newBinderBuilder(SizeMeasure.class, + SizeMeasure.PROPERTY_SIZE, + SizeMeasure.PROPERTY_SIZE_MEASURE_TYPE); + + registerTopiaBinder(SizeMeasure.class, builder, EDIT); + + } + + { + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( ActivityLongline.class, ActivityLongline.PROPERTY_COMMENT, @@ -535,7 +557,7 @@ public class BinderService { { } - + } public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java index cebe40e..3d640bc 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -32,10 +30,4 @@ public interface ActivityLonglineService extends ObserveService { @Commit void delete(String tripLonglineId, String activityLonglineId); - @NoTransaction - TopiaEntityBinder<ActivityLongline> getBinderForEdit(); - - @NoTransaction - void copyForEdit(ActivityLongline source, ActivityLongline target); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index 8e992bc..72406a9 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -6,9 +6,6 @@ import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.ActivityLonglineDAO; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Calendar; import java.util.Date; @@ -45,7 +42,7 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen ActivityLongline loaded = getDao().newInstance(); ActivityLongline toLoad = getDao().findByTopiaId(activityLonglineId); - copyForEdit(toLoad, loaded); + copy(ActivityLongline.class, BinderService.EDIT, toLoad, loaded); return loaded; @@ -57,7 +54,6 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } - @Override public ActivityLongline preCreate(String tripLonglineId) { @@ -109,7 +105,7 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen public ActivityLongline onCreate(TripLongline parent, ActivityLongline toCreate) { ActivityLongline created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(ActivityLongline.class, BinderService.EDIT, toCreate, created); parent.addActivityLongline(created); return created; @@ -118,9 +114,10 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen @Override public ActivityLongline onUpdate(TripLongline parent, ActivityLongline toUpdate, ActivityLongline updated) { - getBinderForEdit().copyExcluding(toUpdate, updated, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); + copyExcluding(ActivityLongline.class, BinderService.EDIT, + toUpdate, updated, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_SENSOR_USED); return updated; } @@ -142,50 +139,6 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } - @Override - public TopiaEntityBinder<ActivityLongline> getBinderForEdit() { - - TopiaEntityBinder<ActivityLongline> binder = loadBinder("-forEdit", ActivityLongline.class, new CreateBinder<ActivityLongline>() { - - @Override - public BinderModelBuilder<ActivityLongline, ActivityLongline> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<ActivityLongline, ActivityLongline> builder = binderService.newBinderBuilder( - ActivityLongline.class, - ActivityLongline.PROPERTY_QUADRANT, - ActivityLongline.PROPERTY_LATITUDE, - ActivityLongline.PROPERTY_LONGITUDE, - ActivityLongline.PROPERTY_TIME_STAMP, - ActivityLongline.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivityLongline.PROPERTY_COMMENT, - ActivityLongline.PROPERTY_SET_LONGLINE, - ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, - ActivityLongline.PROPERTY_FPA_ZONE, - ActivityLongline.PROPERTY_OPEN, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_ENCOUNTER); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_SENSOR_USED); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(ActivityLongline source, ActivityLongline target) { - - getBinderForEdit().load(source, target, true); - - } - protected ActivityLongline create(String tripLonglineId, ActivityLongline toCreate) { ActivityLonglineDAO dao = getDao(); @@ -202,9 +155,10 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen ActivityLonglineDAO dao = getDao(); ActivityLongline updated = dao.findByTopiaId(toUpdate.getTopiaId()); - getBinderForEdit().copyExcluding(toUpdate, updated, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); + copyExcluding(ActivityLongline.class, BinderService.EDIT, + toUpdate, updated, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_SENSOR_USED); return updated; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionService.java new file mode 100644 index 0000000..d066695 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionService.java @@ -0,0 +1,20 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface BaitsCompositionService extends ObserveService { + + SetLongline loadForEdit(String setLonglineId); + + @Commit + void save(SetLongline setLongline); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java new file mode 100644 index 0000000..12d8b37 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java @@ -0,0 +1,61 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.BaitsComposition; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class BaitsCompositionServiceImpl extends AbstractObserveService implements BaitsCompositionService { + + @Override + public SetLongline loadForEdit(String setLonglineId) { + + SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); + + SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); + + copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, parentToLoad, parentLoaded); + + if (!parentToLoad.isBaitsCompositionEmpty()) { + + TopiaEntityBinder<BaitsComposition> binder = getBinder(BaitsComposition.class, BinderService.EDIT); + + TopiaDAO<BaitsComposition> childDao = getDao(BaitsComposition.class); + + List<BaitsComposition> childs = new ArrayList<BaitsComposition>(); + + for (BaitsComposition sourceChild : parentToLoad.getBaitsComposition()) { + + BaitsComposition targetChild = childDao.newInstance(); + + binder.load(sourceChild, targetChild, true); + + childs.add(targetChild); + + } + + parentLoaded.setBaitsComposition(childs); + + } + + return parentLoaded; + + } + + @Override + public void save(SetLongline setLongline) { + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionService.java new file mode 100644 index 0000000..3bb5cec --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionService.java @@ -0,0 +1,20 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface BranchlinesCompositionService extends ObserveService { + + SetLongline loadForEdit(String setLonglineId); + + @Commit + void save(SetLongline setLongline); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java new file mode 100644 index 0000000..42197c6 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java @@ -0,0 +1,56 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.BranchlinesComposition; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class BranchlinesCompositionServiceImpl extends AbstractObserveService implements BranchlinesCompositionService { + @Override + public SetLongline loadForEdit(String setLonglineId) { + + SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); + + SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); + copy(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, parentToLoad, parentLoaded); + + TopiaEntityBinder<BranchlinesComposition> binder = getBinder(BranchlinesComposition.class, BinderService.EDIT); + if (!parentToLoad.isBranchlinesCompositionEmpty()) { + + TopiaDAO<BranchlinesComposition> childDao = getDao(BranchlinesComposition.class); + + List<BranchlinesComposition> childs = new ArrayList<BranchlinesComposition>(); + + for (BranchlinesComposition sourceChild : parentToLoad.getBranchlinesComposition()) { + + BranchlinesComposition targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); + + } + + parentLoaded.setBranchlinesComposition(childs); + + } + + return parentLoaded; + + } + + @Override + public void save(SetLongline setLongline) { + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java index a3cb5bc..49d8afe 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java @@ -1,12 +1,11 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.Branchline; +import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.WeightMeasure; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -20,23 +19,16 @@ public interface CatchLonglineService extends ObserveService { Branchline loadBranchlineForEdit(String branchelineId); - @Commit - Branchline saveBranchline(Branchline toSave); + SetLongline loadForEdit(String setLonglineId); List<SizeMeasure> getCatchLonglineSizeMeasures(String catchLonglineId); List<WeightMeasure> getCatchLonglineWeightMeasures(String catchLonglineId); - @NoTransaction - TopiaEntityBinder<WeightMeasure> getWeightMeasureBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<SizeMeasure> getSizeMeasureBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<Branchline> getBranchlineBinderForEdit(); + @Commit + void save(SetLongline setLongline); - @NoTransaction - void copyBranchlineForEdit(Branchline source, Branchline target); + @Commit + Branchline saveBranchline(Branchline toSave); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java index e5777f6..0289a94 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -1,18 +1,18 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveBinderHelper; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.BranchlineDAO; import fr.ird.observe.entities.longline.CatchLongline; import fr.ird.observe.entities.longline.CatchLonglineDAO; +import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.SizeMeasureImpl; import fr.ird.observe.entities.longline.WeightMeasure; import fr.ird.observe.entities.longline.WeightMeasureImpl; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.List; @@ -31,7 +31,7 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements BranchlineDAO dao = (BranchlineDAO) getDao(Branchline.class); Branchline toLoad = dao.findByTopiaId(branchelineId); Branchline loaded = dao.newInstance(); - getBranchlineBinderForEdit().load(toLoad, loaded, true); + copy(Branchline.class, BinderService.EDIT_CATCH_LONGLINE, toLoad, loaded); return loaded; } @@ -41,22 +41,52 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements BranchlineDAO dao = (BranchlineDAO) getDao(Branchline.class); Branchline saved = dao.findByTopiaId(toSave.getTopiaId()); - getBranchlineBinderForEdit().load(toSave, saved, true); + copy(Branchline.class, BinderService.EDIT_CATCH_LONGLINE, toSave, saved); return saved; } @Override - public void copyBranchlineForEdit(Branchline source, Branchline target) { + public SetLongline loadForEdit(String setLonglineId) { - getBranchlineBinderForEdit().load(source, target, true); + SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); + + SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); + copy(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE, parentToLoad, parentLoaded); + + TopiaEntityBinder<CatchLongline> binder = getBinder(CatchLongline.class, BinderService.EDIT); + + if (!parentToLoad.isCatchLonglineEmpty()) { + + TopiaDAO<CatchLongline> childDao = getDao(CatchLongline.class); + + List<CatchLongline> childs = new ArrayList<CatchLongline>(); + + for (CatchLongline sourceChild : parentToLoad.getCatchLongline()) { + + CatchLongline targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); + + } + + parentLoaded.setCatchLongline(childs); + + } + + return parentLoaded; + + } + + @Override + public void save(SetLongline setLongline) { } @Override public List<SizeMeasure> getCatchLonglineSizeMeasures(String catchLonglineId) { - TopiaEntityBinder<SizeMeasure> binder = getSizeMeasureBinderForEdit(); + TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); List<SizeMeasure> result = new ArrayList<SizeMeasure>(); @@ -72,7 +102,7 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements @Override public List<WeightMeasure> getCatchLonglineWeightMeasures(String catchLonglineId) { - TopiaEntityBinder<WeightMeasure> binder = getWeightMeasureBinderForEdit(); + TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); List<WeightMeasure> result = new ArrayList<WeightMeasure>(); @@ -86,51 +116,7 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements } - @Override - public TopiaEntityBinder<WeightMeasure> getWeightMeasureBinderForEdit() { - - TopiaEntityBinder<WeightMeasure> r = ObserveBinderHelper.getSimpleTopiaBinder(WeightMeasure.class); - return r; - - } - - @Override - public TopiaEntityBinder<SizeMeasure> getSizeMeasureBinderForEdit() { - - TopiaEntityBinder<SizeMeasure> r = ObserveBinderHelper.getSimpleTopiaBinder(SizeMeasure.class); - return r; - - } - - @Override - public TopiaEntityBinder<Branchline> getBranchlineBinderForEdit() { - - TopiaEntityBinder<Branchline> r = loadBinder("-forEdit", Branchline.class, new CreateBinder<Branchline>() { - - @Override - public BinderModelBuilder<Branchline, Branchline> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<Branchline, Branchline> builder = - binderService.newBinderBuilder(Branchline.class, - Branchline.PROPERTY_DEPTH_RECORDER, - Branchline.PROPERTY_HOOK_LOST, - Branchline.PROPERTY_TRACE_CUT_OFF, - Branchline.PROPERTY_TIMER, - Branchline.PROPERTY_TIME_SINCE_CONTACT, - Branchline.PROPERTY_TIMER_TIME_ON_BOARD, - Branchline.PROPERTY_BAIT_HAULING_STATUS); - - return builder; - } - - }); - - return r; - - } - protected CatchLonglineDAO getDao() { return (CatchLonglineDAO) getDao(CatchLongline.class); } - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterService.java new file mode 100644 index 0000000..9f55569 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterService.java @@ -0,0 +1,20 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface EncounterService extends ObserveService { + + ActivityLongline loadForEdit(String activityLonglineId); + + @Commit + void save(ActivityLongline activityLongline); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java new file mode 100644 index 0000000..eff812e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java @@ -0,0 +1,58 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.entities.longline.Encounter; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class EncounterServiceImpl extends AbstractObserveService implements EncounterService { + + @Override + public ActivityLongline loadForEdit(String activityLonglineId) { + + ActivityLongline parentToLoad = findByTopiaId(ActivityLongline.class, activityLonglineId); + + ActivityLongline parentLoaded = getDao(ActivityLongline.class).newInstance(); + copy(ActivityLongline.class, BinderService.EDIT_ENCOUNTER, parentToLoad, parentLoaded); + + TopiaEntityBinder<Encounter> binder = getBinder(Encounter.class, BinderService.EDIT); + + if (!parentToLoad.isEncounterEmpty()) { + + TopiaDAO<Encounter> childDao = getDao(Encounter.class); + + List<Encounter> childs = new ArrayList<Encounter>(); + + for (Encounter sourceChild : parentToLoad.getEncounter()) { + + Encounter targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); + + } + + parentLoaded.setEncounter(childs); + + } + + return parentLoaded; + + } + + @Override + public void save(ActivityLongline activityLongline) { + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionService.java new file mode 100644 index 0000000..253a3d9 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionService.java @@ -0,0 +1,20 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface FloatlinesCompositionService extends ObserveService { + + SetLongline loadForEdit(String setLonglineId); + + @Commit + void save(SetLongline setLongline); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java new file mode 100644 index 0000000..c434059 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java @@ -0,0 +1,57 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.FloatlinesComposition; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class FloatlinesCompositionServiceImpl extends AbstractObserveService implements FloatlinesCompositionService { + @Override + public SetLongline loadForEdit(String setLonglineId) { + + SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); + + SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); + copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, parentToLoad, parentLoaded); + + TopiaEntityBinder<FloatlinesComposition> binder = getBinder(FloatlinesComposition.class, BinderService.EDIT); + + if (!parentToLoad.isFloatlinesCompositionEmpty()) { + + TopiaDAO<FloatlinesComposition> childDao = getDao(FloatlinesComposition.class); + + List<FloatlinesComposition> childs = new ArrayList<FloatlinesComposition>(); + + for (FloatlinesComposition sourceChild : parentToLoad.getFloatlinesComposition()) { + + FloatlinesComposition targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); + + } + + parentLoaded.setFloatlinesComposition(childs); + + } + + return parentLoaded; + + } + + @Override + public void save(SetLongline setLongline) { + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java index 6e69121..f80bf50 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java @@ -1,9 +1,9 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; -import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -19,7 +19,9 @@ public interface GearUseFeaturesLonglineService extends ObserveService { List<GearUseFeaturesMeasurementLongline> loadGearUseFeaturesMeasurementLonglineForEdit(String gearUseFeaturesLonglineId); - @NoTransaction - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLonglineBinderForEdit(); + TripLongline loadForEdit(String tripLonglineId); + + @Commit + void save(TripLongline tripLongline); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index f5bb483..d14f2d0 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -4,11 +4,12 @@ import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLonglineDAO; +import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.Collection; @@ -45,7 +46,8 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i public List<GearUseFeaturesMeasurementLongline> loadGearUseFeaturesMeasurementLonglineForEdit(String gearUseFeaturesLonglineId) { GearUseFeaturesMeasurementLonglineDAO dao = getDao(); - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getGearUseFeaturesMeasurementLonglineBinderForEdit(); + + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); GearUseFeaturesLongline gearUseFeaturesLongline = findByTopiaId(GearUseFeaturesLongline.class, gearUseFeaturesLonglineId); List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); @@ -62,26 +64,38 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i } @Override - public TopiaEntityBinder<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLonglineBinderForEdit() { + public TripLongline loadForEdit(String tripLonglineId) { + + TripLongline parentToLoad = findByTopiaId(TripLongline.class, tripLonglineId); + + TripLongline parentLoaded = getDao(TripLongline.class).newInstance(); + copy(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, parentToLoad, parentLoaded); - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> r = loadBinder("-forEdit", GearUseFeaturesMeasurementLongline.class, new CreateBinder<GearUseFeaturesMeasurementLongline>() { + if (!parentToLoad.isGearUseFeaturesLonglineEmpty()) { - @Override - public BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> createBinderBuilder(BinderService binderService, String name) { + TopiaEntityBinder<GearUseFeaturesLongline> binder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); + TopiaDAO<GearUseFeaturesLongline> childDao = getDao(GearUseFeaturesLongline.class); + List<GearUseFeaturesLongline> childs = new ArrayList<GearUseFeaturesLongline>(); - BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> builder = - binderService.newBinderBuilder(GearUseFeaturesMeasurementLongline.class, - GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, - GearUseFeaturesMeasurementLongline.PROPERTY_MEASUREMENT_VALUE); + for (GearUseFeaturesLongline sourceChild : parentToLoad.getGearUseFeaturesLongline()) { - return builder; + GearUseFeaturesLongline targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); } - }); + parentLoaded.setGearUseFeaturesLongline(childs); + + } - return r; + return parentLoaded; + + } + + @Override + public void save(TripLongline tripLongline) { } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionService.java new file mode 100644 index 0000000..5c09c45 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionService.java @@ -0,0 +1,20 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface HooksCompositionService extends ObserveService { + + SetLongline loadForEdit(String setLonglineId); + + @Commit + void save(SetLongline setLongline); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java new file mode 100644 index 0000000..b142407 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java @@ -0,0 +1,56 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.HooksComposition; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 4/29/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class HooksCompositionServiceImpl extends AbstractObserveService implements HooksCompositionService { + @Override + public SetLongline loadForEdit(String setLonglineId) { + + SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); + + SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); + copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, parentToLoad, parentLoaded); + + if (!parentToLoad.isHooksCompositionEmpty()) { + + TopiaEntityBinder<HooksComposition> binder = getBinder(HooksComposition.class, BinderService.EDIT); + TopiaDAO<HooksComposition> childDao = getDao(HooksComposition.class); + + List<HooksComposition> childs = new ArrayList<HooksComposition>(); + + for (HooksComposition sourceChild : parentToLoad.getHooksComposition()) { + + HooksComposition targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); + + } + + parentLoaded.setHooksComposition(childs); + + } + + return parentLoaded; + + } + + @Override + public void save(SetLongline setLongline) { + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java index af2b697..0df533e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java @@ -1,10 +1,9 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SensorUsed; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** * Created on 4/25/15. @@ -16,22 +15,9 @@ public interface SensorUsedService extends ObserveService { String getSensorUsedDataFilename(SensorUsed sensorUsed); - SensorUsed loadForDisplay(String sensorUsedId); - - SensorUsed loadForEdit(String sensorUsedId); - - SensorUsed preCreate(String setLonglineId); - - @Commit - SensorUsed save(String setLonglineId, SensorUsed toSave); + ActivityLongline loadForEdit(String activityLonglineId); @Commit - void delete(String setLonglineId, String sensorUsedId); - - @NoTransaction - TopiaEntityBinder<SensorUsed> getBinderForEdit(); - - @NoTransaction - void copyForEdit(SensorUsed source, SensorUsed target); + void save(ActivityLongline activityLongline); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java index eb6aa2d..dd74fbf 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java @@ -1,20 +1,25 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SensorUsed; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.TripLonglineDAO; import fr.ird.observe.entities.referentiel.longline.SensorType; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; /** * Created on 4/26/15. * * @author Tony Chemit - chemit@codelutin.com - * @since XXX + * @since 4.0 */ public class SensorUsedServiceImpl extends AbstractObserveService implements SensorUsedService { @@ -47,38 +52,42 @@ public class SensorUsedServiceImpl extends AbstractObserveService implements Sen } - @Override - public SensorUsed loadForDisplay(String sensorUsedId) { - return null; - } @Override - public SensorUsed loadForEdit(String sensorUsedId) { - return null; - } + public ActivityLongline loadForEdit(String activityLonglineId) { - @Override - public SensorUsed preCreate(String setLonglineId) { - return null; - } + ActivityLongline parentToLoad = findByTopiaId(ActivityLongline.class, activityLonglineId); - @Override - public SensorUsed save(String setLonglineId, SensorUsed toSave) { - return null; - } + ActivityLongline parentLoaded = getDao(ActivityLongline.class).newInstance(); + copy(ActivityLongline.class, BinderService.EDIT_SENSOR_USED, parentToLoad, parentLoaded); - @Override - public void delete(String setLonglineId, String sensorUsedId) { - } + if (!parentToLoad.isSensorUsedEmpty()) { + + TopiaEntityBinder<SensorUsed> binder = getBinder(SensorUsed.class, BinderService.EDIT); + TopiaDAO<SensorUsed> childDao = getDao(SensorUsed.class); + + List<SensorUsed> childs = new ArrayList<SensorUsed>(); + + for (SensorUsed sourceChild : parentToLoad.getSensorUsed()) { + + SensorUsed targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); + + } + + parentLoaded.setSensorUsed(childs); + + } + + return parentLoaded; - @Override - public TopiaEntityBinder<SensorUsed> getBinderForEdit() { - return null; } @Override - public void copyForEdit(SensorUsed source, SensorUsed target) { + public void save(ActivityLongline activityLongline) { } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java index 38f574b..5253955 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -22,8 +20,4 @@ public interface SetLonglineService extends ObserveService { String save(String activityId, SetLongline bean); - @NoTransaction - TopiaEntityBinder<SetLongline> getBinderForEdit(); - - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index e432560..7c44be2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -7,13 +7,9 @@ import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SetLonglineDAO; -import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.List; @@ -78,7 +74,7 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se public SetLongline onCreate(ActivityLongline parent, SetLongline toCreate) { SetLongline created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(SetLongline.class, BinderService.EDIT, toCreate, created, false); parent.setSetLongline(created); @@ -88,15 +84,16 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se @Override public SetLongline onUpdate(ActivityLongline parent, SetLongline toUpdate, SetLongline updated) { - getBinderForEdit().copyExcluding(toUpdate, updated, - SetLongline.PROPERTY_BAITS_COMPOSITION, - SetLongline.PROPERTY_FLOATLINES_COMPOSITION, - SetLongline.PROPERTY_HOOKS_COMPOSITION, - SetLongline.PROPERTY_BRANCHLINES_COMPOSITION, - SetLongline.PROPERTY_SECTION, - SetLongline.PROPERTY_CATCH_LONGLINE, - SetLongline.PROPERTY_MITIGATION_TYPE, - SetLongline.PROPERTY_TDR); + copyExcluding(SetLongline.class, BinderService.EDIT, + toUpdate, updated, + SetLongline.PROPERTY_BAITS_COMPOSITION, + SetLongline.PROPERTY_FLOATLINES_COMPOSITION, + SetLongline.PROPERTY_HOOKS_COMPOSITION, + SetLongline.PROPERTY_BRANCHLINES_COMPOSITION, + SetLongline.PROPERTY_SECTION, + SetLongline.PROPERTY_CATCH_LONGLINE, + SetLongline.PROPERTY_MITIGATION_TYPE, + SetLongline.PROPERTY_TDR); return updated; } @@ -105,79 +102,6 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se return setLonglineId; } - @Override - public TopiaEntityBinder<SetLongline> getBinderForEdit() { - TopiaEntityBinder<SetLongline> r = loadBinder("-forEdit", SetLongline.class, new CreateBinder<SetLongline>() { - - @Override - public BinderModelBuilder<SetLongline, SetLongline> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<SetLongline, SetLongline> builder = binderService.newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_COMMENT, - - // setting tab - SetLongline.PROPERTY_HOME_ID, - SetLongline.PROPERTY_NUMBER, - - SetLongline.PROPERTY_SETTING_START_TIME_STAMP, - SetLongline.PROPERTY_SETTING_START_QUADRANT, - SetLongline.PROPERTY_SETTING_START_LATITUDE, - SetLongline.PROPERTY_SETTING_START_LONGITUDE, - - SetLongline.PROPERTY_SETTING_END_TIME_STAMP, - SetLongline.PROPERTY_SETTING_END_QUADRANT, - SetLongline.PROPERTY_SETTING_END_LATITUDE, - SetLongline.PROPERTY_SETTING_END_LONGITUDE, - - // setting caracteristics tab - SetLongline.PROPERTY_SETTING_SHAPE, - SetLongline.PROPERTY_LINE_TYPE, - SetLongline.PROPERTY_LIGHTSTICKS_TYPE, - SetLongline.PROPERTY_LIGHTSTICKS_COLOR, - SetLongline.PROPERTY_SETTING_VESSEL_SPEED, - SetLongline.PROPERTY_MAX_DEPTH_TARGETED, - SetLongline.PROPERTY_SHOOTER_USED, - SetLongline.PROPERTY_SHOOTER_SPEED, - SetLongline.PROPERTY_WEIGHTED_SWIVEL, - SetLongline.PROPERTY_SWIVEL_WEIGHT, - SetLongline.PROPERTY_WEIGHTED_SNAP, - SetLongline.PROPERTY_SNAP_WEIGHT, - SetLongline.PROPERTY_MONITORED, - SetLongline.PROPERTY_TIME_BETWEEN_HOOKS, - SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, - SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT, - SetLongline.PROPERTY_LIGHTSTICKS_PER_BASKET_COUNT, - SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, - SetLongline.PROPERTY_TOTAL_BASKETS_COUNT, - SetLongline.PROPERTY_TOTAL_HOOKS_COUNT, - - // hauling tab - SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, - - SetLongline.PROPERTY_HAULING_START_QUADRANT, - SetLongline.PROPERTY_HAULING_START_LATITUDE, - SetLongline.PROPERTY_HAULING_START_LONGITUDE, - SetLongline.PROPERTY_HAULING_START_TIME_STAMP, - - SetLongline.PROPERTY_HAULING_END_QUADRANT, - SetLongline.PROPERTY_HAULING_END_LATITUDE, - SetLongline.PROPERTY_HAULING_END_LONGITUDE, - SetLongline.PROPERTY_HAULING_END_TIME_STAMP, - - SetLongline.PROPERTY_HAULING_BREAKS); - - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); - - return builder; - } - - }); - - return r; - } - protected SetLonglineDAO getDao() { return (SetLonglineDAO) getDao(SetLongline.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java index afbee3d..ab09e74 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java @@ -1,10 +1,9 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** * Created on 4/25/15. @@ -16,22 +15,9 @@ public interface TdrService extends ObserveService { String getTdrDataFilename(Tdr tdr); - Tdr loadForDisplay(String tdrId); - - Tdr loadForEdit(String tdrId); - - Tdr preCreate(String tripLonglineId); - - @Commit - Tdr save(String setLonglineId, Tdr toSave); + SetLongline loadForEdit(String setLonglineId); @Commit - void delete(String setLonglineId, String tdrId); - - @NoTransaction - TopiaEntityBinder<Tdr> getBinderForEdit(); - - @NoTransaction - void copyForEdit(Tdr source, Tdr target); + void save(SetLongline setLongline); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java index fa6ae63..a00825a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java @@ -1,13 +1,18 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.TripLonglineDAO; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; /** * Created on 4/26/15. @@ -47,37 +52,40 @@ public class TdrServiceImpl extends AbstractObserveService implements TdrService } @Override - public Tdr loadForDisplay(String tdrId) { - return null; - } + public SetLongline loadForEdit(String setLonglineId) { - @Override - public Tdr loadForEdit(String tdrId) { - return null; - } + SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); - @Override - public Tdr preCreate(String tripLonglineId) { - return null; - } + SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); + copy(SetLongline.class, BinderService.EDIT_TDR, parentToLoad, parentLoaded); - @Override - public Tdr save(String setLonglineId, Tdr toSave) { - return null; - } - @Override - public void delete(String setLonglineId, String tdrId) { + if (!parentToLoad.isTdrEmpty()) { - } + TopiaEntityBinder<Tdr> binder = getBinder(Tdr.class, BinderService.EDIT); + TopiaDAO<Tdr> childDao = getDao(Tdr.class); - @Override - public TopiaEntityBinder<Tdr> getBinderForEdit() { - return null; + List<Tdr> childs = new ArrayList<Tdr>(); + + for (Tdr sourceChild : parentToLoad.getTdr()) { + + Tdr targetChild = childDao.newInstance(); + binder.load(sourceChild, targetChild, true); + childs.add(targetChild); + + } + + parentLoaded.setTdr(childs); + + } + + return parentLoaded; + } @Override - public void copyForEdit(Tdr source, Tdr target) { + public void save(SetLongline setLongline) { } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java index 510b6ac..5eae946 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -32,15 +30,4 @@ public interface TripLonglineService extends ObserveService { @Commit void delete(String tripLonglineId); - @NoTransaction - TopiaEntityBinder<TripLongline> getBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<TripLongline> getBinderStubForDisplay(); - - @NoTransaction - void copyForEdit(TripLongline source, TripLongline target); - - @NoTransaction - void copyStubForDisplay(TripLongline source, TripLongline target); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index d832799..69f9044 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -7,10 +7,7 @@ import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.TripLonglineDAO; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Date; import java.util.List; @@ -43,7 +40,7 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T TripLongline loaded = getDao().newInstance(); TripLongline toLoad = getDao().findByTopiaId(tripLonglineId); - copyForEdit(toLoad, loaded); + copy(TripLongline.class, BinderService.EDIT, toLoad, loaded); if (!loaded.isActivityLonglineEmpty()) { @@ -105,13 +102,13 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T @Override public TripLongline onCreate(Program parent, TripLongline toCreate) { TripLongline created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(TripLongline.class, BinderService.EDIT, toCreate, created, false); return created; } @Override public TripLongline onUpdate(Program parentBean, TripLongline toUpdate, TripLongline updated) { - getBinderForEdit().copyExcluding(toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + copyExcluding(TripLongline.class, BinderService.EDIT, toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); return updated; } }); @@ -125,85 +122,6 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T doDelete(null, tripLonglineId, new DeleteAction<Program, TripLongline>(Program.class, TripLongline.class)); } - @Override - public TopiaEntityBinder<TripLongline> getBinderForEdit() { - - TopiaEntityBinder<TripLongline> r = loadBinder("-forEdit", TripLongline.class, new CreateBinder<TripLongline>() { - - @Override - public BinderModelBuilder<TripLongline, TripLongline> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TripLongline, TripLongline> builder = binderService.newBinderBuilder( - TripLongline.class, - TripLongline.PROPERTY_START_DATE, - TripLongline.PROPERTY_END_DATE, - TripLongline.PROPERTY_TRIP_TYPE, - TripLongline.PROPERTY_HOME_ID, - TripLongline.PROPERTY_COMMENT, - TripLongline.PROPERTY_VESSEL, - TripLongline.PROPERTY_OBSERVER, - TripLongline.PROPERTY_CAPTAIN, - TripLongline.PROPERTY_DATA_ENTRY_OPERATOR, - TripLongline.PROPERTY_TOTAL_FISHING_OPERATIONS_NUMBER, - TripLongline.PROPERTY_OCEAN, - TripLongline.PROPERTY_DEPARTURE_HARBOUR, - TripLongline.PROPERTY_LANDING_HARBOUR, - TripLongline.PROPERTY_PROGRAM, - TripLongline.PROPERTY_ACTIVITY_LONGLINE, - TripLongline.PROPERTY_OPEN); - - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripLongline.PROPERTY_ACTIVITY_LONGLINE); - - return builder; - } - - }); - - return r; - - } - - @Override - public TopiaEntityBinder<TripLongline> getBinderStubForDisplay() { - - TopiaEntityBinder<TripLongline> r = loadBinder("-stubFordisplay", TripLongline.class, new CreateBinder<TripLongline>() { - - @Override - public BinderModelBuilder<TripLongline, TripLongline> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TripLongline, TripLongline> builder = binderService.newBinderBuilder( - TripLongline.class, - TripLongline.PROPERTY_START_DATE, - TripLongline.PROPERTY_END_DATE, - TripLongline.PROPERTY_OPEN, - TripLongline.PROPERTY_OBSERVER, - TripLongline.PROPERTY_VESSEL, - TripLongline.PROPERTY_PROGRAM); - - return builder; - } - - }); - - return r; - - } - - @Override - public void copyForEdit(TripLongline source, TripLongline target) { - - getBinderForEdit().load(source, target, true); - - } - - @Override - public void copyStubForDisplay(TripLongline source, TripLongline target) { - - getBinderStubForDisplay().load(source, target, true); - - } - protected TripLonglineDAO getDao() { return (TripLonglineDAO) getDao(TripLongline.class); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 1354ecd..823a9d9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -357,6 +357,10 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { getBinderService().copy(type, context, source, target); } + public <E extends TopiaEntity> void copyEdit(Class<E> type, String context, E source, E target) { + getBinderService().copy(type, BinderService.EDIT, source, target); + } + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { getBinderService().copyExcluding(type, context, source, target, propertyNames); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java index 0e02043..8e46976 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java @@ -22,8 +22,8 @@ package fr.ird.observe.ui.content.list.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.TripLongline; @@ -115,7 +115,7 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin TripLongline loaded = tripService.getTripLonglineStub(selectedId); TripLongline bean = getBean(); - tripService.copyStubForDisplay(loaded, bean); + copy(TripLongline.class, BinderService.DISPLAY, loaded, bean); ActivityLonglineService routeService = getService(ActivityLonglineService.class); List<ActivityLongline> activityLonglines = routeService.getActivityLonglineStubByTrip(selectedId); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java index ef7ce2c..61e8c9a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java @@ -22,6 +22,7 @@ package fr.ird.observe.ui.content.open.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; @@ -151,7 +152,7 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity } ActivityLongline bean = getBean(); - service.copyForEdit(loaded, bean); + copy(ActivityLongline.class, BinderService.EDIT, loaded, bean); finalizeOpenUI(mode, create); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java index 0bbc283..9d0b3c8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java @@ -22,6 +22,7 @@ package fr.ird.observe.ui.content.open.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; @@ -176,7 +177,7 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline } TripLongline bean = getBean(); - service.copyForEdit(loaded, bean); + copy(TripLongline.class, BinderService.EDIT, loaded, bean); getUi().getTripLonglineTabPane().setSelectedIndex(0); buildTripMap = true; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java index 73520e3..a3640c5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java @@ -22,14 +22,14 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; +import fr.ird.observe.BinderService; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.BaitsComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.referentiel.longline.BaitSettingStatus; import fr.ird.observe.entities.referentiel.longline.BaitType; +import fr.ird.observe.services.data.longline.BaitsCompositionService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; @@ -65,6 +65,19 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void loadEditBean() throws DataSourceException { + + String setLonglineId = getDataContext().getSelectedSetId(); + + BaitsCompositionService service = getService(BaitsCompositionService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, loaded, getBean()); + + } + + @Override protected void onSelectedRowChanged(int editingRow, BaitsComposition bean, boolean create) { if (getTableModel().isEditable()) { @@ -112,11 +125,6 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override public SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { return super.onUpdate(tx, parentBean, beanToSave); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java index 616725a..fa25f1f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java @@ -22,14 +22,14 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; +import fr.ird.observe.BinderService; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.BranchlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.referentiel.longline.HookSize; import fr.ird.observe.entities.referentiel.longline.HookType; +import fr.ird.observe.services.data.longline.BranchlinesCompositionService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; @@ -109,8 +109,16 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); + protected void loadEditBean() throws DataSourceException { + + String setLonglineId = getDataContext().getSelectedSetId(); + + BranchlinesCompositionService service = getService(BranchlinesCompositionService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, loaded, getBean()); + } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 37a84b4..a6819aa 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -22,13 +22,11 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.Basket; @@ -49,7 +47,6 @@ import fr.ird.observe.services.data.longline.CatchLonglineService; import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; -import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIInitializer; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; @@ -159,6 +156,32 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override + protected void loadEditBean() throws DataSourceException { + + String setLonglineId = getDataContext().getSelectedSetId(); + + CatchLonglineService service = getService(CatchLonglineService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE, loaded, getBean()); + + // reset size measures + getModel().getSizeMeasuresTableModel().clear(); + + // reset weight measures + getModel().getWeightMeasuresTableModel().clear(); + + // load sections (and baskets and branchlines) + SetLonglineService setLonglineService = getService(SetLonglineService.class); + List<Section> sections = setLonglineService.getSections(setLonglineId); + + LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); + positionHelper.initSections(sections, getTableModel().getData()); + + } + + @Override protected void onSelectedRowChanged(int editingRow, CatchLongline bean, boolean create) { if (log.isInfoEnabled()) { @@ -428,11 +451,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override public void initUI() throws Exception { // add a listPredicate to get only species from the correct configured speciesList @@ -480,31 +498,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected SetLongline loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { - - SetLongline setLongline = super.loadEditBean(mode, dataContext, dataService, dataSource); - - // reset size measures - getModel().getSizeMeasuresTableModel().clear(); - - // reset weight measures - getModel().getWeightMeasuresTableModel().clear(); - - // load sections (and baskets and branchlines) - SetLonglineService service = getService(SetLonglineService.class); - List<Section> sections = service.getSections(setLongline.getTopiaId()); - - LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); - positionHelper.initSections(sections, getTableModel().getData()); - - return setLongline; - - } - - @Override public void openUI() throws Exception { if (log.isInfoEnabled()) { @@ -833,7 +826,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C CatchLonglineService service = getService(CatchLonglineService.class); Branchline loadedBranchline = service.loadBranchlineForEdit(newValue.getTopiaId()); - service.copyBranchlineForEdit(loadedBranchline, getUi().getBranchlineBean()); + copy(Branchline.class, BinderService.EDIT_CATCH_LONGLINE, loadedBranchline, getUi().getBranchlineBean()); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java index 2392b1a..427695e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java @@ -22,15 +22,15 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Encounter; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.longline.EncounterType; +import fr.ird.observe.services.data.longline.EncounterService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; @@ -62,6 +62,19 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override + protected void loadEditBean() throws DataSourceException { + + String activityLonglineId = getDataContext().getSelectedActivityId(); + + EncounterService service = getService(EncounterService.class); + + ActivityLongline loaded = service.loadForEdit(activityLonglineId); + + copy(ActivityLongline.class, BinderService.EDIT_ENCOUNTER, loaded, getBean()); + + } + + @Override protected void onSelectedRowChanged(int editingRow, Encounter bean, boolean create) { if (getTableModel().isEditable()) { if (log.isDebugEnabled()) { @@ -92,17 +105,12 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedActivityId(); - } - - @Override public void initUI() throws Exception { // add a listPredicate to get only species from the correct configured speciesList ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListLonglineEncounterId(); - prepareSpeciesList(speciesListId, getUi().getSpecies() , n("observe.error.speciesList.longline.encounter.notFound")); + prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.longline.encounter.notFound")); super.initUI(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java index d254543..6b96f69 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java @@ -22,13 +22,16 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.FloatlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.referentiel.longline.LineType; +import fr.ird.observe.services.data.longline.FloatlinesCompositionService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; @@ -64,6 +67,19 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override + protected void loadEditBean() throws DataSourceException { + + String setLonglineId = getDataContext().getSelectedSetId(); + + FloatlinesCompositionService service = getService(FloatlinesCompositionService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, loaded, getBean()); + + } + + @Override protected void onSelectedRowChanged(int editingRow, FloatlinesComposition bean, boolean create) { if (getTableModel().isEditable()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index dfce5c6..9596458 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -22,11 +22,10 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; @@ -125,6 +124,22 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override + protected void loadEditBean() throws DataSourceException { + + String activityLonglineId = getDataContext().getSelectedTripLonglineId(); + + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); + + TripLongline loaded = service.loadForEdit(activityLonglineId); + + copy(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, loaded, getBean()); + + // reset measurements + getModel().getMeasurementsTableModel().clear(); + + } + + @Override protected void onSelectedRowChanged(int editingRow, GearUseFeaturesLongline bean, boolean create) { if (log.isInfoEnabled()) { @@ -278,11 +293,6 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedTripLonglineId(); - } - - @Override public void initUI() throws Exception { super.initUI(); @@ -302,18 +312,6 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected TripLongline loadEditBean(ContentMode mode, DataContext dataContext, DataService dataService, DataSource dataSource) throws DataSourceException { - - TripLongline tripLongline = super.loadEditBean(mode, dataContext, dataService, dataSource); - - // reset measurements - getModel().getMeasurementsTableModel().clear(); - - return tripLongline; - - } - - @Override public void openUI() throws Exception { if (log.isInfoEnabled()) { @@ -390,11 +388,6 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected TripLongline onCreate(TopiaContext tx, Object parentBean, TripLongline editBean) throws TopiaException { - return super.onCreate(tx, parentBean, editBean); - } - - @Override protected void onUpdateFinalize(TopiaContext tx, TripLongline bean, Collection<GearUseFeaturesLongline> oldChilds) throws TopiaException { List<GearUseFeaturesLongline> gearUseFeatures = bean.getGearUseFeaturesLongline(); @@ -533,7 +526,8 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(String gearId) { - List<GearUseFeaturesMeasurementLongline> measurements = getService(GearUseFeaturesLonglineService.class).getDefaultGearUseFeaturesMeasurementLongline(gearId); + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); + List<GearUseFeaturesMeasurementLongline> measurements = service.getDefaultGearUseFeaturesMeasurementLongline(gearId); if (log.isInfoEnabled()) { log.info("Create mode, use default measurements: " + measurements.size()); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java index 44f98ab..7d50c06 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java @@ -26,16 +26,13 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveServiceHelper; -import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; +import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.ui.content.table.ContentTableMeta; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIModel; import fr.ird.observe.ui.content.table.ObserveContentTableUI; -import fr.ird.observe.ui.content.table.impl.longline.GearUseFeaturesMeasurementLonglinesTableModel; -import fr.ird.observe.ui.content.table.impl.longline.GearUseFeaturesLonglineTableModel; -import fr.ird.observe.ui.content.table.impl.longline.GearUseFeaturesLonglineUI; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.beans.BinderModelBuilder; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java index 6146c75..6f9b457 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java @@ -22,14 +22,17 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.HooksComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.referentiel.longline.HookSize; import fr.ird.observe.entities.referentiel.longline.HookType; +import fr.ird.observe.services.data.longline.HooksCompositionService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; @@ -65,6 +68,19 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void loadEditBean() throws DataSourceException { + + String setLonglineId = getDataContext().getSelectedSetId(); + + HooksCompositionService service = getService(HooksCompositionService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, loaded, getBean()); + + } + + @Override protected void onSelectedRowChanged(int editingRow, HooksComposition bean, boolean create) { if (getTableModel().isEditable()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java index f261ed5..d7bb9d9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java @@ -25,11 +25,10 @@ package fr.ird.observe.ui.content.table.impl.longline; import com.google.common.base.Predicate; import com.google.common.io.FileWriteMode; import com.google.common.io.Files; -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SensorUsed; @@ -81,6 +80,19 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override + protected void loadEditBean() throws DataSourceException { + + String activityLonglineId = getDataContext().getSelectedActivityId(); + + SensorUsedService service = getService(SensorUsedService.class); + + ActivityLongline loaded = service.loadForEdit(activityLonglineId); + + copy(ActivityLongline.class, BinderService.EDIT_SENSOR_USED, loaded, getBean()); + + } + + @Override protected void onSelectedRowChanged(int editingRow, SensorUsed bean, boolean create) { if (getTableModel().isEditable()) { if (log.isDebugEnabled()) { @@ -121,13 +133,6 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, UIHelper.setTableColumnRenderer(table, 5, UIHelper.newStringTableCellRenderer(renderer, 10, true)); } - @Override - protected String getEditBeanIdToLoad(DataContext dataContext, - DataService dataService, - DataSource dataSource) { - return dataContext.getSelectedActivityId(); - } - public void importData() { File file = UIHelper.chooseFile((Component) ui, diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java index f2400fe..68f8b37 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java @@ -25,12 +25,10 @@ package fr.ird.observe.ui.content.table.impl.longline; import com.google.common.base.Predicate; import com.google.common.io.FileWriteMode; import com.google.common.io.Files; -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.Section; @@ -41,7 +39,6 @@ import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.services.data.longline.TdrService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; -import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; @@ -124,6 +121,27 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override + protected void loadEditBean() throws DataSourceException { + + String setLonglineId = getDataContext().getSelectedSetId(); + + TdrService service = getService(TdrService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_TDR, loaded, getBean()); + + //FIXME Move this somewhere else ? + // load sections (and baskets and branchlines) + SetLonglineService setLonglineService = getService(SetLonglineService.class); + List<Section> sections = setLonglineService.getSections(setLonglineId); + + LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); + positionHelper.initSections(sections, getTableModel().getData()); + + } + + @Override protected void onSelectedRowChanged(int editingRow, Tdr bean, boolean create) { ContentTableModel<SetLongline, Tdr> model = getTableModel(); @@ -201,11 +219,6 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override public void initUI() throws Exception { // add a listPredicate to get only species from the correct configured speciesList @@ -265,22 +278,6 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override - protected SetLongline loadEditBean(ContentMode mode, DataContext dataContext, DataService dataService, DataSource dataSource) throws DataSourceException { - - SetLongline setLongline = super.loadEditBean(mode, dataContext, dataService, dataSource); - - // load sections (and baskets and branchlines) - SetLonglineService service = getService(SetLonglineService.class); - List<Section> sections = service.getSections(setLongline.getTopiaId()); - - LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); - positionHelper.initSections(sections, getTableModel().getData()); - - return setLongline; - - } - - @Override protected void resetEditBean() { super.resetEditBean(); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit ed3eb1f296730ba08f07738322930f182065911e Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 15:43:59 2015 +0200 fix sur le service des binders (refs #7017) --- observe-business/src/main/java/fr/ird/observe/BinderService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 31c1fd5..4e72eda 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -37,7 +37,6 @@ import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.WeightMeasure; -import fr.ird.observe.entities.seine.TripSeine; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -422,9 +421,6 @@ public class BinderService { SetLongline.PROPERTY_HAULING_BREAKS); - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); - registerTopiaBinder(SetLongline.class, builder, EDIT); } @@ -491,6 +487,8 @@ public class BinderService { // species tab Tdr.PROPERTY_SPECIES); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Tdr.PROPERTY_SPECIES); + registerTopiaBinder(Tdr.class, builder, EDIT); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit d2fcd82c2ca700c2911668e2f89375b70510985b Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 15:44:32 2015 +0200 amélioration du contrat pour enregistrer les collections + application sur le modèle ll (refs #7017) --- .../observe/services/AbstractObserveService.java | 36 ++++++++++-- .../data/longline/BaitsCompositionServiceImpl.java | 15 +++++ .../BranchlinesCompositionServiceImpl.java | 16 ++++++ .../data/longline/CatchLonglineServiceImpl.java | 15 +++++ .../data/longline/EncounterServiceImpl.java | 15 +++++ .../longline/FloatlinesCompositionServiceImpl.java | 15 +++++ .../GearUseFeaturesLonglineServiceImpl.java | 15 +++++ .../data/longline/HooksCompositionServiceImpl.java | 15 +++++ .../data/longline/SensorUsedServiceImpl.java | 15 +++++ .../services/data/longline/TdrServiceImpl.java | 17 +++++- .../seine/ObjectObservedSpeciesServiceImpl.java | 51 +++++++++-------- .../seine/ObjectSchoolEstimateServiceImpl.java | 51 +++++++++-------- .../data/seine/SchoolEstimateServiceImpl.java | 66 ++++++++++++---------- .../LonglineGlobalCompositionUIHandler.java | 9 +-- .../impl/longline/BaitsCompositionUIHandler.java | 19 +++++-- .../longline/BranchlinesCompositionUIHandler.java | 16 ++++-- .../impl/longline/CatchLonglineUIHandler.java | 14 +++++ .../table/impl/longline/EncounterUIHandler.java | 14 +++++ .../longline/FloatlinesCompositionUIHandler.java | 27 +++++---- .../longline/GearUseFeaturesLonglineUIHandler.java | 14 +++++ .../impl/longline/HooksCompositionUIHandler.java | 23 ++++---- .../table/impl/longline/SensorUsedUIHandler.java | 14 +++++ .../content/table/impl/longline/TdrUIHandler.java | 14 +++++ 23 files changed, 383 insertions(+), 123 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index ed7492b..7ddc8a3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -380,7 +380,7 @@ public abstract class AbstractObserveService implements ObserveService { } - protected abstract class SaveCollectionAction<P extends TopiaEntity, E extends TopiaEntity> { + protected class SaveCollectionAction<P extends TopiaEntity, E extends TopiaEntity> { protected final Class<P> parentClass; @@ -388,10 +388,17 @@ public abstract class AbstractObserveService implements ObserveService { protected final EntityListUpdator<P, E> listUpdator; - public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass, EntityListUpdator<P, E> listUpdator) { + protected final TopiaEntityBinder<P> parentBinder; + + protected final TopiaEntityBinder<E> childBinder; + + public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass, EntityListUpdator<P, E> listUpdator, + TopiaEntityBinder<P> parentBinder, TopiaEntityBinder<E> childBinder) { this.parentClass = parentClass; this.entityClass = entityClass; this.listUpdator = listUpdator; + this.parentBinder = parentBinder; + this.childBinder = childBinder; } public void prepareSave(P parent, Collection<E> toSaves) { @@ -402,11 +409,30 @@ public abstract class AbstractObserveService implements ObserveService { // par défaut, rien à faire } - public abstract P onUpdateParent(P parentToSave, P parentSaved); + public P onUpdateParent(P parentToSave, P parentSaved) { + + parentBinder.copyExcluding(parentToSave, parentSaved, listUpdator.getPropertyName()); + parentSaved = getDao(parentClass).update(parentSaved); + return parentSaved; + + } + + public E onCreateChild(E childToCreate) { - public abstract E onCreateChild(E childToSave); + E childCreated = getDao(entityClass).create(); + childBinder.load(childToCreate, childCreated, false); + return childCreated; + + } + + public E onUpdateChild(E childToSave, E childSaved) { + + childBinder.load(childToSave, childSaved, true); + childSaved = getDao(entityClass).update(childSaved); + return childSaved; + + } - public abstract E onUpdateChild(E childToSave, E childSaved); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java index 12d8b37..4fc502e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.longline.BaitsComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -56,6 +57,20 @@ public class BaitsCompositionServiceImpl extends AbstractObserveService implemen @Override public void save(SetLongline setLongline) { + TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION); + TopiaEntityBinder<BaitsComposition> childBinder = getBinder(BaitsComposition.class, BinderService.EDIT); + + doSaveList(setLongline, new SaveCollectionAction<SetLongline, BaitsComposition>( + SetLongline.class, BaitsComposition.class, getListUpdator(), parentBinder, childBinder)); + + } + + protected EntityListUpdator<SetLongline, BaitsComposition> getListUpdator() { + EntityListUpdator<SetLongline, BaitsComposition> listUpdator = EntityListUpdator.newEntityListUpdator( + SetLongline.class, + BaitsComposition.class, + SetLongline.PROPERTY_BAITS_COMPOSITION); + return listUpdator; } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java index 42197c6..4986d00 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.longline.BranchlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -51,6 +52,21 @@ public class BranchlinesCompositionServiceImpl extends AbstractObserveService im @Override public void save(SetLongline setLongline) { + TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION); + TopiaEntityBinder<BranchlinesComposition> childBinder = getBinder(BranchlinesComposition.class, BinderService.EDIT); + + doSaveList(setLongline, new SaveCollectionAction<SetLongline, BranchlinesComposition>( + SetLongline.class, BranchlinesComposition.class, getListUpdator(), parentBinder, childBinder)); + + + } + + protected EntityListUpdator<SetLongline, BranchlinesComposition> getListUpdator() { + EntityListUpdator<SetLongline, BranchlinesComposition> listUpdator = EntityListUpdator.newEntityListUpdator( + SetLongline.class, + BranchlinesComposition.class, + SetLongline.PROPERTY_BRANCHLINES_COMPOSITION); + return listUpdator; } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java index 0289a94..212ce50 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -12,6 +12,7 @@ import fr.ird.observe.entities.longline.WeightMeasure; import fr.ird.observe.entities.longline.WeightMeasureImpl; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -81,6 +82,12 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements @Override public void save(SetLongline setLongline) { + TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE); + TopiaEntityBinder<CatchLongline> childBinder = getBinder(CatchLongline.class, BinderService.EDIT); + + doSaveList(setLongline, new SaveCollectionAction<SetLongline, CatchLongline>( + SetLongline.class, CatchLongline.class, getListUpdator(), parentBinder, childBinder)); + } @Override @@ -119,4 +126,12 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements protected CatchLonglineDAO getDao() { return (CatchLonglineDAO) getDao(CatchLongline.class); } + + protected EntityListUpdator<SetLongline, CatchLongline> getListUpdator() { + EntityListUpdator<SetLongline, CatchLongline> listUpdator = EntityListUpdator.newEntityListUpdator( + SetLongline.class, + CatchLongline.class, + SetLongline.PROPERTY_CATCH_LONGLINE); + return listUpdator; + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java index eff812e..ac74e05 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Encounter; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -53,6 +54,20 @@ public class EncounterServiceImpl extends AbstractObserveService implements Enco @Override public void save(ActivityLongline activityLongline) { + TopiaEntityBinder<ActivityLongline> parentBinder = getBinder(ActivityLongline.class, BinderService.EDIT_ENCOUNTER); + TopiaEntityBinder<Encounter> childBinder = getBinder(Encounter.class, BinderService.EDIT); + + doSaveList(activityLongline, new SaveCollectionAction<ActivityLongline, Encounter>( + ActivityLongline.class, Encounter.class, getListUpdator(), parentBinder, childBinder)); + + } + + protected EntityListUpdator<ActivityLongline, Encounter> getListUpdator() { + EntityListUpdator<ActivityLongline, Encounter> listUpdator = EntityListUpdator.newEntityListUpdator( + ActivityLongline.class, + Encounter.class, + ActivityLongline.PROPERTY_ENCOUNTER); + return listUpdator; } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java index c434059..44a444f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.longline.FloatlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -52,6 +53,20 @@ public class FloatlinesCompositionServiceImpl extends AbstractObserveService imp @Override public void save(SetLongline setLongline) { + TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION); + TopiaEntityBinder<FloatlinesComposition> childBinder = getBinder(FloatlinesComposition.class, BinderService.EDIT); + + doSaveList(setLongline, new SaveCollectionAction<SetLongline, FloatlinesComposition>( + SetLongline.class, FloatlinesComposition.class, getListUpdator(), parentBinder, childBinder)); + + } + + protected EntityListUpdator<SetLongline, FloatlinesComposition> getListUpdator() { + EntityListUpdator<SetLongline, FloatlinesComposition> listUpdator = EntityListUpdator.newEntityListUpdator( + SetLongline.class, + FloatlinesComposition.class, + SetLongline.PROPERTY_FLOATLINES_COMPOSITION); + return listUpdator; } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index d14f2d0..979c585 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -9,6 +9,7 @@ import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -97,10 +98,24 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public void save(TripLongline tripLongline) { + TopiaEntityBinder<TripLongline> parentBinder = getBinder(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE); + TopiaEntityBinder<GearUseFeaturesLongline> childBinder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); + + doSaveList(tripLongline, new SaveCollectionAction<TripLongline, GearUseFeaturesLongline>( + TripLongline.class, GearUseFeaturesLongline.class, getListUpdator(), parentBinder, childBinder)); + } protected GearUseFeaturesMeasurementLonglineDAO getDao() { return (GearUseFeaturesMeasurementLonglineDAO) getDao(GearUseFeaturesMeasurementLongline.class); } + protected EntityListUpdator<TripLongline, GearUseFeaturesLongline> getListUpdator() { + EntityListUpdator<TripLongline, GearUseFeaturesLongline> listUpdator = EntityListUpdator.newEntityListUpdator( + TripLongline.class, + GearUseFeaturesLongline.class, + TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE); + return listUpdator; + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java index b142407..0f8fc53 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.longline.HooksComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -51,6 +52,20 @@ public class HooksCompositionServiceImpl extends AbstractObserveService implemen @Override public void save(SetLongline setLongline) { + TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION); + TopiaEntityBinder<HooksComposition> childBinder = getBinder(HooksComposition.class, BinderService.EDIT); + + doSaveList(setLongline, new SaveCollectionAction<SetLongline, HooksComposition>( + SetLongline.class, HooksComposition.class, getListUpdator(), parentBinder, childBinder)); + + } + + protected EntityListUpdator<SetLongline, HooksComposition> getListUpdator() { + EntityListUpdator<SetLongline, HooksComposition> listUpdator = EntityListUpdator.newEntityListUpdator( + SetLongline.class, + HooksComposition.class, + SetLongline.PROPERTY_HOOKS_COMPOSITION); + return listUpdator; } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java index dd74fbf..170fd5b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java @@ -8,6 +8,7 @@ import fr.ird.observe.entities.longline.TripLonglineDAO; import fr.ird.observe.entities.referentiel.longline.SensorType; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.text.SimpleDateFormat; @@ -88,6 +89,20 @@ public class SensorUsedServiceImpl extends AbstractObserveService implements Sen @Override public void save(ActivityLongline activityLongline) { + TopiaEntityBinder<ActivityLongline> parentBinder = getBinder(ActivityLongline.class, BinderService.EDIT_SENSOR_USED); + TopiaEntityBinder<SensorUsed> childBinder = getBinder(SensorUsed.class, BinderService.EDIT); + + doSaveList(activityLongline, new SaveCollectionAction<ActivityLongline, SensorUsed>( + ActivityLongline.class, SensorUsed.class, getListUpdator(), parentBinder, childBinder)); + + } + + protected EntityListUpdator<ActivityLongline, SensorUsed> getListUpdator() { + EntityListUpdator<ActivityLongline, SensorUsed> listUpdator = EntityListUpdator.newEntityListUpdator( + ActivityLongline.class, + SensorUsed.class, + ActivityLongline.PROPERTY_SENSOR_USED); + return listUpdator; } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java index a00825a..b650614 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java @@ -7,6 +7,7 @@ import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.TripLonglineDAO; import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.text.SimpleDateFormat; @@ -80,12 +81,26 @@ public class TdrServiceImpl extends AbstractObserveService implements TdrService } return parentLoaded; - + } @Override public void save(SetLongline setLongline) { + TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_TDR); + TopiaEntityBinder<Tdr> childBinder = getBinder(Tdr.class, BinderService.EDIT); + + doSaveList(setLongline, new SaveCollectionAction<SetLongline, Tdr>( + SetLongline.class, Tdr.class, getListUpdator(), parentBinder, childBinder)); + + } + + protected EntityListUpdator<SetLongline, Tdr> getListUpdator() { + EntityListUpdator<SetLongline, Tdr> listUpdator = EntityListUpdator.newEntityListUpdator( + SetLongline.class, + Tdr.class, + SetLongline.PROPERTY_TDR); + return listUpdator; } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java index e7d37c2..0fddc44 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java @@ -48,30 +48,35 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp @Override public void save(FloatingObject floatingObject) { - doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectObservedSpecies>(FloatingObject.class, ObjectObservedSpecies.class, getListUpdator()) { - @Override - public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { - getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); - getDao(FloatingObject.class).update(parentSaved); - return parentSaved; - } - - @Override - public ObjectObservedSpecies onCreateChild(ObjectObservedSpecies childToSave) { - ObjectObservedSpecies childSaved = getDao(ObjectObservedSpecies.class).newInstance(); - getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); - getDao(ObjectObservedSpecies.class).create(childSaved); - return childSaved; - } - - @Override - public ObjectObservedSpecies onUpdateChild(ObjectObservedSpecies childToSave, ObjectObservedSpecies childSaved) { - getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); - getDao(ObjectObservedSpecies.class).update(childSaved); - return childSaved; - } - }); + TopiaEntityBinder<FloatingObject> parentBinder = getBinderForFloatingObjectEdit(); + TopiaEntityBinder<ObjectObservedSpecies> childbinder = getBinderForObjectObservedSpeciesEdit(); + + doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectObservedSpecies>( + FloatingObject.class, ObjectObservedSpecies.class, getListUpdator(), parentBinder, childbinder)); + +// @Override +// public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { +// getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); +// getDao(FloatingObject.class).update(parentSaved); +// return parentSaved; +// } +// +// @Override +// public ObjectObservedSpecies onCreateChild(ObjectObservedSpecies childToSave) { +// ObjectObservedSpecies childSaved = getDao(ObjectObservedSpecies.class).newInstance(); +// getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); +// getDao(ObjectObservedSpecies.class).create(childSaved); +// return childSaved; +// } +// +// @Override +// public ObjectObservedSpecies onUpdateChild(ObjectObservedSpecies childToSave, ObjectObservedSpecies childSaved) { +// getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); +// getDao(ObjectObservedSpecies.class).update(childSaved); +// return childSaved; +// } +// }); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java index 34b8409..b947c96 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java @@ -49,30 +49,35 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl @Override public void save(FloatingObject floatingObject) { - doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectSchoolEstimate>(FloatingObject.class, ObjectSchoolEstimate.class, getListUpdator()) { - @Override - public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { - getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); - getDao(FloatingObject.class).update(parentSaved); - return parentSaved; - } - - @Override - public ObjectSchoolEstimate onCreateChild(ObjectSchoolEstimate childToSave) { - ObjectSchoolEstimate childSaved = getDao(ObjectSchoolEstimate.class).newInstance(); - getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); - getDao(ObjectSchoolEstimate.class).create(childSaved); - return childSaved; - } - - @Override - public ObjectSchoolEstimate onUpdateChild(ObjectSchoolEstimate childToSave, ObjectSchoolEstimate childSaved) { - getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); - getDao(ObjectSchoolEstimate.class).update(childSaved); - return childSaved; - } - }); + TopiaEntityBinder<FloatingObject> parentBinder = getBinderForFloatingObjectEdit(); + TopiaEntityBinder<ObjectSchoolEstimate> childBinder = getBinderForObjectSchoolEstimateEdit(); + + doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectSchoolEstimate>( + FloatingObject.class, ObjectSchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); + +// @Override +// public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { +// getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); +// getDao(FloatingObject.class).update(parentSaved); +// return parentSaved; +// } +// +// @Override +// public ObjectSchoolEstimate onCreateChild(ObjectSchoolEstimate childToSave) { +// ObjectSchoolEstimate childSaved = getDao(ObjectSchoolEstimate.class).newInstance(); +// getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); +// getDao(ObjectSchoolEstimate.class).create(childSaved); +// return childSaved; +// } +// +// @Override +// public ObjectSchoolEstimate onUpdateChild(ObjectSchoolEstimate childToSave, ObjectSchoolEstimate childSaved) { +// getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); +// getDao(ObjectSchoolEstimate.class).update(childSaved); +// return childSaved; +// } +// }); } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java index 9509a8d..1959817 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -10,7 +10,6 @@ import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** @@ -53,37 +52,42 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements @Override public void save(SetSeine parent) { - doSaveList(parent, new SaveCollectionAction<SetSeine, SchoolEstimate>(SetSeine.class, SchoolEstimate.class, getListUpdator()) { - @Override - public void prepareSave(SetSeine parent, Collection<SchoolEstimate> toSaves) { - for (SchoolEstimate child : toSaves) { - child.setSetSeine(parent); - } - } - - @Override - public SetSeine onUpdateParent(SetSeine parentToSave, SetSeine parentSaved) { - getBinderForSetSeineEdit().copyExcluding(parentToSave, parentSaved, SetSeine.PROPERTY_SCHOOL_ESTIMATE); - getDao(SetSeine.class).update(parentSaved); - return parentSaved; - } - - @Override - public SchoolEstimate onCreateChild(SchoolEstimate childToSave) { - SchoolEstimate childSaved = getDao(SchoolEstimate.class).newInstance(); - getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); - getDao(SchoolEstimate.class).create(childSaved); - return childSaved; - } - - @Override - public SchoolEstimate onUpdateChild(SchoolEstimate childToSave, SchoolEstimate childSaved) { - getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); - getDao(SchoolEstimate.class).update(childSaved); - return childSaved; - } - }); + TopiaEntityBinder<SetSeine> parentBinder = getBinderForSetSeineEdit(); + TopiaEntityBinder<SchoolEstimate> childBinder = getBinderForSchoolEstimateEdit(); + + doSaveList(parent, new SaveCollectionAction<SetSeine, SchoolEstimate>( + SetSeine.class, SchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); +// +// @Override +// public void prepareSave(SetSeine parent, Collection<SchoolEstimate> toSaves) { +// for (SchoolEstimate child : toSaves) { +// child.setSetSeine(parent); +// } +// } +// +// @Override +// public SetSeine onUpdateParent(SetSeine parentToSave, SetSeine parentSaved) { +// getBinderForSetSeineEdit().copyExcluding(parentToSave, parentSaved, SetSeine.PROPERTY_SCHOOL_ESTIMATE); +// getDao(SetSeine.class).update(parentSaved); +// return parentSaved; +// } +// +// @Override +// public SchoolEstimate onCreateChild(SchoolEstimate childToSave) { +// SchoolEstimate childSaved = getDao(SchoolEstimate.class).newInstance(); +// getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); +// getDao(SchoolEstimate.class).create(childSaved); +// return childSaved; +// } +// +// @Override +// public SchoolEstimate onUpdateChild(SchoolEstimate childToSave, SchoolEstimate childSaved) { +// getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); +// getDao(SchoolEstimate.class).update(childSaved); +// return childSaved; +// } +// }); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java index d02be9e..d176a38 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java @@ -202,10 +202,11 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong beanToSave.clearMitigationType(); beanToSave.addAllMitigationType(getBean().getMitigationType()); - getUi().getFloatlinesCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); - getUi().getBranchlinesCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); - getUi().getHooksCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); - getUi().getBaitsCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); + //FIXME +// getUi().getFloatlinesCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); +// getUi().getBranchlinesCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); +// getUi().getHooksCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); +// getUi().getBaitsCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); return beanToSave; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java index a3640c5..42bdefa 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java @@ -34,8 +34,6 @@ import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import javax.swing.JTable; import javax.swing.event.TableModelEvent; @@ -78,6 +76,14 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void doPersist(SetLongline editBean) { + + BaitsCompositionService service = getService(BaitsCompositionService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, BaitsComposition bean, boolean create) { if (getTableModel().isEditable()) { @@ -125,12 +131,13 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - public SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { - return super.onUpdate(tx, parentBean, beanToSave); + public void afterSave(boolean refresh) { + super.afterSave(refresh); } + //TODO Supprimer saveUI et mettre saveUI2 a la place @Override - public void afterSave(boolean refresh) { - super.afterSave(refresh); + public final void saveUI(boolean refresh) { + saveUI2(refresh); } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java index fa25f1f..cdfcc88 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java @@ -34,8 +34,6 @@ import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import javax.swing.JTable; import javax.swing.event.TableModelEvent; @@ -122,13 +120,23 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override - public SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { - return super.onUpdate(tx, parentBean, beanToSave); + protected void doPersist(SetLongline editBean) { + + BranchlinesCompositionService service = getService(BranchlinesCompositionService.class); + service.save(editBean); + } + @Override public void afterSave(boolean refresh) { super.afterSave(refresh); } + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index a6819aa..fdfc42c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -182,6 +182,14 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override + protected void doPersist(SetLongline editBean) { + + CatchLonglineService service = getService(CatchLonglineService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, CatchLongline bean, boolean create) { if (log.isInfoEnabled()) { @@ -917,4 +925,10 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C return (CatchLonglineTableModel) super.getTableModel(); } + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java index 427695e..166b706 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java @@ -75,6 +75,14 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override + protected void doPersist(ActivityLongline editBean) { + + EncounterService service = getService(EncounterService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, Encounter bean, boolean create) { if (getTableModel().isEditable()) { if (log.isDebugEnabled()) { @@ -115,4 +123,10 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, super.initUI(); } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java index 6b96f69..e27355b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java @@ -23,9 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.FloatlinesComposition; @@ -36,8 +33,6 @@ import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import javax.swing.JTable; import javax.swing.event.TableModelEvent; @@ -80,6 +75,14 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override + protected void doPersist(SetLongline editBean) { + + FloatlinesCompositionService service = getService(FloatlinesCompositionService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, FloatlinesComposition bean, boolean create) { if (getTableModel().isEditable()) { @@ -122,17 +125,13 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - public SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { - return super.onUpdate(tx, parentBean, beanToSave); + public void afterSave(boolean refresh) { + super.afterSave(refresh); } + //TODO Supprimer saveUI et mettre saveUI2 a la place @Override - public void afterSave(boolean refresh) { - super.afterSave(refresh); + public final void saveUI(boolean refresh) { + saveUI2(refresh); } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 9596458..12129ff 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -140,6 +140,14 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override + protected void doPersist(TripLongline editBean) { + + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, GearUseFeaturesLongline bean, boolean create) { if (log.isInfoEnabled()) { @@ -567,4 +575,10 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java index 6f9b457..40cc700 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java @@ -23,9 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.HooksComposition; @@ -37,8 +34,6 @@ import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import javax.swing.JTable; import javax.swing.event.TableModelEvent; @@ -81,6 +76,14 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void doPersist(SetLongline editBean) { + + HooksCompositionService service = getService(HooksCompositionService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, HooksComposition bean, boolean create) { if (getTableModel().isEditable()) { @@ -124,14 +127,10 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } + //TODO Supprimer saveUI et mettre saveUI2 a la place @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - public SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { - return super.onUpdate(tx, parentBean, beanToSave); + public final void saveUI(boolean refresh) { + saveUI2(refresh); } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java index d7bb9d9..662960c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java @@ -93,6 +93,14 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override + protected void doPersist(ActivityLongline editBean) { + + SensorUsedService service = getService(SensorUsedService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, SensorUsed bean, boolean create) { if (getTableModel().isEditable()) { if (log.isDebugEnabled()) { @@ -235,4 +243,10 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java index 68f8b37..f2fee7c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java @@ -142,6 +142,14 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override + protected void doPersist(SetLongline editBean) { + + TdrService service = getService(TdrService.class); + service.save(editBean); + + } + + @Override protected void onSelectedRowChanged(int editingRow, Tdr bean, boolean create) { ContentTableModel<SetLongline, Tdr> model = getTableModel(); @@ -476,4 +484,10 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { bean.setFishingEnd(timestamp); } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 796526754295a8fe6f58b86222984dc417179d6d Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 15:49:26 2015 +0200 desciption des binder seine dans binder service, échantillon capturé --- .../main/java/fr/ird/observe/BinderService.java | 219 +++++++++++++++++++++ .../data/seine/ObjectObservedSpeciesService.java | 14 -- .../seine/ObjectObservedSpeciesServiceImpl.java | 85 +------- .../data/seine/ObjectSchoolEstimateService.java | 14 -- .../seine/ObjectSchoolEstimateServiceImpl.java | 83 +------- .../observe/services/data/seine/RouteService.java | 14 -- .../services/data/seine/RouteServiceImpl.java | 91 +-------- .../services/data/seine/SchoolEstimateService.java | 14 -- .../data/seine/SchoolEstimateServiceImpl.java | 102 +--------- .../services/data/seine/SetSeineService.java | 8 - .../services/data/seine/SetSeineServiceImpl.java | 58 +----- .../services/data/seine/TargetLengthService.java | 24 +++ .../data/seine/TargetLengthServiceImpl.java | 91 +++++++++ .../services/data/seine/TargetSampleService.java | 8 +- .../data/seine/TargetSampleServiceImpl.java | 129 ++---------- .../services/data/seine/TripSeineService.java | 14 -- .../services/data/seine/TripSeineServiceImpl.java | 88 +-------- .../ui/content/impl/seine/SetSeineUIHandler.java | 3 +- .../list/impl/seine/ActivitySeinesUIHandler.java | 3 +- .../content/list/impl/seine/RoutesUIHandler.java | 4 +- .../ui/content/open/impl/seine/RouteUIHandler.java | 3 +- .../open/impl/seine/TripSeineUIHandler.java | 3 +- .../impl/seine/ObjectObservedSpeciesUIHandler.java | 3 +- .../impl/seine/ObjectSchoolEstimateUIHandler.java | 3 +- .../table/impl/seine/SchoolEstimateUIHandler.java | 3 +- .../table/impl/seine/TargetSampleUIHandler.java | 58 +++--- 26 files changed, 425 insertions(+), 714 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 4e72eda..6aea2c7 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -37,6 +37,16 @@ import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.WeightMeasure; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.ObjectObservedSpecies; +import fr.ird.observe.entities.seine.ObjectSchoolEstimate; +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.SchoolEstimate; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.entities.seine.TripSeine; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -73,6 +83,13 @@ public class BinderService { public static final String EDIT_TDR = "editTdr"; + public static final String EDIT_TARGET_LENGHT = "editTargetLenght"; + + public static final String EDIT_SCHOOL_ESTIMATE = "editSchoolEstimate"; + + public static final String EDIT_OBJECT_SCHOOL_ESTIMATE = "editObjectSchoolEstimate"; + + public static final String EDIT_OBJECT_OBSERVED_SPECIES = "editObjectObservedSpecies"; static { @@ -538,24 +555,226 @@ public class BinderService { { + BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_START_DATE, + TripSeine.PROPERTY_END_DATE, + TripSeine.PROPERTY_FORMS_URL, + TripSeine.PROPERTY_REPORTS_URL, + TripSeine.PROPERTY_COMMENT, + TripSeine.PROPERTY_VESSEL, + TripSeine.PROPERTY_OBSERVER, + TripSeine.PROPERTY_CAPTAIN, + TripSeine.PROPERTY_DATA_ENTRY_OPERATOR, + TripSeine.PROPERTY_OCEAN, + TripSeine.PROPERTY_DEPARTURE_HARBOUR, + TripSeine.PROPERTY_LANDING_HARBOUR, + TripSeine.PROPERTY_PROGRAM, + TripSeine.PROPERTY_ROUTE, + TripSeine.PROPERTY_ERS_ID, + TripSeine.PROPERTY_OPEN); + + registerTopiaBinder(TripSeine.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_START_DATE, + TripSeine.PROPERTY_END_DATE, + TripSeine.PROPERTY_OPEN, + TripSeine.PROPERTY_OBSERVER, + TripSeine.PROPERTY_VESSEL, + TripSeine.PROPERTY_PROGRAM); + + registerTopiaBinder(TripSeine.class, builder, DISPLAY); + + } + + { + + BinderModelBuilder<TargetLength, TargetLength> builder = newBinderBuilder( + TargetLength.class, + TargetLength.PROPERTY_TARGET_SAMPLE, + TargetLength.PROPERTY_SPECIES, + TargetLength.PROPERTY_LENGTH, + TargetLength.PROPERTY_LENGTH_SOURCE, + TargetLength.PROPERTY_WEIGHT, + TargetLength.PROPERTY_WEIGHT_SOURCE, + TargetLength.PROPERTY_COUNT, + TargetLength.PROPERTY_MEASURE_TYPE, + TargetLength.PROPERTY_ACQUISITION_MODE); + + registerTopiaBinder(TargetLength.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TargetSample, TargetSample> builder = newBinderBuilder( + TargetSample.class, + TargetSample.PROPERTY_TARGET_LENGTH, + TargetSample.PROPERTY_COMMENT); + + registerTopiaBinder(TargetSample.class, builder, EDIT_TARGET_LENGHT); + + } + + { + + BinderModelBuilder<TargetSample, TargetSample> builder = newBinderBuilder( + TargetSample.class, + TargetSample.PROPERTY_TARGET_LENGTH, + TargetSample.PROPERTY_COMMENT); + + registerTopiaBinder(TargetSample.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetSeine, SetSeine> builder = newBinderBuilder( + SetSeine.class, + SetSeine.PROPERTY_COMMENT, + SetSeine.PROPERTY_SUPPORT_VESSEL_NAME, + SetSeine.PROPERTY_START_TIME, + SetSeine.PROPERTY_END_SET_TIME_STAMP, + SetSeine.PROPERTY_END_PURSING_TIME_STAMP, + SetSeine.PROPERTY_CURRENT_DIRECTION, + SetSeine.PROPERTY_CURRENT_SPEED, + SetSeine.PROPERTY_REASON_FOR_NULL_SET, + SetSeine.PROPERTY_SCHOOL_THICKNESS, + SetSeine.PROPERTY_MAX_GEAR_DEPTH, + SetSeine.PROPERTY_SCHOOL_MEAN_DEPTH, + SetSeine.PROPERTY_SCHOOL_TOP_DEPTH, + SetSeine.PROPERTY_CURRENT_MEASURE_DEPTH, + SetSeine.PROPERTY_TARGET_DISCARDED, + SetSeine.PROPERTY_NON_TARGET_DISCARDED, + SetSeine.PROPERTY_SCHOOL_TYPE, + SetSeine.PROPERTY_SONAR_USED, + SetSeine.PROPERTY_TARGET_SAMPLE, + SetSeine.PROPERTY_NON_TARGET_SAMPLE); + + registerTopiaBinder(SetSeine.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SchoolEstimate, SchoolEstimate> builder = newBinderBuilder( + SchoolEstimate.class, + SchoolEstimate.PROPERTY_SET_SEINE, + SchoolEstimate.PROPERTY_SPECIES, + SchoolEstimate.PROPERTY_TOTAL_WEIGHT, + SchoolEstimate.PROPERTY_MEAN_WEIGHT); + + registerTopiaBinder(SchoolEstimate.class, builder, EDIT); + + } + + { + BinderModelBuilder<SetSeine, SetSeine> builder = newBinderBuilder( + SetSeine.class, + SetSeine.PROPERTY_COMMENT, + SetSeine.PROPERTY_SCHOOL_ESTIMATE); + + registerTopiaBinder(SetSeine.class, builder, EDIT_SCHOOL_ESTIMATE); + } { + BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_QUADRANT, + ActivitySeine.PROPERTY_LATITUDE, + ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_TIME, + ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_WIND, + ActivitySeine.PROPERTY_OPEN); + + registerTopiaBinder(ActivitySeine.class, builder, EDIT); } { + BinderModelBuilder<Route, Route> builder = newBinderBuilder( + Route.class, + Route.PROPERTY_DATE, + Route.PROPERTY_START_LOG_VALUE, + Route.PROPERTY_END_LOG_VALUE, + Route.PROPERTY_CHECK_LEVEL, + Route.PROPERTY_ACTIVITY_SEINE, + Route.PROPERTY_OPEN, + Route.PROPERTY_COMMENT); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Route.PROPERTY_ACTIVITY_SEINE); + + registerTopiaBinder(Route.class, builder, EDIT); + } { + BinderModelBuilder<Route, Route> builder = newBinderBuilder( + Route.class, + Route.PROPERTY_DATE, + Route.PROPERTY_OPEN); + + registerTopiaBinder(Route.class, builder, DISPLAY); + } { + BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE, + FloatingObject.PROPERTY_COMMENT); + + registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_SCHOOL_ESTIMATE); } + { + + BinderModelBuilder<ObjectSchoolEstimate, ObjectSchoolEstimate> builder = newBinderBuilder( + ObjectSchoolEstimate.class, + ObjectSchoolEstimate.PROPERTY_SPECIES, + ObjectSchoolEstimate.PROPERTY_TOTAL_WEIGHT); + + registerTopiaBinder(ObjectSchoolEstimate.class, builder, EDIT); + + } + + { + + BinderModelBuilder<ObjectObservedSpecies, ObjectObservedSpecies> builder = newBinderBuilder( + ObjectObservedSpecies.class, + ObjectObservedSpecies.PROPERTY_SPECIES, + ObjectObservedSpecies.PROPERTY_SPECIES_STATUS, + ObjectObservedSpecies.PROPERTY_COUNT); + + registerTopiaBinder(ObjectObservedSpecies.class, builder, EDIT); + + } + + { + + BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES, + FloatingObject.PROPERTY_COMMENT); + + registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OBSERVED_SPECIES); + + } + + } public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java index cf46428..2bd726a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java @@ -3,10 +3,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** * Created on 4/28/15. @@ -21,17 +19,5 @@ public interface ObjectObservedSpeciesService extends ObserveService { @Commit void save(FloatingObject floatingObject); - @NoTransaction - TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit(); - - @NoTransaction - void copyForEdit(FloatingObject source, FloatingObject target); - - @NoTransaction - TopiaEntityBinder<ObjectObservedSpecies> getBinderForObjectObservedSpeciesEdit(); - - @NoTransaction - void copyForEdit(ObjectObservedSpecies source, ObjectObservedSpecies target); - EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator(); } \ No newline at end of file diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java index 0fddc44..5f8e84f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java @@ -7,7 +7,6 @@ import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.List; @@ -23,7 +22,7 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp FloatingObject parentLoaded = getDao(FloatingObject.class).newInstance(); - copyForEdit(parentToLoad, parentLoaded); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES, parentToLoad, parentLoaded); if (!parentToLoad.isObjectObservedSpeciesEmpty()) { @@ -34,7 +33,7 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp for (ObjectObservedSpecies sourceChild : parentToLoad.getObjectObservedSpecies()) { ObjectObservedSpecies targetChild = childDao.newInstance(); - copyForEdit(sourceChild, targetChild); + copy(ObjectObservedSpecies.class, BinderService.EDIT, sourceChild, targetChild); childs.add(targetChild); } @@ -49,88 +48,12 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp @Override public void save(FloatingObject floatingObject) { - TopiaEntityBinder<FloatingObject> parentBinder = getBinderForFloatingObjectEdit(); - TopiaEntityBinder<ObjectObservedSpecies> childbinder = getBinderForObjectObservedSpeciesEdit(); + TopiaEntityBinder<FloatingObject> parentBinder = getBinder(FloatingObject.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES); + TopiaEntityBinder<ObjectObservedSpecies> childbinder = getBinder(ObjectObservedSpecies.class, BinderService.EDIT); doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectObservedSpecies>( FloatingObject.class, ObjectObservedSpecies.class, getListUpdator(), parentBinder, childbinder)); -// @Override -// public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { -// getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); -// getDao(FloatingObject.class).update(parentSaved); -// return parentSaved; -// } -// -// @Override -// public ObjectObservedSpecies onCreateChild(ObjectObservedSpecies childToSave) { -// ObjectObservedSpecies childSaved = getDao(ObjectObservedSpecies.class).newInstance(); -// getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); -// getDao(ObjectObservedSpecies.class).create(childSaved); -// return childSaved; -// } -// -// @Override -// public ObjectObservedSpecies onUpdateChild(ObjectObservedSpecies childToSave, ObjectObservedSpecies childSaved) { -// getBinderForObjectObservedSpeciesEdit().copy(childToSave, childSaved); -// getDao(ObjectObservedSpecies.class).update(childSaved); -// return childSaved; -// } -// }); - - } - - @Override - public TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit() { - TopiaEntityBinder<FloatingObject> binder = loadBinder("-forObjectObservedSpeciesEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { - - @Override - public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES, - FloatingObject.PROPERTY_COMMENT); - - return builder; - - } - - }); - - return binder; - } - - @Override - public void copyForEdit(FloatingObject source, FloatingObject target) { - getBinderForFloatingObjectEdit().load(source, target, true); - } - - @Override - public TopiaEntityBinder<ObjectObservedSpecies> getBinderForObjectObservedSpeciesEdit() { - TopiaEntityBinder<ObjectObservedSpecies> binder = loadBinder("-forEdit", ObjectObservedSpecies.class, new CreateBinder<ObjectObservedSpecies>() { - - @Override - public BinderModelBuilder<ObjectObservedSpecies, ObjectObservedSpecies> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<ObjectObservedSpecies, ObjectObservedSpecies> builder = binderService.newBinderBuilder( - ObjectObservedSpecies.class, - ObjectObservedSpecies.PROPERTY_SPECIES, - ObjectObservedSpecies.PROPERTY_SPECIES_STATUS, - ObjectObservedSpecies.PROPERTY_COUNT); - - return builder; - - } - - }); - - return binder; - } - - @Override - public void copyForEdit(ObjectObservedSpecies source, ObjectObservedSpecies target) { - getBinderForObjectObservedSpeciesEdit().load(source, target, true); } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java index a1e079d..4581a6d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java @@ -3,10 +3,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** * Created on 4/28/15. @@ -21,17 +19,5 @@ public interface ObjectSchoolEstimateService extends ObserveService { @Commit void save(FloatingObject floatingObject); - @NoTransaction - TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit(); - - @NoTransaction - void copyForEdit(FloatingObject source, FloatingObject target); - - @NoTransaction - TopiaEntityBinder<ObjectSchoolEstimate> getBinderForObjectSchoolEstimateEdit(); - - @NoTransaction - void copyForEdit(ObjectSchoolEstimate source, ObjectSchoolEstimate target); - EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java index b947c96..060ecb1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java @@ -7,7 +7,6 @@ import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.List; @@ -24,7 +23,7 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl FloatingObject parentLoaded = getDao(FloatingObject.class).newInstance(); - copyForEdit(parentToLoad, parentLoaded); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE, parentToLoad, parentLoaded); if (!parentToLoad.isObjectSchoolEstimateEmpty()) { @@ -35,7 +34,7 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl for (ObjectSchoolEstimate sourceChild : parentToLoad.getObjectSchoolEstimate()) { ObjectSchoolEstimate targetChild = childDao.newInstance(); - copyForEdit(sourceChild, targetChild); + copy(ObjectSchoolEstimate.class, BinderService.EDIT, sourceChild, targetChild); childs.add(targetChild); } @@ -50,86 +49,12 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl @Override public void save(FloatingObject floatingObject) { - TopiaEntityBinder<FloatingObject> parentBinder = getBinderForFloatingObjectEdit(); - TopiaEntityBinder<ObjectSchoolEstimate> childBinder = getBinderForObjectSchoolEstimateEdit(); + TopiaEntityBinder<FloatingObject> parentBinder = getBinder(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE); + TopiaEntityBinder<ObjectSchoolEstimate> childBinder = getBinder(ObjectSchoolEstimate.class, BinderService.EDIT); doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectSchoolEstimate>( FloatingObject.class, ObjectSchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); -// @Override -// public FloatingObject onUpdateParent(FloatingObject parentToSave, FloatingObject parentSaved) { -// getBinderForFloatingObjectEdit().copyExcluding(parentToSave, parentSaved, FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); -// getDao(FloatingObject.class).update(parentSaved); -// return parentSaved; -// } -// -// @Override -// public ObjectSchoolEstimate onCreateChild(ObjectSchoolEstimate childToSave) { -// ObjectSchoolEstimate childSaved = getDao(ObjectSchoolEstimate.class).newInstance(); -// getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); -// getDao(ObjectSchoolEstimate.class).create(childSaved); -// return childSaved; -// } -// -// @Override -// public ObjectSchoolEstimate onUpdateChild(ObjectSchoolEstimate childToSave, ObjectSchoolEstimate childSaved) { -// getBinderForObjectSchoolEstimateEdit().copy(childToSave, childSaved); -// getDao(ObjectSchoolEstimate.class).update(childSaved); -// return childSaved; -// } -// }); - } - - @Override - public TopiaEntityBinder<FloatingObject> getBinderForFloatingObjectEdit() { - TopiaEntityBinder<FloatingObject> binder = loadBinder("-forObjectSchoolEstimateEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { - - @Override - public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE, - FloatingObject.PROPERTY_COMMENT); - - return builder; - - } - - }); - - return binder; - } - - @Override - public void copyForEdit(FloatingObject source, FloatingObject target) { - getBinderForFloatingObjectEdit().load(source, target, true); - } - - @Override - public TopiaEntityBinder<ObjectSchoolEstimate> getBinderForObjectSchoolEstimateEdit() { - TopiaEntityBinder<ObjectSchoolEstimate> binder = loadBinder("-forEdit", ObjectSchoolEstimate.class, new CreateBinder<ObjectSchoolEstimate>() { - - @Override - public BinderModelBuilder<ObjectSchoolEstimate, ObjectSchoolEstimate> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<ObjectSchoolEstimate, ObjectSchoolEstimate> builder = binderService.newBinderBuilder( - ObjectSchoolEstimate.class, - ObjectSchoolEstimate.PROPERTY_SPECIES, - ObjectSchoolEstimate.PROPERTY_TOTAL_WEIGHT); - - return builder; - - } - - }); - - return binder; - } - - @Override - public void copyForEdit(ObjectSchoolEstimate source, ObjectSchoolEstimate target) { - getBinderForObjectSchoolEstimateEdit().load(source, target, true); } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java index 6dbd6ff..72efcf3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -32,16 +30,4 @@ public interface RouteService extends ObserveService { @Commit void delete(String tripSeineId, String routeId); - @NoTransaction - TopiaEntityBinder<Route> getBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<Route> getBinderStubForDisplay(); - - @NoTransaction - void copyForEdit(Route source, Route target); - - @NoTransaction - void copyStubForDisplay(Route source, Route target); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index 7fde18e..c524c74 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -1,16 +1,13 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeines; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.RouteDAO; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.lang3.time.DateUtils; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Date; import java.util.List; @@ -44,7 +41,7 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer Route loaded = getDao().newInstance(); Route toLoad = getDao().findByTopiaId(routeId); - copyForEdit(toLoad, loaded); + copy(Route.class, BinderService.EDIT, toLoad, loaded); if (!loaded.isActivitySeineEmpty()) { @@ -105,7 +102,7 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer public Route onCreate(TripSeine parent, Route toCreate) { Route created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(Route.class, BinderService.EDIT, toCreate, created); parent.addRoute(created); @@ -122,7 +119,7 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer Date oldDate = DateUtil.getDay(toUpdate.getDate()); // recopie des propriétés vers le bean a sauver - getBinderForEdit().copyExcluding(toUpdate, updated, Route.PROPERTY_ACTIVITY_SEINE); + copyExcluding(Route.class, BinderService.EDIT, toUpdate, updated, Route.PROPERTY_ACTIVITY_SEINE); if (!oldDate.equals(toUpdate.getDate())) { @@ -160,88 +157,6 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer }); } - @Override - public TopiaEntityBinder<Route> getBinderForEdit() { - - TopiaEntityBinder<Route> binder = loadBinder("-forEdit", Route.class, new CreateBinder<Route>() { - - @Override - public BinderModelBuilder<Route, Route> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<Route, Route> builder = binderService.newBinderBuilder( - Route.class, - Route.PROPERTY_DATE, - Route.PROPERTY_START_LOG_VALUE, - Route.PROPERTY_END_LOG_VALUE, - Route.PROPERTY_CHECK_LEVEL, - Route.PROPERTY_ACTIVITY_SEINE, - Route.PROPERTY_OPEN, - Route.PROPERTY_COMMENT); - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder2 = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_QUADRANT, - ActivitySeine.PROPERTY_LATITUDE, - ActivitySeine.PROPERTY_LONGITUDE, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_OPEN); - - TopiaEntityBinder<ActivitySeine> binder2 = - binderService.registerTopiaBinder(ActivitySeine.class, builder2, name); - - builder.addCollectionBinder(binder2, Route.PROPERTY_ACTIVITY_SEINE); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public TopiaEntityBinder<Route> getBinderStubForDisplay() { - - TopiaEntityBinder<Route> binder = loadBinder("-stubForDisplay", Route.class, new CreateBinder<Route>() { - - @Override - public BinderModelBuilder<Route, Route> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<Route, Route> builder = binderService.newBinderBuilder( - Route.class, - Route.PROPERTY_DATE, - Route.PROPERTY_OPEN); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(Route source, Route target) { - - getBinderForEdit().load(source, target, true); - - } - - @Override - public void copyStubForDisplay(Route source, Route target) { - - getBinderStubForDisplay().load(source, target, true); - - } - protected RouteDAO getDao() { return (RouteDAO) getDao(Route.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java index 9be981c..6030cd3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java @@ -3,10 +3,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** * Created on 4/28/15. @@ -21,18 +19,6 @@ public interface SchoolEstimateService extends ObserveService { @Commit void save(SetSeine parent); - @NoTransaction - TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit(); - - @NoTransaction - void copyForEdit(SetSeine source, SetSeine target); - - @NoTransaction - TopiaEntityBinder<SchoolEstimate> getBinderForSchoolEstimateEdit(); - - @NoTransaction - void copyForEdit(SchoolEstimate source, SchoolEstimate target); - EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java index 1959817..351ec2b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -7,7 +7,6 @@ import fr.ird.observe.services.AbstractObserveService; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.List; @@ -26,7 +25,8 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements SetSeine parentToLoad = findByTopiaId(SetSeine.class, setSeineId); SetSeine parentLoaded = getDao(SetSeine.class).newInstance(); - copyForEdit(parentToLoad, parentLoaded); + + copy(SetSeine.class, BinderService.EDIT_SCHOOL_ESTIMATE, parentToLoad, parentLoaded); if (!parentToLoad.isSchoolEstimateEmpty()) { @@ -37,7 +37,7 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements for (SchoolEstimate sourceChild : parentToLoad.getSchoolEstimate()) { SchoolEstimate targetChild = childDao.newInstance(); - copyForEdit(sourceChild, targetChild); + copy(SchoolEstimate.class, BinderService.EDIT, sourceChild, targetChild); childs.add(targetChild); } @@ -53,103 +53,11 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements @Override public void save(SetSeine parent) { - TopiaEntityBinder<SetSeine> parentBinder = getBinderForSetSeineEdit(); - TopiaEntityBinder<SchoolEstimate> childBinder = getBinderForSchoolEstimateEdit(); + TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, BinderService.EDIT_SCHOOL_ESTIMATE); + TopiaEntityBinder<SchoolEstimate> childBinder = getBinder(SchoolEstimate.class, BinderService.EDIT); doSaveList(parent, new SaveCollectionAction<SetSeine, SchoolEstimate>( SetSeine.class, SchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); -// -// @Override -// public void prepareSave(SetSeine parent, Collection<SchoolEstimate> toSaves) { -// for (SchoolEstimate child : toSaves) { -// child.setSetSeine(parent); -// } -// } -// -// @Override -// public SetSeine onUpdateParent(SetSeine parentToSave, SetSeine parentSaved) { -// getBinderForSetSeineEdit().copyExcluding(parentToSave, parentSaved, SetSeine.PROPERTY_SCHOOL_ESTIMATE); -// getDao(SetSeine.class).update(parentSaved); -// return parentSaved; -// } -// -// @Override -// public SchoolEstimate onCreateChild(SchoolEstimate childToSave) { -// SchoolEstimate childSaved = getDao(SchoolEstimate.class).newInstance(); -// getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); -// getDao(SchoolEstimate.class).create(childSaved); -// return childSaved; -// } -// -// @Override -// public SchoolEstimate onUpdateChild(SchoolEstimate childToSave, SchoolEstimate childSaved) { -// getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); -// getDao(SchoolEstimate.class).update(childSaved); -// return childSaved; -// } -// }); - - } - - @Override - public TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit() { - - TopiaEntityBinder<SetSeine> binder = loadBinder("-forSchoolEstimateEdit", SetSeine.class, new CreateBinder<SetSeine>() { - - @Override - public BinderModelBuilder<SetSeine, SetSeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<SetSeine, SetSeine> builder = binderService.newBinderBuilder( - SetSeine.class, - SetSeine.PROPERTY_COMMENT, SetSeine.PROPERTY_SCHOOL_ESTIMATE); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(SetSeine source, SetSeine target) { - - getBinderForSetSeineEdit().load(source, target, true); - - } - - @Override - public TopiaEntityBinder<SchoolEstimate> getBinderForSchoolEstimateEdit() { - - TopiaEntityBinder<SchoolEstimate> binder = loadBinder("-forEdit", SchoolEstimate.class, new CreateBinder<SchoolEstimate>() { - - @Override - public BinderModelBuilder<SchoolEstimate, SchoolEstimate> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<SchoolEstimate, SchoolEstimate> builder = binderService.newBinderBuilder( - SchoolEstimate.class, - SchoolEstimate.PROPERTY_SET_SEINE, - SchoolEstimate.PROPERTY_SPECIES, - SchoolEstimate.PROPERTY_TOTAL_WEIGHT, - SchoolEstimate.PROPERTY_MEAN_WEIGHT); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(SchoolEstimate source, SchoolEstimate target) { - - getBinderForSchoolEstimateEdit().load(source, target, true); - } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java index 9d86f50..94d2d76 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.Date; @@ -29,10 +27,4 @@ public interface SetSeineService extends ObserveService { @Commit void delete(String activitySeineId, String setSeineId); - - @NoTransaction - TopiaEntityBinder<SetSeine> getBinderForEdit(); - - @NoTransaction - void copyForEdit(SetSeine source, SetSeine target); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java index cc31a3d..ed9bd24 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java @@ -9,9 +9,7 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.SetSeineDAO; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Date; @@ -42,7 +40,7 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe SetSeine loaded = getDao().newInstance(); SetSeine toLoad = getDao().findByTopiaId(setSeineId); - copyForEdit(toLoad, loaded); + copy(SetSeine.class, BinderService.EDIT, toLoad, loaded); //FIXME See why need this ? if (!loaded.isTargetSampleEmpty()) { @@ -101,7 +99,7 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe public SetSeine onCreate(ActivitySeine parent, SetSeine toCreate) { SetSeine created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(SetSeine.class, BinderService.EDIT, toCreate, created); parent.setSetSeine(created); @@ -111,7 +109,10 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe @Override public SetSeine onUpdate(ActivitySeine parent, SetSeine toUpdate, SetSeine updated) { - getBinderForEdit().copyExcluding(toUpdate, updated, + copyExcluding(SetSeine.class, + BinderService.EDIT, + toUpdate, + updated, SetSeine.PROPERTY_TARGET_SAMPLE, SetSeine.PROPERTY_NON_TARGET_SAMPLE); return updated; @@ -139,53 +140,6 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe } - @Override - public TopiaEntityBinder<SetSeine> getBinderForEdit() { - - TopiaEntityBinder<SetSeine> binder = loadBinder("-forEdit", SetSeine.class, new CreateBinder<SetSeine>() { - - @Override - public BinderModelBuilder<SetSeine, SetSeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<SetSeine, SetSeine> builder = binderService.newBinderBuilder( - SetSeine.class, - SetSeine.PROPERTY_COMMENT, - SetSeine.PROPERTY_SUPPORT_VESSEL_NAME, - SetSeine.PROPERTY_START_TIME, - SetSeine.PROPERTY_END_SET_TIME_STAMP, - SetSeine.PROPERTY_END_PURSING_TIME_STAMP, - SetSeine.PROPERTY_CURRENT_DIRECTION, - SetSeine.PROPERTY_CURRENT_SPEED, - SetSeine.PROPERTY_REASON_FOR_NULL_SET, - SetSeine.PROPERTY_SCHOOL_THICKNESS, - SetSeine.PROPERTY_MAX_GEAR_DEPTH, - SetSeine.PROPERTY_SCHOOL_MEAN_DEPTH, - SetSeine.PROPERTY_SCHOOL_TOP_DEPTH, - SetSeine.PROPERTY_CURRENT_MEASURE_DEPTH, - SetSeine.PROPERTY_TARGET_DISCARDED, - SetSeine.PROPERTY_NON_TARGET_DISCARDED, - SetSeine.PROPERTY_SCHOOL_TYPE, - SetSeine.PROPERTY_SONAR_USED, - SetSeine.PROPERTY_TARGET_SAMPLE, - SetSeine.PROPERTY_NON_TARGET_SAMPLE); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(SetSeine source, SetSeine target) { - - getBinderForEdit().load(source, target, true); - - } - protected SetSeineDAO getDao() { return (SetSeineDAO) getDao(SetSeine.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java new file mode 100644 index 0000000..b70ca5d --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java @@ -0,0 +1,24 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public interface TargetLengthService extends ObserveService { + + TargetSample loadForEdit(String setId, boolean discarded); + + @Commit + void save(TargetSample parent); + + @NoTransaction + EntityListUpdator<TargetSample, TargetLength> getListUpdator(); + + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java new file mode 100644 index 0000000..339a346 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java @@ -0,0 +1,91 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.Collection; +import java.util.List; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class TargetLengthServiceImpl extends AbstractObserveService implements TargetLengthService { + + @Override + public TargetSample loadForEdit(String setId, boolean discarded) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setId); + + TargetSample toLoad = null; + + if (!setSeine.isNonTargetSampleEmpty()) { + + List<TargetSample> targetSamples = setSeine.getTargetSample(); + for (TargetSample targetSample : targetSamples) { + + Boolean isDiscarded = targetSample.getDiscarded(); + + if (discarded == (isDiscarded != null && isDiscarded)) { + toLoad = targetSample; + } + + } + + } + + TargetSample loaded = getDao(TargetSample.class).newInstance(); + + if (toLoad != null) { + + copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGHT, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); + + for (TargetLength childToLoad : toLoad.getTargetLength()) { + + TargetLength childLoaded = getDao(TargetLength.class).newInstance(); + + copy(TargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + + loaded.addTargetLength(childLoaded); + + } + } + + + return loaded; + } + + @Override + public void save(TargetSample parent) { + + TopiaEntityBinder<TargetSample> parentBinder = getBinder(TargetSample.class, BinderService.EDIT_TARGET_LENGHT); + TopiaEntityBinder<TargetLength> childbinder = getBinder(TargetLength.class, BinderService.EDIT); + + doSaveList(parent, new SaveCollectionAction<TargetSample, TargetLength>( + TargetSample.class, TargetLength.class, getListUpdator(), parentBinder, childbinder) { + + @Override + public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { + + for (TargetLength targetLength : tosaves) { + + // on attache a l'echantillon + targetLength.setTargetSample(parent); + } + + }git + }); + } + + @Override + public EntityListUpdator<TargetSample, TargetLength> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + TargetSample.class, + TargetLength.class, + TargetSample.PROPERTY_TARGET_LENGTH); + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java index 82fe30f..689f730 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java @@ -5,7 +5,6 @@ import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.Collection; import java.util.List; @@ -32,9 +31,6 @@ public interface TargetSampleService extends ObserveService { @Commit void delete(String setId, TargetSample bean); - String save(String setSeineId, TargetSample toSave, Collection<TargetLength> childrenToSave); - - TopiaEntityBinder<TargetLength> getChildBinderForEdit(); - - TopiaEntityBinder<TargetSample> getBinderForEdit(); + @Commit + String save(String setSeineId, TargetSample toSave); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 5fd0a8f..1b6f8a1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -11,8 +11,6 @@ import fr.ird.observe.entities.seine.TargetSampleDAO; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.Collection; @@ -106,13 +104,13 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T if (toLoad != null) { - getBinderForEdit().copy(toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); + copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGHT, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); for (TargetLength childToLoad : toLoad.getTargetLength()) { TargetLength childLoaded = getChildDao().newInstance(); - getChildBinderForEdit().copy(childToLoad, childLoaded); + copy(TargetLength.class, BinderService.EDIT, childToLoad, childLoaded); loaded.addTargetLength(childLoaded); @@ -179,122 +177,29 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } @Override - public String save(String setSeineId, TargetSample toSave, Collection<TargetLength> childrenToSave) { - -// String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { -// @Override -// public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { -// -// TargetSample created = getDao().create(); -// getBinderForEdit().copyExcluding(toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); -// parent.addTargetSample(created); -// getDao().update(created); -// return created; -// } -// -// @Override -// public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { -// getBinderForEdit().copyExcluding(toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); -// getDao().update(beanToSave); -// return beanToSave; -// } -// }); -// -// toSave.setTopiaId(savedId); -// -// doSaveList(toSave, childrenToSave, new SaveCollectionAction<TargetSample, TargetLength>(TargetSample.class, TargetLength.class) { -// -// @Override -// public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { -// -// for (TargetLength targetLength : tosaves) { -// -// // on attache a l'echantillon -// targetLength.setTargetSample(parent); -// } -// -// } -// -// @Override -// public Collection<TargetLength> getChildren(TargetSample parent) { -// return parent.getTargetLength(); -// } -// -// @Override -// public void clearChildren(TargetSample parent) { -// parent.clearTargetLength(); -// } -// -// @Override -// public TargetLength onCreateChild(TargetLength childToSave) { -// TargetLength childSaved = getChildDao().create(); -// getChildBinderForEdit().copy(childToSave, childSaved); -// getChildDao().update(childSaved); -// return childSaved; -// } -// -// @Override -// public TargetLength onUpdateChild(TargetLength childToSave, TargetLength childSaved) { -// getChildBinderForEdit().copy(childToSave, childSaved); -// getChildDao().update(childSaved); -// return childSaved; -// } -// -// @Override -// public void addChild(TargetSample parent, TargetLength child) { -// parent.addTargetLength(child); -// } -// }); - - return null; - - } - - @Override - public TopiaEntityBinder<TargetLength> getChildBinderForEdit() { - TopiaEntityBinder<TargetLength> r = loadBinder("-forEdit", TargetLength.class, new CreateBinder<TargetLength>() { + public String save(String setSeineId, TargetSample toSave) { + String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { @Override - public BinderModelBuilder<TargetLength, TargetLength> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TargetLength, TargetLength> builder = binderService.newBinderBuilder( - TargetLength.class, - TargetLength.PROPERTY_TARGET_SAMPLE, - TargetLength.PROPERTY_SPECIES, - TargetLength.PROPERTY_LENGTH, - TargetLength.PROPERTY_LENGTH_SOURCE, - TargetLength.PROPERTY_WEIGHT, - TargetLength.PROPERTY_WEIGHT_SOURCE, - TargetLength.PROPERTY_COUNT, - TargetLength.PROPERTY_MEASURE_TYPE, - TargetLength.PROPERTY_ACQUISITION_MODE); - - return builder; - } - - }); + public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { - return r; - } - - @Override - public TopiaEntityBinder<TargetSample> getBinderForEdit() { - TopiaEntityBinder<TargetSample> r = loadBinder("-forEdit", TargetSample.class, new CreateBinder<TargetSample>() { + TargetSample created = getDao().create(); + copyExcluding(TargetSample.class, BinderService.EDIT, toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); + parent.addTargetSample(created); + getDao().update(created); + return created; + } @Override - public BinderModelBuilder<TargetSample, TargetSample> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TargetSample, TargetSample> builder = binderService.newBinderBuilder( - TargetSample.class, - TargetSample.PROPERTY_TARGET_LENGTH, - TargetSample.PROPERTY_COMMENT); - - return builder; + public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { + copyExcluding(TargetSample.class, BinderService.EDIT, toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); + getDao().update(beanToSave); + return beanToSave; } - }); - return r; + return savedId; + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java index 4ba8a05..e3b6680 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -32,16 +30,4 @@ public interface TripSeineService extends ObserveService { @Commit void delete(String idToDelete); - @NoTransaction - TopiaEntityBinder<TripSeine> getBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<TripSeine> getBinderStubForDisplay(); - - @NoTransaction - void copyForEdit(TripSeine source, TripSeine target); - - @NoTransaction - void copyStubForDisplay(TripSeine source, TripSeine target); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index b092415..f910d1f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -7,10 +7,7 @@ import fr.ird.observe.entities.seine.Routes; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.entities.seine.TripSeineDAO; import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Date; import java.util.List; @@ -50,7 +47,7 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip TripSeine loaded = getDao().newInstance(); TripSeine toLoad = getDao().findByTopiaId(tripSeineId); - copyForEdit(toLoad, loaded); + copy(TripSeine.class, BinderService.EDIT, toLoad, loaded); if (!loaded.isRouteEmpty()) { @@ -108,13 +105,13 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip @Override public TripSeine onCreate(Program parent, TripSeine toCreate) { TripSeine created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(TripSeine.class, BinderService.EDIT, toCreate, created); return created; } @Override public TripSeine onUpdate(Program parentBean, TripSeine toUpdate, TripSeine updated) { - getBinderForEdit().copyExcluding(toUpdate, updated, TripSeine.PROPERTY_ROUTE); + copyExcluding(TripSeine.class, BinderService.EDIT, toUpdate, updated, TripSeine.PROPERTY_ROUTE); return updated; } }); @@ -128,83 +125,4 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip doDelete(null, idtoDelete, new DeleteAction<Program, TripSeine>(Program.class, TripSeine.class)); } - @Override - public TopiaEntityBinder<TripSeine> getBinderForEdit() { - - TopiaEntityBinder<TripSeine> r = loadBinder("-forEdit", TripSeine.class, new CreateBinder<TripSeine>() { - - @Override - public BinderModelBuilder<TripSeine, TripSeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TripSeine, TripSeine> builder = binderService.newBinderBuilder( - TripSeine.class, - TripSeine.PROPERTY_START_DATE, - TripSeine.PROPERTY_END_DATE, - TripSeine.PROPERTY_FORMS_URL, - TripSeine.PROPERTY_REPORTS_URL, - TripSeine.PROPERTY_COMMENT, - TripSeine.PROPERTY_VESSEL, - TripSeine.PROPERTY_OBSERVER, - TripSeine.PROPERTY_CAPTAIN, - TripSeine.PROPERTY_DATA_ENTRY_OPERATOR, - TripSeine.PROPERTY_OCEAN, - TripSeine.PROPERTY_DEPARTURE_HARBOUR, - TripSeine.PROPERTY_LANDING_HARBOUR, - TripSeine.PROPERTY_PROGRAM, - TripSeine.PROPERTY_ROUTE, - TripSeine.PROPERTY_ERS_ID, - TripSeine.PROPERTY_OPEN); - - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); - - return builder; - } - - }); - - return r; - - } - - @Override - public TopiaEntityBinder<TripSeine> getBinderStubForDisplay() { - - TopiaEntityBinder<TripSeine> r = loadBinder("-stubForDisplay", TripSeine.class, new CreateBinder<TripSeine>() { - - @Override - public BinderModelBuilder<TripSeine, TripSeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TripSeine, TripSeine> builder = binderService.newBinderBuilder( - TripSeine.class, - TripSeine.PROPERTY_START_DATE, - TripSeine.PROPERTY_END_DATE, - TripSeine.PROPERTY_OPEN, - TripSeine.PROPERTY_OBSERVER, - TripSeine.PROPERTY_VESSEL, - TripSeine.PROPERTY_PROGRAM); - - return builder; - } - - }); - - return r; - - } - - @Override - public void copyForEdit(TripSeine source, TripSeine target) { - - getBinderForEdit().load(source, target, true); - - } - - @Override - public void copyStubForDisplay(TripSeine source, TripSeine target) { - - getBinderStubForDisplay().load(source, target, true); - - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java index 904c177..913edb4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -179,7 +180,7 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { } SetSeine bean = getBean(); - service.copyForEdit(loaded, bean); + copy(SetSeine.class, BinderService.EDIT, loaded, bean); Date date = service.getRouteDate(routeId); Date time = bean.getStartTime(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java index 5b866ce..5b80eeb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.list.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.seine.ActivitySeine; @@ -112,7 +113,7 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit Route loaded = routeService.getRouteStub(selectedId); Route bean = getBean(); - routeService.copyStubForDisplay(loaded, bean); + copy(Route.class, BinderService.DISPLAY, loaded, bean); ActivitySeineService activityService = getService(ActivitySeineService.class); List<ActivitySeine> activitySeines = activityService.getActivitySeineStubByRoute(selectedId); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java index d8276b9..f24e760 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java @@ -21,8 +21,8 @@ */ package fr.ird.observe.ui.content.list.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; @@ -109,7 +109,7 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { TripSeineService tripService = getService(TripSeineService.class); TripSeine loaded = tripService.getTripSeineStub(selectedId); TripSeine bean = getBean(); - tripService.copyStubForDisplay(loaded, bean); + copy(TripSeine.class, BinderService.DISPLAY, loaded, bean); RouteService routeService = getService(RouteService.class); List<Route> routes = routeService.getRouteStubByTrip(selectedId); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java index 5f58080..2fc2bd5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.open.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; @@ -146,7 +147,7 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { } Route bean = getBean(); - service.copyForEdit(loaded, bean); + copy(Route.class, BinderService.EDIT, loaded, bean); finalizeOpenUI(mode, create); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java index 27ca6a9..619a52c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.open.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; @@ -175,7 +176,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { } TripSeine bean = getBean(); - service.copyForEdit(loaded, bean); + copy(TripSeine.class, BinderService.EDIT, loaded, bean); getUi().getTripSeineTabPane().setSelectedIndex(0); buildTripMap = true; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index 771e474..04d98f4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; @@ -67,7 +68,7 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati FloatingObject loaded = service.loadForEdit(floatingObjectId); - service.copyForEdit(loaded, getBean()); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES, loaded, getBean()); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java index 853fb15..49902b0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; @@ -67,7 +68,7 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin FloatingObject loaded = service.loadForEdit(floatingObjectId); - service.copyForEdit(loaded, getBean()); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE, loaded, getBean()); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index 01b461d..bc72d5d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; @@ -80,7 +81,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch SetSeine loaded = service.loadForEdit(setSeineId); - service.copyForEdit(loaded, getBean()); + copy(SetSeine.class, BinderService.EDIT_SCHOOL_ESTIMATE, loaded, getBean()); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index 098aafe..15b28a1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; @@ -30,6 +31,7 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.data.seine.TargetLengthService; import fr.ird.observe.services.data.seine.TargetSampleService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -131,67 +133,69 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T } @Override - protected TargetSample loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean() { - String setId = dataContext.getSelectedSetId(); - - TargetSampleService service = getService(TargetSampleService.class); + String setId = getDataContext().getSelectedSetId(); - if (mode == ContentMode.UPDATE) { + TargetSample targetSample = getService(TargetLengthService.class).loadForEdit(setId, discarded); - // on ne charge les speciess uniquement si on est en mode édition + copy(TargetSample.class, BinderService.EDIT_TARGET_LENGHT, targetSample, getBean()); - List<Species> speciesList = service.getAvailableEspeceForTargetSample(setId, discarded); + } - getUi().getSpecies().setData(speciesList); - } + @Override + protected void loadTableEditBeanForm(ContentMode mode) { - TargetSample beanToLoad = getService(TargetSampleService.class).getTargetSample(setId, discarded); + if (mode == ContentMode.UPDATE) { - TargetSample editBean = getBean(); + String setId = getDataContext().getSelectedSetId(); - service.getBinderForEdit().copy(beanToLoad, editBean); + // on ne charge les speciess uniquement si on est en mode édition + List<Species> speciesList = getService(TargetSampleService.class).getAvailableEspeceForTargetSample(setId, discarded); - getModel().getChildsUpdator().setChilds(editBean, beanToLoad.getTargetLength()); + getUi().getSpecies().setData(speciesList); + } getModel().setMode(mode); + // initialisation du modèle du tableau getUi().getTableModel().attachModel(); - return editBean; } - - @Override - protected void doPersist(TargetSample bean, DataService dataService, DataSource dataSource) throws DataSourceException { - - TargetSampleService service = getService(TargetSampleService.class); + protected void doPersist(TargetSample editBean) { String setId = getDataContext().getSelectedSetId(); - if (bean.getTopiaId() != null && bean.isTargetLengthEmpty()) { + if (editBean.getTopiaId() != null && editBean.isTargetLengthEmpty()) { // remove orphan target sample if (log.isInfoEnabled()) { - log.info("Remove obsolete targetSample " + bean.getTopiaId() + " from Set: " + setId); + log.info("Remove obsolete targetSample " + editBean.getTopiaId() + " from Set: " + setId); } - service.delete(setId, bean); + + getService(TargetSampleService.class).delete(setId, editBean); } else { - String savedId = service.save(setId, bean, bean.getTargetLength()); + String savedId = getService(TargetSampleService.class).save(setId, editBean); - bean.setTopiaId(savedId); + editBean.setTopiaId(savedId); + getService(TargetLengthService.class).save(editBean); } } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + @Override protected void onSelectedRowChanged(int editingRow, TargetLength bean, boolean create) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 7dfb645d04e6361f461d56bbff2e8f199ee0d85b Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 16:08:02 2015 +0200 supression de mauvaise saisie --- .../fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java index 339a346..87f5db8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java @@ -77,7 +77,7 @@ public class TargetLengthServiceImpl extends AbstractObserveService implements T targetLength.setTargetSample(parent); } - }git + } }); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 2bb8a87be5471ec217f018dbe473c72b6f5d7967 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 17:39:28 2015 +0200 échantillon acessoire capturé. --- .../main/java/fr/ird/observe/BinderService.java | 53 +++++++++- .../data/seine/NonTargetLengthService.java | 23 +++++ .../data/seine/NonTargetLengthServiceImpl.java | 73 ++++++++++++++ .../data/seine/NonTargetSampleService.java | 11 ++- .../data/seine/NonTargetSampleServiceImpl.java | 74 ++++++++++++-- .../data/seine/TargetLengthServiceImpl.java | 4 +- .../data/seine/TargetSampleServiceImpl.java | 2 +- .../table/impl/seine/NonTargetSampleUIHandler.java | 108 ++++++--------------- .../table/impl/seine/TargetSampleUIHandler.java | 2 +- 9 files changed, 257 insertions(+), 93 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 6aea2c7..797b595 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -39,6 +39,8 @@ import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.WeightMeasure; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.entities.seine.Route; @@ -83,7 +85,7 @@ public class BinderService { public static final String EDIT_TDR = "editTdr"; - public static final String EDIT_TARGET_LENGHT = "editTargetLenght"; + public static final String EDIT_TARGET_LENGTH = "editTargetLength"; public static final String EDIT_SCHOOL_ESTIMATE = "editSchoolEstimate"; @@ -91,6 +93,8 @@ public class BinderService { public static final String EDIT_OBJECT_OBSERVED_SPECIES = "editObjectObservedSpecies"; + public static final String EDIT_NON_TARGET_LENGTH = "editNonTargetLength"; + static { registerBinders(); @@ -618,7 +622,7 @@ public class BinderService { TargetSample.PROPERTY_TARGET_LENGTH, TargetSample.PROPERTY_COMMENT); - registerTopiaBinder(TargetSample.class, builder, EDIT_TARGET_LENGHT); + registerTopiaBinder(TargetSample.class, builder, EDIT_TARGET_LENGTH); } @@ -774,6 +778,46 @@ public class BinderService { } + { + + BinderModelBuilder<NonTargetLength, NonTargetLength> builder = newBinderBuilder( + NonTargetLength.class, + NonTargetLength.PROPERTY_SPECIES, + NonTargetLength.PROPERTY_LENGTH, + NonTargetLength.PROPERTY_LENGTH_SOURCE, + NonTargetLength.PROPERTY_WEIGHT, + NonTargetLength.PROPERTY_WEIGHT_SOURCE, + NonTargetLength.PROPERTY_SEX, + NonTargetLength.PROPERTY_COUNT, + NonTargetLength.PROPERTY_ACQUISITION_MODE, + NonTargetLength.PROPERTY_PICTURES_REFERENCES); + + registerTopiaBinder(NonTargetLength.class, builder, EDIT); + + } + + { + + BinderModelBuilder<NonTargetSample, NonTargetSample> builder = newBinderBuilder( + NonTargetSample.class, + NonTargetSample.PROPERTY_NON_TARGET_LENGTH, + NonTargetSample.PROPERTY_COMMENT); + + registerTopiaBinder(NonTargetSample.class, builder, EDIT_NON_TARGET_LENGTH); + + } + + { + + BinderModelBuilder<NonTargetSample, NonTargetSample> builder = newBinderBuilder( + NonTargetSample.class, + NonTargetSample.PROPERTY_NON_TARGET_LENGTH, + NonTargetSample.PROPERTY_COMMENT); + + registerTopiaBinder(NonTargetSample.class, builder, EDIT); + + } + } @@ -789,6 +833,11 @@ public class BinderService { binder.copyExcluding(source, target, propertyNames); + /* FIXME sbavencoff 29/04/2015 bind techincal fields */ + target.setTopiaId(source.getTopiaId()); + target.setTopiaVersion(source.getTopiaVersion()); + target.setTopiaCreateDate(source.getTopiaCreateDate()); + } public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java new file mode 100644 index 0000000..c52635d --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java @@ -0,0 +1,23 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.entities.seine.NonTargetSample; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public interface NonTargetLengthService extends ObserveService { + + NonTargetSample loadForEdit(String setId); + + @Commit + void save(NonTargetSample parent); + + @NoTransaction + EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator(); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java new file mode 100644 index 0000000..2e068b6 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java @@ -0,0 +1,73 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.entities.seine.NonTargetSample; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.List; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class NonTargetLengthServiceImpl extends AbstractObserveService implements NonTargetLengthService { + + @Override + public NonTargetSample loadForEdit(String setId) { + + SetSeine setSeine = findByTopiaId(SetSeine.class, setId); + + NonTargetSample toLoad = null; + + if (setSeine.isNonTargetSampleEmpty()) { + + toLoad = null; + + } else { + + List<NonTargetSample> nonTargetSamples = setSeine.getNonTargetSample(); + toLoad = nonTargetSamples.get(0); + + } + + NonTargetSample loaded = getDao(NonTargetSample.class).newInstance(); + + if (toLoad != null) { + + copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + + for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { + + NonTargetLength childLoaded = getDao(NonTargetLength.class).newInstance(); + + copy(NonTargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + + loaded.addNonTargetLength(childLoaded); + + } + } + + return loaded; + } + + @Override + public void save(NonTargetSample parent) { + + TopiaEntityBinder<NonTargetSample> parentBinder = getBinder(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH); + TopiaEntityBinder<NonTargetLength> childbinder = getBinder(NonTargetLength.class, BinderService.EDIT); + + doSaveList(parent, new SaveCollectionAction<NonTargetSample, NonTargetLength>( + NonTargetSample.class, NonTargetLength.class, getListUpdator(), parentBinder, childbinder)); + } + + @Override + public EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + NonTargetSample.class, + NonTargetLength.class, + NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java index 6464335..c4bc584 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java @@ -2,6 +2,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.entities.seine.NonTargetSample; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; import java.util.Collection; @@ -17,7 +19,7 @@ public interface NonTargetSampleService extends ObserveService { List<Species> getAvailableEspeceForNonTargetSample(String setSeineId); - String getNonTargetSampleId(String setSeineId); + NonTargetSample getNonTargetSample(String setSeineId); boolean canUseNonTargetSample(String setSeineId); @@ -25,4 +27,11 @@ public interface NonTargetSampleService extends ObserveService { List<Species> speciessUsed, Collection<Species> speciessToDelete, List<NonTargetLength> tailleToDelete); + + @Commit + void delete(String setId, NonTargetSample editBean); + + @Commit + String save(String setId, NonTargetSample editBean); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index d3c700a..06eeb03 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -1,9 +1,11 @@ package fr.ird.observe.services.data.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; +import fr.ird.observe.entities.seine.NonTargetSampleDAO; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.logging.Log; @@ -23,7 +25,11 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement /** Logger. */ private static final Log log = LogFactory.getLog(NonTargetSampleServiceImpl.class); - + + protected NonTargetSampleDAO getDao() { + return (NonTargetSampleDAO) getDao(NonTargetSample.class); + } + @Override public List<Species> getAvailableEspeceForNonTargetSample(String setSeineId) { @@ -50,24 +56,42 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public String getNonTargetSampleId(String setSeineId) { + public NonTargetSample getNonTargetSample(String setSeineId) { SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - String nonTargetSampleId; + NonTargetSample toLoad; if (setSeine.isNonTargetSampleEmpty()) { - nonTargetSampleId = null; + toLoad = null; } else { List<NonTargetSample> nonTargetSamples = setSeine.getNonTargetSample(); - nonTargetSampleId = nonTargetSamples.get(0).getTopiaId(); + toLoad = nonTargetSamples.get(0); } - return nonTargetSampleId; + NonTargetSample loaded = getDao().newInstance(); + + if (toLoad != null) { + + copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + + for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { + + NonTargetLength childLoaded = getDao(NonTargetLength.class).newInstance(); + + copy(NonTargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + + loaded.addNonTargetLength(childLoaded); + + } + } + + + return loaded; } @@ -113,4 +137,42 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } + @Override + public void delete(String setId, NonTargetSample bean) { + doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + @Override + public void onDelete(SetSeine parent, NonTargetSample toDelete) { + super.onDelete(parent, toDelete); + parent.removeNonTargetSample(toDelete); + } + }); + + } + + @Override + public String save(String setSeineId, NonTargetSample toSave) { + + String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + @Override + public NonTargetSample onCreate(SetSeine parent, NonTargetSample toCreate) { + + NonTargetSample created = getDao().create(); + copyExcluding(NonTargetSample.class, BinderService.EDIT, toCreate, created, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + parent.addNonTargetSample(created); + getDao().update(created); + return created; + } + + @Override + public NonTargetSample onUpdate(SetSeine parentBean, NonTargetSample toSave, NonTargetSample beanToSave) { + copyExcluding(NonTargetSample.class, BinderService.EDIT, toSave, beanToSave, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + getDao().update(beanToSave); + return beanToSave; + } + }); + + return savedId; + + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java index 87f5db8..d6b6a85 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java @@ -42,7 +42,7 @@ public class TargetLengthServiceImpl extends AbstractObserveService implements T if (toLoad != null) { - copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGHT, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); + copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); for (TargetLength childToLoad : toLoad.getTargetLength()) { @@ -62,7 +62,7 @@ public class TargetLengthServiceImpl extends AbstractObserveService implements T @Override public void save(TargetSample parent) { - TopiaEntityBinder<TargetSample> parentBinder = getBinder(TargetSample.class, BinderService.EDIT_TARGET_LENGHT); + TopiaEntityBinder<TargetSample> parentBinder = getBinder(TargetSample.class, BinderService.EDIT_TARGET_LENGTH); TopiaEntityBinder<TargetLength> childbinder = getBinder(TargetLength.class, BinderService.EDIT); doSaveList(parent, new SaveCollectionAction<TargetSample, TargetLength>( diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 1b6f8a1..084a408 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -104,7 +104,7 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T if (toLoad != null) { - copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGHT, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); + copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); for (TargetLength childToLoad : toLoad.getTargetLength()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index 7d3cd34..2bd8bfa 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -21,17 +21,16 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Sex; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.data.seine.NonTargetLengthService; import fr.ird.observe.services.data.seine.NonTargetSampleService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -118,119 +117,68 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean() { - String setId = dataContext.getSelectedSetId(); + String setId = getDataContext().getSelectedSetId(); - // on doit récupérer l'unique échantillonThon de la calée - NonTargetSampleService service = getService(NonTargetSampleService.class); - String id = service.getNonTargetSampleId(setId); - return id; + NonTargetSample nonTargetSample = getService(NonTargetLengthService.class).loadForEdit(setId); + + copy(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, nonTargetSample, getBean()); } @Override - protected NonTargetSample loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadTableEditBeanForm(ContentMode mode) { List<Species> speciesList; - String setId = dataContext.getSelectedSetId(); - if (mode == ContentMode.UPDATE) { + String setId = getDataContext().getSelectedSetId(); + NonTargetSampleService service = getService(NonTargetSampleService.class); speciesList = service.getAvailableEspeceForNonTargetSample(setId); - } else { - speciesList = new ArrayList<Species>(); - } - - ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); - - // on doit récupérer l'unique échantillonThon de la calée - String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); - - NonTargetSample editBean = getBean(); - - if (log.isInfoEnabled()) { - log.info(prefix + " - set id : " + setId); - log.info(prefix + " - echantillon faune id : " + id); - log.info(prefix + " - edit bean id : " + editBean.getTopiaId()); - } - - if (id == null) { - - // l'échantillon n'existe pas encore, donc rien a faire - getLoadBinder().load(null, editBean, true); - - getModel().getChildsUpdator().setChilds(editBean, new ArrayList<NonTargetLength>()); - - } else { - - // preparation du bean d'édition - dataService.loadEditEntity(dataSource, id, getLoadExecutor()); + ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); } getModel().setMode(mode); + // initialisation du modèle du tableau getUi().getTableModel().attachModel(); - return editBean; } @Override - protected boolean prepareSave(NonTargetSample bean, List<NonTargetLength> objets) throws DataSourceException { - - boolean withLengths = !objets.isEmpty(); + protected void doPersist(NonTargetSample editBean) { - if (withLengths) { + String setId = getDataContext().getSelectedSetId(); - if (bean.getTopiaId() == null) { + if (editBean.getTopiaId() != null && editBean.isNonTargetLengthEmpty()) { - String setId = getDataContext().getSelectedSetId(); + // remove orphan target sample + if (log.isInfoEnabled()) { + log.info("Remove obsolete nonTargetSample " + editBean.getTopiaId() + " from Set: " + setId); + } - // l'échantillon n'existe pas encore, il faut le créer + getService(NonTargetSampleService.class).delete(setId, editBean); - if (log.isDebugEnabled()) { - log.debug("Will create nonTargetSample " + bean + " for " + setId); - } + } else { - getDataService().create(getDataSource(), setId, bean, null, getCreateExecutor()); + String savedId = getService(NonTargetSampleService.class).save(setId, editBean); - } + editBean.setTopiaId(savedId); + getService(NonTargetLengthService.class).save(editBean); } - - return true; - } - @Override - protected void doPersist(NonTargetSample bean, DataService dataService, DataSource dataSource) throws DataSourceException { - - if (bean.getTopiaId() != null && bean.isNonTargetLengthEmpty()) { - - // remove orphan non target sample - - String setId = getDataContext().getSelectedSetId(); - if (log.isInfoEnabled()) { - log.info("Remove obsolete nonTargetSample " + bean.getTopiaId() + " from Set: " + setId); - } - getDataService().delete(getDataSource(), setId, bean, getDeleteExecutor()); - - } else { - - // normal persist - super.doPersist(bean, dataService, dataSource); - - } + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index 15b28a1..91434fa 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -139,7 +139,7 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T TargetSample targetSample = getService(TargetLengthService.class).loadForEdit(setId, discarded); - copy(TargetSample.class, BinderService.EDIT_TARGET_LENGHT, targetSample, getBean()); + copy(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, targetSample, getBean()); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 7b30af9618610b61ff151933645fa2f60bc2d426 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 29 21:04:42 2015 +0200 utilisation des binders venant du service BinderService (sauf pour les referentiels) (refs #7017) --- .../main/java/fr/ird/observe/BinderService.java | 1524 +++++++++++++------- .../fr/ird/observe/ui/content/ContentUIModel.java | 66 +- .../content/impl/longline/BranchlineUIModel.java | 38 +- .../longline/LonglineDetailCompositionUIModel.java | 123 +- .../longline/LonglineGlobalCompositionUIModel.java | 17 +- .../content/impl/longline/SetLonglineUIModel.java | 65 +- .../seine/ActivitySeineObservedSystemUIModel.java | 17 +- ...tingObjectTransmittingBuoyOperationUIModel.java | 20 +- .../content/impl/seine/FloatingObjectUIModel.java | 19 +- .../ui/content/impl/seine/SetSeineUIModel.java | 32 +- .../ui/content/list/ContentListUIModel.java | 3 +- .../impl/longline/ActivityLonglinesUIModel.java | 25 - .../list/impl/longline/TripLonglinesUIModel.java | 19 - .../list/impl/seine/ActivitySeinesUIModel.java | 30 - .../ui/content/list/impl/seine/RoutesUIModel.java | 17 - .../content/list/impl/seine/TripSeinesUIModel.java | 19 - .../ui/content/open/ContentOpenableUIModel.java | 3 +- .../impl/longline/ActivityLonglineUIModel.java | 28 - .../open/impl/longline/TripLonglineUIModel.java | 31 - .../open/impl/seine/ActivitySeineUIModel.java | 36 - .../ui/content/open/impl/seine/RouteUIModel.java | 37 - .../content/open/impl/seine/TripSeineUIModel.java | 32 - .../ui/content/ref/ContentReferenceUIModel.java | 34 +- .../ui/content/ref/ReferenceHomeUIModel.java | 7 - .../ui/content/table/ContentTableUIModel.java | 77 +- .../impl/longline/BaitsCompositionUIModel.java | 15 +- .../longline/BranchlinesCompositionUIModel.java | 14 +- .../table/impl/longline/CatchLonglineUIModel.java | 65 +- .../table/impl/longline/EncounterUIModel.java | 15 +- .../longline/FloatlinesCompositionUIModel.java | 11 +- .../longline/GearUseFeaturesLonglineUIModel.java | 40 +- .../impl/longline/HooksCompositionUIModel.java | 13 +- .../table/impl/longline/SensorUsedUIModel.java | 20 +- .../ui/content/table/impl/longline/TdrUIModel.java | 125 +- .../impl/seine/GearUseFeaturesSeineUIModel.java | 39 +- .../table/impl/seine/NonTargetCatchUIModel.java | 34 +- .../table/impl/seine/NonTargetSampleUIModel.java | 25 +- .../impl/seine/ObjectObservedSpeciesUIModel.java | 14 +- .../impl/seine/ObjectSchoolEstimateUIModel.java | 9 +- .../table/impl/seine/SchoolEstimateUIModel.java | 13 +- .../table/impl/seine/TargetCatchUIModel.java | 19 +- .../impl/seine/TargetDiscardCatchUIModel.java | 19 +- .../table/impl/seine/TargetSampleUIModel.java | 24 +- 43 files changed, 1373 insertions(+), 1460 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 797b595..1596a68 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -23,6 +23,7 @@ package fr.ird.observe; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.BaitsComposition; +import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.BranchlinesComposition; import fr.ird.observe.entities.longline.CatchLongline; @@ -31,14 +32,19 @@ import fr.ird.observe.entities.longline.FloatlinesComposition; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.HooksComposition; +import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SensorUsed; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.WeightMeasure; +import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; +import fr.ird.observe.entities.seine.GearUseFeaturesSeine; +import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.ObjectObservedSpecies; @@ -46,9 +52,12 @@ import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.entities.seine.TripSeine; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -63,6 +72,9 @@ import org.nuiton.util.beans.BinderModelBuilder; */ public class BinderService { + /** Logger. */ + private static final Log log = LogFactory.getLog(BinderService.class); + public static final String DISPLAY = "display"; public static final String EDIT = "edit"; @@ -79,6 +91,8 @@ public class BinderService { public static final String EDIT_GEAR_USE_FEATURES_LONGLINE = "editGearUseFeaturesLongline"; + public static final String EDIT_GEAR_USE_FEATURES_SEINE = "editGearUseFeaturesSeine"; + public static final String EDIT_HOOKS_COMPOSITION = "editHooksComposition"; public static final String EDIT_SENSOR_USED = "editSensorUsed"; @@ -93,547 +107,566 @@ public class BinderService { public static final String EDIT_OBJECT_OBSERVED_SPECIES = "editObjectObservedSpecies"; + public static final String EDIT_OBJECT_OPERATION = "editObjectOperation"; + + public static final String EDIT_OBSERVED_SYSTEM = "editObservedSystem"; + + public static final String EDIT_GLOBAL_COMPOSITION = "editGlobalComposition"; + + public static final String EDIT_DETAIL_COMPOSITION = "editDetailComposition"; + public static final String EDIT_NON_TARGET_LENGTH = "editNonTargetLength"; - static { + public static final String DISPLAY_LIST = "displayList"; - registerBinders(); + public static final String EDIT_ROUTE = "editRoute"; - } + public static final String EDIT_NON_TARGET_CATCH = "editNonTargetCatch"; - private static void registerBinders() { + public static final String EDIT_TARGET_CATCH = "editTargetCatch"; - { + public static final String EDIT_DISCARD_TARGET_CATCH = "editDiscardTargetCatch"; - BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( - ActivityLongline.class, - ActivityLongline.PROPERTY_QUADRANT, - ActivityLongline.PROPERTY_LATITUDE, - ActivityLongline.PROPERTY_LONGITUDE, - ActivityLongline.PROPERTY_TIME_STAMP, - ActivityLongline.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivityLongline.PROPERTY_COMMENT, - ActivityLongline.PROPERTY_SET_LONGLINE, - ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, - ActivityLongline.PROPERTY_FPA_ZONE, - ActivityLongline.PROPERTY_OPEN, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); + static { - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_ENCOUNTER); + try { - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_SENSOR_USED); + registerSeineBinders(); - registerTopiaBinder(ActivityLongline.class, builder, EDIT); + registerLonglineBinders(); + + } catch (Exception e) { + + if (log.isErrorEnabled()) { + log.error("Could not load binders", e); + } + throw new ObserveTechnicalException("Could not load binders", e); } - { + } - BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_BAITS_COMPOSITION); + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { - registerTopiaBinder(SetLongline.class, builder, EDIT_BAITS_COMPOSITION); + copy(type, context, source, target, true); - } + } - { + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { - BinderModelBuilder<BaitsComposition, BaitsComposition> builder = newBinderBuilder( - BaitsComposition.class, - BaitsComposition.PROPERTY_BAIT_TYPE, - BaitsComposition.PROPERTY_BAIT_SETTING_STATUS, - BaitsComposition.PROPERTY_INDIVIDUAL_SIZE, - BaitsComposition.PROPERTY_INDIVIDUAL_WEIGHT, - BaitsComposition.PROPERTY_PROPORTION); + TopiaEntityBinder<E> binder = getBinder(type, context); - registerTopiaBinder(BaitsComposition.class, builder, EDIT); + binder.copyExcluding(source, target, propertyNames); - } + /* FIXME sbavencoff 29/04/2015 bind techincal fields */ + target.setTopiaId(source.getTopiaId()); + target.setTopiaVersion(source.getTopiaVersion()); + target.setTopiaCreateDate(source.getTopiaCreateDate()); - { + } - BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_BRANCHLINES_COMPOSITION); + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { - registerTopiaBinder(SetLongline.class, builder, EDIT_BRANCHLINES_COMPOSITION); + TopiaEntityBinder<E> binder = getBinder(type, context); + binder.load(source, target, bindTechnical); + + } + + public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> type, String context) { + TopiaEntityBinder<E> binder = getTopiaBinder(type, context); + if (binder == null) { + throw new IllegalArgumentException("Could not find binder for " + type.getName() + "::" + context); } + return binder; + } - { - BinderModelBuilder<BranchlinesComposition, BranchlinesComposition> builder = newBinderBuilder( - BranchlinesComposition.class, - BranchlinesComposition.PROPERTY_TOP_TYPE, - BranchlinesComposition.PROPERTY_TRACELINE_TYPE, - BranchlinesComposition.PROPERTY_LENGTH, - BranchlinesComposition.PROPERTY_PROPORTION); + public static <E extends TopiaEntity> BinderModelBuilder<E, E> newBinderBuilder(Class<E> type, String... properties) { + BinderModelBuilder<E, E> builder = BinderModelBuilder.newEmptyBuilder(type); + builder.addSimpleProperties(properties); + return builder; + } - registerTopiaBinder(BranchlinesComposition.class, builder, EDIT); + public <E extends TopiaEntity> TopiaEntityBinder<E> getTopiaBinder(Class<E> entityClass, + String contextName) { + if (ObserveBinderHelper.getCachedBinderModel(entityClass, entityClass, contextName) == null) { + // we do not want to have auto created binder model by the factory + return null; } + return (TopiaEntityBinder<E>) ObserveBinderHelper.newBinder(entityClass, entityClass, contextName, TopiaEntityBinder.class); + } - { - - BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_CATCH_LONGLINE); + public static <E extends TopiaEntity> TopiaEntityBinder<E> registerTopiaBinder(Class<E> entityClass, + BinderModelBuilder<E, E> builder, + String contextName) { + return ObserveBinderHelper.registerTopiaBinder(entityClass, builder, contextName); + } - registerTopiaBinder(SetLongline.class, builder, EDIT_CATCH_LONGLINE); + public <E extends TopiaEntity> TopiaEntityBinder<E> getSimpleTopiaBinder(Class<E> entityClass) { + return getTopiaBinder(entityClass, "Observe"); + } + public <E extends TopiaEntity> void simpleCopy(E source, E target, boolean tech) { + Class<E> entityClass = (Class<E>) TopiaEntityHelper.getContractClass(ObserveDAOHelper.getContracts(), target.getClass()); + TopiaEntityBinder<E> binder = getSimpleTopiaBinder(entityClass); + if (binder == null) { + throw new NullPointerException("could not find a simple topia binder of type : " + target.getClass()); } + binder.load(source, target, tech); + } + protected static void registerSeineBinders() { { - BinderModelBuilder<CatchLongline, CatchLongline> builder = newBinderBuilder( - CatchLongline.class, - CatchLongline.PROPERTY_SPECIES_CATCH, - CatchLongline.PROPERTY_ACQUISITION_MODE, - CatchLongline.PROPERTY_COUNT, - CatchLongline.PROPERTY_CATCH_HEALTHNESS, - CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, - CatchLongline.PROPERTY_DISCARD_HEALTHNESS, - CatchLongline.PROPERTY_DEPREDATED, - CatchLongline.PROPERTY_NUMBER, - CatchLongline.PROPERTY_HOME_ID, - CatchLongline.PROPERTY_HOOK_POSITION, - CatchLongline.PROPERTY_HOOK_WHEN_DISCARDED, - CatchLongline.PROPERTY_MATURITY_STATUS, - CatchLongline.PROPERTY_PHOTO_REFERENCES, - CatchLongline.PROPERTY_SEX, - CatchLongline.PROPERTY_PREDATOR, - CatchLongline.PROPERTY_STOMAC_FULLNESS, - CatchLongline.PROPERTY_TOTAL_WEIGHT, - CatchLongline.PROPERTY_BEAT_DIAMETER, - CatchLongline.PROPERTY_GONADE_WEIGHT, - CatchLongline.PROPERTY_SECTION, - CatchLongline.PROPERTY_BASKET, - CatchLongline.PROPERTY_BRANCHLINE, - CatchLongline.PROPERTY_COMMENT); + BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_START_DATE, + TripSeine.PROPERTY_END_DATE, + TripSeine.PROPERTY_FORMS_URL, + TripSeine.PROPERTY_REPORTS_URL, + TripSeine.PROPERTY_COMMENT, + TripSeine.PROPERTY_VESSEL, + TripSeine.PROPERTY_OBSERVER, + TripSeine.PROPERTY_CAPTAIN, + TripSeine.PROPERTY_DATA_ENTRY_OPERATOR, + TripSeine.PROPERTY_OCEAN, + TripSeine.PROPERTY_DEPARTURE_HARBOUR, + TripSeine.PROPERTY_LANDING_HARBOUR, + TripSeine.PROPERTY_PROGRAM, + TripSeine.PROPERTY_ROUTE, + TripSeine.PROPERTY_ERS_ID, + TripSeine.PROPERTY_OPEN); - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, CatchLongline.PROPERTY_PREDATOR); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); - registerTopiaBinder(CatchLongline.class, builder, EDIT); + registerTopiaBinder(TripSeine.class, builder, EDIT); } { - BinderModelBuilder<Branchline, Branchline> builder = newBinderBuilder(Branchline.class, - Branchline.PROPERTY_DEPTH_RECORDER, - Branchline.PROPERTY_HOOK_LOST, - Branchline.PROPERTY_TRACE_CUT_OFF, - Branchline.PROPERTY_TIMER, - Branchline.PROPERTY_TIME_SINCE_CONTACT, - Branchline.PROPERTY_TIMER_TIME_ON_BOARD, - Branchline.PROPERTY_BAIT_HAULING_STATUS); + BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_START_DATE, + TripSeine.PROPERTY_END_DATE, + TripSeine.PROPERTY_OPEN, + TripSeine.PROPERTY_OBSERVER, + TripSeine.PROPERTY_VESSEL, + TripSeine.PROPERTY_PROGRAM); - registerTopiaBinder(Branchline.class, builder, EDIT_CATCH_LONGLINE); + registerTopiaBinder(TripSeine.class, builder, DISPLAY); } { - BinderModelBuilder<WeightMeasure, WeightMeasure> builder = newBinderBuilder(WeightMeasure.class, - WeightMeasure.PROPERTY_WEIGHT, - WeightMeasure.PROPERTY_WEIGHT_MEASURE_TYPE); + BinderModelBuilder<ActivitySeine, ActivitySeine> activitySeineBuilder = newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_QUADRANT, + ActivitySeine.PROPERTY_LATITUDE, + ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_TIME, + ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_WIND, + ActivitySeine.PROPERTY_OPEN); - registerTopiaBinder(WeightMeasure.class, builder, EDIT); + TopiaEntityBinder<ActivitySeine> activitySeineBinder = + registerTopiaBinder(ActivitySeine.class, activitySeineBuilder, EDIT_ROUTE); - } - { + BinderModelBuilder<Route, Route> builder = newBinderBuilder( + Route.class, + Route.PROPERTY_DATE, + Route.PROPERTY_START_LOG_VALUE, + Route.PROPERTY_END_LOG_VALUE, + Route.PROPERTY_CHECK_LEVEL, + Route.PROPERTY_ACTIVITY_SEINE, + Route.PROPERTY_OPEN, + Route.PROPERTY_COMMENT); - BinderModelBuilder<SizeMeasure, SizeMeasure> builder = newBinderBuilder(SizeMeasure.class, - SizeMeasure.PROPERTY_SIZE, - SizeMeasure.PROPERTY_SIZE_MEASURE_TYPE); + builder.addCollectionBinder(activitySeineBinder, Route.PROPERTY_ACTIVITY_SEINE); - registerTopiaBinder(SizeMeasure.class, builder, EDIT); + registerTopiaBinder(Route.class, builder, EDIT); } { - BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( - ActivityLongline.class, - ActivityLongline.PROPERTY_COMMENT, - ActivityLongline.PROPERTY_ENCOUNTER); + BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_QUADRANT, + ActivitySeine.PROPERTY_LATITUDE, + ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_ERS_ID, + ActivitySeine.PROPERTY_TIME, + ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_COMMENT, + ActivitySeine.PROPERTY_VESSEL_SPEED, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, + ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, + ActivitySeine.PROPERTY_WIND, + ActivitySeine.PROPERTY_DETECTION_MODE, + ActivitySeine.PROPERTY_SET_SEINE, + ActivitySeine.PROPERTY_FLOATING_OBJECT, + ActivitySeine.PROPERTY_OPEN, + ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, + ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, + ActivitySeine.PROPERTY_NEXT_FPA_ZONE); - registerTopiaBinder(ActivityLongline.class, builder, EDIT_ENCOUNTER); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); - } + registerTopiaBinder(ActivitySeine.class, builder, EDIT); + } { - BinderModelBuilder<Encounter, Encounter> builder = newBinderBuilder( - Encounter.class, - Encounter.PROPERTY_SPECIES, - Encounter.PROPERTY_DISTANCE, - Encounter.PROPERTY_COUNT, - Encounter.PROPERTY_ENCOUNTER_TYPE); + BinderModelBuilder<TargetLength, TargetLength> builder = newBinderBuilder( + TargetLength.class, + TargetLength.PROPERTY_TARGET_SAMPLE, + TargetLength.PROPERTY_SPECIES, + TargetLength.PROPERTY_LENGTH, + TargetLength.PROPERTY_LENGTH_SOURCE, + TargetLength.PROPERTY_WEIGHT, + TargetLength.PROPERTY_WEIGHT_SOURCE, + TargetLength.PROPERTY_COUNT, + TargetLength.PROPERTY_MEASURE_TYPE, + TargetLength.PROPERTY_ACQUISITION_MODE); - registerTopiaBinder(Encounter.class, builder, EDIT); + registerTopiaBinder(TargetLength.class, builder, EDIT); } { - BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_FLOATLINES_COMPOSITION); + BinderModelBuilder<TargetSample, TargetSample> builder = newBinderBuilder( + TargetSample.class, + TargetSample.PROPERTY_TARGET_LENGTH, + TargetSample.PROPERTY_COMMENT); - registerTopiaBinder(SetLongline.class, builder, EDIT_FLOATLINES_COMPOSITION); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TargetSample.PROPERTY_TARGET_LENGTH); + + registerTopiaBinder(TargetSample.class, builder, EDIT_TARGET_LENGTH); } { - BinderModelBuilder<FloatlinesComposition, FloatlinesComposition> builder = newBinderBuilder( - FloatlinesComposition.class, - FloatlinesComposition.PROPERTY_LINE_TYPE, - FloatlinesComposition.PROPERTY_LENGTH, - FloatlinesComposition.PROPERTY_PROPORTION); - + BinderModelBuilder<TargetSample, TargetSample> builder = newBinderBuilder( + TargetSample.class, + TargetSample.PROPERTY_TARGET_LENGTH, + TargetSample.PROPERTY_COMMENT); - registerTopiaBinder(FloatlinesComposition.class, builder, EDIT); + registerTopiaBinder(TargetSample.class, builder, EDIT); } { - BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( - TripLongline.class, - TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE); + BinderModelBuilder<SetSeine, SetSeine> builder = newBinderBuilder( + SetSeine.class, + SetSeine.PROPERTY_COMMENT, + SetSeine.PROPERTY_SUPPORT_VESSEL_NAME, + SetSeine.PROPERTY_START_TIME, + SetSeine.PROPERTY_END_SET_TIME_STAMP, + SetSeine.PROPERTY_END_PURSING_TIME_STAMP, + SetSeine.PROPERTY_CURRENT_DIRECTION, + SetSeine.PROPERTY_CURRENT_SPEED, + SetSeine.PROPERTY_REASON_FOR_NULL_SET, + SetSeine.PROPERTY_SCHOOL_THICKNESS, + SetSeine.PROPERTY_MAX_GEAR_DEPTH, + SetSeine.PROPERTY_SCHOOL_MEAN_DEPTH, + SetSeine.PROPERTY_SCHOOL_TOP_DEPTH, + SetSeine.PROPERTY_CURRENT_MEASURE_DEPTH, + SetSeine.PROPERTY_TARGET_DISCARDED, + SetSeine.PROPERTY_NON_TARGET_DISCARDED, + SetSeine.PROPERTY_SCHOOL_TYPE, + SetSeine.PROPERTY_SONAR_USED, + SetSeine.PROPERTY_TARGET_SAMPLE, + SetSeine.PROPERTY_NON_TARGET_SAMPLE); - registerTopiaBinder(TripLongline.class, builder, EDIT_GEAR_USE_FEATURES_LONGLINE); + registerTopiaBinder(SetSeine.class, builder, EDIT); } { - BinderModelBuilder<GearUseFeaturesLongline, GearUseFeaturesLongline> builder = newBinderBuilder( - GearUseFeaturesLongline.class, - GearUseFeaturesLongline.PROPERTY_COMMENT, - GearUseFeaturesLongline.PROPERTY_GEAR, - GearUseFeaturesLongline.PROPERTY_NUMBER, - GearUseFeaturesLongline.PROPERTY_USED_IN_TRIP); + BinderModelBuilder<SchoolEstimate, SchoolEstimate> builder = newBinderBuilder( + SchoolEstimate.class, + SchoolEstimate.PROPERTY_SET_SEINE, + SchoolEstimate.PROPERTY_SPECIES, + SchoolEstimate.PROPERTY_TOTAL_WEIGHT, + SchoolEstimate.PROPERTY_MEAN_WEIGHT); - registerTopiaBinder(GearUseFeaturesLongline.class, builder, EDIT); + registerTopiaBinder(SchoolEstimate.class, builder, EDIT); } { + BinderModelBuilder<SetSeine, SetSeine> builder = newBinderBuilder( + SetSeine.class, + SetSeine.PROPERTY_SCHOOL_ESTIMATE, + SetSeine.PROPERTY_COMMENT); - BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> builder = - newBinderBuilder(GearUseFeaturesMeasurementLongline.class, - GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, - GearUseFeaturesMeasurementLongline.PROPERTY_MEASUREMENT_VALUE); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetSeine.PROPERTY_SCHOOL_ESTIMATE); - registerTopiaBinder(GearUseFeaturesMeasurementLongline.class, builder, EDIT); + registerTopiaBinder(SetSeine.class, builder, EDIT_SCHOOL_ESTIMATE); } { - BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_HOOKS_COMPOSITION); - - registerTopiaBinder(SetLongline.class, builder, EDIT_HOOKS_COMPOSITION); + BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_QUADRANT, + ActivitySeine.PROPERTY_LATITUDE, + ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_TIME, + ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_WIND, + ActivitySeine.PROPERTY_OPEN); + registerTopiaBinder(ActivitySeine.class, builder, EDIT); } { - BinderModelBuilder<HooksComposition, HooksComposition> builder = newBinderBuilder( - HooksComposition.class, - HooksComposition.PROPERTY_HOOK_TYPE, - HooksComposition.PROPERTY_HOOK_SIZE, - HooksComposition.PROPERTY_HOOK_OFFSET, - HooksComposition.PROPERTY_PROPORTION); + BinderModelBuilder<Route, Route> builder = newBinderBuilder( + Route.class, + Route.PROPERTY_DATE, + Route.PROPERTY_START_LOG_VALUE, + Route.PROPERTY_END_LOG_VALUE, + Route.PROPERTY_CHECK_LEVEL, + Route.PROPERTY_ACTIVITY_SEINE, + Route.PROPERTY_OPEN, + Route.PROPERTY_COMMENT); - registerTopiaBinder(HooksComposition.class, builder, EDIT); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Route.PROPERTY_ACTIVITY_SEINE); + + registerTopiaBinder(Route.class, builder, EDIT); } { - BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( - ActivityLongline.class, - ActivityLongline.PROPERTY_SENSOR_USED, ActivityLongline.PROPERTY_COMMENT); + BinderModelBuilder<Route, Route> builder = newBinderBuilder( + Route.class, + Route.PROPERTY_DATE, + Route.PROPERTY_OPEN); - registerTopiaBinder(ActivityLongline.class, builder, EDIT_SENSOR_USED); + registerTopiaBinder(Route.class, builder, DISPLAY); } { + BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE, + FloatingObject.PROPERTY_COMMENT); - BinderModelBuilder<SensorUsed, SensorUsed> builder = newBinderBuilder( - SensorUsed.class, - SensorUsed.PROPERTY_DATA, - SensorUsed.PROPERTY_DATA_FILENAME, - SensorUsed.PROPERTY_DATA_LOCATION, - SensorUsed.PROPERTY_SENSOR_SERIAL_NO, - SensorUsed.PROPERTY_SENSOR_TYPE, - SensorUsed.PROPERTY_SENSOR_BRAND, - SensorUsed.PROPERTY_SENSOR_DATA_FORMAT); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); - registerTopiaBinder(SensorUsed.class, builder, EDIT); + registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_SCHOOL_ESTIMATE); } { - BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_COMMENT, + BinderModelBuilder<ObjectSchoolEstimate, ObjectSchoolEstimate> builder = newBinderBuilder( + ObjectSchoolEstimate.class, + ObjectSchoolEstimate.PROPERTY_SPECIES, + ObjectSchoolEstimate.PROPERTY_TOTAL_WEIGHT); - // setting tab - SetLongline.PROPERTY_HOME_ID, - SetLongline.PROPERTY_NUMBER, + registerTopiaBinder(ObjectSchoolEstimate.class, builder, EDIT); - SetLongline.PROPERTY_SETTING_START_TIME_STAMP, - SetLongline.PROPERTY_SETTING_START_QUADRANT, - SetLongline.PROPERTY_SETTING_START_LATITUDE, - SetLongline.PROPERTY_SETTING_START_LONGITUDE, + } - SetLongline.PROPERTY_SETTING_END_TIME_STAMP, - SetLongline.PROPERTY_SETTING_END_QUADRANT, - SetLongline.PROPERTY_SETTING_END_LATITUDE, - SetLongline.PROPERTY_SETTING_END_LONGITUDE, + { - // setting caracteristics tab - SetLongline.PROPERTY_SETTING_SHAPE, - SetLongline.PROPERTY_LINE_TYPE, - SetLongline.PROPERTY_LIGHTSTICKS_TYPE, - SetLongline.PROPERTY_LIGHTSTICKS_COLOR, - SetLongline.PROPERTY_SETTING_VESSEL_SPEED, - SetLongline.PROPERTY_MAX_DEPTH_TARGETED, - SetLongline.PROPERTY_SHOOTER_USED, - SetLongline.PROPERTY_SHOOTER_SPEED, - SetLongline.PROPERTY_WEIGHTED_SWIVEL, - SetLongline.PROPERTY_SWIVEL_WEIGHT, - SetLongline.PROPERTY_WEIGHTED_SNAP, - SetLongline.PROPERTY_SNAP_WEIGHT, - SetLongline.PROPERTY_MONITORED, - SetLongline.PROPERTY_TIME_BETWEEN_HOOKS, - SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, - SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT, - SetLongline.PROPERTY_LIGHTSTICKS_PER_BASKET_COUNT, - SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, - SetLongline.PROPERTY_TOTAL_BASKETS_COUNT, - SetLongline.PROPERTY_TOTAL_HOOKS_COUNT, + BinderModelBuilder<ObjectObservedSpecies, ObjectObservedSpecies> builder = newBinderBuilder( + ObjectObservedSpecies.class, + ObjectObservedSpecies.PROPERTY_SPECIES, + ObjectObservedSpecies.PROPERTY_SPECIES_STATUS, + ObjectObservedSpecies.PROPERTY_COUNT); - // hauling tab - SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, + registerTopiaBinder(ObjectObservedSpecies.class, builder, EDIT); - SetLongline.PROPERTY_HAULING_START_QUADRANT, - SetLongline.PROPERTY_HAULING_START_LATITUDE, - SetLongline.PROPERTY_HAULING_START_LONGITUDE, - SetLongline.PROPERTY_HAULING_START_TIME_STAMP, + } - SetLongline.PROPERTY_HAULING_END_QUADRANT, - SetLongline.PROPERTY_HAULING_END_LATITUDE, - SetLongline.PROPERTY_HAULING_END_LONGITUDE, - SetLongline.PROPERTY_HAULING_END_TIME_STAMP, + { - SetLongline.PROPERTY_HAULING_BREAKS); + BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES, + FloatingObject.PROPERTY_COMMENT); - registerTopiaBinder(SetLongline.class, builder, EDIT); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); + + registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OBSERVED_SPECIES); } { - BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_TDR, - SetLongline.PROPERTY_SETTING_START_TIME_STAMP, - SetLongline.PROPERTY_SETTING_END_TIME_STAMP, - SetLongline.PROPERTY_HAULING_START_TIME_STAMP, - SetLongline.PROPERTY_HAULING_END_TIME_STAMP); + BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_TYPE, + FloatingObject.PROPERTY_OBJECT_FATE, + FloatingObject.PROPERTY_OBJECT_OPERATION, + FloatingObject.PROPERTY_COMMENT, + FloatingObject.PROPERTY_SUPPORT_VESSEL_NAME, + FloatingObject.PROPERTY_DAYS_AT_SEA_COUNT); - registerTopiaBinder(SetLongline.class, builder, EDIT_TDR); + registerTopiaBinder(FloatingObject.class, builder, EDIT); } { - BinderModelBuilder<Tdr, Tdr> builder = newBinderBuilder( - Tdr.class, - // caracteristics tab - Tdr.PROPERTY_HOME_ID, - Tdr.PROPERTY_SERIAL_NO, - Tdr.PROPERTY_SENSOR_BRAND, - Tdr.PROPERTY_DATA, - Tdr.PROPERTY_DATA_FILENAME, - Tdr.PROPERTY_DATA_LOCATION, + BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( + FloatingObject.class, + FloatingObject.PROPERTY_OBJECT_OPERATION, + FloatingObject.PROPERTY_COMMENT); - // localisation tab - Tdr.PROPERTY_SECTION, - Tdr.PROPERTY_BASKET, - Tdr.PROPERTY_BRANCHLINE, - Tdr.PROPERTY_ITEM_HORIZONTAL_POSITION, - Tdr.PROPERTY_ITEM_VERTICAL_POSITION, - Tdr.PROPERTY_FLOATLINE1_LENGTH, - Tdr.PROPERTY_FLOATLINE2_LENGTH, + registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OPERATION); - // timestamp tab - Tdr.PROPERTY_DEPLOYEMENT_START, - Tdr.PROPERTY_DEPLOYEMENT_START_DATE, - Tdr.PROPERTY_DEPLOYEMENT_START_TIME, - Tdr.PROPERTY_DEPLOYEMENT_END, - Tdr.PROPERTY_DEPLOYEMENT_END_DATE, - Tdr.PROPERTY_DEPLOYEMENT_END_TIME, - Tdr.PROPERTY_FISHING_START, - Tdr.PROPERTY_FISHING_START_DATE, - Tdr.PROPERTY_FISHING_START_TIME, - Tdr.PROPERTY_FISHING_END, - Tdr.PROPERTY_FISHING_END_DATE, - Tdr.PROPERTY_FISHING_END_TIME, + } - // key data tab - Tdr.PROPERTY_FISHING_START_DEPTH, - Tdr.PROPERTY_FISHING_END_DEPTH, - Tdr.PROPERTY_MEAN_DEPLOYEMENT_DEPTH, - Tdr.PROPERTY_MEDIAN_DEPLOYEMENT_DEPTH, - Tdr.PROPERTY_MEAN_FISHING_DEPTH, - Tdr.PROPERTY_MEDIAN_FISHING_DEPTH, - Tdr.PROPERTY_MIN_FISHING_DEPTH, - Tdr.PROPERTY_MAX_FISHING_DEPTH, + { - // species tab - Tdr.PROPERTY_SPECIES); + BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_SET_SEINE, + ActivitySeine.PROPERTY_COMMENT, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE); - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Tdr.PROPERTY_SPECIES); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); - registerTopiaBinder(Tdr.class, builder, EDIT); + registerTopiaBinder(ActivitySeine.class, builder, EDIT_OBSERVED_SYSTEM); } - { - BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( - TripLongline.class, - TripLongline.PROPERTY_START_DATE, - TripLongline.PROPERTY_END_DATE, - TripLongline.PROPERTY_TRIP_TYPE, - TripLongline.PROPERTY_HOME_ID, - TripLongline.PROPERTY_COMMENT, - TripLongline.PROPERTY_VESSEL, - TripLongline.PROPERTY_OBSERVER, - TripLongline.PROPERTY_CAPTAIN, - TripLongline.PROPERTY_DATA_ENTRY_OPERATOR, - TripLongline.PROPERTY_TOTAL_FISHING_OPERATIONS_NUMBER, - TripLongline.PROPERTY_OCEAN, - TripLongline.PROPERTY_DEPARTURE_HARBOUR, - TripLongline.PROPERTY_LANDING_HARBOUR, - TripLongline.PROPERTY_PROGRAM, - TripLongline.PROPERTY_ACTIVITY_LONGLINE, - TripLongline.PROPERTY_OPEN); - - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + BinderModelBuilder<NonTargetLength, NonTargetLength> builder = newBinderBuilder( + NonTargetLength.class, + NonTargetLength.PROPERTY_SPECIES, + NonTargetLength.PROPERTY_LENGTH, + NonTargetLength.PROPERTY_LENGTH_SOURCE, + NonTargetLength.PROPERTY_WEIGHT, + NonTargetLength.PROPERTY_WEIGHT_SOURCE, + NonTargetLength.PROPERTY_SEX, + NonTargetLength.PROPERTY_COUNT, + NonTargetLength.PROPERTY_ACQUISITION_MODE, + NonTargetLength.PROPERTY_PICTURES_REFERENCES); - registerTopiaBinder(TripLongline.class, builder, EDIT); + registerTopiaBinder(NonTargetLength.class, builder, EDIT); } { - BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( - TripLongline.class, - TripLongline.PROPERTY_START_DATE, - TripLongline.PROPERTY_END_DATE, - TripLongline.PROPERTY_OPEN, - TripLongline.PROPERTY_OBSERVER, - TripLongline.PROPERTY_VESSEL, - TripLongline.PROPERTY_PROGRAM); + BinderModelBuilder<NonTargetSample, NonTargetSample> builder = newBinderBuilder( + NonTargetSample.class, + NonTargetSample.PROPERTY_NON_TARGET_LENGTH, + NonTargetSample.PROPERTY_COMMENT); - registerTopiaBinder(TripLongline.class, builder, DISPLAY); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + + registerTopiaBinder(NonTargetSample.class, builder, EDIT_NON_TARGET_LENGTH); } { - BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( - TripSeine.class, - TripSeine.PROPERTY_START_DATE, - TripSeine.PROPERTY_END_DATE, - TripSeine.PROPERTY_FORMS_URL, - TripSeine.PROPERTY_REPORTS_URL, - TripSeine.PROPERTY_COMMENT, - TripSeine.PROPERTY_VESSEL, - TripSeine.PROPERTY_OBSERVER, - TripSeine.PROPERTY_CAPTAIN, - TripSeine.PROPERTY_DATA_ENTRY_OPERATOR, - TripSeine.PROPERTY_OCEAN, - TripSeine.PROPERTY_DEPARTURE_HARBOUR, - TripSeine.PROPERTY_LANDING_HARBOUR, - TripSeine.PROPERTY_PROGRAM, - TripSeine.PROPERTY_ROUTE, - TripSeine.PROPERTY_ERS_ID, - TripSeine.PROPERTY_OPEN); + BinderModelBuilder<NonTargetSample, NonTargetSample> builder = newBinderBuilder( + NonTargetSample.class, + NonTargetSample.PROPERTY_NON_TARGET_LENGTH, + NonTargetSample.PROPERTY_COMMENT); - registerTopiaBinder(TripSeine.class, builder, EDIT); + registerTopiaBinder(NonTargetSample.class, builder, EDIT); } { - BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( - TripSeine.class, - TripSeine.PROPERTY_START_DATE, - TripSeine.PROPERTY_END_DATE, - TripSeine.PROPERTY_OPEN, - TripSeine.PROPERTY_OBSERVER, - TripSeine.PROPERTY_VESSEL, - TripSeine.PROPERTY_PROGRAM); + BinderModelBuilder<ActivitySeine, ActivitySeine> activitySeineBuilder = newBinderBuilder( + ActivitySeine.class, + ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_TIME, + ActivitySeine.PROPERTY_OPEN); - registerTopiaBinder(TripSeine.class, builder, DISPLAY); + TopiaEntityBinder<ActivitySeine> activitySeineBinder = registerTopiaBinder(ActivitySeine.class, activitySeineBuilder, DISPLAY_LIST); + + BinderModelBuilder<Route, Route> routeBuilder = newBinderBuilder( + Route.class, + Route.PROPERTY_OPEN, + Route.PROPERTY_ACTIVITY_SEINE); + + routeBuilder.addCollectionBinder(activitySeineBinder, Route.PROPERTY_ACTIVITY_SEINE); + + registerTopiaBinder(Route.class, routeBuilder, DISPLAY_LIST); } { - BinderModelBuilder<TargetLength, TargetLength> builder = newBinderBuilder( - TargetLength.class, - TargetLength.PROPERTY_TARGET_SAMPLE, - TargetLength.PROPERTY_SPECIES, - TargetLength.PROPERTY_LENGTH, - TargetLength.PROPERTY_LENGTH_SOURCE, - TargetLength.PROPERTY_WEIGHT, - TargetLength.PROPERTY_WEIGHT_SOURCE, - TargetLength.PROPERTY_COUNT, - TargetLength.PROPERTY_MEASURE_TYPE, - TargetLength.PROPERTY_ACQUISITION_MODE); + BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_OPEN, + TripSeine.PROPERTY_ROUTE); - registerTopiaBinder(TargetLength.class, builder, EDIT); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); + + registerTopiaBinder(TripSeine.class, builder, DISPLAY_LIST); } { - BinderModelBuilder<TargetSample, TargetSample> builder = newBinderBuilder( - TargetSample.class, - TargetSample.PROPERTY_TARGET_LENGTH, - TargetSample.PROPERTY_COMMENT); + BinderModelBuilder<Program, Program> builder = newBinderBuilder( + Program.class, + Program.PROPERTY_LABEL1, + Program.PROPERTY_LABEL2, + Program.PROPERTY_LABEL3, + Program.PROPERTY_LABEL4, + Program.PROPERTY_LABEL5, + Program.PROPERTY_LABEL6, + Program.PROPERTY_LABEL7, + Program.PROPERTY_LABEL8); - registerTopiaBinder(TargetSample.class, builder, EDIT_TARGET_LENGTH); + registerTopiaBinder(Program.class, builder, DISPLAY_LIST); } { - BinderModelBuilder<TargetSample, TargetSample> builder = newBinderBuilder( - TargetSample.class, - TargetSample.PROPERTY_TARGET_LENGTH, - TargetSample.PROPERTY_COMMENT); - - registerTopiaBinder(TargetSample.class, builder, EDIT); + BinderModelBuilder<NonTargetCatch, NonTargetCatch> builder = newBinderBuilder( + NonTargetCatch.class, + NonTargetCatch.PROPERTY_SPECIES, + NonTargetCatch.PROPERTY_CATCH_WEIGHT, + NonTargetCatch.PROPERTY_TOTAL_COUNT, + NonTargetCatch.PROPERTY_MEAN_WEIGHT, + NonTargetCatch.PROPERTY_MEAN_LENGTH, + NonTargetCatch.PROPERTY_REASON_FOR_DISCARD, + NonTargetCatch.PROPERTY_SPECIES_FATE, + NonTargetCatch.PROPERTY_TOTAL_COUNT_COMPUTED_SOURCE, + NonTargetCatch.PROPERTY_MEAN_WEIGHT_COMPUTED_SOURCE, + NonTargetCatch.PROPERTY_CATCH_WEIGHT_COMPUTED_SOURCE, + NonTargetCatch.PROPERTY_MEAN_LENGTH_COMPUTED_SOURCE, + NonTargetCatch.PROPERTY_COMMENT); + + registerTopiaBinder(NonTargetCatch.class, builder, EDIT); } @@ -641,254 +674,733 @@ public class BinderService { BinderModelBuilder<SetSeine, SetSeine> builder = newBinderBuilder( SetSeine.class, - SetSeine.PROPERTY_COMMENT, - SetSeine.PROPERTY_SUPPORT_VESSEL_NAME, - SetSeine.PROPERTY_START_TIME, - SetSeine.PROPERTY_END_SET_TIME_STAMP, - SetSeine.PROPERTY_END_PURSING_TIME_STAMP, - SetSeine.PROPERTY_CURRENT_DIRECTION, - SetSeine.PROPERTY_CURRENT_SPEED, - SetSeine.PROPERTY_REASON_FOR_NULL_SET, - SetSeine.PROPERTY_SCHOOL_THICKNESS, - SetSeine.PROPERTY_MAX_GEAR_DEPTH, - SetSeine.PROPERTY_SCHOOL_MEAN_DEPTH, - SetSeine.PROPERTY_SCHOOL_TOP_DEPTH, - SetSeine.PROPERTY_CURRENT_MEASURE_DEPTH, - SetSeine.PROPERTY_TARGET_DISCARDED, - SetSeine.PROPERTY_NON_TARGET_DISCARDED, - SetSeine.PROPERTY_SCHOOL_TYPE, - SetSeine.PROPERTY_SONAR_USED, - SetSeine.PROPERTY_TARGET_SAMPLE, - SetSeine.PROPERTY_NON_TARGET_SAMPLE); + SetSeine.PROPERTY_NON_TARGET_CATCH, + SetSeine.PROPERTY_NON_TARGET_DISCARDED); - registerTopiaBinder(SetSeine.class, builder, EDIT); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetSeine.PROPERTY_NON_TARGET_CATCH); + + registerTopiaBinder(SetSeine.class, builder, EDIT_NON_TARGET_CATCH); } { - BinderModelBuilder<SchoolEstimate, SchoolEstimate> builder = newBinderBuilder( - SchoolEstimate.class, - SchoolEstimate.PROPERTY_SET_SEINE, - SchoolEstimate.PROPERTY_SPECIES, - SchoolEstimate.PROPERTY_TOTAL_WEIGHT, - SchoolEstimate.PROPERTY_MEAN_WEIGHT); + BinderModelBuilder<TargetCatch, TargetCatch> builder = newBinderBuilder( + TargetCatch.class, + TargetCatch.PROPERTY_SET_SEINE, + TargetCatch.PROPERTY_WEIGHT_CATEGORY, + TargetCatch.PROPERTY_CATCH_WEIGHT, + TargetCatch.PROPERTY_WELL, + TargetCatch.PROPERTY_BROUGHT_ON_DECK, + TargetCatch.PROPERTY_DISCARDED, + TargetCatch.PROPERTY_COMMENT); - registerTopiaBinder(SchoolEstimate.class, builder, EDIT); + registerTopiaBinder(TargetCatch.class, builder, EDIT_TARGET_CATCH); } { BinderModelBuilder<SetSeine, SetSeine> builder = newBinderBuilder( SetSeine.class, - SetSeine.PROPERTY_COMMENT, - SetSeine.PROPERTY_SCHOOL_ESTIMATE); + SetSeine.PROPERTY_TARGET_CATCH); - registerTopiaBinder(SetSeine.class, builder, EDIT_SCHOOL_ESTIMATE); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetSeine.PROPERTY_TARGET_CATCH); + + registerTopiaBinder(SetSeine.class, builder, EDIT_TARGET_CATCH); } { - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_QUADRANT, - ActivitySeine.PROPERTY_LATITUDE, - ActivitySeine.PROPERTY_LONGITUDE, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_OPEN); + BinderModelBuilder<TargetCatch, TargetCatch> builder = newBinderBuilder( + TargetCatch.class, + TargetCatch.PROPERTY_SET_SEINE, + TargetCatch.PROPERTY_WEIGHT_CATEGORY, + TargetCatch.PROPERTY_CATCH_WEIGHT, + TargetCatch.PROPERTY_REASON_FOR_DISCARD, + TargetCatch.PROPERTY_DISCARDED, + TargetCatch.PROPERTY_BROUGHT_ON_DECK, + TargetCatch.PROPERTY_COMMENT); + + registerTopiaBinder(TargetCatch.class, builder, EDIT_DISCARD_TARGET_CATCH); - registerTopiaBinder(ActivitySeine.class, builder, EDIT); } { + BinderModelBuilder<SetSeine, SetSeine> builder = newBinderBuilder( + SetSeine.class, + SetSeine.PROPERTY_TARGET_CATCH); - BinderModelBuilder<Route, Route> builder = newBinderBuilder( - Route.class, - Route.PROPERTY_DATE, - Route.PROPERTY_START_LOG_VALUE, - Route.PROPERTY_END_LOG_VALUE, - Route.PROPERTY_CHECK_LEVEL, - Route.PROPERTY_ACTIVITY_SEINE, - Route.PROPERTY_OPEN, - Route.PROPERTY_COMMENT); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Route.PROPERTY_ACTIVITY_SEINE); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetSeine.PROPERTY_TARGET_CATCH); - registerTopiaBinder(Route.class, builder, EDIT); + registerTopiaBinder(SetSeine.class, builder, EDIT_DISCARD_TARGET_CATCH); } + { - BinderModelBuilder<Route, Route> builder = newBinderBuilder( - Route.class, - Route.PROPERTY_DATE, - Route.PROPERTY_OPEN); + BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); - registerTopiaBinder(Route.class, builder, DISPLAY); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); + + registerTopiaBinder(TripSeine.class, builder, EDIT_GEAR_USE_FEATURES_SEINE); } { - BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE, - FloatingObject.PROPERTY_COMMENT); - registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_SCHOOL_ESTIMATE); + BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( + TripSeine.class, + TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); + + registerTopiaBinder(TripSeine.class, builder, EDIT_GEAR_USE_FEATURES_SEINE); } { - BinderModelBuilder<ObjectSchoolEstimate, ObjectSchoolEstimate> builder = newBinderBuilder( - ObjectSchoolEstimate.class, - ObjectSchoolEstimate.PROPERTY_SPECIES, - ObjectSchoolEstimate.PROPERTY_TOTAL_WEIGHT); + BinderModelBuilder<GearUseFeaturesSeine, GearUseFeaturesSeine> builder = newBinderBuilder( + GearUseFeaturesSeine.class, + GearUseFeaturesSeine.PROPERTY_COMMENT, + GearUseFeaturesSeine.PROPERTY_GEAR, + GearUseFeaturesSeine.PROPERTY_NUMBER, + GearUseFeaturesSeine.PROPERTY_USED_IN_TRIP); - registerTopiaBinder(ObjectSchoolEstimate.class, builder, EDIT); + registerTopiaBinder(GearUseFeaturesSeine.class, builder, EDIT); } { - BinderModelBuilder<ObjectObservedSpecies, ObjectObservedSpecies> builder = newBinderBuilder( - ObjectObservedSpecies.class, - ObjectObservedSpecies.PROPERTY_SPECIES, - ObjectObservedSpecies.PROPERTY_SPECIES_STATUS, - ObjectObservedSpecies.PROPERTY_COUNT); + BinderModelBuilder<GearUseFeaturesMeasurementSeine, GearUseFeaturesMeasurementSeine> builder = + newBinderBuilder(GearUseFeaturesMeasurementSeine.class, + GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, + GearUseFeaturesMeasurementSeine.PROPERTY_MEASUREMENT_VALUE); - registerTopiaBinder(ObjectObservedSpecies.class, builder, EDIT); + registerTopiaBinder(GearUseFeaturesMeasurementSeine.class, builder, EDIT); } - { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES, - FloatingObject.PROPERTY_COMMENT); - registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OBSERVED_SPECIES); + } - } + protected static void registerLonglineBinders() { { - BinderModelBuilder<NonTargetLength, NonTargetLength> builder = newBinderBuilder( - NonTargetLength.class, - NonTargetLength.PROPERTY_SPECIES, - NonTargetLength.PROPERTY_LENGTH, - NonTargetLength.PROPERTY_LENGTH_SOURCE, - NonTargetLength.PROPERTY_WEIGHT, - NonTargetLength.PROPERTY_WEIGHT_SOURCE, - NonTargetLength.PROPERTY_SEX, - NonTargetLength.PROPERTY_COUNT, - NonTargetLength.PROPERTY_ACQUISITION_MODE, - NonTargetLength.PROPERTY_PICTURES_REFERENCES); - - registerTopiaBinder(NonTargetLength.class, builder, EDIT); + BinderModelBuilder<Branchline, Branchline> builder = newBinderBuilder( + Branchline.class, + Branchline.PROPERTY_COMMENT, + + // general tab + Branchline.PROPERTY_TOP_TYPE, + Branchline.PROPERTY_TRACELINE_TYPE, + Branchline.PROPERTY_DEPTH_RECORDER, + Branchline.PROPERTY_HOOK_LOST, + Branchline.PROPERTY_TRACE_CUT_OFF, + Branchline.PROPERTY_WEIGHTED_SWIVEL, + Branchline.PROPERTY_SWIVEL_WEIGHT, + Branchline.PROPERTY_WEIGHTED_SNAP, + Branchline.PROPERTY_SNAP_WEIGHT, + Branchline.PROPERTY_BAIT_TYPE, + Branchline.PROPERTY_TIMER, + Branchline.PROPERTY_TIME_SINCE_CONTACT, + Branchline.PROPERTY_TIMER_TIME_ON_BOARD, + + // hook and bait tab + Branchline.PROPERTY_HOOK_TYPE, + Branchline.PROPERTY_HOOK_SIZE, + Branchline.PROPERTY_HOOK_OFFSET, + Branchline.PROPERTY_BAIT_SETTING_STATUS, + Branchline.PROPERTY_BAIT_HAULING_STATUS + + ); + + registerTopiaBinder(Branchline.class, builder, EDIT); } { - BinderModelBuilder<NonTargetSample, NonTargetSample> builder = newBinderBuilder( - NonTargetSample.class, - NonTargetSample.PROPERTY_NON_TARGET_LENGTH, - NonTargetSample.PROPERTY_COMMENT); + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_QUADRANT, + ActivityLongline.PROPERTY_LATITUDE, + ActivityLongline.PROPERTY_LONGITUDE, + ActivityLongline.PROPERTY_TIME_STAMP, + ActivityLongline.PROPERTY_SEA_SURFACE_TEMPERATURE, + ActivityLongline.PROPERTY_COMMENT, + ActivityLongline.PROPERTY_SET_LONGLINE, + ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, + ActivityLongline.PROPERTY_FPA_ZONE, + ActivityLongline.PROPERTY_OPEN, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_SENSOR_USED); - registerTopiaBinder(NonTargetSample.class, builder, EDIT_NON_TARGET_LENGTH); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_ENCOUNTER); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_SENSOR_USED); + + registerTopiaBinder(ActivityLongline.class, builder, EDIT); } { - BinderModelBuilder<NonTargetSample, NonTargetSample> builder = newBinderBuilder( - NonTargetSample.class, - NonTargetSample.PROPERTY_NON_TARGET_LENGTH, - NonTargetSample.PROPERTY_COMMENT); - - registerTopiaBinder(NonTargetSample.class, builder, EDIT); + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_BAITS_COMPOSITION); - } + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_BAITS_COMPOSITION); + registerTopiaBinder(SetLongline.class, builder, EDIT_BAITS_COMPOSITION); - } + } - public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { + { - copy(type, context, source, target, true); + BinderModelBuilder<BaitsComposition, BaitsComposition> builder = newBinderBuilder( + BaitsComposition.class, + BaitsComposition.PROPERTY_BAIT_TYPE, + BaitsComposition.PROPERTY_BAIT_SETTING_STATUS, + BaitsComposition.PROPERTY_INDIVIDUAL_SIZE, + BaitsComposition.PROPERTY_INDIVIDUAL_WEIGHT, + BaitsComposition.PROPERTY_PROPORTION); - } + registerTopiaBinder(BaitsComposition.class, builder, EDIT); - public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { + } - TopiaEntityBinder<E> binder = getBinder(type, context); + { - binder.copyExcluding(source, target, propertyNames); + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_BRANCHLINES_COMPOSITION); - /* FIXME sbavencoff 29/04/2015 bind techincal fields */ - target.setTopiaId(source.getTopiaId()); - target.setTopiaVersion(source.getTopiaVersion()); - target.setTopiaCreateDate(source.getTopiaCreateDate()); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_BRANCHLINES_COMPOSITION); - } + registerTopiaBinder(SetLongline.class, builder, EDIT_BRANCHLINES_COMPOSITION); - public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { + } - TopiaEntityBinder<E> binder = getBinder(type, context); + { - binder.load(source, target, bindTechnical); + BinderModelBuilder<BranchlinesComposition, BranchlinesComposition> builder = newBinderBuilder( + BranchlinesComposition.class, + BranchlinesComposition.PROPERTY_TOP_TYPE, + BranchlinesComposition.PROPERTY_TRACELINE_TYPE, + BranchlinesComposition.PROPERTY_LENGTH, + BranchlinesComposition.PROPERTY_PROPORTION); - } + registerTopiaBinder(BranchlinesComposition.class, builder, EDIT); - public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> type, String context) { - TopiaEntityBinder<E> binder = getTopiaBinder(type, context); - if (binder == null) { - throw new IllegalArgumentException("Could not find binder for " + type.getName() + "::" + context); } - return binder; - } + { - public static <E extends TopiaEntity> BinderModelBuilder<E, E> newBinderBuilder(Class<E> type, String... properties) { - BinderModelBuilder<E, E> builder = BinderModelBuilder.newEmptyBuilder(type); - builder.addSimpleProperties(properties); - return builder; - } + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_CATCH_LONGLINE); - public <E extends TopiaEntity> TopiaEntityBinder<E> getTopiaBinder(Class<E> entityClass, - String contextName) { - if (ObserveBinderHelper.getCachedBinderModel(entityClass, entityClass, contextName) == null) { + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_CATCH_LONGLINE); + + registerTopiaBinder(SetLongline.class, builder, EDIT_CATCH_LONGLINE); - // we do not want to have auto created binder model by the factory - return null; } - return (TopiaEntityBinder<E>) ObserveBinderHelper.newBinder(entityClass, entityClass, contextName, TopiaEntityBinder.class); - } - public static <E extends TopiaEntity> TopiaEntityBinder<E> registerTopiaBinder(Class<E> entityClass, - BinderModelBuilder<E, E> builder, - String contextName) { - return ObserveBinderHelper.registerTopiaBinder(entityClass, builder, contextName); - } + { - public <E extends TopiaEntity> TopiaEntityBinder<E> getSimpleTopiaBinder(Class<E> entityClass) { - return getTopiaBinder(entityClass, "Observe"); - } + BinderModelBuilder<CatchLongline, CatchLongline> builder = newBinderBuilder( + CatchLongline.class, + CatchLongline.PROPERTY_SPECIES_CATCH, + CatchLongline.PROPERTY_ACQUISITION_MODE, + CatchLongline.PROPERTY_COUNT, + CatchLongline.PROPERTY_CATCH_HEALTHNESS, + CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, + CatchLongline.PROPERTY_DISCARD_HEALTHNESS, + CatchLongline.PROPERTY_DEPREDATED, + CatchLongline.PROPERTY_NUMBER, + CatchLongline.PROPERTY_HOME_ID, + CatchLongline.PROPERTY_HOOK_POSITION, + CatchLongline.PROPERTY_HOOK_WHEN_DISCARDED, + CatchLongline.PROPERTY_MATURITY_STATUS, + CatchLongline.PROPERTY_PHOTO_REFERENCES, + CatchLongline.PROPERTY_SEX, + CatchLongline.PROPERTY_PREDATOR, + CatchLongline.PROPERTY_STOMAC_FULLNESS, + CatchLongline.PROPERTY_TOTAL_WEIGHT, + CatchLongline.PROPERTY_BEAT_DIAMETER, + CatchLongline.PROPERTY_GONADE_WEIGHT, + CatchLongline.PROPERTY_SECTION, + CatchLongline.PROPERTY_BASKET, + CatchLongline.PROPERTY_BRANCHLINE, + CatchLongline.PROPERTY_COMMENT); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, CatchLongline.PROPERTY_PREDATOR); + + registerTopiaBinder(CatchLongline.class, builder, EDIT); - public <E extends TopiaEntity> void simpleCopy(E source, E target, boolean tech) { - Class<E> entityClass = (Class<E>) TopiaEntityHelper.getContractClass(ObserveDAOHelper.getContracts(), target.getClass()); - TopiaEntityBinder<E> binder = getSimpleTopiaBinder(entityClass); - if (binder == null) { - throw new NullPointerException("could not find a simple topia binder of type : " + target.getClass()); } - binder.load(source, target, tech); + + { + + BinderModelBuilder<Branchline, Branchline> builder = newBinderBuilder(Branchline.class, + Branchline.PROPERTY_DEPTH_RECORDER, + Branchline.PROPERTY_HOOK_LOST, + Branchline.PROPERTY_TRACE_CUT_OFF, + Branchline.PROPERTY_TIMER, + Branchline.PROPERTY_TIME_SINCE_CONTACT, + Branchline.PROPERTY_TIMER_TIME_ON_BOARD, + Branchline.PROPERTY_BAIT_HAULING_STATUS); + + registerTopiaBinder(Branchline.class, builder, EDIT_CATCH_LONGLINE); + + } + + { + + BinderModelBuilder<WeightMeasure, WeightMeasure> builder = newBinderBuilder(WeightMeasure.class, + WeightMeasure.PROPERTY_WEIGHT, + WeightMeasure.PROPERTY_WEIGHT_MEASURE_TYPE); + + registerTopiaBinder(WeightMeasure.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SizeMeasure, SizeMeasure> builder = newBinderBuilder(SizeMeasure.class, + SizeMeasure.PROPERTY_SIZE, + SizeMeasure.PROPERTY_SIZE_MEASURE_TYPE); + + registerTopiaBinder(SizeMeasure.class, builder, EDIT); + + } + + { + + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_ENCOUNTER, + ActivityLongline.PROPERTY_COMMENT); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_ENCOUNTER); + + registerTopiaBinder(ActivityLongline.class, builder, EDIT_ENCOUNTER); + + } + + { + + BinderModelBuilder<Encounter, Encounter> builder = newBinderBuilder( + Encounter.class, + Encounter.PROPERTY_SPECIES, + Encounter.PROPERTY_DISTANCE, + Encounter.PROPERTY_COUNT, + Encounter.PROPERTY_ENCOUNTER_TYPE); + + registerTopiaBinder(Encounter.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_FLOATLINES_COMPOSITION); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_FLOATLINES_COMPOSITION); + + registerTopiaBinder(SetLongline.class, builder, EDIT_FLOATLINES_COMPOSITION); + + } + + { + + BinderModelBuilder<FloatlinesComposition, FloatlinesComposition> builder = newBinderBuilder( + FloatlinesComposition.class, + FloatlinesComposition.PROPERTY_LINE_TYPE, + FloatlinesComposition.PROPERTY_LENGTH, + FloatlinesComposition.PROPERTY_PROPORTION); + + + registerTopiaBinder(FloatlinesComposition.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE); + + registerTopiaBinder(TripLongline.class, builder, EDIT_GEAR_USE_FEATURES_LONGLINE); + + } + + { + + BinderModelBuilder<GearUseFeaturesLongline, GearUseFeaturesLongline> builder = newBinderBuilder( + GearUseFeaturesLongline.class, + GearUseFeaturesLongline.PROPERTY_COMMENT, + GearUseFeaturesLongline.PROPERTY_GEAR, + GearUseFeaturesLongline.PROPERTY_NUMBER, + GearUseFeaturesLongline.PROPERTY_USED_IN_TRIP); + + registerTopiaBinder(GearUseFeaturesLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> builder = + newBinderBuilder(GearUseFeaturesMeasurementLongline.class, + GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, + GearUseFeaturesMeasurementLongline.PROPERTY_MEASUREMENT_VALUE); + + registerTopiaBinder(GearUseFeaturesMeasurementLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_HOOKS_COMPOSITION); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_HOOKS_COMPOSITION); + + registerTopiaBinder(SetLongline.class, builder, EDIT_HOOKS_COMPOSITION); + + } + + { + + BinderModelBuilder<HooksComposition, HooksComposition> builder = newBinderBuilder( + HooksComposition.class, + HooksComposition.PROPERTY_HOOK_TYPE, + HooksComposition.PROPERTY_HOOK_SIZE, + HooksComposition.PROPERTY_HOOK_OFFSET, + HooksComposition.PROPERTY_PROPORTION); + + registerTopiaBinder(HooksComposition.class, builder, EDIT); + + } + + { + + BinderModelBuilder<ActivityLongline, ActivityLongline> builder = newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_SENSOR_USED, + ActivityLongline.PROPERTY_COMMENT); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_SENSOR_USED); + + registerTopiaBinder(ActivityLongline.class, builder, EDIT_SENSOR_USED); + + } + + { + + BinderModelBuilder<SensorUsed, SensorUsed> builder = newBinderBuilder( + SensorUsed.class, + SensorUsed.PROPERTY_DATA, + SensorUsed.PROPERTY_DATA_FILENAME, + SensorUsed.PROPERTY_DATA_LOCATION, + SensorUsed.PROPERTY_SENSOR_SERIAL_NO, + SensorUsed.PROPERTY_SENSOR_TYPE, + SensorUsed.PROPERTY_SENSOR_BRAND, + SensorUsed.PROPERTY_SENSOR_DATA_FORMAT); + + registerTopiaBinder(SensorUsed.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_COMMENT, + + // setting tab + SetLongline.PROPERTY_HOME_ID, + SetLongline.PROPERTY_NUMBER, + + SetLongline.PROPERTY_SETTING_START_TIME_STAMP, + SetLongline.PROPERTY_SETTING_START_QUADRANT, + SetLongline.PROPERTY_SETTING_START_LATITUDE, + SetLongline.PROPERTY_SETTING_START_LONGITUDE, + + SetLongline.PROPERTY_SETTING_END_TIME_STAMP, + SetLongline.PROPERTY_SETTING_END_QUADRANT, + SetLongline.PROPERTY_SETTING_END_LATITUDE, + SetLongline.PROPERTY_SETTING_END_LONGITUDE, + + // setting caracteristics tab + SetLongline.PROPERTY_SETTING_SHAPE, + SetLongline.PROPERTY_LINE_TYPE, + SetLongline.PROPERTY_LIGHTSTICKS_TYPE, + SetLongline.PROPERTY_LIGHTSTICKS_COLOR, + SetLongline.PROPERTY_SETTING_VESSEL_SPEED, + SetLongline.PROPERTY_MAX_DEPTH_TARGETED, + SetLongline.PROPERTY_SHOOTER_USED, + SetLongline.PROPERTY_SHOOTER_SPEED, + SetLongline.PROPERTY_WEIGHTED_SWIVEL, + SetLongline.PROPERTY_SWIVEL_WEIGHT, + SetLongline.PROPERTY_WEIGHTED_SNAP, + SetLongline.PROPERTY_SNAP_WEIGHT, + SetLongline.PROPERTY_MONITORED, + SetLongline.PROPERTY_TIME_BETWEEN_HOOKS, + SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, + SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT, + SetLongline.PROPERTY_LIGHTSTICKS_PER_BASKET_COUNT, + SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, + SetLongline.PROPERTY_TOTAL_BASKETS_COUNT, + SetLongline.PROPERTY_TOTAL_HOOKS_COUNT, + + // hauling tab + SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, + + SetLongline.PROPERTY_HAULING_START_QUADRANT, + SetLongline.PROPERTY_HAULING_START_LATITUDE, + SetLongline.PROPERTY_HAULING_START_LONGITUDE, + SetLongline.PROPERTY_HAULING_START_TIME_STAMP, + + SetLongline.PROPERTY_HAULING_END_QUADRANT, + SetLongline.PROPERTY_HAULING_END_LATITUDE, + SetLongline.PROPERTY_HAULING_END_LONGITUDE, + SetLongline.PROPERTY_HAULING_END_TIME_STAMP, + + SetLongline.PROPERTY_HAULING_BREAKS); + + registerTopiaBinder(SetLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_TDR, + SetLongline.PROPERTY_SETTING_START_TIME_STAMP, + SetLongline.PROPERTY_SETTING_END_TIME_STAMP, + SetLongline.PROPERTY_HAULING_START_TIME_STAMP, + SetLongline.PROPERTY_HAULING_END_TIME_STAMP); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_TDR); + + registerTopiaBinder(SetLongline.class, builder, EDIT_TDR); + + } + + { + + BinderModelBuilder<Tdr, Tdr> builder = newBinderBuilder( + Tdr.class, + // caracteristics tab + Tdr.PROPERTY_HOME_ID, + Tdr.PROPERTY_SERIAL_NO, + Tdr.PROPERTY_SENSOR_BRAND, + Tdr.PROPERTY_DATA, + Tdr.PROPERTY_DATA_FILENAME, + Tdr.PROPERTY_DATA_LOCATION, + + // localisation tab + Tdr.PROPERTY_SECTION, + Tdr.PROPERTY_BASKET, + Tdr.PROPERTY_BRANCHLINE, + Tdr.PROPERTY_ITEM_HORIZONTAL_POSITION, + Tdr.PROPERTY_ITEM_VERTICAL_POSITION, + Tdr.PROPERTY_FLOATLINE1_LENGTH, + Tdr.PROPERTY_FLOATLINE2_LENGTH, + + // timestamp tab + Tdr.PROPERTY_DEPLOYEMENT_START, + Tdr.PROPERTY_DEPLOYEMENT_START_DATE, + Tdr.PROPERTY_DEPLOYEMENT_START_TIME, + Tdr.PROPERTY_DEPLOYEMENT_END, + Tdr.PROPERTY_DEPLOYEMENT_END_DATE, + Tdr.PROPERTY_DEPLOYEMENT_END_TIME, + Tdr.PROPERTY_FISHING_START, + Tdr.PROPERTY_FISHING_START_DATE, + Tdr.PROPERTY_FISHING_START_TIME, + Tdr.PROPERTY_FISHING_END, + Tdr.PROPERTY_FISHING_END_DATE, + Tdr.PROPERTY_FISHING_END_TIME, + + // key data tab + Tdr.PROPERTY_FISHING_START_DEPTH, + Tdr.PROPERTY_FISHING_END_DEPTH, + Tdr.PROPERTY_MEAN_DEPLOYEMENT_DEPTH, + Tdr.PROPERTY_MEDIAN_DEPLOYEMENT_DEPTH, + Tdr.PROPERTY_MEAN_FISHING_DEPTH, + Tdr.PROPERTY_MEDIAN_FISHING_DEPTH, + Tdr.PROPERTY_MIN_FISHING_DEPTH, + Tdr.PROPERTY_MAX_FISHING_DEPTH, + + // species tab + Tdr.PROPERTY_SPECIES); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Tdr.PROPERTY_SPECIES); + + registerTopiaBinder(Tdr.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_START_DATE, + TripLongline.PROPERTY_END_DATE, + TripLongline.PROPERTY_TRIP_TYPE, + TripLongline.PROPERTY_HOME_ID, + TripLongline.PROPERTY_COMMENT, + TripLongline.PROPERTY_VESSEL, + TripLongline.PROPERTY_OBSERVER, + TripLongline.PROPERTY_CAPTAIN, + TripLongline.PROPERTY_DATA_ENTRY_OPERATOR, + TripLongline.PROPERTY_TOTAL_FISHING_OPERATIONS_NUMBER, + TripLongline.PROPERTY_OCEAN, + TripLongline.PROPERTY_DEPARTURE_HARBOUR, + TripLongline.PROPERTY_LANDING_HARBOUR, + TripLongline.PROPERTY_PROGRAM, + TripLongline.PROPERTY_ACTIVITY_LONGLINE, + TripLongline.PROPERTY_OPEN); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + + registerTopiaBinder(TripLongline.class, builder, EDIT); + + } + + { + + BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_START_DATE, + TripLongline.PROPERTY_END_DATE, + TripLongline.PROPERTY_OPEN, + TripLongline.PROPERTY_OBSERVER, + TripLongline.PROPERTY_VESSEL, + TripLongline.PROPERTY_PROGRAM); + + registerTopiaBinder(TripLongline.class, builder, DISPLAY); + + } + + { + + BinderModelBuilder<SetLongline, SetLongline> builder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_MITIGATION_TYPE, + SetLongline.PROPERTY_COMMENT); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_MITIGATION_TYPE); + + registerTopiaBinder(SetLongline.class, builder, EDIT_GLOBAL_COMPOSITION); + + } + + { + + BinderModelBuilder<Branchline, Branchline> branchlineBuilder = newBinderBuilder( + Branchline.class, + Branchline.PROPERTY_SETTING_IDENTIFIER, + Branchline.PROPERTY_HAULING_IDENTIFIER, + Branchline.PROPERTY_TRACELINE_LENGTH, + Branchline.PROPERTY_BRANCHLINE_LENGTH, + Branchline.PROPERTY_COMMENT, + Branchline.PROPERTY_TOP_TYPE, + Branchline.PROPERTY_TRACELINE_TYPE, + Branchline.PROPERTY_DEPTH_RECORDER, + Branchline.PROPERTY_HOOK_LOST, + Branchline.PROPERTY_TRACE_CUT_OFF, + Branchline.PROPERTY_WEIGHTED_SWIVEL, + Branchline.PROPERTY_SWIVEL_WEIGHT, + Branchline.PROPERTY_WEIGHTED_SNAP, + Branchline.PROPERTY_SNAP_WEIGHT, + Branchline.PROPERTY_BAIT_TYPE, + Branchline.PROPERTY_BAIT_SETTING_STATUS, + Branchline.PROPERTY_BAIT_HAULING_STATUS, + Branchline.PROPERTY_HOOK_TYPE, + Branchline.PROPERTY_HOOK_SIZE, + Branchline.PROPERTY_HOOK_OFFSET, + Branchline.PROPERTY_TIMER, + Branchline.PROPERTY_TIME_SINCE_CONTACT, + Branchline.PROPERTY_TIMER_TIME_ON_BOARD); + + TopiaEntityBinder<Branchline> branchlineBinder = registerTopiaBinder(Branchline.class, branchlineBuilder, EDIT_DETAIL_COMPOSITION); + + BinderModelBuilder<Basket, Basket> basketBuilder = newBinderBuilder( + Basket.class, + Basket.PROPERTY_BRANCHLINE, + Basket.PROPERTY_SETTING_IDENTIFIER, + Basket.PROPERTY_HAULING_IDENTIFIER, + Basket.PROPERTY_FLOATLINE1_LENGTH, + Basket.PROPERTY_FLOATLINE2_LENGTH); + + basketBuilder.addCollectionBinder(branchlineBinder, Basket.PROPERTY_BRANCHLINE); + + TopiaEntityBinder<Basket> basketBinder = registerTopiaBinder(Basket.class, basketBuilder, EDIT_DETAIL_COMPOSITION); + + BinderModelBuilder<Section, Section> sectionBuilder = newBinderBuilder( + Section.class, + Section.PROPERTY_SET_LONGLINE, + Section.PROPERTY_BASKET, + Section.PROPERTY_SETTING_IDENTIFIER, + Section.PROPERTY_HAULING_IDENTIFIER); + + sectionBuilder.addCollectionBinder(basketBinder, Section.PROPERTY_BASKET); + + TopiaEntityBinder<Section> sectionBinder = registerTopiaBinder(Section.class, sectionBuilder, EDIT_DETAIL_COMPOSITION); + + BinderModelBuilder<SetLongline, SetLongline> setLonglineBuilder = newBinderBuilder( + SetLongline.class, + SetLongline.PROPERTY_SECTION, + SetLongline.PROPERTY_SETTING_START_TIME_STAMP, + SetLongline.PROPERTY_SETTING_END_TIME_STAMP, + SetLongline.PROPERTY_HAULING_START_TIME_STAMP, + SetLongline.PROPERTY_HAULING_END_TIME_STAMP, + SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, + SetLongline.PROPERTY_HAULING_BREAKS, + SetLongline.PROPERTY_MONITORED, + SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, + SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, + SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT + ); + setLonglineBuilder.addCollectionBinder(sectionBinder, SetLongline.PROPERTY_SECTION); + + registerTopiaBinder(SetLongline.class, setLonglineBuilder, EDIT_DETAIL_COMPOSITION); + + } + + { + + BinderModelBuilder<ActivityLongline, ActivityLongline> activityLonglineBuilder = newBinderBuilder( + ActivityLongline.class, + ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, + ActivityLongline.PROPERTY_TIME_STAMP, + ActivityLongline.PROPERTY_OPEN); + + TopiaEntityBinder<ActivityLongline> activityLonglineBinder = registerTopiaBinder(ActivityLongline.class, activityLonglineBuilder, DISPLAY_LIST); + + BinderModelBuilder<TripLongline, TripLongline> builder = newBinderBuilder( + TripLongline.class, + TripLongline.PROPERTY_OPEN, + TripLongline.PROPERTY_ACTIVITY_LONGLINE); + + builder.addCollectionBinder(activityLonglineBinder, TripLongline.PROPERTY_ACTIVITY_LONGLINE); + + registerTopiaBinder(TripLongline.class, builder, DISPLAY_LIST); + + } + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java index 7c91935..48eb5af 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java @@ -21,16 +21,14 @@ */ package fr.ird.observe.ui.content; -import fr.ird.observe.BinderService; +import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.ObserveTechnicalException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.beans.AbstractSerializableBean; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Le modèle d'un écran d'édition @@ -103,6 +101,24 @@ public abstract class ContentUIModel<E extends TopiaEntity> extends AbstractSeri } + public ContentUIModel(Class<E> beanType, String binderContext) { + this.beanType = beanType; + this.loadBinder = ObserveContext.get().getBinderService().getBinder(beanType, binderContext); + ObserveEntityEnum constant = ObserveEntityEnum.valueOf(beanType); + if (constant != null) { + try { + setBean((E) constant.getImplementation().newInstance()); + } catch (Exception e) { + // ne devrait jamain arrive + if (log.isErrorEnabled()) { + log.error(e); + } + } + } + + } + + public static <E extends TopiaEntity> ContentUIModel<E> newModel(ObserveContentUI<E> ui) { String uiName = ui.getClass().getName(); @@ -122,33 +138,33 @@ public abstract class ContentUIModel<E extends TopiaEntity> extends AbstractSeri public final TopiaEntityBinder<E> getLoadBinder() { - if (loadBinder == null) { - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - - String binderName = getClass().getName() + "-open"; - TopiaEntityBinder<E> r = binderService.getTopiaBinder(beanType, binderName); - if (r == null) { - - BinderModelBuilder<E, E> builder = createOpeningBinder(binderService, binderName); - - if (builder != null) { - - r = binderService.registerTopiaBinder(beanType, builder, binderName); - - } - - } - - loadBinder = r; - - } +// if (loadBinder == null) { +// +// BinderService binderService = ObserveServiceHelper.get().getBinderService(); +// +// String binderName = getClass().getName() + "-open"; +// TopiaEntityBinder<E> r = binderService.getTopiaBinder(beanType, binderName); +// if (r == null) { +// +// BinderModelBuilder<E, E> builder = createOpeningBinder(binderService, binderName); +// +// if (builder != null) { +// +// r = binderService.registerTopiaBinder(beanType, builder, binderName); +// +// } +// +// } +// +// loadBinder = r; +// +// } return loadBinder; } - protected abstract BinderModelBuilder<E, E> createOpeningBinder(BinderService binderService, String binderName); +// protected abstract BinderModelBuilder<E, E> createOpeningBinder(BinderService binderService, String binderName); public E getBean() { return bean; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java index 1b7956f..14a6758 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSet; import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Set; @@ -75,42 +74,7 @@ public class BranchlineUIModel extends ContentUIModel<Branchline> { private boolean hookAndBaitTabValid; public BranchlineUIModel() { - super(Branchline.class); - } - - @Override - protected BinderModelBuilder<Branchline, Branchline> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<Branchline, Branchline> builder = binderService.newBinderBuilder( - Branchline.class, - Branchline.PROPERTY_COMMENT, - - // general tab - Branchline.PROPERTY_TOP_TYPE, - Branchline.PROPERTY_TRACELINE_TYPE, - Branchline.PROPERTY_DEPTH_RECORDER, - Branchline.PROPERTY_HOOK_LOST, - Branchline.PROPERTY_TRACE_CUT_OFF, - Branchline.PROPERTY_WEIGHTED_SWIVEL, - Branchline.PROPERTY_SWIVEL_WEIGHT, - Branchline.PROPERTY_WEIGHTED_SNAP, - Branchline.PROPERTY_SNAP_WEIGHT, - Branchline.PROPERTY_BAIT_TYPE, - Branchline.PROPERTY_TIMER, - Branchline.PROPERTY_TIME_SINCE_CONTACT, - Branchline.PROPERTY_TIMER_TIME_ON_BOARD, - - // hook and bait tab - Branchline.PROPERTY_HOOK_TYPE, - Branchline.PROPERTY_HOOK_SIZE, - Branchline.PROPERTY_HOOK_OFFSET, - Branchline.PROPERTY_BAIT_SETTING_STATUS, - Branchline.PROPERTY_BAIT_HAULING_STATUS - - ); - - return builder; - + super(Branchline.class, BinderService.EDIT); } public Branchline getBranchline() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java index 1ccc090..885296b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java @@ -23,14 +23,13 @@ package fr.ird.observe.ui.content.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveServiceHelper; +import fr.ird.observe.ObserveContext; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.content.ContentUIModel; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 12/5/14. @@ -66,15 +65,19 @@ public class LonglineDetailCompositionUIModel extends ContentUIModel<SetLongline protected boolean branchlineDetailTabValid; - protected TopiaEntityBinder<Section> sectionBinder; + protected final TopiaEntityBinder<Section> sectionBinder; - protected TopiaEntityBinder<Basket> basketBinder; + protected final TopiaEntityBinder<Basket> basketBinder; - protected TopiaEntityBinder<Branchline> branchlineBinder; + protected final TopiaEntityBinder<Branchline> branchlineBinder; public LonglineDetailCompositionUIModel() { - super(SetLongline.class); + super(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION); + BinderService binderService = ObserveContext.get().getBinderService(); + this.sectionBinder = binderService.getBinder(Section.class, BinderService.EDIT_DETAIL_COMPOSITION); + this.basketBinder = binderService.getBinder(Basket.class, BinderService.EDIT_DETAIL_COMPOSITION); + this.branchlineBinder = binderService.getBinder(Branchline.class, BinderService.EDIT_DETAIL_COMPOSITION); this.sectionTemplatesTableModel = new SectionTemplatesTableModel(); this.sectionsTableModel = new SectionsTableModel(this); this.basketsTableModel = new BasketsTableModel(this); @@ -143,123 +146,15 @@ public class LonglineDetailCompositionUIModel extends ContentUIModel<SetLongline } public TopiaEntityBinder<Basket> getBasketBinder() { - - if (basketBinder == null) { - - String binderName = getClass().getName() + "-open"; - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - basketBinder = binderService.getTopiaBinder(Basket.class, binderName); - - if (basketBinder == null) { - - BinderModelBuilder<Basket, Basket> builderBasket = binderService.newBinderBuilder( - Basket.class, - Basket.PROPERTY_BRANCHLINE, - Basket.PROPERTY_SETTING_IDENTIFIER, - Basket.PROPERTY_HAULING_IDENTIFIER, - Basket.PROPERTY_FLOATLINE1_LENGTH, - Basket.PROPERTY_FLOATLINE2_LENGTH); - builderBasket.addCollectionBinder(getBranchlineBinder(), Basket.PROPERTY_BRANCHLINE); - - basketBinder = binderService.registerTopiaBinder(Basket.class, builderBasket, binderName); - - } - - } return basketBinder; } public TopiaEntityBinder<Branchline> getBranchlineBinder() { - if (branchlineBinder == null) { - - String binderName = getClass().getName() + "-open"; - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - branchlineBinder = binderService.getTopiaBinder(Branchline.class, binderName); - - if (branchlineBinder == null) { - - BinderModelBuilder<Branchline, Branchline> builderBranchline = binderService.newBinderBuilder( - Branchline.class, - Branchline.PROPERTY_SETTING_IDENTIFIER, - Branchline.PROPERTY_HAULING_IDENTIFIER, - Branchline.PROPERTY_TRACELINE_LENGTH, - Branchline.PROPERTY_BRANCHLINE_LENGTH, - Branchline.PROPERTY_COMMENT, - Branchline.PROPERTY_TOP_TYPE, - Branchline.PROPERTY_TRACELINE_TYPE, - Branchline.PROPERTY_DEPTH_RECORDER, - Branchline.PROPERTY_HOOK_LOST, - Branchline.PROPERTY_TRACE_CUT_OFF, - Branchline.PROPERTY_WEIGHTED_SWIVEL, - Branchline.PROPERTY_SWIVEL_WEIGHT, - Branchline.PROPERTY_WEIGHTED_SNAP, - Branchline.PROPERTY_SNAP_WEIGHT, - Branchline.PROPERTY_BAIT_TYPE, - Branchline.PROPERTY_BAIT_SETTING_STATUS, - Branchline.PROPERTY_BAIT_HAULING_STATUS, - Branchline.PROPERTY_HOOK_TYPE, - Branchline.PROPERTY_HOOK_SIZE, - Branchline.PROPERTY_HOOK_OFFSET, - Branchline.PROPERTY_TIMER, - Branchline.PROPERTY_TIME_SINCE_CONTACT, - Branchline.PROPERTY_TIMER_TIME_ON_BOARD); - - branchlineBinder = binderService.registerTopiaBinder(Branchline.class, builderBranchline, binderName); - } - - } return branchlineBinder; } public TopiaEntityBinder<Section> getSectionBinder() { - if (sectionBinder == null) { - - String binderName = getClass().getName() + "-open"; - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - sectionBinder = binderService.getTopiaBinder(Section.class, binderName); - - if (sectionBinder == null) { - - BinderModelBuilder<Section, Section> builderSection = binderService.newBinderBuilder( - Section.class, - Section.PROPERTY_SET_LONGLINE, - Section.PROPERTY_BASKET, - Section.PROPERTY_SETTING_IDENTIFIER, - Section.PROPERTY_HAULING_IDENTIFIER); - builderSection.addCollectionBinder(getBasketBinder(), Section.PROPERTY_BASKET); - - sectionBinder = binderService.registerTopiaBinder(Section.class, builderSection, binderName); - - } - - } return sectionBinder; } - @Override - protected BinderModelBuilder<SetLongline, SetLongline> createOpeningBinder(BinderService binderService, String binderName) { - - // SetLongline binder - - BinderModelBuilder<SetLongline, SetLongline> builderSetLongline = binderService.newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_SECTION, - SetLongline.PROPERTY_SETTING_START_TIME_STAMP, - SetLongline.PROPERTY_SETTING_END_TIME_STAMP, - SetLongline.PROPERTY_HAULING_START_TIME_STAMP, - SetLongline.PROPERTY_HAULING_END_TIME_STAMP, - SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, - SetLongline.PROPERTY_HAULING_BREAKS, - SetLongline.PROPERTY_MONITORED, - SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, - SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, - SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT - ); - builderSetLongline.addCollectionBinder(getSectionBinder(), SetLongline.PROPERTY_SECTION); - return builderSetLongline; - - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIModel.java index 4631e12..219ed5c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIModel.java @@ -25,8 +25,6 @@ package fr.ird.observe.ui.content.impl.longline; import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 12/5/14. @@ -39,20 +37,7 @@ public class LonglineGlobalCompositionUIModel extends ContentUIModel<SetLongline private static final long serialVersionUID = 1L; public LonglineGlobalCompositionUIModel() { - super(SetLongline.class); + super(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION); } - @Override - protected BinderModelBuilder<SetLongline, SetLongline> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<SetLongline, SetLongline> builder = binderService.newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_MITIGATION_TYPE, - SetLongline.PROPERTY_COMMENT); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, SetLongline.PROPERTY_MITIGATION_TYPE); - - return builder; - - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIModel.java index af4588b..ba14ede 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIModel.java @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSet; import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Set; @@ -101,69 +100,7 @@ public class SetLonglineUIModel extends ContentUIModel<SetLongline> { protected boolean haulingTabValid; public SetLonglineUIModel() { - super(SetLongline.class); - } - - @Override - protected BinderModelBuilder<SetLongline, SetLongline> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<SetLongline, SetLongline> builder = binderService.newBinderBuilder( - SetLongline.class, - SetLongline.PROPERTY_COMMENT, - - // setting tab - SetLongline.PROPERTY_HOME_ID, - SetLongline.PROPERTY_NUMBER, - - SetLongline.PROPERTY_SETTING_START_TIME_STAMP, - SetLongline.PROPERTY_SETTING_START_QUADRANT, - SetLongline.PROPERTY_SETTING_START_LATITUDE, - SetLongline.PROPERTY_SETTING_START_LONGITUDE, - - SetLongline.PROPERTY_SETTING_END_TIME_STAMP, - SetLongline.PROPERTY_SETTING_END_QUADRANT, - SetLongline.PROPERTY_SETTING_END_LATITUDE, - SetLongline.PROPERTY_SETTING_END_LONGITUDE, - - // setting caracteristics tab - SetLongline.PROPERTY_SETTING_SHAPE, - SetLongline.PROPERTY_LINE_TYPE, - SetLongline.PROPERTY_LIGHTSTICKS_TYPE, - SetLongline.PROPERTY_LIGHTSTICKS_COLOR, - SetLongline.PROPERTY_SETTING_VESSEL_SPEED, - SetLongline.PROPERTY_MAX_DEPTH_TARGETED, - SetLongline.PROPERTY_SHOOTER_USED, - SetLongline.PROPERTY_SHOOTER_SPEED, - SetLongline.PROPERTY_WEIGHTED_SWIVEL, - SetLongline.PROPERTY_SWIVEL_WEIGHT, - SetLongline.PROPERTY_WEIGHTED_SNAP, - SetLongline.PROPERTY_SNAP_WEIGHT, - SetLongline.PROPERTY_MONITORED, - SetLongline.PROPERTY_TIME_BETWEEN_HOOKS, - SetLongline.PROPERTY_BASKETS_PER_SECTION_COUNT, - SetLongline.PROPERTY_BRANCHLINES_PER_BASKET_COUNT, - SetLongline.PROPERTY_LIGHTSTICKS_PER_BASKET_COUNT, - SetLongline.PROPERTY_TOTAL_SECTIONS_COUNT, - SetLongline.PROPERTY_TOTAL_BASKETS_COUNT, - SetLongline.PROPERTY_TOTAL_HOOKS_COUNT, - - // hauling tab - SetLongline.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, - - SetLongline.PROPERTY_HAULING_START_QUADRANT, - SetLongline.PROPERTY_HAULING_START_LATITUDE, - SetLongline.PROPERTY_HAULING_START_LONGITUDE, - SetLongline.PROPERTY_HAULING_START_TIME_STAMP, - - SetLongline.PROPERTY_HAULING_END_QUADRANT, - SetLongline.PROPERTY_HAULING_END_LATITUDE, - SetLongline.PROPERTY_HAULING_END_LONGITUDE, - SetLongline.PROPERTY_HAULING_END_TIME_STAMP, - - SetLongline.PROPERTY_HAULING_BREAKS); - - return builder; - + super(SetLongline.class, BinderService.EDIT); } public boolean isHaulingTabValid() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIModel.java index 03f67e9..a73702b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIModel.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/28/14. @@ -38,21 +37,7 @@ public class ActivitySeineObservedSystemUIModel extends ContentUIModel<ActivityS private static final long serialVersionUID = 1L; public ActivitySeineObservedSystemUIModel() { - super(ActivitySeine.class); - } - - @Override - protected BinderModelBuilder<ActivitySeine, ActivitySeine> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_SET_SEINE, - ActivitySeine.PROPERTY_COMMENT, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE); - - return builder; - + super(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java index 3fe2242..36d6015 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/28/14. @@ -40,7 +39,7 @@ public class FloatingObjectTransmittingBuoyOperationUIModel extends ContentUIMod // protected TopiaEntityBinder<TransmittingBuoy> childLoador; public FloatingObjectTransmittingBuoyOperationUIModel() { - super(FloatingObject.class); + super(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION); // String binderName = getClass().getName() + "-open"; // @@ -68,20 +67,7 @@ public class FloatingObjectTransmittingBuoyOperationUIModel extends ContentUIMod } -// public TopiaEntityBinder<TransmittingBuoy> getChildLoador() { -// return childLoador; -// } - - @Override - protected BinderModelBuilder<FloatingObject, FloatingObject> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_COMMENT, - FloatingObject.PROPERTY_OBJECT_OPERATION - ); - return builder; - - } +// @Override +// protected BinderModelBuilder<FloatingObject, FloatingObject> createOpeningBinder(BinderService binderService, String binderName) { return null; } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIModel.java index 90723e1..c0210df 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIModel.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/28/14. @@ -38,23 +37,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObject> { private static final long serialVersionUID = 1L; public FloatingObjectUIModel() { - super(FloatingObject.class); - } - - @Override - protected BinderModelBuilder<FloatingObject, FloatingObject> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_OBJECT_TYPE, - FloatingObject.PROPERTY_OBJECT_FATE, - FloatingObject.PROPERTY_OBJECT_OPERATION, - FloatingObject.PROPERTY_COMMENT, - FloatingObject.PROPERTY_SUPPORT_VESSEL_NAME, - FloatingObject.PROPERTY_DAYS_AT_SEA_COUNT); - - return builder; - + super(FloatingObject.class, BinderService.EDIT); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIModel.java index 118e103..f613050 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIModel.java @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSet; import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Set; @@ -70,7 +69,7 @@ public class SetSeineUIModel extends ContentUIModel<SetSeine> { public SetSeineUIModel() { - super(SetSeine.class); + super(SetSeine.class, BinderService.EDIT); } public boolean isMeasurementsTabValid() { @@ -93,33 +92,4 @@ public class SetSeineUIModel extends ContentUIModel<SetSeine> { firePropertyChange(PROPERTY_GENERAL_TAB_VALID, oldValue, generalTabValid); } - @Override - protected BinderModelBuilder<SetSeine, SetSeine> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<SetSeine, SetSeine> builder = binderService.newBinderBuilder( - SetSeine.class, - SetSeine.PROPERTY_COMMENT, - SetSeine.PROPERTY_SUPPORT_VESSEL_NAME, - SetSeine.PROPERTY_START_TIME, - SetSeine.PROPERTY_END_SET_TIME_STAMP, - SetSeine.PROPERTY_END_PURSING_TIME_STAMP, - SetSeine.PROPERTY_CURRENT_DIRECTION, - SetSeine.PROPERTY_CURRENT_SPEED, - SetSeine.PROPERTY_REASON_FOR_NULL_SET, - SetSeine.PROPERTY_SCHOOL_THICKNESS, - SetSeine.PROPERTY_MAX_GEAR_DEPTH, - SetSeine.PROPERTY_SCHOOL_MEAN_DEPTH, - SetSeine.PROPERTY_SCHOOL_TOP_DEPTH, - SetSeine.PROPERTY_CURRENT_MEASURE_DEPTH, - SetSeine.PROPERTY_TARGET_DISCARDED, - SetSeine.PROPERTY_NON_TARGET_DISCARDED, - SetSeine.PROPERTY_SCHOOL_TYPE, - SetSeine.PROPERTY_SONAR_USED, - SetSeine.PROPERTY_TARGET_SAMPLE, - SetSeine.PROPERTY_NON_TARGET_SAMPLE); - - return builder; - - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIModel.java index 4ec81be..b8fce79 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIModel.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.list; +import fr.ird.observe.BinderService; import fr.ird.observe.ui.content.ContentUIModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,7 +63,7 @@ public abstract class ContentListUIModel<E extends TopiaEntity, C extends TopiaE protected boolean canReopen; public ContentListUIModel(Class<E> beanType, Class<C> childType) { - super(beanType); + super(beanType, BinderService.DISPLAY_LIST); this.childType = childType; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java index 5f88dff..742c843 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIModel.java @@ -22,12 +22,9 @@ package fr.ird.observe.ui.content.list.impl.longline; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.ui.content.list.ContentListUIModel; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -43,26 +40,4 @@ public class ActivityLonglinesUIModel extends ContentListUIModel<TripLongline, A super(TripLongline.class, ActivityLongline.class); } - @Override - protected BinderModelBuilder<TripLongline, TripLongline> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<TripLongline, TripLongline> builder = binderService.newBinderBuilder( - TripLongline.class, - TripLongline.PROPERTY_OPEN, - TripLongline.PROPERTY_ACTIVITY_LONGLINE); - - BinderModelBuilder<ActivityLongline, ActivityLongline> builder2 = binderService.newBinderBuilder( - ActivityLongline.class, - ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, - ActivityLongline.PROPERTY_TIME_STAMP, - ActivityLongline.PROPERTY_OPEN); - - TopiaEntityBinder<ActivityLongline> binder = - binderService.registerTopiaBinder(ActivityLongline.class, builder2, binderName); - - builder.addCollectionBinder(binder, TripLongline.PROPERTY_ACTIVITY_LONGLINE); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java index 48d95f4..6f1dfb7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIModel.java @@ -22,11 +22,9 @@ package fr.ird.observe.ui.content.list.impl.longline; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.ui.content.list.ContentListUIModel; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -42,21 +40,4 @@ public class TripLonglinesUIModel extends ContentListUIModel<Program, TripLongli super(Program.class, TripLongline.class); } - @Override - protected BinderModelBuilder<Program, Program> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<Program, Program> builder = binderService.newBinderBuilder( - Program.class, - Program.PROPERTY_LABEL1, - Program.PROPERTY_LABEL2, - Program.PROPERTY_LABEL3, - Program.PROPERTY_LABEL4, - Program.PROPERTY_LABEL5, - Program.PROPERTY_LABEL6, - Program.PROPERTY_LABEL7, - Program.PROPERTY_LABEL8); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIModel.java index 3036a3d..1c04cf7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIModel.java @@ -22,12 +22,9 @@ package fr.ird.observe.ui.content.list.impl.seine; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.ui.content.list.ContentListUIModel; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -43,31 +40,4 @@ public class ActivitySeinesUIModel extends ContentListUIModel<Route, ActivitySei super(Route.class, ActivitySeine.class); } - @Override - protected BinderModelBuilder<Route, Route> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<Route, Route> builder = binderService.newBinderBuilder( - Route.class, - Route.PROPERTY_OPEN, - Route.PROPERTY_ACTIVITY_SEINE); - -// // on ajoute la recopie de l'association route -// builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, -// Route.PROPERTY_ACTIVITY_SEINE -// ); - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder2 = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_OPEN); - - TopiaEntityBinder<ActivitySeine> binder = - binderService.registerTopiaBinder(ActivitySeine.class, builder2, binderName); - - builder.addCollectionBinder(binder, Route.PROPERTY_ACTIVITY_SEINE); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIModel.java index f778002..c61b41a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIModel.java @@ -22,12 +22,9 @@ package fr.ird.observe.ui.content.list.impl.seine; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.ui.content.list.ContentListUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -43,18 +40,4 @@ public class RoutesUIModel extends ContentListUIModel<TripSeine, Route> { super(TripSeine.class, Route.class); } - @Override - protected BinderModelBuilder<TripSeine, TripSeine> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<TripSeine, TripSeine> builder = binderService.newBinderBuilder( - TripSeine.class, - TripSeine.PROPERTY_OPEN, - TripSeine.PROPERTY_ROUTE); - - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java index af7ca80..7f0db06 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIModel.java @@ -22,11 +22,9 @@ package fr.ird.observe.ui.content.list.impl.seine; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.ui.content.list.ContentListUIModel; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -42,21 +40,4 @@ public class TripSeinesUIModel extends ContentListUIModel<Program, TripSeine> { super(Program.class, TripSeine.class); } - @Override - protected BinderModelBuilder<Program, Program> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<Program, Program> builder = binderService.newBinderBuilder( - Program.class, - Program.PROPERTY_LABEL1, - Program.PROPERTY_LABEL2, - Program.PROPERTY_LABEL3, - Program.PROPERTY_LABEL4, - Program.PROPERTY_LABEL5, - Program.PROPERTY_LABEL6, - Program.PROPERTY_LABEL7, - Program.PROPERTY_LABEL8); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIModel.java index 1dc3c7f..706bc41 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIModel.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.open; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.OpenableEntity; import fr.ird.observe.ui.content.ContentUIModel; import org.nuiton.topia.persistence.TopiaEntity; @@ -44,7 +45,7 @@ public abstract class ContentOpenableUIModel<E extends TopiaEntity & OpenableEnt protected boolean historicalData; public ContentOpenableUIModel(Class<E> beanType) { - super(beanType); + super(beanType, BinderService.EDIT); } public boolean isCanReopen() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIModel.java index 2450ecc..0bf6360 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIModel.java @@ -22,11 +22,8 @@ package fr.ird.observe.ui.content.open.impl.longline; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -42,29 +39,4 @@ public class ActivityLonglineUIModel extends ContentOpenableUIModel<ActivityLong super(ActivityLongline.class); } - @Override - protected BinderModelBuilder<ActivityLongline, ActivityLongline> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<ActivityLongline, ActivityLongline> builder = binderService.newBinderBuilder( - ActivityLongline.class, - ActivityLongline.PROPERTY_QUADRANT, - ActivityLongline.PROPERTY_LATITUDE, - ActivityLongline.PROPERTY_LONGITUDE, - ActivityLongline.PROPERTY_TIME_STAMP, - ActivityLongline.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivityLongline.PROPERTY_COMMENT, - ActivityLongline.PROPERTY_SET_LONGLINE, - ActivityLongline.PROPERTY_VESSEL_ACTIVITY_LONGLINE, - ActivityLongline.PROPERTY_FPA_ZONE, - ActivityLongline.PROPERTY_OPEN, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_ENCOUNTER); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivityLongline.PROPERTY_SENSOR_USED); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIModel.java index 5152309..24bfaf7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIModel.java @@ -22,11 +22,8 @@ package fr.ird.observe.ui.content.open.impl.longline; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -42,32 +39,4 @@ public class TripLonglineUIModel extends ContentOpenableUIModel<TripLongline> { super(TripLongline.class); } - @Override - protected BinderModelBuilder<TripLongline, TripLongline> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<TripLongline, TripLongline> builder = binderService.newBinderBuilder( - TripLongline.class, - TripLongline.PROPERTY_START_DATE, - TripLongline.PROPERTY_END_DATE, - TripLongline.PROPERTY_TRIP_TYPE, - TripLongline.PROPERTY_HOME_ID, - TripLongline.PROPERTY_COMMENT, - TripLongline.PROPERTY_VESSEL, - TripLongline.PROPERTY_OBSERVER, - TripLongline.PROPERTY_CAPTAIN, - TripLongline.PROPERTY_DATA_ENTRY_OPERATOR, - TripLongline.PROPERTY_TOTAL_FISHING_OPERATIONS_NUMBER, - TripLongline.PROPERTY_OCEAN, - TripLongline.PROPERTY_DEPARTURE_HARBOUR, - TripLongline.PROPERTY_LANDING_HARBOUR, - TripLongline.PROPERTY_PROGRAM, - TripLongline.PROPERTY_ACTIVITY_LONGLINE, - TripLongline.PROPERTY_OPEN); - - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripLongline.PROPERTY_ACTIVITY_LONGLINE); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIModel.java index 5a5e851..1088c12 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIModel.java @@ -23,11 +23,8 @@ package fr.ird.observe.ui.content.open.impl.seine; */ import com.google.common.collect.ImmutableSet; -import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Set; @@ -92,37 +89,4 @@ public class ActivitySeineUIModel extends ContentOpenableUIModel<ActivitySeine> firePropertyChange(PROPERTY_GENERAL_TAB_VALID, oldValue, generalTabValid); } - @Override - protected BinderModelBuilder<ActivitySeine, ActivitySeine> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_QUADRANT, - ActivitySeine.PROPERTY_LATITUDE, - ActivitySeine.PROPERTY_LONGITUDE, - ActivitySeine.PROPERTY_ERS_ID, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, - ActivitySeine.PROPERTY_COMMENT, - ActivitySeine.PROPERTY_VESSEL_SPEED, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, - ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_DETECTION_MODE, - ActivitySeine.PROPERTY_SET_SEINE, - ActivitySeine.PROPERTY_FLOATING_OBJECT, - ActivitySeine.PROPERTY_OPEN, - ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, - ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, - ActivitySeine.PROPERTY_NEXT_FPA_ZONE); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); - - return builder; - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIModel.java index 78be644..d135b84 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIModel.java @@ -22,12 +22,8 @@ package fr.ird.observe.ui.content.open.impl.seine; * #L% */ -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -43,37 +39,4 @@ public class RouteUIModel extends ContentOpenableUIModel<Route> { super(Route.class); } - @Override - protected BinderModelBuilder<Route, Route> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<Route, Route> builder = binderService.newBinderBuilder( - Route.class, - Route.PROPERTY_DATE, - Route.PROPERTY_START_LOG_VALUE, - Route.PROPERTY_END_LOG_VALUE, - Route.PROPERTY_CHECK_LEVEL, - Route.PROPERTY_ACTIVITY_SEINE, - Route.PROPERTY_OPEN, - Route.PROPERTY_COMMENT); - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder2 = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_QUADRANT, - ActivitySeine.PROPERTY_LATITUDE, - ActivitySeine.PROPERTY_LONGITUDE, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_OPEN); - - TopiaEntityBinder<ActivitySeine> binder = - binderService.registerTopiaBinder(ActivitySeine.class, builder2, binderName); - - builder.addCollectionBinder(binder, Route.PROPERTY_ACTIVITY_SEINE); - - return builder; - - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIModel.java index ddaab6b..c2b10dc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIModel.java @@ -22,11 +22,8 @@ package fr.ird.observe.ui.content.open.impl.seine; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/26/14. @@ -42,33 +39,4 @@ public class TripSeineUIModel extends ContentOpenableUIModel<TripSeine> { super(TripSeine.class); } - @Override - protected BinderModelBuilder<TripSeine, TripSeine> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<TripSeine, TripSeine> builder = binderService.newBinderBuilder( - TripSeine.class, - TripSeine.PROPERTY_START_DATE, - TripSeine.PROPERTY_END_DATE, - TripSeine.PROPERTY_FORMS_URL, - TripSeine.PROPERTY_REPORTS_URL, - TripSeine.PROPERTY_COMMENT, - TripSeine.PROPERTY_VESSEL, - TripSeine.PROPERTY_OBSERVER, - TripSeine.PROPERTY_CAPTAIN, - TripSeine.PROPERTY_DATA_ENTRY_OPERATOR, - TripSeine.PROPERTY_OCEAN, - TripSeine.PROPERTY_DEPARTURE_HARBOUR, - TripSeine.PROPERTY_LANDING_HARBOUR, - TripSeine.PROPERTY_PROGRAM, - TripSeine.PROPERTY_ROUTE, - TripSeine.PROPERTY_ERS_ID, - TripSeine.PROPERTY_OPEN); - - // on ajoute la recopie de l'association route - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_ROUTE); - - return builder; - - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java index 0ac9b91..519846b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java @@ -173,6 +173,12 @@ public abstract class ContentReferenceUIModel<E extends ReferenceEntity> extends List<String> bindings = buildDataBindings(useDefault, extraBindings); this.dataBinding = bindings.toArray(new String[bindings.size()]); +// BinderService binderService = ObserveServiceHelper.get().getBinderService(); + BinderModelBuilder<E, E> builder = BinderService.newBinderBuilder(beanType, this.properties); + this.loadBinder = BinderService.registerTopiaBinder(beanType, builder, BinderService.EDIT); + +// this.loadBinder = binderService.getBinder(beanType, BinderService.EDIT); + } @@ -194,20 +200,20 @@ public abstract class ContentReferenceUIModel<E extends ReferenceEntity> extends firePropertyChange(PROPERTY_SELECTED_BEAN, oldvalue, selectedBean); } - @Override - protected BinderModelBuilder<E, E> createOpeningBinder(BinderService binderService, String binderName) { - - BinderModelBuilder<E, E> builder = binderService.newBinderBuilder(beanType, properties); - - if (log.isDebugEnabled()) { - log.debug("new binder [" + getClass().getName() + "#" + - beanType.getName() + "] : " + - Arrays.toString(properties) - ); - } - - return builder; - } +// @Override +// protected BinderModelBuilder<E, E> createOpeningBinder(BinderService binderService, String binderName) { +// +// BinderModelBuilder<E, E> builder = binderService.newBinderBuilder(beanType, properties); +// +// if (log.isDebugEnabled()) { +// log.debug("new binder [" + getClass().getName() + "#" + +// beanType.getName() + "] : " + +// Arrays.toString(properties) +// ); +// } +// +// return builder; +// } /** diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferenceHomeUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferenceHomeUIModel.java index b9c99f6..4fc3b87 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferenceHomeUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferenceHomeUIModel.java @@ -22,10 +22,8 @@ package fr.ird.observe.ui.content.ref; * #L% */ -import fr.ird.observe.BinderService; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.beans.BinderModelBuilder; /** * Created on 9/28/14. @@ -41,9 +39,4 @@ public class ReferenceHomeUIModel extends ContentUIModel<Program> { super(Program.class); } - @Override - protected BinderModelBuilder<Program, Program> createOpeningBinder(BinderService binderService, String binderName) { - return null; - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java index f0b6de4..2f6646b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java @@ -32,8 +32,6 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import javax.swing.DefaultListSelectionModel; import javax.swing.ListSelectionModel; @@ -62,10 +60,6 @@ public abstract class ContentTableUIModel<E extends TopiaEntity, D extends Topia protected final Class<D> childType; - protected final String[] parentProperties; - - protected final String[] childProperties; - private final ListSelectionModel selectionModel; protected D tableEditBean; @@ -89,19 +83,24 @@ public abstract class ContentTableUIModel<E extends TopiaEntity, D extends Topia private ContentTableModel<E, D> tableModel; - private TopiaEntityBinder<D> childLoador; + private final TopiaEntityBinder<D> childLoador; - private EntityListUpdator<E, D> childsUpdator; + private final EntityListUpdator<E, D> childsUpdator; public ContentTableUIModel(Class<E> beanType, Class<D> childType, - String[] parentProperties, - String[] childProperties) { - super(beanType); + String beanBinderContext, + String childBinderContext, + String collectionName) { + super(beanType, beanBinderContext); this.childType = childType; - this.parentProperties = parentProperties; - this.childProperties = childProperties; + this.childsUpdator = EntityListUpdator.newEntityListUpdator(beanType, childType, collectionName); this.selectionModel = new ContentTableListSelectionModel(); + + BinderService binderService = ObserveServiceHelper.get().getBinderService(); + + this.childLoador = binderService.getTopiaBinder(childType, childBinderContext); + } public static <E extends TopiaEntity, D extends TopiaEntity> ContentTableUIModel<E, D> newModel(ObserveContentTableUI<E, D> ui) { @@ -121,44 +120,10 @@ public abstract class ContentTableUIModel<E extends TopiaEntity, D extends Topia } - @Override - protected BinderModelBuilder<E, E> createOpeningBinder(BinderService binderService, String binderName) { - - String[] properties = getParentProperties(); - - BinderModelBuilder<E, E> builder = binderService.newBinderBuilder(getBeanType(), properties); - - // la première propriete est l'association - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, properties[0]); - - return builder; - } - public void initModel(ObserveContentTableUI<E, D> ui, List<ContentTableMeta<D>> metas) { this.tableModel = createTableModel(ui, metas); - this.childsUpdator = EntityListUpdator.newEntityListUpdator( - getBeanType(), - getChildType(), - getParentProperties()[0]); - - - String binderName = getClass().getName() + "-open"; - Class<D> childBeanType = getChildType(); - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - - childLoador = binderService.getTopiaBinder(childBeanType, binderName); - - if (childLoador == null) { - - BinderModelBuilder<D, D> builder = prepareChildLoador(binderService, binderName); - - childLoador = binderService.registerTopiaBinder(childBeanType, builder, binderName); - - } - } protected ContentTableModel<E, D> createTableModel(ObserveContentTableUI<E, D> ui, List<ContentTableMeta<D>> metas) { @@ -177,14 +142,6 @@ public abstract class ContentTableUIModel<E extends TopiaEntity, D extends Topia return childType; } - public String[] getParentProperties() { - return parentProperties; - } - - public String[] getChildProperties() { - return childProperties; - } - public ContentTableModel<E, D> getTableModel() { return tableModel; } @@ -259,16 +216,6 @@ public abstract class ContentTableUIModel<E extends TopiaEntity, D extends Topia firePropertyChange(PROPERTY_SHOW_DATA, oldValue, showData); } - protected BinderModelBuilder<D, D> prepareChildLoador(BinderService binderService, String binderName) { - - String[] properties = getChildProperties(); - - BinderModelBuilder<D, D> builder = binderService.newBinderBuilder(childType, properties); - - return builder; - - } - /** * Le modèle de sélection pour un tableau. * <p/> diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIModel.java index 45d9795..83131ed 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.BaitsComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -43,13 +44,13 @@ public class BaitsCompositionUIModel extends ContentTableUIModel<SetLongline, Ba public BaitsCompositionUIModel(BaitsCompositionUI ui) { super(SetLongline.class, - BaitsComposition.class, - new String[]{SetLongline.PROPERTY_BAITS_COMPOSITION}, - new String[]{BaitsComposition.PROPERTY_BAIT_TYPE, - BaitsComposition.PROPERTY_BAIT_SETTING_STATUS, - BaitsComposition.PROPERTY_INDIVIDUAL_SIZE, - BaitsComposition.PROPERTY_INDIVIDUAL_WEIGHT, - BaitsComposition.PROPERTY_PROPORTION}); + BaitsComposition.class, BinderService.EDIT_BAITS_COMPOSITION, BinderService.EDIT,SetLongline.PROPERTY_BAITS_COMPOSITION); +// new String[]{SetLongline.PROPERTY_BAITS_COMPOSITION}, +// new String[]{BaitsComposition.PROPERTY_BAIT_TYPE, +// BaitsComposition.PROPERTY_BAIT_SETTING_STATUS, +// BaitsComposition.PROPERTY_INDIVIDUAL_SIZE, +// BaitsComposition.PROPERTY_INDIVIDUAL_WEIGHT, +// BaitsComposition.PROPERTY_PROPORTION}); List<ContentTableMeta<BaitsComposition>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(BaitsComposition.class, BaitsComposition.PROPERTY_BAIT_TYPE, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIModel.java index c038403..86f207a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.BranchlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -43,12 +44,13 @@ public class BranchlinesCompositionUIModel extends ContentTableUIModel<SetLongli public BranchlinesCompositionUIModel(BranchlinesCompositionUI ui) { super(SetLongline.class, - BranchlinesComposition.class, - new String[]{SetLongline.PROPERTY_BRANCHLINES_COMPOSITION}, - new String[]{BranchlinesComposition.PROPERTY_TOP_TYPE, - BranchlinesComposition.PROPERTY_TRACELINE_TYPE, - BranchlinesComposition.PROPERTY_LENGTH, - BranchlinesComposition.PROPERTY_PROPORTION}); + BranchlinesComposition.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, BinderService.EDIT, + SetLongline.PROPERTY_BRANCHLINES_COMPOSITION); +// new String[]{SetLongline.PROPERTY_BRANCHLINES_COMPOSITION}, +// new String[]{BranchlinesComposition.PROPERTY_TOP_TYPE, +// BranchlinesComposition.PROPERTY_TRACELINE_TYPE, +// BranchlinesComposition.PROPERTY_LENGTH, +// BranchlinesComposition.PROPERTY_PROPORTION}); List<ContentTableMeta<BranchlinesComposition>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(BranchlinesComposition.class, BranchlinesComposition.PROPERTY_TOP_TYPE, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java index 6e15270..a4d7fe7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIModel.java @@ -32,8 +32,6 @@ import fr.ird.observe.ui.content.table.ContentTableMeta; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIModel; import fr.ird.observe.ui.content.table.ObserveContentTableUI; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.List; import java.util.Set; @@ -113,32 +111,32 @@ public class CatchLonglineUIModel extends ContentTableUIModel<SetLongline, Catch public CatchLonglineUIModel(CatchLonglineUI ui) { super(SetLongline.class, - CatchLongline.class, - new String[]{SetLongline.PROPERTY_CATCH_LONGLINE}, - new String[]{CatchLongline.PROPERTY_SPECIES_CATCH, - CatchLongline.PROPERTY_ACQUISITION_MODE, - CatchLongline.PROPERTY_COUNT, - CatchLongline.PROPERTY_CATCH_HEALTHNESS, - CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, - CatchLongline.PROPERTY_DISCARD_HEALTHNESS, - CatchLongline.PROPERTY_DEPREDATED, - CatchLongline.PROPERTY_NUMBER, - CatchLongline.PROPERTY_HOME_ID, - CatchLongline.PROPERTY_HOOK_POSITION, - CatchLongline.PROPERTY_HOOK_WHEN_DISCARDED, - CatchLongline.PROPERTY_MATURITY_STATUS, - CatchLongline.PROPERTY_PHOTO_REFERENCES, - CatchLongline.PROPERTY_SEX, - CatchLongline.PROPERTY_PREDATOR, - CatchLongline.PROPERTY_STOMAC_FULLNESS, - CatchLongline.PROPERTY_TOTAL_WEIGHT, - CatchLongline.PROPERTY_BEAT_DIAMETER, - CatchLongline.PROPERTY_GONADE_WEIGHT, - CatchLongline.PROPERTY_SECTION, - CatchLongline.PROPERTY_BASKET, - CatchLongline.PROPERTY_BRANCHLINE, - CatchLongline.PROPERTY_COMMENT - }); + CatchLongline.class,BinderService.EDIT_CATCH_LONGLINE, BinderService.EDIT,SetLongline.PROPERTY_CATCH_LONGLINE); +// new String[]{SetLongline.PROPERTY_CATCH_LONGLINE}, +// new String[]{CatchLongline.PROPERTY_SPECIES_CATCH, +// CatchLongline.PROPERTY_ACQUISITION_MODE, +// CatchLongline.PROPERTY_COUNT, +// CatchLongline.PROPERTY_CATCH_HEALTHNESS, +// CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, +// CatchLongline.PROPERTY_DISCARD_HEALTHNESS, +// CatchLongline.PROPERTY_DEPREDATED, +// CatchLongline.PROPERTY_NUMBER, +// CatchLongline.PROPERTY_HOME_ID, +// CatchLongline.PROPERTY_HOOK_POSITION, +// CatchLongline.PROPERTY_HOOK_WHEN_DISCARDED, +// CatchLongline.PROPERTY_MATURITY_STATUS, +// CatchLongline.PROPERTY_PHOTO_REFERENCES, +// CatchLongline.PROPERTY_SEX, +// CatchLongline.PROPERTY_PREDATOR, +// CatchLongline.PROPERTY_STOMAC_FULLNESS, +// CatchLongline.PROPERTY_TOTAL_WEIGHT, +// CatchLongline.PROPERTY_BEAT_DIAMETER, +// CatchLongline.PROPERTY_GONADE_WEIGHT, +// CatchLongline.PROPERTY_SECTION, +// CatchLongline.PROPERTY_BASKET, +// CatchLongline.PROPERTY_BRANCHLINE, +// CatchLongline.PROPERTY_COMMENT +// }); this.sizeMeasuresTableModel = new SizeMeasuresTableModel(); this.weightMeasuresTableModel = new WeightMeasuresTableModel(); @@ -218,15 +216,4 @@ public class CatchLonglineUIModel extends ContentTableUIModel<SetLongline, Catch return new CatchLonglineTableModel(ui, contentTableMetas); } - @Override - protected BinderModelBuilder<CatchLongline, CatchLongline> prepareChildLoador(BinderService binderService, String binderName) { - - BinderModelBuilder<CatchLongline, CatchLongline> builder = super.prepareChildLoador(binderService, binderName); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, CatchLongline.PROPERTY_PREDATOR); - - return builder; - - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIModel.java index 455ca9f..52f3e20 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Encounter; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -43,13 +44,13 @@ public class EncounterUIModel extends ContentTableUIModel<ActivityLongline, Enco public EncounterUIModel(EncounterUI ui) { super(ActivityLongline.class, - Encounter.class, - new String[]{ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_COMMENT}, - new String[]{Encounter.PROPERTY_SPECIES, - Encounter.PROPERTY_DISTANCE, - Encounter.PROPERTY_COUNT, - Encounter.PROPERTY_ENCOUNTER_TYPE}); + Encounter.class, BinderService.EDIT_ENCOUNTER, BinderService.EDIT,ActivityLongline.PROPERTY_ENCOUNTER); +// new String[]{ActivityLongline.PROPERTY_ENCOUNTER, +// ActivityLongline.PROPERTY_COMMENT}, +// new String[]{Encounter.PROPERTY_SPECIES, +// Encounter.PROPERTY_DISTANCE, +// Encounter.PROPERTY_COUNT, +// Encounter.PROPERTY_ENCOUNTER_TYPE}); List<ContentTableMeta<Encounter>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(Encounter.class, Encounter.PROPERTY_ENCOUNTER_TYPE, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIModel.java index 07f7453..d5170b5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.FloatlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -43,11 +44,11 @@ public class FloatlinesCompositionUIModel extends ContentTableUIModel<SetLonglin public FloatlinesCompositionUIModel(FloatlinesCompositionUI ui) { super(SetLongline.class, - FloatlinesComposition.class, - new String[]{SetLongline.PROPERTY_FLOATLINES_COMPOSITION}, - new String[]{FloatlinesComposition.PROPERTY_LINE_TYPE, - FloatlinesComposition.PROPERTY_LENGTH, - FloatlinesComposition.PROPERTY_PROPORTION}); + FloatlinesComposition.class, BinderService.EDIT_FLOATLINES_COMPOSITION, BinderService.EDIT,SetLongline.PROPERTY_FLOATLINES_COMPOSITION); +// new String[]{SetLongline.PROPERTY_FLOATLINES_COMPOSITION}, +// new String[]{FloatlinesComposition.PROPERTY_LINE_TYPE, +// FloatlinesComposition.PROPERTY_LENGTH, +// FloatlinesComposition.PROPERTY_PROPORTION}); List<ContentTableMeta<FloatlinesComposition>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(FloatlinesComposition.class, FloatlinesComposition.PROPERTY_LINE_TYPE, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java index 7d50c06..2eed3dc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIModel.java @@ -34,7 +34,6 @@ import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIModel; import fr.ird.observe.ui.content.table.ObserveContentTableUI; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.List; import java.util.Set; @@ -64,30 +63,31 @@ public class GearUseFeaturesLonglineUIModel extends ContentTableUIModel<TripLong public GearUseFeaturesLonglineUIModel(GearUseFeaturesLonglineUI ui) { super(TripLongline.class, - GearUseFeaturesLongline.class, - new String[]{TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE}, - new String[]{ - GearUseFeaturesLongline.PROPERTY_COMMENT, - GearUseFeaturesLongline.PROPERTY_GEAR, - GearUseFeaturesLongline.PROPERTY_NUMBER, - GearUseFeaturesLongline.PROPERTY_USED_IN_TRIP}); + GearUseFeaturesLongline.class,BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, BinderService.EDIT, + TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE); +// new String[]{TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE}, +// new String[]{ +// GearUseFeaturesLongline.PROPERTY_COMMENT, +// GearUseFeaturesLongline.PROPERTY_GEAR, +// GearUseFeaturesLongline.PROPERTY_NUMBER, +// GearUseFeaturesLongline.PROPERTY_USED_IN_TRIP}); BinderService binderService = ObserveServiceHelper.get().getBinderService(); - String binderName = getClass().getName() + "-open"; +// String binderName = getClass().getName() + "-open"; - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = binderService.getTopiaBinder(GearUseFeaturesMeasurementLongline.class, binderName); + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = binderService.getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - if (binder == null) { - - BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> builder = - binderService.newBinderBuilder(GearUseFeaturesMeasurementLongline.class, - GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, - GearUseFeaturesMeasurementLongline.PROPERTY_MEASUREMENT_VALUE); - - binder = binderService.registerTopiaBinder(GearUseFeaturesMeasurementLongline.class, builder, binderName); - - } +// if (binder == null) { +// +// BinderModelBuilder<GearUseFeaturesMeasurementLongline, GearUseFeaturesMeasurementLongline> builder = +// binderService.newBinderBuilder(GearUseFeaturesMeasurementLongline.class, +// GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, +// GearUseFeaturesMeasurementLongline.PROPERTY_MEASUREMENT_VALUE); +// +// binder = binderService.registerTopiaBinder(GearUseFeaturesMeasurementLongline.class, builder, binderName); +// +// } this.measurementsTableModel = new GearUseFeaturesMeasurementLonglinesTableModel(binder); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIModel.java index 985a187..8d22b39 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.HooksComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -43,12 +44,12 @@ public class HooksCompositionUIModel extends ContentTableUIModel<SetLongline, Ho public HooksCompositionUIModel(HooksCompositionUI ui) { super(SetLongline.class, - HooksComposition.class, - new String[]{SetLongline.PROPERTY_HOOKS_COMPOSITION}, - new String[]{HooksComposition.PROPERTY_HOOK_TYPE, - HooksComposition.PROPERTY_HOOK_SIZE, - HooksComposition.PROPERTY_HOOK_OFFSET, - HooksComposition.PROPERTY_PROPORTION}); + HooksComposition.class, BinderService.EDIT_HOOKS_COMPOSITION, BinderService.EDIT,SetLongline.PROPERTY_HOOKS_COMPOSITION); +// new String[]{SetLongline.PROPERTY_HOOKS_COMPOSITION}, +// new String[]{HooksComposition.PROPERTY_HOOK_TYPE, +// HooksComposition.PROPERTY_HOOK_SIZE, +// HooksComposition.PROPERTY_HOOK_OFFSET, +// HooksComposition.PROPERTY_PROPORTION}); List<ContentTableMeta<HooksComposition>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(HooksComposition.class, HooksComposition.PROPERTY_HOOK_TYPE, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIModel.java index d3a8d99..d9b75b6 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SensorUsed; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -44,15 +45,16 @@ public class SensorUsedUIModel extends ContentTableUIModel<ActivityLongline, Sen public SensorUsedUIModel(SensorUsedUI ui) { super(ActivityLongline.class, - SensorUsed.class, - new String[]{ActivityLongline.PROPERTY_SENSOR_USED, ActivityLongline.PROPERTY_COMMENT}, - new String[]{SensorUsed.PROPERTY_DATA, - SensorUsed.PROPERTY_DATA_FILENAME, - SensorUsed.PROPERTY_DATA_LOCATION, - SensorUsed.PROPERTY_SENSOR_SERIAL_NO, - SensorUsed.PROPERTY_SENSOR_TYPE, - SensorUsed.PROPERTY_SENSOR_BRAND, - SensorUsed.PROPERTY_SENSOR_DATA_FORMAT}); + SensorUsed.class, BinderService.EDIT_SENSOR_USED, BinderService.EDIT, + ActivityLongline.PROPERTY_SENSOR_USED); +// new String[]{ActivityLongline.PROPERTY_SENSOR_USED, ActivityLongline.PROPERTY_COMMENT}, +// new String[]{SensorUsed.PROPERTY_DATA, +// SensorUsed.PROPERTY_DATA_FILENAME, +// SensorUsed.PROPERTY_DATA_LOCATION, +// SensorUsed.PROPERTY_SENSOR_SERIAL_NO, +// SensorUsed.PROPERTY_SENSOR_TYPE, +// SensorUsed.PROPERTY_SENSOR_BRAND, +// SensorUsed.PROPERTY_SENSOR_DATA_FORMAT}); List<ContentTableMeta<SensorUsed>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(SensorUsed.class, SensorUsed.PROPERTY_SENSOR_TYPE, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIModel.java index 478277b..5e4059e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIModel.java @@ -30,8 +30,6 @@ import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.ui.content.table.ContentTableMeta; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIModel; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.List; import java.util.Set; @@ -113,57 +111,58 @@ public class TdrUIModel extends ContentTableUIModel<SetLongline, Tdr> { public TdrUIModel(TdrUI ui) { super(SetLongline.class, - Tdr.class, - new String[]{SetLongline.PROPERTY_TDR, - SetLongline.PROPERTY_SETTING_START_TIME_STAMP, - SetLongline.PROPERTY_SETTING_END_TIME_STAMP, - SetLongline.PROPERTY_HAULING_START_TIME_STAMP, - SetLongline.PROPERTY_HAULING_END_TIME_STAMP}, - new String[]{ - - // caracteristics tab - Tdr.PROPERTY_HOME_ID, - Tdr.PROPERTY_SERIAL_NO, - Tdr.PROPERTY_SENSOR_BRAND, - Tdr.PROPERTY_DATA, - Tdr.PROPERTY_DATA_FILENAME, - Tdr.PROPERTY_DATA_LOCATION, - - // localisation tab - Tdr.PROPERTY_SECTION, - Tdr.PROPERTY_BASKET, - Tdr.PROPERTY_BRANCHLINE, - Tdr.PROPERTY_ITEM_HORIZONTAL_POSITION, - Tdr.PROPERTY_ITEM_VERTICAL_POSITION, - Tdr.PROPERTY_FLOATLINE1_LENGTH, - Tdr.PROPERTY_FLOATLINE2_LENGTH, - - // timestamp tab - Tdr.PROPERTY_DEPLOYEMENT_START, - Tdr.PROPERTY_DEPLOYEMENT_START_DATE, - Tdr.PROPERTY_DEPLOYEMENT_START_TIME, - Tdr.PROPERTY_DEPLOYEMENT_END, - Tdr.PROPERTY_DEPLOYEMENT_END_DATE, - Tdr.PROPERTY_DEPLOYEMENT_END_TIME, - Tdr.PROPERTY_FISHING_START, - Tdr.PROPERTY_FISHING_START_DATE, - Tdr.PROPERTY_FISHING_START_TIME, - Tdr.PROPERTY_FISHING_END, - Tdr.PROPERTY_FISHING_END_DATE, - Tdr.PROPERTY_FISHING_END_TIME, - - // key data tab - Tdr.PROPERTY_FISHING_START_DEPTH, - Tdr.PROPERTY_FISHING_END_DEPTH, - Tdr.PROPERTY_MEAN_DEPLOYEMENT_DEPTH, - Tdr.PROPERTY_MEDIAN_DEPLOYEMENT_DEPTH, - Tdr.PROPERTY_MEAN_FISHING_DEPTH, - Tdr.PROPERTY_MEDIAN_FISHING_DEPTH, - Tdr.PROPERTY_MIN_FISHING_DEPTH, - Tdr.PROPERTY_MAX_FISHING_DEPTH, - - // species tab - Tdr.PROPERTY_SPECIES}); + Tdr.class,BinderService.EDIT_TDR, BinderService.EDIT, + SetLongline.PROPERTY_TDR); +// new String[]{SetLongline.PROPERTY_TDR, +// SetLongline.PROPERTY_SETTING_START_TIME_STAMP, +// SetLongline.PROPERTY_SETTING_END_TIME_STAMP, +// SetLongline.PROPERTY_HAULING_START_TIME_STAMP, +// SetLongline.PROPERTY_HAULING_END_TIME_STAMP}, +// new String[]{ +// +// // caracteristics tab +// Tdr.PROPERTY_HOME_ID, +// Tdr.PROPERTY_SERIAL_NO, +// Tdr.PROPERTY_SENSOR_BRAND, +// Tdr.PROPERTY_DATA, +// Tdr.PROPERTY_DATA_FILENAME, +// Tdr.PROPERTY_DATA_LOCATION, +// +// // localisation tab +// Tdr.PROPERTY_SECTION, +// Tdr.PROPERTY_BASKET, +// Tdr.PROPERTY_BRANCHLINE, +// Tdr.PROPERTY_ITEM_HORIZONTAL_POSITION, +// Tdr.PROPERTY_ITEM_VERTICAL_POSITION, +// Tdr.PROPERTY_FLOATLINE1_LENGTH, +// Tdr.PROPERTY_FLOATLINE2_LENGTH, +// +// // timestamp tab +// Tdr.PROPERTY_DEPLOYEMENT_START, +// Tdr.PROPERTY_DEPLOYEMENT_START_DATE, +// Tdr.PROPERTY_DEPLOYEMENT_START_TIME, +// Tdr.PROPERTY_DEPLOYEMENT_END, +// Tdr.PROPERTY_DEPLOYEMENT_END_DATE, +// Tdr.PROPERTY_DEPLOYEMENT_END_TIME, +// Tdr.PROPERTY_FISHING_START, +// Tdr.PROPERTY_FISHING_START_DATE, +// Tdr.PROPERTY_FISHING_START_TIME, +// Tdr.PROPERTY_FISHING_END, +// Tdr.PROPERTY_FISHING_END_DATE, +// Tdr.PROPERTY_FISHING_END_TIME, +// +// // key data tab +// Tdr.PROPERTY_FISHING_START_DEPTH, +// Tdr.PROPERTY_FISHING_END_DEPTH, +// Tdr.PROPERTY_MEAN_DEPLOYEMENT_DEPTH, +// Tdr.PROPERTY_MEDIAN_DEPLOYEMENT_DEPTH, +// Tdr.PROPERTY_MEAN_FISHING_DEPTH, +// Tdr.PROPERTY_MEDIAN_FISHING_DEPTH, +// Tdr.PROPERTY_MIN_FISHING_DEPTH, +// Tdr.PROPERTY_MAX_FISHING_DEPTH, +// +// // species tab +// Tdr.PROPERTY_SPECIES}); List<ContentTableMeta<Tdr>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(Tdr.class, Tdr.PROPERTY_HOME_ID, false), @@ -175,16 +174,16 @@ public class TdrUIModel extends ContentTableUIModel<SetLongline, Tdr> { } - @Override - protected BinderModelBuilder<Tdr, Tdr> prepareChildLoador(BinderService binderService, String binderName) { - - BinderModelBuilder<Tdr, Tdr> builder = super.prepareChildLoador(binderService, binderName); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Tdr.PROPERTY_SPECIES); - - return builder; - - } +// @Override +// protected BinderModelBuilder<Tdr, Tdr> prepareChildLoador(BinderService binderService, String binderName) { +// +// BinderModelBuilder<Tdr, Tdr> builder = super.prepareChildLoador(binderService, binderName); +// +// builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Tdr.PROPERTY_SPECIES); +// +// return builder; +// +// } public boolean isCaracteristicsTabValid() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIModel.java index 5e9cd3a..adc3068 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIModel.java @@ -34,7 +34,6 @@ import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIModel; import fr.ird.observe.ui.content.table.ObserveContentTableUI; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.List; import java.util.Set; @@ -64,30 +63,30 @@ public class GearUseFeaturesSeineUIModel extends ContentTableUIModel<TripSeine, public GearUseFeaturesSeineUIModel(GearUseFeaturesSeineUI ui) { super(TripSeine.class, - GearUseFeaturesSeine.class, - new String[]{TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE}, - new String[]{ - GearUseFeaturesSeine.PROPERTY_COMMENT, - GearUseFeaturesSeine.PROPERTY_GEAR, - GearUseFeaturesSeine.PROPERTY_NUMBER, - GearUseFeaturesSeine.PROPERTY_USED_IN_TRIP}); + GearUseFeaturesSeine.class,BinderService.EDIT_GEAR_USE_FEATURES_SEINE, BinderService.EDIT,TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); +// new String[]{TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE}, +// new String[]{ +// GearUseFeaturesSeine.PROPERTY_COMMENT, +// GearUseFeaturesSeine.PROPERTY_GEAR, +// GearUseFeaturesSeine.PROPERTY_NUMBER, +// GearUseFeaturesSeine.PROPERTY_USED_IN_TRIP}); BinderService binderService = ObserveServiceHelper.get().getBinderService(); - String binderName = getClass().getName() + "-open"; +// String binderName = getClass().getName() + "-open"; - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = binderService.getTopiaBinder(GearUseFeaturesMeasurementSeine.class, binderName); + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = binderService.getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - if (binder == null) { - - BinderModelBuilder<GearUseFeaturesMeasurementSeine, GearUseFeaturesMeasurementSeine> builder = - binderService.newBinderBuilder(GearUseFeaturesMeasurementSeine.class, - GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, - GearUseFeaturesMeasurementSeine.PROPERTY_MEASUREMENT_VALUE); - - binder = binderService.registerTopiaBinder(GearUseFeaturesMeasurementSeine.class, builder, binderName); - - } +// if (binder == null) { +// +// BinderModelBuilder<GearUseFeaturesMeasurementSeine, GearUseFeaturesMeasurementSeine> builder = +// binderService.newBinderBuilder(GearUseFeaturesMeasurementSeine.class, +// GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, +// GearUseFeaturesMeasurementSeine.PROPERTY_MEASUREMENT_VALUE); +// +// binder = binderService.registerTopiaBinder(GearUseFeaturesMeasurementSeine.class, builder, binderName); +// +// } this.measurementsTableModel = new GearUseFeaturesMeasurementSeinesTableModel(binder); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIModel.java index bab2cf4..dd4190f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -44,21 +45,24 @@ public class NonTargetCatchUIModel extends ContentTableUIModel<SetSeine, NonTarg public NonTargetCatchUIModel(NonTargetCatchUI ui) { super(SetSeine.class, NonTargetCatch.class, - new String[]{SetSeine.PROPERTY_NON_TARGET_CATCH, - SetSeine.PROPERTY_NON_TARGET_DISCARDED}, - new String[]{NonTargetCatch.PROPERTY_SPECIES, - NonTargetCatch.PROPERTY_CATCH_WEIGHT, - NonTargetCatch.PROPERTY_TOTAL_COUNT, - NonTargetCatch.PROPERTY_MEAN_WEIGHT, - NonTargetCatch.PROPERTY_MEAN_LENGTH, - NonTargetCatch.PROPERTY_REASON_FOR_DISCARD, - NonTargetCatch.PROPERTY_SPECIES_FATE, - NonTargetCatch.PROPERTY_TOTAL_COUNT_COMPUTED_SOURCE, - NonTargetCatch.PROPERTY_MEAN_WEIGHT_COMPUTED_SOURCE, - NonTargetCatch.PROPERTY_CATCH_WEIGHT_COMPUTED_SOURCE, - NonTargetCatch.PROPERTY_MEAN_LENGTH_COMPUTED_SOURCE, - NonTargetCatch.PROPERTY_COMMENT - }); + BinderService.EDIT_NON_TARGET_CATCH, + BinderService.EDIT, + SetSeine.PROPERTY_NON_TARGET_CATCH); +// new String[]{SetSeine.PROPERTY_NON_TARGET_CATCH, +// SetSeine.PROPERTY_NON_TARGET_DISCARDED}, +// new String[]{NonTargetCatch.PROPERTY_SPECIES, +// NonTargetCatch.PROPERTY_CATCH_WEIGHT, +// NonTargetCatch.PROPERTY_TOTAL_COUNT, +// NonTargetCatch.PROPERTY_MEAN_WEIGHT, +// NonTargetCatch.PROPERTY_MEAN_LENGTH, +// NonTargetCatch.PROPERTY_REASON_FOR_DISCARD, +// NonTargetCatch.PROPERTY_SPECIES_FATE, +// NonTargetCatch.PROPERTY_TOTAL_COUNT_COMPUTED_SOURCE, +// NonTargetCatch.PROPERTY_MEAN_WEIGHT_COMPUTED_SOURCE, +// NonTargetCatch.PROPERTY_CATCH_WEIGHT_COMPUTED_SOURCE, +// NonTargetCatch.PROPERTY_MEAN_LENGTH_COMPUTED_SOURCE, +// NonTargetCatch.PROPERTY_COMMENT +// }); List<ContentTableMeta<NonTargetCatch>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(NonTargetCatch.class, NonTargetCatch.PROPERTY_SPECIES, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIModel.java index 0a4d3c8..15659f6 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -44,18 +45,18 @@ public class NonTargetSampleUIModel extends ContentTableUIModel<NonTargetSample, public NonTargetSampleUIModel(NonTargetSampleUI ui) { super(NonTargetSample.class, - NonTargetLength.class, - new String[]{NonTargetSample.PROPERTY_NON_TARGET_LENGTH, NonTargetSample.PROPERTY_COMMENT}, - new String[]{NonTargetLength.PROPERTY_SPECIES, - NonTargetLength.PROPERTY_LENGTH, - NonTargetLength.PROPERTY_LENGTH_SOURCE, - NonTargetLength.PROPERTY_WEIGHT, - NonTargetLength.PROPERTY_WEIGHT_SOURCE, - NonTargetLength.PROPERTY_SEX, - NonTargetLength.PROPERTY_COUNT, - NonTargetLength.PROPERTY_ACQUISITION_MODE, - NonTargetLength.PROPERTY_PICTURES_REFERENCES - }); + NonTargetLength.class, BinderService.EDIT_NON_TARGET_LENGTH, BinderService.EDIT,NonTargetSample.PROPERTY_NON_TARGET_LENGTH); +// new String[]{NonTargetSample.PROPERTY_NON_TARGET_LENGTH, NonTargetSample.PROPERTY_COMMENT}, +// new String[]{NonTargetLength.PROPERTY_SPECIES, +// NonTargetLength.PROPERTY_LENGTH, +// NonTargetLength.PROPERTY_LENGTH_SOURCE, +// NonTargetLength.PROPERTY_WEIGHT, +// NonTargetLength.PROPERTY_WEIGHT_SOURCE, +// NonTargetLength.PROPERTY_SEX, +// NonTargetLength.PROPERTY_COUNT, +// NonTargetLength.PROPERTY_ACQUISITION_MODE, +// NonTargetLength.PROPERTY_PICTURES_REFERENCES +// }); List<ContentTableMeta<NonTargetLength>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(NonTargetLength.class, NonTargetLength.PROPERTY_SPECIES, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIModel.java index 4b31de8..3d6a938 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -44,12 +45,13 @@ public class ObjectObservedSpeciesUIModel extends ContentTableUIModel<FloatingOb public ObjectObservedSpeciesUIModel(ObjectObservedSpeciesUI ui) { super(FloatingObject.class, - ObjectObservedSpecies.class, - new String[]{FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES, FloatingObject.PROPERTY_COMMENT}, - new String[]{ - ObjectObservedSpecies.PROPERTY_SPECIES, - ObjectObservedSpecies.PROPERTY_SPECIES_STATUS, - ObjectObservedSpecies.PROPERTY_COUNT}); + ObjectObservedSpecies.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES, BinderService.EDIT, + FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); +// new String[]{FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES, FloatingObject.PROPERTY_COMMENT}, +// new String[]{ +// ObjectObservedSpecies.PROPERTY_SPECIES, +// ObjectObservedSpecies.PROPERTY_SPECIES_STATUS, +// ObjectObservedSpecies.PROPERTY_COUNT}); List<ContentTableMeta<ObjectObservedSpecies>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(ObjectObservedSpecies.class, ObjectObservedSpecies.PROPERTY_SPECIES, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIModel.java index 5006765..187cf72 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -44,10 +45,10 @@ public class ObjectSchoolEstimateUIModel extends ContentTableUIModel<FloatingObj public ObjectSchoolEstimateUIModel(ObjectSchoolEstimateUI ui) { super(FloatingObject.class, - ObjectSchoolEstimate.class, - new String[]{FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE, FloatingObject.PROPERTY_COMMENT}, - new String[]{ObjectSchoolEstimate.PROPERTY_SPECIES, ObjectSchoolEstimate.PROPERTY_TOTAL_WEIGHT} - ); + ObjectSchoolEstimate.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE, BinderService.EDIT,FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); +// new String[]{FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE, FloatingObject.PROPERTY_COMMENT}, +// new String[]{ObjectSchoolEstimate.PROPERTY_SPECIES, ObjectSchoolEstimate.PROPERTY_TOTAL_WEIGHT} +// ); List<ContentTableMeta<ObjectSchoolEstimate>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(ObjectSchoolEstimate.class, ObjectSchoolEstimate.PROPERTY_SPECIES, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIModel.java index b71f77a..815193d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -44,12 +45,12 @@ public class SchoolEstimateUIModel extends ContentTableUIModel<SetSeine, SchoolE public SchoolEstimateUIModel(SchoolEstimateUI ui) { super(SetSeine.class, - SchoolEstimate.class, - new String[]{SetSeine.PROPERTY_SCHOOL_ESTIMATE, SetSeine.PROPERTY_COMMENT}, - new String[]{SchoolEstimate.PROPERTY_SET_SEINE, - SchoolEstimate.PROPERTY_SPECIES, - SchoolEstimate.PROPERTY_TOTAL_WEIGHT, - SchoolEstimate.PROPERTY_MEAN_WEIGHT}); + SchoolEstimate.class, BinderService.EDIT_SCHOOL_ESTIMATE, BinderService.EDIT,SetSeine.PROPERTY_SCHOOL_ESTIMATE); +// new String[]{SetSeine.PROPERTY_SCHOOL_ESTIMATE, SetSeine.PROPERTY_COMMENT}, +// new String[]{SchoolEstimate.PROPERTY_SET_SEINE, +// SchoolEstimate.PROPERTY_SPECIES, +// SchoolEstimate.PROPERTY_TOTAL_WEIGHT, +// SchoolEstimate.PROPERTY_MEAN_WEIGHT}); List<ContentTableMeta<SchoolEstimate>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(SchoolEstimate.class, SchoolEstimate.PROPERTY_SPECIES, false), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIModel.java index 83892f0..ea9e35d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; @@ -45,15 +46,15 @@ public class TargetCatchUIModel extends ContentTableUIModel<SetSeine, TargetCatc public TargetCatchUIModel(TargetCatchUI ui) { super(SetSeine.class, - TargetCatch.class, - new String[]{SetSeine.PROPERTY_TARGET_CATCH}, - new String[]{TargetCatch.PROPERTY_SET_SEINE, - TargetCatch.PROPERTY_WEIGHT_CATEGORY, - TargetCatch.PROPERTY_CATCH_WEIGHT, - TargetCatch.PROPERTY_WELL, - TargetCatch.PROPERTY_BROUGHT_ON_DECK, - TargetCatch.PROPERTY_DISCARDED, - TargetCatch.PROPERTY_COMMENT}); + TargetCatch.class, BinderService.EDIT_TARGET_CATCH, BinderService.EDIT_TARGET_CATCH,SetSeine.PROPERTY_TARGET_CATCH); +// new String[]{SetSeine.PROPERTY_TARGET_CATCH}, +// new String[]{TargetCatch.PROPERTY_SET_SEINE, +// TargetCatch.PROPERTY_WEIGHT_CATEGORY, +// TargetCatch.PROPERTY_CATCH_WEIGHT, +// TargetCatch.PROPERTY_WELL, +// TargetCatch.PROPERTY_BROUGHT_ON_DECK, +// TargetCatch.PROPERTY_DISCARDED, +// TargetCatch.PROPERTY_COMMENT}); List<ContentTableMeta<TargetCatch>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(TargetCatch.class, WeightCategory.PROPERTY_SPECIES, true), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIModel.java index 807aec5..fdd83ad 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; @@ -45,15 +46,15 @@ public class TargetDiscardCatchUIModel extends ContentTableUIModel<SetSeine, Tar public TargetDiscardCatchUIModel(TargetDiscardCatchUI ui) { super(SetSeine.class, - TargetCatch.class, - new String[]{SetSeine.PROPERTY_TARGET_CATCH, SetSeine.PROPERTY_TARGET_DISCARDED}, - new String[]{TargetCatch.PROPERTY_SET_SEINE, - TargetCatch.PROPERTY_WEIGHT_CATEGORY, - TargetCatch.PROPERTY_CATCH_WEIGHT, - TargetCatch.PROPERTY_REASON_FOR_DISCARD, - TargetCatch.PROPERTY_DISCARDED, - TargetCatch.PROPERTY_BROUGHT_ON_DECK, - TargetCatch.PROPERTY_COMMENT}); + TargetCatch.class, BinderService.EDIT_DISCARD_TARGET_CATCH, BinderService.EDIT_DISCARD_TARGET_CATCH,SetSeine.PROPERTY_TARGET_CATCH); +// new String[]{SetSeine.PROPERTY_TARGET_CATCH, SetSeine.PROPERTY_TARGET_DISCARDED}, +// new String[]{TargetCatch.PROPERTY_SET_SEINE, +// TargetCatch.PROPERTY_WEIGHT_CATEGORY, +// TargetCatch.PROPERTY_CATCH_WEIGHT, +// TargetCatch.PROPERTY_REASON_FOR_DISCARD, +// TargetCatch.PROPERTY_DISCARDED, +// TargetCatch.PROPERTY_BROUGHT_ON_DECK, +// TargetCatch.PROPERTY_COMMENT}); List<ContentTableMeta<TargetCatch>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(TargetCatch.class, WeightCategory.PROPERTY_SPECIES, true), diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIModel.java index 53ab578..8279b5d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIModel.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import com.google.common.collect.Lists; +import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.ui.content.table.ContentTableMeta; @@ -44,17 +45,18 @@ public class TargetSampleUIModel extends ContentTableUIModel<TargetSample, Targe public TargetSampleUIModel(TargetSampleUI ui) { super(TargetSample.class, - TargetLength.class, - new String[]{TargetSample.PROPERTY_TARGET_LENGTH, TargetSample.PROPERTY_COMMENT}, - new String[]{TargetLength.PROPERTY_TARGET_SAMPLE, - TargetLength.PROPERTY_SPECIES, - TargetLength.PROPERTY_LENGTH, - TargetLength.PROPERTY_LENGTH_SOURCE, - TargetLength.PROPERTY_WEIGHT, - TargetLength.PROPERTY_WEIGHT_SOURCE, - TargetLength.PROPERTY_COUNT, - TargetLength.PROPERTY_MEASURE_TYPE, - TargetLength.PROPERTY_ACQUISITION_MODE}); + TargetLength.class, BinderService.EDIT_TARGET_LENGTH, BinderService.EDIT, + TargetSample.PROPERTY_TARGET_LENGTH); +// new String[]{TargetSample.PROPERTY_TARGET_LENGTH, TargetSample.PROPERTY_COMMENT}, +// new String[]{TargetLength.PROPERTY_TARGET_SAMPLE, +// TargetLength.PROPERTY_SPECIES, +// TargetLength.PROPERTY_LENGTH, +// TargetLength.PROPERTY_LENGTH_SOURCE, +// TargetLength.PROPERTY_WEIGHT, +// TargetLength.PROPERTY_WEIGHT_SOURCE, +// TargetLength.PROPERTY_COUNT, +// TargetLength.PROPERTY_MEASURE_TYPE, +// TargetLength.PROPERTY_ACQUISITION_MODE}); List<ContentTableMeta<TargetLength>> metas = Lists.newArrayList( ContentTableModel.newTableMeta(TargetLength.class, TargetLength.PROPERTY_SPECIES, true), -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit c5ffd2deed422fbbe4726d550f06c7ce7c400a76 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 09:45:46 2015 +0200 faunes accesoires et équipements --- .../data/seine/GearUseFeaturesSeineService.java | 12 ++- .../seine/GearUseFeaturesSeineServiceImpl.java | 46 +++++++---- .../services/data/seine/NonTargetCatchService.java | 23 ++++++ .../data/seine/NonTargetCatchServiceImpl.java | 77 +++++++++++++++++++ .../impl/seine/GearUseFeaturesSeineUIHandler.java | 26 ++++++- .../table/impl/seine/NonTargetCatchUIHandler.java | 88 ++++++++++++++++++---- 6 files changed, 239 insertions(+), 33 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java index 23a4565..3e42f29 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java @@ -1,9 +1,12 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; +import fr.ird.observe.entities.seine.GearUseFeaturesSeine; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; +import org.nuiton.topia.persistence.util.EntityListUpdator; import java.util.List; @@ -19,7 +22,12 @@ public interface GearUseFeaturesSeineService extends ObserveService { List<GearUseFeaturesMeasurementSeine> loadGearUseFeaturesMeasurementSeineForEdit(String gearUseFeaturesSeineId); + TripSeine loadForEdit(String tripId); + + @Commit + void save(TripSeine parent); + @NoTransaction - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeineBinderForEdit(); + EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index ecb28cd..f28616f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -6,9 +6,10 @@ import fr.ird.observe.entities.referentiel.GearCaracteristic; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineDAO; import fr.ird.observe.entities.seine.GearUseFeaturesSeine; +import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.Collection; @@ -44,7 +45,7 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl public List<GearUseFeaturesMeasurementSeine> loadGearUseFeaturesMeasurementSeineForEdit(String gearUseFeaturesSeineId) { GearUseFeaturesMeasurementSeineDAO dao = getDao(); - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getGearUseFeaturesMeasurementSeineBinderForEdit(); + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); GearUseFeaturesSeine gearUseFeaturesSeine = findByTopiaId(GearUseFeaturesSeine.class, gearUseFeaturesSeineId); List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); @@ -61,26 +62,45 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl } @Override - public TopiaEntityBinder<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeineBinderForEdit() { + public TripSeine loadForEdit(String tripId) { + TripSeine toLoad = findByTopiaId(TripSeine.class, tripId); - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> r = loadBinder("-forEdit", GearUseFeaturesMeasurementSeine.class, new CreateBinder<GearUseFeaturesMeasurementSeine>() { + TripSeine loaded = getDao(TripSeine.class).newInstance(); - @Override - public BinderModelBuilder<GearUseFeaturesMeasurementSeine, GearUseFeaturesMeasurementSeine> createBinderBuilder(BinderService binderService, String name) { + if (toLoad != null) { - BinderModelBuilder<GearUseFeaturesMeasurementSeine, GearUseFeaturesMeasurementSeine> builder = - binderService.newBinderBuilder(GearUseFeaturesMeasurementSeine.class, - GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, - GearUseFeaturesMeasurementSeine.PROPERTY_MEASUREMENT_VALUE); + copyExcluding(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE, toLoad, loaded, TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); - return builder; + for (GearUseFeaturesSeine childToLoad : toLoad.getGearUseFeaturesSeine()) { + + GearUseFeaturesSeine childLoaded = getDao(GearUseFeaturesSeine.class).newInstance(); + + copy(GearUseFeaturesSeine.class, BinderService.EDIT, childToLoad, childLoaded); + + loaded.addGearUseFeaturesSeine(childLoaded); } - }); + } + + return loaded; + } - return r; + @Override + public void save(TripSeine parent) { + TopiaEntityBinder<TripSeine> parentBinder = getBinder(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE); + TopiaEntityBinder<GearUseFeaturesSeine> childbinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); + doSaveList(parent, new SaveCollectionAction<TripSeine, GearUseFeaturesSeine>( + TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childbinder)); + } + + @Override + public EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + TripSeine.class, + GearUseFeaturesSeine.class, + TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); } protected GearUseFeaturesMeasurementSeineDAO getDao() { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java new file mode 100644 index 0000000..538d153 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java @@ -0,0 +1,23 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.NonTargetCatch; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.NoTransaction; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public interface NonTargetCatchService extends ObserveService { + + SetSeine loadForEdit(String setId); + + @Commit + void save(SetSeine parent); + + @NoTransaction + EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator(); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java new file mode 100644 index 0000000..3166ffa --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java @@ -0,0 +1,77 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.seine.NonTargetCatch; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.util.EntityListUpdator; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.Collection; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class NonTargetCatchServiceImpl extends AbstractObserveService implements NonTargetCatchService { + + @Override + public SetSeine loadForEdit(String setId) { + + SetSeine toLoad = findByTopiaId(SetSeine.class, setId); + + SetSeine loaded = getDao(SetSeine.class).newInstance(); + + if (toLoad != null) { + + copyExcluding(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH, toLoad, loaded, SetSeine.PROPERTY_NON_TARGET_CATCH); + + for (NonTargetCatch childToLoad : toLoad.getNonTargetCatch()) { + + NonTargetCatch childLoaded = getDao(NonTargetCatch.class).newInstance(); + + copy(NonTargetCatch.class, BinderService.EDIT, childToLoad, childLoaded); + + loaded.addNonTargetCatch(childLoaded); + + } + + } + + return loaded; + } + + @Override + public void save(SetSeine parent) { + TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH); + TopiaEntityBinder<NonTargetCatch> childbinder = getBinder(NonTargetCatch.class, BinderService.EDIT); + + doSaveList(parent, new SaveCollectionAction<SetSeine, NonTargetCatch>( + SetSeine.class, NonTargetCatch.class, getListUpdator(), parentBinder, childbinder) { + + @Override + public void prepareSave(SetSeine parent, Collection<NonTargetCatch> toSaves) { + + // mise a jour de la propriete nonTargetDiscarded + + boolean hasRejet = false; + for (NonTargetCatch c : toSaves) { + if (c.getReasonForDiscard() != null) { + // on a trouve un rejet de faune + hasRejet = true; + break; + } + } + parent.setNonTargetDiscarded(hasRejet); + } + }); + + } + + @Override + public EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + SetSeine.class, + NonTargetCatch.class, + SetSeine.PROPERTY_NON_TARGET_CATCH); + } +} diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index 08161ec..f750158 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -22,6 +22,7 @@ package fr.ird.observe.ui.content.table.impl.seine; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveDAOHelper; @@ -299,15 +300,17 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected TripSeine loadEditBean(ContentMode mode, DataContext dataContext, DataService dataService, DataSource dataSource) throws DataSourceException { + protected void loadEditBean() throws DataSourceException { - TripSeine tripSeine = super.loadEditBean(mode, dataContext, dataService, dataSource); + String tripSeineId = getDataContext().getSelectedTripSeineId(); + + TripSeine tripSeine = getService(GearUseFeaturesSeineService.class).loadForEdit(tripSeineId); + + copy(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE, tripSeine, getBean()); // reset measurements getModel().getMeasurementsTableModel().clear(); - return tripSeine; - } @Override @@ -386,6 +389,19 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } + + @Override + protected void doPersist(TripSeine editBean) { + getService(GearUseFeaturesSeineService.class).save(editBean); + } + + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + @Override protected void onUpdateFinalize(TopiaContext tx, TripSeine bean, Collection<GearUseFeaturesSeine> oldChilds) throws TopiaException { @@ -411,6 +427,8 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei for (GearUseFeaturesMeasurementSeine measure : measurements) { + + if (measurementsTableModel.isRowNotEmpty(measure)) { GearUseFeaturesMeasurementSeine measureToSave; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 417e8fc..968330f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.DataContext; @@ -39,6 +40,7 @@ import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.NonTargetCatchService; import fr.ird.observe.services.data.seine.NonTargetSampleService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; @@ -260,6 +262,53 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override + protected void loadEditBean() { + + String setId = getDataContext().getSelectedSetId(); + + SetSeine setSeine = getService(NonTargetCatchService.class).loadForEdit(setId); + + copy(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH, setSeine, getBean()); + + } + + @Override + protected void loadTableEditBeanForm(ContentMode mode) { + + List<Species> speciesList; + + String tripId = getDataContext().getSelectedTripId(); + + if (mode == ContentMode.UPDATE) { + + // get current ocean + Ocean ocean = getService(TripService.class).getTripOcean(tripId); + + ObserveConfig config = getUi().getContextValue(ObserveConfig.class); + String speciesListId = config.getSpeciesListSeineNonTargetCatchId(); + + // get all species + List<Species> allSpecies = getService(ReferentialService.class).loadDecoratedSpecies(speciesListId); + + // filtre par status actif + ReferenceEntities.filterReferentielListByStatus(allSpecies); + + // filtre par ocean + speciesList = Species2.filterByOcean(allSpecies, ocean); + + } else { + + speciesList = new ArrayList<Species>(); + } + + ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); + if (log.isDebugEnabled()) { + log.debug("speciesList = " + speciesList.size()); + } + + } + + @Override protected void onSelectedRowChanged(int editingRow, NonTargetCatch bean, boolean create) { @@ -358,6 +407,17 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override + protected boolean doSave(SetSeine bean) { + try { + return super.doSave(bean); + } finally { + + // toujours supprimer la référence du context, quoiqu'il arrive + ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); + } + } + + @Override protected boolean prepareSave(SetSeine editBean, List<NonTargetCatch> objets) throws Exception { super.prepareSave(editBean, objets); @@ -368,9 +428,9 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non NonTargetSampleService service = getService(NonTargetSampleService.class); service.getObsoleteEspeceForNonTargetSample(editBean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete); + speciessUsed, + speciessToDelete, + tailleToDelete); if (!tailleToDelete.isEmpty()) { @@ -416,19 +476,19 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); } - // mise a jour de la propriete nonTargetDiscarded + return true; + } + + @Override + protected void doPersist(SetSeine editBean) { + getService(NonTargetCatchService.class).save(editBean); + } - boolean hasRejet = false; - for (NonTargetCatch c : objets) { - if (c.getReasonForDiscard() != null) { - // on a trouve un rejet de faune - hasRejet = true; - break; - } - } - editBean.setNonTargetDiscarded(hasRejet); - return true; + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); } @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 74147e48119cf5d3648db7a5a06f4e1082825051 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 11:25:00 2015 +0200 savegarde des caractéristiques des équipements --- .../seine/GearUseFeaturesSeineServiceImpl.java | 76 +++++++++++++++++++++- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 21 ++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index f28616f..db5f437 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -1,5 +1,6 @@ package fr.ird.observe.services.data.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; @@ -8,6 +9,7 @@ import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineDAO; import fr.ird.observe.entities.seine.GearUseFeaturesSeine; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -77,6 +79,16 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl copy(GearUseFeaturesSeine.class, BinderService.EDIT, childToLoad, childLoaded); + for (GearUseFeaturesMeasurementSeine measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { + + GearUseFeaturesMeasurementSeine measurementLoaded = getDao(GearUseFeaturesMeasurementSeine.class).newInstance(); + + copy(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT, measurementToLoad, measurementLoaded); + + childLoaded.addGearUseFeaturesMeasurement(measurementLoaded); + + } + loaded.addGearUseFeaturesSeine(childLoaded); } @@ -92,7 +104,69 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl TopiaEntityBinder<GearUseFeaturesSeine> childbinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); doSaveList(parent, new SaveCollectionAction<TripSeine, GearUseFeaturesSeine>( - TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childbinder)); + TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childbinder) { + + @Override + public GearUseFeaturesSeine onCreateChild(GearUseFeaturesSeine childToCreate) { + GearUseFeaturesSeine childCreated = super.onCreateChild(childToCreate); + saveMeasurement(childToCreate, childCreated); + return childCreated; + + } + + @Override + public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToSave, GearUseFeaturesSeine childSaved) { + super.onUpdateChild(childToSave, childSaved); + saveMeasurement(childToSave, childSaved); + return childSaved; + } + + protected void saveMeasurement(GearUseFeaturesSeine childToSave, GearUseFeaturesSeine childSaved) { + + TopiaDAO<GearUseFeaturesMeasurementSeine> dao = getDao(GearUseFeaturesMeasurementSeine.class); + + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> measurementBinder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); + + List<GearUseFeaturesMeasurementSeine> measurementsToDelete = Lists.newArrayList(childSaved.getGearUseFeaturesMeasurement()); + + List<GearUseFeaturesMeasurementSeine> measurementsNew = Lists.newArrayList(); + + for (GearUseFeaturesMeasurementSeine measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + + GearUseFeaturesMeasurementSeine measurementSaved; + + if (measurementToSave.getTopiaId() == null) { + + measurementSaved = dao.create(); + + measurementBinder.load(measurementToSave, measurementSaved, false); + + } else { + + measurementSaved = findByTopiaId(GearUseFeaturesMeasurementSeine.class, measurementToSave.getTopiaId()); + + measurementBinder.load(measurementToSave, measurementSaved, true); + + measurementsToDelete.remove(measurementSaved); + + } + + measurementsNew.add(measurementSaved); + + } + + childSaved.clearGearUseFeaturesMeasurement(); + + childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); + + for (GearUseFeaturesMeasurementSeine toDelete : measurementsToDelete) { + + dao.delete(toDelete); + + } + + } + }); } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index f750158..d3fcf24 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -392,6 +392,27 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei @Override protected void doPersist(TripSeine editBean) { + + List<GearUseFeaturesSeine> gearUseFeatures = editBean.getGearUseFeaturesSeine(); + + GearUseFeaturesSeineUIModel model = getModel(); + + GearUseFeaturesMeasurementSeinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); + + Set<Integer> rowsChanged = measurementsTableModel.getCacheRowsChanged(); + + for (Integer row : rowsChanged) { + + GearUseFeaturesSeine gearUseFeaturesSeine = gearUseFeatures.get(row); + + List<GearUseFeaturesMeasurementSeine> measurements = measurementsTableModel.getCacheForRow(row); + + gearUseFeaturesSeine.clearGearUseFeaturesMeasurement(); + + gearUseFeaturesSeine.addAllGearUseFeaturesMeasurement(measurements); + + } + getService(GearUseFeaturesSeineService.class).save(editBean); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit cc28455d329cec7d3074777404b6c7e57f2522c3 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 15:37:37 2015 +0200 savegarde des caractéristiques des équipements pour la palangre. fix npe --- .../GearUseFeaturesLonglineServiceImpl.java | 72 ++++++++++++++++++- .../seine/GearUseFeaturesSeineServiceImpl.java | 8 ++- .../longline/GearUseFeaturesLonglineUIHandler.java | 80 ++++++---------------- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 61 ----------------- 4 files changed, 99 insertions(+), 122 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index 979c585..efbe94b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -1,5 +1,6 @@ package fr.ird.observe.services.data.longline; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; @@ -102,7 +103,76 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i TopiaEntityBinder<GearUseFeaturesLongline> childBinder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); doSaveList(tripLongline, new SaveCollectionAction<TripLongline, GearUseFeaturesLongline>( - TripLongline.class, GearUseFeaturesLongline.class, getListUpdator(), parentBinder, childBinder)); + TripLongline.class, GearUseFeaturesLongline.class, getListUpdator(), parentBinder, childBinder) { + + @Override + public GearUseFeaturesLongline onCreateChild(GearUseFeaturesLongline childToCreate) { + GearUseFeaturesLongline childCreated = super.onCreateChild(childToCreate); + saveMeasurement(childToCreate, childCreated); + return childCreated; + + } + + @Override + public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToSave, GearUseFeaturesLongline childSaved) { + super.onUpdateChild(childToSave, childSaved); + saveMeasurement(childToSave, childSaved); + return childSaved; + } + + protected void saveMeasurement(GearUseFeaturesLongline childToSave, GearUseFeaturesLongline childSaved) { + + TopiaDAO<GearUseFeaturesMeasurementLongline> dao = getDao(GearUseFeaturesMeasurementLongline.class); + + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> measurementBinder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); + + List<GearUseFeaturesMeasurementLongline> measurementsToDelete = Lists.newArrayList(); + + if (childSaved.getGearUseFeaturesMeasurement() != null) { + + measurementsToDelete.addAll(childSaved.getGearUseFeaturesMeasurement()); + + } + + List<GearUseFeaturesMeasurementLongline> measurementsNew = Lists.newArrayList(); + + for (GearUseFeaturesMeasurementLongline measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + + GearUseFeaturesMeasurementLongline measurementSaved; + + if (measurementToSave.getTopiaId() == null) { + + measurementSaved = dao.create(); + + measurementBinder.load(measurementToSave, measurementSaved, false); + + } else { + + measurementSaved = findByTopiaId(GearUseFeaturesMeasurementLongline.class, measurementToSave.getTopiaId()); + + measurementBinder.load(measurementToSave, measurementSaved, true); + + measurementsToDelete.remove(measurementSaved); + + } + + measurementsNew.add(measurementSaved); + + } + + childSaved.clearGearUseFeaturesMeasurement(); + + childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); + + for (GearUseFeaturesMeasurementLongline toDelete : measurementsToDelete) { + + dao.delete(toDelete); + + } + } + + + }); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index db5f437..a76e778 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -127,7 +127,13 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl TopiaEntityBinder<GearUseFeaturesMeasurementSeine> measurementBinder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - List<GearUseFeaturesMeasurementSeine> measurementsToDelete = Lists.newArrayList(childSaved.getGearUseFeaturesMeasurement()); + List<GearUseFeaturesMeasurementSeine> measurementsToDelete = Lists.newArrayList(); + + if (childSaved.getGearUseFeaturesMeasurement() != null) { + + measurementsToDelete.addAll(childSaved.getGearUseFeaturesMeasurement()); + + } List<GearUseFeaturesMeasurementSeine> measurementsNew = Lists.newArrayList(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 12129ff..c36fd99 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -24,13 +24,11 @@ package fr.ird.observe.ui.content.table.impl.longline; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; -import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLonglineDAO; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; @@ -50,9 +48,6 @@ import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -69,8 +64,6 @@ import java.awt.Insets; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -142,6 +135,27 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip @Override protected void doPersist(TripLongline editBean) { + List<GearUseFeaturesLongline> gearUseFeatures = editBean.getGearUseFeaturesLongline(); + + GearUseFeaturesLonglineUIModel model = getModel(); + + GearUseFeaturesMeasurementLonglinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); + + Set<Integer> rowsChanged = measurementsTableModel.getCacheRowsChanged(); + + for (Integer row : rowsChanged) { + + GearUseFeaturesLongline gearUseFeaturesLongline = gearUseFeatures.get(row); + + List<GearUseFeaturesMeasurementLongline> measurements = measurementsTableModel.getCacheForRow(row); + + gearUseFeaturesLongline.clearGearUseFeaturesMeasurement(); + + gearUseFeaturesLongline.addAllGearUseFeaturesMeasurement(measurements); + + } + + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); service.save(editBean); @@ -396,58 +410,6 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected void onUpdateFinalize(TopiaContext tx, TripLongline bean, Collection<GearUseFeaturesLongline> oldChilds) throws TopiaException { - - List<GearUseFeaturesLongline> gearUseFeatures = bean.getGearUseFeaturesLongline(); - - GearUseFeaturesLonglineUIModel model = getModel(); - { - - // save measurments - - GearUseFeaturesMeasurementLonglineDAO measureDao = ObserveDAOHelper.getGearUseFeaturesMeasurementLonglineDAO(tx); - - GearUseFeaturesMeasurementLonglinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); - Set<Integer> rowsChanged = measurementsTableModel.getCacheRowsChanged(); - - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> loader = measurementsTableModel.getLoader(); - for (Integer row : rowsChanged) { - - GearUseFeaturesLongline gearUseFeaturesLongline = gearUseFeatures.get(row); - - List<GearUseFeaturesMeasurementLongline> measurements = measurementsTableModel.getCacheForRow(row); - List<GearUseFeaturesMeasurementLongline> measurementsToSave = new ArrayList<GearUseFeaturesMeasurementLongline>(measurements.size()); - - for (GearUseFeaturesMeasurementLongline measure : measurements) { - - if (measurementsTableModel.isRowNotEmpty(measure)) { - - GearUseFeaturesMeasurementLongline measureToSave; - - if (measure.getTopiaId() == null) { - measureToSave = measureDao.create(measure); - loader.load(measureToSave, measure, true); - } else { - measureToSave = gearUseFeaturesLongline.getGearUseFeaturesMeasurementByTopiaId(measure.getTopiaId()); - loader.load(measure, measureToSave, true); - } - - measurementsToSave.add(measureToSave); - - } - - } - - gearUseFeaturesLongline.clearGearUseFeaturesMeasurement(); - gearUseFeaturesLongline.addAllGearUseFeaturesMeasurement(measurementsToSave); - - } - - } - - } - - @Override protected void resetEditBean() { UIHelper.stopEditing(getUi().getMeasurementsTable()); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index d3fcf24..64c854b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; @@ -33,7 +32,6 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; -import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineDAO; import fr.ird.observe.entities.seine.GearUseFeaturesSeine; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.data.seine.GearUseFeaturesSeineService; @@ -50,9 +48,6 @@ import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -69,8 +64,6 @@ import java.awt.Insets; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -424,60 +417,6 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected void onUpdateFinalize(TopiaContext tx, TripSeine bean, Collection<GearUseFeaturesSeine> oldChilds) throws TopiaException { - - List<GearUseFeaturesSeine> gearUseFeatures = bean.getGearUseFeaturesSeine(); - - GearUseFeaturesSeineUIModel model = getModel(); - { - - // save measurments - - GearUseFeaturesMeasurementSeineDAO measureDao = ObserveDAOHelper.getGearUseFeaturesMeasurementSeineDAO(tx); - - GearUseFeaturesMeasurementSeinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); - Set<Integer> rowsChanged = measurementsTableModel.getCacheRowsChanged(); - - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> loader = measurementsTableModel.getLoader(); - for (Integer row : rowsChanged) { - - GearUseFeaturesSeine gearUseFeaturesSeine = gearUseFeatures.get(row); - - List<GearUseFeaturesMeasurementSeine> measurements = measurementsTableModel.getCacheForRow(row); - List<GearUseFeaturesMeasurementSeine> measurementsToSave = new ArrayList<GearUseFeaturesMeasurementSeine>(measurements.size()); - - for (GearUseFeaturesMeasurementSeine measure : measurements) { - - - - if (measurementsTableModel.isRowNotEmpty(measure)) { - - GearUseFeaturesMeasurementSeine measureToSave; - - if (measure.getTopiaId() == null) { - measureToSave = measureDao.create(measure); - loader.load(measureToSave, measure, true); - } else { - measureToSave = gearUseFeaturesSeine.getGearUseFeaturesMeasurementByTopiaId(measure.getTopiaId()); - loader.load(measure, measureToSave, true); - } - - measurementsToSave.add(measureToSave); - - } - - } - - gearUseFeaturesSeine.clearGearUseFeaturesMeasurement(); - gearUseFeaturesSeine.addAllGearUseFeaturesMeasurement(measurementsToSave); - - } - - } - - } - - @Override protected void resetEditBean() { UIHelper.stopEditing(getUi().getMeasurementsTable()); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit d35ba0b59e83d735cf23d1259f3c5355c409ed52 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 30 16:37:00 2015 +0200 mise en place des binders pour les référentiels et adaptation des ui (refs #7017) --- .../main/java/fr/ird/observe/BinderService.java | 310 +++++++++++++++++++-- .../observe/services/AbstractObserveService.java | 4 + .../services/data/seine/ActivitySeineService.java | 2 - .../data/seine/ActivitySeineServiceImpl.java | 8 - .../services/referential/ReferentialService.java | 10 +- .../referential/ReferentialServiceImpl.java | 104 ++++++- .../list/impl/longline/TripLonglinesUIHandler.java | 5 +- .../list/impl/seine/TripSeinesUIHandler.java | 4 +- .../ui/content/ref/ContentReferenceUIHandler.java | 268 ++++++------------ .../ui/content/ref/ContentReferenceUIModel.java | 153 +--------- .../ref/ReferentialContentUIInitializer.java | 43 ++- .../ui/content/ref/impl/CountryUIModel.java | 4 +- .../ui/content/ref/impl/FpaZoneUIModel.java | 3 +- .../content/ref/impl/GearCaracteristicUIModel.java | 8 +- .../observe/ui/content/ref/impl/GearUIModel.java | 4 +- .../ui/content/ref/impl/HarbourUIModel.java | 18 +- .../ref/impl/LengthWeightParameterUIModel.java | 22 +- .../ui/content/ref/impl/OrganismUIModel.java | 4 +- .../observe/ui/content/ref/impl/PersonUIModel.java | 25 +- .../ui/content/ref/impl/ProgramUIModel.java | 38 +-- .../ui/content/ref/impl/SpeciesListUIModel.java | 4 +- .../ui/content/ref/impl/SpeciesUIModel.java | 35 +-- .../ref/impl/VesselSizeCategoryUIModel.java | 9 +- .../observe/ui/content/ref/impl/VesselUIModel.java | 34 +-- .../impl/longline/BaitSettingStatusUIModel.java | 4 +- .../ref/impl/longline/MaturityStatusUIModel.java | 4 +- .../ref/impl/longline/SensorBrandUIModel.java | 3 +- .../ref/impl/seine/ObservedSystemUIModel.java | 3 +- .../ref/impl/seine/WeightCategoryUIModel.java | 14 +- .../ui/content/ref/impl/seine/WindUIModel.java | 1 - 30 files changed, 612 insertions(+), 536 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 1596a68..701b12f 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -39,7 +39,67 @@ import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.Tdr; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.WeightMeasure; +import fr.ird.observe.entities.referentiel.Country; +import fr.ird.observe.entities.referentiel.FpaZone; +import fr.ird.observe.entities.referentiel.Gear; +import fr.ird.observe.entities.referentiel.GearCaracteristic; +import fr.ird.observe.entities.referentiel.GearCaracteristicType; +import fr.ird.observe.entities.referentiel.Harbour; +import fr.ird.observe.entities.referentiel.I18nReferenceEntity; +import fr.ird.observe.entities.referentiel.LengthWeightParameter; +import fr.ird.observe.entities.referentiel.Ocean; +import fr.ird.observe.entities.referentiel.Organism; +import fr.ird.observe.entities.referentiel.Person; import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.entities.referentiel.Sex; +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.referentiel.SpeciesGroup; +import fr.ird.observe.entities.referentiel.SpeciesList; +import fr.ird.observe.entities.referentiel.Vessel; +import fr.ird.observe.entities.referentiel.VesselSizeCategory; +import fr.ird.observe.entities.referentiel.VesselType; +import fr.ird.observe.entities.referentiel.longline.BaitHaulingStatus; +import fr.ird.observe.entities.referentiel.longline.BaitSettingStatus; +import fr.ird.observe.entities.referentiel.longline.BaitType; +import fr.ird.observe.entities.referentiel.longline.CatchFateLongline; +import fr.ird.observe.entities.referentiel.longline.EncounterType; +import fr.ird.observe.entities.referentiel.longline.Healthness; +import fr.ird.observe.entities.referentiel.longline.HookPosition; +import fr.ird.observe.entities.referentiel.longline.HookSize; +import fr.ird.observe.entities.referentiel.longline.HookType; +import fr.ird.observe.entities.referentiel.longline.ItemHorizontalPosition; +import fr.ird.observe.entities.referentiel.longline.ItemVerticalPosition; +import fr.ird.observe.entities.referentiel.longline.LightsticksColor; +import fr.ird.observe.entities.referentiel.longline.LightsticksType; +import fr.ird.observe.entities.referentiel.longline.LineType; +import fr.ird.observe.entities.referentiel.longline.MaturityStatus; +import fr.ird.observe.entities.referentiel.longline.MitigationType; +import fr.ird.observe.entities.referentiel.longline.SensorBrand; +import fr.ird.observe.entities.referentiel.longline.SensorDataFormat; +import fr.ird.observe.entities.referentiel.longline.SensorType; +import fr.ird.observe.entities.referentiel.longline.SettingShape; +import fr.ird.observe.entities.referentiel.longline.SizeMeasureType; +import fr.ird.observe.entities.referentiel.longline.StomacFullness; +import fr.ird.observe.entities.referentiel.longline.TripType; +import fr.ird.observe.entities.referentiel.longline.VesselActivityLongline; +import fr.ird.observe.entities.referentiel.longline.WeightMeasureType; +import fr.ird.observe.entities.referentiel.seine.DetectionMode; +import fr.ird.observe.entities.referentiel.seine.ObjectFate; +import fr.ird.observe.entities.referentiel.seine.ObjectOperation; +import fr.ird.observe.entities.referentiel.seine.ObjectType; +import fr.ird.observe.entities.referentiel.seine.ObservedSystem; +import fr.ird.observe.entities.referentiel.seine.ReasonForDiscard; +import fr.ird.observe.entities.referentiel.seine.ReasonForNoFishing; +import fr.ird.observe.entities.referentiel.seine.ReasonForNullSet; +import fr.ird.observe.entities.referentiel.seine.SpeciesFate; +import fr.ird.observe.entities.referentiel.seine.SpeciesStatus; +import fr.ird.observe.entities.referentiel.seine.SurroundingActivity; +import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation; +import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType; +import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; +import fr.ird.observe.entities.referentiel.seine.WeightCategory; +import fr.ird.observe.entities.referentiel.seine.Wind; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; @@ -127,10 +187,49 @@ public class BinderService { public static final String EDIT_DISCARD_TARGET_CATCH = "editDiscardTargetCatch"; + protected final static String[] DEFAULT_PROPERTIES_WITH_CODE = { + ReferenceEntity.PROPERTY_CODE, + ReferenceEntity.PROPERTY_URI, + ReferenceEntity.PROPERTY_STATUS, + ReferenceEntity.PROPERTY_NEED_COMMENT + }; + + protected final static String[] DEFAULT_PROPERTIES_WITHOUT_CODE = { + ReferenceEntity.PROPERTY_URI, + ReferenceEntity.PROPERTY_STATUS, + ReferenceEntity.PROPERTY_NEED_COMMENT + }; + + protected final static String[] DEFAULT_LENGTH_WEIGHT_PARAMETER_PROPERTIES = { + LengthWeightParameter.PROPERTY_START_DATE, + LengthWeightParameter.PROPERTY_END_DATE, + LengthWeightParameter.PROPERTY_OCEAN, + LengthWeightParameter.PROPERTY_SPECIES, + LengthWeightParameter.PROPERTY_SEX, + LengthWeightParameter.PROPERTY_LENGTH_WEIGHT_FORMULA, + LengthWeightParameter.PROPERTY_WEIGHT_LENGTH_FORMULA, + LengthWeightParameter.PROPERTY_COEFFICIENTS, + LengthWeightParameter.PROPERTY_MEAN_LENGTH, + LengthWeightParameter.PROPERTY_MEAN_WEIGHT + }; + + protected final static String[] DEFAULT_I18N_PROPERTIES = { + I18nReferenceEntity.PROPERTY_LABEL1, + I18nReferenceEntity.PROPERTY_LABEL2, + I18nReferenceEntity.PROPERTY_LABEL3, + I18nReferenceEntity.PROPERTY_LABEL4, + I18nReferenceEntity.PROPERTY_LABEL5, + I18nReferenceEntity.PROPERTY_LABEL6, + I18nReferenceEntity.PROPERTY_LABEL7, + I18nReferenceEntity.PROPERTY_LABEL8 + }; + static { try { + registerReferentialBinders(); + registerSeineBinders(); registerLonglineBinders(); @@ -152,16 +251,26 @@ public class BinderService { } + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { + copyExcluding(type, context, source, target, true, propertyNames); + + } + + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, boolean bindTechnical, String... propertyNames) { + TopiaEntityBinder<E> binder = getBinder(type, context); binder.copyExcluding(source, target, propertyNames); - /* FIXME sbavencoff 29/04/2015 bind techincal fields */ - target.setTopiaId(source.getTopiaId()); - target.setTopiaVersion(source.getTopiaVersion()); - target.setTopiaCreateDate(source.getTopiaCreateDate()); + if (bindTechnical) { + + target.setTopiaId(source.getTopiaId()); + target.setTopiaVersion(source.getTopiaVersion()); + target.setTopiaCreateDate(source.getTopiaCreateDate()); + + } } @@ -634,23 +743,6 @@ public class BinderService { { - BinderModelBuilder<Program, Program> builder = newBinderBuilder( - Program.class, - Program.PROPERTY_LABEL1, - Program.PROPERTY_LABEL2, - Program.PROPERTY_LABEL3, - Program.PROPERTY_LABEL4, - Program.PROPERTY_LABEL5, - Program.PROPERTY_LABEL6, - Program.PROPERTY_LABEL7, - Program.PROPERTY_LABEL8); - - registerTopiaBinder(Program.class, builder, DISPLAY_LIST); - - } - - { - BinderModelBuilder<NonTargetCatch, NonTargetCatch> builder = newBinderBuilder( NonTargetCatch.class, NonTargetCatch.PROPERTY_SPECIES, @@ -1403,4 +1495,180 @@ public class BinderService { } } + + protected static void registerReferentialBinders() { + + { + + BinderModelBuilder<Program, Program> builder = newBinderBuilder( + Program.class, + Program.PROPERTY_LABEL1, + Program.PROPERTY_LABEL2, + Program.PROPERTY_LABEL3, + Program.PROPERTY_LABEL4, + Program.PROPERTY_LABEL5, + Program.PROPERTY_LABEL6, + Program.PROPERTY_LABEL7, + Program.PROPERTY_LABEL8); + + registerTopiaBinder(Program.class, builder, DISPLAY); + + } + + { + + BinderModelBuilder<Program, Program> builder = newBinderBuilder( + Program.class, + Program.PROPERTY_LABEL1, + Program.PROPERTY_LABEL2, + Program.PROPERTY_LABEL3, + Program.PROPERTY_LABEL4, + Program.PROPERTY_LABEL5, + Program.PROPERTY_LABEL6, + Program.PROPERTY_LABEL7, + Program.PROPERTY_LABEL8); + + registerTopiaBinder(Program.class, builder, DISPLAY_LIST); + + } + + registerReferentialForEditBinder(Country.class, Country.PROPERTY_ISO2_CODE, Country.PROPERTY_ISO3_CODE); + registerReferentialForEditBinder(FpaZone.class, FpaZone.PROPERTY_START_DATE, FpaZone.PROPERTY_END_DATE); + registerReferentialForEditBinder(GearCaracteristicType.class); + registerReferentialForEditBinder(GearCaracteristic.class, GearCaracteristic.PROPERTY_GEAR_CARACTERISTIC_TYPE, + GearCaracteristic.PROPERTY_UNIT); + registerReferentialForEditBinder(Gear.class, Gear.PROPERTY_GEAR_CARACTERISTIC); + registerReferentialForEditBinder(Harbour.class, Harbour.PROPERTY_NAME, + Harbour.PROPERTY_COUNTRY, + Harbour.PROPERTY_LOCODE, + Harbour.PROPERTY_LATITUDE, + Harbour.PROPERTY_LONGITUDE, + Harbour.PROPERTY_QUADRANT); + registerReferentialForEditBinder(LengthWeightParameter.class, LengthWeightParameter.PROPERTY_SEX, + LengthWeightParameter.PROPERTY_OCEAN, + LengthWeightParameter.PROPERTY_SPECIES, + LengthWeightParameter.PROPERTY_START_DATE); + registerReferentialForEditBinder(Ocean.class); + registerReferentialForEditBinder(Organism.class, Organism.PROPERTY_COUNTRY, Organism.PROPERTY_DESCRIPTION); + registerReferentialForEditBinder(Person.class, Person.PROPERTY_CODE, + Person.PROPERTY_LAST_NAME, + Person.PROPERTY_FIRST_NAME, + Person.PROPERTY_CAPTAIN, + Person.PROPERTY_OBSERVER, + Person.PROPERTY_DATA_ENTRY_OPERATOR, + Person.PROPERTY_COUNTRY); + registerReferentialForEditBinder(Program.class, Program.PROPERTY_ORGANISM, + Program.PROPERTY_START_DATE, + Program.PROPERTY_END_DATE, + Program.PROPERTY_DETAILLED_ACTIVITIES_OBSERVATION, + Program.PROPERTY_NON_TARGET_OBSERVATION, + Program.PROPERTY_BAIT_OBSERVATION, + Program.PROPERTY_MAMMALS_OBSERVATION, + Program.PROPERTY_SAMPLES_OBSERVATION, + Program.PROPERTY_OBJECTS_OBSERVATION, + Program.PROPERTY_BIRDS_OBSERVATION, + Program.PROPERTY_TARGET_DISCARDS_OBSERVATION, + Program.PROPERTY_GEAR_TYPE); + registerReferentialForEditBinder(Sex.class); + registerReferentialForEditBinder(SpeciesGroup.class); + registerReferentialForEditBinder(SpeciesList.class, SpeciesList.PROPERTY_SPECIES); + registerReferentialForEditBinder(Species.class, Species.PROPERTY_SPECIES_GROUP, + Species.PROPERTY_OCEAN, + Species.PROPERTY_LENGTH_MEASURE_TYPE, + Species.PROPERTY_MIN_LENGTH, + Species.PROPERTY_MAX_LENGTH, + Species.PROPERTY_MIN_WEIGHT, + Species.PROPERTY_MAX_WEIGHT, + Species.PROPERTY_HOME_ID, + Species.PROPERTY_FAO_CODE, + Species.PROPERTY_WORMS_ID, + Species.PROPERTY_SCIENTIFIC_LABEL); + registerReferentialForEditBinder(VesselSizeCategory.class, VesselSizeCategory.PROPERTY_GAUGE_LABEL, + VesselSizeCategory.PROPERTY_CAPACITY_LABEL); + registerReferentialForEditBinder(VesselType.class); + registerReferentialForEditBinder(Vessel.class, Vessel.PROPERTY_VESSEL_TYPE, + Vessel.PROPERTY_VESSEL_SIZE_CATEGORY, + Vessel.PROPERTY_FLAG_COUNTRY, + Vessel.PROPERTY_KEEL_CODE, + Vessel.PROPERTY_FLEET_COUNTRY, + Vessel.PROPERTY_YEAR_SERVICE, + Vessel.PROPERTY_LENGTH, + Vessel.PROPERTY_CAPACITY, + Vessel.PROPERTY_POWER, + Vessel.PROPERTY_SEARCH_MAXIMUM, + Vessel.PROPERTY_CHANGE_DATE); + + registerReferentialForEditBinder(DetectionMode.class); + registerReferentialForEditBinder(ObjectFate.class); + registerReferentialForEditBinder(ObjectOperation.class); + registerReferentialForEditBinder(ObjectType.class); + registerReferentialForEditBinder(ObservedSystem.class, ObservedSystem.PROPERTY_SCHOOL_TYPE); + registerReferentialForEditBinder(ReasonForDiscard.class); + registerReferentialForEditBinder(ReasonForNoFishing.class); + registerReferentialForEditBinder(ReasonForNullSet.class); + registerReferentialForEditBinder(SpeciesFate.class); + registerReferentialForEditBinder(SpeciesStatus.class); + registerReferentialForEditBinder(SurroundingActivity.class); + registerReferentialForEditBinder(TransmittingBuoyOperation.class); + registerReferentialForEditBinder(TransmittingBuoyType.class); + registerReferentialForEditBinder(VesselActivitySeine.class); + registerReferentialForEditBinder(Wind.class, Wind.PROPERTY_SPEED_RANGE, Wind.PROPERTY_WAVE_HEIGHT); + registerReferentialForEditBinder(WeightCategory.class, WeightCategory.PROPERTY_CODE, WeightCategory.PROPERTY_SPECIES); + + registerReferentialForEditBinder(BaitHaulingStatus.class); + registerReferentialForEditBinder(BaitSettingStatus.class); + registerReferentialForEditBinder(BaitType.class); + registerReferentialForEditBinder(CatchFateLongline.class); + registerReferentialForEditBinder(EncounterType.class); + registerReferentialForEditBinder(Healthness.class); + registerReferentialForEditBinder(HookPosition.class); + registerReferentialForEditBinder(HookSize.class); + registerReferentialForEditBinder(HookType.class); + registerReferentialForEditBinder(ItemHorizontalPosition.class); + registerReferentialForEditBinder(ItemVerticalPosition.class); + registerReferentialForEditBinder(LightsticksColor.class); + registerReferentialForEditBinder(LightsticksType.class); + registerReferentialForEditBinder(LineType.class); + registerReferentialForEditBinder(MaturityStatus.class, MaturityStatus.PROPERTY_LOWER_VALUE, MaturityStatus.PROPERTY_UPPER_VALUE); + registerReferentialForEditBinder(MitigationType.class); + registerReferentialForEditBinder(SensorBrand.class, SensorBrand.PROPERTY_BRAND_NAME); + registerReferentialForEditBinder(SensorDataFormat.class); + registerReferentialForEditBinder(SensorType.class); + registerReferentialForEditBinder(SettingShape.class); + registerReferentialForEditBinder(SizeMeasureType.class); + registerReferentialForEditBinder(StomacFullness.class); + registerReferentialForEditBinder(TripType.class); + registerReferentialForEditBinder(VesselActivityLongline.class); + registerReferentialForEditBinder(WeightMeasureType.class); + + } + + protected static <R extends ReferenceEntity> void registerReferentialForEditBinder(Class<R> entityType, String... extraProperties) { + registerReferentialForEditBinder(entityType, true, extraProperties); + } + + protected static <R extends ReferenceEntity> void registerReferentialForEditBinder(Class<R> entityType, boolean useDefault, String... extraProperties) { + + BinderModelBuilder<R, R> binder = newBinderBuilder(entityType); + + if (useDefault) { + binder.addSimpleProperties(DEFAULT_PROPERTIES_WITH_CODE); + } else { + binder.addSimpleProperties(DEFAULT_PROPERTIES_WITHOUT_CODE); + } + + if (I18nReferenceEntity.class.isAssignableFrom(entityType)) { + binder.addSimpleProperties(DEFAULT_I18N_PROPERTIES); + } + if (LengthWeightParameter.class.isAssignableFrom(entityType)) { + binder.addSimpleProperties(DEFAULT_LENGTH_WEIGHT_PARAMETER_PROPERTIES); + } + + if (extraProperties.length > 0) { + binder.addSimpleProperties(extraProperties); + } + registerTopiaBinder(entityType, binder, EDIT); + + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 7ddc8a3..37c7307 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -141,6 +141,10 @@ public abstract class AbstractObserveService implements ObserveService { getBinderService().copyExcluding(type, context, source, target, propertyNames); } + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target,boolean bindTechnical, String... propertyNames) { + getBinderService().copyExcluding(type, context, source, target, bindTechnical, propertyNames); + } + public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { getBinderService().copy(type, context, source, target, bindTechnical); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java index 6278b0b..2ded71e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java @@ -20,8 +20,6 @@ public interface ActivitySeineService extends ObserveService { List<ActivitySeine> getActivitySeineStubByRoute(String routeId); - List<ActivitySeine> loadAllByRouteForDisplay(String routeId); - ActivitySeine loadForDisplay(String activitySeineId); ActivitySeine loadForEdit(String activitySeineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 2dea317..860cc3e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -44,14 +44,6 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } @Override - public List<ActivitySeine> loadAllByRouteForDisplay(String routeId) { - - List<ActivitySeine> loaded = getDao().findAllStubByRouteId(routeId, getReferentielLocale()); - return loaded; - - } - - @Override public ActivitySeine loadForDisplay(String activitySeineId) { ActivitySeine loaded = getDao().newInstance(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java index 4646e30..0a7a418 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java @@ -3,6 +3,7 @@ package fr.ird.observe.services.referential; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; import java.util.List; @@ -22,6 +23,8 @@ public interface ReferentialService extends ObserveService { Program getProgramStub(String programId); + <E extends ReferenceEntity> List<E> loadListForEdit(Class<E> entityType); + <E extends ReferenceEntity> List<E> loadAndDecorateList(Class<E> entityType); <E extends ReferenceEntity> E loadAndDecorate(Class<E> entityType, String topiaId); @@ -30,6 +33,11 @@ public interface ReferentialService extends ObserveService { Set<String> getSpeciesListSpeciesIds(String speciesListId); - void copyProgramForDisplay(Program source, Program target); + <R extends ReferenceEntity> R preCreate(Class<R> entityType); + + @Commit + <R extends ReferenceEntity> String save(R toSave); + @Commit + <R extends ReferenceEntity> void delete(Class<R> entityType, String referentialId); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 3e1e86e..63b1078 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -3,19 +3,26 @@ package fr.ird.observe.services.referential; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ird.observe.BinderService; +import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.constants.ReferenceStatus; +import fr.ird.observe.entities.referentiel.LengthWeightParameter; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ProgramDAO; import fr.ird.observe.entities.referentiel.Programs; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.SpeciesList; +import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.collections.CollectionUtils; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -60,6 +67,17 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } @Override + public <E extends ReferenceEntity> List<E> loadListForEdit(Class<E> entityType) { + + List<E> entities = getDao(entityType).findAll(); + TopiaEntityBinder<E> binder = getBinder(entityType, BinderService.EDIT); + for (E entity : entities) { + binder.obtainProperties(entity); + } + return Lists.newArrayList(entities); + } + + @Override public <E extends ReferenceEntity> List<E> loadAndDecorateList(Class<E> entityType) { List<E> entities = getDao(entityType).findAll(); @@ -77,6 +95,7 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } + @Override public List<Species> loadDecoratedSpecies(String speciesListCode) { List<Species> speciess = new ArrayList<Species>(); @@ -91,7 +110,7 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } - + @Override public Set<String> getSpeciesListSpeciesIds(String speciesListId) { SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListId); @@ -103,10 +122,87 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } @Override - public void copyProgramForDisplay(Program source, Program target) { + public <R extends ReferenceEntity> R preCreate(Class<R> entityType) { + + R preCreated = getDao(entityType).newInstance(); + preCreated.setStatus(ReferenceStatus.enabled); + return preCreated; + + } + + @Override + public <R extends ReferenceEntity> String save(R toSave) { + + Class<R> entityType = (Class<R>) ObserveEntityEnum.valueOf(toSave).getContract(); + + String referentialId = doSave(null, toSave, new SaveAction<R, R>(entityType, entityType) { + + @Override + public R onCreate(R parent, R toCreate) { + + R created; + + if (getNaturalIds().containsKey(entityClass)) { + + // utilisation d'un clef naturelle + String[] naturalIdPropertyNames = getNaturalIds().get(entityClass); + TopiaEntityBinder<R> binder = getBinder(entityClass, BinderService.EDIT); + Map<String, Object> naturalIdValue = binder.obtainProperties(toCreate, naturalIdPropertyNames); + + created = getDao(entityClass).create(naturalIdValue); + copyExcluding(entityClass, BinderService.EDIT, toCreate, created, false, naturalIdPropertyNames); + + } else { + + created = getDao(entityClass).create(); + copy(entityClass, BinderService.EDIT, toCreate, created, false); + + } + + return created; + + } + + @Override + public R onUpdate(R parentBean, R toUpdate, R updated) { + + copyExcluding(entityClass, BinderService.EDIT, toUpdate, updated); + return updated; + + } + }); + + return referentialId; + + } + + @Override + public <R extends ReferenceEntity> void delete(Class<R> entityType, String referentialId) { + + doDelete(null, referentialId, new DeleteAction<R, R>(entityType, entityType)); + + } - BinderService binderService = serviceContext.getBinderService(); - binderService.simpleCopy(source, target, true); + protected static Map<Class<? extends ReferenceEntity>, String[]> NATURAL_IDS; + protected static Map<Class<? extends ReferenceEntity>, String[]> getNaturalIds() { + if (NATURAL_IDS == null) { + NATURAL_IDS = new HashMap<Class<? extends ReferenceEntity>, String[]>(); + + NATURAL_IDS.put(LengthWeightParameter.class, new String[]{ + LengthWeightParameter.PROPERTY_SEX, + LengthWeightParameter.PROPERTY_OCEAN, + LengthWeightParameter.PROPERTY_SPECIES, + LengthWeightParameter.PROPERTY_START_DATE, + }); + + NATURAL_IDS.put(WeightCategory.class, new String[]{ + WeightCategory.PROPERTY_CODE, + WeightCategory.PROPERTY_SPECIES + }); + + + } + return NATURAL_IDS; } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java index b5f58bc..a431838 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java @@ -22,8 +22,8 @@ package fr.ird.observe.ui.content.list.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; @@ -97,7 +97,8 @@ public class TripLonglinesUIHandler extends ContentListUIHandler<Program, TripLo ReferentialService service = getService(ReferentialService.class); Program loaded = service.loadAndDecorate(Program.class, selectedId); Program bean = getBean(); - service.copyProgramForDisplay(loaded, bean); + + copy(Program.class, BinderService.DISPLAY,loaded, bean); TripLonglineService tripService = getService(TripLonglineService.class); List<TripLongline> tripLonglines = tripService.getTripLonglineStubByProgram(bean.getTopiaId()); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java index 3802775..dfece7f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java @@ -21,8 +21,8 @@ */ package fr.ird.observe.ui.content.list.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; @@ -94,7 +94,7 @@ public class TripSeinesUIHandler extends ContentListUIHandler<Program, TripSeine ReferentialService service = getService(ReferentialService.class); Program loaded = service.loadAndDecorate(Program.class, selectedId); Program bean = getBean(); - service.copyProgramForDisplay(loaded, bean); + copy(Program.class, BinderService.DISPLAY, loaded, bean); TripSeineService tripService = getService(TripSeineService.class); List<TripSeine> tripSeines = tripService.getTripSeineStubByProgram(bean.getTopiaId()); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java index 378451f..d597124 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java @@ -21,14 +21,12 @@ */ package fr.ird.observe.ui.content.ref; -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.ReferenceStatus; @@ -46,37 +44,29 @@ import fr.ird.observe.ui.util.SpringUtilities; import fr.ird.observe.validation.ValidationContext; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.CardLayout2Ext; -import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.editor.bean.BeanListHeader; import jaxx.runtime.validator.swing.SwingValidatorUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.Loador; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JToolBar; -import javax.swing.ListModel; import javax.swing.RowSorter; import javax.swing.SortOrder; import javax.swing.SpringLayout; import javax.swing.SwingUtilities; import javax.swing.border.TitledBorder; import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellRenderer; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; @@ -84,8 +74,7 @@ import java.beans.Introspector; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -123,6 +112,18 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } }; + //TODO Supprimer deleteUI et mettre deleteUI2 a la place + @Override + public final void deleteUI() { + deleteUI2(); + } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + public ContentReferenceUIHandler(ContentReferenceUI<E> ui) { super(ui, null, null); } @@ -256,7 +257,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten data[0] = decorator.toString(e); for (String property : naturalIds) { Object o = values.get(property); - if (ContentReferenceUIModel.DEFAULT_PROPERTIES[0].equals(property) && o == null) { + if (ContentReferenceUIModel.DEFAULT_NATURAL_ID[0].equals(property) && o == null) { // cas special du code à 0, le loador ne retourne pas // de valeur car c'est la valeur par defaut d'un type // primitif, on force donc l'utilisation du zero. @@ -290,8 +291,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten JTable table = new JTable(new UniqueKeyTableModel(columns, datas)); table.setAutoCreateRowSorter(true); - table.getRowSorter().setSortKeys(Arrays.asList( - new RowSorter.SortKey(0, SortOrder.ASCENDING))); + table.getRowSorter().setSortKeys(Collections.singletonList(new RowSorter.SortKey(0, SortOrder.ASCENDING))); table.setFillsViewportHeight(true); JScrollPane pane = new JScrollPane(); @@ -301,8 +301,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten pane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - String title = t("observe.title.unique.key", - t(DecoratorService.getEntityLabel(beanType))); + String title = t("observe.title.unique.key", t(DecoratorService.getEntityLabel(beanType))); pane.setBorder(new TitledBorder(title)); @@ -491,16 +490,20 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten addInfoMessage(t("observe.message.creating.referentiel")); // creation mode - try { - getDataService().preCreate(getDataSource(), - null, - bean, - getLoadBinder(), - getPreCreateExecutor() - ); - } catch (DataSourceException e) { - ErrorDialogUI.showError(e); - } + + E preCreate = getService(ReferentialService.class).preCreate(model.getBeanType()); + copy(model.getBeanType(), BinderService.EDIT, preCreate, bean, true); + +// try { +// getDataService().preCreate(getDataSource(), +// null, +// bean, +// getLoadBinder(), +// getPreCreateExecutor() +// ); +// } catch (DataSourceException e) { +// ErrorDialogUI.showError(e); +// } } else { addInfoMessage(t("observe.message.updating.referentiel")); @@ -541,11 +544,6 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten validationContext.setEditingReferentielList(data); } -// @Override -// public boolean closeUI() throws Exception { -// return super.closeUI(); -// } - public final void createUI() { ContentReferenceUI<E> ui = getUi(); @@ -557,7 +555,8 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten log.debug("Will create new entity [" + getModel().getBeanType() + "]"); } - getLoadBinder().load(null, getBean(), true); + copy(getModel().getBeanType(), BinderService.EDIT, null, getBean()); +// getLoadBinder().load(null, getBean(), true); // on demarre l'edition ui.startEdit(null); @@ -572,7 +571,8 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten model.setMode(ContentMode.UPDATE); } - getLoadBinder().load(model.getSelectedBean(), getBean(), true); + copy(getModel().getBeanType(), BinderService.EDIT, model.getSelectedBean(), getBean()); +// getLoadBinder().load(model.getSelectedBean(), getBean(), true); getUi().startEdit(null); } @@ -618,24 +618,53 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } @Override - protected boolean doSave(E bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<E> binder) throws Exception { + protected boolean doSave(E bean) throws Exception { ContentReferenceUIModel<E> model = getModel(); - if (bean.getTopiaId() == null) { + boolean create = bean.getTopiaId() == null; + + ReferentialService service = getService(ReferentialService.class); + + if (!create) { + + // le bean original + E oldBean = model.getSelectedBean(); - if (log.isInfoEnabled()) { - log.info("Create referentiel " + bean); + if (oldBean != null + && oldBean.getStatus() == ReferenceStatus.enabled + && bean.getStatus() == ReferenceStatus.disabled) { + + // l'entite a ete desactive + // on recherche les objets utilisant cette entite + // on indique a l'utilisateur ce changement + if (log.isDebugEnabled()) { + log.debug("entity status was desactivated, looking for usage"); + } + EntityMap usages = service.findAllUsages(bean); + + if (usages.isEmpty()) { + if (log.isInfoEnabled()) { + log.info("No usage found, no warning to display"); + } + } else { + // some usages were found + boolean willsave = showUsagesForDesactivated(getUi(), bean, usages); + if (!willsave) { + if (log.isDebugEnabled()) { + log.debug("User refuses to continue, skip saving..."); + } + return false; + } + } } - dataService.create(dataSource, - null, - bean, - binder, - getCreateExecutor() - ); + + } + + String id = service.save(bean); + bean.setTopiaId(id); + + if (create) { if (bean instanceof Program) { @@ -644,77 +673,22 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten treeHelper.addProgram((Program) bean); } - return true; - } - - if (log.isInfoEnabled()) { - log.info("Will update exisintg entity : " + bean.getTopiaId()); - } - // le bean original - E oldBean = model.getSelectedBean(); - - if (oldBean != null && - oldBean.getStatus() == ReferenceStatus.enabled && - bean.getStatus() == ReferenceStatus.disabled) { + } else { - // l'entite a ete desactive - // on recherche les objets utilisant cette entitee - // on indique a l'utilisateur ce changement - if (log.isDebugEnabled()) { - log.debug("entity status was desactivated, looking " + - "for usage"); - } - ReferentialService service = getService(ReferentialService.class); - EntityMap usages = service.findAllUsages(bean); + if (bean instanceof Program) { - if (usages.isEmpty()) { - if (log.isInfoEnabled()) { - log.info("No usage found, no warning to display"); - } - } else { - // some usages were found - boolean willsave = showUsagesForDesactivated(getUi(), bean, - usages); - if (!willsave) { - if (log.isDebugEnabled()) { - log.debug("User refuses to continue, skip " + - "saving..."); - } - return false; - } + // update the program in tree + ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + treeHelper.updateProgram((Program) bean); } - } - // sauvegarde du bean d'edition dans le bean de la base - bean = dataService.update(dataSource, - null, // pas de parent a sauvegarder - bean, - getUpdateExecutor() - ); - if (bean instanceof Program) { - - // update the program in tree - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); - treeHelper.updateProgram((Program) bean); } return true; } @Override - protected E onUpdate(TopiaContext tx, - Object parentBean, - E beanToSave) throws TopiaException { - - getLoadBinder().copy(getBean(), beanToSave); - return beanToSave; - } - - @Override - protected boolean doDelete(E bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, E> deletor) throws Exception { + protected boolean doDelete(E bean) { ContentReferenceUI<E> ui = getUi(); ContentReferenceUIModel<E> model = getModel(); @@ -747,8 +721,10 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } String beanId = bean.getTopiaId(); - dataService.delete(dataSource, null, bean, deletor); + service.delete(model.getBeanType(), beanId); + + //FIXME Move this in afterDelete if (bean instanceof Program) { // remove the program in tree @@ -759,11 +735,9 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } @Override - protected void onDelete(TopiaContext tx, - Object parentBean, - E beanToDelete) throws TopiaException { - TopiaDAO<E> dao = getDataSource().getDAO(tx, beanToDelete); - dao.delete(beanToDelete); + protected void afterDelete() { + super.afterDelete(); + } @Override @@ -772,75 +746,11 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten getUi().stopEdit(); } - @Override - protected E onPreCreate(TopiaContext tx, - Object parent, - E bean) throws TopiaException { - - // par defaut, les objets en creation sont activés - bean.setTopiaId(null); - bean.setTopiaCreateDate(null); - bean.setTopiaVersion(0); - bean.setStatus(ReferenceStatus.enabled); - return bean; - } - - @Override - protected final E onCreate(TopiaContext tx, - Object parent, - E editBean) throws TopiaException { - - // obtention du dictionnaire de la clef metier - Map<String, Object> properties = - getLoadBinder().obtainProperties(editBean, getModel().getNaturalIds()); - - // creation de l'entite - TopiaDAO<E> dao = getDataSource().getDAO(tx, getModel().getBeanType()); - E beanToSave = dao.create(properties); - - // application du topiaId sur le bean d'édition - editBean.setTopiaId(beanToSave.getTopiaId()); - return beanToSave; - } - - public <I> int[] updateIndices(JList jlist, Collection<I> list) { - if (log.isDebugEnabled()) { - log.debug(list == null ? 0 : list.size()); - } - List<Integer> indices = new ArrayList<Integer>(); - - if (list != null && !list.isEmpty()) { - - ListModel model = jlist.getModel(); - for (int i = 0, max = model.getSize(); i < max; i++) { - I s = (I) model.getElementAt(i); - if (list.contains(s)) { - indices.add(i); - } - } - } - - int[] result = new int[indices.size()]; - int i = 0; - for (Integer indice : indices) { - result[i++] = indice; - } - indices.clear(); - return result; - } - public boolean canSeeI18nTable(E bean) { return bean instanceof I18nReferenceEntity || bean instanceof VesselSizeCategory; } - public void decorateUniqueKeyTable(JTable table, - TableCellRenderer renderer, - JScrollPane pane) { - table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - UIHelper.fixTableColumnWidth(table, 1, 70); - } - public String updateView(boolean editing) { if (log.isDebugEnabled()) { log.debug("Editing has changed : " + editing); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java index 519846b..3a66f17 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIModel.java @@ -22,13 +22,11 @@ package fr.ird.observe.ui.content.ref; import fr.ird.observe.BinderService; +import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.entities.referentiel.I18nReferenceEntity; import fr.ird.observe.entities.referentiel.LengthWeightParameter; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.ui.content.ContentUIModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.Arrays; @@ -42,8 +40,6 @@ import java.util.List; */ public abstract class ContentReferenceUIModel<E extends ReferenceEntity> extends ContentUIModel<E> { - public static final String PROPERTY_EMPTY = "empty"; - public static final String PROPERTY_SELECTED_BEAN = "selectedBean"; public static final String SUFFIX_TEXT = ".text"; @@ -92,98 +88,29 @@ public abstract class ContentReferenceUIModel<E extends ReferenceEntity> extends I18nReferenceEntity.PROPERTY_LABEL8 + SUFFIX_TEXT }; - /** liste des proprietes present sur tous les ecrans du referentiel */ - protected final static String[] DEFAULT_PROPERTIES = { - ReferenceEntity.PROPERTY_CODE, - ReferenceEntity.PROPERTY_URI, - ReferenceEntity.PROPERTY_STATUS, - ReferenceEntity.PROPERTY_NEED_COMMENT - }; - - /** liste des proprietes presents sur les entites taillePoidsAble */ - protected final static String[] DEFAULT_PARAMETRAGE_TAILLE_POIDS_ABLE_PROPERTIES = { - LengthWeightParameter.PROPERTY_START_DATE, - LengthWeightParameter.PROPERTY_END_DATE, - LengthWeightParameter.PROPERTY_OCEAN, - LengthWeightParameter.PROPERTY_SPECIES, - LengthWeightParameter.PROPERTY_SEX, - LengthWeightParameter.PROPERTY_LENGTH_WEIGHT_FORMULA, - LengthWeightParameter.PROPERTY_WEIGHT_LENGTH_FORMULA, - LengthWeightParameter.PROPERTY_COEFFICIENTS, - LengthWeightParameter.PROPERTY_MEAN_LENGTH, - LengthWeightParameter.PROPERTY_MEAN_WEIGHT - }; - - /** liste des proprietes presents sur les entites i18n */ - protected final static String[] DEFAULT_I18N_PROPERTIES = { - I18nReferenceEntity.PROPERTY_LABEL1, - I18nReferenceEntity.PROPERTY_LABEL2, - I18nReferenceEntity.PROPERTY_LABEL3, - I18nReferenceEntity.PROPERTY_LABEL4, - I18nReferenceEntity.PROPERTY_LABEL5, - I18nReferenceEntity.PROPERTY_LABEL6, - I18nReferenceEntity.PROPERTY_LABEL7, - I18nReferenceEntity.PROPERTY_LABEL8 - }; + protected final static String[] DEFAULT_NATURAL_ID = {ReferenceEntity.PROPERTY_CODE}; private static final long serialVersionUID = 1L; - /** Logger. */ - private static final Log log = LogFactory.getLog(ContentReferenceUIModel.class); - - /** la liste des propriétés du bean a charger */ - protected final String[] properties; - - /** la liste des propriétés faisant partie de la clef metier */ - protected final String[] naturalIds; - /** la liste des bindings à activer lors de l'ouverture de l'ui */ protected final String[] dataBinding; protected E selectedBean; - protected ContentReferenceUIModel(Class<E> beanType) { - - this(beanType, null, null, null); - - } - - protected ContentReferenceUIModel(Class<E> beanType, - String[] extraProperties, - String[] extraBindings) { - - this(beanType, extraProperties, null, extraBindings); - - } - protected ContentReferenceUIModel(Class<E> beanType, - String[] extraProperties, - String[] naturalIds, - String[] extraBindings) { + protected ContentReferenceUIModel(Class<E> beanType, String... extraBindings) { super(beanType); - boolean useDefault = naturalIds == null; - - // la clef naturelle par defaut est la premiere des properties - this.naturalIds = useDefault ? new String[]{DEFAULT_PROPERTIES[0]} : naturalIds; - - List<String> properties = buildProperties(useDefault, extraProperties); - this.properties = properties.toArray(new String[properties.size()]); - - List<String> bindings = buildDataBindings(useDefault, extraBindings); + List<String> bindings = buildDataBindings(extraBindings); this.dataBinding = bindings.toArray(new String[bindings.size()]); -// BinderService binderService = ObserveServiceHelper.get().getBinderService(); - BinderModelBuilder<E, E> builder = BinderService.newBinderBuilder(beanType, this.properties); - this.loadBinder = BinderService.registerTopiaBinder(beanType, builder, BinderService.EDIT); - -// this.loadBinder = binderService.getBinder(beanType, BinderService.EDIT); - + BinderService binderService = ObserveServiceHelper.get().getBinderService(); + this.loadBinder = binderService.getBinder(beanType, BinderService.EDIT); } public String[] getNaturalIds() { - return naturalIds; + return DEFAULT_NATURAL_ID; } public String[] getDataBinding() { @@ -200,70 +127,19 @@ public abstract class ContentReferenceUIModel<E extends ReferenceEntity> extends firePropertyChange(PROPERTY_SELECTED_BEAN, oldvalue, selectedBean); } -// @Override -// protected BinderModelBuilder<E, E> createOpeningBinder(BinderService binderService, String binderName) { -// -// BinderModelBuilder<E, E> builder = binderService.newBinderBuilder(beanType, properties); -// -// if (log.isDebugEnabled()) { -// log.debug("new binder [" + getClass().getName() + "#" + -// beanType.getName() + "] : " + -// Arrays.toString(properties) -// ); -// } -// -// return builder; -// } - - - /** - * construction de la liste des propriétés a binder pour une entite. - * - * @param usedefault un drapeau pour savoir si on doit conserver la premiere valeur par defaut - * @param properties les propriétés supplémentaires a ajouter en plus de - * celles communes - * @return la liste des toutes les proprietes utilises sur l'entite edite dans l'ui - */ - protected final List<String> buildProperties(boolean usedefault, String[] properties) { - - List<String> result = new ArrayList<String>(); - result.addAll(Arrays.asList(DEFAULT_PROPERTIES)); - if (properties != null) { - result.addAll(Arrays.asList(properties)); - } - Class<E> beanType = getBeanType(); - - if (I18nReferenceEntity.class.isAssignableFrom(beanType)) { - result.addAll(Arrays.asList(DEFAULT_I18N_PROPERTIES)); - } - if (LengthWeightParameter.class.isAssignableFrom(beanType)) { - result.addAll(Arrays.asList(DEFAULT_PARAMETRAGE_TAILLE_POIDS_ABLE_PROPERTIES)); - } - if (!usedefault) { - - // on supprime le premiere valeur - result.remove(DEFAULT_PROPERTIES[0]); - } - return result; - - } - /** * construction de la liste des databindings utiliser pour une entite. * - * @param usedefault un drapeau pour savoir si on doit conserver la premiere valeur par defaut - * @param dataBinding les bindings supplémentaires a utiliser en plus de - * ceux communs + * @param dataBinding les bindings supplémentaires a utiliser en plus de ceux communs * @return la liste de tous les databindings utilises sur l'entite edite dans l'ui */ - protected final List<String> buildDataBindings(boolean usedefault, String[] dataBinding) { + protected final List<String> buildDataBindings(String... dataBinding) { List<String> result = new ArrayList<String>(); result.addAll(Arrays.asList(DEFAULT_DATABINDING)); if (dataBinding != null) { result.addAll(Arrays.asList(dataBinding)); } - Class<E> beanType = getBeanType(); if (I18nReferenceEntity.class.isAssignableFrom(beanType)) { result.addAll(Arrays.asList(DEFAULT_I18N_DATABINDING)); @@ -271,11 +147,12 @@ public abstract class ContentReferenceUIModel<E extends ReferenceEntity> extends if (LengthWeightParameter.class.isAssignableFrom(beanType)) { result.addAll(Arrays.asList(DEFAULT_LENGTH_WEIGHT_PARAMETER_ABLE_DATABINDING)); } - if (!usedefault) { - - // on supprime le premier binding - result.remove(DEFAULT_DATABINDING[0]); - } + //FIXME Voir si cela casse quelque chose +// if (!usedefault) { +// +// // on supprime le premier binding +// result.remove(DEFAULT_DATABINDING[0]); +// } return result; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java index 7b8a730..f8abdd4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java @@ -22,15 +22,14 @@ package fr.ird.observe.ui.content.ref; * #L% */ -import com.google.common.base.Predicate; import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentUIInitializer; -import fr.ird.observe.ui.content.ObserveContentUI; import jaxx.runtime.swing.editor.bean.BeanListHeader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -38,11 +37,9 @@ import org.nuiton.decorator.Decorator; import org.nuiton.decorator.DecoratorUtil; import org.nuiton.decorator.JXPathDecorator; import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JList; import javax.swing.ListCellRenderer; -import java.util.ArrayList; import java.util.List; /** @@ -64,7 +61,7 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param storageService le service de persistance à utiliser pour + * @param serviceFactory le service de persistance à utiliser pour * récupérer les entités * @param entityClass le type de l'entité * @param list le component graphique à initialiser @@ -72,30 +69,22 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten * des entités * @since 1.5 */ - public static <E extends TopiaEntity> void prepareEntityList(DataSource storageService, - Class<E> entityClass, - BeanListHeader<E> list, - TopiaEntityBinder<E> loador) throws DataSourceException { + public static <E extends ReferenceEntity> void prepareMainEntityList(ObserveServiceFactory serviceFactory, + Class<E> entityClass, + BeanListHeader<E> list) { - ObserveContext tx = ObserveContext.get(); + ObserveContext context = ObserveContext.get(); // init list - Decorator<E> decorator = tx.getDecorator(entityClass); + Decorator<E> decorator = context.getDecorator(entityClass); if (log.isDebugEnabled()) { log.debug("Will use decorator " + decorator); } list.putClientProperty("decorator", decorator); - List<E> data; + ReferentialService service = serviceFactory.getService(ReferentialService.class); - if (ReferenceEntity.class.isAssignableFrom(entityClass)) { - - Predicate<E> predicate = (Predicate<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - data = tx.getDataService().getList(storageService, entityClass, predicate, loador); - - } else { - data = new ArrayList<E>(); - } + List<E> data = service.loadListForEdit(entityClass); // sort data from first decorator context DecoratorUtil.sort((JXPathDecorator<E>) decorator, data, 0); @@ -111,16 +100,16 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten list.putClientProperty("data", data); + //FIXME Remove this!!! // listen on cache modification EntityListPropertyChangeListener<E> listener = new EntityListPropertyChangeListener<E>(entityClass, list); - DataService service = ObserveContext.get().getDataService(); - service.addReferentielPropertyChangeListener(entityClass, listener); + DataService dataService = ObserveContext.get().getDataService(); + dataService.addReferentielPropertyChangeListener(entityClass, listener); } @SuppressWarnings("unchecked") - protected void init(DataSource service, DecoratorService decoratorService, BeanListHeader beanList) - throws DataSourceException { + protected void init(ObserveServiceFactory serviceFactory, DecoratorService decoratorService, BeanListHeader beanList) { beanList.setI18nPrefix("observe.common."); @@ -131,11 +120,11 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten if ("listHeader".equals(beanList.getName())) { // use the binder for loading - prepareEntityList(service, beanList.getBeanType(), beanList, ui.getModel().getLoadBinder()); + prepareMainEntityList(serviceFactory, beanList.getBeanType(), beanList); } else { - prepareEntityList(service, beanList.getBeanType(), beanList, null); + super.init(serviceFactory, decoratorService, beanList); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/CountryUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/CountryUIModel.java index afa38a4..221250f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/CountryUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/CountryUIModel.java @@ -37,9 +37,7 @@ public class CountryUIModel extends ContentReferenceUIModel<Country> { public CountryUIModel() { super(Country.class, - new String[]{Country.PROPERTY_ISO2_CODE, Country.PROPERTY_ISO3_CODE}, - new String[]{CountryUI.BINDING_ISO2_CODE_TEXT, CountryUI.BINDING_ISO3_CODE_TEXT} - ); + CountryUI.BINDING_ISO2_CODE_TEXT, CountryUI.BINDING_ISO3_CODE_TEXT); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/FpaZoneUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/FpaZoneUIModel.java index 75f8e64..9d04225 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/FpaZoneUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/FpaZoneUIModel.java @@ -37,8 +37,7 @@ public class FpaZoneUIModel extends ContentReferenceUIModel<FpaZone> { public FpaZoneUIModel() { super(FpaZone.class, - new String[]{FpaZone.PROPERTY_START_DATE, FpaZone.PROPERTY_END_DATE}, - new String[]{FpaZoneUI.BINDING_START_DATE_DATE, FpaZoneUI.BINDING_END_DATE_DATE} + FpaZoneUI.BINDING_START_DATE_DATE, FpaZoneUI.BINDING_END_DATE_DATE ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearCaracteristicUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearCaracteristicUIModel.java index 7f16da6..f2b945a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearCaracteristicUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearCaracteristicUIModel.java @@ -37,12 +37,8 @@ public class GearCaracteristicUIModel extends ContentReferenceUIModel<GearCaract public GearCaracteristicUIModel() { super(GearCaracteristic.class, - new String[]{ - GearCaracteristic.PROPERTY_GEAR_CARACTERISTIC_TYPE, - GearCaracteristic.PROPERTY_UNIT, - }, - new String[]{GearCaracteristic.PROPERTY_GEAR_CARACTERISTIC_TYPE + SUFFIX_SELECTED_ITEM, - GearCaracteristic.PROPERTY_UNIT + SUFFIX_TEXT} + GearCaracteristic.PROPERTY_GEAR_CARACTERISTIC_TYPE + SUFFIX_SELECTED_ITEM, + GearCaracteristic.PROPERTY_UNIT + SUFFIX_TEXT ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearUIModel.java index d07a3a0..3c9c633 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/GearUIModel.java @@ -65,8 +65,8 @@ public class GearUIModel extends ContentReferenceUIModel<Gear> { public GearUIModel() { super(Gear.class, - new String[]{Gear.PROPERTY_GEAR_CARACTERISTIC}, - new String[]{Gear.PROPERTY_GEAR_CARACTERISTIC + SUFFIX_SELECTED}); + Gear.PROPERTY_GEAR_CARACTERISTIC + SUFFIX_SELECTED + ); } public boolean isGearCaracteristicTabValid() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/HarbourUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/HarbourUIModel.java index 0b2da20..80c65a7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/HarbourUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/HarbourUIModel.java @@ -37,18 +37,12 @@ public class HarbourUIModel extends ContentReferenceUIModel<Harbour> { public HarbourUIModel() { super(Harbour.class, - new String[]{Harbour.PROPERTY_NAME, - Harbour.PROPERTY_COUNTRY, - Harbour.PROPERTY_LOCODE, - Harbour.PROPERTY_LATITUDE, - Harbour.PROPERTY_LONGITUDE, - Harbour.PROPERTY_QUADRANT}, - new String[]{HarbourUI.BINDING_COUNTRY_SELECTED_ITEM, - HarbourUI.BINDING_HARBOUR_NAME_TEXT, - HarbourUI.BINDING_LOCODE_TEXT, - HarbourUI.BINDING_COORDINATES_LATITUDE, - HarbourUI.BINDING_COORDINATES_LONGITUDE, - HarbourUI.BINDING_COORDINATES_QUADRANT} + HarbourUI.BINDING_COUNTRY_SELECTED_ITEM, + HarbourUI.BINDING_HARBOUR_NAME_TEXT, + HarbourUI.BINDING_LOCODE_TEXT, + HarbourUI.BINDING_COORDINATES_LATITUDE, + HarbourUI.BINDING_COORDINATES_LONGITUDE, + HarbourUI.BINDING_COORDINATES_QUADRANT ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/LengthWeightParameterUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/LengthWeightParameterUIModel.java index aeeb862..6e94af7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/LengthWeightParameterUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/LengthWeightParameterUIModel.java @@ -62,21 +62,23 @@ public class LengthWeightParameterUIModel extends ContentReferenceUIModel<Length private static final long serialVersionUID = 1L; + public static final String[] NATURAL_ID = new String[]{ + LengthWeightParameter.PROPERTY_SEX, + LengthWeightParameter.PROPERTY_OCEAN, + LengthWeightParameter.PROPERTY_SPECIES, + LengthWeightParameter.PROPERTY_START_DATE, + }; + protected boolean generalTabValid; protected boolean otherTabValid; public LengthWeightParameterUIModel() { - super(LengthWeightParameter.class, - null, - new String[]{ - LengthWeightParameter.PROPERTY_SEX, - LengthWeightParameter.PROPERTY_OCEAN, - LengthWeightParameter.PROPERTY_SPECIES, - LengthWeightParameter.PROPERTY_START_DATE, - }, - null - ); + super(LengthWeightParameter.class); + } + + public String[] getNaturalIds() { + return NATURAL_ID; } public boolean isOtherTabValid() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/OrganismUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/OrganismUIModel.java index 66fbfe6..7f75e16 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/OrganismUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/OrganismUIModel.java @@ -37,8 +37,8 @@ public class OrganismUIModel extends ContentReferenceUIModel<Organism> { public OrganismUIModel() { super(Organism.class, - new String[]{Organism.PROPERTY_COUNTRY, Organism.PROPERTY_DESCRIPTION}, - new String[]{OrganismUI.BINDING_COUNTRY_SELECTED_ITEM, OrganismUI.BINDING_DESCRIPTION_TEXT} + OrganismUI.BINDING_COUNTRY_SELECTED_ITEM, + OrganismUI.BINDING_DESCRIPTION_TEXT ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/PersonUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/PersonUIModel.java index 71d7817..9b1d7bb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/PersonUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/PersonUIModel.java @@ -37,24 +37,13 @@ public class PersonUIModel extends ContentReferenceUIModel<Person> { public PersonUIModel() { super(Person.class, - new String[]{ - Person.PROPERTY_CODE, - Person.PROPERTY_LAST_NAME, - Person.PROPERTY_FIRST_NAME, - Person.PROPERTY_CAPTAIN, - Person.PROPERTY_OBSERVER, - Person.PROPERTY_DATA_ENTRY_OPERATOR, - Person.PROPERTY_COUNTRY - }, - new String[]{Person.PROPERTY_CODE}, - new String[]{PersonUI.BINDING_CODE_TEXT, - PersonUI.BINDING_FIRST_NAME_TEXT, - PersonUI.BINDING_LAST_NAME_TEXT, - PersonUI.BINDING_CAPTAIN_SELECTED, - PersonUI.BINDING_OBSERVER_SELECTED, - PersonUI.BINDING_DATA_ENTRY_OPERATOR_SELECTED, - PersonUI.BINDING_COUNTRY_SELECTED_ITEM, - } + PersonUI.BINDING_CODE_TEXT, + PersonUI.BINDING_FIRST_NAME_TEXT, + PersonUI.BINDING_LAST_NAME_TEXT, + PersonUI.BINDING_CAPTAIN_SELECTED, + PersonUI.BINDING_OBSERVER_SELECTED, + PersonUI.BINDING_DATA_ENTRY_OPERATOR_SELECTED, + PersonUI.BINDING_COUNTRY_SELECTED_ITEM ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/ProgramUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/ProgramUIModel.java index c02b20a..7ac29a7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/ProgramUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/ProgramUIModel.java @@ -74,32 +74,18 @@ public class ProgramUIModel extends ContentReferenceUIModel<Program> { public ProgramUIModel() { super(Program.class, - new String[]{ - Program.PROPERTY_ORGANISM, - Program.PROPERTY_START_DATE, - Program.PROPERTY_END_DATE, - Program.PROPERTY_DETAILLED_ACTIVITIES_OBSERVATION, - Program.PROPERTY_NON_TARGET_OBSERVATION, - Program.PROPERTY_BAIT_OBSERVATION, - Program.PROPERTY_MAMMALS_OBSERVATION, - Program.PROPERTY_SAMPLES_OBSERVATION, - Program.PROPERTY_OBJECTS_OBSERVATION, - Program.PROPERTY_BIRDS_OBSERVATION, - Program.PROPERTY_TARGET_DISCARDS_OBSERVATION, - Program.PROPERTY_GEAR_TYPE}, - new String[]{ - ProgramUI.BINDING_ORGANISM_SELECTED_ITEM, - ProgramUI.BINDING_START_DATE_DATE, - ProgramUI.BINDING_END_DATE_DATE, - ProgramUI.BINDING_DETAILLED_ACTIVITIES_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_NON_TARGET_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_BAIT_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_MAMMALS_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_SAMPLES_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_OBJECTS_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_BIRDS_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_TARGET_DISCARDS_OBSERVATION_SELECTED_INDEX, - ProgramUI.BINDING_GEAR_TYPE_SELECTED_ITEM} + ProgramUI.BINDING_ORGANISM_SELECTED_ITEM, + ProgramUI.BINDING_START_DATE_DATE, + ProgramUI.BINDING_END_DATE_DATE, + ProgramUI.BINDING_DETAILLED_ACTIVITIES_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_NON_TARGET_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_BAIT_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_MAMMALS_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_SAMPLES_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_OBJECTS_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_BIRDS_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_TARGET_DISCARDS_OBSERVATION_SELECTED_INDEX, + ProgramUI.BINDING_GEAR_TYPE_SELECTED_ITEM ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesListUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesListUIModel.java index b6041b7..b6f8871 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesListUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesListUIModel.java @@ -65,9 +65,7 @@ public class SpeciesListUIModel extends ContentReferenceUIModel<SpeciesList> { public SpeciesListUIModel() { super(SpeciesList.class, - new String[]{SpeciesList.PROPERTY_SPECIES}, - new String[]{SpeciesList.PROPERTY_SPECIES + SUFFIX_SELECTED}, - null + SpeciesList.PROPERTY_SPECIES + SUFFIX_SELECTED ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesUIModel.java index 49fef78..b149107 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/SpeciesUIModel.java @@ -72,32 +72,19 @@ public class SpeciesUIModel extends ContentReferenceUIModel<Species> { protected boolean otherTabValid; - public SpeciesUIModel() { super(Species.class, - new String[]{Species.PROPERTY_SPECIES_GROUP, - Species.PROPERTY_OCEAN, - Species.PROPERTY_LENGTH_MEASURE_TYPE, - Species.PROPERTY_MIN_LENGTH, - Species.PROPERTY_MAX_LENGTH, - Species.PROPERTY_MIN_WEIGHT, - Species.PROPERTY_MAX_WEIGHT, - Species.PROPERTY_HOME_ID, - Species.PROPERTY_FAO_CODE, - Species.PROPERTY_WORMS_ID, - Species.PROPERTY_SCIENTIFIC_LABEL}, - new String[]{ - Species.PROPERTY_SPECIES_GROUP + SUFFIX_SELECTED_ITEM, - Species.PROPERTY_LENGTH_MEASURE_TYPE + SUFFIX_TEXT, - Species.PROPERTY_MIN_LENGTH + SUFFIX_MODEL, - Species.PROPERTY_MAX_LENGTH + SUFFIX_MODEL, - Species.PROPERTY_MIN_WEIGHT + SUFFIX_MODEL, - Species.PROPERTY_MAX_WEIGHT + SUFFIX_MODEL, - Species.PROPERTY_HOME_ID + SUFFIX_TEXT, - Species.PROPERTY_FAO_CODE + SUFFIX_TEXT, - Species.PROPERTY_WORMS_ID + SUFFIX_TEXT, - Species.PROPERTY_SCIENTIFIC_LABEL + SUFFIX_TEXT, - Species.PROPERTY_OCEAN + SUFFIX_SELECTED} + Species.PROPERTY_SPECIES_GROUP + SUFFIX_SELECTED_ITEM, + Species.PROPERTY_LENGTH_MEASURE_TYPE + SUFFIX_TEXT, + Species.PROPERTY_MIN_LENGTH + SUFFIX_MODEL, + Species.PROPERTY_MAX_LENGTH + SUFFIX_MODEL, + Species.PROPERTY_MIN_WEIGHT + SUFFIX_MODEL, + Species.PROPERTY_MAX_WEIGHT + SUFFIX_MODEL, + Species.PROPERTY_HOME_ID + SUFFIX_TEXT, + Species.PROPERTY_FAO_CODE + SUFFIX_TEXT, + Species.PROPERTY_WORMS_ID + SUFFIX_TEXT, + Species.PROPERTY_SCIENTIFIC_LABEL + SUFFIX_TEXT, + Species.PROPERTY_OCEAN + SUFFIX_SELECTED ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselSizeCategoryUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselSizeCategoryUIModel.java index 2b747d3..148c068 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselSizeCategoryUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselSizeCategoryUIModel.java @@ -37,13 +37,8 @@ public class VesselSizeCategoryUIModel extends ContentReferenceUIModel<VesselSiz public VesselSizeCategoryUIModel() { super(VesselSizeCategory.class, - new String[]{ - VesselSizeCategory.PROPERTY_GAUGE_LABEL, - VesselSizeCategory.PROPERTY_CAPACITY_LABEL - }, - new String[]{ - VesselSizeCategoryUI.BINDING_CAPACITY_LABEL_TEXT, - VesselSizeCategoryUI.BINDING_GAUGE_LABEL_TEXT} + VesselSizeCategoryUI.BINDING_CAPACITY_LABEL_TEXT, + VesselSizeCategoryUI.BINDING_GAUGE_LABEL_TEXT ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselUIModel.java index 6104995..3d3ee87 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/VesselUIModel.java @@ -77,29 +77,17 @@ public class VesselUIModel extends ContentReferenceUIModel<Vessel> { public VesselUIModel() { super(Vessel.class, - new String[]{ - Vessel.PROPERTY_VESSEL_TYPE, - Vessel.PROPERTY_VESSEL_SIZE_CATEGORY, - Vessel.PROPERTY_FLAG_COUNTRY, - Vessel.PROPERTY_KEEL_CODE, - Vessel.PROPERTY_FLEET_COUNTRY, - Vessel.PROPERTY_YEAR_SERVICE, - Vessel.PROPERTY_LENGTH, - Vessel.PROPERTY_CAPACITY, - Vessel.PROPERTY_POWER, - Vessel.PROPERTY_SEARCH_MAXIMUM, - Vessel.PROPERTY_CHANGE_DATE}, - new String[]{VesselUI.BINDING_VESSEL_TYPE_SELECTED_ITEM, - VesselUI.BINDING_VESSEL_SIZE_CATEGORY_SELECTED_ITEM, - VesselUI.BINDING_FLAG_COUNTRY_SELECTED_ITEM, - VesselUI.BINDING_KEEL_CODE_MODEL, - VesselUI.BINDING_FLEET_COUNTRY_MODEL, - VesselUI.BINDING_YEAR_SERVICE_MODEL, - VesselUI.BINDING_LENGTH_MODEL, - VesselUI.BINDING_CAPACITY_MODEL, - VesselUI.BINDING_POWER_MODEL, - VesselUI.BINDING_SEARCH_MAXIMUM_MODEL, - VesselUI.BINDING_CHANGE_DATE_DATE} + VesselUI.BINDING_VESSEL_TYPE_SELECTED_ITEM, + VesselUI.BINDING_VESSEL_SIZE_CATEGORY_SELECTED_ITEM, + VesselUI.BINDING_FLAG_COUNTRY_SELECTED_ITEM, + VesselUI.BINDING_KEEL_CODE_MODEL, + VesselUI.BINDING_FLEET_COUNTRY_MODEL, + VesselUI.BINDING_YEAR_SERVICE_MODEL, + VesselUI.BINDING_LENGTH_MODEL, + VesselUI.BINDING_CAPACITY_MODEL, + VesselUI.BINDING_POWER_MODEL, + VesselUI.BINDING_SEARCH_MAXIMUM_MODEL, + VesselUI.BINDING_CHANGE_DATE_DATE ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/BaitSettingStatusUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/BaitSettingStatusUIModel.java index 098b373..0aab29d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/BaitSettingStatusUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/BaitSettingStatusUIModel.java @@ -36,9 +36,7 @@ public class BaitSettingStatusUIModel extends ContentReferenceUIModel<BaitSettin private static final long serialVersionUID = 1L; public BaitSettingStatusUIModel() { - super(BaitSettingStatus.class - - ); + super(BaitSettingStatus.class); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/MaturityStatusUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/MaturityStatusUIModel.java index 7bfb4c2..8830a7c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/MaturityStatusUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/MaturityStatusUIModel.java @@ -37,8 +37,8 @@ public class MaturityStatusUIModel extends ContentReferenceUIModel<MaturityStatu public MaturityStatusUIModel() { super(MaturityStatus.class, - new String[]{MaturityStatus.PROPERTY_LOWER_VALUE, MaturityStatus.PROPERTY_UPPER_VALUE}, - new String[]{MaturityStatusUI.BINDING_LOWER_VALUE_TEXT, MaturityStatusUI.BINDING_UPPER_VALUE_TEXT} + MaturityStatusUI.BINDING_LOWER_VALUE_TEXT, + MaturityStatusUI.BINDING_UPPER_VALUE_TEXT ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/SensorBrandUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/SensorBrandUIModel.java index 4be8e0b..6771bf1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/SensorBrandUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/longline/SensorBrandUIModel.java @@ -37,8 +37,7 @@ public class SensorBrandUIModel extends ContentReferenceUIModel<SensorBrand> { public SensorBrandUIModel() { super(SensorBrand.class, - new String[]{SensorBrand.PROPERTY_BRAND_NAME}, - new String[]{SensorBrandUI.BINDING_BRAND_NAME_TEXT} + SensorBrandUI.BINDING_BRAND_NAME_TEXT ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/ObservedSystemUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/ObservedSystemUIModel.java index e6ed8da..f223bb2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/ObservedSystemUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/ObservedSystemUIModel.java @@ -37,8 +37,7 @@ public class ObservedSystemUIModel extends ContentReferenceUIModel<ObservedSyste public ObservedSystemUIModel() { super(ObservedSystem.class, - new String[]{ObservedSystem.PROPERTY_SCHOOL_TYPE}, - new String[]{ObservedSystemUI.BINDING_SCHOOL_TYPE_SELECTED_ITEM} + ObservedSystemUI.BINDING_SCHOOL_TYPE_SELECTED_ITEM ); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WeightCategoryUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WeightCategoryUIModel.java index 4cd1290..2e8cdd3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WeightCategoryUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WeightCategoryUIModel.java @@ -35,12 +35,18 @@ public class WeightCategoryUIModel extends ContentReferenceUIModel<WeightCategor private static final long serialVersionUID = 1L; + public static final String[] NATURAL_ID = new String[]{ + WeightCategory.PROPERTY_CODE, + WeightCategory.PROPERTY_SPECIES + }; + public WeightCategoryUIModel() { super(WeightCategory.class, - new String[]{WeightCategory.PROPERTY_CODE, WeightCategory.PROPERTY_SPECIES}, - new String[]{WeightCategory.PROPERTY_CODE, WeightCategory.PROPERTY_SPECIES}, - new String[]{WeightCategoryUI.BINDING_CODE_TEXT, WeightCategoryUI.BINDING_SPECIES_SELECTED_ITEM} - ); + WeightCategoryUI.BINDING_CODE_TEXT, WeightCategoryUI.BINDING_SPECIES_SELECTED_ITEM); } + @Override + public String[] getNaturalIds() { + return NATURAL_ID; + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WindUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WindUIModel.java index b0d50ea..cc74252 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WindUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/impl/seine/WindUIModel.java @@ -37,7 +37,6 @@ public class WindUIModel extends ContentReferenceUIModel<Wind> { public WindUIModel() { super(Wind.class, - new String[]{Wind.PROPERTY_SPEED_RANGE, Wind.PROPERTY_WAVE_HEIGHT}, new String[]{WindUI.BINDING_SPEED_RANGE_TEXT, WindUI.BINDING_WAVE_HEIGHT_TEXT} ); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 85e84bfdec44e9e39ecdfb72d6b939c5fe8a1a36 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 16:49:58 2015 +0200 deplacement du traitement après enregistrement dans les services. --- .../services/data/seine/NonTargetCatchService.java | 5 +++- .../data/seine/NonTargetCatchServiceImpl.java | 29 +++++++++++++++++++++- .../table/impl/seine/NonTargetCatchUIHandler.java | 29 ++++------------------ 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java index 538d153..f83dbd8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java @@ -1,12 +1,15 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.NonTargetCatch; +import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; import org.nuiton.topia.persistence.util.EntityListUpdator; +import java.util.List; + /** * @author Sylvain Bavencoff - bavencoff@codelutin.com */ @@ -15,7 +18,7 @@ public interface NonTargetCatchService extends ObserveService { SetSeine loadForEdit(String setId); @Commit - void save(SetSeine parent); + void save(SetSeine parent, List<NonTargetLength> tailleToDelete); @NoTransaction EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java index 3166ffa..91bf7d2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java @@ -2,18 +2,26 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.NonTargetCatch; +import fr.ird.observe.entities.seine.NonTargetLength; +import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.Collection; +import java.util.List; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com */ public class NonTargetCatchServiceImpl extends AbstractObserveService implements NonTargetCatchService { + private static final Log log = LogFactory.getLog(NonTargetCatchServiceImpl.class); + @Override public SetSeine loadForEdit(String setId) { @@ -41,7 +49,7 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements } @Override - public void save(SetSeine parent) { + public void save(SetSeine parent, final List<NonTargetLength> tailleToDelete) { TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH); TopiaEntityBinder<NonTargetCatch> childbinder = getBinder(NonTargetCatch.class, BinderService.EDIT); @@ -63,6 +71,25 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements } parent.setNonTargetDiscarded(hasRejet); } + + @Override + public void onUpdateFinalize(SetSeine parent, Collection<NonTargetCatch> oldChilds) throws TopiaException { + + if (tailleToDelete != null && !tailleToDelete.isEmpty()) { + + // on a demande la suppression de taille obsoletes + + if (log.isInfoEnabled()) { + log.info("Will remove " + tailleToDelete.size() + + " obsolete nonTargetSample(s)."); + } + + NonTargetSample echantillon = parent.getNonTargetSample().get(0); + + // on supprime les echantillons obsoletes + echantillon.getNonTargetLength().removeAll(tailleToDelete); + } + } }); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 968330f..300f200 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -37,7 +37,6 @@ import fr.ird.observe.entities.referentiel.seine.ReasonForDiscard; import fr.ird.observe.entities.referentiel.seine.SpeciesFate; import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; -import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.data.TripService; import fr.ird.observe.services.data.seine.NonTargetCatchService; @@ -51,7 +50,6 @@ import jaxx.runtime.context.JAXXContextEntryDef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JComponent; @@ -409,6 +407,7 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non @Override protected boolean doSave(SetSeine bean) { try { + return super.doSave(bean); } finally { @@ -481,7 +480,10 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non @Override protected void doPersist(SetSeine editBean) { - getService(NonTargetCatchService.class).save(editBean); + List<NonTargetLength> tailleToDelete = + ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); + + getService(NonTargetCatchService.class).save(editBean, tailleToDelete); } @@ -491,25 +493,4 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non saveUI2(refresh); } - @Override - protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<NonTargetCatch> oldChilds) { - - List<NonTargetLength> tailleToDelete = - ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); - - if (tailleToDelete != null && !tailleToDelete.isEmpty()) { - - // on a demande la suppression de taille obsoletes - - if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + - " obsolete nonTargetSample(s)."); - } - - NonTargetSample echantillon = bean.getNonTargetSample().get(0); - - // on supprime les echantillons obsoletes - echantillon.getNonTargetLength().removeAll(tailleToDelete); - } - } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit d11548946d5ce3603c0b5d108cee140cac3ef1c8 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 30 17:59:41 2015 +0200 add not null constrainst on gear use features --- observe-entities/src/main/xmi/observe-longline.properties | 6 ++++++ observe-entities/src/main/xmi/observe-seine.properties | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/observe-entities/src/main/xmi/observe-longline.properties b/observe-entities/src/main/xmi/observe-longline.properties index 14871b1..3fcb760 100644 --- a/observe-entities/src/main/xmi/observe-longline.properties +++ b/observe-entities/src/main/xmi/observe-longline.properties @@ -150,3 +150,9 @@ fr.ird.observe.entities.longline.Basket.attribute.haulingIdentifier.tagValue.not fr.ird.observe.entities.longline.Branchline.attribute.settingIdentifier.tagValue.notNull=true fr.ird.observe.entities.longline.Branchline.attribute.haulingIdentifier.tagValue.notNull=true + +fr.ird.observe.entities.longline.GearUseFeaturesLongline.attribute.gear.tagvalue.notNull=true +fr.ird.observe.entities.longline.GearUseFeaturesLongline.attribute.number.tagvalue.notNull=true + +fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline.attribute.gearCaracteristic.tagvalue.notNull=true + diff --git a/observe-entities/src/main/xmi/observe-seine.properties b/observe-entities/src/main/xmi/observe-seine.properties index 56c5db0..7a56696 100644 --- a/observe-entities/src/main/xmi/observe-seine.properties +++ b/observe-entities/src/main/xmi/observe-seine.properties @@ -133,3 +133,12 @@ fr.ird.observe.entities.seine.GearUseFeaturesSeine.attribute.gearUseFeaturesMeas ############################################################################### ### Unicite ############################################################### ############################################################################### + +############################################################################### +### NotNull ################################################################### +############################################################################### + +fr.ird.observe.entities.seine.GearUseFeaturesSeine.attribute.gear.tagvalue.notNull=true +fr.ird.observe.entities.seine.GearUseFeaturesSeine.attribute.number.tagvalue.notNull=true + +fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine.attribute.gearCaracteristic.tagvalue.notNull=true \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit f6d0a5e02e1d33c306f8c287cadcf02c178c4fb9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 30 18:03:33 2015 +0200 fix measurement save code --- .../GearUseFeaturesLonglineServiceImpl.java | 42 ++++++++++------------ .../seine/GearUseFeaturesSeineServiceImpl.java | 41 +++++++++------------ 2 files changed, 34 insertions(+), 49 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index efbe94b..920d654 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -107,7 +107,12 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public GearUseFeaturesLongline onCreateChild(GearUseFeaturesLongline childToCreate) { - GearUseFeaturesLongline childCreated = super.onCreateChild(childToCreate); + + GearUseFeaturesLongline childCreated = getDao(entityClass).create( + GearUseFeaturesLongline.PROPERTY_GEAR,childToCreate.getGear(), + GearUseFeaturesLongline.PROPERTY_NUMBER,childToCreate.getNumber() + ); + childBinder.load(childToCreate, childCreated, false); saveMeasurement(childToCreate, childCreated); return childCreated; @@ -126,49 +131,38 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i TopiaEntityBinder<GearUseFeaturesMeasurementLongline> measurementBinder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - List<GearUseFeaturesMeasurementLongline> measurementsToDelete = Lists.newArrayList(); - - if (childSaved.getGearUseFeaturesMeasurement() != null) { - - measurementsToDelete.addAll(childSaved.getGearUseFeaturesMeasurement()); + List<GearUseFeaturesMeasurementLongline> measurementsNew = Lists.newArrayList(); - } + if (!childToSave.isGearUseFeaturesMeasurementEmpty()) { - List<GearUseFeaturesMeasurementLongline> measurementsNew = Lists.newArrayList(); + for (GearUseFeaturesMeasurementLongline measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { - for (GearUseFeaturesMeasurementLongline measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + GearUseFeaturesMeasurementLongline measurementSaved; - GearUseFeaturesMeasurementLongline measurementSaved; + if (measurementToSave.getTopiaId() == null) { - if (measurementToSave.getTopiaId() == null) { + measurementSaved = dao.create(GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); - measurementSaved = dao.create(); + measurementBinder.load(measurementToSave, measurementSaved, false); - measurementBinder.load(measurementToSave, measurementSaved, false); + } else { - } else { + measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - measurementSaved = findByTopiaId(GearUseFeaturesMeasurementLongline.class, measurementToSave.getTopiaId()); + measurementBinder.load(measurementToSave, measurementSaved, true); - measurementBinder.load(measurementToSave, measurementSaved, true); + } - measurementsToDelete.remove(measurementSaved); + measurementsNew.add(measurementSaved); } - measurementsNew.add(measurementSaved); - } childSaved.clearGearUseFeaturesMeasurement(); childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); - for (GearUseFeaturesMeasurementLongline toDelete : measurementsToDelete) { - - dao.delete(toDelete); - - } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index a76e778..1f61015 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -108,7 +108,10 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public GearUseFeaturesSeine onCreateChild(GearUseFeaturesSeine childToCreate) { - GearUseFeaturesSeine childCreated = super.onCreateChild(childToCreate); + GearUseFeaturesSeine childCreated = getDao(entityClass).create( + GearUseFeaturesSeine.PROPERTY_GEAR, childToCreate.getGear(), + GearUseFeaturesSeine.PROPERTY_NUMBER, childToCreate.getNumber()); + childBinder.load(childToCreate, childCreated, false); saveMeasurement(childToCreate, childCreated); return childCreated; @@ -127,50 +130,38 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl TopiaEntityBinder<GearUseFeaturesMeasurementSeine> measurementBinder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - List<GearUseFeaturesMeasurementSeine> measurementsToDelete = Lists.newArrayList(); - - if (childSaved.getGearUseFeaturesMeasurement() != null) { + List<GearUseFeaturesMeasurementSeine> measurementsNew = Lists.newArrayList(); - measurementsToDelete.addAll(childSaved.getGearUseFeaturesMeasurement()); + if (!childToSave.isGearUseFeaturesMeasurementEmpty()) { - } - - List<GearUseFeaturesMeasurementSeine> measurementsNew = Lists.newArrayList(); + for (GearUseFeaturesMeasurementSeine measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { - for (GearUseFeaturesMeasurementSeine measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + GearUseFeaturesMeasurementSeine measurementSaved; - GearUseFeaturesMeasurementSeine measurementSaved; + if (measurementToSave.getTopiaId() == null) { - if (measurementToSave.getTopiaId() == null) { + measurementSaved = dao.create(GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); - measurementSaved = dao.create(); + measurementBinder.load(measurementToSave, measurementSaved, false); - measurementBinder.load(measurementToSave, measurementSaved, false); + } else { - } else { + measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - measurementSaved = findByTopiaId(GearUseFeaturesMeasurementSeine.class, measurementToSave.getTopiaId()); + measurementBinder.load(measurementToSave, measurementSaved, true); - measurementBinder.load(measurementToSave, measurementSaved, true); + } - measurementsToDelete.remove(measurementSaved); + measurementsNew.add(measurementSaved); } - measurementsNew.add(measurementSaved); - } childSaved.clearGearUseFeaturesMeasurement(); childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); - for (GearUseFeaturesMeasurementSeine toDelete : measurementsToDelete) { - - dao.delete(toDelete); - - } - } }); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 0c7e4f80cb5130bbe3ec21420752ca276cd740de Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 30 18:19:57 2015 +0200 correction sauvegarde équipement, sauvegarde composition --- .../observe/services/AbstractObserveService.java | 26 +++++++++++++++ .../GearUseFeaturesLonglineServiceImpl.java | 2 +- .../longline/LonglineGlobalCompositionService.java | 15 +++++++++ .../LonglineGlobalCompositionServiceImpl.java | 39 ++++++++++++++++++++++ .../LonglineGlobalCompositionUIHandler.java | 28 +++++++++------- .../longline/GearUseFeaturesLonglineUIHandler.java | 2 +- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 2 +- .../EditableTableWithCacheTableModelSupport.java | 11 ++++++ 8 files changed, 110 insertions(+), 15 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 37c7307..d9f5bf5 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -7,9 +7,11 @@ import fr.ird.observe.BinderService; import fr.ird.observe.IObserveConfig; import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.ObserveServiceHelper; +import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceLocale; +import org.apache.commons.lang3.reflect.ConstructorUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; @@ -449,6 +451,30 @@ public abstract class AbstractObserveService implements ObserveService { TopiaEntityHelper.checkNotNullAndExistingEntity(variableName, entity); } + protected <S extends ObserveService> S newService(Class<S> serviceType) { + + Class<S> serviceImpl; + try { + //FIXME Cela devrait dépendre de la datasource ? + serviceImpl = (Class<S>) Class.forName(serviceType.getName() + "Impl"); + } catch (ClassNotFoundException e) { + throw new IllegalStateException("Could not find implementation class for " + serviceType); + } + + try { + + // Instanciate concrete service + S service = ConstructorUtils.invokeConstructor(serviceImpl); + service.setServiceContext(serviceContext); + + return service; + + } catch (Exception e) { + throw new ObserveTechnicalException("Could not create service: " + serviceType, e); + } + + } + diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index 920d654..b089a8e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -140,7 +140,7 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i GearUseFeaturesMeasurementLongline measurementSaved; if (measurementToSave.getTopiaId() == null) { - + measurementSaved = dao.create(GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); measurementBinder.load(measurementToSave, measurementSaved, false); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java new file mode 100644 index 0000000..41fe50e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java @@ -0,0 +1,15 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public interface LonglineGlobalCompositionService extends ObserveService{ + + @Commit + String save(SetLongline bean); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java new file mode 100644 index 0000000..2ffef64 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java @@ -0,0 +1,39 @@ +package fr.ird.observe.services.data.longline; + +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.entities.referentiel.longline.MitigationType; +import fr.ird.observe.services.AbstractObserveService; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class LonglineGlobalCompositionServiceImpl extends AbstractObserveService implements LonglineGlobalCompositionService { + + @Override + public String save(SetLongline toSave) { + + SetLongline saved = findByTopiaId(SetLongline.class, toSave.getTopiaId()); + + copyExcluding(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION, toSave, saved, SetLongline.PROPERTY_MITIGATION_TYPE); + + saved.clearMitigationType(); + + for (MitigationType mitigationTypeToSave : toSave.getMitigationType()) { + + MitigationType mitigationTypeSaved = findByTopiaId(MitigationType.class, mitigationTypeToSave.getTopiaId()); + + saved.addMitigationType(mitigationTypeSaved); + + } + + getDao(SetLongline.class).update(saved); + + newService(FloatlinesCompositionService.class).save(toSave); + newService(BranchlinesCompositionService.class).save(toSave); + newService(HooksCompositionService.class).save(toSave); + newService(BaitsCompositionService.class).save(toSave); + + return saved.getTopiaId(); + } +} diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java index d176a38..821f821 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java @@ -22,12 +22,14 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.data.longline.LonglineGlobalCompositionService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.content.table.impl.longline.BaitsCompositionUI; @@ -36,8 +38,6 @@ import fr.ird.observe.ui.content.table.impl.longline.FloatlinesCompositionUI; import fr.ird.observe.ui.content.table.impl.longline.HooksCompositionUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; @@ -196,19 +196,16 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong } @Override - protected SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { + protected boolean doSave(SetLongline bean) throws Exception { - beanToSave.setComment(getBean().getComment()); - beanToSave.clearMitigationType(); - beanToSave.addAllMitigationType(getBean().getMitigationType()); + copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, getUi().getFloatlinesCompositionUI().getBean(), bean); + copy(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, getUi().getBranchlinesCompositionUI().getBean(), bean); + copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, getUi().getHooksCompositionUI().getBean(), bean); + copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, getUi().getBaitsCompositionUI().getBean(), bean); - //FIXME -// getUi().getFloatlinesCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); -// getUi().getBranchlinesCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); -// getUi().getHooksCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); -// getUi().getBaitsCompositionUI().getHandler().onUpdate(tx, parentBean, beanToSave); + getService(LonglineGlobalCompositionService.class).save(bean); - return beanToSave; + return true; } @Override @@ -220,4 +217,11 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong getUi().getHooksCompositionUI().getHandler().afterSave(refresh); getUi().getBaitsCompositionUI().getHandler().afterSave(refresh); } + + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); + } + } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index c36fd99..6d1421f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -147,7 +147,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip GearUseFeaturesLongline gearUseFeaturesLongline = gearUseFeatures.get(row); - List<GearUseFeaturesMeasurementLongline> measurements = measurementsTableModel.getCacheForRow(row); + List<GearUseFeaturesMeasurementLongline> measurements = measurementsTableModel.getCacheForRowNotEmpty(row); gearUseFeaturesLongline.clearGearUseFeaturesMeasurement(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index 64c854b..9416c2f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -398,7 +398,7 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei GearUseFeaturesSeine gearUseFeaturesSeine = gearUseFeatures.get(row); - List<GearUseFeaturesMeasurementSeine> measurements = measurementsTableModel.getCacheForRow(row); + List<GearUseFeaturesMeasurementSeine> measurements = measurementsTableModel.getCacheForRowNotEmpty(row); gearUseFeaturesSeine.clearGearUseFeaturesMeasurement(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/util/table/EditableTableWithCacheTableModelSupport.java b/observe-swing/src/main/java/fr/ird/observe/ui/util/table/EditableTableWithCacheTableModelSupport.java index 54f2cc1..705d16a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/util/table/EditableTableWithCacheTableModelSupport.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/util/table/EditableTableWithCacheTableModelSupport.java @@ -71,6 +71,17 @@ public abstract class EditableTableWithCacheTableModelSupport<E extends TopiaEnt return measures == null ? null : measures.getData(); } + public List<E> getCacheForRowNotEmpty(int rowIndex) { + List<E> measures = Lists.newArrayList(); + for (E measure : getCacheForRow(rowIndex)) { + if (isRowNotEmpty(measure)) { + measures.add(measure); + } + } + + return measures; + } + public void initCacheForRow(int editingRow, List<E> data) { EditableList<E> editableList = cacheByRow.get(editingRow); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 785c85708d6a2d2bec8ae81da90bcb4c6411e12a Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 00:14:16 2015 +0200 - Suppression dans les handlers to code avec les transactions - Amélioration du code dans les services - faire fonctionner la sauvegarde de CatchLongine refs #7017 --- .../main/java/fr/ird/observe/BinderService.java | 55 ++- .../java/fr/ird/observe/entities/Entities.java | 4 + .../observe/services/AbstractObserveService.java | 53 +-- .../observe/services/ObserveServiceFactory.java | 32 +- .../data/longline/ActivityLonglineServiceImpl.java | 24 -- .../BranchlinesCompositionServiceImpl.java | 3 +- .../data/longline/CatchLonglineServiceImpl.java | 143 +++++++- .../data/longline/EncounterServiceImpl.java | 3 +- .../longline/FloatlinesCompositionServiceImpl.java | 4 +- .../GearUseFeaturesLonglineServiceImpl.java | 132 ++++--- .../data/longline/HooksCompositionServiceImpl.java | 1 + .../longline/LonglineDetailCompositionService.java | 11 + .../LonglineDetailCompositionServiceImpl.java | 182 ++++++++++ .../longline/LonglineGlobalCompositionService.java | 3 +- .../LonglineGlobalCompositionServiceImpl.java | 33 +- .../data/longline/SensorUsedServiceImpl.java | 1 - .../services/data/longline/SetLonglineService.java | 11 +- .../data/longline/SetLonglineServiceImpl.java | 56 ++- .../services/data/longline/TdrServiceImpl.java | 1 - .../services/data/seine/ActivitySeineService.java | 15 - .../data/seine/ActivitySeineServiceImpl.java | 115 +----- .../services/data/seine/FloatingObjectService.java | 21 -- .../data/seine/FloatingObjectServiceImpl.java | 193 ++++------ .../data/seine/GearUseFeaturesSeineService.java | 6 - .../seine/GearUseFeaturesSeineServiceImpl.java | 125 ++++--- .../services/data/seine/NonTargetCatchService.java | 6 - .../data/seine/NonTargetCatchServiceImpl.java | 23 +- .../data/seine/NonTargetLengthService.java | 6 - .../data/seine/NonTargetLengthServiceImpl.java | 18 +- .../data/seine/NonTargetSampleServiceImpl.java | 49 ++- .../data/seine/ObjectObservedSpeciesService.java | 3 - .../seine/ObjectObservedSpeciesServiceImpl.java | 8 +- .../data/seine/ObjectSchoolEstimateService.java | 3 - .../seine/ObjectSchoolEstimateServiceImpl.java | 6 +- .../services/data/seine/SchoolEstimateService.java | 4 - .../data/seine/SchoolEstimateServiceImpl.java | 6 +- .../services/data/seine/TargetLengthService.java | 7 - .../data/seine/TargetLengthServiceImpl.java | 17 +- .../data/seine/TargetSampleServiceImpl.java | 15 +- .../services/referential/ReferentialService.java | 3 + .../referential/ReferentialServiceImpl.java | 12 + .../ird/observe/ui/content/ContentUIHandler.java | 177 ++------- .../content/impl/longline/BranchlineUIHandler.java | 14 +- .../LonglineDetailCompositionUIHandler.java | 165 +-------- .../LonglineGlobalCompositionUIHandler.java | 33 +- .../impl/longline/SetLonglineUIHandler.java | 135 +++---- .../ActivitySeineObservedSystemUIHandler.java | 11 +- ...ngObjectTransmittingBuoyOperationUIHandler.java | 112 +----- ...tingObjectTransmittingBuoyOperationUIModel.java | 31 +- .../impl/seine/FloatingObjectUIHandler.java | 14 +- .../ui/content/impl/seine/SetSeineUIHandler.java | 12 - .../ui/content/open/ContentOpenableUIHandler.java | 12 - .../open/impl/seine/ActivitySeineUIHandler.java | 9 +- .../ui/content/ref/ContentReferenceUIHandler.java | 12 - .../ui/content/table/ContentTableUIHandler.java | 329 +++++++++-------- .../impl/longline/BaitsCompositionUIHandler.java | 9 +- .../longline/BranchlinesCompositionUIHandler.java | 10 +- .../impl/longline/CatchLonglineUIHandler.java | 182 +++------- .../table/impl/longline/EncounterUIHandler.java | 9 +- .../longline/FloatlinesCompositionUIHandler.java | 9 +- .../longline/GearUseFeaturesLonglineUIHandler.java | 8 +- .../impl/longline/HooksCompositionUIHandler.java | 10 +- .../table/impl/longline/SensorUsedUIHandler.java | 10 +- .../content/table/impl/longline/TdrUIHandler.java | 8 +- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 17 +- .../table/impl/seine/NonTargetCatchUIHandler.java | 58 +-- .../table/impl/seine/NonTargetSampleUIHandler.java | 58 ++- .../impl/seine/ObjectObservedSpeciesUIHandler.java | 14 +- .../impl/seine/ObjectSchoolEstimateUIHandler.java | 14 +- .../table/impl/seine/SchoolEstimateUIHandler.java | 9 +- .../table/impl/seine/TargetCatchUIHandler.java | 190 +++++----- .../impl/seine/TargetDiscardCatchUIHandler.java | 394 ++++++++++----------- .../table/impl/seine/TargetSampleUIHandler.java | 34 +- 73 files changed, 1507 insertions(+), 2015 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 701b12f..0874332 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -115,6 +115,8 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.entities.seine.TransmittingBuoy; +import fr.ird.observe.entities.seine.TransmittingBuoyImpl; import fr.ird.observe.entities.seine.TripSeine; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -167,7 +169,7 @@ public class BinderService { public static final String EDIT_OBJECT_OBSERVED_SPECIES = "editObjectObservedSpecies"; - public static final String EDIT_OBJECT_OPERATION = "editObjectOperation"; + public static final String EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY = "editObjectOperation"; public static final String EDIT_OBSERVED_SYSTEM = "editObservedSystem"; @@ -538,13 +540,41 @@ public class BinderService { ActivitySeine.PROPERTY_QUADRANT, ActivitySeine.PROPERTY_LATITUDE, ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_ERS_ID, ActivitySeine.PROPERTY_TIME, ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_COMMENT, + ActivitySeine.PROPERTY_VESSEL_SPEED, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_OPEN); + ActivitySeine.PROPERTY_DETECTION_MODE, + ActivitySeine.PROPERTY_SET_SEINE, + ActivitySeine.PROPERTY_FLOATING_OBJECT, + ActivitySeine.PROPERTY_OPEN, + ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, + ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, + ActivitySeine.PROPERTY_NEXT_FPA_ZONE); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); + //FIXME this one was used ? +// BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( +// ActivitySeine.class, +// ActivitySeine.PROPERTY_QUADRANT, +// ActivitySeine.PROPERTY_LATITUDE, +// ActivitySeine.PROPERTY_LONGITUDE, +// ActivitySeine.PROPERTY_TIME, +// ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, +// ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, +// ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, +// ActivitySeine.PROPERTY_WIND, +// ActivitySeine.PROPERTY_OPEN); +// registerTopiaBinder(ActivitySeine.class, builder, EDIT); } @@ -644,10 +674,29 @@ public class BinderService { BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( FloatingObject.class, + FloatingObject.PROPERTY_TRANSMITTING_BUOY, FloatingObject.PROPERTY_OBJECT_OPERATION, FloatingObject.PROPERTY_COMMENT); - registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OPERATION); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, FloatingObject.PROPERTY_TRANSMITTING_BUOY); + + registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY); + + } + + { + + BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = newBinderBuilder( + TransmittingBuoy.class, + TransmittingBuoy.PROPERTY_CODE, + TransmittingBuoy.PROPERTY_OWNERSHIP, + TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, + TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, + TransmittingBuoy.PROPERTY_BRAND, + TransmittingBuoy.PROPERTY_COUNTRY); + + TopiaEntityBinder<TransmittingBuoy> binder = registerTopiaBinder(TransmittingBuoy.class, builder, EDIT); + binder.setEmpty(new TransmittingBuoyImpl()); } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java b/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java index f69517c..822d926 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java @@ -365,4 +365,8 @@ public class Entities { return id.contains("Longline"); } + public static <E extends TopiaEntity> boolean isNew(E entity) { + return entity.getTopiaId()==null; + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index d9f5bf5..2f2df05 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -7,11 +7,9 @@ import fr.ird.observe.BinderService; import fr.ird.observe.IObserveConfig; import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.ObserveServiceHelper; -import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceLocale; -import org.apache.commons.lang3.reflect.ConstructorUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; @@ -143,7 +141,7 @@ public abstract class AbstractObserveService implements ObserveService { getBinderService().copyExcluding(type, context, source, target, propertyNames); } - public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target,boolean bindTechnical, String... propertyNames) { + public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, boolean bindTechnical, String... propertyNames) { getBinderService().copyExcluding(type, context, source, target, bindTechnical, propertyNames); } @@ -246,7 +244,7 @@ public abstract class AbstractObserveService implements ObserveService { checkNotNullAndExistingEntity(PARENT_BEAN, parent); } - if (toSave.getTopiaId() == null) { + if (Entities.isNew(toSave)) { checkNotNullAndNoneExistingEntity(BEAN, toSave); @@ -342,7 +340,7 @@ public abstract class AbstractObserveService implements ObserveService { } - public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction ) { + public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction) { Collection<E> childrenToSave = saveCollectionAction.listUpdator.getChilds(parentToSave); @@ -356,13 +354,11 @@ public abstract class AbstractObserveService implements ObserveService { saveCollectionAction.listUpdator.removeAll(parentSaved); - TopiaDAO<E> dao = getDao(saveCollectionAction.entityClass); - for (E childToSave : childrenToSave) { E childSaved; - if (childToSave.getTopiaId() == null) { + if (Entities.isNew(childToSave)) { // creation du fils childSaved = saveCollectionAction.onCreateChild(childToSave); @@ -370,16 +366,14 @@ public abstract class AbstractObserveService implements ObserveService { } else { // mise a jour du fils - childSaved = dao.findByTopiaId(childToSave.getTopiaId()); + childSaved = saveCollectionAction.onUpdateChild(childToSave); - childSaved = saveCollectionAction.onUpdateChild(childToSave, childSaved); } saveCollectionAction.listUpdator.addToList(parentSaved, childSaved); } - // on donne la main aux implantations pour faire des traitements - // supplémentaires + // on donne la main aux implantations pour faire des traitements supplémentaires saveCollectionAction.onUpdateFinalize(parentToSave, oldChilds); @@ -412,7 +406,7 @@ public abstract class AbstractObserveService implements ObserveService { } public void onUpdateFinalize(P parent, Collection<E> oldChilds) throws TopiaException { - // par défaut, rien à faire + // par défaut, rien à faire après la sauvegarde de la liste } public P onUpdateParent(P parentToSave, P parentSaved) { @@ -431,17 +425,21 @@ public abstract class AbstractObserveService implements ObserveService { } - public E onUpdateChild(E childToSave, E childSaved) { + public E onUpdateChild(E childToSave) { + + TopiaDAO<E> dao = getDao(entityClass); + + E childSaved = dao.findByTopiaId(childToSave.getTopiaId()); childBinder.load(childToSave, childSaved, true); - childSaved = getDao(entityClass).update(childSaved); + childSaved = dao.update(childSaved); + return childSaved; } } - public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); } @@ -453,29 +451,10 @@ public abstract class AbstractObserveService implements ObserveService { protected <S extends ObserveService> S newService(Class<S> serviceType) { - Class<S> serviceImpl; - try { - //FIXME Cela devrait dépendre de la datasource ? - serviceImpl = (Class<S>) Class.forName(serviceType.getName() + "Impl"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Could not find implementation class for " + serviceType); - } - - try { - - // Instanciate concrete service - S service = ConstructorUtils.invokeConstructor(serviceImpl); - service.setServiceContext(serviceContext); - - return service; - - } catch (Exception e) { - throw new ObserveTechnicalException("Could not create service: " + serviceType, e); - } + S service = ObserveServiceFactory.newService(serviceType, serviceContext); + return service; } - - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index 79f76ef..3e6af98 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -56,7 +56,7 @@ public class ObserveServiceFactory implements Closeable { public ObserveService load(Class<? extends ObserveService> key) throws Exception { Preconditions.checkNotNull(key, "service key can't be null"); Preconditions.checkNotNull(dataSource, "can't ask a service if not datasource is setted"); - ObserveService service = createService(key, ObserveServiceFactory.this.applicationContext, ObserveServiceFactory.this.dataSource); + ObserveService service = newProxyService(key, ObserveServiceFactory.this.applicationContext, ObserveServiceFactory.this.dataSource); if (log.isDebugEnabled()) { log.debug("New service " + service); } @@ -102,7 +102,7 @@ public class ObserveServiceFactory implements Closeable { services.invalidateAll(); } - protected <S extends ObserveService> S createService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { + public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { Preconditions.checkNotNull(serviceType, "serviceType can't be null"); Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); @@ -110,23 +110,24 @@ public class ObserveServiceFactory implements Closeable { ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); - S service = newService(serviceType, serviceContext); - return service; + S service = newProxyService(serviceType, serviceContext); + return service ; } - protected <S extends ObserveService> S createService(Class<S> serviceType, ObserveServiceContext serviceContext) { + public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveServiceContext serviceContext) { Preconditions.checkNotNull(serviceType, "serviceType can't be null"); Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); Preconditions.checkNotNull(serviceContext, "serviceContext can't be null"); S service = newService(serviceType, serviceContext); - return service; + S proxyService = addProxyService(serviceType, service, serviceContext); + return proxyService; } - protected <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { + public static <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { Class<S> serviceImpl; try { @@ -142,11 +143,7 @@ public class ObserveServiceFactory implements Closeable { S service = ConstructorUtils.invokeConstructor(serviceImpl); service.setServiceContext(serviceContext); - // Instanciate transactional proxied service - ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); - S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); - - return proxyService; + return service; } catch (Exception e) { throw new ObserveTechnicalException("Could not create service: " + serviceType, e); @@ -154,6 +151,17 @@ public class ObserveServiceFactory implements Closeable { } + protected <S extends ObserveService> S addProxyService(Class<S> serviceType, S service, ObserveServiceContext serviceContext) { + + // Instanciate transactional proxied service + ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); + S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); + + return proxyService; + + + } + protected static class ServiceInvocationHandler implements InvocationHandler { private final ObserveServiceContext serviceContext; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index 72406a9..8a81987 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -139,30 +139,6 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } - protected ActivityLongline create(String tripLonglineId, ActivityLongline toCreate) { - - ActivityLonglineDAO dao = getDao(); - ActivityLongline created = dao.create(toCreate); - - TripLongline tripLongline = findByTopiaId(TripLongline.class, tripLonglineId); - tripLongline.addActivityLongline(created); - - return created; - - } - - protected ActivityLongline update(ActivityLongline toUpdate) { - - ActivityLonglineDAO dao = getDao(); - ActivityLongline updated = dao.findByTopiaId(toUpdate.getTopiaId()); - copyExcluding(ActivityLongline.class, BinderService.EDIT, - toUpdate, updated, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); - return updated; - - } - protected ActivityLonglineDAO getDao() { return (ActivityLonglineDAO) getDao(ActivityLongline.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java index 4986d00..0eb34f6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java @@ -18,6 +18,7 @@ import java.util.List; * @since 4.0 */ public class BranchlinesCompositionServiceImpl extends AbstractObserveService implements BranchlinesCompositionService { + @Override public SetLongline loadForEdit(String setLonglineId) { @@ -26,9 +27,9 @@ public class BranchlinesCompositionServiceImpl extends AbstractObserveService im SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); copy(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, parentToLoad, parentLoaded); - TopiaEntityBinder<BranchlinesComposition> binder = getBinder(BranchlinesComposition.class, BinderService.EDIT); if (!parentToLoad.isBranchlinesCompositionEmpty()) { + TopiaEntityBinder<BranchlinesComposition> binder = getBinder(BranchlinesComposition.class, BinderService.EDIT); TopiaDAO<BranchlinesComposition> childDao = getDao(BranchlinesComposition.class); List<BranchlinesComposition> childs = new ArrayList<BranchlinesComposition>(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java index 212ce50..2f0c60a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -1,21 +1,23 @@ package fr.ird.observe.services.data.longline; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.longline.Branchline; import fr.ird.observe.entities.longline.BranchlineDAO; import fr.ird.observe.entities.longline.CatchLongline; import fr.ird.observe.entities.longline.CatchLonglineDAO; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SizeMeasure; -import fr.ird.observe.entities.longline.SizeMeasureImpl; import fr.ird.observe.entities.longline.WeightMeasure; -import fr.ird.observe.entities.longline.WeightMeasureImpl; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections4.CollectionUtils; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -55,10 +57,9 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); copy(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE, parentToLoad, parentLoaded); - TopiaEntityBinder<CatchLongline> binder = getBinder(CatchLongline.class, BinderService.EDIT); - if (!parentToLoad.isCatchLonglineEmpty()) { + TopiaEntityBinder<CatchLongline> binder = getBinder(CatchLongline.class, BinderService.EDIT); TopiaDAO<CatchLongline> childDao = getDao(CatchLongline.class); List<CatchLongline> childs = new ArrayList<CatchLongline>(); @@ -85,22 +86,123 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE); TopiaEntityBinder<CatchLongline> childBinder = getBinder(CatchLongline.class, BinderService.EDIT); - doSaveList(setLongline, new SaveCollectionAction<SetLongline, CatchLongline>( - SetLongline.class, CatchLongline.class, getListUpdator(), parentBinder, childBinder)); + doSaveList(setLongline, + new SaveCollectionAction<SetLongline, CatchLongline>(SetLongline.class, + CatchLongline.class, + getListUpdator(), parentBinder, childBinder) { + + @Override + public CatchLongline onCreateChild(CatchLongline childToCreate) { + + CatchLongline createdChild = super.onCreateChild(childToCreate); + saveSizeMeasures(childToCreate.getSizeMeasure(), createdChild); + saveWeightMeasures(childToCreate.getWeightMeasure(), createdChild); + return createdChild; + + } + + @Override + public CatchLongline onUpdateChild(CatchLongline childToSave) { + + CatchLongline childSaved = super.onUpdateChild(childToSave); + saveSizeMeasures(childToSave.getSizeMeasure(), childSaved); + saveWeightMeasures(childToSave.getWeightMeasure(), childSaved); + return childSaved; + + } + + protected void saveSizeMeasures(Collection<SizeMeasure> sizeMeasurementsToSave, CatchLongline childSaved) { + + List<SizeMeasure> sizeMeasuresToSave = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(sizeMeasurementsToSave)) { + + TopiaDAO<SizeMeasure> dao = getDao(SizeMeasure.class); + TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); + + for (SizeMeasure sizeMeasureToSave : sizeMeasurementsToSave) { + + SizeMeasure sizeMeasureSaved; + + if (Entities.isNew(sizeMeasureToSave)) { + + sizeMeasureSaved = dao.create(); + binder.load(sizeMeasureToSave, sizeMeasureSaved, false); + + } else { + + sizeMeasureSaved = dao.findByTopiaId(sizeMeasureToSave.getTopiaId()); + binder.load(sizeMeasureToSave, sizeMeasureSaved, true); + + } + + sizeMeasuresToSave.add(sizeMeasureSaved); + + } + + } + + childSaved.clearSizeMeasure(); + childSaved.addAllSizeMeasure(sizeMeasuresToSave); + + } + + protected void saveWeightMeasures(Collection<WeightMeasure> weightMeasurementsTosave, CatchLongline childSaved) { + + List<WeightMeasure> weightMeasuresToSave = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(weightMeasurementsTosave)) { + + TopiaDAO<WeightMeasure> dao = getDao(WeightMeasure.class); + TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); + + for (WeightMeasure weightMeasureToSave : weightMeasurementsTosave) { + + WeightMeasure weightMeasureSaved; + + if (Entities.isNew(weightMeasureToSave)) { + + weightMeasureSaved = dao.create(); + binder.load(weightMeasureToSave, weightMeasureSaved, false); + + } else { + + weightMeasureSaved = dao.findByTopiaId(weightMeasureToSave.getTopiaId()); + binder.load(weightMeasureToSave, weightMeasureSaved, true); + + } + + weightMeasuresToSave.add(weightMeasureSaved); + + } + + } + + childSaved.clearWeightMeasure(); + childSaved.addAllWeightMeasure(weightMeasuresToSave); + + } + } + + ); } @Override public List<SizeMeasure> getCatchLonglineSizeMeasures(String catchLonglineId) { - TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); - CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); List<SizeMeasure> result = new ArrayList<SizeMeasure>(); - for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { - SizeMeasure target = new SizeMeasureImpl(); - binder.load(sizeSource, target, true); - result.add(target); + if (!catchLongline.isSizeMeasureEmpty()) { + + TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); + TopiaDAO<SizeMeasure> sizeMeasureDao = getDao(SizeMeasure.class); + + for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { + SizeMeasure target = sizeMeasureDao.newInstance(); + binder.load(sizeSource, target, true); + result.add(target); + } } return result; @@ -109,14 +211,19 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements @Override public List<WeightMeasure> getCatchLonglineWeightMeasures(String catchLonglineId) { - TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); - CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); List<WeightMeasure> result = new ArrayList<WeightMeasure>(); - for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { - WeightMeasure target = new WeightMeasureImpl(); - binder.load(weightSource, target, true); - result.add(target); + if (!catchLongline.isWeightMeasureEmpty()) { + + TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); + TopiaDAO<WeightMeasure> weightMeasureDao = getDao(WeightMeasure.class); + + for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { + WeightMeasure target = weightMeasureDao.newInstance(); + binder.load(weightSource, target, true); + result.add(target); + } + } return result; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java index ac74e05..eaaa8ee 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java @@ -27,10 +27,9 @@ public class EncounterServiceImpl extends AbstractObserveService implements Enco ActivityLongline parentLoaded = getDao(ActivityLongline.class).newInstance(); copy(ActivityLongline.class, BinderService.EDIT_ENCOUNTER, parentToLoad, parentLoaded); - TopiaEntityBinder<Encounter> binder = getBinder(Encounter.class, BinderService.EDIT); - if (!parentToLoad.isEncounterEmpty()) { + TopiaEntityBinder<Encounter> binder = getBinder(Encounter.class, BinderService.EDIT); TopiaDAO<Encounter> childDao = getDao(Encounter.class); List<Encounter> childs = new ArrayList<Encounter>(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java index 44a444f..07f8d26 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java @@ -18,6 +18,7 @@ import java.util.List; * @since 4.0 */ public class FloatlinesCompositionServiceImpl extends AbstractObserveService implements FloatlinesCompositionService { + @Override public SetLongline loadForEdit(String setLonglineId) { @@ -26,10 +27,9 @@ public class FloatlinesCompositionServiceImpl extends AbstractObserveService imp SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, parentToLoad, parentLoaded); - TopiaEntityBinder<FloatlinesComposition> binder = getBinder(FloatlinesComposition.class, BinderService.EDIT); - if (!parentToLoad.isFloatlinesCompositionEmpty()) { + TopiaEntityBinder<FloatlinesComposition> binder = getBinder(FloatlinesComposition.class, BinderService.EDIT); TopiaDAO<FloatlinesComposition> childDao = getDao(FloatlinesComposition.class); List<FloatlinesComposition> childs = new ArrayList<FloatlinesComposition>(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index b089a8e..541605d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.longline; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLonglineDAO; @@ -9,12 +10,12 @@ import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections4.CollectionUtils; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** @@ -28,16 +29,22 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(String gearId) { - GearUseFeaturesMeasurementLonglineDAO dao = getDao(); - Gear gear = findByTopiaId(Gear.class, gearId); - Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - for (GearCaracteristic caracteristic : gearCaracteristic) { - GearUseFeaturesMeasurementLongline target = dao.newInstance(); - target.setGearCaracteristic(caracteristic); - result.add(target); + + if (gear.isGearCaracteristicEmpty()) { + + GearUseFeaturesMeasurementLonglineDAO dao = getDao(); + + for (GearCaracteristic caracteristic : gear.getGearCaracteristic()) { + + GearUseFeaturesMeasurementLongline target = dao.newInstance(); + target.setGearCaracteristic(caracteristic); + result.add(target); + + } + } return result; @@ -47,18 +54,23 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public List<GearUseFeaturesMeasurementLongline> loadGearUseFeaturesMeasurementLonglineForEdit(String gearUseFeaturesLonglineId) { - GearUseFeaturesMeasurementLonglineDAO dao = getDao(); - - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - GearUseFeaturesLongline gearUseFeaturesLongline = findByTopiaId(GearUseFeaturesLongline.class, gearUseFeaturesLonglineId); List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { - GearUseFeaturesMeasurementLongline target = dao.newInstance(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); + if (!gearUseFeaturesLongline.isGearUseFeaturesMeasurementEmpty()) { + + GearUseFeaturesMeasurementLonglineDAO dao = getDao(); + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); + + for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { + + GearUseFeaturesMeasurementLongline target = dao.newInstance(); + measurementSource.getGearCaracteristic().getGearCaracteristicType(); + binder.load(measurementSource, target, true); + result.add(target); + + } + } return result; @@ -68,31 +80,53 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public TripLongline loadForEdit(String tripLonglineId) { - TripLongline parentToLoad = findByTopiaId(TripLongline.class, tripLonglineId); + TripLongline toLoad = findByTopiaId(TripLongline.class, tripLonglineId); - TripLongline parentLoaded = getDao(TripLongline.class).newInstance(); - copy(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, parentToLoad, parentLoaded); + TripLongline loaded = getDao(TripLongline.class).newInstance(); + copy(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, toLoad, loaded); - if (!parentToLoad.isGearUseFeaturesLonglineEmpty()) { + if (!toLoad.isGearUseFeaturesLonglineEmpty()) { - TopiaEntityBinder<GearUseFeaturesLongline> binder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); TopiaDAO<GearUseFeaturesLongline> childDao = getDao(GearUseFeaturesLongline.class); + TopiaDAO<GearUseFeaturesMeasurementLongline> measurementDao = getDao(GearUseFeaturesMeasurementLongline.class); + TopiaEntityBinder<GearUseFeaturesLongline> childBinder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> measurementBinder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); + + List<GearUseFeaturesLongline> childsLoaded = new ArrayList<GearUseFeaturesLongline>(); - List<GearUseFeaturesLongline> childs = new ArrayList<GearUseFeaturesLongline>(); + if (!toLoad.isGearUseFeaturesLonglineEmpty()) { - for (GearUseFeaturesLongline sourceChild : parentToLoad.getGearUseFeaturesLongline()) { + for (GearUseFeaturesLongline childToLoad : toLoad.getGearUseFeaturesLongline()) { - GearUseFeaturesLongline targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); + GearUseFeaturesLongline childLoaded = childDao.newInstance(); + childBinder.load(childToLoad, childLoaded, true); + childsLoaded.add(childLoaded); + + if (!childToLoad.isGearUseFeaturesMeasurementEmpty()) { + + List<GearUseFeaturesMeasurementLongline> measurementsLoaded = new ArrayList<GearUseFeaturesMeasurementLongline>(); + + for (GearUseFeaturesMeasurementLongline measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { + + GearUseFeaturesMeasurementLongline measurementLoaded = measurementDao.newInstance(); + measurementBinder.load(measurementToLoad, measurementLoaded, true); + measurementsLoaded.add(measurementLoaded); + + } + + childLoaded.setGearUseFeaturesMeasurement(measurementsLoaded); + + } + + } } - parentLoaded.setGearUseFeaturesLongline(childs); + loaded.setGearUseFeaturesLongline(childsLoaded); } - return parentLoaded; + return loaded; } @@ -109,59 +143,55 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i public GearUseFeaturesLongline onCreateChild(GearUseFeaturesLongline childToCreate) { GearUseFeaturesLongline childCreated = getDao(entityClass).create( - GearUseFeaturesLongline.PROPERTY_GEAR,childToCreate.getGear(), - GearUseFeaturesLongline.PROPERTY_NUMBER,childToCreate.getNumber() + GearUseFeaturesLongline.PROPERTY_GEAR, childToCreate.getGear(), + GearUseFeaturesLongline.PROPERTY_NUMBER, childToCreate.getNumber() ); childBinder.load(childToCreate, childCreated, false); - saveMeasurement(childToCreate, childCreated); + saveMeasurement(childToCreate.getGearUseFeaturesMeasurement(), childCreated); return childCreated; } @Override - public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToSave, GearUseFeaturesLongline childSaved) { - super.onUpdateChild(childToSave, childSaved); - saveMeasurement(childToSave, childSaved); + public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToSave) { + GearUseFeaturesLongline childSaved = super.onUpdateChild(childToSave); + saveMeasurement(childToSave.getGearUseFeaturesMeasurement(), childSaved); return childSaved; } - protected void saveMeasurement(GearUseFeaturesLongline childToSave, GearUseFeaturesLongline childSaved) { - - TopiaDAO<GearUseFeaturesMeasurementLongline> dao = getDao(GearUseFeaturesMeasurementLongline.class); + protected void saveMeasurement(List<GearUseFeaturesMeasurementLongline> measurementsToSave, GearUseFeaturesLongline childSaved) { - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> measurementBinder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); + List<GearUseFeaturesMeasurementLongline> measurementsSaved = Lists.newArrayList(); - List<GearUseFeaturesMeasurementLongline> measurementsNew = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(measurementsToSave)) { - if (!childToSave.isGearUseFeaturesMeasurementEmpty()) { + TopiaDAO<GearUseFeaturesMeasurementLongline> dao = getDao(GearUseFeaturesMeasurementLongline.class); + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - for (GearUseFeaturesMeasurementLongline measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + for (GearUseFeaturesMeasurementLongline measurementToSave : measurementsToSave) { GearUseFeaturesMeasurementLongline measurementSaved; - if (measurementToSave.getTopiaId() == null) { - - measurementSaved = dao.create(GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); + if (Entities.isNew(measurementToSave)) { - measurementBinder.load(measurementToSave, measurementSaved, false); + measurementSaved = dao.create(GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); + binder.load(measurementToSave, measurementSaved, false); } else { measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - - measurementBinder.load(measurementToSave, measurementSaved, true); + binder.load(measurementToSave, measurementSaved, true); } - measurementsNew.add(measurementSaved); + measurementsSaved.add(measurementSaved); } } childSaved.clearGearUseFeaturesMeasurement(); - - childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); + childSaved.addAllGearUseFeaturesMeasurement(measurementsSaved); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java index 0f8fc53..043b3dc 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java @@ -18,6 +18,7 @@ import java.util.List; * @since 4.0 */ public class HooksCompositionServiceImpl extends AbstractObserveService implements HooksCompositionService { + @Override public SetLongline loadForEdit(String setLonglineId) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java index f9891f9..d0b3637 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java @@ -1,7 +1,12 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.entities.longline.SectionWithTemplate; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; +import java.util.List; + /** * Created on 4/26/15. * @@ -9,4 +14,10 @@ import fr.ird.observe.services.ObserveService; * @since 4.0 */ public interface LonglineDetailCompositionService extends ObserveService { + + SetLongline loadForEdit(String setLonglineId); + + @Commit + void save(SetLongline toSave, List<SectionWithTemplate> sections); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java index 63fa0f9..40dd524 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java @@ -1,6 +1,20 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.Entities; +import fr.ird.observe.entities.longline.Basket; +import fr.ird.observe.entities.longline.Branchline; +import fr.ird.observe.entities.longline.Section; +import fr.ird.observe.entities.longline.SectionWithTemplate; +import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * Created on 4/26/15. @@ -10,4 +24,172 @@ import fr.ird.observe.services.AbstractObserveService; */ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService implements LonglineDetailCompositionService { + @Override + public SetLongline loadForEdit(String setLonglineId) { + + TopiaDAO<SetLongline> dao = getDao(SetLongline.class); + SetLongline toLoad = dao.findByTopiaId(setLonglineId); + SetLongline loaded = dao.newInstance(); + copy(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION, toLoad, loaded); + + return loaded; + + } + + @Override + public void save(SetLongline toSave, List<SectionWithTemplate> sections) { + + Map<String, Section> existingSectionsByTopiaId = Entities.toIdMap(toSave.getSection()); + + toSave.clearSection(); + + SetLongline saved = findByTopiaId(SetLongline.class, toSave.getTopiaId()); + + copyExcluding(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION, toSave, saved, SetLongline.PROPERTY_SECTION); + + TopiaDAO<Section> sectionsDao = getDao(Section.class); + TopiaDAO<Basket> basketDao = getDao(Basket.class); + TopiaDAO<Branchline> branchlineDao = getDao(Branchline.class); + + TopiaEntityBinder<Section> sectionBinder = getBinder(Section.class, BinderService.EDIT_DETAIL_COMPOSITION); + TopiaEntityBinder<Basket> basketBinder = getBinder(Basket.class, BinderService.EDIT_DETAIL_COMPOSITION); + TopiaEntityBinder<Branchline> branchlineBinder = getBinder(Branchline.class, BinderService.EDIT_DETAIL_COMPOSITION); + + List<Section> sectionsToSave = new ArrayList<Section>(); + + for (SectionWithTemplate section : sections) { + + Section sectionToSave = persistSection(sectionBinder, + basketBinder, + branchlineBinder, + sectionsDao, + basketDao, + branchlineDao, + existingSectionsByTopiaId, + section); + sectionsToSave.add(sectionToSave); + sectionToSave.setSetLongline(saved); + + } + + saved.clearSection(); + saved.addAllSection(sectionsToSave); + + } + + protected Section persistSection(TopiaEntityBinder<Section> sectionBinder, + TopiaEntityBinder<Basket> basketBinder, + TopiaEntityBinder<Branchline> branchlineBinder, + TopiaDAO<Section> sectionsDao, + TopiaDAO<Basket> basketDao, + TopiaDAO<Branchline> branchlineDao, + Map<String, Section> existingSectionsByTopiaId, + Section section) throws TopiaException { + + Section sectionToSave; + + if (section.getTopiaId() == null) { + + // create + sectionToSave = sectionsDao.create( + Section.PROPERTY_SETTING_IDENTIFIER, section.getSettingIdentifier(), + Section.PROPERTY_HAULING_IDENTIFIER, section.getHaulingIdentifier()); + + } else { + + sectionToSave = existingSectionsByTopiaId.get(section.getTopiaId()); + + } + + sectionBinder.copyExcluding(section, sectionToSave, Section.PROPERTY_BASKET); + + Map<String, Basket> existingBasketsByTopiaId = Entities.toIdMap(sectionToSave.getBasket()); + + List<Basket> baskets = section.getBasket(); + sectionToSave.clearBasket(); + + for (Basket basket : baskets) { + + Basket basketToSave = persistBasket(basketBinder, + branchlineBinder, + basketDao, + branchlineDao, + existingBasketsByTopiaId, + basket); + sectionToSave.addBasket(basketToSave); + + } + + return sectionToSave; + + } + + protected Basket persistBasket(TopiaEntityBinder<Basket> basketBinder, + TopiaEntityBinder<Branchline> branchlineBinder, + TopiaDAO<Basket> basketDao, + TopiaDAO<Branchline> branchlineDao, + Map<String, Basket> existingBasketsByTopiaId, + Basket basket) throws TopiaException { + + Basket basketToSave; + + if (basket.getTopiaId() == null) { + + // create + basketToSave = basketDao.create( + Basket.PROPERTY_SETTING_IDENTIFIER, basket.getSettingIdentifier(), + Basket.PROPERTY_HAULING_IDENTIFIER, basket.getHaulingIdentifier()); + + } else { + + basketToSave = existingBasketsByTopiaId.get(basket.getTopiaId()); + + } + + basketBinder.copyExcluding(basket, basketToSave, Basket.PROPERTY_BRANCHLINE); + + Map<String, Branchline> existingBranchlinesByTopiaId = Entities.toIdMap(basketToSave.getBranchline()); + + basketToSave.clearBranchline(); + + List<Branchline> branchlines = basket.getBranchline(); + + for (Branchline branchline : branchlines) { + + Branchline branchlineToSave = persistBranchline(branchlineBinder, + branchlineDao, existingBranchlinesByTopiaId, branchline); + basketToSave.addBranchline(branchlineToSave); + + } + + return basketToSave; + + } + + protected Branchline persistBranchline(TopiaEntityBinder<Branchline> branchlineBinder, + TopiaDAO<Branchline> branchlineDao, + Map<String, Branchline> existingBranchlinesByTopiaId, + Branchline branchline) throws TopiaException { + + Branchline branchlineToSave; + + if (branchline.getTopiaId() == null) { + + // create + branchlineToSave = branchlineDao.create( + Branchline.PROPERTY_SETTING_IDENTIFIER, branchline.getSettingIdentifier(), + Branchline.PROPERTY_HAULING_IDENTIFIER, branchline.getHaulingIdentifier()); + + } else { + + branchlineToSave = existingBranchlinesByTopiaId.get(branchline.getTopiaId()); + + } + + branchlineBinder.copy(branchline, branchlineToSave); + + return branchlineToSave; + + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java index 41fe50e..9c245c2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java @@ -9,7 +9,8 @@ import fr.ird.observe.services.ObserveService; */ public interface LonglineGlobalCompositionService extends ObserveService{ + SetLongline loadForEdit(String setLonglineId); + @Commit String save(SetLongline bean); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java index 2ffef64..9e5060f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java @@ -4,29 +4,53 @@ import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.referentiel.longline.MitigationType; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; + +import java.util.ArrayList; +import java.util.Collection; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com + * @since 4.0 */ public class LonglineGlobalCompositionServiceImpl extends AbstractObserveService implements LonglineGlobalCompositionService { @Override + public SetLongline loadForEdit(String setLonglineId) { + + TopiaDAO<SetLongline> dao = getDao(SetLongline.class); + SetLongline toLoad = dao.findByTopiaId(setLonglineId); + SetLongline loaded = dao.newInstance(); + copy(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION, toLoad, loaded); + + return loaded; + + } + + @Override public String save(SetLongline toSave) { SetLongline saved = findByTopiaId(SetLongline.class, toSave.getTopiaId()); copyExcluding(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION, toSave, saved, SetLongline.PROPERTY_MITIGATION_TYPE); - saved.clearMitigationType(); + Collection<MitigationType> mitigationTypesSaved = new ArrayList<MitigationType>(); + + if (!toSave.isMitigationTypeEmpty()) { - for (MitigationType mitigationTypeToSave : toSave.getMitigationType()) { + TopiaDAO<MitigationType> dao = getDao(MitigationType.class); - MitigationType mitigationTypeSaved = findByTopiaId(MitigationType.class, mitigationTypeToSave.getTopiaId()); + for (MitigationType mitigationTypeToSave : toSave.getMitigationType()) { - saved.addMitigationType(mitigationTypeSaved); + MitigationType mitigationTypeSaved = dao.findByTopiaId(mitigationTypeToSave.getTopiaId()); + mitigationTypesSaved.add(mitigationTypeSaved); + } } + saved.clearMitigationType(); + saved.addAllMitigationType(mitigationTypesSaved); + getDao(SetLongline.class).update(saved); newService(FloatlinesCompositionService.class).save(toSave); @@ -36,4 +60,5 @@ public class LonglineGlobalCompositionServiceImpl extends AbstractObserveService return saved.getTopiaId(); } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java index 170fd5b..d10093c 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java @@ -62,7 +62,6 @@ public class SensorUsedServiceImpl extends AbstractObserveService implements Sen ActivityLongline parentLoaded = getDao(ActivityLongline.class).newInstance(); copy(ActivityLongline.class, BinderService.EDIT_SENSOR_USED, parentToLoad, parentLoaded); - if (!parentToLoad.isSensorUsedEmpty()) { TopiaEntityBinder<SensorUsed> binder = getBinder(SensorUsed.class, BinderService.EDIT); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java index 5253955..89c8324 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; import java.util.List; @@ -18,6 +19,14 @@ public interface SetLonglineService extends ObserveService { List<Section> getSections(String setLonglineId); - String save(String activityId, SetLongline bean); + SetLongline preCreate(String activityLonglineId); + + SetLongline loadForEdit(String setLonglineId); + + @Commit + String save(String activityLonglineId, SetLongline setLongline); + + @Commit + void delete(String activityLonglineId, String setLonglineId); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index 7c44be2..793e631 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -8,9 +8,11 @@ import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SetLonglineDAO; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.lang3.time.DateUtils; import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDAO; +import java.util.Date; import java.util.List; /** @@ -67,8 +69,43 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se } @Override - public String save(String activityLonglineId, SetLongline toSave) { - String setLonglineId = doSave(activityLonglineId, toSave, new SaveAction<ActivityLongline, SetLongline>(ActivityLongline.class, SetLongline.class) { + public SetLongline preCreate(String activityLonglineId) { + + ActivityLongline activityLongline = findByTopiaId(ActivityLongline.class, activityLonglineId); + + SetLongline preCreated = getDao().newInstance(); + + // on utilise la date - heure de l'activité pour initialiser les horodatages + // de l'opération de peche + Date timeStamp = activityLongline.getTimeStamp(); + preCreated.setSettingStartTimeStamp(timeStamp); + preCreated.setSettingEndTimeStamp(DateUtils.addHours(timeStamp, 1)); + preCreated.setHaulingStartTimeStamp(DateUtils.addHours(timeStamp, 2)); + preCreated.setHaulingEndTimeStamp(DateUtils.addHours(timeStamp, 3)); + + // on reporte la position de l'activité pour la position de début de filage + Float latitude = activityLongline.getLatitude(); + Float longitude = activityLongline.getLongitude(); + + // On enregistre deux fois les coordonnées car la première fois on perd le signe à cause de l'éditeur + preCreated.setSettingStartLatitude(latitude); + preCreated.setSettingStartLongitude(longitude); + preCreated.setSettingStartLatitude(latitude); + preCreated.setSettingStartLongitude(longitude); + + return preCreated; + + } + + @Override + public SetLongline loadForEdit(String setLonglineId) { + return null; + } + + @Override + public String save(String activityLonglineId, SetLongline setLongline) { + + String setLonglineId = doSave(activityLonglineId, setLongline, new SaveAction<ActivityLongline, SetLongline>(ActivityLongline.class, SetLongline.class) { @Override public SetLongline onCreate(ActivityLongline parent, SetLongline toCreate) { @@ -102,6 +139,21 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se return setLonglineId; } + @Override + public void delete(String activityLonglineId, String setLonglineId) { + + // on doit supprimer physiquement la set + // car il n'y a pas de delete-orphan sur une telle relation + SetLonglineDAO dao = getDao(); + SetLongline setsetLongline = dao.findByTopiaId(setLonglineId); + dao.delete(setsetLongline); + + // supprime la reference sur l'activite + ActivityLongline activitySeine = findByTopiaId(ActivityLongline.class, activityLonglineId); + activitySeine.setSetLongline(null); + + } + protected SetLonglineDAO getDao() { return (SetLonglineDAO) getDao(SetLongline.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java index b650614..e59f6d6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java @@ -60,7 +60,6 @@ public class TdrServiceImpl extends AbstractObserveService implements TdrService SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); copy(SetLongline.class, BinderService.EDIT_TDR, parentToLoad, parentLoaded); - if (!parentToLoad.isTdrEmpty()) { TopiaEntityBinder<Tdr> binder = getBinder(Tdr.class, BinderService.EDIT); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java index 2ded71e..212b8d1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -20,8 +18,6 @@ public interface ActivitySeineService extends ObserveService { List<ActivitySeine> getActivitySeineStubByRoute(String routeId); - ActivitySeine loadForDisplay(String activitySeineId); - ActivitySeine loadForEdit(String activitySeineId); ActivitySeine loadForEditObservedSystem(String activitySeineId); @@ -37,15 +33,4 @@ public interface ActivitySeineService extends ObserveService { @Commit void delete(String routeId, String activitySeineId); - @NoTransaction - TopiaEntityBinder<ActivitySeine> getBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<ActivitySeine> getBinderForEditObservedSystem() ; - - @NoTransaction - void copyForEdit(ActivitySeine source, ActivitySeine target); - - @NoTransaction - void copyForEditObservedSystem(ActivitySeine source, ActivitySeine target); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 860cc3e..6dfb81e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -9,10 +9,7 @@ import fr.ird.observe.entities.seine.ActivitySeineDAO; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Date; import java.util.List; @@ -44,20 +41,11 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } @Override - public ActivitySeine loadForDisplay(String activitySeineId) { + public ActivitySeine loadForEdit(String activitySeineId) { ActivitySeine loaded = getDao().newInstance(); ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); - copyForEdit(toLoad, loaded); - - return loaded; - - } - - @Override - public ActivitySeine loadForEdit(String activitySeineId) { - - ActivitySeine loaded = loadForDisplay(activitySeineId); + copy(ActivitySeine.class, BinderService.EDIT, toLoad, loaded); return loaded; } @@ -67,8 +55,9 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); ActivitySeine loaded = getDao().newInstance(); - //TODO + copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, toLoad, loaded); return loaded; + } @Override @@ -139,7 +128,8 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); - getBinderForEditObservedSystem().copyExcluding(toUpdate, updated, ActivitySeine.PROPERTY_SET_SEINE); + + copyExcluding(ActivitySeine.class, BinderService.EDIT, toUpdate, updated, true, ActivitySeine.PROPERTY_SET_SEINE); if (needUpdateSet) { @@ -154,13 +144,14 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements @Override public String save(String routeId, ActivitySeine toSave) { + String activitySeineId = doSave(routeId, toSave, new SaveAction<Route, ActivitySeine>(Route.class, ActivitySeine.class) { @Override public ActivitySeine onCreate(Route parent, ActivitySeine toCreate) { ActivitySeine created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(ActivitySeine.class, BinderService.EDIT, toCreate, created, false); parent.addActivitySeine(created); return created; @@ -172,9 +163,8 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements toUpdate.setTime(d); - getBinderForEdit().copyExcluding(toUpdate, updated, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_FLOATING_OBJECT); + copyExcluding(ActivitySeine.class, BinderService.EDIT, toUpdate, updated, true, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, ActivitySeine.PROPERTY_FLOATING_OBJECT); return updated; } @@ -197,91 +187,6 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } - @Override - public TopiaEntityBinder<ActivitySeine> getBinderForEditObservedSystem() { - - TopiaEntityBinder<ActivitySeine> binder = loadBinder("-forEditObservedSystem", ActivitySeine.class, new CreateBinder<ActivitySeine>() { - - @Override - public BinderModelBuilder<ActivitySeine, ActivitySeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_SET_SEINE, - ActivitySeine.PROPERTY_COMMENT, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public TopiaEntityBinder<ActivitySeine> getBinderForEdit() { - - TopiaEntityBinder<ActivitySeine> binder = loadBinder("-forEdit", ActivitySeine.class, new CreateBinder<ActivitySeine>() { - - @Override - public BinderModelBuilder<ActivitySeine, ActivitySeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_QUADRANT, - ActivitySeine.PROPERTY_LATITUDE, - ActivitySeine.PROPERTY_LONGITUDE, - ActivitySeine.PROPERTY_ERS_ID, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, - ActivitySeine.PROPERTY_COMMENT, - ActivitySeine.PROPERTY_VESSEL_SPEED, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, - ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_DETECTION_MODE, - ActivitySeine.PROPERTY_SET_SEINE, - ActivitySeine.PROPERTY_FLOATING_OBJECT, - ActivitySeine.PROPERTY_OPEN, - ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, - ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, - ActivitySeine.PROPERTY_NEXT_FPA_ZONE); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(ActivitySeine source, ActivitySeine target) { - - getBinderForEdit().load(source, target, true); - - } - - @Override - public void copyForEditObservedSystem(ActivitySeine source, ActivitySeine target) { - - getBinderForEditObservedSystem().load(source, target, true); - - } - protected ActivitySeineDAO getDao() { return (ActivitySeineDAO) getDao(ActivitySeine.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java index c9dec98..c4c6ba2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java @@ -1,11 +1,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.TransmittingBuoy; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -36,22 +33,4 @@ public interface FloatingObjectService extends ObserveService { @Commit void delete(String activitySeineId, String floatingObjectId); - @NoTransaction - TopiaEntityBinder<FloatingObject> getBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<FloatingObject> getBinderForEditTransmittingBuoyOperation(); - - @NoTransaction - TopiaEntityBinder<TransmittingBuoy> getBinderForEditTransmittingBuoy(); - - @NoTransaction - void copyForEdit(FloatingObject source, FloatingObject target); - - @NoTransaction - void copyForEditTransmittingBuoyOperation(FloatingObject source, FloatingObject target); - - @NoTransaction - void copyForEditTransmittingBuoy(TransmittingBuoy source, TransmittingBuoy target); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index f4e9fa4..7d937af 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -1,16 +1,21 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.Country; +import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation; +import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.FloatingObjectDAO; import fr.ird.observe.entities.seine.TransmittingBuoy; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.util.beans.BinderModelBuilder; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -43,9 +48,11 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject loadForEdit(String floatingObjectId) { - FloatingObject loaded = getDao().newInstance(); - FloatingObject toLoad = getDao().findByTopiaId(floatingObjectId); - copyForEdit(toLoad, loaded); + FloatingObjectDAO dao = getDao(); + + FloatingObject loaded = dao.newInstance(); + FloatingObject toLoad = dao.findByTopiaId(floatingObjectId); + copy(FloatingObject.class, BinderService.EDIT, toLoad, loaded, true); return loaded; @@ -54,10 +61,37 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject loadForEditTransmittingBuoyOperation(String floatingObjectId) { - FloatingObject loaded = getDao().newInstance(); - FloatingObject toLoad = getDao().findByTopiaId(floatingObjectId); - copyForEditTransmittingBuoyOperation(toLoad, loaded); + FloatingObjectDAO dao = getDao(); + + FloatingObject loaded = dao.newInstance(); + FloatingObject toLoad = dao.findByTopiaId(floatingObjectId); + + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, toLoad, loaded); + + if (!toLoad.isTransmittingBuoyEmpty()) { + Decorator<Country> countryDecorator = getDecoratorByType(Country.class, null); + Decorator<TransmittingBuoyOperation> transmittingBuoyOperationDecorator = getDecoratorByType(TransmittingBuoyOperation.class, null); + Decorator<TransmittingBuoyType> transmittingBuoyTypeDecorator = getDecoratorByType(TransmittingBuoyType.class, null); + + TopiaEntityBinder<TransmittingBuoy> binder = getBinder(TransmittingBuoy.class, BinderService.EDIT); + TopiaDAO<TransmittingBuoy> transmittingBuoyDao = getDao(TransmittingBuoy.class); + List<TransmittingBuoy> transmittingBuoys = new ArrayList<TransmittingBuoy>(); + for (TransmittingBuoy transmittingBuoyToLoad : toLoad.getTransmittingBuoy()) { + + transmittingBuoyOperationDecorator.toString(transmittingBuoyToLoad.getTransmittingBuoyOperation()); + transmittingBuoyTypeDecorator.toString(transmittingBuoyToLoad.getTransmittingBuoyType()); + countryDecorator.toString(transmittingBuoyToLoad.getCountry()); + + TransmittingBuoy transmittingBuoyLoaded = transmittingBuoyDao.newInstance(); + binder.load(transmittingBuoyToLoad, transmittingBuoyLoaded, true); + transmittingBuoys.add(transmittingBuoyLoaded); + + } + + loaded.setTransmittingBuoy(transmittingBuoys); + + } return loaded; } @@ -79,8 +113,7 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements public FloatingObject onCreate(ActivitySeine parent, FloatingObject toCreate) { FloatingObject created = getDao().create(); - getBinderForEdit().copy(toCreate, created); - + copy(FloatingObject.class, BinderService.EDIT, toCreate, created, false); parent.addFloatingObject(created); return created; @@ -89,7 +122,8 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject onUpdate(ActivitySeine parent, FloatingObject toUpdate, FloatingObject updated) { - copyForEdit(toUpdate, updated); + + copy(FloatingObject.class, BinderService.EDIT, toUpdate, updated, true); return updated; } }); @@ -105,33 +139,35 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements updated.setComment(toUpdate.getComment()); updated.clearTransmittingBuoy(); - TopiaEntityBinder<TransmittingBuoy> childLoador = getBinderForEditTransmittingBuoy(); + if (!toUpdate.isTransmittingBuoyEmpty()) { - TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = getDao(TransmittingBuoy.class); + TopiaEntityBinder<TransmittingBuoy> binder = getBinder(TransmittingBuoy.class, BinderService.EDIT); + TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = getDao(TransmittingBuoy.class); - for (TransmittingBuoy transmittingBuoy : toUpdate.getTransmittingBuoy()) { + for (TransmittingBuoy transmittingBuoy : toUpdate.getTransmittingBuoy()) { - TransmittingBuoy newTransmittingBuoy; + TransmittingBuoy newTransmittingBuoy; - if (transmittingBuoy.getTopiaId() == null) { + if (Entities.isNew(transmittingBuoy)) { - // creation de la balise + // creation de la balise + Map<String, Object> map = binder.obtainProperties(transmittingBuoy); + newTransmittingBuoy = transmittingBuoyDAO.create(map); - Map<String, Object> map = childLoador.obtainProperties(transmittingBuoy); - newTransmittingBuoy = transmittingBuoyDAO.create(map); + } else { - } else { + // mise a jour de la balise - // mise a jour de la balise + newTransmittingBuoy = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); + binder.load(transmittingBuoy, newTransmittingBuoy, true); - newTransmittingBuoy = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); - childLoador.load(transmittingBuoy, newTransmittingBuoy, false); + } - } - - updated.addTransmittingBuoy(newTransmittingBuoy); + updated.addTransmittingBuoy(newTransmittingBuoy); + } } + return updated; } @@ -147,113 +183,6 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements } - @Override - public TopiaEntityBinder<FloatingObject> getBinderForEdit() { - - TopiaEntityBinder<FloatingObject> binder = loadBinder("-forEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { - - @Override - public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_OBJECT_TYPE, - FloatingObject.PROPERTY_OBJECT_FATE, - FloatingObject.PROPERTY_OBJECT_OPERATION, - FloatingObject.PROPERTY_COMMENT, - FloatingObject.PROPERTY_SUPPORT_VESSEL_NAME, - FloatingObject.PROPERTY_DAYS_AT_SEA_COUNT); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(FloatingObject source, FloatingObject target) { - - getBinderForEdit().load(source, target, true); - - } - - @Override - public TopiaEntityBinder<FloatingObject> getBinderForEditTransmittingBuoyOperation() { - - TopiaEntityBinder<FloatingObject> binder = loadBinder("-forEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { - - @Override - public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_COMMENT, - FloatingObject.PROPERTY_OBJECT_OPERATION - ); - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEditTransmittingBuoyOperation(FloatingObject source, FloatingObject target) { - - getBinderForEditTransmittingBuoyOperation().load(source, target, true); - - } - - @Override - public TopiaEntityBinder<TransmittingBuoy> getBinderForEditTransmittingBuoy() { - - TopiaEntityBinder<TransmittingBuoy> binder = loadBinder("-forEdit", TransmittingBuoy.class, new CreateBinder<TransmittingBuoy>() { - - @Override - public BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = binderService.newBinderBuilder( - TransmittingBuoy.class, - TransmittingBuoy.PROPERTY_CODE, - TransmittingBuoy.PROPERTY_OWNERSHIP, - TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, - TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, - TransmittingBuoy.PROPERTY_BRAND, - TransmittingBuoy.PROPERTY_COUNTRY); - - return builder; - - } - - @Override - public TopiaEntityBinder<TransmittingBuoy> registerTopiaBinder(BinderService binderService, Class<TransmittingBuoy> entityType, BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder, String name) { - - TopiaEntityBinder<TransmittingBuoy> binder = super.registerTopiaBinder(binderService, entityType, builder, name); - binder.setEmpty(getDao(TransmittingBuoy.class).newInstance()); - return binder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEditTransmittingBuoy(TransmittingBuoy source, TransmittingBuoy target) { - - getBinderForEditTransmittingBuoy().load(source, target, true); - - } - protected FloatingObjectDAO getDao() { return (FloatingObjectDAO) getDao(FloatingObject.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java index 3e42f29..28c9636 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java @@ -1,12 +1,9 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; -import fr.ird.observe.entities.seine.GearUseFeaturesSeine; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; import java.util.List; @@ -27,7 +24,4 @@ public interface GearUseFeaturesSeineService extends ObserveService { @Commit void save(TripSeine parent); - @NoTransaction - EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index 1f61015..49d0f1c 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.seine; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; @@ -9,12 +10,12 @@ import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineDAO; import fr.ird.observe.entities.seine.GearUseFeaturesSeine; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections4.CollectionUtils; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** @@ -28,15 +29,22 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(String gearId) { - GearUseFeaturesMeasurementSeineDAO dao = getDao(); Gear gear = findByTopiaId(Gear.class, gearId); - Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - for (GearCaracteristic caracteristic : gearCaracteristic) { - GearUseFeaturesMeasurementSeine target = dao.newInstance(); - target.setGearCaracteristic(caracteristic); - result.add(target); + + if (!gear.isGearCaracteristicEmpty()) { + + GearUseFeaturesMeasurementSeineDAO dao = getDao(); + + for (GearCaracteristic caracteristic : gear.getGearCaracteristic()) { + + GearUseFeaturesMeasurementSeine target = dao.newInstance(); + target.setGearCaracteristic(caracteristic); + result.add(target); + + } + } return result; @@ -46,17 +54,23 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public List<GearUseFeaturesMeasurementSeine> loadGearUseFeaturesMeasurementSeineForEdit(String gearUseFeaturesSeineId) { - GearUseFeaturesMeasurementSeineDAO dao = getDao(); - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - GearUseFeaturesSeine gearUseFeaturesSeine = findByTopiaId(GearUseFeaturesSeine.class, gearUseFeaturesSeineId); List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { - GearUseFeaturesMeasurementSeine target = dao.newInstance(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); + if (!gearUseFeaturesSeine.isGearUseFeaturesMeasurementEmpty()) { + + GearUseFeaturesMeasurementSeineDAO dao = getDao(); + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); + + for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { + + GearUseFeaturesMeasurementSeine target = dao.newInstance(); + measurementSource.getGearCaracteristic().getGearCaracteristicType(); + binder.load(measurementSource, target, true); + result.add(target); + + } + } return result; @@ -65,31 +79,50 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public TripSeine loadForEdit(String tripId) { - TripSeine toLoad = findByTopiaId(TripSeine.class, tripId); - TripSeine loaded = getDao(TripSeine.class).newInstance(); + TopiaDAO<TripSeine> dao = getDao(TripSeine.class); + TripSeine toLoad = dao.findByTopiaId(tripId); + + TripSeine loaded = dao.newInstance(); if (toLoad != null) { copyExcluding(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE, toLoad, loaded, TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); - for (GearUseFeaturesSeine childToLoad : toLoad.getGearUseFeaturesSeine()) { + if (!toLoad.isGearUseFeaturesSeineEmpty()) { - GearUseFeaturesSeine childLoaded = getDao(GearUseFeaturesSeine.class).newInstance(); + TopiaDAO<GearUseFeaturesSeine> childDao = getDao(GearUseFeaturesSeine.class); + TopiaDAO<GearUseFeaturesMeasurementSeine> measurementDao = getDao(GearUseFeaturesMeasurementSeine.class); + TopiaEntityBinder<GearUseFeaturesSeine> childBinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> measurementBinder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); + + List<GearUseFeaturesSeine> childsLoaded = new ArrayList<GearUseFeaturesSeine>(); + + for (GearUseFeaturesSeine childToLoad : toLoad.getGearUseFeaturesSeine()) { + + GearUseFeaturesSeine childLoaded = childDao.newInstance(); + childBinder.load(childToLoad, childLoaded, true); + childsLoaded.add(childLoaded); - copy(GearUseFeaturesSeine.class, BinderService.EDIT, childToLoad, childLoaded); + if (!childToLoad.isGearUseFeaturesMeasurementEmpty()) { - for (GearUseFeaturesMeasurementSeine measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { + List<GearUseFeaturesMeasurementSeine> measurementsLoaded = new ArrayList<GearUseFeaturesMeasurementSeine>(); - GearUseFeaturesMeasurementSeine measurementLoaded = getDao(GearUseFeaturesMeasurementSeine.class).newInstance(); + for (GearUseFeaturesMeasurementSeine measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { - copy(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT, measurementToLoad, measurementLoaded); + GearUseFeaturesMeasurementSeine measurementLoaded = measurementDao.newInstance(); + measurementBinder.load(measurementToLoad, measurementLoaded, true); + measurementsLoaded.add(measurementLoaded); - childLoaded.addGearUseFeaturesMeasurement(measurementLoaded); + } + + childLoaded.setGearUseFeaturesMeasurement(measurementsLoaded); + + } } - loaded.addGearUseFeaturesSeine(childLoaded); + loaded.setGearUseFeaturesSeine(childsLoaded); } @@ -100,11 +133,12 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public void save(TripSeine parent) { + TopiaEntityBinder<TripSeine> parentBinder = getBinder(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE); - TopiaEntityBinder<GearUseFeaturesSeine> childbinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); + TopiaEntityBinder<GearUseFeaturesSeine> childBinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); doSaveList(parent, new SaveCollectionAction<TripSeine, GearUseFeaturesSeine>( - TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childbinder) { + TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childBinder) { @Override public GearUseFeaturesSeine onCreateChild(GearUseFeaturesSeine childToCreate) { @@ -112,62 +146,57 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl GearUseFeaturesSeine.PROPERTY_GEAR, childToCreate.getGear(), GearUseFeaturesSeine.PROPERTY_NUMBER, childToCreate.getNumber()); childBinder.load(childToCreate, childCreated, false); - saveMeasurement(childToCreate, childCreated); + saveMeasurement(childToCreate.getGearUseFeaturesMeasurement(), childCreated); return childCreated; } @Override - public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToSave, GearUseFeaturesSeine childSaved) { - super.onUpdateChild(childToSave, childSaved); - saveMeasurement(childToSave, childSaved); + public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToSave) { + GearUseFeaturesSeine childSaved = super.onUpdateChild(childToSave); + saveMeasurement(childToSave.getGearUseFeaturesMeasurement(), childSaved); return childSaved; } - protected void saveMeasurement(GearUseFeaturesSeine childToSave, GearUseFeaturesSeine childSaved) { - - TopiaDAO<GearUseFeaturesMeasurementSeine> dao = getDao(GearUseFeaturesMeasurementSeine.class); + protected void saveMeasurement(List<GearUseFeaturesMeasurementSeine> measurementsToSave, GearUseFeaturesSeine childSaved) { - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> measurementBinder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); + List<GearUseFeaturesMeasurementSeine> measurementsSaved = Lists.newArrayList(); - List<GearUseFeaturesMeasurementSeine> measurementsNew = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(measurementsToSave)) { - if (!childToSave.isGearUseFeaturesMeasurementEmpty()) { + TopiaDAO<GearUseFeaturesMeasurementSeine> dao = getDao(GearUseFeaturesMeasurementSeine.class); + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - for (GearUseFeaturesMeasurementSeine measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + for (GearUseFeaturesMeasurementSeine measurementToSave : measurementsToSave) { GearUseFeaturesMeasurementSeine measurementSaved; - if (measurementToSave.getTopiaId() == null) { + if (Entities.isNew(measurementToSave)) { measurementSaved = dao.create(GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); - - measurementBinder.load(measurementToSave, measurementSaved, false); + binder.load(measurementToSave, measurementSaved, false); } else { measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - - measurementBinder.load(measurementToSave, measurementSaved, true); + binder.load(measurementToSave, measurementSaved, true); } - measurementsNew.add(measurementSaved); + measurementsSaved.add(measurementSaved); } } childSaved.clearGearUseFeaturesMeasurement(); - - childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); + childSaved.addAllGearUseFeaturesMeasurement(measurementsSaved); } }); } - @Override - public EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator() { + protected EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator() { return EntityListUpdator.newEntityListUpdator( TripSeine.class, GearUseFeaturesSeine.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java index f83dbd8..a92d6b4 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java @@ -1,12 +1,9 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; import java.util.List; @@ -20,7 +17,4 @@ public interface NonTargetCatchService extends ObserveService { @Commit void save(SetSeine parent, List<NonTargetLength> tailleToDelete); - @NoTransaction - EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java index 91bf7d2..c7a6139 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java @@ -6,9 +6,11 @@ import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -33,14 +35,18 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements copyExcluding(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH, toLoad, loaded, SetSeine.PROPERTY_NON_TARGET_CATCH); - for (NonTargetCatch childToLoad : toLoad.getNonTargetCatch()) { + if (!toLoad.isNonTargetCatchEmpty()) { - NonTargetCatch childLoaded = getDao(NonTargetCatch.class).newInstance(); + TopiaDAO<NonTargetCatch> dao = getDao(NonTargetCatch.class); + TopiaEntityBinder<NonTargetCatch> binder = getBinder(NonTargetCatch.class, BinderService.EDIT); - copy(NonTargetCatch.class, BinderService.EDIT, childToLoad, childLoaded); + for (NonTargetCatch childToLoad : toLoad.getNonTargetCatch()) { - loaded.addNonTargetCatch(childLoaded); + NonTargetCatch childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addNonTargetCatch(childLoaded); + } } } @@ -75,27 +81,26 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements @Override public void onUpdateFinalize(SetSeine parent, Collection<NonTargetCatch> oldChilds) throws TopiaException { - if (tailleToDelete != null && !tailleToDelete.isEmpty()) { + if (CollectionUtils.isNotEmpty(tailleToDelete)) { // on a demande la suppression de taille obsoletes if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + - " obsolete nonTargetSample(s)."); + log.info("Will remove " + tailleToDelete.size() + " obsolete nonTargetSample(s)."); } NonTargetSample echantillon = parent.getNonTargetSample().get(0); // on supprime les echantillons obsoletes echantillon.getNonTargetLength().removeAll(tailleToDelete); + } } }); } - @Override - public EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator() { + protected EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator() { return EntityListUpdator.newEntityListUpdator( SetSeine.class, NonTargetCatch.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java index c52635d..1423c61 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java @@ -1,11 +1,8 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com @@ -17,7 +14,4 @@ public interface NonTargetLengthService extends ObserveService { @Commit void save(NonTargetSample parent); - @NoTransaction - EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java index 2e068b6..a70b69e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -20,7 +21,7 @@ public class NonTargetLengthServiceImpl extends AbstractObserveService implement SetSeine setSeine = findByTopiaId(SetSeine.class, setId); - NonTargetSample toLoad = null; + NonTargetSample toLoad; if (setSeine.isNonTargetSampleEmpty()) { @@ -39,14 +40,18 @@ public class NonTargetLengthServiceImpl extends AbstractObserveService implement copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { + if (!toLoad.isNonTargetLengthEmpty()) { - NonTargetLength childLoaded = getDao(NonTargetLength.class).newInstance(); + TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); + TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); - copy(NonTargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { - loaded.addNonTargetLength(childLoaded); + NonTargetLength childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addNonTargetLength(childLoaded); + } } } @@ -63,8 +68,7 @@ public class NonTargetLengthServiceImpl extends AbstractObserveService implement NonTargetSample.class, NonTargetLength.class, getListUpdator(), parentBinder, childbinder)); } - @Override - public EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator() { + protected EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator() { return EntityListUpdator.newEntityListUpdator( NonTargetSample.class, NonTargetLength.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index 06eeb03..b453188 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -10,6 +10,8 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.Collection; @@ -79,14 +81,18 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { + if (!toLoad.isNonTargetLengthEmpty()) { - NonTargetLength childLoaded = getDao(NonTargetLength.class).newInstance(); + TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); + TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); - copy(NonTargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { - loaded.addNonTargetLength(childLoaded); + NonTargetLength childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addNonTargetLength(childLoaded); + } } } @@ -138,36 +144,29 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public void delete(String setId, NonTargetSample bean) { - doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { - @Override - public void onDelete(SetSeine parent, NonTargetSample toDelete) { - super.onDelete(parent, toDelete); - parent.removeNonTargetSample(toDelete); - } - }); - - } - - @Override public String save(String setSeineId, NonTargetSample toSave) { String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { @Override public NonTargetSample onCreate(SetSeine parent, NonTargetSample toCreate) { - NonTargetSample created = getDao().create(); + NonTargetSampleDAO dao = getDao(); + + NonTargetSample created = dao.create(); copyExcluding(NonTargetSample.class, BinderService.EDIT, toCreate, created, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); parent.addNonTargetSample(created); - getDao().update(created); + dao.update(created); return created; + } @Override public NonTargetSample onUpdate(SetSeine parentBean, NonTargetSample toSave, NonTargetSample beanToSave) { + copyExcluding(NonTargetSample.class, BinderService.EDIT, toSave, beanToSave, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); getDao().update(beanToSave); return beanToSave; + } }); @@ -175,4 +174,18 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } + @Override + public void delete(String setId, NonTargetSample bean) { + doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + @Override + public void onDelete(SetSeine parent, NonTargetSample toDelete) { + + super.onDelete(parent, toDelete); + parent.removeNonTargetSample(toDelete); + + } + }); + + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java index 2bd726a..f83bcfe 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java @@ -1,10 +1,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * Created on 4/28/15. @@ -19,5 +17,4 @@ public interface ObjectObservedSpeciesService extends ObserveService { @Commit void save(FloatingObject floatingObject); - EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator(); } \ No newline at end of file diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java index 5f8e84f..bd4b6f2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java @@ -15,6 +15,7 @@ import java.util.List; * @author Sylvain Bavencoff - bavencoff@codelutin.com */ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService implements ObjectObservedSpeciesService { + @Override public FloatingObject loadForEdit(String floatingObjectId) { @@ -27,13 +28,13 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp if (!parentToLoad.isObjectObservedSpeciesEmpty()) { TopiaDAO<ObjectObservedSpecies> childDao = getDao(ObjectObservedSpecies.class); - + TopiaEntityBinder<ObjectObservedSpecies> binder = getBinder(ObjectObservedSpecies.class, BinderService.EDIT); List<ObjectObservedSpecies> childs = new ArrayList<ObjectObservedSpecies>(); for (ObjectObservedSpecies sourceChild : parentToLoad.getObjectObservedSpecies()) { ObjectObservedSpecies targetChild = childDao.newInstance(); - copy(ObjectObservedSpecies.class, BinderService.EDIT, sourceChild, targetChild); + binder.load(sourceChild, targetChild, true); childs.add(targetChild); } @@ -56,8 +57,7 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp } - @Override - public EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator() { + protected EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator() { return EntityListUpdator.newEntityListUpdator( FloatingObject.class, ObjectObservedSpecies.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java index 4581a6d..e253b52 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java @@ -1,10 +1,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * Created on 4/28/15. @@ -19,5 +17,4 @@ public interface ObjectSchoolEstimateService extends ObserveService { @Commit void save(FloatingObject floatingObject); - EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java index 060ecb1..10913c3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java @@ -28,13 +28,14 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl if (!parentToLoad.isObjectSchoolEstimateEmpty()) { TopiaDAO<ObjectSchoolEstimate> childDao = getDao(ObjectSchoolEstimate.class); + TopiaEntityBinder<ObjectSchoolEstimate> binder = getBinder(ObjectSchoolEstimate.class, BinderService.EDIT); List<ObjectSchoolEstimate> childs = new ArrayList<ObjectSchoolEstimate>(); for (ObjectSchoolEstimate sourceChild : parentToLoad.getObjectSchoolEstimate()) { ObjectSchoolEstimate targetChild = childDao.newInstance(); - copy(ObjectSchoolEstimate.class, BinderService.EDIT, sourceChild, targetChild); + binder.load(sourceChild, targetChild, true); childs.add(targetChild); } @@ -57,8 +58,7 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl } - @Override - public EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator() { + protected EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator() { return EntityListUpdator.newEntityListUpdator( FloatingObject.class, ObjectSchoolEstimate.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java index 6030cd3..8feaac6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java @@ -1,10 +1,8 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * Created on 4/28/15. @@ -19,6 +17,4 @@ public interface SchoolEstimateService extends ObserveService { @Commit void save(SetSeine parent); - EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java index 351ec2b..045a27d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -31,13 +31,14 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements if (!parentToLoad.isSchoolEstimateEmpty()) { TopiaDAO<SchoolEstimate> childDao = getDao(SchoolEstimate.class); + TopiaEntityBinder<SchoolEstimate> binder = getBinder(SchoolEstimate.class, BinderService.EDIT); List<SchoolEstimate> childs = new ArrayList<SchoolEstimate>(); for (SchoolEstimate sourceChild : parentToLoad.getSchoolEstimate()) { SchoolEstimate targetChild = childDao.newInstance(); - copy(SchoolEstimate.class, BinderService.EDIT, sourceChild, targetChild); + binder.load(sourceChild, targetChild, true); childs.add(targetChild); } @@ -60,8 +61,7 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements SetSeine.class, SchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); } - @Override - public EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { + protected EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { return EntityListUpdator.newEntityListUpdator( SetSeine.class, SchoolEstimate.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java index b70ca5d..4201f7f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java @@ -1,11 +1,8 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com @@ -17,8 +14,4 @@ public interface TargetLengthService extends ObserveService { @Commit void save(TargetSample parent); - @NoTransaction - EntityListUpdator<TargetSample, TargetLength> getListUpdator(); - - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java index d6b6a85..e6fa067 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -44,14 +45,19 @@ public class TargetLengthServiceImpl extends AbstractObserveService implements T copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); - for (TargetLength childToLoad : toLoad.getTargetLength()) { - TargetLength childLoaded = getDao(TargetLength.class).newInstance(); + if (!toLoad.isTargetLengthEmpty()) { - copy(TargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); + TopiaDAO<TargetLength> dao = getDao(TargetLength.class); - loaded.addTargetLength(childLoaded); + for (TargetLength childToLoad : toLoad.getTargetLength()) { + TargetLength childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addTargetLength(childLoaded); + + } } } @@ -81,8 +87,7 @@ public class TargetLengthServiceImpl extends AbstractObserveService implements T }); } - @Override - public EntityListUpdator<TargetSample, TargetLength> getListUpdator() { + protected EntityListUpdator<TargetSample, TargetLength> getListUpdator() { return EntityListUpdator.newEntityListUpdator( TargetSample.class, TargetLength.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 084a408..2ce82b8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -11,6 +11,7 @@ import fr.ird.observe.entities.seine.TargetSampleDAO; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.Collection; @@ -106,14 +107,18 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); - for (TargetLength childToLoad : toLoad.getTargetLength()) { + if (!toLoad.isTargetLengthEmpty()) { - TargetLength childLoaded = getChildDao().newInstance(); + TargetLengthDAO childDao = getChildDao(); + TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); - copy(TargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + for (TargetLength childToLoad : toLoad.getTargetLength()) { - loaded.addTargetLength(childLoaded); + TargetLength childLoaded = childDao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addTargetLength(childLoaded); + } } } @@ -192,9 +197,11 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T @Override public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { + copyExcluding(TargetSample.class, BinderService.EDIT, toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); getDao().update(beanToSave); return beanToSave; + } }); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java index 0a7a418..5ae0df8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java @@ -3,6 +3,7 @@ package fr.ird.observe.services.referential; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; @@ -31,6 +32,8 @@ public interface ReferentialService extends ObserveService { List<Species> loadDecoratedSpecies(String speciesListCode); + List<WeightCategory> loadDecoratedWeightCategory(); + Set<String> getSpeciesListSpeciesIds(String speciesListId); <R extends ReferenceEntity> R preCreate(Class<R> entityType); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 63b1078..270858f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -16,6 +16,7 @@ import fr.ird.observe.entities.referentiel.SpeciesList; import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.collections.CollectionUtils; +import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -111,6 +112,17 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } @Override + public List<WeightCategory> loadDecoratedWeightCategory() { + + List<WeightCategory> weightCategories = loadAndDecorateList(WeightCategory.class); + Decorator<Species> speciesDecorator = getDecoratorByType(Species.class, null); + for (WeightCategory weightCategory : weightCategories) { + speciesDecorator.toString(weightCategory.getSpecies()); + } + return weightCategories; + } + + @Override public Set<String> getSpeciesListSpeciesIds(String speciesListId) { SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListId); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 823a9d9..01dad8b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -30,8 +30,6 @@ import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.services.ObserveService; import fr.ird.observe.ui.UIHelper; @@ -85,16 +83,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { protected final String prefix; - private final TopiaExecutor<E> loadExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> preCreateExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> createExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> updateExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> deleteExecutor; - private final DataContextType parentType; private final DataContextType type; @@ -112,37 +100,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { if (log.isDebugEnabled()) { log.debug("New handler [" + this + "] for ui " + prefix); } - loadExecutor = new TopiaExecutor<E>() { - @Override - public void execute(TopiaContext tx, E bean) throws TopiaException { - onLoad(tx, bean); - } - }; - preCreateExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E bean) throws TopiaException { - return onPreCreate(tx, parentBean, bean); - } - }; - createExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E bean) throws TopiaException { - return onCreate(tx, parentBean, bean); - } - }; - updateExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E bean) throws TopiaException { - return onUpdate(tx, parentBean, bean); - } - }; - deleteExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E beanToDelete) throws TopiaException { - onDelete(tx, parentBean, beanToDelete); - return null; - } - }; errorIcon = UIManager.getIcon("action.error"); } @@ -163,10 +120,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } -// protected static void attachTopiaContext(DataSource service, TopiaEntityAbstract entity) { -// DBHelper.attachTopiaContext(service.getRootCtxt(), entity); -// } - public static ObserveTreeHelper getTreeHelper(JAXXContext context) { return context.getContextValue(ObserveTreeHelper.class); } @@ -277,11 +230,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { model.addMessages((JComponent) ui, fieldName, scope, message); } -// public static void removeAllMessages(ContentUI<?> ui, NuitonValidatorScope scope, String fieldName) { -// SwingValidatorMessageTableModel model = ui.getErrorTableModel(); -// model.removeMessages(ui, fieldName, scope); -// } - public static void removeAllMessages(ObserveContentUI<?> ui) { SwingValidatorMessageTableModel model = ui.getErrorTableModel(); model.removeMessages((JComponent) ui, null); @@ -357,10 +305,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { getBinderService().copy(type, context, source, target); } - public <E extends TopiaEntity> void copyEdit(Class<E> type, String context, E source, E target) { - getBinderService().copy(type, BinderService.EDIT, source, target); - } - public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { getBinderService().copyExcluding(type, context, source, target, propertyNames); } @@ -522,30 +466,9 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { updateActions(); } - //TODO a remplacer par saveUI2 public void saveUI(boolean refresh) { boolean ok = false; try { - ok = doSave(getBean(), - getDataService(), - getDataSource(), - getLoadBinder() - ); - } catch (Exception e) { - ErrorDialogUI.showError(e); - if (log.isErrorEnabled()) { - log.error(e); - } - } finally { - if (ok) { - afterSave(refresh); - } - } - } - - public void saveUI2(boolean refresh) { - boolean ok = false; - try { ok = doSave(getBean()); } catch (Exception e) { ErrorDialogUI.showError(e); @@ -559,14 +482,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } } - //TODO a remplacer par doSave simple - protected boolean doSave(E bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<E> binder) throws Exception { - return false; - } - protected boolean doSave(E bean) throws Exception { return false; } @@ -609,41 +524,11 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } - //TODO a remplacer par deleteUI2 public void deleteUI() { boolean ok = false; ui.stopEdit(); removeAllMessages(ui); try { - ok = doDelete(getBean(), - getDataService(), - getDataSource(), - getDeleteExecutor()); - } catch (Exception e) { - ErrorDialogUI.showError(e); - if (log.isErrorEnabled()) { - log.error(e); - } - } finally { - if (ok) { - afterDelete(); - } - } - } - - //TODO a remplacer par doDelete simple - protected boolean doDelete(E bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, E> deletor) throws Exception { - return false; - } - - public void deleteUI2() { - boolean ok = false; - ui.stopEdit(); - removeAllMessages(ui); - try { ok = doDelete(getBean()); } catch (Exception e) { ErrorDialogUI.showError(e); @@ -728,18 +613,18 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } } - protected E onCreate(TopiaContext tx, Object parentBean, E editBean) throws TopiaException { - return editBean; - } - - protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { - // rien par defaut - return beanToSave; - } - - protected void onDelete(TopiaContext tx, Object parentBean, E beanToDelete) throws TopiaException { - // rien par defaut - } +// protected E onCreate(TopiaContext tx, Object parentBean, E editBean) throws TopiaException { +// return editBean; +// } +// +// protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { +// // rien par defaut +// return beanToSave; +// } +// +// protected void onDelete(TopiaContext tx, Object parentBean, E beanToDelete) throws TopiaException { +// // rien par defaut +// } protected void addInfoMessage(String message) { addMessage(ui, @@ -764,25 +649,25 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return getModel().getLoadBinder(); } - protected final TopiaExecutor<E> getLoadExecutor() { - return loadExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getPreCreateExecutor() { - return preCreateExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getCreateExecutor() { - return createExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getUpdateExecutor() { - return updateExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getDeleteExecutor() { - return deleteExecutor; - } +// protected final TopiaExecutor<E> getLoadExecutor() { +// return loadExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getPreCreateExecutor() { +// return preCreateExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getCreateExecutor() { +// return createExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getUpdateExecutor() { +// return updateExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getDeleteExecutor() { +// return deleteExecutor; +// } protected final ContentMode computeContentMode() { ContentMode mode; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java index 929b591..22fa0a9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java @@ -22,7 +22,7 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -39,7 +39,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.i18n.I18n; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JOptionPane; @@ -83,7 +82,7 @@ public class BranchlineUIHandler extends ContentUIHandler<Branchline> { } getModel().setBranchline(branchline); - getLoadBinder().copy(branchline, getBean()); + copy(Branchline.class, BinderService.EDIT, branchline, getBean()); if (branchline == null) { @@ -218,14 +217,11 @@ public class BranchlineUIHandler extends ContentUIHandler<Branchline> { } @Override - protected boolean doSave(Branchline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<Branchline> binder) throws Exception { + protected boolean doSave(Branchline bean) { // bind back to model branchline Branchline beanToSave = getModel().getBranchline(); - binder.copy(bean, beanToSave); + copy(Branchline.class, BinderService.EDIT, bean, beanToSave); // for external models getModel().fireSaved(); @@ -358,7 +354,7 @@ public class BranchlineUIHandler extends ContentUIHandler<Branchline> { boolean generalTabValid = !errorProperties.removeAll(BranchlineUIModel.GENERAL_TAB_PROPERTIES); boolean hookAndBaitTabValid = !errorProperties.removeAll(BranchlineUIModel.HOOK_AND_BAIT_TAB_PROPERTIES); - BranchlineUIModel model = getModel(); + BranchlineUIModel model = getModel(); model.setGeneralTabValid(generalTabValid); model.setHookAndBaitTabValid(hookAndBaitTabValid); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java index 2227310..641ebf5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java @@ -22,12 +22,11 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Basket; @@ -48,10 +47,6 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComboBox; @@ -65,7 +60,6 @@ import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import static org.nuiton.i18n.I18n.t; @@ -398,12 +392,10 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } ContentMode mode = computeContentMode(); - DataService dataService = getDataService(); - - DataSource source = getDataSource(); - // update mode - dataService.loadEditEntity(source, setId, getLoadExecutor()); + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + SetLongline loaded = service.loadForEdit(setId); + copy(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION, loaded, getBean()); // utilisation du mode requis setContentMode(mode); @@ -479,14 +471,11 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } @Override - protected boolean doSave(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetLongline> binder) throws Exception { - + protected boolean doSave(SetLongline bean) { SectionsTableModel sectionsTableModel = getSectionsTableModel(); SectionWithTemplate selectedSection = sectionsTableModel.getSelectedRow(); + if (selectedSection != null) { // flush selected section before save @@ -494,146 +483,12 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - return true; - } - - @Override - protected SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { - - Map<String, Section> existingSectionsByTopiaId = Entities.toIdMap(beanToSave.getSection()); - - TopiaDAO<Section> sectionsDao = getDataSource().getDAO(tx, Section.class); - TopiaDAO<Basket> basketDao = getDataSource().getDAO(tx, Basket.class); - TopiaDAO<Branchline> branchlineDao = getDataSource().getDAO(tx, Branchline.class); - - List<SectionWithTemplate> sections = getSectionsTableModel().getNotEmptyData(); - - beanToSave.clearSection(); - - for (SectionWithTemplate section : sections) { - - Section sectionToSave = persistSection(sectionsDao, - basketDao, - branchlineDao, - existingSectionsByTopiaId, - section); - beanToSave.addSection(sectionToSave); - sectionToSave.setSetLongline(beanToSave); - - } - - return beanToSave; + List<SectionWithTemplate> sections = sectionsTableModel.getNotEmptyData(); - } - - protected Section persistSection(TopiaDAO<Section> sectionsDao, - TopiaDAO<Basket> basketDao, - TopiaDAO<Branchline> branchlineDao, - Map<String, Section> existingSectionsByTopiaId, - Section section) throws TopiaException { - - Section sectionToSave; - - if (section.getTopiaId() == null) { - - // create - sectionToSave = sectionsDao.create( - Section.PROPERTY_SETTING_IDENTIFIER, section.getSettingIdentifier(), - Section.PROPERTY_HAULING_IDENTIFIER, section.getHaulingIdentifier()); - - } else { - - sectionToSave = existingSectionsByTopiaId.get(section.getTopiaId()); - - } - - TopiaEntityBinder<Section> sectionBinder = getModel().getSectionBinder(); - sectionBinder.copyExcluding(section, sectionToSave, Section.PROPERTY_BASKET); - - Map<String, Basket> existingBasketsByTopiaId = Entities.toIdMap(sectionToSave.getBasket()); - - List<Basket> baskets = section.getBasket(); - sectionToSave.clearBasket(); - - for (Basket basket : baskets) { - - Basket basketToSave = persistBasket(basketDao, - branchlineDao, - existingBasketsByTopiaId, - basket); - sectionToSave.addBasket(basketToSave); - - } + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + service.save(bean, sections); - return sectionToSave; - - } - - protected Basket persistBasket(TopiaDAO<Basket> basketDao, - TopiaDAO<Branchline> branchlineDao, - Map<String, Basket> existingBasketsByTopiaId, - Basket basket) throws TopiaException { - - Basket basketToSave; - - if (basket.getTopiaId() == null) { - - // create - basketToSave = basketDao.create( - Basket.PROPERTY_SETTING_IDENTIFIER, basket.getSettingIdentifier(), - Basket.PROPERTY_HAULING_IDENTIFIER, basket.getHaulingIdentifier()); - - } else { - - basketToSave = existingBasketsByTopiaId.get(basket.getTopiaId()); - - } - - TopiaEntityBinder<Basket> basketBinder = getModel().getBasketBinder(); - basketBinder.copyExcluding(basket, basketToSave, Basket.PROPERTY_BRANCHLINE); - - Map<String, Branchline> existingBranchlinesByTopiaId = Entities.toIdMap(basketToSave.getBranchline()); - - basketToSave.clearBranchline(); - - List<Branchline> branchlines = basket.getBranchline(); - - for (Branchline branchline : branchlines) { - - Branchline branchlineToSave = persistBranchline(branchlineDao, existingBranchlinesByTopiaId, branchline); - basketToSave.addBranchline(branchlineToSave); - - } - - return basketToSave; - - } - - protected Branchline persistBranchline(TopiaDAO<Branchline> branchlineDao, - Map<String, Branchline> existingBranchlinesByTopiaId, - Branchline branchline) throws TopiaException { - - Branchline branchlineToSave; - - if (branchline.getTopiaId() == null) { - - // create - branchlineToSave = branchlineDao.create( - Branchline.PROPERTY_SETTING_IDENTIFIER, branchline.getSettingIdentifier(), - Branchline.PROPERTY_HAULING_IDENTIFIER, branchline.getHaulingIdentifier()); - - } else { - - branchlineToSave = existingBranchlinesByTopiaId.get(branchline.getTopiaId()); - - } - - TopiaEntityBinder<Branchline> branchlineBinder = getModel().getBranchlineBinder(); - branchlineBinder.copy(branchline, branchlineToSave); - - return branchlineToSave; + return true; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java index 821f821..3a5fec7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -38,7 +37,6 @@ import fr.ird.observe.ui.content.table.impl.longline.FloatlinesCompositionUI; import fr.ird.observe.ui.content.table.impl.longline.HooksCompositionUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import static org.nuiton.i18n.I18n.t; @@ -124,6 +122,7 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong @Override public void openUI() throws Exception { + super.openUI(); String activityId = getSelectedParentId(); @@ -135,12 +134,10 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong } ContentMode mode = computeContentMode(); - DataService dataService = getDataService(); - - DataSource source = getDataSource(); - // update mode - dataService.loadEditEntity(source, setId, getLoadExecutor()); + LonglineGlobalCompositionService service = getService(LonglineGlobalCompositionService.class); + SetLongline loaded = service.loadForEdit(setId); + copy(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION, loaded, getBean()); // utilisation du mode requis setContentMode(mode); @@ -177,22 +174,13 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong @Override public void startEditUI(String... binding) { + LonglineGlobalCompositionUIModel model = (LonglineGlobalCompositionUIModel) getModel(); addInfoMessage(t("observe.longlineGlobalComposition.message.updating")); super.startEditUI(LonglineGlobalCompositionUI.BINDING_COMMENT2_TEXT); model.setModified(false); - } - - @Override - protected boolean doSave(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetLongline> binder) throws Exception { - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - return true; } @Override @@ -203,25 +191,24 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, getUi().getHooksCompositionUI().getBean(), bean); copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, getUi().getBaitsCompositionUI().getBean(), bean); - getService(LonglineGlobalCompositionService.class).save(bean); + LonglineGlobalCompositionService service = getService(LonglineGlobalCompositionService.class); + String id = service.save(bean); + bean.setTopiaId(id); return true; + } @Override protected void afterSave(boolean refresh) { + super.afterSave(refresh); getUi().getFloatlinesCompositionUI().getHandler().afterSave(refresh); getUi().getBranchlinesCompositionUI().getHandler().afterSave(refresh); getUi().getHooksCompositionUI().getHandler().afterSave(refresh); getUi().getBaitsCompositionUI().getHandler().afterSave(refresh); - } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java index 11414a1..7cf9f43 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java @@ -22,12 +22,10 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.data.longline.SetLonglineService; @@ -40,22 +38,16 @@ import jaxx.runtime.swing.HidorButton; import jaxx.runtime.validator.swing.SwingValidatorMessage; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import jaxx.runtime.validator.swing.SwingValidatorUtil; -import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.widgets.gis.CoordinateFormat; import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditorModel; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -166,7 +158,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } - @Override public void openUI() throws Exception { @@ -190,26 +181,45 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } ContentMode mode = computeContentMode(); - DataService dataService = getDataService(); + SetLonglineService service = getService(SetLonglineService.class); - SetLongline bean = getBean(); + SetLongline loaded; - TopiaEntityBinder<SetLongline> binder = getLoadBinder(); - DataSource source = getDataSource(); if (setId == null) { // creation mode - dataService.preCreate(source, activityId, bean, binder, getPreCreateExecutor()); + loaded = service.preCreate(activityId); getUi().getFishingOperationTabPane().setSelectedIndex(0); } else { // update mode - dataService.loadEditEntity(source, setId, getLoadExecutor()); + loaded = service.loadForEdit(setId); } + Float settingStartLatitude = loaded.getSettingStartLatitude(); + Float settingStartLongitude = loaded.getSettingStartLongitude(); + Float settingEndLatitude = loaded.getSettingEndLatitude(); + Float settingEndLongitude = loaded.getSettingEndLongitude(); + Float haulingStartLatitude = loaded.getHaulingStartLatitude(); + Float haulingStartLongitude = loaded.getHaulingStartLongitude(); + Float haulingEndLatitude = loaded.getHaulingEndLatitude(); + Float haulingEndLongitude = loaded.getHaulingEndLongitude(); + + SetLongline bean = getBean(); + copy(SetLongline.class, BinderService.EDIT, loaded, bean); + + bean.setSettingStartLatitude(settingStartLatitude); + bean.setSettingStartLongitude(settingStartLongitude); + bean.setSettingEndLatitude(settingEndLatitude); + bean.setSettingEndLongitude(settingEndLongitude); + bean.setHaulingStartLatitude(haulingStartLatitude); + bean.setHaulingStartLongitude(haulingStartLongitude); + bean.setHaulingEndLatitude(haulingEndLatitude); + bean.setHaulingEndLongitude(haulingEndLongitude); + // passage en coordonnes absolues + utilisation du quadrant bean.initCoordinates(); @@ -231,31 +241,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected void onLoad(TopiaContext tx, SetLongline bean) throws TopiaException { - - Float settingStartLatitude = bean.getSettingStartLatitude(); - Float settingStartLongitude = bean.getSettingStartLongitude(); - Float settingEndLatitude = bean.getSettingEndLatitude(); - Float settingEndLongitude = bean.getSettingEndLongitude(); - Float haulingStartLatitude = bean.getHaulingStartLatitude(); - Float haulingStartLongitude = bean.getHaulingStartLongitude(); - Float haulingEndLatitude = bean.getHaulingEndLatitude(); - Float haulingEndLongitude = bean.getHaulingEndLongitude(); - - super.onLoad(tx, bean); - - getBean().setSettingStartLatitude(settingStartLatitude); - getBean().setSettingStartLongitude(settingStartLongitude); - getBean().setSettingEndLatitude(settingEndLatitude); - getBean().setSettingEndLongitude(settingEndLongitude); - getBean().setHaulingStartLatitude(haulingStartLatitude); - getBean().setHaulingStartLongitude(haulingStartLongitude); - getBean().setHaulingEndLatitude(haulingEndLatitude); - getBean().setHaulingEndLongitude(haulingEndLongitude); - - } - - @Override protected void closeSafeUI() { if (log.isInfoEnabled()) { @@ -269,35 +254,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected SetLongline onPreCreate(TopiaContext tx, - Object parent, - SetLongline bean) throws TopiaException { - - ActivityLongline parentBean = (ActivityLongline) parent; - - // on utilise la date - heure de l'activité pour initialiser les horodatages - // de l'opération de peche - Date timeStamp = parentBean.getTimeStamp(); - bean.setSettingStartTimeStamp(timeStamp); - bean.setSettingEndTimeStamp(DateUtils.addHours(timeStamp, 1)); - bean.setHaulingStartTimeStamp(DateUtils.addHours(timeStamp, 2)); - bean.setHaulingEndTimeStamp(DateUtils.addHours(timeStamp, 3)); - - // on reporte la position de l'activité pour la position de début de filage - Float latitude = parentBean.getLatitude(); - Float longitude = parentBean.getLongitude(); - - // On enregistre deux fois les coordonnées car la première fois on perd le signe à cause de l'éditeur - bean.setSettingStartLatitude(latitude); - bean.setSettingStartLongitude(longitude); - bean.setSettingStartLatitude(latitude); - bean.setSettingStartLongitude(longitude); - - return bean; - - } - - @Override public void startEditUI(String... binding) { ContentUIModel<SetLongline> model = getModel(); @@ -368,10 +324,7 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected boolean doSave(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetLongline> binder) throws Exception { + protected boolean doSave(SetLongline bean) { String activityId = getSelectedParentId(); @@ -379,6 +332,7 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { String savedId = service.save(activityId, bean); bean.setTopiaId(savedId); return true; + } @Override @@ -409,7 +363,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } else { // select ancestor node -// treeHelper.refreshNode(node, false); treeHelper.reloadSelectedNode(false, false); } @@ -417,33 +370,26 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected boolean doDelete(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, SetLongline> deletor) throws Exception { + protected boolean doDelete(SetLongline bean) { + + boolean result; if (askToDelete(bean)) { - return false; - } - String activityId = getSelectedParentId(); - dataService.delete(dataSource, activityId, bean, deletor); + result = false; - return true; + } else { - } + SetLonglineService service = getService(SetLonglineService.class); - @Override - protected void onDelete(TopiaContext tx, Object parent, SetLongline beanToDelete) throws TopiaException { + String activityId = getSelectedParentId(); + service.delete(activityId, bean.getTopiaId()); - ActivityLongline parentBean = (ActivityLongline) parent; + result = true; - // on doit supprimer physiquement la set - // car il n'y a pas de delete-orphan sur une telle - // relation - ObserveDAOHelper.getSetLonglineDAO(tx).delete(parentBean.getSetLongline()); - // supprime la reference sur l'activity - parentBean.setSetLongline(null); + } + + return result; } @@ -525,4 +471,5 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java index 58214c3..86ace0a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -85,7 +86,7 @@ public class ActivitySeineObservedSystemUIHandler extends ContentUIHandler<Activ ActivitySeineService service = getService(ActivitySeineService.class); ActivitySeine activitySeine = service.loadForEditObservedSystem(activityId); - service.copyForEditObservedSystem(activitySeine, getBean()); + copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, activitySeine, getBean()); getModel().setMode(mode); @@ -105,15 +106,9 @@ public class ActivitySeineObservedSystemUIHandler extends ContentUIHandler<Activ ActivitySeineService service = getService(ActivitySeineService.class); ActivitySeine saved = service.updateObservedSystem(getBean()); - service.copyForEditObservedSystem(saved, bean); + copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, saved, bean); return true; } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java index 21c72a3..186d458 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java @@ -21,15 +21,13 @@ */ package fr.ird.observe.ui.content.impl.seine; -import fr.ird.observe.DecoratorService; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.constants.seine.Ownership; import fr.ird.observe.entities.constants.seine.TypeTransmittingBuoyOperation; -import fr.ird.observe.entities.referentiel.Country; import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation; -import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.TransmittingBuoy; @@ -39,9 +37,6 @@ import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JPanel; @@ -121,7 +116,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH FloatingObjectService service = getService(FloatingObjectService.class); FloatingObject loaded = service.loadForEditTransmittingBuoyOperation(floatingObjectId); - service.copyForEditTransmittingBuoyOperation(loaded, getBean()); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, loaded, bean); getUi().processDataBinding(FloatingObjectTransmittingBuoyOperationUI.BINDING_TYPE_OPERATION_SELECTED_ITEM); @@ -136,55 +131,6 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH } @Override - protected void onLoad(TopiaContext tx, FloatingObject bean) throws TopiaException { - - FloatingObject editBean = getBean(); - - // chargement du bean depuis celui qui vient de la base - getLoadBinder().load(bean, editBean, true); - - editBean.clearTransmittingBuoy(); - - List<TransmittingBuoy> objets = bean.getTransmittingBuoy(); - - if (objets != null) { - DecoratorService decoratorService = getDecoratorService(); - Decorator<TransmittingBuoy> dB = decoratorService.getDecoratorByType(TransmittingBuoy.class); - Decorator<TransmittingBuoyOperation> dB2 = decoratorService.getDecoratorByType(TransmittingBuoyOperation.class); - Decorator<TransmittingBuoyType> dB3 = decoratorService.getDecoratorByType(TransmittingBuoyType.class); - Decorator<Country> dB4 = decoratorService.getDecoratorByType(Country.class); - for (TransmittingBuoy transmittingBuoy : objets) { - String s = dB.toString(transmittingBuoy); - if (log.isDebugEnabled()) { - log.debug("use balise lue : " + s); - } - TransmittingBuoyOperation objectOperation = transmittingBuoy.getTransmittingBuoyOperation(); - if (objectOperation != null) { - s = dB2.toString(objectOperation); - if (log.isDebugEnabled()) { - log.debug("use objectOperation balise : " + s); - } - } - TransmittingBuoyType type = transmittingBuoy.getTransmittingBuoyType(); - if (type != null) { - s = dB3.toString(type); - if (log.isDebugEnabled()) { - log.debug("use type balise : " + s); - } - } - Country country = transmittingBuoy.getCountry(); - if (country != null) { - s = dB4.toString(country); - if (log.isDebugEnabled()) { - log.debug("use country : " + s); - } - } - editBean.addTransmittingBuoy(transmittingBuoy); - } - } - } - - @Override public void startEditUI(String... binding) { super.startEditUI( FloatingObjectTransmittingBuoyOperationUI.BINDING_TRANSMITTING_BUOY_OPERATION1_SELECTED_ITEM, @@ -238,56 +184,15 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH @Override protected boolean doSave(FloatingObject bean) { + //FIXME On ne doit pas retourner l'objet... FloatingObjectService service = getService(FloatingObjectService.class); FloatingObject saved = service.updateTransmittingBuoyOperation(bean); - service.copyForEditTransmittingBuoyOperation(saved, bean); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, saved, bean); //FIXME, il faut declancher un evenement dans le cache du storage pour pouvoir redessiner le noeud return true; } -// @Override -// protected FloatingObject onUpdate(TopiaContext tx, -// Object parentBean, -// FloatingObject beanToSave) throws TopiaException { -// -// FloatingObject editBean = getBean(); -// -// List<TransmittingBuoy> objets = editBean.getTransmittingBuoy(); -// -// beanToSave.setComment(editBean.getComment()); -// -// beanToSave.clearTransmittingBuoy(); -// -// TopiaEntityBinder<TransmittingBuoy> childLoador = getModel().getChildLoador(); -// -// TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = ObserveDAOHelper.getTransmittingBuoyDAO(tx); -// -// for (TransmittingBuoy transmittingBuoy : objets) { -// TransmittingBuoy newBalise; -// -// if (transmittingBuoy.getTopiaId() == null) { -// -// // creation de la balise -// -// Map<String, Object> map = childLoador.obtainProperties(transmittingBuoy); -// -// newBalise = transmittingBuoyDAO.create(map); -// -// } else { -// -// // mise a jour de la balise -// -// newBalise = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); -// -// childLoador.load(transmittingBuoy, newBalise, false); -// } -// -// beanToSave.addTransmittingBuoy(newBalise); -// } -// return beanToSave; -// } - @Override protected void afterSave(boolean refresh) { // rien a rafraichir ? @@ -388,8 +293,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH TransmittingBuoyOperation transmittingBuoyOperation, TransmittingBuoy transmittingBuoy) { - FloatingObjectService service = getService(FloatingObjectService.class); - service.copyForEditTransmittingBuoy(transmittingBuoy, editBean); + copy(TransmittingBuoy.class, BinderService.EDIT, transmittingBuoy, editBean); if (transmittingBuoy == null) { @@ -433,10 +337,4 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH return objectOperation; } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java index 36d6015..b424211 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java @@ -36,38 +36,9 @@ public class FloatingObjectTransmittingBuoyOperationUIModel extends ContentUIMod private static final long serialVersionUID = 1L; -// protected TopiaEntityBinder<TransmittingBuoy> childLoador; - public FloatingObjectTransmittingBuoyOperationUIModel() { - super(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION); - -// String binderName = getClass().getName() + "-open"; -// -// BinderService binderService = ObserveServiceHelper.get().getBinderService(); - -// childLoador = binderService.getTopiaBinder(TransmittingBuoy.class, binderName); -// -// if (childLoador == null) { -// -// BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = binderService.newBinderBuilder( -// TransmittingBuoy.class, -// TransmittingBuoy.PROPERTY_CODE, -// TransmittingBuoy.PROPERTY_OWNERSHIP, -// TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, -// TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, -// TransmittingBuoy.PROPERTY_BRAND, -// TransmittingBuoy.PROPERTY_COUNTRY); -// -// // enregistrement du binder -// childLoador = binderService.registerTopiaBinder(TransmittingBuoy.class, builder, binderName); -// -// // positionnement de l'entite empty -// childLoador.setEmpty(new TransmittingBuoyImpl()); -// } + super(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY); } -// @Override -// protected BinderModelBuilder<FloatingObject, FloatingObject> createOpeningBinder(BinderService binderService, String binderName) { return null; } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java index cec5c6c..591d1e3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -121,7 +122,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { } FloatingObject bean = getBean(); - service.copyForEdit(loaded, bean); + copy(FloatingObject.class, BinderService.EDIT, loaded, bean); // utilisation du mode requis setContentMode(mode); @@ -217,15 +218,4 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java index 913edb4..1fe72ea 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java @@ -351,16 +351,4 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { } - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java index acc0335..1b52eef 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java @@ -77,18 +77,6 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE return service.getOpenablePosition(containerId, beanId); } - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override public ContentOpenableUI<E> getUi() { return (ContentOpenableUI<E>) super.getUi(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java index 10cf6ab..7e0e1fe 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.open.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; @@ -174,16 +175,12 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei } else { // update mode - if (mode == ContentMode.UPDATE) { - loaded = service.loadForEdit(activityId); - } else { - loaded = service.loadForDisplay(activityId); - } + loaded = service.loadForEdit(activityId); } ActivitySeine bean = getBean(); - service.copyForEdit(loaded, bean); + copy(ActivitySeine.class, BinderService.EDIT, loaded, bean); SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java index d597124..7e64197 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java @@ -112,18 +112,6 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } }; - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - public ContentReferenceUIHandler(ContentReferenceUI<E> ui) { super(ui, null, null); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index 0d2093d..c5be916 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -21,9 +21,7 @@ */ package fr.ird.observe.ui.content.table; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; @@ -36,16 +34,11 @@ import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.content.ObserveContentUI; import fr.ird.observe.ui.tree.ObserveNode; import jaxx.runtime.swing.ErrorDialogUI; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.Loador; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -54,11 +47,9 @@ import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.table.DefaultTableCellRenderer; import java.awt.Rectangle; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Set; import static org.nuiton.i18n.I18n.n; @@ -193,86 +184,88 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top protected abstract void initTableUI(DefaultTableCellRenderer renderer); - protected String getEditBeanIdToLoad(DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { - throw new IllegalStateException("Do NOT USE ME!!!"); - } +// protected String getEditBeanIdToLoad(DataContext dataContext, +// DataService dataService, +// DataSource dataSource) throws DataSourceException { +// throw new IllegalStateException("Do NOT USE ME!!!"); +// } - protected E loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { +// protected E loadEditBean(ContentMode mode, +// DataContext dataContext, +// DataService dataService, +// DataSource dataSource) throws DataSourceException { +// +// loadEditBean(mode); +// +//// String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); +//// +//// if (id == null) { +//// throw new IllegalStateException("Could not find id form " + this); +//// } +//// +//// // preparation du bean d'édition +//// dataService.loadEditEntity(dataSource, id, getLoadExecutor()); +// +//// getModel().setMode(mode); +//// +//// // initialisation du modèle du tableau +//// getUi().getTableModel().attachModel(); +// +// E editBean = getBean(); +// return editBean; +// +// } - loadEditBean(); + //FIXME Rendre cette methode abstract + protected abstract void loadEditBean(ContentMode mode) ; -// String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); +// protected abstract void loadEditBean() throws DataSourceException { +// +// String id = getEditBeanIdToLoad(getDataContext(), getDataService(), getDataSource()); // // if (id == null) { // throw new IllegalStateException("Could not find id form " + this); // } // // // preparation du bean d'édition -// dataService.loadEditEntity(dataSource, id, getLoadExecutor()); - -// getModel().setMode(mode); +// getDataService().loadEditEntity(getDataSource(), id, getLoadExecutor()); // -// // initialisation du modèle du tableau -// getUi().getTableModel().attachModel(); - - E editBean = getBean(); - return editBean; - - } - - //FIXME Rendre cette methode abstract - protected void loadEditBean() throws DataSourceException { +// } - String id = getEditBeanIdToLoad(getDataContext(), getDataService(), getDataSource()); - - if (id == null) { - throw new IllegalStateException("Could not find id form " + this); - } - - // preparation du bean d'édition - getDataService().loadEditEntity(getDataSource(), id, getLoadExecutor()); - - } - - //FIXME A supprimer - @Override - protected final void onLoad(TopiaContext tx, E bean) throws TopiaException { - super.onLoad(tx, bean); - - // on duplique la liste des fils traites dans le tableau - // sinon on reste sur les references d'origine et on aura pas - // la possibilité d'annuler l'edition ensuite car on aura modifie - // les entrées d'origine... - E editBean = getBean(); - Collection<D> data = loadChilds(tx, editBean); - getModel().getChildsUpdator().setChilds(editBean, data); - } - - //FIXME A supprimer - protected Collection<D> loadChilds(TopiaContext tx, E bean) throws TopiaException { - Collection<D> childs = getModel().getChildsUpdator().getChilds(bean); - Collection<D> data = new ArrayList<D>(); - if (CollectionUtils.isNotEmpty(childs)) { - Loador<D> loader = getModel().getChildLoador(); - TopiaDAO<D> dao = getDataSource().getDAO(tx, getTableEditBean()); - for (D c : childs) { - try { - D cUp = dao.findByTopiaId(c.getTopiaId()); - D c2 = getModel().newTableEditBean(); - loader.load(cUp, c2, true); - data.add(c2); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - return data; - } +// //FIXME A supprimer +// @Override +// protected final void onLoad(TopiaContext tx, E bean) throws TopiaException { +// super.onLoad(tx, bean); +// +// // on duplique la liste des fils traites dans le tableau +// // sinon on reste sur les references d'origine et on aura pas +// // la possibilité d'annuler l'edition ensuite car on aura modifie +// // les entrées d'origine... +// E editBean = getBean(); +// Collection<D> data = loadChilds(tx, editBean); +// getModel().getChildsUpdator().setChilds(editBean, data); +// } +// +// //FIXME A supprimer +// protected Collection<D> loadChilds(TopiaContext tx, E bean) throws TopiaException { +// Collection<D> childs = getModel().getChildsUpdator().getChilds(bean); +// Collection<D> data = new ArrayList<D>(); +// if (CollectionUtils.isNotEmpty(childs)) { +// Loador<D> loader = getModel().getChildLoador(); +// TopiaDAO<D> dao = getDataSource().getDAO(tx, getTableEditBean()); +// for (D c : childs) { +// try { +// D cUp = dao.findByTopiaId(c.getTopiaId()); +// D c2 = getModel().newTableEditBean(); +// loader.load(cUp, c2, true); +// data.add(c2); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// } +// return data; +// } @Override public void initUI() throws Exception { @@ -329,7 +322,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top ui.getTableModel().dettachModel(); // chargement du bean d'édition - loadEditBean(mode, getDataContext(), getDataService(), getDataSource()); + loadEditBean(mode); // chargement de l'écran d'édition loadTableEditBeanForm(mode); @@ -396,36 +389,36 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } } - @Override - protected boolean doSave(E bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<E> binder) throws Exception { - - ObserveContentTableUI<E, D> ui = getUi(); - - List<D> objets = ui.getTableModel().getData(); - - boolean canContinue; - try { - canContinue = prepareSave(bean, objets); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error(e); - } - ErrorDialogUI.showError(e); - canContinue = false; - } - if (!canContinue) { - - // l'utilisateur a choisi de ne pas sauvegarder - return false; - } - doPersist(bean, dataService, dataSource); - - - return true; - } +// @Override +// protected boolean doSave(E bean, +// DataService dataService, +// DataSource dataSource, +// TopiaEntityBinder<E> binder) throws Exception { +// +// ObserveContentTableUI<E, D> ui = getUi(); +// +// List<D> objets = ui.getTableModel().getData(); +// +// boolean canContinue; +// try { +// canContinue = prepareSave(bean, objets); +// } catch (Exception e) { +// if (log.isErrorEnabled()) { +// log.error(e); +// } +// ErrorDialogUI.showError(e); +// canContinue = false; +// } +// if (!canContinue) { +// +// // l'utilisateur a choisi de ne pas sauvegarder +// return false; +// } +// doPersist(bean, dataService, dataSource); +// +// +// return true; +// } @Override protected boolean doSave(E bean) { @@ -456,70 +449,70 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } - protected void doPersist(E bean, DataService dataService, DataSource dataSource) throws DataSourceException { - // sauvegarde du bean en base - dataService.update(dataSource, null, bean, getUpdateExecutor()); - } +// protected void doPersist(E bean, DataService dataService, DataSource dataSource) throws DataSourceException { +// // sauvegarde du bean en base +// dataService.update(dataSource, null, bean, getUpdateExecutor()); +// } protected void doPersist(E editBean) { } - @Override - protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { - - List<D> childs = getUi().getTableModel().getData(); - - E editBean = getBean(); - - TopiaEntityBinder<E> binder = getLoadBinder(); - - Loador<D> childBinder = getModel().getChildLoador(); - - EntityListUpdator<E, D> childUpdator = getModel().getChildsUpdator(); - - // recopie des propriétés du bean en excluant toujours la liste des fils - binder.copyExcluding(editBean, beanToSave, childUpdator.getPropertyName()); - - // on conserve l'ancienne liste des fils (pour traitement ultérieure) - Collection<D> oldChilds = - new ArrayList<D>(childUpdator.getChilds(beanToSave)); - - // suppression des fils dans le bean a sauver - childUpdator.removeAll(beanToSave); - - TopiaDAO<D> dao = ObserveDAOHelper.getDAO(tx, getModel().getChildType()); - - for (D child : childs) { - - D childToSave; - - if (child.getTopiaId() == null) { - - // creation du fils - Map<String, Object> map = childBinder.obtainProperties(child); - - childToSave = dao.create(map); - - } else { - - // mise a jour du fils - - childToSave = dao.findByTopiaId(child.getTopiaId()); - - childBinder.load(child, childToSave, false); - } - - // ajout du fils au bean à sauver - childUpdator.addToList(beanToSave, childToSave); - } - - // on donne la main aux implantations pour faire des traitements - // supplémentaires - onUpdateFinalize(tx, beanToSave, oldChilds); - - return beanToSave; - } +// @Override +// protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { +// +// List<D> childs = getUi().getTableModel().getData(); +// +// E editBean = getBean(); +// +// TopiaEntityBinder<E> binder = getLoadBinder(); +// +// Loador<D> childBinder = getModel().getChildLoador(); +// +// EntityListUpdator<E, D> childUpdator = getModel().getChildsUpdator(); +// +// // recopie des propriétés du bean en excluant toujours la liste des fils +// binder.copyExcluding(editBean, beanToSave, childUpdator.getPropertyName()); +// +// // on conserve l'ancienne liste des fils (pour traitement ultérieure) +// Collection<D> oldChilds = +// new ArrayList<D>(childUpdator.getChilds(beanToSave)); +// +// // suppression des fils dans le bean a sauver +// childUpdator.removeAll(beanToSave); +// +// TopiaDAO<D> dao = ObserveDAOHelper.getDAO(tx, getModel().getChildType()); +// +// for (D child : childs) { +// +// D childToSave; +// +// if (child.getTopiaId() == null) { +// +// // creation du fils +// Map<String, Object> map = childBinder.obtainProperties(child); +// +// childToSave = dao.create(map); +// +// } else { +// +// // mise a jour du fils +// +// childToSave = dao.findByTopiaId(child.getTopiaId()); +// +// childBinder.load(child, childToSave, false); +// } +// +// // ajout du fils au bean à sauver +// childUpdator.addToList(beanToSave, childToSave); +// } +// +// // on donne la main aux implantations pour faire des traitements +// // supplémentaires +// onUpdateFinalize(tx, beanToSave, oldChilds); +// +// return beanToSave; +// } @Override protected void afterSave(boolean refresh) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java index 42bdefa..af75db0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.BaitsComposition; import fr.ird.observe.entities.longline.SetLongline; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.referentiel.longline.BaitSettingStatus; import fr.ird.observe.entities.referentiel.longline.BaitType; import fr.ird.observe.services.data.longline.BaitsCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -63,7 +63,7 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -135,9 +135,4 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline super.afterSave(refresh); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java index cdfcc88..001bb49 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.BranchlinesComposition; import fr.ird.observe.entities.longline.SetLongline; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.referentiel.longline.HookSize; import fr.ird.observe.entities.referentiel.longline.HookType; import fr.ird.observe.services.data.longline.BranchlinesCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -107,7 +107,7 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -133,10 +133,4 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo super.afterSave(refresh); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index fdfc42c..710b8ad 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -26,8 +26,6 @@ import fr.ird.observe.BinderService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Branchline; @@ -35,9 +33,7 @@ import fr.ird.observe.entities.longline.CatchLongline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SizeMeasure; -import fr.ird.observe.entities.longline.SizeMeasureDAO; import fr.ird.observe.entities.longline.WeightMeasure; -import fr.ird.observe.entities.longline.WeightMeasureDAO; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.longline.CatchFateLongline; import fr.ird.observe.entities.referentiel.longline.Healthness; @@ -47,6 +43,7 @@ import fr.ird.observe.services.data.longline.CatchLonglineService; import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIInitializer; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; @@ -58,9 +55,6 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -70,8 +64,6 @@ import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -156,7 +148,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -184,11 +176,61 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C @Override protected void doPersist(SetLongline editBean) { + List<CatchLongline> catchLonglines = editBean.getCatchLongline(); + + { + SizeMeasuresTableModel tableModel = getModel().getSizeMeasuresTableModel(); + + Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); + + for (Integer row : rowsChanged) { + + CatchLongline catchLongline = catchLonglines.get(row); + + List<SizeMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); + catchLongline.clearSizeMeasure(); + catchLongline.addAllSizeMeasure(measurements); + + } + } + + { + WeightMeasuresTableModel tableModel = getModel().getWeightMeasuresTableModel(); + + Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); + + for (Integer row : rowsChanged) { + + CatchLongline catchLongline = catchLonglines.get(row); + + List<WeightMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); + catchLongline.clearWeightMeasure(); + catchLongline.addAllWeightMeasure(measurements); + + } + } + CatchLonglineService service = getService(CatchLonglineService.class); service.save(editBean); } + public void saveBranchline() { + + if (log.isInfoEnabled()) { + log.info("Saved modified branchline"); + } + + Branchline branchline = getTableEditBean().getBranchline(); + + CatchLonglineService service = getService(CatchLonglineService.class); + + Branchline beanSaved = service.saveBranchline(branchline); + getTableEditBean().setBranchline(beanSaved); + getUi().getBranchlineValidator().setChanged(false); + + } + @Override protected void onSelectedRowChanged(int editingRow, CatchLongline bean, boolean create) { @@ -542,103 +584,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected void onUpdateFinalize(TopiaContext tx, SetLongline bean, Collection<CatchLongline> oldChilds) throws TopiaException { - - List<CatchLongline> catchLonglines = bean.getCatchLongline(); - - // remove less precise position on longline - LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); - positionHelper.savePosition(catchLonglines); - - CatchLonglineUIModel model = getModel(); - { - - // save sizes - - SizeMeasureDAO measureDao = ObserveDAOHelper.getSizeMeasureDAO(tx); - - SizeMeasuresTableModel sizeMeasuresTableModel = model.getSizeMeasuresTableModel(); - Set<Integer> rowsChanged = sizeMeasuresTableModel.getCacheRowsChanged(); - - TopiaEntityBinder<SizeMeasure> loader = sizeMeasuresTableModel.getLoader(); - for (Integer row : rowsChanged) { - - CatchLongline catchLongline = catchLonglines.get(row); - - List<SizeMeasure> measures = sizeMeasuresTableModel.getCacheForRow(row); - List<SizeMeasure> measuresToSave = new ArrayList<SizeMeasure>(measures.size()); - - for (SizeMeasure measure : measures) { - - if (sizeMeasuresTableModel.isRowNotEmpty(measure)) { - - SizeMeasure measureToSave; - - if (measure.getTopiaId() == null) { - measureToSave = measureDao.create(measure); - loader.load(measureToSave, measure, true); - } else { - measureToSave = catchLongline.getSizeMeasureByTopiaId(measure.getTopiaId()); - loader.load(measure, measureToSave, true); - } - - measuresToSave.add(measureToSave); - - } - - } - - catchLongline.clearSizeMeasure(); - catchLongline.addAllSizeMeasure(measuresToSave); - - } - - } - - { - - // save weights - - WeightMeasureDAO dao = ObserveDAOHelper.getWeightMeasureDAO(tx); - - WeightMeasuresTableModel weightMeasuresTableModel = model.getWeightMeasuresTableModel(); - TopiaEntityBinder<WeightMeasure> loader = weightMeasuresTableModel.getLoader(); - Set<Integer> rowsChanged = weightMeasuresTableModel.getCacheRowsChanged(); - - for (Integer row : rowsChanged) { - - CatchLongline catchLongline = catchLonglines.get(row); - - List<WeightMeasure> measures = weightMeasuresTableModel.getCacheForRow(row); - List<WeightMeasure> measuresToSave = new ArrayList<WeightMeasure>(measures.size()); - for (WeightMeasure measure : measures) { - - if (weightMeasuresTableModel.isRowNotEmpty(measure)) { - - WeightMeasure measureToSave; - - if (measure.getTopiaId() == null) { - measureToSave = dao.create(measure); - loader.load(measureToSave, measure, true); - } else { - measureToSave = catchLongline.getWeightMeasureByTopiaId(measure.getTopiaId()); - loader.load(measure, measureToSave, true); - } - measuresToSave.add(measureToSave); - - } - - } - - catchLongline.clearWeightMeasure(); - catchLongline.addAllWeightMeasure(measuresToSave); - } - - } - - } - - @Override protected void resetEditBean() { UIHelper.stopEditing(getUi().getSizeMeasuresTable()); @@ -659,23 +604,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } - public void saveBranchline() { - - if (log.isInfoEnabled()) { - log.info("Saved modified branchline"); - } - - Branchline branchline = getTableEditBean().getBranchline(); - - CatchLonglineService service = getService(CatchLonglineService.class); - - Branchline beanSaved = service.saveBranchline(branchline); - getTableEditBean().setBranchline(beanSaved); - getUi().getBranchlineValidator().setChanged(false); - - - } - public void updateCatchAcquisitionMode(CatchAcquisitionModeEnum newMode) { if (log.isDebugEnabled()) { @@ -925,10 +853,4 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C return (CatchLonglineTableModel) super.getTableModel(); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java index 166b706..a00e5c0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java @@ -24,7 +24,6 @@ package fr.ird.observe.ui.content.table.impl.longline; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Encounter; @@ -32,6 +31,7 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.longline.EncounterType; import fr.ird.observe.services.data.longline.EncounterService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,7 +62,7 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedActivityId(); @@ -124,9 +124,4 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java index e27355b..89bd006 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java @@ -23,13 +23,13 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.FloatlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.referentiel.longline.LineType; import fr.ird.observe.services.data.longline.FloatlinesCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,7 +62,7 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -129,9 +129,4 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon super.afterSave(refresh); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 6d1421f..98b64bf 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.table.impl.longline; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; @@ -117,7 +116,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedTripLonglineId(); @@ -538,9 +537,4 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java index 40cc700..765f2c5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.HooksComposition; import fr.ird.observe.entities.longline.SetLongline; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.referentiel.longline.HookSize; import fr.ird.observe.entities.referentiel.longline.HookType; import fr.ird.observe.services.data.longline.HooksCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -63,7 +63,7 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -127,12 +127,6 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override public void afterSave(boolean refresh) { super.afterSave(refresh); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java index 662960c..cbdf74d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java @@ -28,7 +28,6 @@ import com.google.common.io.Files; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SensorUsed; @@ -38,6 +37,7 @@ import fr.ird.observe.entities.referentiel.longline.SensorType; import fr.ird.observe.services.data.longline.SensorUsedService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -80,7 +80,7 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedActivityId(); @@ -243,10 +243,4 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java index f2fee7c..973161c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java @@ -39,6 +39,7 @@ import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.services.data.longline.TdrService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; @@ -121,7 +122,7 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -485,9 +486,4 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index 9416c2f..c030953 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -23,11 +23,8 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; @@ -269,11 +266,6 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedTripSeineId(); - } - - @Override public void initUI() throws Exception { super.initUI(); @@ -293,7 +285,7 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String tripSeineId = getDataContext().getSelectedTripSeineId(); @@ -409,13 +401,6 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei getService(GearUseFeaturesSeineService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override protected void resetEditBean() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 300f200..0a96590 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -22,11 +22,7 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.constants.seine.NonTargetCatchComputedValueSource; import fr.ird.observe.entities.referentiel.Ocean; @@ -50,7 +46,6 @@ import jaxx.runtime.context.JAXXContextEntryDef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JComponent; import javax.swing.JOptionPane; @@ -218,22 +213,14 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - protected SetSeine loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean(ContentMode mode) { List<Species> speciesList; if (mode == ContentMode.UPDATE) { // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineNonTargetCatchId(); @@ -256,11 +243,6 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non if (log.isDebugEnabled()) { log.debug("speciesList = " + speciesList.size()); } - return super.loadEditBean(mode, dataContext, dataService, dataSource); - } - - @Override - protected void loadEditBean() { String setId = getDataContext().getSelectedSetId(); @@ -391,33 +373,23 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override - protected boolean doSave(SetSeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetSeine> binder) throws Exception { - try { - return super.doSave(bean, dataService, dataSource, binder); - } finally { - - // toujours supprimer la référence du context, quoiqu'il arrive - ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); - } - } - - @Override protected boolean doSave(SetSeine bean) { + try { return super.doSave(bean); + } finally { // toujours supprimer la référence du context, quoiqu'il arrive ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); } + } @Override protected boolean prepareSave(SetSeine editBean, List<NonTargetCatch> objets) throws Exception { + super.prepareSave(editBean, objets); List<Species> speciessUsed = getTableModel().getColumnValues(0); @@ -427,9 +399,9 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non NonTargetSampleService service = getService(NonTargetSampleService.class); service.getObsoleteEspeceForNonTargetSample(editBean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete); + speciessUsed, + speciessToDelete, + tailleToDelete); if (!tailleToDelete.isEmpty()) { @@ -476,21 +448,17 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } return true; + } @Override protected void doPersist(SetSeine editBean) { - List<NonTargetLength> tailleToDelete = - ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); - getService(NonTargetCatchService.class).save(editBean, tailleToDelete); - } + List<NonTargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); + NonTargetCatchService service = getService(NonTargetCatchService.class); + service.save(editBean, tailleToDelete); - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index 2bd8bfa..920fd6c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Sex; @@ -39,8 +38,6 @@ import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -117,7 +114,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam } @Override - protected void loadEditBean() { + protected void loadEditBean(ContentMode mode) { String setId = getDataContext().getSelectedSetId(); @@ -174,36 +171,29 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam } } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - @Override - protected NonTargetSample onCreate(TopiaContext tx, - Object parent, - NonTargetSample editBean) throws TopiaException { - SetSeine parentBean = (SetSeine) parent; - NonTargetSample beanToSave = - ObserveDAOHelper.getNonTargetSampleDAO(tx).create(); - if (log.isInfoEnabled()) { - log.info("Echantillon faune " + beanToSave.getTopiaId() + - " was created."); - } - editBean.setTopiaId(beanToSave.getTopiaId()); - editBean.setTopiaCreateDate(beanToSave.getTopiaCreateDate()); - editBean.setTopiaVersion(beanToSave.getTopiaVersion()); - parentBean.addNonTargetSample(beanToSave); - return beanToSave; - } - - @Override - protected void onDelete(TopiaContext tx, Object parent, NonTargetSample beanToDelete) throws TopiaException { - SetSeine parentBean = (SetSeine) parent; - parentBean.removeNonTargetSample(beanToDelete); - } +// @Override +// protected NonTargetSample onCreate(TopiaContext tx, +// Object parent, +// NonTargetSample editBean) throws TopiaException { +// SetSeine parentBean = (SetSeine) parent; +// NonTargetSample beanToSave = +// ObserveDAOHelper.getNonTargetSampleDAO(tx).create(); +// if (log.isInfoEnabled()) { +// log.info("Echantillon faune " + beanToSave.getTopiaId() + +// " was created."); +// } +// editBean.setTopiaId(beanToSave.getTopiaId()); +// editBean.setTopiaCreateDate(beanToSave.getTopiaCreateDate()); +// editBean.setTopiaVersion(beanToSave.getTopiaVersion()); +// parentBean.addNonTargetSample(beanToSave); +// return beanToSave; +// } + +// @Override +// protected void onDelete(TopiaContext tx, Object parent, NonTargetSample beanToDelete) throws TopiaException { +// SetSeine parentBean = (SetSeine) parent; +// parentBean.removeNonTargetSample(beanToDelete); +// } @SuppressWarnings("unchecked") @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index 04d98f4..f012ad7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.seine.SpeciesStatus; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.services.data.seine.ObjectObservedSpeciesService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -60,7 +60,7 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); @@ -110,7 +110,7 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati // add a listPredicate to get only species from the correct configured speciesList ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineObjectObservedSpeciesId(); - prepareSpeciesList(speciesListId, getUi().getSpecies(),n("observe.error.speciesList.seine.objectObservedSpecies.notFound")); + prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.seine.objectObservedSpecies.notFound")); super.initUI(); @@ -121,12 +121,4 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati getService(ObjectObservedSpeciesService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java index 49902b0..2245c1e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java @@ -23,13 +23,13 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.services.data.seine.ObjectSchoolEstimateService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,7 +45,6 @@ import static org.nuiton.i18n.I18n.n; */ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<FloatingObject, ObjectSchoolEstimate> { - /** Logger */ static private Log log = LogFactory.getLog(ObjectSchoolEstimateUIHandler.class); @@ -60,7 +59,7 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); @@ -118,13 +117,4 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin getService(ObjectSchoolEstimateService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index bc72d5d..ec3d09b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; @@ -73,7 +72,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setSeineId = getDataContext().getSelectedSetId(); @@ -175,10 +174,4 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch getService(SchoolEstimateService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java index 6d0361c..d9a3e19 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java @@ -21,14 +21,10 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; -import fr.ird.observe.DecoratorService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Species; @@ -37,9 +33,10 @@ import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.NonTargetCatchService; import fr.ird.observe.services.data.seine.TargetSampleService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -47,14 +44,9 @@ import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.editor.bean.BeanComboBox; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JComponent; import javax.swing.JOptionPane; @@ -92,13 +84,6 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target JAXXContextEntryDef<List<WeightCategory>> ALL_CATEGORIES_ENTRY = UIHelper.newListContextEntryDef("TargetCatchUI-all-categories"); - TopiaExecutor<WeightCategory> weightCategoryTopiaExecutor = new TopiaExecutor<WeightCategory>() { - @Override - public void execute(TopiaContext tx, WeightCategory bean) { - getDecoratorService().decorate(bean.getSpecies()); - } - }; - public TargetCatchUIHandler(TargetCatchUI ui) { super(ui, DataContextType.SetSeine); } @@ -142,15 +127,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - protected SetSeine loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean(ContentMode mode) { List<Species> speciesList; List<WeightCategory> categorieList; @@ -159,10 +136,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // on charge le formulaire uniquement si en mode édition - categorieList = new ArrayList<WeightCategory>( - dataService.loadDecoratedEntities(dataSource, - WeightCategory.class, - weightCategoryTopiaExecutor)); + categorieList = getService(ReferentialService.class).loadDecoratedWeightCategory(); // Keep only weight categories for the species ObserveConfig config = getUi().getContextValue(ObserveConfig.class); @@ -170,14 +144,13 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target java.util.Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); - categorieList = Species2.filterWeightCategoryBySpeciesIds( - categorieList, speciesIds); + categorieList = Species2.filterWeightCategoryBySpeciesIds(categorieList, speciesIds); // filtre par status actif ReferenceEntities.filterReferentielListByStatus(categorieList); // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); // filtre par ocean categorieList = Species2.filterWeightCategoryByOcean(categorieList, ocean); @@ -200,48 +173,53 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target ui.getSpecies().setData(speciesList); - return super.loadEditBean(mode, dataContext, dataService, dataSource); - } + String setId = getDataContext().getSelectedSetId(); + + SetSeine setSeine = getService(NonTargetCatchService.class).loadForEdit(setId); + + copy(SetSeine.class, BinderService.EDIT_TARGET_CATCH, setSeine, getBean()); - @Override - protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { - Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); - Collection<TargetCatch> data = new ArrayList<TargetCatch>(); - if (CollectionUtils.isNotEmpty(childs)) { - TopiaDAO<TargetCatch> dao = - getDataSource().getDAO(tx, getTableEditBean()); - TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); - - DecoratorService decoratorService = getDecoratorService(); - - for (TargetCatch c : childs) { - if (c.isDiscarded()) { - // c'est un rejet, on ne le retient pas dans cette liste - if (log.isDebugEnabled()) { - log.debug("targetDiscarded " + c.getSpecies().getLabel2() + - " non retenu."); - } - continue; - } - try { - - TargetCatch c2 = getModel().newTableEditBean(); - TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); - WeightCategory weightCategory = safeC.getWeightCategory(); - if (weightCategory != null) { - Species species = weightCategory.getSpecies(); - decoratorService.decorate(species); - } - childLoador.load(safeC, c2, true); - data.add(c2); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - return data; } +// @Override +// protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { +// Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); +// Collection<TargetCatch> data = new ArrayList<TargetCatch>(); +// if (CollectionUtils.isNotEmpty(childs)) { +// TopiaDAO<TargetCatch> dao = +// getDataSource().getDAO(tx, getTableEditBean()); +// TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); +// +// DecoratorService decoratorService = getDecoratorService(); +// +// for (TargetCatch c : childs) { +// if (c.isDiscarded()) { +// // c'est un rejet, on ne le retient pas dans cette liste +// if (log.isDebugEnabled()) { +// log.debug("targetDiscarded " + c.getSpecies().getLabel2() + +// " non retenu."); +// } +// continue; +// } +// try { +// +// TargetCatch c2 = getModel().newTableEditBean(); +// TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); +// WeightCategory weightCategory = safeC.getWeightCategory(); +// if (weightCategory != null) { +// Species species = weightCategory.getSpecies(); +// decoratorService.decorate(species); +// } +// childLoador.load(safeC, c2, true); +// data.add(c2); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// } +// return data; +// } + @Override protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { @@ -320,37 +298,37 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target return true; } - @Override - protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { - - if (oldChilds != null && !oldChilds.isEmpty()) { - - // on reinjecte les rejet thon precedemment saisie dans la set - for (TargetCatch targetCatch : oldChilds) { - if (targetCatch.isDiscarded()) { - bean.addTargetCatch(targetCatch); - } - } - } - - - List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); - - if (tailleToDelete != null && !tailleToDelete.isEmpty()) { - - // on a demande la suppression de taille obsoletes - - if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + - " obsolete targetLength(s)."); - } - - TargetSample echantillon = bean.getTargetSample(false); - - // on supprime les echantillons obsoletes - echantillon.getTargetLength().removeAll(tailleToDelete); - } - } +// @Override +// protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { +// +// if (oldChilds != null && !oldChilds.isEmpty()) { +// +// // on reinjecte les rejet thon precedemment saisie dans la set +// for (TargetCatch targetCatch : oldChilds) { +// if (targetCatch.isDiscarded()) { +// bean.addTargetCatch(targetCatch); +// } +// } +// } +// +// +// List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); +// +// if (tailleToDelete != null && !tailleToDelete.isEmpty()) { +// +// // on a demande la suppression de taille obsoletes +// +// if (log.isInfoEnabled()) { +// log.info("Will remove " + tailleToDelete.size() + +// " obsolete targetLength(s)."); +// } +// +// TargetSample echantillon = bean.getTargetSample(false); +// +// // on supprime les echantillons obsoletes +// echantillon.getTargetLength().removeAll(tailleToDelete); +// } +// } @Override protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { @@ -466,8 +444,8 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } protected List<WeightCategory> getAllCategories(JAXXContext context) { - List<WeightCategory> list = new ArrayList<WeightCategory>( - ALL_CATEGORIES_ENTRY.getContextValue(context)); + List<WeightCategory> list = new ArrayList<WeightCategory>(ALL_CATEGORIES_ENTRY.getContextValue(context)); return list; } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java index 22bd908..f1ad697 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java @@ -21,14 +21,9 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; -import fr.ird.observe.DecoratorService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Species; @@ -38,9 +33,8 @@ import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.data.seine.TargetSampleService; +import fr.ird.observe.services.data.seine.NonTargetCatchService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -49,17 +43,10 @@ import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.editor.bean.BeanComboBox; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JComponent; -import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; @@ -73,7 +60,6 @@ import java.util.Iterator; import java.util.List; import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; /** * @author Tony Chemit - chemit@codelutin.com @@ -93,13 +79,6 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, JAXXContextEntryDef<List<TargetLength>> ALL_TAILLES_TO_DELETE_ENTRY = UIHelper.newListContextEntryDef("RejetThonUI-all-taille-to-delete"); - TopiaExecutor<WeightCategory> weightCategoryTopiaExecutor = new TopiaExecutor<WeightCategory>() { - @Override - public void execute(TopiaContext tx, WeightCategory bean) { - getDecoratorService().decorate(bean.getSpecies()); - } - }; - public TargetDiscardCatchUIHandler(TargetDiscardCatchUI ui) { super(ui, DataContextType.SetSeine); } @@ -197,15 +176,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - protected SetSeine loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean(ContentMode mode) { List<WeightCategory> categorieList; List<ReasonForDiscard> reasonForDiscardList; @@ -214,31 +185,26 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // on charge le formulaire uniquement si en mode édition - categorieList = new ArrayList<WeightCategory>( - dataService.loadDecoratedEntities( - dataSource, - WeightCategory.class, - weightCategoryTopiaExecutor) - ); + ReferentialService service = getService(ReferentialService.class); + + categorieList = service.loadDecoratedWeightCategory(); // filtre sur la liste d'espèce configuree ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineTargetCatchId(); java.util.Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); - categorieList = Species2.filterWeightCategoryBySpeciesIds( - categorieList, speciesIds); + categorieList = Species2.filterWeightCategoryBySpeciesIds(categorieList, speciesIds); // filtre par status actif ReferenceEntities.filterReferentielListByStatus(categorieList); // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); // filtre par ocean categorieList = Species2.filterWeightCategoryByOcean(categorieList, ocean); - ReferentialService service = getService(ReferentialService.class); reasonForDiscardList = service.loadAndDecorateList(ReasonForDiscard.class); // filtre par status actif @@ -255,178 +221,188 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, ALL_CATEGORIES_ENTRY.setContextValue(ui, categorieList); ALL_RAISONS_REJET_ENTRY.setContextValue(ui, reasonForDiscardList); - return super.loadEditBean(mode, dataContext, dataService, dataSource); - } - - @Override - protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { - Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); - Collection<TargetCatch> data = new ArrayList<TargetCatch>(); - if (CollectionUtils.isNotEmpty(childs)) { - TopiaDAO<TargetCatch> dao = - getDataSource().getDAO(tx, getTableEditBean()); - TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); - DecoratorService decoratorService = getDecoratorService(); - for (TargetCatch c : childs) { - if (!c.isDiscarded()) { - // ce n'est pas un rejet, on ne le retient pas dans cette - // liste - if (log.isDebugEnabled()) { - log.debug("targetCatch " + c.getSpecies().getLabel2() + " non retenu."); - } - continue; - } - try { - TargetCatch c2 = getModel().newTableEditBean(); - TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); - WeightCategory weightCategory = safeC.getWeightCategory(); - if (weightCategory != null) { - Species species = weightCategory.getSpecies(); - decoratorService.decorate(species); - } - childLoador.load(safeC, c2, true); - data.add(c2); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - return data; - } - - @Override - protected boolean doSave(SetSeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetSeine> binder) throws Exception { - try { - return super.doSave(bean, dataService, dataSource, binder); - } finally { - - // toujours supprimer la référence du context, quoiqu'il arrive - ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); - } - } - - @Override - protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { - - // on recupere les speciess acceptables pour des echantillonnages - // i.e une species d'un targetDiscarded montee sur le pont - - java.util.Set<Species> speciessUsed = new HashSet<Species>(); - for (TargetCatch c : objets) { - if (c.getBroughtOnDeck() != null && c.getBroughtOnDeck()) { - speciessUsed.add(c.getSpecies()); - } - } - - // il faut supprimer les echantillon thons sur des speciess qui ne - // sont plus sur un rejet - - List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); - java.util.Set<Species> speciessToDelete = new HashSet<Species>(); + String setId = getDataContext().getSelectedSetId(); - TargetSampleService service = getService(TargetSampleService.class); - service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete, - true); + SetSeine setSeine = getService(NonTargetCatchService.class).loadForEdit(setId); - if (!tailleToDelete.isEmpty()) { + copy(SetSeine.class, BinderService.EDIT_DISCARD_TARGET_CATCH, setSeine, getBean()); - // il existe des echantillon thon a supprimer on demande une - // confirmation - StringBuilder sb = new StringBuilder(512); - StringBuilder sb2 = new StringBuilder(512); - Decorator<Species> decorator = - getDecoratorService().getDecoratorByType(Species.class); - Decorator<TargetLength> decorator2 = - getDecoratorService().getDecoratorByType(TargetLength.class); - - for (Species e : speciessToDelete) { - sb.append(" - ").append(decorator.toString(e)).append('\n'); - } - for (TargetLength t : tailleToDelete) { - sb2.append(" - ").append(decorator2.toString(t)).append('\n'); - } - int reponse = UIHelper.askUser( - t("observe.title.need.confirm"), - t("observe.targetDiscarded.message.table.will.delete.targetLength", sb.toString(), sb2.toString()), - JOptionPane.ERROR_MESSAGE, - new Object[]{ - t("observe.choice.continue"), - t("observe.choice.cancel")}, - 0); - if (log.isDebugEnabled()) { - log.debug("response : " + reponse); - } - boolean canContinue = false; - switch (reponse) { - case 0: - // wil reset ui - canContinue = true; - break; - } - - if (!canContinue) { - - // l'utilisateur a choisi de ne pas continuer - return false; - } - - // on conserve les tailles a supprimer - ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); - } - - // mise a jour de la propriete targetDiscarded - bean.setTargetDiscarded(!objets.isEmpty()); - - for (TargetCatch discarded : objets) { - - // FIXME : on devrait pas a avoir a repositionner la propriete discarded - discarded.setDiscarded(true); - - // on attache la set - discarded.setSetSeine(bean); - } - - return true; } - @Override - protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { - - if (oldChilds != null && !oldChilds.isEmpty()) { - - // on reinjecte les discarded thon precedemment saisies dans la set - // et qui ne sont pas des rejets - - for (TargetCatch targetCatch : oldChilds) { - if (!targetCatch.isDiscarded()) { - bean.addTargetCatch(targetCatch); - } - } - } - - List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); - - if (tailleToDelete != null && !tailleToDelete.isEmpty()) { - - // on a demande la suppression de taille obsoletes - - if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + - " obsolete targetLength(s)."); - } - - TargetSample echantillon = bean.getTargetSample(true); - - // on supprime les echantillons obsoletes - echantillon.getTargetLength().removeAll(tailleToDelete); - } - } +// @Override +// protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { +// return dataContext.getSelectedSetId(); +// } + +// @Override +// protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { +// Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); +// Collection<TargetCatch> data = new ArrayList<TargetCatch>(); +// if (CollectionUtils.isNotEmpty(childs)) { +// TopiaDAO<TargetCatch> dao = +// getDataSource().getDAO(tx, getTableEditBean()); +// TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); +// DecoratorService decoratorService = getDecoratorService(); +// for (TargetCatch c : childs) { +// if (!c.isDiscarded()) { +// // ce n'est pas un rejet, on ne le retient pas dans cette +// // liste +// if (log.isDebugEnabled()) { +// log.debug("targetCatch " + c.getSpecies().getLabel2() + " non retenu."); +// } +// continue; +// } +// try { +// TargetCatch c2 = getModel().newTableEditBean(); +// TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); +// WeightCategory weightCategory = safeC.getWeightCategory(); +// if (weightCategory != null) { +// Species species = weightCategory.getSpecies(); +// decoratorService.decorate(species); +// } +// childLoador.load(safeC, c2, true); +// data.add(c2); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// } +// return data; +// } + +// @Override +// protected boolean doSave(SetSeine bean, +// DataService dataService, +// DataSource dataSource, +// TopiaEntityBinder<SetSeine> binder) throws Exception { +// try { +// return super.doSave(bean, dataService, dataSource, binder); +// } finally { +// +// // toujours supprimer la référence du context, quoiqu'il arrive +// ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); +// } +// } + +// @Override +// protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { +// +// // on recupere les speciess acceptables pour des echantillonnages +// // i.e une species d'un targetDiscarded montee sur le pont +// +// java.util.Set<Species> speciessUsed = new HashSet<Species>(); +// for (TargetCatch c : objets) { +// if (c.getBroughtOnDeck() != null && c.getBroughtOnDeck()) { +// speciessUsed.add(c.getSpecies()); +// } +// } +// +// // il faut supprimer les echantillon thons sur des speciess qui ne +// // sont plus sur un rejet +// +// List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); +// java.util.Set<Species> speciessToDelete = new HashSet<Species>(); +// +// TargetSampleService service = getService(TargetSampleService.class); +// service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), +// speciessUsed, +// speciessToDelete, +// tailleToDelete, +// true); +// +// if (!tailleToDelete.isEmpty()) { +// +// // il existe des echantillon thon a supprimer on demande une +// // confirmation +// StringBuilder sb = new StringBuilder(512); +// StringBuilder sb2 = new StringBuilder(512); +// Decorator<Species> decorator = +// getDecoratorService().getDecoratorByType(Species.class); +// Decorator<TargetLength> decorator2 = +// getDecoratorService().getDecoratorByType(TargetLength.class); +// +// for (Species e : speciessToDelete) { +// sb.append(" - ").append(decorator.toString(e)).append('\n'); +// } +// for (TargetLength t : tailleToDelete) { +// sb2.append(" - ").append(decorator2.toString(t)).append('\n'); +// } +// int reponse = UIHelper.askUser( +// t("observe.title.need.confirm"), +// t("observe.targetDiscarded.message.table.will.delete.targetLength", sb.toString(), sb2.toString()), +// JOptionPane.ERROR_MESSAGE, +// new Object[]{ +// t("observe.choice.continue"), +// t("observe.choice.cancel")}, +// 0); +// if (log.isDebugEnabled()) { +// log.debug("response : " + reponse); +// } +// boolean canContinue = false; +// switch (reponse) { +// case 0: +// // wil reset ui +// canContinue = true; +// break; +// } +// +// if (!canContinue) { +// +// // l'utilisateur a choisi de ne pas continuer +// return false; +// } +// +// // on conserve les tailles a supprimer +// ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); +// } +// +// // mise a jour de la propriete targetDiscarded +// bean.setTargetDiscarded(!objets.isEmpty()); +// +// for (TargetCatch discarded : objets) { +// +// // FIXME : on devrait pas a avoir a repositionner la propriete discarded +// discarded.setDiscarded(true); +// +// // on attache la set +// discarded.setSetSeine(bean); +// } +// +// return true; +// } + +// @Override +// protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { +// +// if (oldChilds != null && !oldChilds.isEmpty()) { +// +// // on reinjecte les discarded thon precedemment saisies dans la set +// // et qui ne sont pas des rejets +// +// for (TargetCatch targetCatch : oldChilds) { +// if (!targetCatch.isDiscarded()) { +// bean.addTargetCatch(targetCatch); +// } +// } +// } +// +// List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); +// +// if (tailleToDelete != null && !tailleToDelete.isEmpty()) { +// +// // on a demande la suppression de taille obsoletes +// +// if (log.isInfoEnabled()) { +// log.info("Will remove " + tailleToDelete.size() + +// " obsolete targetLength(s)."); +// } +// +// TargetSample echantillon = bean.getTargetSample(true); +// +// // on supprime les echantillons obsoletes +// echantillon.getTargetLength().removeAll(tailleToDelete); +// } +// } @Override protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index 91434fa..bcfc0d7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -22,10 +22,7 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; @@ -120,20 +117,20 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T getUi().getLength().grabFocus(); } - @Override - protected String getEditBeanIdToLoad(DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { - String setId = dataContext.getSelectedSetId(); - // on doit récupérer l'unique échantillonThon de la calée - - TargetSample targetSample = getService(TargetSampleService.class).getTargetSample(setId, discarded); - String id = targetSample == null ? null : targetSample.getTopiaId(); - return id; - } +// @Override +// protected String getEditBeanIdToLoad(DataContext dataContext, +// DataService dataService, +// DataSource dataSource) throws DataSourceException { +// String setId = dataContext.getSelectedSetId(); +// // on doit récupérer l'unique échantillonThon de la calée +// +// TargetSample targetSample = getService(TargetSampleService.class).getTargetSample(setId, discarded); +// String id = targetSample == null ? null : targetSample.getTopiaId(); +// return id; +// } @Override - protected void loadEditBean() { + protected void loadEditBean(ContentMode mode) { String setId = getDataContext().getSelectedSetId(); @@ -189,13 +186,6 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T } } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override protected void onSelectedRowChanged(int editingRow, TargetLength bean, boolean create) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit b820d62b094ae70913ca6c95ccfe31f257a57672 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 15:16:21 2015 +0200 - Amélioration de la validation des activités - Revue de la cinématiques pour les écrans de type Open (ajout méthode onOpenUI) - implantation du service pour les TargetCatch - ménache! refs #7017 --- .../main/java/fr/ird/observe/BinderService.java | 128 ++--- .../fr/ird/observe/ObserveApplicationContext.java | 8 - .../java/fr/ird/observe/entities/Entities.java | 14 +- .../observe/entities/seine/ActivitySeineImpl.java | 38 +- .../ird/observe/entities/seine/ActivitySeines.java | 3 +- .../java/fr/ird/observe/entities/seine/Routes.java | 22 + .../ird/observe/entities/seine/TargetCatches.java | 24 + .../observe/services/AbstractObserveService.java | 31 -- .../data/longline/ActivityLonglineService.java | 2 - .../data/longline/ActivityLonglineServiceImpl.java | 7 +- .../services/data/longline/SetLonglineService.java | 2 +- .../data/longline/SetLonglineServiceImpl.java | 34 +- .../services/data/seine/NonTargetCatchService.java | 2 +- .../data/seine/NonTargetCatchServiceImpl.java | 13 +- .../data/seine/NonTargetSampleService.java | 13 +- .../data/seine/NonTargetSampleServiceImpl.java | 58 +-- .../observe/services/data/seine/RouteService.java | 2 - .../services/data/seine/RouteServiceImpl.java | 8 +- .../services/data/seine/SetSeineServiceImpl.java | 5 +- .../services/data/seine/TargetCatchService.java | 28 ++ .../data/seine/TargetCatchServiceImpl.java | 164 +++++++ .../services/data/seine/TargetSampleService.java | 16 +- .../data/seine/TargetSampleServiceImpl.java | 75 +-- .../services/referential/ReferentialService.java | 2 + .../referential/ReferentialServiceImpl.java | 8 + .../ird/observe/ui/content/ContentUIHandler.java | 69 +-- .../fr/ird/observe/ui/content/ContentUIModel.java | 26 -- .../LonglineGlobalCompositionUIHandler.java | 6 +- .../impl/longline/SetLonglineUIHandler.java | 10 +- .../ActivitySeineObservedSystemUIHandler.java | 1 + .../ui/content/impl/seine/SetSeineUIHandler.java | 6 +- .../ui/content/open/ContentOpenableUIHandler.java | 43 +- .../impl/longline/ActivityLonglineUIHandler.java | 62 +-- .../open/impl/longline/TripLonglineUIHandler.java | 39 +- .../open/impl/seine/ActivitySeineUIHandler.java | 79 ++-- .../ui/content/open/impl/seine/RouteUIHandler.java | 139 ++---- .../open/impl/seine/TripSeineUIHandler.java | 38 +- .../ui/content/table/ContentTableUIHandler.java | 450 ++++++------------ .../ui/content/table/ContentTableUIModel.java | 2 +- .../impl/longline/SizeMeasuresTableModel.java | 3 +- .../impl/longline/WeightMeasuresTableModel.java | 3 +- .../table/impl/seine/NonTargetCatchUIHandler.java | 299 ++++++------ .../table/impl/seine/NonTargetSampleUIHandler.java | 134 +++--- .../impl/seine/ObjectObservedSpeciesUIHandler.java | 8 +- .../table/impl/seine/TargetCatchUIHandler.java | 293 +++++------- .../impl/seine/TargetDiscardCatchUIHandler.java | 514 +++++++++------------ .../table/impl/seine/TargetSampleUIHandler.java | 2 +- .../fr/ird/observe/ui/tree/SetLonglineNode.java | 2 +- .../field/VesselActivityFieldValidator.java | 52 +-- 49 files changed, 1343 insertions(+), 1644 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 0874332..a0cfdba 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -21,6 +21,8 @@ */ package fr.ird.observe; +import com.google.common.base.Preconditions; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.BaitsComposition; import fr.ird.observe.entities.longline.Basket; @@ -122,7 +124,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderModelBuilder; @@ -226,6 +227,8 @@ public class BinderService { I18nReferenceEntity.PROPERTY_LABEL8 }; + public static final String SIMPLE = "Observe"; + static { try { @@ -253,7 +256,6 @@ public class BinderService { } - public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { copyExcluding(type, context, source, target, true, propertyNames); @@ -292,40 +294,41 @@ public class BinderService { return binder; } + public <E extends TopiaEntity> void simpleCopy(E source, E target, boolean tech) { + Class<E> entityClass = Entities.getContract(target); + TopiaEntityBinder<E> binder = getBinder(entityClass, SIMPLE); + binder.load(source, target, tech); + } - public static <E extends TopiaEntity> BinderModelBuilder<E, E> newBinderBuilder(Class<E> type, String... properties) { + protected static <E extends TopiaEntity> BinderModelBuilder<E, E> newBinderBuilder(Class<E> type, String... properties) { BinderModelBuilder<E, E> builder = BinderModelBuilder.newEmptyBuilder(type); builder.addSimpleProperties(properties); return builder; } - public <E extends TopiaEntity> TopiaEntityBinder<E> getTopiaBinder(Class<E> entityClass, - String contextName) { + @SuppressWarnings("unchecked") + protected <E extends TopiaEntity> TopiaEntityBinder<E> getTopiaBinder(Class<E> entityClass, String contextName) { + + TopiaEntityBinder<E> binder; if (ObserveBinderHelper.getCachedBinderModel(entityClass, entityClass, contextName) == null) { // we do not want to have auto created binder model by the factory - return null; + binder = null; + } else { + + binder = (TopiaEntityBinder<E>) + ObserveBinderHelper.newBinder(entityClass, entityClass, contextName, TopiaEntityBinder.class); + } - return (TopiaEntityBinder<E>) ObserveBinderHelper.newBinder(entityClass, entityClass, contextName, TopiaEntityBinder.class); + return binder; } - public static <E extends TopiaEntity> TopiaEntityBinder<E> registerTopiaBinder(Class<E> entityClass, + protected static <E extends TopiaEntity> TopiaEntityBinder<E> registerTopiaBinder(Class<E> entityClass, BinderModelBuilder<E, E> builder, String contextName) { - return ObserveBinderHelper.registerTopiaBinder(entityClass, builder, contextName); - } - - public <E extends TopiaEntity> TopiaEntityBinder<E> getSimpleTopiaBinder(Class<E> entityClass) { - return getTopiaBinder(entityClass, "Observe"); - } - public <E extends TopiaEntity> void simpleCopy(E source, E target, boolean tech) { - Class<E> entityClass = (Class<E>) TopiaEntityHelper.getContractClass(ObserveDAOHelper.getContracts(), target.getClass()); - TopiaEntityBinder<E> binder = getSimpleTopiaBinder(entityClass); - if (binder == null) { - throw new NullPointerException("could not find a simple topia binder of type : " + target.getClass()); - } - binder.load(source, target, tech); + Preconditions.checkArgument(ObserveBinderHelper.getCachedBinderModel(entityClass, entityClass, contextName) == null, "there is already a bindermodel resigtred for type " + entityClass + " and context " + contextName); + return ObserveBinderHelper.registerTopiaBinder(entityClass, builder, contextName); } protected static void registerSeineBinders() { @@ -535,69 +538,6 @@ public class BinderService { { - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_QUADRANT, - ActivitySeine.PROPERTY_LATITUDE, - ActivitySeine.PROPERTY_LONGITUDE, - ActivitySeine.PROPERTY_ERS_ID, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, - ActivitySeine.PROPERTY_COMMENT, - ActivitySeine.PROPERTY_VESSEL_SPEED, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, - ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_DETECTION_MODE, - ActivitySeine.PROPERTY_SET_SEINE, - ActivitySeine.PROPERTY_FLOATING_OBJECT, - ActivitySeine.PROPERTY_OPEN, - ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, - ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, - ActivitySeine.PROPERTY_NEXT_FPA_ZONE); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); - - //FIXME this one was used ? -// BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( -// ActivitySeine.class, -// ActivitySeine.PROPERTY_QUADRANT, -// ActivitySeine.PROPERTY_LATITUDE, -// ActivitySeine.PROPERTY_LONGITUDE, -// ActivitySeine.PROPERTY_TIME, -// ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, -// ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, -// ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, -// ActivitySeine.PROPERTY_WIND, -// ActivitySeine.PROPERTY_OPEN); -// - registerTopiaBinder(ActivitySeine.class, builder, EDIT); - } - - { - - BinderModelBuilder<Route, Route> builder = newBinderBuilder( - Route.class, - Route.PROPERTY_DATE, - Route.PROPERTY_START_LOG_VALUE, - Route.PROPERTY_END_LOG_VALUE, - Route.PROPERTY_CHECK_LEVEL, - Route.PROPERTY_ACTIVITY_SEINE, - Route.PROPERTY_OPEN, - Route.PROPERTY_COMMENT); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, Route.PROPERTY_ACTIVITY_SEINE); - - registerTopiaBinder(Route.class, builder, EDIT); - - } - - { - BinderModelBuilder<Route, Route> builder = newBinderBuilder( Route.class, Route.PROPERTY_DATE, @@ -878,19 +818,6 @@ public class BinderService { } - - { - - BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( - TripSeine.class, - TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); - - registerTopiaBinder(TripSeine.class, builder, EDIT_GEAR_USE_FEATURES_SEINE); - - } - { BinderModelBuilder<TripSeine, TripSeine> builder = newBinderBuilder( @@ -1548,6 +1475,13 @@ public class BinderService { protected static void registerReferentialBinders() { { + // Need to add by hand a speciesList binder + // see https://forge.codelutin.com/issues/6963 + BinderModelBuilder<SpeciesList, SpeciesList> builderModel = newBinderBuilder(SpeciesList.class); + registerTopiaBinder(SpeciesList.class, builderModel, "Observe"); + + } + { BinderModelBuilder<Program, Program> builder = newBinderBuilder( Program.class, diff --git a/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java b/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java index 1e92b58..bd17f13 100644 --- a/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java +++ b/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java @@ -25,7 +25,6 @@ import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceFactory; import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.referentiel.SpeciesList; import fr.ird.observe.gps.GPSService; import fr.ird.observe.validation.ObserveValidator; import fr.ird.observe.validation.ValidationContext; @@ -35,7 +34,6 @@ import jaxx.runtime.context.JAXXContextEntryDef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Locale; @@ -153,12 +151,6 @@ public class ObserveApplicationContext extends DefaultApplicationContext { if (service == null) { service = new BinderService(); - // Need to add by hand a speciesList binder - // see https://forge.codelutin.com/issues/6963 - BinderModelBuilder<SpeciesList, SpeciesList> builderModel= - BinderModelBuilder.newEmptyBuilder(SpeciesList.class); - service.registerTopiaBinder(SpeciesList.class, builderModel, "Observe"); - BINDER_SERVICE_ENTRY_DEF.setContextValue(this, service); } return service; diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java b/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java index 822d926..89340df 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java @@ -28,6 +28,7 @@ import fr.ird.observe.ObserveEntityEnum; import org.apache.commons.collections4.CollectionUtils; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaId; +import org.nuiton.topia.persistence.util.TopiaEntityHelper; import java.util.Arrays; import java.util.Collection; @@ -353,20 +354,25 @@ public class Entities { public static <E extends TopiaEntity> String getTableName(E entity) { ObserveEntityEnum entityEnum = ObserveEntityEnum.valueOf(entity); - return entityEnum.dbSchemaName()+"."+entityEnum.dbTableName(); + return entityEnum.dbSchemaName() + "." + entityEnum.dbTableName(); } public static boolean isSeineId(String id) { - return id.contains("Seine"); + return id.contains("Seine"); } public static boolean isLonglineId(String id) { - return id.contains("Longline"); + return id.contains("Longline"); } public static <E extends TopiaEntity> boolean isNew(E entity) { - return entity.getTopiaId()==null; + return entity.getTopiaId() == null; + } + + @SuppressWarnings("unchecked") + public static <E extends TopiaEntity> Class<E> getContract(E entity) { + return (Class<E>) TopiaEntityHelper.getContractClass(ObserveDAOHelper.getContracts(), entity.getClass()); } } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java index 7bfed7a..444539e 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineImpl.java @@ -43,26 +43,28 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { private static final long serialVersionUID = 2L; - public static final String ACTIVITY_FIN_DE_VEILLE = "16"; + public static final String ACTIVITY_FIN_DE_VEILLE_ID = "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675372#0.21399033380125898"; - public static final String ACTIVITY_DEBUT_DE_PECHE = "6"; + public static final String ACTIVITY_DEBUT_DE_PECHE_ID = "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675369#0.12552908048322586"; - public static final String ACTIVITY_DEBUT_DE_PECHE_ID = "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675369#0.027011527426829218"; + public static final String ACTIVITY_FIN_DE_PECHE_ID = "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675369#0.10731168577264139"; - public static final String ACTIVITY_FIN_DE_PECHE = "7"; + public static final String ACTIVITY_CHANGED_ZONE_ID = "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1379684416896#0.38648073770690594"; - public static final String ACTIVITY_CHANGED_ZONE = "21"; + private static final List<String> CALEE_OPERATIONS_ID = Collections.singletonList(ACTIVITY_DEBUT_DE_PECHE_ID); - private static final List<String> CALEE_OPERATIONS = Collections.singletonList(ACTIVITY_DEBUT_DE_PECHE_ID); + private static final List<String> DCP_OPERATIONS_ID = Arrays.asList( + "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675370#0.9125190289998782", + "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675371#0.15012142294280495", + "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675371#0.23195165331640677"); - private static final List<String> DCP_OPERATIONS = Arrays.asList("13", "14", "15"); - - private static final List<String> SYSTEM_OPERATIONS = Arrays.asList("0", "11", "11", ACTIVITY_FIN_DE_VEILLE); + private static final List<String> SYSTEM_OPERATIONS_ID = Arrays.asList( + "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675349#0.363119635949572", + "fr.ird.observe.entities.referentiel.seine.VesselActivitySeine#1239832675370#0.495613158646268", + ACTIVITY_FIN_DE_VEILLE_ID); public static final String PROPERTY_CHANGED_ZONE_OPERATION = "changedZoneOperation"; -// public static final String PROPERTY_SET_OPERATION = "setOperation"; - /** * La valeur du quadrant (utilisé uniquement dans l'interface graphique) : * en base on conserve cette information dans les coordonnées {@link #longitude} @@ -87,25 +89,25 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { /** @return {@code true} si l'activite concerne un DCP */ @Override public boolean isDCPOperation() { - return vesselActivitySeine != null && DCP_OPERATIONS.contains(vesselActivitySeine.getCode()); + return vesselActivitySeine != null && DCP_OPERATIONS_ID.contains(vesselActivitySeine.getTopiaId()); } /** @return {@code true} si l'activite concerne une calée */ @Override public boolean isSetOperation() { - return vesselActivitySeine != null && CALEE_OPERATIONS.contains(vesselActivitySeine.getTopiaId()); + return vesselActivitySeine != null && CALEE_OPERATIONS_ID.contains(vesselActivitySeine.getTopiaId()); } /** @return {@code true} si l'activite concerne un système observé */ @Override public boolean isObservedSystemOperation() { - return vesselActivitySeine != null && SYSTEM_OPERATIONS.contains(vesselActivitySeine.getCode()); + return vesselActivitySeine != null && SYSTEM_OPERATIONS_ID.contains(vesselActivitySeine.getTopiaId()); } /** @return {@code true} si l'activite concerne un changement de zone */ @Override public boolean isChangedZoneOperation() { - return vesselActivitySeine != null && ACTIVITY_CHANGED_ZONE.equals(vesselActivitySeine.getCode()); + return vesselActivitySeine != null && ACTIVITY_CHANGED_ZONE_ID.equals(vesselActivitySeine.getTopiaId()); } @Override @@ -125,7 +127,7 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { @Override public void setQuadrant(Integer quadrant) { if (log.isInfoEnabled()) { - log.info("New quadrant value: "+quadrant); + log.info("New quadrant value: " + quadrant); } Integer old = this.quadrant; // fireOnPreWrite(PROPERTY_QUADRANT, old, quadrant); @@ -151,7 +153,7 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { @Override public boolean isActivityFinDePeche() { - return vesselActivitySeine != null && ACTIVITY_FIN_DE_PECHE.equals(vesselActivitySeine.getCode()); + return vesselActivitySeine != null && ACTIVITY_FIN_DE_PECHE_ID.equals(vesselActivitySeine.getTopiaId()); } @Override @@ -161,7 +163,7 @@ public class ActivitySeineImpl extends ActivitySeineAbstract { @Override public boolean isActivityFinDeVeille() { - return vesselActivitySeine != null && ACTIVITY_FIN_DE_VEILLE.equals(vesselActivitySeine.getCode()); + return vesselActivitySeine != null && ACTIVITY_FIN_DE_VEILLE_ID.equals(vesselActivitySeine.getTopiaId()); } @Override diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeines.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeines.java index a3dcd99..89a923d 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeines.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeines.java @@ -48,8 +48,7 @@ public class ActivitySeines { @Override public int compare(ActivitySeine o1, ActivitySeine o2) { - return o1.getTime().compareTo( - o2.getTime()); + return o1.getTime().compareTo(o2.getTime()); } }; diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/Routes.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/Routes.java index c59c644..add626f 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/Routes.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/Routes.java @@ -22,9 +22,11 @@ package fr.ird.observe.entities.seine; * #L% */ +import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -91,4 +93,24 @@ public class Routes { return previous; } + /** + * Recupere les positions des activités d'un certain type. + * + * @param route la route à inspecter + * @param vesselActivityId l'id du type d'activité à rechercher + * @return les positions des activitys d'un certain type donné + */ + public static Integer[] detectActivities(Route route, String vesselActivityId) { + List<Integer> list = new ArrayList<Integer>(); + int index = 0; + for (ActivitySeine a : route.getActivitySeine()) { + VesselActivitySeine vesselActivitySeine = a.getVesselActivitySeine(); + if (vesselActivityId.equals(vesselActivitySeine.getTopiaId())) { + list.add(index); + } + index++; + } + return list.toArray(new Integer[list.size()]); + } + } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/TargetCatches.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/TargetCatches.java new file mode 100644 index 0000000..482cbcb --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/TargetCatches.java @@ -0,0 +1,24 @@ +package fr.ird.observe.entities.seine; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + +/** + * Created on 5/2/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TargetCatches { + + public static final Predicate<TargetCatch> TARGET_CATCH_IS_DISCARDED = new Predicate<TargetCatch>() { + @Override + public boolean apply(TargetCatch input) { + return input.isDiscarded(); + } + }; + + public static final Predicate<TargetCatch> TARGET_CATCH_IS_NOT_DISCARDED = + Predicates.not(TARGET_CATCH_IS_DISCARDED); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 2f2df05..9fa8dc1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -6,7 +6,6 @@ import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.IObserveConfig; import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceLocale; @@ -20,7 +19,6 @@ import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; import java.util.Collection; @@ -201,35 +199,6 @@ public abstract class AbstractObserveService implements ObserveService { } - - protected <E extends TopiaEntity> TopiaEntityBinder<E> loadBinder(String suffix, Class<E> entityType, CreateBinder<E> createBinder) { - - BinderService binderService = ObserveServiceHelper.get().getBinderService(); - - String binderName = getClass().getName() + suffix; - TopiaEntityBinder<E> r = binderService.getTopiaBinder(entityType, binderName); - - if (r == null) { - - BinderModelBuilder<E, E> builder = createBinder.createBinderBuilder(binderService, binderName); - r = createBinder.registerTopiaBinder(binderService, entityType, builder, binderName); - - } - - return r; - - } - - protected abstract class CreateBinder<E extends TopiaEntity> { - - public abstract BinderModelBuilder<E, E> createBinderBuilder(BinderService binderService, String name); - - public TopiaEntityBinder<E> registerTopiaBinder(BinderService binderService, Class<E> entityType, BinderModelBuilder<E, E> builder, String name) { - return binderService.registerTopiaBinder(entityType, builder, name); - } - - } - public <P extends TopiaEntity, E extends TopiaEntity> String doSave(String parentId, E toSave, SaveAction<P, E> saveAction) { E saved; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java index 3d640bc..3aaa858 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java @@ -18,8 +18,6 @@ public interface ActivityLonglineService extends ObserveService { List<ActivityLongline> getActivityLonglineStubByTrip(String tripId); - ActivityLongline loadForDisplay(String activityLonglineId); - ActivityLongline loadForEdit(String activityLonglineId); ActivityLongline preCreate(String tripLonglineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index 8a81987..20a96c5 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -38,7 +38,7 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } @Override - public ActivityLongline loadForDisplay(String activityLonglineId) { + public ActivityLongline loadForEdit(String activityLonglineId) { ActivityLongline loaded = getDao().newInstance(); ActivityLongline toLoad = getDao().findByTopiaId(activityLonglineId); @@ -48,11 +48,6 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } - @Override - public ActivityLongline loadForEdit(String activityLonglineId) { - return loadForDisplay(activityLonglineId); - } - @Override public ActivityLongline preCreate(String tripLonglineId) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java index 89c8324..a4b4902 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java @@ -15,7 +15,7 @@ import java.util.List; */ public interface SetLonglineService extends ObserveService { - SetLongline loadSet(String setLonglineId); + SetLongline loadForDisplay(String setLonglineId); List<Section> getSections(String setLonglineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index 793e631..b6e88aa 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -23,11 +23,6 @@ import java.util.List; */ public class SetLonglineServiceImpl extends AbstractObserveService implements SetLonglineService { - @Override - public SetLongline loadSet(String setLonglineId) { - return null; - } - public List<Section> getSections(String setLonglineId) { TopiaDAO<Section> dao = getDao(Section.class); @@ -69,6 +64,30 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se } @Override + public SetLongline loadForDisplay(String setLonglineId) { + + SetLonglineDAO dao = getDao(); + + SetLongline loaded = dao.newInstance(); + SetLongline toLoad = dao.findByTopiaId(setLonglineId); + copy(SetLongline.class, BinderService.EDIT, toLoad, loaded); + return loaded; + + } + + @Override + public SetLongline loadForEdit(String setLonglineId) { + + SetLonglineDAO dao = getDao(); + + SetLongline loaded = dao.newInstance(); + SetLongline toLoad = dao.findByTopiaId(setLonglineId); + copy(SetLongline.class, BinderService.EDIT, toLoad, loaded); + return loaded; + + } + + @Override public SetLongline preCreate(String activityLonglineId) { ActivityLongline activityLongline = findByTopiaId(ActivityLongline.class, activityLonglineId); @@ -98,11 +117,6 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se } @Override - public SetLongline loadForEdit(String setLonglineId) { - return null; - } - - @Override public String save(String activityLonglineId, SetLongline setLongline) { String setLonglineId = doSave(activityLonglineId, setLongline, new SaveAction<ActivityLongline, SetLongline>(ActivityLongline.class, SetLongline.class) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java index a92d6b4..59786f6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java @@ -15,6 +15,6 @@ public interface NonTargetCatchService extends ObserveService { SetSeine loadForEdit(String setId); @Commit - void save(SetSeine parent, List<NonTargetLength> tailleToDelete); + void save(SetSeine toSave, List<NonTargetLength> nonTargetLengthsToDelete); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java index c7a6139..51d5711 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java @@ -52,14 +52,16 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements } return loaded; + } @Override - public void save(SetSeine parent, final List<NonTargetLength> tailleToDelete) { + public void save(SetSeine toSave, final List<NonTargetLength> nonTargetLengthsToDelete) { + TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH); TopiaEntityBinder<NonTargetCatch> childbinder = getBinder(NonTargetCatch.class, BinderService.EDIT); - doSaveList(parent, new SaveCollectionAction<SetSeine, NonTargetCatch>( + doSaveList(toSave, new SaveCollectionAction<SetSeine, NonTargetCatch>( SetSeine.class, NonTargetCatch.class, getListUpdator(), parentBinder, childbinder) { @Override @@ -81,18 +83,18 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements @Override public void onUpdateFinalize(SetSeine parent, Collection<NonTargetCatch> oldChilds) throws TopiaException { - if (CollectionUtils.isNotEmpty(tailleToDelete)) { + if (CollectionUtils.isNotEmpty(nonTargetLengthsToDelete)) { // on a demande la suppression de taille obsoletes if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + " obsolete nonTargetSample(s)."); + log.info("Will remove " + nonTargetLengthsToDelete.size() + " obsolete nonTargetSample(s)."); } NonTargetSample echantillon = parent.getNonTargetSample().get(0); // on supprime les echantillons obsoletes - echantillon.getNonTargetLength().removeAll(tailleToDelete); + echantillon.getNonTargetLength().removeAll(nonTargetLengthsToDelete); } } @@ -106,4 +108,5 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements NonTargetCatch.class, SetSeine.PROPERTY_NON_TARGET_CATCH); } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java index c4bc584..e433ab6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java @@ -6,8 +6,8 @@ import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import java.util.Collection; import java.util.List; +import java.util.Set; /** * Created on 4/26/15. @@ -17,21 +17,18 @@ import java.util.List; */ public interface NonTargetSampleService extends ObserveService { - List<Species> getAvailableEspeceForNonTargetSample(String setSeineId); + List<Species> getAvailableSpeciesForNonTargetSample(String setSeineId); NonTargetSample getNonTargetSample(String setSeineId); boolean canUseNonTargetSample(String setSeineId); - void getObsoleteEspeceForNonTargetSample(String setSeineId, - List<Species> speciessUsed, - Collection<Species> speciessToDelete, - List<NonTargetLength> tailleToDelete); + List<NonTargetLength> getObsoleteNonTargetLengths(String setSeineId, Set<String> speciesIdsUsed); @Commit - void delete(String setId, NonTargetSample editBean); + String save(String setId, NonTargetSample editBean); @Commit - String save(String setId, NonTargetSample editBean); + void delete(String setId, NonTargetSample editBean); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index b453188..d7a0983 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -16,6 +16,7 @@ import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Set; /** * Created on 4/26/15. @@ -33,7 +34,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public List<Species> getAvailableEspeceForNonTargetSample(String setSeineId) { + public List<Species> getAvailableSpeciesForNonTargetSample(String setSeineId) { List<Species> speciesList = new ArrayList<Species>(); @@ -110,36 +111,38 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public void getObsoleteEspeceForNonTargetSample(String setSeineId, - List<Species> speciessUsed, - Collection<Species> speciessToDelete, - List<NonTargetLength> tailleToDelete) { + public List<NonTargetLength> getObsoleteNonTargetLengths(String setSeineId, Set<String> speciessUsed) { SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - if (setSeine.isNonTargetSampleEmpty()) { - return; - } + List<NonTargetLength> nonTargetLengthsToDelete = new ArrayList<NonTargetLength>(); - NonTargetSample echantillon = setSeine.getNonTargetSample().get(0); + if (!setSeine.isNonTargetSampleEmpty()) { - if (echantillon.isNonTargetLengthEmpty()) { - return; - } + NonTargetSample nonTargetSample = setSeine.getNonTargetSample().get(0); + + if (!nonTargetSample.isNonTargetLengthEmpty()) { + + for (NonTargetLength taille : nonTargetSample.getNonTargetLength()) { + + Species species = taille.getSpecies(); + if (!speciessUsed.contains(species.getTopiaId())) { + + // l'espèce n'existe plus dans les rejet faune, on doit le supprimer + nonTargetLengthsToDelete.add(taille); + if (log.isDebugEnabled()) { + log.debug("remove obsolote echantillon " + taille + " for species " + species); + } + + } - for (NonTargetLength taille : echantillon.getNonTargetLength()) { - Species tailleEspece = taille.getSpecies(); - if (!speciessUsed.contains(tailleEspece)) { - // l'species n'existe plus dans les rejet faune, - // on doit le supprimer - tailleToDelete.add(taille); - speciessToDelete.add(tailleEspece); - if (log.isDebugEnabled()) { - log.debug("remove obsolote echantillon " + taille + " for species " + tailleEspece); } + } + } + return nonTargetLengthsToDelete; } @@ -161,11 +164,11 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public NonTargetSample onUpdate(SetSeine parentBean, NonTargetSample toSave, NonTargetSample beanToSave) { + public NonTargetSample onUpdate(SetSeine parentBean, NonTargetSample toUpdate, NonTargetSample updated) { - copyExcluding(NonTargetSample.class, BinderService.EDIT, toSave, beanToSave, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - getDao().update(beanToSave); - return beanToSave; + copyExcluding(NonTargetSample.class, BinderService.EDIT, toUpdate, updated, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + getDao().update(updated); + return updated; } }); @@ -175,8 +178,9 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public void delete(String setId, NonTargetSample bean) { - doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + public void delete(String setId, NonTargetSample toDelete) { + + doDelete(setId, toDelete.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { @Override public void onDelete(SetSeine parent, NonTargetSample toDelete) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java index 72efcf3..76976c9 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java @@ -18,8 +18,6 @@ public interface RouteService extends ObserveService { Route getRouteStub(String routeId); - Route loadForDisplay(String routeId); - Route loadForEdit(String routeId); Route preCreate(String tripSeineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index c524c74..533f3a7 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -37,7 +37,7 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer } @Override - public Route loadForDisplay(String routeId) { + public Route loadForEdit(String routeId) { Route loaded = getDao().newInstance(); Route toLoad = getDao().findByTopiaId(routeId); @@ -54,12 +54,6 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer } @Override - public Route loadForEdit(String routeId) { - Route loaded = loadForDisplay(routeId); - return loaded; - } - - @Override public Route preCreate(String tripSeineId) { TripSeine tripLongline = findByTopiaId(TripSeine.class, tripSeineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java index ed9bd24..87b0113 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java @@ -38,8 +38,9 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe @Override public SetSeine loadForEdit(String setSeineId) { - SetSeine loaded = getDao().newInstance(); - SetSeine toLoad = getDao().findByTopiaId(setSeineId); + SetSeineDAO dao = getDao(); + SetSeine loaded = dao.newInstance(); + SetSeine toLoad = dao.findByTopiaId(setSeineId); copy(SetSeine.class, BinderService.EDIT, toLoad, loaded); //FIXME See why need this ? diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchService.java new file mode 100644 index 0000000..0ae9764 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchService.java @@ -0,0 +1,28 @@ +package fr.ird.observe.services.data.seine; + +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +import java.util.List; + +/** + * Created on 5/2/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface TargetCatchService extends ObserveService { + + SetSeine loadForEdit(String setSeineId); + + SetSeine loadForEditDiscarded(String setSeineId); + + @Commit + void save(SetSeine setSeinetoSave, List<TargetLength> targetLengthsToDelete); + + @Commit + void saveForDiscarded(SetSeine setSeinetoSave, List<TargetLength> targetLengthsToDelete); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java new file mode 100644 index 0000000..e2155d1 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java @@ -0,0 +1,164 @@ +package fr.ird.observe.services.data.seine; + +import com.google.common.base.Predicate; +import fr.ird.observe.BinderService; +import fr.ird.observe.entities.referentiel.seine.WeightCategory; +import fr.ird.observe.entities.seine.SetSeine; +import fr.ird.observe.entities.seine.TargetCatch; +import fr.ird.observe.entities.seine.TargetCatches; +import fr.ird.observe.entities.seine.TargetLength; +import fr.ird.observe.entities.seine.TargetSample; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.referential.ReferentialService; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Created on 5/2/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TargetCatchServiceImpl extends AbstractObserveService implements TargetCatchService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(TargetCatchServiceImpl.class); + + @Override + public SetSeine loadForEdit(String setSeineId) { + + SetSeine loaded = load(setSeineId, BinderService.EDIT_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_NOT_DISCARDED); + return loaded; + + } + + @Override + public SetSeine loadForEditDiscarded(String setSeineId) { + + SetSeine loaded = load(setSeineId, BinderService.EDIT_DISCARD_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_DISCARDED); + return loaded; + + } + + @Override + public void save(SetSeine setSeinetoSave, final List<TargetLength> targetLengthsToDelete) { + + save(setSeinetoSave, BinderService.EDIT_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_NOT_DISCARDED, targetLengthsToDelete); + + } + + @Override + public void saveForDiscarded(SetSeine setSeinetoSave, final List<TargetLength> targetLengthsToDelete) { + + save(setSeinetoSave, BinderService.EDIT_DISCARD_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_DISCARDED, targetLengthsToDelete); + + } + + protected SetSeine load(String setId, String binderContext, Predicate<TargetCatch> predicate) { + + TopiaDAO<SetSeine> setSeineDao = getDao(SetSeine.class); + SetSeine toLoad = setSeineDao.findByTopiaId(setId); + SetSeine loaded = setSeineDao.newInstance(); + + copyExcluding(SetSeine.class, binderContext, toLoad, loaded, SetSeine.PROPERTY_TARGET_CATCH); + + if (!toLoad.isTargetCatchEmpty()) { + + ReferentialService referentialService = newService(ReferentialService.class); + + TopiaDAO<TargetCatch> dao = getDao(TargetCatch.class); + TopiaEntityBinder<TargetCatch> binder = getBinder(TargetCatch.class, binderContext); + + List<TargetCatch> childsLoaded = new ArrayList<TargetCatch>(); + + for (TargetCatch childToLoad : toLoad.getTargetCatch()) { + + if (predicate.apply(childToLoad)) { + + WeightCategory weightCategory = childToLoad.getWeightCategory(); + if (weightCategory != null) { + referentialService.loadDecoratedWeightCategory(weightCategory); + } + + TargetCatch childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + childsLoaded.add(childLoaded); + + } + + } + + loaded.setTargetCatch(childsLoaded); + + } + + return loaded; + + } + + void save(SetSeine setSeinetoSave, String binderContext, final Predicate<TargetCatch> predicate, final List<TargetLength> targetLengthsToDelete) { + + TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, binderContext); + TopiaEntityBinder<TargetCatch> childBinder = getBinder(TargetCatch.class, binderContext); + + doSaveList(setSeinetoSave, new SaveCollectionAction<SetSeine, TargetCatch>( + SetSeine.class, TargetCatch.class, getListUpdator(), parentBinder, childBinder) { + + @Override + public void onUpdateFinalize(SetSeine parent, Collection<TargetCatch> oldChilds) throws TopiaException { + + if (CollectionUtils.isNotEmpty(oldChilds)) { + + Collection<TargetCatch> targetCatchesToReinject = new ArrayList<TargetCatch>(); + + for (TargetCatch oldChild : oldChilds) { + + if (predicate.apply(oldChild)) { + + // on réinjecte cette capture + targetCatchesToReinject.add(oldChild); + + } + + } + + parent.addAllTargetCatch(targetCatchesToReinject); + + } + + if (CollectionUtils.isNotEmpty(targetLengthsToDelete)) { + + // suppression des échantillons obsoletes + + if (log.isInfoEnabled()) { + log.info("Will remove " + targetLengthsToDelete.size() + " obsolete targetLength(s)."); + } + + TargetSample targetSample = parent.getTargetSample().get(0); + + // on supprime les echantillons obsoletes + targetSample.getTargetLength().removeAll(targetLengthsToDelete); + + } + } + }); + + } + + protected EntityListUpdator<SetSeine, TargetCatch> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + SetSeine.class, + TargetCatch.class, + SetSeine.PROPERTY_TARGET_CATCH); + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java index 689f730..c1b2d32 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java @@ -6,8 +6,8 @@ import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import java.util.Collection; import java.util.List; +import java.util.Set; /** * Created on 4/26/15. @@ -17,20 +17,18 @@ import java.util.List; */ public interface TargetSampleService extends ObserveService { - List<Species> getAvailableEspeceForTargetSample(String setSeineId, boolean discarded); + List<Species> getAvailableSpeciesForTargetSample(String setSeineId, boolean discarded); + + List<TargetLength> getObsoleteTargetLengths(String setSeineId, Set<String> speciesIdsUsed, boolean discarded); TargetSample getTargetSample(String setSeineId, boolean discarded); boolean canUseTargetSample(String setSeineId, boolean discarded); - void getObsoleteEspeceForTargetSample(String setSeineId, - Collection<Species> speciessUsed, - Collection<Species> speciessToDelete, - List<TargetLength> tailleToDelete, - boolean discarded); @Commit - void delete(String setId, TargetSample bean); + String save(String setSeineId, TargetSample toSave); @Commit - String save(String setSeineId, TargetSample toSave); + void delete(String setId, TargetSample bean); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 2ce82b8..8735b1b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -16,6 +16,7 @@ import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Set; /** * Created on 4/26/15. @@ -37,7 +38,7 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } @Override - public List<Species> getAvailableEspeceForTargetSample(String setSeineId, boolean discarded) { + public List<Species> getAvailableSpeciesForTargetSample(String setSeineId, boolean discarded) { List<Species> speciesList = new ArrayList<Species>(); @@ -136,48 +137,36 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } @Override - public void getObsoleteEspeceForTargetSample(String setSeineId, - Collection<Species> speciessUsed, - Collection<Species> speciessToDelete, - List<TargetLength> tailleToDelete, - boolean discarded) { + public List<TargetLength> getObsoleteTargetLengths(String setSeineId, Set<String> speciesIdsUsed, boolean discarded) { SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - if (setSeine.isTargetSampleEmpty()) { - return; - } + List<TargetLength> targetLengthsToDelete = new ArrayList<TargetLength>(); - TargetSample echantillon = setSeine.getTargetSample(discarded); + if (!setSeine.isTargetSampleEmpty()) { - if (echantillon == null || echantillon.isTargetLengthEmpty()) { - return; - } + TargetSample targetSample = setSeine.getTargetSample(discarded); + if (targetSample != null && !targetSample.isTargetLengthEmpty()) { + + for (TargetLength targetLength : targetSample.getTargetLength()) { + + Species species = targetLength.getSpecies(); + + if (!speciesIdsUsed.contains(species.getTopiaId())) { + // l'espèce n'existe plus dans les rejet faune, on doit le supprimer + targetLengthsToDelete.add(targetLength); + if (log.isDebugEnabled()) { + log.debug("remove obsolote echantillon " + targetLength + " for species " + species); + } + } - for (TargetLength taille : echantillon.getTargetLength()) { - Species tailleEspece = taille.getSpecies(); - if (!speciessUsed.contains(tailleEspece)) { - // l'species n'existe plus dans les rejet faune, - // on doit le supprimer - tailleToDelete.add(taille); - speciessToDelete.add(tailleEspece); - if (log.isDebugEnabled()) { - log.debug("remove obsolote echantillon " + taille + " for species " + tailleEspece); } + } - } - } + } - @Override - public void delete(String setId, TargetSample bean) { - doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { - @Override - public void onDelete(SetSeine parent, TargetSample toDelete) { - super.onDelete(parent, toDelete); - parent.removeTargetSample(toDelete); - } - }); + return targetLengthsToDelete; } @@ -196,11 +185,11 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } @Override - public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { + public TargetSample onUpdate(SetSeine parentBean, TargetSample toUpdate, TargetSample updated) { - copyExcluding(TargetSample.class, BinderService.EDIT, toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); - getDao().update(beanToSave); - return beanToSave; + copyExcluding(TargetSample.class, BinderService.EDIT, toUpdate, updated, TargetSample.PROPERTY_TARGET_LENGTH); + getDao().update(updated); + return updated; } }); @@ -209,4 +198,16 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } + @Override + public void delete(String setId, TargetSample bean) { + doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { + @Override + public void onDelete(SetSeine parent, TargetSample toDelete) { + super.onDelete(parent, toDelete); + parent.removeTargetSample(toDelete); + } + }); + + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java index 5ae0df8..654a379 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java @@ -34,6 +34,8 @@ public interface ReferentialService extends ObserveService { List<WeightCategory> loadDecoratedWeightCategory(); + void loadDecoratedWeightCategory(WeightCategory weightCategory); + Set<String> getSpeciesListSpeciesIds(String speciesListId); <R extends ReferenceEntity> R preCreate(Class<R> entityType); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 270858f..fa3c99a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -123,6 +123,14 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } @Override + public void loadDecoratedWeightCategory(WeightCategory weightCategory) { + + decorate(WeightCategory.class, weightCategory); + decorate(Species.class, weightCategory.getSpecies()); + + } + + @Override public Set<String> getSpeciesListSpeciesIds(String speciesListId) { SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListId); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 01dad8b..1ef2472 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.content; import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveServiceHelper; @@ -64,6 +63,8 @@ import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.JToolBar; import javax.swing.UIManager; +import javax.swing.event.TableModelListener; +import javax.swing.table.TableModel; import java.awt.Component; import java.util.ArrayList; import java.util.List; @@ -92,15 +93,15 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { /** l'interface graphique que le controleur utilise */ protected ObserveContentUI<E> ui; - public ContentUIHandler(ObserveContentUI<E> ui, DataContextType parentType, DataContextType type) { + protected ContentUIHandler(ObserveContentUI<E> ui, DataContextType parentType, DataContextType type) { this.ui = ui; this.parentType = parentType; this.type = type; - prefix = "[" + ui.getClass().getSimpleName() + "] "; + this.prefix = "[" + ui.getClass().getSimpleName() + "] "; if (log.isDebugEnabled()) { log.debug("New handler [" + this + "] for ui " + prefix); } - errorIcon = UIManager.getIcon("action.error"); + this.errorIcon = UIManager.getIcon("action.error"); } public static <E extends TopiaEntity> ContentUIHandler<E> newHandler(ObserveContentUI<E> ui) { @@ -301,22 +302,14 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return ObserveContext.get().getBinderService(); } - public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { + public <EE extends TopiaEntity> void copy(Class<EE> type, String context, EE source, EE target) { getBinderService().copy(type, context, source, target); } - public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { - getBinderService().copyExcluding(type, context, source, target, propertyNames); - } - - public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { + public <EE extends TopiaEntity> void copy(Class<EE> type, String context, EE source, EE target, boolean bindTechnical) { getBinderService().copy(type, context, source, target, bindTechnical); } - public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> type, String context) { - return getBinderService().getBinder(type, context); - } - protected DataSource getDataSource() { return ui.getDataSource(); } @@ -613,19 +606,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } } -// protected E onCreate(TopiaContext tx, Object parentBean, E editBean) throws TopiaException { -// return editBean; -// } -// -// protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { -// // rien par defaut -// return beanToSave; -// } -// -// protected void onDelete(TopiaContext tx, Object parentBean, E beanToDelete) throws TopiaException { -// // rien par defaut -// } - protected void addInfoMessage(String message) { addMessage(ui, NuitonValidatorScope.INFO, @@ -649,26 +629,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return getModel().getLoadBinder(); } -// protected final TopiaExecutor<E> getLoadExecutor() { -// return loadExecutor; -// } -// -// protected final TopiaExecutor2<? extends TopiaEntity, E> getPreCreateExecutor() { -// return preCreateExecutor; -// } -// -// protected final TopiaExecutor2<? extends TopiaEntity, E> getCreateExecutor() { -// return createExecutor; -// } -// -// protected final TopiaExecutor2<? extends TopiaEntity, E> getUpdateExecutor() { -// return updateExecutor; -// } -// -// protected final TopiaExecutor2<? extends TopiaEntity, E> getDeleteExecutor() { -// return deleteExecutor; -// } - protected final ContentMode computeContentMode() { ContentMode mode; @@ -693,10 +653,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return contextName; } - protected final DataService getDataService() { - return ObserveContext.get().getDataService(); - } - protected final <S extends ObserveService> S getService(Class<S> serviceType) { return ObserveContext.get().getService(serviceType); } @@ -805,4 +761,15 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { quadrantBG.add(editor.getQuadrant4()); } + + protected void setQuadrant(CoordinatesEditor editor, Integer quadrant) { + editor.setQuadrant(null); + editor.setQuadrant(quadrant); + } + + protected void reloadTableModelListener(TableModel tableModel, TableModelListener listener) { + tableModel.removeTableModelListener(listener); + tableModel.addTableModelListener(listener); + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java index 48eb5af..42f3797 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIModel.java @@ -137,35 +137,9 @@ public abstract class ContentUIModel<E extends TopiaEntity> extends AbstractSeri } public final TopiaEntityBinder<E> getLoadBinder() { - -// if (loadBinder == null) { -// -// BinderService binderService = ObserveServiceHelper.get().getBinderService(); -// -// String binderName = getClass().getName() + "-open"; -// TopiaEntityBinder<E> r = binderService.getTopiaBinder(beanType, binderName); -// if (r == null) { -// -// BinderModelBuilder<E, E> builder = createOpeningBinder(binderService, binderName); -// -// if (builder != null) { -// -// r = binderService.registerTopiaBinder(beanType, builder, binderName); -// -// } -// -// } -// -// loadBinder = r; -// -// } - return loadBinder; - } -// protected abstract BinderModelBuilder<E, E> createOpeningBinder(BinderService binderService, String binderName); - public E getBean() { return bean; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java index 3a5fec7..70d3ef9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java @@ -50,7 +50,7 @@ import static org.nuiton.i18n.I18n.t; public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLongline> { /** Logger */ - static private Log log = LogFactory.getLog(LonglineGlobalCompositionUIHandler.class); + public static final Log log = LogFactory.getLog(LonglineGlobalCompositionUIHandler.class); public LonglineGlobalCompositionUIHandler(LonglineGlobalCompositionUI ui) { super(ui, DataContextType.ActivityLongline, DataContextType.SetLongline); @@ -142,7 +142,7 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong // utilisation du mode requis setContentMode(mode); - if (mode != ContentMode.READ) { + if (ContentMode.READ != mode) { getUi().startEdit(null); } @@ -184,7 +184,7 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong } @Override - protected boolean doSave(SetLongline bean) throws Exception { + protected boolean doSave(SetLongline bean) { copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, getUi().getFloatlinesCompositionUI().getBean(), bean); copy(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, getUi().getBranchlinesCompositionUI().getBean(), bean); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java index 7cf9f43..34e4f92 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java @@ -145,6 +145,9 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { super.initUI(); + // listen messages to see if required to add + reloadTableModelListener(getUi().getErrorTableModel(), computeTabValidStateListener); + getUi().getSettingStartTimeStamp().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); getUi().getSettingEndTimeStamp().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); getUi().getHaulingStartTimeStamp().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); @@ -226,15 +229,10 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { // utilisation du mode requis setContentMode(mode); - // To be sure always remove listener (could prevent some leaks) - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); - // listen messages to see if required to add - getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); - SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); - if (mode != ContentMode.READ) { + if (ContentMode.READ != mode) { getUi().startEdit(null); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java index 86ace0a..149899d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java @@ -109,6 +109,7 @@ public class ActivitySeineObservedSystemUIHandler extends ContentUIHandler<Activ copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, saved, bean); return true; + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java index 1fe72ea..d8dc84c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java @@ -137,10 +137,8 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { super.initUI(); - // To be sure always remove listener (could prevent some leaks) - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); // listen messages to see if required to add - getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); + reloadTableModelListener(getUi().getErrorTableModel(), computeTabValidStateListener); getUi().getStartTime().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); getUi().getEndPursingTimeStamp().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); @@ -199,7 +197,7 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); - if (mode != ContentMode.READ) { + if (ContentMode.READ != mode) { getUi().startEdit(null); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java index 1b52eef..7aafb12 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java @@ -55,6 +55,20 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE protected final String closeMessage; + /** + * Méthode invoquée à chaque ouverture de l'écran. + * + * La méthode est invoquée par {@link #openUI()}. + * + * @param selectedParentId l'id du parent sélectionné + * @param selectedId l'id de l'entité de l'écran, peut être {@code null} en cas de création. + * @param mode le mode de l'écran + * @since 4.0 + */ + protected abstract void onOpenUI(String selectedParentId, String selectedId, ContentMode mode); + + protected abstract boolean obtainCanReopen(boolean create); + protected ContentOpenableUIHandler(ContentOpenableUI<E> ui, DataContextType parentType, DataContextType type, @@ -65,8 +79,6 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE } - protected abstract boolean obtainCanReopen(boolean create); - protected void updateOpenState(String beanId, boolean openState) { OpenableService service = getService(OpenableService.class); service.updateOpenState(beanId, openState); @@ -88,6 +100,29 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE } @Override + public void openUI() throws Exception { + + super.openUI(); + + String selectedParentId = getSelectedParentId(); + String selectedId = getSelectedId(); + ContentMode mode = computeContentMode(); + + if (log.isInfoEnabled()) { + log.info(prefix + "selectedParentId = " + selectedParentId); + log.info(prefix + "selectedId = " + selectedId); + log.info(prefix + "content mode = " + mode); + } + + onOpenUI(selectedParentId, selectedId, mode); + + boolean create = selectedId == null; + + finalizeOpenUI(mode, create); + + } + + @Override protected boolean computeCanWrite(DataSource source) { return source.canWriteData(); } @@ -297,6 +332,7 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE log.debug("PARENT NODE = " + parentNode); } treeHelper.addUnsavedNode(parentNode, getBeanType()); + } protected final void obtainChildPosition(E bean) throws DataSourceException { @@ -310,6 +346,7 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE } getUi().setContextValue(position, POSITION_OPENABLE); + } protected final void finalizeOpenUI(ContentMode mode, boolean create) { @@ -345,7 +382,7 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE } model.setCanReopen(canReopen); - if (mode != ContentMode.READ) { + if (ContentMode.READ != mode) { getUi().startEdit(null); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java index 61e8c9a..bc11d0a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/ActivityLonglineUIHandler.java @@ -33,6 +33,7 @@ import fr.ird.observe.ui.content.ContentUIModel; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; import org.nuiton.validator.NuitonValidatorScope; import static org.nuiton.i18n.I18n.n; @@ -77,18 +78,18 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity // mode creation return ContentMode.CREATE; + } - // l'activity existe en base + // l'activité existe en base if (dataContext.isSelectedOpen(ActivityLongline.class)) { - // l'activity est ouverte, donc modifiable + // l'activité est ouverte, donc modifiable return ContentMode.UPDATE; - } - ActivityLonglineUI ui = getUi(); + } - // l'activity n'est pas ouverte, donc pas éditable + // l'activité n'est pas ouverte, donc pas éditable if (!dataContext.isSelectedOpen(TripLongline.class)) { // la marée n'est pas ouverte @@ -100,35 +101,25 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity if (getModel().isHistoricalData()) { addInfoMessage(t("observe.message.historical.data")); + } } else { - // seule l'activity n'est pas ouverte + // seule l'activité n'est pas ouverte addInfoMessage(t(closeMessage)); + } return ContentMode.READ; + } @Override - public void openUI() throws Exception { - super.openUI(); - - resetQuadrant(getUi().getCoordinatesEditor()); - - String tripId = getSelectedParentId(); - String activityId = getSelectedId(); - - if (log.isInfoEnabled()) { - log.info(prefix + "tripId = " + tripId); - log.info(prefix + "activityId = " + activityId); - } + protected void onOpenUI(String tripId, String activityId, ContentMode mode) { - ContentMode mode = computeContentMode(); - if (log.isInfoEnabled()) { - log.info(prefix + "content mode " + mode); - } + CoordinatesEditor coordinatesEditor = getUi().getCoordinatesEditor(); + resetQuadrant(coordinatesEditor); boolean create = activityId == null; @@ -143,39 +134,32 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity } else { // update mode - if (mode == ContentMode.UPDATE) { - loaded = service.loadForEdit(activityId); - } else { - loaded = service.loadForDisplay(activityId); - } + loaded = service.loadForEdit(activityId); } ActivityLongline bean = getBean(); copy(ActivityLongline.class, BinderService.EDIT, loaded, bean); - finalizeOpenUI(mode, create); - - getUi().getCoordinatesEditor().setLatitudeAndLongitude(bean.getLatitude(), bean.getLongitude()); + coordinatesEditor.setLatitudeAndLongitude(bean.getLatitude(), bean.getLongitude()); if (create) { + + // on positionne le quadrant (celui de l'activité précédent si elle existe) Integer quadrant = bean.getQuadrant(); - getUi().getCoordinatesEditor().setQuadrant(null); - getUi().getCoordinatesEditor().setQuadrant(quadrant); + setQuadrant(coordinatesEditor, quadrant); + } - // on annule la modification engendree par ce binding - getModel().setModified(create); } @Override public void startEditUI(String... binding) { - ActivityLonglineUI ui = getUi(); ContentUIModel<ActivityLongline> model = getModel(); boolean create = model.getMode() == ContentMode.CREATE; String contextName = getValidatorContextName(model.getMode()); - ui.getValidator().setContext(contextName); + getUi().getValidator().setContext(contextName); if (create) { addMessage(ui, NuitonValidatorScope.INFO, @@ -196,7 +180,9 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity ActivityLonglineUI.BINDING_FPA_ZONE_SELECTED_ITEM, ActivityLonglineUI.BINDING_CLOSE_ENABLED, ActivityLonglineUI.BINDING_CLOSE_AND_CREATE_ENABLED); + model.setModified(create); + } @Override @@ -232,9 +218,6 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity ActivityLonglineService service = getService(ActivityLonglineService.class); String tripId = getSelectedParentId(); service.delete(tripId, bean.getTopiaId()); - if (log.isInfoEnabled()) { - log.info("Delete done for Activity " + bean.getTopiaId()); - } result = true; } @@ -255,6 +238,7 @@ public class ActivityLonglineUIHandler extends ContentOpenableUIHandler<Activity dataContext.isSelectedOpen(TripLongline.class) && !dataContext.isOpenActivity(); return canReopen; + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java index 9d0b3c8..a85a3ed 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/longline/TripLonglineUIHandler.java @@ -87,11 +87,14 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline } addInfoMessage(t(closeMessage)); + return ContentMode.READ; + } @Override public void initUI() throws Exception { + super.initUI(); TripLonglineUI ui = getUi(); @@ -131,19 +134,7 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline } @Override - public void openUI() throws Exception { - super.openUI(); - - ContentMode mode = computeContentMode(); - - String programId = getSelectedParentId(); - String tripId = getSelectedId(); - - if (log.isInfoEnabled()) { - log.info(prefix + "programId = " + programId); - log.info(prefix + "tripId = " + tripId); - log.info(prefix + "mode = " + mode); - } + protected void onOpenUI(String programId, String tripId, ContentMode mode) { TripLongline loaded; @@ -154,24 +145,19 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline if (create) { // create mode - - if (log.isInfoEnabled()) { - log.info(prefix + "create a new trip"); - } - loaded = service.preCreate(programId); } else { // update mode - if (log.isInfoEnabled()) { - log.info(prefix + "using existing trip " + tripId); - } + if (ContentMode.UPDATE == mode) { - if (mode == ContentMode.UPDATE) { loaded = service.loadForEdit(tripId); + } else { + loaded = service.loadForDisplay(tripId); + } } @@ -181,14 +167,11 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline getUi().getTripLonglineTabPane().setSelectedIndex(0); buildTripMap = true; - finalizeOpenUI(mode, create); } @Override public void startEditUI(String... binding) { - TripLonglineUI ui = getUi(); - ContentOpenableUIModel<TripLongline> model = getModel(); ContentMode mode = model.getMode(); @@ -196,7 +179,7 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline boolean create = mode == ContentMode.CREATE; String contextName = getValidatorContextName(mode); - ui.getValidator().setContext(contextName); + getUi().getValidator().setContext(contextName); if (create) { addInfoMessage(t("observe.tripLongline.message.creating")); @@ -205,6 +188,7 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline if (model.isHistoricalData()) { addInfoMessage(t("observe.message.historical.data")); + } } @@ -221,7 +205,9 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline TripLonglineUI.BINDING_HOME_ID_TEXT, TripLonglineUI.BINDING_CLOSE_ENABLED, TripLonglineUI.BINDING_CLOSE_AND_CREATE_ENABLED); + model.setModified(create); + } @Override @@ -237,6 +223,7 @@ public class TripLonglineUIHandler extends ContentOpenableUIHandler<TripLongline obtainChildPosition(bean); return true; + } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java index 7e0e1fe..3b3ab5f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java @@ -29,8 +29,8 @@ import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeineImpl; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.services.data.seine.ActivitySeineService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIModel; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; @@ -38,6 +38,7 @@ import jaxx.runtime.validator.swing.SwingValidatorMessage; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.event.TableModelEvent; @@ -81,6 +82,16 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei } @Override + public void initUI() throws Exception { + + super.initUI(); + + // listen messages to see if required to add + reloadTableModelListener(getUi().getErrorTableModel(), computeTabValidStateListener); + + } + + @Override protected ContentMode getContentMode(DataContext dataContext) { String activityId = getSelectedId(); @@ -91,16 +102,15 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei return ContentMode.CREATE; } - // l'activity existe en base + // l'activité existe en base if (dataContext.isSelectedOpen(ActivitySeine.class)) { - // l'activity est ouverte, donc modifiable + // l'activité est ouverte, donc modifiable return ContentMode.UPDATE; - } - ActivitySeineUI ui = getUi(); + } - // l'activity n'est pas ouverte, donc pas éditable + // l'activité n'est pas ouverte, donc pas éditable if (!dataContext.isSelectedOpen(Route.class)) { // la route n'est pas ouverte @@ -120,47 +130,26 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei if (getModel().isHistoricalData()) { addInfoMessage(t("observe.message.historical.data")); + } } else { - // seule l'activity n'est pas ouverte + // seule l'activité n'est pas ouverte addInfoMessage(t(closeMessage)); + } return ContentMode.READ; - } - - @Override - public void initUI() throws Exception { - - super.initUI(); - - // To be sure always remove listener (could prevent some leaks) - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); - // listen messages to see if required to add - getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); } @Override - public void openUI() throws Exception { - super.openUI(); - - resetQuadrant(getUi().getCoordinatesEditor()); + protected void onOpenUI(String routeId, String activityId, ContentMode mode) { - String routeId = getSelectedParentId(); - String activityId = getSelectedId(); - - if (log.isInfoEnabled()) { - log.info(prefix + "routeId = " + routeId); - log.info(prefix + "activityId = " + activityId); - } + CoordinatesEditor coordinatesEditor = getUi().getCoordinatesEditor(); - ContentMode mode = computeContentMode(); - if (log.isInfoEnabled()) { - log.info(prefix + "content mode " + mode); - } + resetQuadrant(coordinatesEditor); boolean create = activityId == null; @@ -185,29 +174,25 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); - finalizeOpenUI(mode, create); - - getUi().getCoordinatesEditor().setLatitudeAndLongitude(bean.getLatitude(), bean.getLongitude()); + coordinatesEditor.setLatitudeAndLongitude(bean.getLatitude(), bean.getLongitude()); if (create) { + + // on positionne le quadrant (celui de l'activité précédent si elle existe) Integer quadrant = bean.getQuadrant(); - getUi().getCoordinatesEditor().setQuadrant(null); - getUi().getCoordinatesEditor().setQuadrant(quadrant); - } + setQuadrant(coordinatesEditor, quadrant); - // on annule la modification engendree par ce binding - getModel().setModified(create); + } } @Override public void startEditUI(String... binding) { - ActivitySeineUI ui = getUi(); ContentUIModel<ActivitySeine> model = getModel(); boolean create = model.getMode() == ContentMode.CREATE; String contextName = getValidatorContextName(model.getMode()); - ui.getValidator().setContext(contextName); + getUi().getValidator().setContext(contextName); if (create) { addMessage(ui, NuitonValidatorScope.INFO, @@ -215,9 +200,9 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei t("observe.activitySeine.message.creating")); } else { addMessage(ui, - NuitonValidatorScope.INFO, - getEntityLabel(ActivitySeine.class), - t("observe.activitySeine.message.updating")); + NuitonValidatorScope.INFO, + getEntityLabel(ActivitySeine.class), + t("observe.activitySeine.message.updating")); } super.startEditUI(ActivitySeineUI.BINDING_TIME_TIME, @@ -232,7 +217,9 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei ActivitySeineUI.BINDING_CLOSE_ENABLED, ActivitySeineUI.BINDING_ADD_SET_ENABLED, ActivitySeineUI.BINDING_CLOSE_AND_CREATE_ENABLED); + model.setModified(create); + } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java index 2fc2bd5..90ba8bc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/RouteUIHandler.java @@ -42,6 +42,7 @@ import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JOptionPane; import java.util.Date; +import java.util.List; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -78,6 +79,7 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { // mode creation return ContentMode.CREATE; + } // route deja existante @@ -85,9 +87,8 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { // la route est ouverte return ContentMode.UPDATE; - } - RouteUI ui = getUi(); + } // route non ouverte if (!dataContext.isSelectedOpen(TripSeine.class)) { @@ -104,26 +105,11 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { t(closeMessage)); } return ContentMode.READ; + } @Override - public void openUI() throws Exception { - - super.openUI(); - - String tripId = getSelectedParentId(); - String routeId = getSelectedId(); - - if (log.isInfoEnabled()) { - log.info(prefix + "tripId = " + tripId); - log.info(prefix + "routeId = " + routeId); - } - - ContentMode mode = computeContentMode(); - - if (log.isInfoEnabled()) { - log.info(prefix + "content mode = " + mode); - } + protected void onOpenUI(String tripId, String routeId, ContentMode mode) { Route loaded; @@ -138,19 +124,13 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { } else { // update mode - if (mode == ContentMode.UPDATE) { - loaded = service.loadForEdit(routeId); - } else { - loaded = service.loadForDisplay(routeId); - } + loaded = service.loadForEdit(routeId); } Route bean = getBean(); copy(Route.class, BinderService.EDIT, loaded, bean); - finalizeOpenUI(mode, create); - } @Override @@ -159,9 +139,7 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { boolean create = getModel().getMode() == ContentMode.CREATE; String contextName = getValidatorContextName(getModel().getMode()); - RouteUI ui = getUi(); - - ui.getValidator().setContext(contextName); + getUi().getValidator().setContext(contextName); if (create) { addMessage(ui, @@ -189,6 +167,7 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { // le formulaire est en état modifié uniquement si on est en création getModel().setModified(create); + } @Override @@ -200,7 +179,6 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { log.info("will save route " + bean.getTopiaId()); } - bean.setOpen(true); RouteService service = getService(RouteService.class); @@ -214,64 +192,12 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { @Override protected void afterSave(boolean refresh) { + super.afterSave(refresh); repaintTripNode(); - } - @Override - protected void afterDelete() { - super.afterDelete(); - repaintTripNode(); } -// @Override -// protected Route onCreate(TopiaContext tx, Object parent, Route editBean) throws TopiaException { -// -// TripSeine parentBean = (TripSeine) parent; -// -// // creation de la route -// Route beanToSave = ObserveDAOHelper.getRouteDAO(tx).create(); -// editBean.setTopiaId(beanToSave.getTopiaId()); -// -// // ajout de la route dans la amree -// parentBean.addRoute(beanToSave); -// -// // on renseigne le jour d'observation car on en a besoin pour -// // mettre la date de fin de la maree -// beanToSave.setDate(editBean.getDate()); -// -// // on met a jour si necessaire la date de fin de la maree -// updateDateFin(parentBean); -// -// return beanToSave; -// } -// -// @Override -// protected Route onUpdate(TopiaContext tx, Object parent, Route beanToSave) throws TopiaException { -// -// TripSeine parentBean = (TripSeine) parent; -// -// Route editBean = getBean(); -// -// // on conserve l'ancienne date d'observation -// Date oldDate = DateUtil.getDay(beanToSave.getDate()); -// -// // recopie des propriétés vers le bean a sauver -// getLoadBinder().copyExcluding(editBean, beanToSave, Route.PROPERTY_ACTIVITY_SEINE); -// -// if (!oldDate.equals(editBean.getDate())) { -// -// // le jour a change, il faut mettre à jour les dates des activitys -// // et des sets -// beanToSave.updateDates(); -// } -// -// // on met a jour si necessaire la date de fin de la maree -// updateDateFin(parentBean); -// -// return beanToSave; -// } - @Override protected boolean doDelete(Route bean) { @@ -300,6 +226,14 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { } @Override + protected void afterDelete() { + + super.afterDelete(); + repaintTripNode(); + + } + + @Override public boolean doCloseData() throws Exception { Route route = getBean(); @@ -335,7 +269,6 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { log.debug("response : " + reponse); } - switch (reponse) { case JOptionPane.CLOSED_OPTION: case 3: @@ -390,6 +323,7 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { super.doCloseData(); return true; + } protected ActivitySeineUI addActivityFinDeVeille(boolean close) { @@ -398,26 +332,22 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { // on créee l'activity de fin de veille ObserveNode parentNode = treeHelper.getSelectedNode(); - parentNode = treeHelper.findNode( - parentNode, - n("observe.common.activities") - ); + parentNode = treeHelper.findNode(parentNode, n("observe.common.activities")); if (log.isDebugEnabled()) { log.debug("PARENT NODE = " + parentNode); } treeHelper.addUnsavedNode(parentNode, ActivitySeine.class); // on recupère l'écran d'édition - ActivitySeineUI selectedUI = (ActivitySeineUI) - ObserveContext.get().getSelectedContentUI(); + ActivitySeineUI selectedUI = (ActivitySeineUI) ObserveContext.get().getSelectedContentUI(); // on recupère l'activity de fin de veille VesselActivitySeine vesselActivitySeine = null; - for (Object o : selectedUI.getVesselActivitySeine().getData()) { - VesselActivitySeine a = (VesselActivitySeine) o; - if (ActivitySeineImpl.ACTIVITY_FIN_DE_VEILLE.equals(a.getCode())) { - vesselActivitySeine = a; + List<VesselActivitySeine> vesselActivitySeines = selectedUI.getVesselActivitySeine().getData(); + for (VesselActivitySeine vesselActivitySeine1 : vesselActivitySeines) { + if (ActivitySeineImpl.ACTIVITY_FIN_DE_VEILLE_ID.equals(vesselActivitySeine1.getTopiaId())) { + vesselActivitySeine = vesselActivitySeine1; break; } } @@ -434,14 +364,16 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { // on ferme l'écean selectedUI.stopEdit(); + } + return selectedUI; + } @Override protected boolean obtainCanReopen(boolean create) { - DataContext dataContext = getDataContext(); // on peut reouvrir une route si : @@ -451,6 +383,7 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { dataContext.isSelectedOpen(TripSeine.class) && !dataContext.isOpenRoute(); return canReopen; + } protected void repaintTripNode() { @@ -463,20 +396,20 @@ public class RouteUIHandler extends ContentOpenableUIHandler<Route> { getUi().removeContextValue(Boolean.class, UPDATE_TRIP_NODE); - if (updateTripNode == null || !updateTripNode) { - return; - } + if (updateTripNode != null && updateTripNode) { + ObserveTreeHelper treeHelper = getTreeHelper(getUi()); + ObserveNode tripNode = treeHelper.getSelectedNode().getParent().getParent(); + if (log.isInfoEnabled()) { + log.info("Refresh trip node : " + tripNode); + } + treeHelper.reloadNode(tripNode, false); - ObserveTreeHelper treeHelper = getTreeHelper(getUi()); - ObserveNode tripNode = treeHelper.getSelectedNode().getParent().getParent(); - if (log.isInfoEnabled()) { - log.info("Refresh trip node : " + tripNode); } - treeHelper.reloadNode(tripNode, false); } + //FIXME Remettre ça en place protected void updateDateFin(TripSeine parentBean) { Date endDate = parentBean.getEndDate(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java index 619a52c..661bc93 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java @@ -90,6 +90,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { @Override public void initUI() throws Exception { + super.initUI(); TripSeineUI ui = getUi(); @@ -130,19 +131,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { } @Override - public void openUI() throws Exception { - super.openUI(); - - ContentMode mode = computeContentMode(); - - String programId = getSelectedParentId(); - final String tripId = getSelectedId(); - - if (log.isInfoEnabled()) { - log.info(prefix + "programId = " + programId); - log.info(prefix + "tripId = " + tripId); - log.info(prefix + "mode = " + mode); - } + protected void onOpenUI(String programId, String tripId, ContentMode mode) { TripSeineService service = getService(TripSeineService.class); @@ -152,25 +141,19 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { if (create) { // create mode - - if (log.isInfoEnabled()) { - log.info(prefix + "create a new trip"); - } - - loaded = service.preCreate(programId); } else { // update mode - if (log.isInfoEnabled()) { - log.info(prefix + "using existing trip " + tripId); - } + if (ContentMode.UPDATE == mode) { - if (mode == ContentMode.UPDATE) { loaded = service.loadForEdit(tripId); + } else { + loaded = service.loadForDisplay(tripId); + } } @@ -178,16 +161,14 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { TripSeine bean = getBean(); copy(TripSeine.class, BinderService.EDIT, loaded, bean); getUi().getTripSeineTabPane().setSelectedIndex(0); + buildTripMap = true; - finalizeOpenUI(mode, create); } @Override public void startEditUI(String... binding) { - TripSeineUI ui = getUi(); - ContentOpenableUIModel<TripSeine> model = getModel(); ContentMode mode = model.getMode(); @@ -195,7 +176,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { boolean create = mode == ContentMode.CREATE; String contextName = getValidatorContextName(mode); - ui.getValidator().setContext(contextName); + getUi().getValidator().setContext(contextName); if (create) { @@ -219,7 +200,9 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { TripSeineUI.BINDING_ERS_ID_TEXT, TripSeineUI.BINDING_CLOSE_ENABLED, TripSeineUI.BINDING_CLOSE_AND_CREATE_ENABLED); + model.setModified(create); + } @Override @@ -235,6 +218,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { obtainChildPosition(bean); return true; + } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index c5be916..1242dfc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -33,11 +33,8 @@ import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.content.ObserveContentUI; import fr.ird.observe.ui.tree.ObserveNode; -import jaxx.runtime.swing.ErrorDialogUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.validator.NuitonValidatorScope; @@ -47,7 +44,6 @@ import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.table.DefaultTableCellRenderer; import java.awt.Rectangle; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; @@ -79,6 +75,33 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top */ protected abstract void onSelectedRowChanged(int editingRow, D bean, boolean create); + /** + * Initialiser le tableau de l'écran. + * + * Cette méthode est appelée la première fois que l'écran est affiché. + * + * @param renderer le renderer par défaut à utiliser. + */ + protected abstract void initTableUI(DefaultTableCellRenderer renderer); + + /** + * Pour charger le bean d'édition dans la méthode {@link #openUI()}. + * + * Cette méthode est appelée à chaque affichage de l'écran. + * + * @param mode le mode de l'écran + */ + protected abstract void loadEditBean(ContentMode mode); + + /** + * Pour enregistre l'objet en cours d'édition. + * + * Cette méthode est appelé dans la méthode {@link #doSave(TopiaEntity)}. + * + * @param editBean l'objet à enregistrer + */ + protected abstract void doPersist(E editBean); + @Override protected boolean computeCanWrite(DataSource source) { return source.canWriteData(); @@ -123,10 +146,102 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top return (ObserveContentTableUI<E, D>) super.getUi(); } + protected ContentTableModel<E, D> getTableModel() { + return getUi().getTableModel(); + } + public final D getTableEditBean() { return getModel().getTableEditBean(); } + @Override + public void initUI() throws Exception { + + ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>> uiInitializer = + new ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>>(getUi()); + uiInitializer.initUI(ObserveContext.get().getServices()); + + } + + @Override + public void openUI() throws Exception { + + super.openUI(); + + ContentTableModel<E, D> tableModel = getTableModel(); + + // récupération de la ligne sélectionnée + int oldIndex = tableModel.getSelectedRow(); + + // on déttache le modèle du tableau + tableModel.dettachModel(); + + // récupération du mode de l'écran + ContentMode mode = computeContentMode(); + + // chargement du bean d'édition + loadEditBean(mode); + + // chargement de l'écran d'édition + loadTableEditBeanForm(mode); + + // enregistrement du mode de l'écran + getModel().setMode(mode); + + // initialisation du modèle du tableau + tableModel.attachModel(); + + boolean canEdit = mode == ContentMode.UPDATE; + + if (canEdit) { + // on lance le mode edition + ui.startEdit(null); + } + + if (!tableModel.isEmpty()) { + + if (tableModel.getRowCount() <= oldIndex) { + oldIndex = 0; + } + if (oldIndex == -1) { + oldIndex = 0; + } + + // le tableau contient au moins une entrée + // on la sélectionne la première entrée + tableModel.changeSelectedRow(oldIndex); + + } + + if (canEdit) { + + // on force l'ecran en non modification + //FIXME normalement, on ne devrait pas a avoir a faire ca ? + //FIXME mais il est possible que les validateurs modifient l'état + //FIXME modified sur l'ecran lors des bindings d'initilisation... + getModel().setModified(false); + + } + + } + + protected void loadTableEditBeanForm(ContentMode mode) { + // par defaut, rien à faire + } + + + @Override + public void startEditUI(String... binding) { + + addUpdateInfoMessage(); + super.startEditUI(binding); + + } + + protected void resetEditBean() { + getTableModel().resetEditBean(); + } + public final void updateEditor(ListSelectionEvent event) { final ObserveContentTableUI<E, D> ui = getUi(); @@ -142,7 +257,10 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top if (log.isDebugEnabled()) { log.debug(event); } - if (getTableModel().isEmpty()) { + + ContentTableModel<E, D> tableModel = getTableModel(); + + if (tableModel.isEmpty()) { // le modele est vide, on ne propage rien //FIXME le modèle de selection ne devrait plus declancher des evenement //FIXME des que le modele est vide ? @@ -172,111 +290,28 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } }); - int selectedRow = getTableModel().getSelectedRow(); + int selectedRow = tableModel.getSelectedRow(); if (newIndex == selectedRow) { // on bloque du code re-entrant log.debug("new index already set in model " + newIndex + ", do nothing"); return; } // on doit changer de ligne selectionne dans le modele - getTableModel().changeSelectedRow(newIndex); - } - - protected abstract void initTableUI(DefaultTableCellRenderer renderer); + tableModel.changeSelectedRow(newIndex); -// protected String getEditBeanIdToLoad(DataContext dataContext, -// DataService dataService, -// DataSource dataSource) throws DataSourceException { -// throw new IllegalStateException("Do NOT USE ME!!!"); -// } - -// protected E loadEditBean(ContentMode mode, -// DataContext dataContext, -// DataService dataService, -// DataSource dataSource) throws DataSourceException { -// -// loadEditBean(mode); -// -//// String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); -//// -//// if (id == null) { -//// throw new IllegalStateException("Could not find id form " + this); -//// } -//// -//// // preparation du bean d'édition -//// dataService.loadEditEntity(dataSource, id, getLoadExecutor()); -// -//// getModel().setMode(mode); -//// -//// // initialisation du modèle du tableau -//// getUi().getTableModel().attachModel(); -// -// E editBean = getBean(); -// return editBean; -// -// } - - //FIXME Rendre cette methode abstract - protected abstract void loadEditBean(ContentMode mode) ; - -// protected abstract void loadEditBean() throws DataSourceException { -// -// String id = getEditBeanIdToLoad(getDataContext(), getDataService(), getDataSource()); -// -// if (id == null) { -// throw new IllegalStateException("Could not find id form " + this); -// } -// -// // preparation du bean d'édition -// getDataService().loadEditEntity(getDataSource(), id, getLoadExecutor()); -// -// } - -// //FIXME A supprimer -// @Override -// protected final void onLoad(TopiaContext tx, E bean) throws TopiaException { -// super.onLoad(tx, bean); -// -// // on duplique la liste des fils traites dans le tableau -// // sinon on reste sur les references d'origine et on aura pas -// // la possibilité d'annuler l'edition ensuite car on aura modifie -// // les entrées d'origine... -// E editBean = getBean(); -// Collection<D> data = loadChilds(tx, editBean); -// getModel().getChildsUpdator().setChilds(editBean, data); -// } -// -// //FIXME A supprimer -// protected Collection<D> loadChilds(TopiaContext tx, E bean) throws TopiaException { -// Collection<D> childs = getModel().getChildsUpdator().getChilds(bean); -// Collection<D> data = new ArrayList<D>(); -// if (CollectionUtils.isNotEmpty(childs)) { -// Loador<D> loader = getModel().getChildLoador(); -// TopiaDAO<D> dao = getDataSource().getDAO(tx, getTableEditBean()); -// for (D c : childs) { -// try { -// D cUp = dao.findByTopiaId(c.getTopiaId()); -// D c2 = getModel().newTableEditBean(); -// loader.load(cUp, c2, true); -// data.add(c2); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// } -// } -// return data; -// } - - @Override - public void initUI() throws Exception { + } - ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>> uiInitializer = - new ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>>(getUi()); - uiInitializer.initUI(ObserveContext.get().getServices()); + public void removeSelectedRow(int selectedRow) { + try { + getTableModel().doRemoveRow(selectedRow, false); + } finally { + // always reset busy model to false + ObserveContext.get().getObserveMainUI().setBusy(false); + } } - public Set<String> loadSpeciesList(String speciesListId, String errorMessage) { + protected Set<String> loadSpeciesList(String speciesListId, String errorMessage) { Set<String> speciesIds; try { @@ -294,7 +329,6 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } - protected void prepareSpeciesList(String speciesListId, JComponent speciesComponent, String errorMessage) throws DataSourceException { Set<String> speciesIds = loadSpeciesList(speciesListId, errorMessage); @@ -303,73 +337,6 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top Species2.newSpeciesByIdPredicate(speciesIds)); } - protected void loadTableEditBeanForm(ContentMode mode) { - // par defaut, rien à faire - } - - @Override - public void openUI() throws Exception { - - super.openUI(); - - // récupération du mode de l'écran - ContentMode mode = computeContentMode(); - - ObserveContentTableUI<E, D> ui = getUi(); - - int oldIndex = ui.getTableModel().getSelectedRow(); - - ui.getTableModel().dettachModel(); - - // chargement du bean d'édition - loadEditBean(mode); - - // chargement de l'écran d'édition - loadTableEditBeanForm(mode); - - // enregistrement du mode de l'écran - getModel().setMode(mode); - - // initialisation du modèle du tableau - getUi().getTableModel().attachModel(); - - boolean canEdit = mode == ContentMode.UPDATE; - - if (canEdit) { - // on lance le mode edition - ui.startEdit(null); - } - - if (!ui.getTableModel().isEmpty()) { - if (ui.getTableModel().getRowCount() <= oldIndex) { - oldIndex = 0; - } - if (oldIndex == -1) { - oldIndex = 0; - } - - // le tableau contient au moins une entrée - // on la sélectionne la première entrée - ui.getTableModel().changeSelectedRow(oldIndex); - } - - if (canEdit) { - - // on force l'ecran en non modification - //FIXME normalement, on ne devrait pas a avoir a faire ca ? - //FIXME mais il est possible que les validateurs modifient l'état - //FIXME modified sur l'ecran lors des bindings d'initilisation... - getModel().setModified(false); - } - } - - @Override - public void startEditUI(String... binding) { - - addUpdateInfoMessage(); - super.startEditUI(binding); - } - protected void addUpdateInfoMessage() { String message = n("observe.entity.message.updating"); ObserveNode node = getTreeHelper(getUi()).getSelectedNode(); @@ -379,163 +346,36 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top addMessage(getUi(), NuitonValidatorScope.INFO, entityLabel, message); } - public void removeSelectedRow(int selectedRow) { - try { - getTableModel().doRemoveRow(selectedRow, false); - } finally { - - // always reset busy model to false - ObserveContext.get().getObserveMainUI().setBusy(false); - } - } - -// @Override -// protected boolean doSave(E bean, -// DataService dataService, -// DataSource dataSource, -// TopiaEntityBinder<E> binder) throws Exception { -// -// ObserveContentTableUI<E, D> ui = getUi(); -// -// List<D> objets = ui.getTableModel().getData(); -// -// boolean canContinue; -// try { -// canContinue = prepareSave(bean, objets); -// } catch (Exception e) { -// if (log.isErrorEnabled()) { -// log.error(e); -// } -// ErrorDialogUI.showError(e); -// canContinue = false; -// } -// if (!canContinue) { -// -// // l'utilisateur a choisi de ne pas sauvegarder -// return false; -// } -// doPersist(bean, dataService, dataSource); -// -// -// return true; -// } - @Override - protected boolean doSave(E bean) { + protected final boolean doSave(E bean) { - ObserveContentTableUI<E, D> ui = getUi(); + List<D> objets = getTableModel().getData(); - List<D> objets = ui.getTableModel().getData(); + boolean canContinue = prepareSave(bean, objets); - boolean canContinue; - try { - canContinue = prepareSave(bean, objets); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error(e); - } - ErrorDialogUI.showError(e); - canContinue = false; - } - if (!canContinue) { + if (canContinue) { + + doPersist(bean); + canContinue = true; - // l'utilisateur a choisi de ne pas sauvegarder - return false; } - doPersist(bean); + return canContinue; - return true; } + protected boolean prepareSave(E editBean, List<D> objets) { -// protected void doPersist(E bean, DataService dataService, DataSource dataSource) throws DataSourceException { -// // sauvegarde du bean en base -// dataService.update(dataSource, null, bean, getUpdateExecutor()); -// } - - protected void doPersist(E editBean) { - + // par defaut, rien de specifique a faire avant de faire la sauvegarde + return true; } -// @Override -// protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { -// -// List<D> childs = getUi().getTableModel().getData(); -// -// E editBean = getBean(); -// -// TopiaEntityBinder<E> binder = getLoadBinder(); -// -// Loador<D> childBinder = getModel().getChildLoador(); -// -// EntityListUpdator<E, D> childUpdator = getModel().getChildsUpdator(); -// -// // recopie des propriétés du bean en excluant toujours la liste des fils -// binder.copyExcluding(editBean, beanToSave, childUpdator.getPropertyName()); -// -// // on conserve l'ancienne liste des fils (pour traitement ultérieure) -// Collection<D> oldChilds = -// new ArrayList<D>(childUpdator.getChilds(beanToSave)); -// -// // suppression des fils dans le bean a sauver -// childUpdator.removeAll(beanToSave); -// -// TopiaDAO<D> dao = ObserveDAOHelper.getDAO(tx, getModel().getChildType()); -// -// for (D child : childs) { -// -// D childToSave; -// -// if (child.getTopiaId() == null) { -// -// // creation du fils -// Map<String, Object> map = childBinder.obtainProperties(child); -// -// childToSave = dao.create(map); -// -// } else { -// -// // mise a jour du fils -// -// childToSave = dao.findByTopiaId(child.getTopiaId()); -// -// childBinder.load(child, childToSave, false); -// } -// -// // ajout du fils au bean à sauver -// childUpdator.addToList(beanToSave, childToSave); -// } -// -// // on donne la main aux implantations pour faire des traitements -// // supplémentaires -// onUpdateFinalize(tx, beanToSave, oldChilds); -// -// return beanToSave; -// } - @Override protected void afterSave(boolean refresh) { // on recharge l'écran resetEditUI(); - } - - protected boolean prepareSave(E editBean, List<D> objets) throws Exception { - // par defaut, rien de specifique a faire avant de faire la sauvegarde - return true; } - protected void onUpdateFinalize(TopiaContext tx, E bean, Collection<D> oldChilds) throws TopiaException { - // par défaut, rien à faire - } - - protected ContentTableModel<E, D> getTableModel() { - return getUi().getTableModel(); - } - - protected void resetEditBean() { - getTableModel().resetEditBean(); - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java index 2f6646b..fadfe3c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIModel.java @@ -99,7 +99,7 @@ public abstract class ContentTableUIModel<E extends TopiaEntity, D extends Topia BinderService binderService = ObserveServiceHelper.get().getBinderService(); - this.childLoador = binderService.getTopiaBinder(childType, childBinderContext); + this.childLoador = binderService.getBinder(childType, childBinderContext); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SizeMeasuresTableModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SizeMeasuresTableModel.java index 3bb120a..a08f575 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SizeMeasuresTableModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SizeMeasuresTableModel.java @@ -22,6 +22,7 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.entities.longline.SizeMeasure; import fr.ird.observe.entities.longline.SizeMeasureImpl; @@ -40,7 +41,7 @@ public class SizeMeasuresTableModel extends EditableTableWithCacheTableModelSupp public SizeMeasuresTableModel() { - super(ObserveServiceHelper.get().getBinderService().getSimpleTopiaBinder(SizeMeasure.class)); + super(ObserveServiceHelper.get().getBinderService().getBinder(SizeMeasure.class, BinderService.EDIT)); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/WeightMeasuresTableModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/WeightMeasuresTableModel.java index d36086d..e125f4b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/WeightMeasuresTableModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/WeightMeasuresTableModel.java @@ -22,6 +22,7 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.entities.longline.WeightMeasure; import fr.ird.observe.entities.longline.WeightMeasureImpl; @@ -39,7 +40,7 @@ public class WeightMeasuresTableModel extends EditableTableWithCacheTableModelSu private static final long serialVersionUID = 1L; public WeightMeasuresTableModel() { - super(ObserveServiceHelper.get().getBinderService().getSimpleTopiaBinder(WeightMeasure.class)); + super(ObserveServiceHelper.get().getBinderService().getBinder(WeightMeasure.class, BinderService.EDIT)); } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 0a96590..8e59f98 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -54,10 +54,10 @@ import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Set; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -71,11 +71,16 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non /** Logger */ static private Log log = LogFactory.getLog(NonTargetCatchUIHandler.class); - /** l'entrée dans le contexte pour récupérer la liste complete des speciess */ + /** + * L'entrée dans le contexte pour récupérer la liste complete des espèces. + */ protected final JAXXContextEntryDef<List<Species>> ALL_ESPECES_ENTRY = UIHelper.newListContextEntryDef("NonTargetCatchUI-all-speciess"); - protected final JAXXContextEntryDef<List<NonTargetLength>> ALL_TAILLES_TO_DELETE_ENTRY = + /** + * L'entrée dans le contexte pour conserver les mensurations obsolètes à supprimer lors de la sauvegarde. + */ + protected final JAXXContextEntryDef<List<NonTargetLength>> ALL_NON_TARGET_LENGTH_TO_DELETE_ENTRY = UIHelper.newListContextEntryDef("NonTargetCatchUI-all-taille-to-delete"); /** @@ -147,69 +152,44 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non return (NonTargetCatchUI) super.getUi(); } - public String getCatchWeightDataTip(NonTargetCatchComputedValueSource computed) { - String result; - - if (computed == null) { - result = t("observe.common.catchWeightComputed.observed.tip"); - } else { - result = t("observe.common.catchWeightComputed.computed.tip", computed.toString()); - } - return result; - } - - public String getTotalCountDataTip(NonTargetCatchComputedValueSource computed) { - String result; - - if (computed == null) { - result = t("observe.common.totalCountComputed.observed.tip"); - } else { - result = t("observe.common.totalCountComputed.computed.tip", computed.toString()); - - } - return result; - } - - public String getMeanWeightDataTip(NonTargetCatchComputedValueSource computed) { - String result; - - if (computed == null) { - result = t("observe.common.meanWeightComputed.observed.tip"); - } else { - result = t("observe.common.meanWeightComputed.computed.tip", computed.toString()); - } - return result; - } - - public String getMeanLengthDataTip(NonTargetCatchComputedValueSource computed) { - String result; - - if (computed == null) { - result = t("observe.common.meanLengthComputed.observed.tip"); - } else { - result = t("observe.common.meanLengthComputed.computed.tip", computed.toString()); - } - return result; - } + @Override + protected void initTableUI(DefaultTableCellRenderer renderer) { - public void resetCatchWeightComputed() { - getTableEditBean().setCatchWeightComputedSource(null); - getUi().getCatchWeight().grabFocus(); - } + JTable table = getUi().getTable(); - public void resetTotalCountComputed() { - getTableEditBean().setTotalCountComputedSource(null); - getUi().getTotalCount().grabFocus(); - } + UIHelper.fixTableColumnWidth(table, 3, 55); + UIHelper.fixTableColumnWidth(table, 4, 65); + UIHelper.fixTableColumnWidth(table, 5, 75); + UIHelper.fixTableColumnWidth(table, 6, 55); + UIHelper.fixTableColumnWidth(table, 7, 50); - public void resetMeanWeightComputed() { - getTableEditBean().setMeanWeightComputedSource(null); - getUi().getMeanWeight().grabFocus(); - } + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.nonTargetCatch.table.speciesFaune"), + n("observe.nonTargetCatch.table.speciesFaune.tip"), + n("observe.nonTargetCatch.table.speciesFate"), + n("observe.nonTargetCatch.table.speciesFate.tip"), + n("observe.nonTargetCatch.table.reasonForDiscard"), + n("observe.nonTargetCatch.table.reasonForDiscard.tip"), + n("observe.nonTargetCatch.table.catchWeight"), + n("observe.nonTargetCatch.table.catchWeight.tip"), + n("observe.nonTargetCatch.table.totalCount"), + n("observe.nonTargetCatch.table.totalCount.tip"), + n("observe.nonTargetCatch.table.meanWeight"), + n("observe.nonTargetCatch.table.meanWeight.tip"), + n("observe.nonTargetCatch.table.meanLength"), + n("observe.nonTargetCatch.table.meanLength.tip"), + n("observe.nonTargetCatch.table.comment"), + n("observe.nonTargetCatch.table.comment.tip")); - public void resetMeanLengthComputed() { - getTableEditBean().setMeanLengthComputedSource(null); - getUi().getMeanLength().grabFocus(); + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, SpeciesFate.class)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newDecorateTableCellRenderer(renderer, ReasonForDiscard.class)); + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 4, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 5, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 6, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 7, UIHelper.newStringTableCellRenderer(renderer, 10, true)); } @Override @@ -289,9 +269,8 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override - protected void onSelectedRowChanged(int editingRow, - NonTargetCatch bean, - boolean create) { + protected void onSelectedRowChanged(int editingRow, NonTargetCatch bean, boolean create) { + NonTargetCatchUI ui = getUi(); ContentTableModel<SetSeine, NonTargetCatch> model = getTableModel(); @@ -302,20 +281,23 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non return; } - List<Species> availableEspeces; + List<Species> availableSpecies; JComponent requestFocus; if (create) { - availableEspeces = new ArrayList<Species>(ALL_ESPECES_ENTRY.getContextValue(ui)); + availableSpecies = new ArrayList<Species>(ALL_ESPECES_ENTRY.getContextValue(ui)); requestFocus = ui.getSpecies(); + } else { + Species species = bean.getSpecies(); - availableEspeces = Arrays.asList(species); + availableSpecies = Collections.singletonList(species); requestFocus = ui.getTable(); + } - ui.getSpecies().setData(availableEspeces); + ui.getSpecies().setData(availableSpecies); requestFocus.requestFocus(); NonTargetCatch tableEditBean = getTableEditBean(); @@ -330,103 +312,48 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non tableEditBean.removePropertyChangeListener(NonTargetCatch.PROPERTY_MEAN_LENGTH, meanLengthChanged); tableEditBean.addPropertyChangeListener(NonTargetCatch.PROPERTY_MEAN_LENGTH, meanLengthChanged); - } - - @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - - JTable table = getUi().getTable(); - - UIHelper.fixTableColumnWidth(table, 3, 55); - UIHelper.fixTableColumnWidth(table, 4, 65); - UIHelper.fixTableColumnWidth(table, 5, 75); - UIHelper.fixTableColumnWidth(table, 6, 55); - UIHelper.fixTableColumnWidth(table, 7, 50); - - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.nonTargetCatch.table.speciesFaune"), - n("observe.nonTargetCatch.table.speciesFaune.tip"), - n("observe.nonTargetCatch.table.speciesFate"), - n("observe.nonTargetCatch.table.speciesFate.tip"), - n("observe.nonTargetCatch.table.reasonForDiscard"), - n("observe.nonTargetCatch.table.reasonForDiscard.tip"), - n("observe.nonTargetCatch.table.catchWeight"), - n("observe.nonTargetCatch.table.catchWeight.tip"), - n("observe.nonTargetCatch.table.totalCount"), - n("observe.nonTargetCatch.table.totalCount.tip"), - n("observe.nonTargetCatch.table.meanWeight"), - n("observe.nonTargetCatch.table.meanWeight.tip"), - n("observe.nonTargetCatch.table.meanLength"), - n("observe.nonTargetCatch.table.meanLength.tip"), - n("observe.nonTargetCatch.table.comment"), - n("observe.nonTargetCatch.table.comment.tip")); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, SpeciesFate.class)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newDecorateTableCellRenderer(renderer, ReasonForDiscard.class)); - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 4, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 5, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 6, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 7, UIHelper.newStringTableCellRenderer(renderer, 10, true)); - } - - @Override - protected boolean doSave(SetSeine bean) { - - try { - - return super.doSave(bean); - - } finally { - - // toujours supprimer la référence du context, quoiqu'il arrive - ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); - } } @Override - protected boolean prepareSave(SetSeine editBean, List<NonTargetCatch> objets) throws Exception { + protected boolean prepareSave(SetSeine editBean, List<NonTargetCatch> objets) { super.prepareSave(editBean, objets); List<Species> speciessUsed = getTableModel().getColumnValues(0); - - Collection<Species> speciessToDelete = new HashSet<Species>(); - List<NonTargetLength> tailleToDelete = new ArrayList<NonTargetLength>(); + Set<String> speciesIdsUsed = new HashSet<String>(); + for (Species species : speciessUsed) { + speciesIdsUsed.add(species.getTopiaId()); + } NonTargetSampleService service = getService(NonTargetSampleService.class); - service.getObsoleteEspeceForNonTargetSample(editBean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete); + List<NonTargetLength> lengthsToDelete = service.getObsoleteNonTargetLengths(editBean.getTopiaId(), speciesIdsUsed); - if (!tailleToDelete.isEmpty()) { + if (!lengthsToDelete.isEmpty()) { + + // il existe des echantillon faune a supprimer on demande une confirmation + + Set<Species> speciessToDelete = new HashSet<Species>(); + for (NonTargetLength targetLength : lengthsToDelete) { + speciessToDelete.add(targetLength.getSpecies()); + } - // il existe des echantillon faune a supprimer on demande une - // confirmation StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); - Decorator<Species> decorator; - Decorator<NonTargetLength> decorator2; - decorator = getDecoratorService().getDecoratorByType(Species.class); - decorator2 = getDecoratorService().getDecoratorByType(NonTargetLength.class); + Decorator<Species> speciesDecorator = getDecoratorService().getDecoratorByType(Species.class); + Decorator<NonTargetLength> nonTargetLengthDecorator = getDecoratorService().getDecoratorByType(NonTargetLength.class); for (Species e : speciessToDelete) { - sb.append(" - ").append(decorator.toString(e)).append('\n'); + sb.append(" - ").append(speciesDecorator.toString(e)).append('\n'); } - for (NonTargetLength t : tailleToDelete) { - sb2.append(" - ").append(decorator2.toString(t)).append('\n'); + for (NonTargetLength t : lengthsToDelete) { + sb2.append(" - ").append(nonTargetLengthDecorator.toString(t)).append('\n'); } int reponse = UIHelper.askUser( t("observe.title.need.confirm"), t("observe.nonTargetCatch.message.table.will.delete.nonTargetSample", sb.toString(), sb2.toString()), JOptionPane.ERROR_MESSAGE, - new Object[]{ - t("observe.choice.continue"), - t("observe.choice.cancel")}, + new Object[]{t("observe.choice.continue"), t("observe.choice.cancel")}, 0); if (log.isDebugEnabled()) { log.debug("response : " + reponse); @@ -444,7 +371,8 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } // on conserve les tailles a supprimer - ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); + ALL_NON_TARGET_LENGTH_TO_DELETE_ENTRY.setContextValue(getUi(), lengthsToDelete); + } return true; @@ -454,11 +382,84 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non @Override protected void doPersist(SetSeine editBean) { - List<NonTargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); + List<NonTargetLength> tailleToDelete = ALL_NON_TARGET_LENGTH_TO_DELETE_ENTRY.getContextValue(getUi()); - NonTargetCatchService service = getService(NonTargetCatchService.class); - service.save(editBean, tailleToDelete); + try { + NonTargetCatchService service = getService(NonTargetCatchService.class); + service.save(editBean, tailleToDelete); + + } finally { + + // toujours supprimer la référence du context, quoiqu'il arrive + ALL_NON_TARGET_LENGTH_TO_DELETE_ENTRY.removeContextValue(getUi()); + } + + } + + public String getCatchWeightDataTip(NonTargetCatchComputedValueSource computed) { + String result; + + if (computed == null) { + result = t("observe.common.catchWeightComputed.observed.tip"); + } else { + result = t("observe.common.catchWeightComputed.computed.tip", computed.toString()); + } + return result; + } + + public String getTotalCountDataTip(NonTargetCatchComputedValueSource computed) { + String result; + + if (computed == null) { + result = t("observe.common.totalCountComputed.observed.tip"); + } else { + result = t("observe.common.totalCountComputed.computed.tip", computed.toString()); + + } + return result; + } + + public String getMeanWeightDataTip(NonTargetCatchComputedValueSource computed) { + String result; + + if (computed == null) { + result = t("observe.common.meanWeightComputed.observed.tip"); + } else { + result = t("observe.common.meanWeightComputed.computed.tip", computed.toString()); + } + return result; + } + + public String getMeanLengthDataTip(NonTargetCatchComputedValueSource computed) { + String result; + + if (computed == null) { + result = t("observe.common.meanLengthComputed.observed.tip"); + } else { + result = t("observe.common.meanLengthComputed.computed.tip", computed.toString()); + } + return result; + } + + public void resetCatchWeightComputed() { + getTableEditBean().setCatchWeightComputedSource(null); + getUi().getCatchWeight().grabFocus(); + } + + public void resetTotalCountComputed() { + getTableEditBean().setTotalCountComputedSource(null); + getUi().getTotalCount().grabFocus(); + } + + public void resetMeanWeightComputed() { + getTableEditBean().setMeanWeightComputedSource(null); + getUi().getMeanWeight().grabFocus(); + } + + public void resetMeanLengthComputed() { + getTableEditBean().setMeanLengthComputedSource(null); + getUi().getMeanLength().grabFocus(); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index 920fd6c..88bc806 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -36,6 +36,7 @@ import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.editor.NumberEditor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.NuitonValidatorScope; @@ -46,7 +47,7 @@ import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -103,6 +104,38 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam return (NonTargetSampleUI) super.getUi(); } + @Override + protected void initTableUI(DefaultTableCellRenderer renderer) { + + JTable table = getUi().getTable(); + + UIHelper.fixTableColumnWidth(table, 1, 100); + UIHelper.fixTableColumnWidth(table, 2, 100); + + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.nonTargetSample.table.speciesFaune"), + n("observe.nonTargetSample.table.speciesFaune.tip"), + n("observe.nonTargetSample.table.length"), + n("observe.nonTargetSample.table.length.tip"), + n("observe.nonTargetSample.table.meanWeight"), + n("observe.nonTargetSample.table.meanWeight.tip"), + n("observe.nonTargetSample.table.count"), + n("observe.nonTargetSample.table.count.tip"), + n("observe.nonTargetSample.table.gender"), + n("observe.nonTargetSample.table.gender.tip"), + n("observe.nonTargetSample.table.picturesReferences"), + n("observe.nonTargetSample.table.picturesReferences.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 4, UIHelper.newDecorateTableCellRenderer(renderer, Sex.class)); + UIHelper.setTableColumnRenderer(table, 5, renderer); + + } + public void resetWeightSource() { getTableEditBean().setWeightSource(false); getUi().getWeight().grabFocus(); @@ -134,7 +167,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam String setId = getDataContext().getSelectedSetId(); NonTargetSampleService service = getService(NonTargetSampleService.class); - speciesList = service.getAvailableEspeceForNonTargetSample(setId); + speciesList = service.getAvailableSpeciesForNonTargetSample(setId); ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); } @@ -152,6 +185,8 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam String setId = getDataContext().getSelectedSetId(); + NonTargetSampleService service = getService(NonTargetSampleService.class); + if (editBean.getTopiaId() != null && editBean.isNonTargetLengthEmpty()) { // remove orphan target sample @@ -159,47 +194,22 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam log.info("Remove obsolete nonTargetSample " + editBean.getTopiaId() + " from Set: " + setId); } - getService(NonTargetSampleService.class).delete(setId, editBean); + service.delete(setId, editBean); } else { - String savedId = getService(NonTargetSampleService.class).save(setId, editBean); + String savedId = service.save(setId, editBean); editBean.setTopiaId(savedId); getService(NonTargetLengthService.class).save(editBean); + } } -// @Override -// protected NonTargetSample onCreate(TopiaContext tx, -// Object parent, -// NonTargetSample editBean) throws TopiaException { -// SetSeine parentBean = (SetSeine) parent; -// NonTargetSample beanToSave = -// ObserveDAOHelper.getNonTargetSampleDAO(tx).create(); -// if (log.isInfoEnabled()) { -// log.info("Echantillon faune " + beanToSave.getTopiaId() + -// " was created."); -// } -// editBean.setTopiaId(beanToSave.getTopiaId()); -// editBean.setTopiaCreateDate(beanToSave.getTopiaCreateDate()); -// editBean.setTopiaVersion(beanToSave.getTopiaVersion()); -// parentBean.addNonTargetSample(beanToSave); -// return beanToSave; -// } - -// @Override -// protected void onDelete(TopiaContext tx, Object parent, NonTargetSample beanToDelete) throws TopiaException { -// SetSeine parentBean = (SetSeine) parent; -// parentBean.removeNonTargetSample(beanToDelete); -// } - - @SuppressWarnings("unchecked") @Override - protected void onSelectedRowChanged(int editingRow, - NonTargetLength bean, - boolean create) { + protected void onSelectedRowChanged(int editingRow, NonTargetLength bean, boolean create) { + ContentTableModel<NonTargetSample, NonTargetLength> model = getTableModel(); if (!model.isEditable()) { @@ -223,12 +233,10 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam ui.getAcquisitionModeGroup().setSelectedValue(ModeSaisieEchantillonEnum.byEffectif); } - availableEspeces = new ArrayList<Species>( - ALL_ESPECES_ENTRY.getContextValue(ui)); + availableEspeces = new ArrayList<Species>(ALL_ESPECES_ENTRY.getContextValue(ui)); requestFocus = ui.getSpecies(); - } else { - requestFocus = ui.getCount(); + } else { // on passe le mode de saisie int acquisitionMode = bean.getAcquisitionMode(); @@ -237,8 +245,11 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam ui.getAcquisitionModeGroup().setSelectedValue(null); ui.getAcquisitionModeGroup().setSelectedValue(enumValue); - availableEspeces = Arrays.asList(species); + availableEspeces = Collections.singletonList(species); + requestFocus = ui.getCount(); + } + ui.getSpecies().setData(availableEspeces); requestFocus.requestFocus(); @@ -248,40 +259,12 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam tableEditBean.removePropertyChangeListener(NonTargetLength.PROPERTY_LENGTH, lengthChanged); tableEditBean.addPropertyChangeListener(NonTargetLength.PROPERTY_LENGTH, lengthChanged); - } - - @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - JTable table = getUi().getTable(); - - UIHelper.fixTableColumnWidth(table, 1, 100); - UIHelper.fixTableColumnWidth(table, 2, 100); - - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.nonTargetSample.table.speciesFaune"), - n("observe.nonTargetSample.table.speciesFaune.tip"), - n("observe.nonTargetSample.table.length"), - n("observe.nonTargetSample.table.length.tip"), - n("observe.nonTargetSample.table.meanWeight"), - n("observe.nonTargetSample.table.meanWeight.tip"), - n("observe.nonTargetSample.table.count"), - n("observe.nonTargetSample.table.count.tip"), - n("observe.nonTargetSample.table.gender"), - n("observe.nonTargetSample.table.gender.tip"), - n("observe.nonTargetSample.table.picturesReferences"), - n("observe.nonTargetSample.table.picturesReferences.tip")); - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 4, UIHelper.newDecorateTableCellRenderer(renderer, Sex.class)); - UIHelper.setTableColumnRenderer(table, 5, renderer); } @Override protected ContentMode getContentMode(DataContext dataContext) { + ContentMode mode = super.getContentMode(dataContext); String setId = getDataContext().getSelectedSetId(); @@ -320,20 +303,21 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam return; } - NonTargetSampleUI ui = getUi(); + NumberEditor weight = getUi().getWeight(); + NumberEditor count = getUi().getCount(); - boolean createMode = ui.getTableModel().isCreate(); + boolean createMode = getTableModel().isCreate(); - NonTargetLength editBean = ui.getTableEditBean(); + NonTargetLength editBean = getTableEditBean(); switch (newMode) { case byEffectif: // le weight n'est pas modifiable - ui.getWeight().setEnabled(false); + weight.setEnabled(false); // l'count est modifiable - ui.getCount().setEnabled(true); + count.setEnabled(true); if (createMode) { @@ -347,11 +331,10 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam case byIndividu: // le weight est pas modifiable - ui.getWeight().setEnabled(true); + weight.setEnabled(true); // l'count n'est pas modifiable et est toujours de 1 - ui.getCount().setEnabled(false); - + count.setEnabled(false); if (createMode) { @@ -365,6 +348,9 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam // on propage le mode de saisie dans le bean editBean.setAcquisitionMode(newMode.ordinal()); + } + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index f012ad7..1db6bda 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -47,8 +47,7 @@ import static org.nuiton.i18n.I18n.n; public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<FloatingObject, ObjectObservedSpecies> { /** Logger */ - static private Log log = - LogFactory.getLog(ObjectObservedSpeciesUIHandler.class); + public static final Log log = LogFactory.getLog(ObjectObservedSpeciesUIHandler.class); public ObjectObservedSpeciesUIHandler(ObjectObservedSpeciesUI ui) { super(ui, DataContextType.SetSeine); @@ -72,11 +71,6 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati } -// @Override -// protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { -// return dataContext.getSelectedFloatingObjectId(); -// } - @Override protected void onSelectedRowChanged(int editingRow, ObjectObservedSpecies bean, boolean create) { if (log.isDebugEnabled()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java index d9a3e19..3967c6a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java @@ -23,8 +23,8 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Species; @@ -34,7 +34,7 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.data.seine.NonTargetCatchService; +import fr.ird.observe.services.data.seine.TargetCatchService; import fr.ird.observe.services.data.seine.TargetSampleService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; @@ -55,12 +55,11 @@ import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -74,12 +73,14 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target /** Logger */ private static final Log log = LogFactory.getLog(TargetCatchUIHandler.class); - JAXXContextEntryDef<List<TargetLength>> ALL_TAILLES_TO_DELETE_ENTRY = + /** + * L'entrée dans le contexte pour conserver les mensurations obsolètes à supprimer lors de la sauvegarde. + */ + JAXXContextEntryDef<List<TargetLength>> ALL_TARGET_LENGTH_TO_DELETE_ENTRY = UIHelper.newListContextEntryDef("TargetCatchUI-all-taille-to-delete"); /** - * l'entrée dans le contexte pour récupérer la liste complètes des - * catégories + * L'entrée dans le contexte pour récupérer la liste complète des catégories. */ JAXXContextEntryDef<List<WeightCategory>> ALL_CATEGORIES_ENTRY = UIHelper.newListContextEntryDef("TargetCatchUI-all-categories"); @@ -95,10 +96,11 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target @Override public void initUI() throws Exception { + super.initUI(); - // lors de la modification d'une species (sur une entree non sauvee) - // - on recalcule la liste des categories pour cette species. + // lors de la modification d'une espèces (sur une entree non sauvee) + // - on recalcule la liste des categories pour cette espèce. // - on reinitialiser la categorie selectionnee getUi().getSpecies().addPropertyChangeListener( @@ -108,18 +110,15 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target @Override public void propertyChange(PropertyChangeEvent evt) { - ContentTableModel<SetSeine, TargetCatch> model; - model = getTableModel(); + ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); + TargetCatch bean = model.getRowBean(); - if (model.getRowBean().getTopiaId() == null) { - - // en mode creation , on doit recalculer la liste - // des categories + if (Entities.isNew(bean)) { + // en mode creation , on doit recalculer la liste des categories Species species = (Species) evt.getNewValue(); - - onEspeceChanged(species); + } } } @@ -127,12 +126,42 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } @Override + protected void initTableUI(DefaultTableCellRenderer renderer) { + + JTable table = getUi().getTable(); + + UIHelper.fixTableColumnWidth(table, 2, 100); + UIHelper.fixTableColumnWidth(table, 3, 50); + UIHelper.fixTableColumnWidth(table, 4, 50); + + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.targetCatch.table.speciesThon"), + n("observe.targetCatch.table.speciesThon.tip"), + n("observe.targetCatch.table.weightCategory"), + n("observe.targetCatch.table.weightCategory.tip"), + n("observe.targetCatch.table.well"), + n("observe.targetCatch.table.well.tip"), + n("observe.targetCatch.table.weight"), + n("observe.targetCatch.table.weight.tip"), + n("observe.targetCatch.table.comment"), + n("observe.targetCatch.table.comment.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, WeightCategory.class)); + UIHelper.setTableColumnRenderer(table, 2, renderer); + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 4, UIHelper.newStringTableCellRenderer(renderer, 10, true)); + + } + + @Override protected void loadEditBean(ContentMode mode) { List<Species> speciesList; List<WeightCategory> categorieList; - if (mode == ContentMode.UPDATE) { + if (ContentMode.UPDATE == mode) { // on charge le formulaire uniquement si en mode édition @@ -142,7 +171,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineTargetCatchId(); - java.util.Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); + Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); categorieList = Species2.filterWeightCategoryBySpeciesIds(categorieList, speciesIds); @@ -165,109 +194,63 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target speciesList = new ArrayList<Species>(); categorieList = new ArrayList<WeightCategory>(); - } - TargetCatchUI ui = getUi(); + } ALL_CATEGORIES_ENTRY.setContextValue(ui, categorieList); - ui.getSpecies().setData(speciesList); + getUi().getSpecies().setData(speciesList); String setId = getDataContext().getSelectedSetId(); - SetSeine setSeine = getService(NonTargetCatchService.class).loadForEdit(setId); + TargetCatchService service = getService(TargetCatchService.class); + SetSeine setSeine = service.loadForEdit(setId); copy(SetSeine.class, BinderService.EDIT_TARGET_CATCH, setSeine, getBean()); } -// @Override -// protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { -// Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); -// Collection<TargetCatch> data = new ArrayList<TargetCatch>(); -// if (CollectionUtils.isNotEmpty(childs)) { -// TopiaDAO<TargetCatch> dao = -// getDataSource().getDAO(tx, getTableEditBean()); -// TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); -// -// DecoratorService decoratorService = getDecoratorService(); -// -// for (TargetCatch c : childs) { -// if (c.isDiscarded()) { -// // c'est un rejet, on ne le retient pas dans cette liste -// if (log.isDebugEnabled()) { -// log.debug("targetDiscarded " + c.getSpecies().getLabel2() + -// " non retenu."); -// } -// continue; -// } -// try { -// -// TargetCatch c2 = getModel().newTableEditBean(); -// TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); -// WeightCategory weightCategory = safeC.getWeightCategory(); -// if (weightCategory != null) { -// Species species = weightCategory.getSpecies(); -// decoratorService.decorate(species); -// } -// childLoador.load(safeC, c2, true); -// data.add(c2); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// } -// } -// return data; -// } - @Override - protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { + protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) { - // on recupere les speciess acceptables pour des echantillonnages - // i.e une species d'un targetCatch + // on recupere les espèces acceptables pour des echantillonnages + // i.e une espèce d'un targetCatch - Collection<Species> speciessUsed = new HashSet<Species>(); - for (TargetCatch c : objets) { - speciessUsed.add(c.getSpecies()); + Set<String> speciesIdsUsed = new HashSet<String>(); + for (TargetCatch targetCatch : objets) { + speciesIdsUsed.add(targetCatch.getSpecies().getTopiaId()); } - // il faut supprimer les echantillon thons sur des speciess qui ne - // sont plus sur un rejet - - List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); - Collection<Species> speciessToDelete = new HashSet<Species>(); + // il faut supprimer les echantillon thons sur des espèces qui ne sont plus sur un rejet TargetSampleService service = getService(TargetSampleService.class); - service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete, - false); + List<TargetLength> targetLengthsToDelete = + service.getObsoleteTargetLengths(bean.getTopiaId(), speciesIdsUsed, false); + + if (!targetLengthsToDelete.isEmpty()) { - if (!tailleToDelete.isEmpty()) { + Set<Species> speciessToDelete = new HashSet<Species>(); + for (TargetLength targetLength : targetLengthsToDelete) { + speciessToDelete.add(targetLength.getSpecies()); + } - // il existe des echantillon thon a supprimer on demande une - // confirmation + // il existe des echantillon thon a supprimer on demande une confirmation StringBuilder sb = new StringBuilder(512); StringBuilder sb2 = new StringBuilder(512); - Decorator<Species> decorator = - getDecoratorService().getDecoratorByType(Species.class); - Decorator<TargetLength> decorator2 = - getDecoratorService().getDecoratorByType(TargetLength.class); + Decorator<Species> speciesDecorator = getDecoratorService().getDecoratorByType(Species.class); + Decorator<TargetLength> targetLengthDecorator = getDecoratorService().getDecoratorByType(TargetLength.class); for (Species e : speciessToDelete) { - sb.append(" - ").append(decorator.toString(e)).append('\n'); + sb.append(" - ").append(speciesDecorator.toString(e)).append('\n'); } - for (TargetLength t : tailleToDelete) { - sb2.append(" - ").append(decorator2.toString(t)).append('\n'); + for (TargetLength t : targetLengthsToDelete) { + sb2.append(" - ").append(targetLengthDecorator.toString(t)).append('\n'); } int reponse = UIHelper.askUser( t("observe.title.need.confirm"), t("observe.targetDiscarded.message.table.will.delete.targetLength", sb.toString(), sb2.toString()), JOptionPane.ERROR_MESSAGE, - new Object[]{ - t("observe.choice.continue"), - t("observe.choice.cancel")}, + new Object[]{t("observe.choice.continue"), t("observe.choice.cancel")}, 0); if (log.isDebugEnabled()) { log.debug("response : " + reponse); @@ -284,77 +267,69 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // l'utilisateur a choisi de ne pas continuer return false; + } // on conserve les tailles a supprimer - ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); + ALL_TARGET_LENGTH_TO_DELETE_ENTRY.setContextValue(getUi(), targetLengthsToDelete); + } for (TargetCatch targetCatch : objets) { // on attache la set targetCatch.setSetSeine(bean); + } + return true; + } -// @Override -// protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { -// -// if (oldChilds != null && !oldChilds.isEmpty()) { -// -// // on reinjecte les rejet thon precedemment saisie dans la set -// for (TargetCatch targetCatch : oldChilds) { -// if (targetCatch.isDiscarded()) { -// bean.addTargetCatch(targetCatch); -// } -// } -// } -// -// -// List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); -// -// if (tailleToDelete != null && !tailleToDelete.isEmpty()) { -// -// // on a demande la suppression de taille obsoletes -// -// if (log.isInfoEnabled()) { -// log.info("Will remove " + tailleToDelete.size() + -// " obsolete targetLength(s)."); -// } -// -// TargetSample echantillon = bean.getTargetSample(false); -// -// // on supprime les echantillons obsoletes -// echantillon.getTargetLength().removeAll(tailleToDelete); -// } -// } + @Override + protected void doPersist(SetSeine editBean) { + + List<TargetLength> tailleToDelete = ALL_TARGET_LENGTH_TO_DELETE_ENTRY.getContextValue(getUi()); + + try { + + TargetCatchService service = getService(TargetCatchService.class); + service.save(editBean, tailleToDelete); + + } finally { + + // toujours supprimer la référence du context, quoiqu'il arrive + ALL_TARGET_LENGTH_TO_DELETE_ENTRY.removeContextValue(getUi()); + + } + + } @Override protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { TargetCatchUI ui = getUi(); - WeightCategory beanWeightCategory = bean.getWeightCategory(); - Species beanEspece = beanWeightCategory == null ? - null : beanWeightCategory.getSpecies(); + WeightCategory weightCategory = bean.getWeightCategory(); + Species species = weightCategory == null ? null : weightCategory.getSpecies(); + + BeanComboBox<Species> speciesComboBox = ui.getSpecies(); + BeanComboBox<WeightCategory> weightCategoryComboBox = ui.getWeightCategory(); JComponent requestFocus; if (create) { - // on reinitilise toujours l'species (pour reinitialiser la liste - // des categories) - ui.getSpecies().setSelectedItem(null); + // on reinitilise toujours l'espèce (pour reinitialiser la liste des categories) + speciesComboBox.setSelectedItem(null); if (!getTableModel().isCreate()) { - // on repositionne l'species (cela reconstruira la liste - // des categories) - ui.getSpecies().setSelectedItem(beanEspece); + // on repositionne l'espèce (cela reconstruira la liste des categories) + speciesComboBox.setSelectedItem(species); // on repositionne la categorie - ui.getWeightCategory().setSelectedItem(beanWeightCategory); + weightCategoryComboBox.setSelectedItem(weightCategory); } - requestFocus = ui.getSpecies(); + requestFocus = speciesComboBox; } else { @@ -362,48 +337,20 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // au singleton de sa valeur correspondante dans le bean // puisque dans ce mode, pas possibilite de modifier de cette // valeur (clef metier) - ui.getSpecies().setSelectedItem(beanEspece); - ui.getWeightCategory().setData( - Arrays.asList(beanWeightCategory)); - ui.getWeightCategory().setSelectedItem(beanWeightCategory); + speciesComboBox.setSelectedItem(species); + weightCategoryComboBox.setData(Collections.singletonList(weightCategory)); + weightCategoryComboBox.setSelectedItem(weightCategory); requestFocus = ui.getCatchWeight(); + } if (log.isDebugEnabled()) { - log.debug("selected categoriePoid " + beanWeightCategory); - log.debug("selected species " + beanEspece); + log.debug("selected categoriePoid " + weightCategory); + log.debug("selected species " + species); } requestFocus.requestFocus(); - } - - @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - - JTable table = getUi().getTable(); - - UIHelper.fixTableColumnWidth(table, 2, 100); - UIHelper.fixTableColumnWidth(table, 3, 50); - UIHelper.fixTableColumnWidth(table, 4, 50); - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.targetCatch.table.speciesThon"), - n("observe.targetCatch.table.speciesThon.tip"), - n("observe.targetCatch.table.weightCategory"), - n("observe.targetCatch.table.weightCategory.tip"), - n("observe.targetCatch.table.well"), - n("observe.targetCatch.table.well.tip"), - n("observe.targetCatch.table.weight"), - n("observe.targetCatch.table.weight.tip"), - n("observe.targetCatch.table.comment"), - n("observe.targetCatch.table.comment.tip")); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, WeightCategory.class)); - UIHelper.setTableColumnRenderer(table, 2, renderer); - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 4, UIHelper.newStringTableCellRenderer(renderer, 10, true)); } @SuppressWarnings("unchecked") @@ -418,21 +365,22 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // species puis une categorie availableCategories = Collections.emptyList(); + } else { - // un species est selectionnee, + // une espèce est selectionnee, // on calcule les categories pour cette species availableCategories = getAllCategories(getUi()); - // on ne conserve que les categories de l'species - for (Iterator<WeightCategory> it = availableCategories.iterator(); - it.hasNext(); ) { + // on ne conserve que les categories de l'espèce + for (Iterator<WeightCategory> it = availableCategories.iterator(); it.hasNext(); ) { WeightCategory weighte = it.next(); if (!species.equals(weighte.getSpecies())) { it.remove(); } } + } // on met a jour la liste des categories disponibles @@ -441,6 +389,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // on reinitialise toujours la categorie selectionnee combo.setSelectedItem(null); + } protected List<WeightCategory> getAllCategories(JAXXContext context) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java index f1ad697..b640cda 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java @@ -24,6 +24,7 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.constants.DataContextType; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Species; @@ -34,7 +35,8 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.data.seine.NonTargetCatchService; +import fr.ird.observe.services.data.seine.TargetCatchService; +import fr.ird.observe.services.data.seine.TargetSampleService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -45,21 +47,24 @@ import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.decorator.Decorator; import javax.swing.JComponent; +import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import static org.nuiton.i18n.I18n.n; +import static org.nuiton.i18n.I18n.t; /** * @author Tony Chemit - chemit@codelutin.com @@ -68,47 +73,30 @@ import static org.nuiton.i18n.I18n.n; public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, TargetCatch> { /** Logger */ - static private Log log = LogFactory.getLog(TargetDiscardCatchUIHandler.class); + private static final Log log = LogFactory.getLog(TargetDiscardCatchUIHandler.class); + /** + * L'entrée dans le contexte pour récupérer la liste complète des catégories. + */ JAXXContextEntryDef<List<WeightCategory>> ALL_CATEGORIES_ENTRY = UIHelper.newListContextEntryDef("RejetThonUI-all-categories"); + /** + * L'entrée dans le contexte pour récupérer la liste complète des raisons de rejet. + */ JAXXContextEntryDef<List<ReasonForDiscard>> ALL_RAISONS_REJET_ENTRY = UIHelper.newListContextEntryDef("RejetThonUI-all-reasonForDiscards"); - JAXXContextEntryDef<List<TargetLength>> ALL_TAILLES_TO_DELETE_ENTRY = + /** + * L'entrée dans le contexte pour conserver les mensurations obsolètes à supprimer lors de la sauvegarde. + */ + JAXXContextEntryDef<List<TargetLength>> ALL_TARGET_LENGTH_TO_DELETE_ENTRY = UIHelper.newListContextEntryDef("RejetThonUI-all-taille-to-delete"); public TargetDiscardCatchUIHandler(TargetDiscardCatchUI ui) { super(ui, DataContextType.SetSeine); } - protected static Collection<WeightCategory> getWeightCategoryUsed( - ContentTableModel<SetSeine, TargetCatch> model) { - List<WeightCategory> list = model.getColumnValues(1); - Collection<WeightCategory> set = new HashSet<WeightCategory>(list); - list.clear(); - return set; - } - - protected static Collection<ReasonForDiscard> getReasonForDiscardUsed( - ContentTableModel<SetSeine, TargetCatch> model, - WeightCategory weightCategory) { - - Collection<ReasonForDiscard> set = new HashSet<ReasonForDiscard>(); - if (weightCategory != null) { - for (int i = 0; i < model.getRowCount(); i++) { - TargetCatch c = model.getValueAt(i); - if (c != null && - weightCategory.equals(c.getWeightCategory()) && - c.getReasonForDiscard() != null) { - set.add(c.getReasonForDiscard()); - } - } - } - return set; - } - @Override public TargetDiscardCatchUI getUi() { return (TargetDiscardCatchUI) super.getUi(); @@ -119,29 +107,26 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, super.initUI(); - TargetDiscardCatchUI ui = getUi(); - - // lors de la modification d'une species (sur une entree non sauvee) - // - on recalcule la liste des categories pour cette species. + // lors de la modification d'une espèce (sur une entree non sauvee) + // - on recalcule la liste des categories pour cette espèce. // - on reinitialiser la categorie selectionnee - ui.getSpecies().addPropertyChangeListener( + getUi().getSpecies().addPropertyChangeListener( BeanComboBox.PROPERTY_SELECTED_ITEM, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - ContentTableModel<SetSeine, TargetCatch> model = - getTableModel(); + ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); TargetCatch bean = model.getRowBean(); - if (bean.getTopiaId() == null) { - // en mode creation , on doit recalculer la liste - // des categories + if (Entities.isNew(bean)) { + // en mode creation , on doit recalculer la liste des categories Species species = (Species) evt.getNewValue(); onEspeceChanged(bean, species); + } } } @@ -151,22 +136,22 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // - on recalcule la liste des raison rejets. // - on reinitialiser la raison rejet selectionnee - ui.getWeightCategory().addPropertyChangeListener( + getUi().getWeightCategory().addPropertyChangeListener( BeanComboBox.PROPERTY_SELECTED_ITEM, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - ContentTableModel<SetSeine, TargetCatch> model = - getTableModel(); + ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); TargetCatch bean = model.getRowBean(); - if (bean.getTopiaId() == null) { - // en mode creation , on doit recalculer la liste - // des raison rejet - WeightCategory weightCategory = - (WeightCategory) evt.getNewValue(); + + if (Entities.isNew(bean)) { + + // en mode creation , on doit recalculer la liste des raison rejet + WeightCategory weightCategory = (WeightCategory) evt.getNewValue(); onCategorieChanged(bean, weightCategory); + } } @@ -176,12 +161,44 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } @Override + protected void initTableUI(DefaultTableCellRenderer renderer) { + + JTable table = getUi().getTable(); + UIHelper.fixTableColumnWidth(table, 3, 75); + UIHelper.fixTableColumnWidth(table, 4, 20); + UIHelper.fixTableColumnWidth(table, 5, 50); + + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.targetDiscarded.table.speciesThon"), + n("observe.targetDiscarded.table.speciesThon.tip"), + n("observe.targetDiscarded.table.weightCategory"), + n("observe.targetDiscarded.table.weightCategory.tip"), + n("observe.targetDiscarded.table.reasonForDiscard"), + n("observe.targetDiscarded.table.reasonForDiscard.tip"), + n("observe.targetDiscarded.table.weight"), + n("observe.targetDiscarded.table.weight.tip"), + n("observe.targetDiscarded.table.broughtOnDeck"), + n("observe.targetDiscarded.table.broughtOnDeck.tip"), + n("observe.targetDiscarded.table.comment"), + n("observe.targetDiscarded.table.comment.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, WeightCategory.class)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newDecorateTableCellRenderer(renderer, ReasonForDiscard.class)); + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 4, UIHelper.newStringTableCellRenderer(renderer, 20, false)); + UIHelper.setTableColumnRenderer(table, 5, UIHelper.newStringTableCellRenderer(renderer, 10, true)); + + } + + @Override protected void loadEditBean(ContentMode mode) { List<WeightCategory> categorieList; List<ReasonForDiscard> reasonForDiscardList; - if (mode == ContentMode.UPDATE) { + if (ContentMode.UPDATE == mode) { // on charge le formulaire uniquement si en mode édition @@ -192,7 +209,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // filtre sur la liste d'espèce configuree ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineTargetCatchId(); - java.util.Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); + Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); categorieList = Species2.filterWeightCategoryBySpeciesIds(categorieList, speciesIds); @@ -214,203 +231,128 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, categorieList = new ArrayList<WeightCategory>(); reasonForDiscardList = new ArrayList<ReasonForDiscard>(); - } - TargetDiscardCatchUI ui = getUi(); + } ALL_CATEGORIES_ENTRY.setContextValue(ui, categorieList); ALL_RAISONS_REJET_ENTRY.setContextValue(ui, reasonForDiscardList); String setId = getDataContext().getSelectedSetId(); - SetSeine setSeine = getService(NonTargetCatchService.class).loadForEdit(setId); + TargetCatchService service = getService(TargetCatchService.class); + SetSeine setSeine = service.loadForEditDiscarded(setId); copy(SetSeine.class, BinderService.EDIT_DISCARD_TARGET_CATCH, setSeine, getBean()); } -// @Override -// protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { -// return dataContext.getSelectedSetId(); -// } - -// @Override -// protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { -// Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); -// Collection<TargetCatch> data = new ArrayList<TargetCatch>(); -// if (CollectionUtils.isNotEmpty(childs)) { -// TopiaDAO<TargetCatch> dao = -// getDataSource().getDAO(tx, getTableEditBean()); -// TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); -// DecoratorService decoratorService = getDecoratorService(); -// for (TargetCatch c : childs) { -// if (!c.isDiscarded()) { -// // ce n'est pas un rejet, on ne le retient pas dans cette -// // liste -// if (log.isDebugEnabled()) { -// log.debug("targetCatch " + c.getSpecies().getLabel2() + " non retenu."); -// } -// continue; -// } -// try { -// TargetCatch c2 = getModel().newTableEditBean(); -// TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); -// WeightCategory weightCategory = safeC.getWeightCategory(); -// if (weightCategory != null) { -// Species species = weightCategory.getSpecies(); -// decoratorService.decorate(species); -// } -// childLoador.load(safeC, c2, true); -// data.add(c2); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// } -// } -// return data; -// } - -// @Override -// protected boolean doSave(SetSeine bean, -// DataService dataService, -// DataSource dataSource, -// TopiaEntityBinder<SetSeine> binder) throws Exception { -// try { -// return super.doSave(bean, dataService, dataSource, binder); -// } finally { -// -// // toujours supprimer la référence du context, quoiqu'il arrive -// ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); -// } -// } - -// @Override -// protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { -// -// // on recupere les speciess acceptables pour des echantillonnages -// // i.e une species d'un targetDiscarded montee sur le pont -// -// java.util.Set<Species> speciessUsed = new HashSet<Species>(); -// for (TargetCatch c : objets) { -// if (c.getBroughtOnDeck() != null && c.getBroughtOnDeck()) { -// speciessUsed.add(c.getSpecies()); -// } -// } -// -// // il faut supprimer les echantillon thons sur des speciess qui ne -// // sont plus sur un rejet -// -// List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); -// java.util.Set<Species> speciessToDelete = new HashSet<Species>(); -// -// TargetSampleService service = getService(TargetSampleService.class); -// service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), -// speciessUsed, -// speciessToDelete, -// tailleToDelete, -// true); -// -// if (!tailleToDelete.isEmpty()) { -// -// // il existe des echantillon thon a supprimer on demande une -// // confirmation -// StringBuilder sb = new StringBuilder(512); -// StringBuilder sb2 = new StringBuilder(512); -// Decorator<Species> decorator = -// getDecoratorService().getDecoratorByType(Species.class); -// Decorator<TargetLength> decorator2 = -// getDecoratorService().getDecoratorByType(TargetLength.class); -// -// for (Species e : speciessToDelete) { -// sb.append(" - ").append(decorator.toString(e)).append('\n'); -// } -// for (TargetLength t : tailleToDelete) { -// sb2.append(" - ").append(decorator2.toString(t)).append('\n'); -// } -// int reponse = UIHelper.askUser( -// t("observe.title.need.confirm"), -// t("observe.targetDiscarded.message.table.will.delete.targetLength", sb.toString(), sb2.toString()), -// JOptionPane.ERROR_MESSAGE, -// new Object[]{ -// t("observe.choice.continue"), -// t("observe.choice.cancel")}, -// 0); -// if (log.isDebugEnabled()) { -// log.debug("response : " + reponse); -// } -// boolean canContinue = false; -// switch (reponse) { -// case 0: -// // wil reset ui -// canContinue = true; -// break; -// } -// -// if (!canContinue) { -// -// // l'utilisateur a choisi de ne pas continuer -// return false; -// } -// -// // on conserve les tailles a supprimer -// ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); -// } -// -// // mise a jour de la propriete targetDiscarded -// bean.setTargetDiscarded(!objets.isEmpty()); -// -// for (TargetCatch discarded : objets) { -// -// // FIXME : on devrait pas a avoir a repositionner la propriete discarded -// discarded.setDiscarded(true); -// -// // on attache la set -// discarded.setSetSeine(bean); -// } -// -// return true; -// } - -// @Override -// protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { -// -// if (oldChilds != null && !oldChilds.isEmpty()) { -// -// // on reinjecte les discarded thon precedemment saisies dans la set -// // et qui ne sont pas des rejets -// -// for (TargetCatch targetCatch : oldChilds) { -// if (!targetCatch.isDiscarded()) { -// bean.addTargetCatch(targetCatch); -// } -// } -// } -// -// List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); -// -// if (tailleToDelete != null && !tailleToDelete.isEmpty()) { -// -// // on a demande la suppression de taille obsoletes -// -// if (log.isInfoEnabled()) { -// log.info("Will remove " + tailleToDelete.size() + -// " obsolete targetLength(s)."); -// } -// -// TargetSample echantillon = bean.getTargetSample(true); -// -// // on supprime les echantillons obsoletes -// echantillon.getTargetLength().removeAll(tailleToDelete); -// } -// } + @Override + protected boolean prepareSave(SetSeine editBean, List<TargetCatch> objets) { + + // on recupere les espèces acceptables pour des echantillonnages + // i.e une espèces d'un targetDiscarded montee sur le pont + + Set<String> speciesIdsUsed = new HashSet<String>(); + for (TargetCatch targetCatch : objets) { + speciesIdsUsed.add(targetCatch.getSpecies().getTopiaId()); + } + + // il faut supprimer les echantillon thons sur des espèces qui ne sont plus sur un rejet + + TargetSampleService service = getService(TargetSampleService.class); + List<TargetLength> targetLengthsToDelete = service.getObsoleteTargetLengths(editBean.getTopiaId(), speciesIdsUsed, true); + + if (!targetLengthsToDelete.isEmpty()) { + + // il existe des echantillon thon a supprimer on demande une confirmation + + Set<Species> speciessToDelete = new HashSet<Species>(); + for (TargetLength targetLength : targetLengthsToDelete) { + speciessToDelete.add(targetLength.getSpecies()); + } + + StringBuilder sb = new StringBuilder(512); + StringBuilder sb2 = new StringBuilder(512); + Decorator<Species> speciesDecorator = getDecoratorService().getDecoratorByType(Species.class); + Decorator<TargetLength> targetLengthDecorator = getDecoratorService().getDecoratorByType(TargetLength.class); + + for (Species e : speciessToDelete) { + sb.append(" - ").append(speciesDecorator.toString(e)).append('\n'); + } + for (TargetLength t : targetLengthsToDelete) { + sb2.append(" - ").append(targetLengthDecorator.toString(t)).append('\n'); + } + int reponse = UIHelper.askUser( + t("observe.title.need.confirm"), + t("observe.targetDiscarded.message.table.will.delete.targetLength", sb.toString(), sb2.toString()), + JOptionPane.ERROR_MESSAGE, + new Object[]{t("observe.choice.continue"), t("observe.choice.cancel")}, + 0); + if (log.isDebugEnabled()) { + log.debug("response : " + reponse); + } + boolean canContinue = false; + switch (reponse) { + case 0: + // wil reset ui + canContinue = true; + break; + } + + if (!canContinue) { + + // l'utilisateur a choisi de ne pas continuer + return false; + + } + + // on conserve les tailles a supprimer + ALL_TARGET_LENGTH_TO_DELETE_ENTRY.setContextValue(getUi(), targetLengthsToDelete); + + } + + // mise a jour de la propriete targetDiscarded + editBean.setTargetDiscarded(!objets.isEmpty()); + + for (TargetCatch targetCatch : objets) { + + // FIXME : on devrait pas a avoir a repositionner la propriete discarded + targetCatch.setDiscarded(true); + + // on attache la set + targetCatch.setSetSeine(editBean); + + } + + return true; + + } + + @Override + protected void doPersist(SetSeine editBean) { + + List<TargetLength> targetLengthsToDelete = ALL_TARGET_LENGTH_TO_DELETE_ENTRY.getContextValue(ui); + + try { + + TargetCatchService service = getService(TargetCatchService.class); + service.saveForDiscarded(editBean, targetLengthsToDelete); + + } finally { + + ALL_TARGET_LENGTH_TO_DELETE_ENTRY.removeContextValue(ui); + + } + + } @Override protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { + TargetDiscardCatchUI ui = getUi(); WeightCategory beanWeightCategory = bean.getWeightCategory(); - Species beanEspece = beanWeightCategory == null ? null : - beanWeightCategory.getSpecies(); + Species beanEspece = beanWeightCategory == null ? null : beanWeightCategory.getSpecies(); ReasonForDiscard beanReasonForDiscard = bean.getReasonForDiscard(); if (log.isDebugEnabled()) { log.debug("selected categoriePoid " + beanWeightCategory); @@ -418,8 +360,11 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, log.debug("selected reasonForDiscard " + beanReasonForDiscard); } + BeanComboBox<Species> speciesComboBox = ui.getSpecies(); + JComponent requestFocus; if (create) { + ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); if (model.isCreate()) { // par défaut, on considère que l'espèce a été monté sur le pont @@ -428,71 +373,42 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } // on recalcule la liste des speciess disponibles - List<Species> availableEspeces = buildEspeceList( - beanEspece, beanWeightCategory); - ui.getSpecies().setData(availableEspeces); + List<Species> availableEspeces = buildEspeceList(beanEspece, beanWeightCategory); + speciesComboBox.setData(availableEspeces); - // on reinitilise toujours l'species (pour reinitialiser la liste - // des categories) - ui.getSpecies().setSelectedItem(null); + // on reinitilise toujours la liste des espèces (pour reinitialiser la liste des categories) + speciesComboBox.setSelectedItem(null); if (!model.isCreate()) { // on repositionne l'species (cela reconstruira la liste // des categories) - ui.getSpecies().setSelectedItem(beanEspece); + speciesComboBox.setSelectedItem(beanEspece); // on repositionne la categorie ui.getWeightCategory().setSelectedItem(beanWeightCategory); ui.getReasonForDiscard().setSelectedItem(beanReasonForDiscard); } - requestFocus = ui.getSpecies(); + requestFocus = speciesComboBox; + } else { + // en mode mise a jour, on restreint la liste des categories // au singleton de sa valeur correspondante dans le bean // puisque dans ce mode, pas possibilite de modifier de cette // valeur (clef metier) - ui.getSpecies().setSelectedItem(beanEspece); - ui.getWeightCategory().setData(Arrays.asList(beanWeightCategory)); + speciesComboBox.setSelectedItem(beanEspece); + ui.getWeightCategory().setData(Collections.singletonList(beanWeightCategory)); ui.getWeightCategory().setSelectedItem(beanWeightCategory); - ui.getReasonForDiscard().setData(Arrays.asList(beanReasonForDiscard)); + ui.getReasonForDiscard().setData(Collections.singletonList(beanReasonForDiscard)); ui.getReasonForDiscard().setSelectedItem(beanReasonForDiscard); requestFocus = ui.getCatchWeight(); + } requestFocus.requestFocus(); } - @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - JTable table = getUi().getTable(); - UIHelper.fixTableColumnWidth(table, 3, 75); - UIHelper.fixTableColumnWidth(table, 4, 20); - UIHelper.fixTableColumnWidth(table, 5, 50); - - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.targetDiscarded.table.speciesThon"), - n("observe.targetDiscarded.table.speciesThon.tip"), - n("observe.targetDiscarded.table.weightCategory"), - n("observe.targetDiscarded.table.weightCategory.tip"), - n("observe.targetDiscarded.table.reasonForDiscard"), - n("observe.targetDiscarded.table.reasonForDiscard.tip"), - n("observe.targetDiscarded.table.weight"), - n("observe.targetDiscarded.table.weight.tip"), - n("observe.targetDiscarded.table.broughtOnDeck"), - n("observe.targetDiscarded.table.broughtOnDeck.tip"), - n("observe.targetDiscarded.table.comment"), - n("observe.targetDiscarded.table.comment.tip")); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, WeightCategory.class)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newDecorateTableCellRenderer(renderer, ReasonForDiscard.class)); - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 4, UIHelper.newStringTableCellRenderer(renderer, 20, false)); - UIHelper.setTableColumnRenderer(table, 5, UIHelper.newStringTableCellRenderer(renderer, 10, true)); - } - protected void onEspeceChanged(TargetCatch bean, Species species) { WeightCategory weightCategory = null; @@ -511,15 +427,13 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // un species est selectionne, on met a jour la liste des categories // disponibles pour cet species - List<WeightCategory> availableCategories = buildWeightCategoryList( - species); + List<WeightCategory> availableCategories = buildWeightCategoryList(species); data = availableCategories; weightCategory = bean.getWeightCategory(); - if (weightCategory != null && - !availableCategories.contains(weightCategory)) { + if (weightCategory != null && !availableCategories.contains(weightCategory)) { weightCategory = null; } } @@ -530,9 +444,11 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // on selectionne la categorie retenue combo.setSelectedItem(weightCategory); + } protected void onCategorieChanged(TargetCatch bean, WeightCategory weightCategory) { + TargetDiscardCatchUI ui = getUi(); ReasonForDiscard reasonForDiscard = null; @@ -574,6 +490,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // on selectionne la raison rejet retenue combo.setSelectedItem(reasonForDiscard); + } protected List<Species> buildEspeceList(Species species, WeightCategory weightCategory) { @@ -594,7 +511,9 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, List<Species> result = new ArrayList<Species>(usedEspeces); weightCategoryList.clear(); usedEspeces.clear(); + return result; + } protected List<WeightCategory> buildWeightCategoryList(Species species) { @@ -615,9 +534,9 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, removeFullyUsedCategories(weightCategoryList); return weightCategoryList; + } - @SuppressWarnings("unchecked") protected List<ReasonForDiscard> buildReasonFordiscardList(WeightCategory weightCategory) { ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); @@ -634,6 +553,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } return reasonForDiscardList; + } protected List<WeightCategory> getAllCategories(JAXXContext context) { @@ -642,22 +562,46 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, return list; } - protected void removeFullyUsedCategories( - List<WeightCategory> weightCategoryAvaillable) { - - ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); + protected void removeFullyUsedCategories(List<WeightCategory> weightCategoryAvaillable) { - int nbReasonForDiscard = - ALL_RAISONS_REJET_ENTRY.getContextValue(getUi()).size(); + int nbReasonForDiscard = ALL_RAISONS_REJET_ENTRY.getContextValue(getUi()).size(); - // on filtre toutes les weightCategory qui ont deja references toutes - // les raisons rejets - for (WeightCategory c : getWeightCategoryUsed(model)) { - Collection<ReasonForDiscard> raisonUsed = getReasonForDiscardUsed(model, c); + // on filtre toutes les weightCategory qui ont deja references toutes les raisons rejets + for (WeightCategory c : getWeightCategoryUsed()) { + Collection<ReasonForDiscard> raisonUsed = getReasonForDiscardUsed(c); if (raisonUsed.size() == nbReasonForDiscard) { // toutes les raison de rejet epuisé pour cette categorie weightCategoryAvaillable.remove(c); } } + + } + + protected Collection<WeightCategory> getWeightCategoryUsed() { + + ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); + + List<WeightCategory> list = model.getColumnValues(1); + Collection<WeightCategory> set = new HashSet<WeightCategory>(list); + list.clear(); + return set; + + } + + protected Collection<ReasonForDiscard> getReasonForDiscardUsed(WeightCategory weightCategory) { + + ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); + + Collection<ReasonForDiscard> set = new HashSet<ReasonForDiscard>(); + if (weightCategory != null) { + for (int i = 0; i < model.getRowCount(); i++) { + TargetCatch c = model.getValueAt(i); + if (c != null && weightCategory.equals(c.getWeightCategory()) && c.getReasonForDiscard() != null) { + set.add(c.getReasonForDiscard()); + } + } + } + return set; + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index bcfc0d7..5a90ee1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -148,7 +148,7 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T String setId = getDataContext().getSelectedSetId(); // on ne charge les speciess uniquement si on est en mode édition - List<Species> speciesList = getService(TargetSampleService.class).getAvailableEspeceForTargetSample(setId, discarded); + List<Species> speciesList = getService(TargetSampleService.class).getAvailableSpeciesForTargetSample(setId, discarded); getUi().getSpecies().setData(speciesList); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java index 4b0fb0c..570f852 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java @@ -44,7 +44,7 @@ public class SetLonglineNode extends EntityNodeSupport<SetLongline> { @Override protected SetLongline getEntity(ObserveServiceFactory services) { SetLonglineService service = services.getService(SetLonglineService.class); - return service.loadSet(id); + return service.loadForDisplay(id); } } diff --git a/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java b/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java index 191eab6..0710dd2 100644 --- a/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java +++ b/observe-validation/src/main/java/fr/ird/observe/validation/field/VesselActivityFieldValidator.java @@ -25,15 +25,15 @@ package fr.ird.observe.validation.field; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.validator.ValidationException; import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; +import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeineImpl; -import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; +import fr.ird.observe.entities.seine.Routes; +import fr.ird.observe.entities.seine.TripSeine; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.util.ArrayList; import java.util.List; /** @@ -144,29 +144,28 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { log.debug("route : " + route); } - String activityCode = activitySeine.getVesselActivitySeine().getCode(); + String vesselActivityId = activitySeine.getVesselActivitySeine().getTopiaId(); int nbActivitys = route.sizeActivitySeine(); - if (code.equals("-16") && !activityCode.equals(ActivitySeineImpl.ACTIVITY_FIN_DE_VEILLE)) { + if (code.equals("-16") && !activitySeine.isActivityFinDeVeille()) { valid = validate_16(activitySeine, maree, route, nbActivitys, false); } switch (Integer.valueOf(code)) { case 6: - if (activityCode.equals(ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE)) { + if (vesselActivityId.equals(ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE_ID)) { valid = validate_6(activitySeine, maree, route, nbActivitys); } break; case 7: - if (activityCode.equals(ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE)) { + if (vesselActivityId.equals(ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE_ID)) { valid = validate_7(activitySeine, maree, route, nbActivitys); } break; case 16: - if (activityCode.equals(ActivitySeineImpl.ACTIVITY_FIN_DE_VEILLE)) { - valid = validate_16(activitySeine, maree, route, - nbActivitys, true); + if (activitySeine.isActivityFinDeVeille()) { + valid = validate_16(activitySeine, maree, route, nbActivitys, true); } break; } @@ -223,8 +222,8 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { //FIXME: sinon on verifier que l'activity qu'on veut créer n'est pas //FIXME: dans un intervalle (debut-fin) List<ActivitySeine> activitySeines = route.getActivitySeine(); - Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); - Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); + Integer[] detectDebutSet = Routes.detectActivities(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE_ID); + Integer[] detectFinSet = Routes.detectActivities(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE_ID); int nbDebutReal = 0; int lastDebutReal = 0; for (Integer i : detectDebutSet) { @@ -273,8 +272,8 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { return false; } List<ActivitySeine> activitySeines = route.getActivitySeine(); - Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); - Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); + Integer[] detectDebutSet = Routes.detectActivities(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE_ID); + Integer[] detectFinSet = Routes.detectActivities(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE_ID); Integer lastFinSet = null; if (detectFinSet.length > 0) { lastFinSet = detectFinSet[detectFinSet.length - 1]; @@ -359,7 +358,7 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { // on est sur une activity de fin de veille List<ActivitySeine> activitySeines = route.getActivitySeine(); // une seule activity de fin de veille par route - Integer[] detectActivity = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_VEILLE); + Integer[] detectActivity = Routes.detectActivities(route, ActivitySeineImpl.ACTIVITY_FIN_DE_VEILLE_ID); if (activitySeine.getTopiaId() == null && detectActivity.length > 0) { log.info("il existe deja une activity de fin de veille!"); @@ -380,8 +379,8 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { // } // il ne peut pas rester une activity de debut de peche sans fin // de set (sauf si non coup de senne ?) - Integer[] detectDebutSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE); - Integer[] detectFinSet = detectActivity(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE); + Integer[] detectDebutSet = Routes.detectActivities(route, ActivitySeineImpl.ACTIVITY_DEBUT_DE_PECHE_ID); + Integer[] detectFinSet = Routes.detectActivities(route, ActivitySeineImpl.ACTIVITY_FIN_DE_PECHE_ID); int nbDebutReal = 0; for (Integer i : detectDebutSet) { ActivitySeine bActivitySeine = activitySeines.get(i); @@ -423,23 +422,4 @@ public class VesselActivityFieldValidator extends FieldValidatorSupport { return true; } - /** - * Recupere les positions des activitys d'un certain type - * - * @param route la route à inspecter - * @param code le code du type d'activité à rechercher - * @return les positions des activitys d'un certain type donné - */ - protected Integer[] detectActivity(Route route, String code) { - List<Integer> list = new ArrayList<Integer>(); - int index = 0; - for (ActivitySeine a : route.getActivitySeine()) { - String c = a.getVesselActivitySeine().getCode(); - if (code.equals(c)) { - list.add(index); - } - index++; - } - return list.toArray(new Integer[list.size()]); - } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 89032218320002c3eb42cb5d29f91ff3ff28ab64 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 15:50:00 2015 +0200 revue des écrans de type list (refs #7017) --- .../ui/content/list/ContentListUIHandler.java | 84 ++++++++++++---------- .../impl/longline/ActivityLonglinesUIHandler.java | 18 ++--- .../list/impl/longline/TripLonglinesUIHandler.java | 24 ++----- .../list/impl/seine/ActivitySeinesUIHandler.java | 23 +++--- .../content/list/impl/seine/RoutesUIHandler.java | 19 +++-- .../list/impl/seine/TripSeinesUIHandler.java | 23 ++---- .../ui/content/open/ContentOpenableUIHandler.java | 2 +- 7 files changed, 83 insertions(+), 110 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java index c086ec2..2a4e811 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/ContentListUIHandler.java @@ -54,21 +54,24 @@ import static org.nuiton.i18n.I18n.t; public abstract class ContentListUIHandler<E extends TopiaEntity, C extends TopiaEntity> extends ContentUIHandler<E> { /** Logger */ - static private Log log = LogFactory.getLog(ContentListUIHandler.class); + public static final Log log = LogFactory.getLog(ContentListUIHandler.class); - public ContentListUIHandler(ContentListUI<E, C> ui, - DataContextType parentType, - DataContextType type) { + public ContentListUIHandler(ContentListUI<E, C> ui, DataContextType parentType, DataContextType type) { super(ui, parentType, type); } /** - * Load data (the main bean + the data list) in model. + * Méthode invoquée à chaque ouverture de l'écran. * - * @param selectedId id of the entity to load + * Il faut dans cette méthode charger le bean d'édition et retourner la liste gérée par l'écran. + * + * La méthode est invoquée par {@link #openUI()}. + * + * @param selectedId l'id de l'entité de l'écran. + * @return la liste à gérer par l'écran * @since 4.0 */ - protected abstract void loadDataInModel(String selectedId); + protected abstract List<C> onOpenUI(String selectedId); @Override protected boolean computeCanWrite(DataSource source) { @@ -85,19 +88,20 @@ public abstract class ContentListUIHandler<E extends TopiaEntity, C extends Topi return (ContentListUIModel<E, C>) super.getModel(); } + @SuppressWarnings("unchecked") @Override - public void initUI() throws Exception { + public final void initUI() throws Exception { + super.initUI(); - // on installe un renderer sur la liste pour afficher les couleurs + - // icones comme dans l'arbre + // on installe un renderer sur la liste pour afficher les couleurs + icones comme dans l'arbre ListCellRenderer renderer = getUi().getList().getCellRenderer(); ObserveTreeHelper treeHelper = getTreeHelper(getUi()); - ListCellRenderer renderer2 = - new EntityListCellRenderer(renderer, treeHelper); + ListCellRenderer renderer2 = new EntityListCellRenderer(renderer, treeHelper); getUi().getList().setCellRenderer(renderer2); + } @Override @@ -106,8 +110,7 @@ public abstract class ContentListUIHandler<E extends TopiaEntity, C extends Topi super.openUI(); // init renderer - EntityListCellRenderer renderer = (EntityListCellRenderer) - getUi().getList().getCellRenderer(); + EntityListCellRenderer renderer = (EntityListCellRenderer) getUi().getList().getCellRenderer(); renderer.init(); ContentListUIModel<E, C> model = getModel(); @@ -125,13 +128,18 @@ public abstract class ContentListUIHandler<E extends TopiaEntity, C extends Topi } model.setMode(mode); - boolean canReopen = mode == ContentMode.CREATE; + boolean canReopen = ContentMode.CREATE == mode; if (log.isInfoEnabled()) { log.info(prefix + "canReopen = " + canReopen); } model.setCanReopen(canReopen); - loadDataInModel(selectedId); + List<C> childs = onOpenUI(selectedId); + model.setData(childs); + + if (log.isDebugEnabled()) { + log.debug("Will use " + childs.size() + " child(s)."); + } if (!model.isEmpty()) { @@ -140,8 +148,6 @@ public abstract class ContentListUIHandler<E extends TopiaEntity, C extends Topi } - // finalize openUI with specified code - finalizeOpenUI(); } public void addChild() { @@ -154,37 +160,37 @@ public abstract class ContentListUIHandler<E extends TopiaEntity, C extends Topi * @param event the mouse event fired */ public void onDataSelected(MouseEvent event) { + C selectedData = getUi().getSelectedData(); if (event.getClickCount() > 1) { + gotoChild(selectedData); - return; - } - ObserveNode node = null; - if (selectedData != null) { - - // obtain the node corresponding to the selected data - String id = selectedData.getTopiaId(); - ObserveTreeHelper helper = getTreeHelper(getUi()); - ObserveNode selectedNode = helper.getSelectedNode(); - node = helper.findNode(selectedNode, id); + + } else { + + ObserveNode node = null; + if (selectedData != null) { + + // obtain the node corresponding to the selected data + String id = selectedData.getTopiaId(); + ObserveTreeHelper helper = getTreeHelper(getUi()); + ObserveNode selectedNode = helper.getSelectedNode(); + node = helper.findNode(selectedNode, id); + } + + // attach the node to action + JButton button = getUi().getGotoSelectedChild(); + button.putClientProperty(SelectNodeUIAction.NODE, node); + } - // attach the node to action - JButton button = getUi().getGotoSelectedChild(); - button.putClientProperty(SelectNodeUIAction.NODE, node); } - public <E> List<E> updateList(BeanListHeader<E> list, List<E> data) { + public <EE> List<EE> updateList(BeanListHeader<EE> list, List<EE> data) { + String message = t(getUi().getEmptyListMessage()); return updateList(list, data, message); - } - /** - * Pour effectuer un traitement supplémantaire à la fin de la méthode - * {@link #openUI()}. - */ - protected void finalizeOpenUI() { - // rien par default } /** diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java index 8e46976..060b74d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/ActivityLonglinesUIHandler.java @@ -31,8 +31,6 @@ import fr.ird.observe.services.data.longline.ActivityLonglineService; import fr.ird.observe.services.data.longline.TripLonglineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import java.util.List; @@ -46,9 +44,6 @@ import static org.nuiton.i18n.I18n.n; */ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLongline, ActivityLongline> { - /** Logger */ - static private Log log = LogFactory.getLog(ActivityLonglinesUIHandler.class); - public ActivityLonglinesUIHandler(ActivityLonglinesUI ui) { super(ui, DataContextType.TripLongline, DataContextType.ActivityLongline); } @@ -63,6 +58,7 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin // pas de marée ouverte, donc on ne peut pas ouvrir une activité addInfoMessage(n("observe.tripLongline.message.no.active.found")); return ContentMode.READ; + } // @@ -83,11 +79,13 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin // il existe une activite d'ouverte dans la maree courante addInfoMessage(n("observe.activityLongline.message.active.found")); return ContentMode.UPDATE; + } // pas d'activité ouverte, on peut en ouvrir une addInfoMessage(n("observe.activityLongline.message.no.active.found")); return ContentMode.CREATE; + } // @@ -98,10 +96,12 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin // il existe une activité ouverte dans la marée ouverte addInfoMessage(n("observe.activityLongline.message.active.found.for.other.trip")); + } else { // il n'existe pas d'activité ouverte dans la marée ouverte addInfoMessage(n("observe.activityLongline.message.no.active.found.for.other.trip")); + } return ContentMode.READ; @@ -109,7 +109,7 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin } @Override - protected void loadDataInModel(String selectedId) { + protected List<ActivityLongline> onOpenUI(String selectedId) { TripLonglineService tripService = getService(TripLonglineService.class); TripLongline loaded = tripService.getTripLonglineStub(selectedId); @@ -120,13 +120,9 @@ public class ActivityLonglinesUIHandler extends ContentListUIHandler<TripLonglin ActivityLonglineService routeService = getService(ActivityLonglineService.class); List<ActivityLongline> activityLonglines = routeService.getActivityLonglineStubByTrip(selectedId); - if (log.isDebugEnabled()) { - log.debug("Will use " + activityLonglines.size() + " activities."); - } - bean.setActivityLongline(activityLonglines); - getModel().setData(activityLonglines); + return activityLonglines; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java index a431838..877368e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/longline/TripLonglinesUIHandler.java @@ -31,8 +31,6 @@ import fr.ird.observe.services.data.longline.TripLonglineService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import java.util.List; @@ -46,9 +44,6 @@ import static org.nuiton.i18n.I18n.n; */ public class TripLonglinesUIHandler extends ContentListUIHandler<Program, TripLongline> { - /** Logger */ - static private final Log log = LogFactory.getLog(TripLonglinesUIHandler.class); - public TripLonglinesUIHandler(TripLonglinesUI ui) { super(ui, DataContextType.Program, DataContextType.TripLongline); } @@ -86,28 +81,21 @@ public class TripLonglinesUIHandler extends ContentListUIHandler<Program, TripLo } @Override - protected void finalizeOpenUI() { - String title = getDecoratorService().decorate(getBean()); - getUi().setContentTitle(title); - } - - @Override - protected void loadDataInModel(String selectedId) { + protected List<TripLongline> onOpenUI(String selectedId) { ReferentialService service = getService(ReferentialService.class); Program loaded = service.loadAndDecorate(Program.class, selectedId); Program bean = getBean(); - copy(Program.class, BinderService.DISPLAY,loaded, bean); + copy(Program.class, BinderService.DISPLAY, loaded, bean); + + String title = getDecoratorService().decorate(getBean()); + getUi().setContentTitle(title); TripLonglineService tripService = getService(TripLonglineService.class); List<TripLongline> tripLonglines = tripService.getTripLonglineStubByProgram(bean.getTopiaId()); - if (log.isDebugEnabled()) { - log.debug("Will use " + tripLonglines.size() + " trips."); - } - - getModel().setData(tripLonglines); + return tripLonglines; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java index 5b80eeb..d9661a8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/ActivitySeinesUIHandler.java @@ -30,8 +30,6 @@ import fr.ird.observe.services.data.seine.ActivitySeineService; import fr.ird.observe.services.data.seine.RouteService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import java.util.List; @@ -43,9 +41,6 @@ import static org.nuiton.i18n.I18n.n; */ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, ActivitySeine> { - /** Logger */ - static private Log log = LogFactory.getLog(ActivitySeinesUIHandler.class); - public ActivitySeinesUIHandler(ActivitySeinesUI ui) { super(ui, DataContextType.Route, DataContextType.ActivitySeine); } @@ -60,6 +55,7 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit // pas de route ouverte, donc on ne peut pas ouvrir une activité addInfoMessage(n("observe.route.message.no.active.found")); return ContentMode.READ; + } // @@ -68,7 +64,6 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit boolean openActivity = dataContext.isOpenActivity(); - if (dataContext.isSelectedOpen(Route.class)) { // @@ -81,11 +76,13 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit // il existe une activité ouverte dans la route courante addInfoMessage(n("observe.activitySeine.message.active.found")); return ContentMode.UPDATE; + } // pas d'activité ouverte, on peut en ouvrir une addInfoMessage(n("observe.activitySeine.message.no.active.found")); return ContentMode.CREATE; + } // @@ -96,10 +93,12 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit // il existe une activité ouverte dans la route ouverte addInfoMessage(n("observe.activitySeine.message.active.found.for.other.route")); + } else { // il n'existe pas d'activité ouverte dans la route ouverte addInfoMessage(n("observe.activitySeine.message.no.active.found.for.other.route")); + } return ContentMode.READ; @@ -107,24 +106,20 @@ public class ActivitySeinesUIHandler extends ContentListUIHandler<Route, Activit } @Override - protected void loadDataInModel(String selectedId) { + protected List<ActivitySeine> onOpenUI(String routeId) { RouteService routeService = getService(RouteService.class); - Route loaded = routeService.getRouteStub(selectedId); + Route loaded = routeService.getRouteStub(routeId); Route bean = getBean(); copy(Route.class, BinderService.DISPLAY, loaded, bean); ActivitySeineService activityService = getService(ActivitySeineService.class); - List<ActivitySeine> activitySeines = activityService.getActivitySeineStubByRoute(selectedId); - - if (log.isDebugEnabled()) { - log.debug("Will use " + activitySeines.size() + " activities."); - } + List<ActivitySeine> activitySeines = activityService.getActivitySeineStubByRoute(routeId); bean.setActivitySeine(activitySeines); - getModel().setData(activitySeines); + return activitySeines; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java index f24e760..285ea24 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/RoutesUIHandler.java @@ -30,8 +30,6 @@ import fr.ird.observe.services.data.seine.RouteService; import fr.ird.observe.services.data.seine.TripSeineService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import java.util.List; @@ -43,9 +41,6 @@ import static org.nuiton.i18n.I18n.n; */ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { - /** Logger */ - static private Log log = LogFactory.getLog(RoutesUIHandler.class); - public RoutesUIHandler(RoutesUI ui) { super(ui, DataContextType.TripSeine, DataContextType.Route); } @@ -62,6 +57,7 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { // pas de marée d'ouverte, donc on ne peut pas ouvrir une route addInfoMessage(n("observe.tripSeine.message.no.active.found")); return ContentMode.READ; + } // @@ -79,11 +75,13 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { // il existe une route ouverte dans la marée courante addInfoMessage(n("observe.route.message.active.found")); return ContentMode.UPDATE; + } // pas de route ouverte, on peut en ouvrir une addInfoMessage(n("observe.route.message.no.active.found")); return ContentMode.CREATE; + } // @@ -94,17 +92,20 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { //il existe une route existe dans la maree ouverte addInfoMessage(n("observe.route.message.active.found.for.other.trip")); + } else { // pas de route ouverte dans la maree ouverte addInfoMessage(n("observe.route.message.no.active.found.for.other.trip")); + } return ContentMode.READ; + } @Override - protected void loadDataInModel(String selectedId) { + protected List<Route> onOpenUI(String selectedId) { TripSeineService tripService = getService(TripSeineService.class); TripSeine loaded = tripService.getTripSeineStub(selectedId); @@ -114,13 +115,9 @@ public class RoutesUIHandler extends ContentListUIHandler<TripSeine, Route> { RouteService routeService = getService(RouteService.class); List<Route> routes = routeService.getRouteStubByTrip(selectedId); - if (log.isDebugEnabled()) { - log.debug("Will use " + routes.size() + " routes."); - } - bean.setRoute(routes); - getModel().setData(routes); + return routes; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java index dfece7f..7a4558e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/list/impl/seine/TripSeinesUIHandler.java @@ -30,8 +30,6 @@ import fr.ird.observe.services.data.seine.TripSeineService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.list.ContentListUIHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import java.util.List; @@ -43,9 +41,6 @@ import static org.nuiton.i18n.I18n.n; */ public class TripSeinesUIHandler extends ContentListUIHandler<Program, TripSeine> { - /** Logger */ - static private final Log log = LogFactory.getLog(TripSeinesUIHandler.class); - public TripSeinesUIHandler(TripSeinesUI ui) { super(ui, DataContextType.Program, DataContextType.TripSeine); } @@ -61,6 +56,7 @@ public class TripSeinesUIHandler extends ContentListUIHandler<Program, TripSeine // on peut reouvrir une maree addInfoMessage(n("observe.tripSeine.message.no.active.found")); return ContentMode.CREATE; + } // @@ -72,6 +68,7 @@ public class TripSeinesUIHandler extends ContentListUIHandler<Program, TripSeine // le program courant a une maree ouverte addInfoMessage(n("observe.tripSeine.message.active.found")); return ContentMode.UPDATE; + } // @@ -80,30 +77,24 @@ public class TripSeinesUIHandler extends ContentListUIHandler<Program, TripSeine addInfoMessage(n("observe.tripSeine.message.active.found.for.other.program")); return ContentMode.READ; - } - @Override - protected void finalizeOpenUI() { - String title = getDecoratorService().decorate(getBean()); - getUi().setContentTitle(title); } @Override - protected void loadDataInModel(String selectedId) { + protected List<TripSeine> onOpenUI(String selectedId) { ReferentialService service = getService(ReferentialService.class); Program loaded = service.loadAndDecorate(Program.class, selectedId); Program bean = getBean(); copy(Program.class, BinderService.DISPLAY, loaded, bean); + String title = getDecoratorService().decorate(getBean()); + getUi().setContentTitle(title); + TripSeineService tripService = getService(TripSeineService.class); List<TripSeine> tripSeines = tripService.getTripSeineStubByProgram(bean.getTopiaId()); - if (log.isDebugEnabled()) { - log.debug("Will use " + tripSeines.size() + " trips."); - } - - getModel().setData(tripSeines); + return tripSeines; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java index 7aafb12..db307a5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java @@ -100,7 +100,7 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE } @Override - public void openUI() throws Exception { + public final void openUI() throws Exception { super.openUI(); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 6711f3ff5f05e50e3aeb0225719205f002e9fb6f Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 17:15:18 2015 +0200 debut de revue des ecrans de type tableau (refs #7017) --- .../ird/observe/ui/content/ContentUIHandler.java | 8 ++++ .../ui/content/table/ContentTableUIHandler.java | 27 +++++------ .../impl/longline/BaitsCompositionUIHandler.java | 2 +- .../longline/BranchlinesCompositionUIHandler.java | 3 +- .../impl/longline/CatchLonglineUIHandler.java | 20 +++----- .../table/impl/longline/EncounterUIHandler.java | 2 +- .../longline/FloatlinesCompositionUIHandler.java | 2 +- .../longline/GearUseFeaturesLonglineUIHandler.java | 3 +- .../impl/longline/HooksCompositionUIHandler.java | 2 +- .../table/impl/longline/SensorUsedUIHandler.java | 2 +- .../content/table/impl/longline/TdrUIHandler.java | 11 ++--- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 38 +++++++-------- .../table/impl/seine/NonTargetCatchUIHandler.java | 55 +++------------------- .../table/impl/seine/NonTargetSampleUIHandler.java | 46 +++++++----------- .../impl/seine/ObjectObservedSpeciesUIHandler.java | 7 ++- .../impl/seine/ObjectSchoolEstimateUIHandler.java | 12 ++--- .../table/impl/seine/SchoolEstimateUIHandler.java | 15 ++---- .../table/impl/seine/TargetCatchUIHandler.java | 6 +-- .../impl/seine/TargetDiscardCatchUIHandler.java | 19 ++++---- .../table/impl/seine/TargetSampleUIHandler.java | 45 ++++++------------ 20 files changed, 123 insertions(+), 202 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 1ef2472..97a049e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -66,6 +66,7 @@ import javax.swing.UIManager; import javax.swing.event.TableModelListener; import javax.swing.table.TableModel; import java.awt.Component; +import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; @@ -767,6 +768,13 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { editor.setQuadrant(quadrant); } + protected void reloadPropertyChangeListener(TopiaEntity bean, String propertyName, PropertyChangeListener listener) { + + bean.removePropertyChangeListener(propertyName, listener); + bean.addPropertyChangeListener(propertyName, listener); + + } + protected void reloadTableModelListener(TableModel tableModel, TableModelListener listener) { tableModel.removeTableModelListener(listener); tableModel.addTableModelListener(listener); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index 1242dfc..f72ccdf 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -87,11 +87,11 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top /** * Pour charger le bean d'édition dans la méthode {@link #openUI()}. * - * Cette méthode est appelée à chaque affichage de l'écran. + * Cette méthode est appelée à chaque ouverture de l'écran. * * @param mode le mode de l'écran */ - protected abstract void loadEditBean(ContentMode mode); + protected abstract void onOpenUI(ContentMode mode); /** * Pour enregistre l'objet en cours d'édition. @@ -119,6 +119,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top // mode mise a jour return ContentMode.UPDATE; + } // mode lecture @@ -134,6 +135,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } return ContentMode.READ; + } @Override @@ -154,11 +156,16 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top return getModel().getTableEditBean(); } + protected ContentTableUIInitializer createInitializer() { + ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>> uiInitializer = + new ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>>(getUi()); + return uiInitializer; + } + @Override public void initUI() throws Exception { - ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>> uiInitializer = - new ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>>(getUi()); + ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>> uiInitializer = createInitializer(); uiInitializer.initUI(ObserveContext.get().getServices()); } @@ -179,11 +186,8 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top // récupération du mode de l'écran ContentMode mode = computeContentMode(); - // chargement du bean d'édition - loadEditBean(mode); - // chargement de l'écran d'édition - loadTableEditBeanForm(mode); + onOpenUI(mode); // enregistrement du mode de l'écran getModel().setMode(mode); @@ -191,7 +195,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top // initialisation du modèle du tableau tableModel.attachModel(); - boolean canEdit = mode == ContentMode.UPDATE; + boolean canEdit = ContentMode.UPDATE == mode; if (canEdit) { // on lance le mode edition @@ -225,11 +229,6 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } - protected void loadTableEditBeanForm(ContentMode mode) { - // par defaut, rien à faire - } - - @Override public void startEditUI(String... binding) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java index af75db0..f25ad5d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java @@ -63,7 +63,7 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java index 001bb49..8911e36 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java @@ -107,7 +107,7 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -127,7 +127,6 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } - @Override public void afterSave(boolean refresh) { super.afterSave(refresh); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 710b8ad..030c1fe 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -148,7 +148,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -374,14 +374,9 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } - bean.removePropertyChangeListener(CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, catchFateChanged); - bean.addPropertyChangeListener(CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, catchFateChanged); - - bean.removePropertyChangeListener(CatchLongline.PROPERTY_BRANCHLINE, branchlineChanged); - bean.addPropertyChangeListener(CatchLongline.PROPERTY_BRANCHLINE, branchlineChanged); - - bean.removePropertyChangeListener(CatchLongline.PROPERTY_DEPREDATED, depredatedChanged); - bean.addPropertyChangeListener(CatchLongline.PROPERTY_DEPREDATED, depredatedChanged); + reloadPropertyChangeListener(bean, CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, catchFateChanged); + reloadPropertyChangeListener(bean, CatchLongline.PROPERTY_BRANCHLINE, branchlineChanged); + reloadPropertyChangeListener(bean, CatchLongline.PROPERTY_DEPREDATED, depredatedChanged); LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(ui); positionHelper.resetPosition(bean); @@ -560,12 +555,11 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); getUi().getSection().setData(positionHelper.getSectionUniverse()); - // To be sure always remove listener (could prevent some leaks) - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); + SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); + // listen messages to see if required to add - getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); + reloadTableModelListener(errorTableModel, computeTabValidStateListener); - SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java index a00e5c0..7d335cb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java @@ -62,7 +62,7 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedActivityId(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java index 89bd006..48926bd 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java @@ -62,7 +62,7 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 98b64bf..89cde36 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -116,7 +116,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedTripLonglineId(); @@ -154,7 +154,6 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } - GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); service.save(editBean); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java index 765f2c5..ca49581 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java @@ -63,7 +63,7 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java index cbdf74d..dd46581 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java @@ -80,7 +80,7 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedActivityId(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java index 973161c..ac05514 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java @@ -29,7 +29,6 @@ import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; @@ -122,7 +121,7 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -132,7 +131,6 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { copy(SetLongline.class, BinderService.EDIT_TDR, loaded, getBean()); - //FIXME Move this somewhere else ? // load sections (and baskets and branchlines) SetLonglineService setLonglineService = getService(SetLonglineService.class); List<Section> sections = setLonglineService.getSections(setLonglineId); @@ -264,12 +262,11 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); getUi().getSection().setData(positionHelper.getSectionUniverse()); - // To be sure always remove listener (could prevent some leaks) - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); + SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); + // listen messages to see if required to add - getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); + reloadTableModelListener(errorTableModel, computeTabValidStateListener); - SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index c030953..ad6c5b1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -285,35 +285,34 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected void loadEditBean(ContentMode mode) { + public void openUI() throws Exception { - String tripSeineId = getDataContext().getSelectedTripSeineId(); + if (log.isInfoEnabled()) { + log.info("OpenUI: " + getModel()); + } - TripSeine tripSeine = getService(GearUseFeaturesSeineService.class).loadForEdit(tripSeineId); + super.openUI(); - copy(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE, tripSeine, getBean()); + SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); - // reset measurements - getModel().getMeasurementsTableModel().clear(); + // listen messages to see to compute tab valid states + reloadTableModelListener(errorTableModel, computeTabValidStateListener); + + computeTabValidState(errorTableModel); } @Override - public void openUI() throws Exception { + protected void onOpenUI(ContentMode mode) { - if (log.isInfoEnabled()) { - log.info("OpenUI: " + getModel()); - } + String tripSeineId = getDataContext().getSelectedTripSeineId(); - super.openUI(); + TripSeine tripSeine = getService(GearUseFeaturesSeineService.class).loadForEdit(tripSeineId); - // To be sure always remove listener (could prevent some leaks) - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); - // listen messages to see if required to add - getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); + copy(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE, tripSeine, getBean()); - SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); - computeTabValidState(errorTableModel); + // reset measurements + getModel().getMeasurementsTableModel().clear(); } @@ -393,12 +392,13 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei List<GearUseFeaturesMeasurementSeine> measurements = measurementsTableModel.getCacheForRowNotEmpty(row); gearUseFeaturesSeine.clearGearUseFeaturesMeasurement(); - gearUseFeaturesSeine.addAllGearUseFeaturesMeasurement(measurements); } - getService(GearUseFeaturesSeineService.class).save(editBean); + GearUseFeaturesSeineService service = getService(GearUseFeaturesSeineService.class); + service.save(editBean); + } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 8e59f98..482db1f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -193,11 +193,11 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { List<Species> speciesList; - if (mode == ContentMode.UPDATE) { + if (ContentMode.UPDATE == mode) { // get current ocean Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); @@ -233,42 +233,6 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override - protected void loadTableEditBeanForm(ContentMode mode) { - - List<Species> speciesList; - - String tripId = getDataContext().getSelectedTripId(); - - if (mode == ContentMode.UPDATE) { - - // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(tripId); - - ObserveConfig config = getUi().getContextValue(ObserveConfig.class); - String speciesListId = config.getSpeciesListSeineNonTargetCatchId(); - - // get all species - List<Species> allSpecies = getService(ReferentialService.class).loadDecoratedSpecies(speciesListId); - - // filtre par status actif - ReferenceEntities.filterReferentielListByStatus(allSpecies); - - // filtre par ocean - speciesList = Species2.filterByOcean(allSpecies, ocean); - - } else { - - speciesList = new ArrayList<Species>(); - } - - ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); - if (log.isDebugEnabled()) { - log.debug("speciesList = " + speciesList.size()); - } - - } - - @Override protected void onSelectedRowChanged(int editingRow, NonTargetCatch bean, boolean create) { NonTargetCatchUI ui = getUi(); @@ -301,17 +265,10 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non requestFocus.requestFocus(); NonTargetCatch tableEditBean = getTableEditBean(); - tableEditBean.removePropertyChangeListener(NonTargetCatch.PROPERTY_TOTAL_COUNT, totalCountChanged); - tableEditBean.addPropertyChangeListener(NonTargetCatch.PROPERTY_TOTAL_COUNT, totalCountChanged); - - tableEditBean.removePropertyChangeListener(NonTargetCatch.PROPERTY_CATCH_WEIGHT, catchWeightChanged); - tableEditBean.addPropertyChangeListener(NonTargetCatch.PROPERTY_CATCH_WEIGHT, catchWeightChanged); - - tableEditBean.removePropertyChangeListener(NonTargetCatch.PROPERTY_MEAN_WEIGHT, meanWeightChanged); - tableEditBean.addPropertyChangeListener(NonTargetCatch.PROPERTY_MEAN_WEIGHT, meanWeightChanged); - - tableEditBean.removePropertyChangeListener(NonTargetCatch.PROPERTY_MEAN_LENGTH, meanLengthChanged); - tableEditBean.addPropertyChangeListener(NonTargetCatch.PROPERTY_MEAN_LENGTH, meanLengthChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_TOTAL_COUNT, totalCountChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_CATCH_WEIGHT, catchWeightChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_MEAN_WEIGHT, meanWeightChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_MEAN_LENGTH, meanLengthChanged); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index 88bc806..58f949c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -62,7 +62,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam /** Logger */ static private Log log = LogFactory.getLog(NonTargetSampleUIHandler.class); - protected final JAXXContextEntryDef<List<Species>> ALL_ESPECES_ENTRY = + protected final JAXXContextEntryDef<List<Species>> ALL_SPECIES_ENTRY = UIHelper.newListContextEntryDef("NonTargetSampleUI-all-speciess"); /** @@ -136,18 +136,8 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam } - public void resetWeightSource() { - getTableEditBean().setWeightSource(false); - getUi().getWeight().grabFocus(); - } - - public void resetLengthSource() { - getTableEditBean().setLengthSource(false); - getUi().getLength().grabFocus(); - } - @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setId = getDataContext().getSelectedSetId(); @@ -155,29 +145,16 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam copy(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, nonTargetSample, getBean()); - } - - @Override - protected void loadTableEditBeanForm(ContentMode mode) { - List<Species> speciesList; - if (mode == ContentMode.UPDATE) { - - String setId = getDataContext().getSelectedSetId(); + if (ContentMode.UPDATE == mode) { NonTargetSampleService service = getService(NonTargetSampleService.class); speciesList = service.getAvailableSpeciesForNonTargetSample(setId); - ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); + ALL_SPECIES_ENTRY.setContextValue(getUi(), speciesList); } - getModel().setMode(mode); - - - // initialisation du modèle du tableau - getUi().getTableModel().attachModel(); - } @Override @@ -194,12 +171,13 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam log.info("Remove obsolete nonTargetSample " + editBean.getTopiaId() + " from Set: " + setId); } + //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) service.delete(setId, editBean); } else { + //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) String savedId = service.save(setId, editBean); - editBean.setTopiaId(savedId); getService(NonTargetLengthService.class).save(editBean); @@ -207,6 +185,16 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam } } + public void resetWeightSource() { + getTableEditBean().setWeightSource(false); + getUi().getWeight().grabFocus(); + } + + public void resetLengthSource() { + getTableEditBean().setLengthSource(false); + getUi().getLength().grabFocus(); + } + @Override protected void onSelectedRowChanged(int editingRow, NonTargetLength bean, boolean create) { @@ -233,7 +221,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam ui.getAcquisitionModeGroup().setSelectedValue(ModeSaisieEchantillonEnum.byEffectif); } - availableEspeces = new ArrayList<Species>(ALL_ESPECES_ENTRY.getContextValue(ui)); + availableEspeces = new ArrayList<Species>(ALL_SPECIES_ENTRY.getContextValue(ui)); requestFocus = ui.getSpecies(); } else { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index 1db6bda..b1369e3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -59,7 +59,7 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); @@ -112,7 +112,10 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati @Override protected void doPersist(FloatingObject editBean) { - getService(ObjectObservedSpeciesService.class).save(editBean); + + ObjectObservedSpeciesService service = getService(ObjectObservedSpeciesService.class); + service.save(editBean); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java index 2245c1e..8c6b3b8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java @@ -59,7 +59,7 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); @@ -81,11 +81,6 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin } } -// @Override -// protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { -// return dataContext.getSelectedFloatingObjectId(); -// } - @Override protected void initTableUI(DefaultTableCellRenderer renderer) { JTable table = getUi().getTable(); @@ -114,7 +109,10 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin @Override protected void doPersist(FloatingObject editBean) { - getService(ObjectSchoolEstimateService.class).save(editBean); + + ObjectSchoolEstimateService service = getService(ObjectSchoolEstimateService.class); + service.save(editBean); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index ec3d09b..663544d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -59,7 +59,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch /** Logger */ static private Log log = LogFactory.getLog(SchoolEstimateUIHandler.class); - JAXXContextEntryDef<List<Species>> ALL_ESPECES_ENTRY = + JAXXContextEntryDef<List<Species>> ALL_SPECIES_ENTRY = UIHelper.newListContextEntryDef("SchoolEstimateUI-all-speciess"); public SchoolEstimateUIHandler(SchoolEstimateUI ui) { @@ -72,7 +72,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setSeineId = getDataContext().getSelectedSetId(); @@ -82,14 +82,9 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch copy(SetSeine.class, BinderService.EDIT_SCHOOL_ESTIMATE, loaded, getBean()); - } - - @Override - protected void loadTableEditBeanForm(ContentMode mode) { - List<Species> speciesList; - if (mode == ContentMode.UPDATE) { + if (ContentMode.UPDATE == mode) { // get current ocean Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); @@ -111,7 +106,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch speciesList = new ArrayList<Species>(); } - ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); + ALL_SPECIES_ENTRY.setContextValue(getUi(), speciesList); if (log.isDebugEnabled()) { log.debug("speciesList = " + speciesList.size()); } @@ -135,7 +130,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch if (create) { availableEspeces = new ArrayList<Species>( - ALL_ESPECES_ENTRY.getContextValue(ui)); + ALL_SPECIES_ENTRY.getContextValue(ui)); List<Species> list = model.getColumnValues(0); availableEspeces.removeAll(list); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java index 3967c6a..39a8e98 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java @@ -117,7 +117,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // en mode creation , on doit recalculer la liste des categories Species species = (Species) evt.getNewValue(); - onEspeceChanged(species); + onSpeciesChanged(species); } } @@ -156,7 +156,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { List<Species> speciesList; List<WeightCategory> categorieList; @@ -354,7 +354,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } @SuppressWarnings("unchecked") - protected void onEspeceChanged(Species species) { + protected void onSpeciesChanged(Species species) { List<WeightCategory> availableCategories; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java index b640cda..739fcc5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java @@ -125,7 +125,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // en mode creation , on doit recalculer la liste des categories Species species = (Species) evt.getNewValue(); - onEspeceChanged(bean, species); + onSpeciesChanged(bean, species); } } @@ -150,7 +150,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // en mode creation , on doit recalculer la liste des raison rejet WeightCategory weightCategory = (WeightCategory) evt.getNewValue(); - onCategorieChanged(bean, weightCategory); + onWeightCategoryChanged(bean, weightCategory); } @@ -193,7 +193,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { List<WeightCategory> categorieList; List<ReasonForDiscard> reasonForDiscardList; @@ -373,7 +373,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } // on recalcule la liste des speciess disponibles - List<Species> availableEspeces = buildEspeceList(beanEspece, beanWeightCategory); + List<Species> availableEspeces = buildSpeciesList(beanEspece, beanWeightCategory); speciesComboBox.setData(availableEspeces); // on reinitilise toujours la liste des espèces (pour reinitialiser la liste des categories) @@ -409,7 +409,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, requestFocus.requestFocus(); } - protected void onEspeceChanged(TargetCatch bean, Species species) { + protected void onSpeciesChanged(TargetCatch bean, Species species) { WeightCategory weightCategory = null; @@ -447,7 +447,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } - protected void onCategorieChanged(TargetCatch bean, WeightCategory weightCategory) { + protected void onWeightCategoryChanged(TargetCatch bean, WeightCategory weightCategory) { TargetDiscardCatchUI ui = getUi(); @@ -465,7 +465,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // un categorie est selectionne, on met a jour la liste des raisons // rejet disponible pour cette categorie - List<ReasonForDiscard> reasonForDiscardList = buildReasonFordiscardList( + List<ReasonForDiscard> reasonForDiscardList = buildReasonForDiscardList( weightCategory); if (log.isDebugEnabled()) { @@ -493,7 +493,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } - protected List<Species> buildEspeceList(Species species, WeightCategory weightCategory) { + protected List<Species> buildSpeciesList(Species species, WeightCategory weightCategory) { List<WeightCategory> weightCategoryList = getAllCategories(getUi()); @@ -537,7 +537,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } - protected List<ReasonForDiscard> buildReasonFordiscardList(WeightCategory weightCategory) { + protected List<ReasonForDiscard> buildReasonForDiscardList(WeightCategory weightCategory) { ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); List<ReasonForDiscard> reasonForDiscardList = @@ -604,4 +604,5 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, return set; } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index 5a90ee1..0cfa053 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -24,6 +24,7 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetLength; @@ -117,20 +118,8 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T getUi().getLength().grabFocus(); } -// @Override -// protected String getEditBeanIdToLoad(DataContext dataContext, -// DataService dataService, -// DataSource dataSource) throws DataSourceException { -// String setId = dataContext.getSelectedSetId(); -// // on doit récupérer l'unique échantillonThon de la calée -// -// TargetSample targetSample = getService(TargetSampleService.class).getTargetSample(setId, discarded); -// String id = targetSample == null ? null : targetSample.getTopiaId(); -// return id; -// } - @Override - protected void loadEditBean(ContentMode mode) { + protected void onOpenUI(ContentMode mode) { String setId = getDataContext().getSelectedSetId(); @@ -138,19 +127,13 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T copy(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, targetSample, getBean()); - } - - @Override - protected void loadTableEditBeanForm(ContentMode mode) { - - if (mode == ContentMode.UPDATE) { - - String setId = getDataContext().getSelectedSetId(); + if (ContentMode.UPDATE == mode) { // on ne charge les speciess uniquement si on est en mode édition List<Species> speciesList = getService(TargetSampleService.class).getAvailableSpeciesForTargetSample(setId, discarded); getUi().getSpecies().setData(speciesList); + } getModel().setMode(mode); @@ -166,23 +149,25 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T String setId = getDataContext().getSelectedSetId(); - if (editBean.getTopiaId() != null && editBean.isTargetLengthEmpty()) { + TargetSampleService service = getService(TargetSampleService.class); + + if (!Entities.isNew(editBean) && editBean.isTargetLengthEmpty()) { // remove orphan target sample if (log.isInfoEnabled()) { log.info("Remove obsolete targetSample " + editBean.getTopiaId() + " from Set: " + setId); } - - getService(TargetSampleService.class).delete(setId, editBean); + //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) + service.delete(setId, editBean); } else { - String savedId = getService(TargetSampleService.class).save(setId, editBean); - + String savedId = service.save(setId, editBean); editBean.setTopiaId(savedId); - + //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) getService(TargetLengthService.class).save(editBean); + } } @@ -245,11 +230,9 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T requestFocus.requestFocus(); TargetLength tableEditBean = getTableEditBean(); - tableEditBean.removePropertyChangeListener(TargetLength.PROPERTY_WEIGHT, weightChanged); - tableEditBean.addPropertyChangeListener(TargetLength.PROPERTY_WEIGHT, weightChanged); + reloadPropertyChangeListener(tableEditBean, TargetLength.PROPERTY_WEIGHT, weightChanged); + reloadPropertyChangeListener(tableEditBean, TargetLength.PROPERTY_LENGTH, lengthChanged); - tableEditBean.removePropertyChangeListener(TargetLength.PROPERTY_LENGTH, lengthChanged); - tableEditBean.addPropertyChangeListener(TargetLength.PROPERTY_LENGTH, lengthChanged); } @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 010d21dbbd6827d701b89c6e9a8dc0228ce9e271 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 19:01:14 2015 +0200 reorganisation des controleurs des ecrans de type tableaux + correction des sauvegardes des echantillons seine --- .../observe/services/AbstractObserveService.java | 42 ++- .../data/longline/CatchLonglineServiceImpl.java | 18 +- .../GearUseFeaturesLonglineServiceImpl.java | 8 +- .../data/longline/TripLonglineServiceImpl.java | 2 +- .../seine/GearUseFeaturesSeineServiceImpl.java | 11 +- .../data/seine/NonTargetCatchServiceImpl.java | 10 +- .../data/seine/NonTargetLengthService.java | 17 - .../data/seine/NonTargetLengthServiceImpl.java | 77 ---- .../data/seine/NonTargetSampleService.java | 6 +- .../data/seine/NonTargetSampleServiceImpl.java | 66 +++- .../data/seine/TargetCatchServiceImpl.java | 6 +- .../services/data/seine/TargetLengthService.java | 17 - .../data/seine/TargetLengthServiceImpl.java | 96 ----- .../services/data/seine/TargetSampleService.java | 4 +- .../data/seine/TargetSampleServiceImpl.java | 91 ++++- .../services/data/seine/TripSeineServiceImpl.java | 2 +- .../impl/longline/BaitsCompositionUIHandler.java | 66 ++-- .../longline/BranchlinesCompositionUIHandler.java | 27 +- .../impl/longline/CatchLonglineUIHandler.java | 420 ++++++++++----------- .../table/impl/longline/EncounterUIHandler.java | 65 ++-- .../longline/FloatlinesCompositionUIHandler.java | 64 ++-- .../longline/GearUseFeaturesLonglineUIHandler.java | 300 +++++++-------- .../impl/longline/HooksCompositionUIHandler.java | 69 ++-- .../table/impl/longline/SensorUsedUIHandler.java | 62 +-- .../content/table/impl/longline/TdrUIHandler.java | 188 ++++----- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 305 ++++++++------- .../table/impl/seine/NonTargetCatchUIHandler.java | 51 ++- .../table/impl/seine/NonTargetSampleUIHandler.java | 163 ++++---- .../impl/seine/ObjectObservedSpeciesUIHandler.java | 50 +-- .../impl/seine/ObjectSchoolEstimateUIHandler.java | 51 +-- .../table/impl/seine/SchoolEstimateUIHandler.java | 85 +++-- .../table/impl/seine/TargetCatchUIHandler.java | 100 ++--- .../impl/seine/TargetDiscardCatchUIHandler.java | 130 +++---- .../table/impl/seine/TargetSampleUIHandler.java | 250 ++++++------ 34 files changed, 1429 insertions(+), 1490 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 9fa8dc1..127fd89 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -264,7 +264,8 @@ public abstract class AbstractObserveService implements ObserveService { public abstract E onCreate(P parent, E toCreate); - public abstract E onUpdate(P parentBean, E toSave, E beanToSave); + public abstract E onUpdate(P parent, E toSave, E beanToSave); + } public <P extends TopiaEntity, E extends TopiaEntity> void doDelete(String parentId, String idToDelete, DeleteAction<P, E> deleteAction) { @@ -315,9 +316,7 @@ public abstract class AbstractObserveService implements ObserveService { saveCollectionAction.prepareSave(parentToSave, childrenToSave); - P parentSaved = getDao(saveCollectionAction.parentClass).findByTopiaId(parentToSave.getTopiaId()); - - saveCollectionAction.onUpdateParent(parentToSave, parentSaved); + P parentSaved = saveCollectionAction.onUpdateParent(parentToSave); List<E> oldChilds = new ArrayList<E>(saveCollectionAction.listUpdator.getChilds(parentSaved)); @@ -340,11 +339,11 @@ public abstract class AbstractObserveService implements ObserveService { } saveCollectionAction.listUpdator.addToList(parentSaved, childSaved); + } // on donne la main aux implantations pour faire des traitements supplémentaires - saveCollectionAction.onUpdateFinalize(parentToSave, oldChilds); - + saveCollectionAction.onUpdateFinalize(parentSaved, oldChilds); } @@ -361,8 +360,11 @@ public abstract class AbstractObserveService implements ObserveService { protected final TopiaEntityBinder<E> childBinder; - public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass, EntityListUpdator<P, E> listUpdator, - TopiaEntityBinder<P> parentBinder, TopiaEntityBinder<E> childBinder) { + public SaveCollectionAction(Class<P> parentClass, + Class<E> entityClass, + EntityListUpdator<P, E> listUpdator, + TopiaEntityBinder<P> parentBinder, + TopiaEntityBinder<E> childBinder) { this.parentClass = parentClass; this.entityClass = entityClass; this.listUpdator = listUpdator; @@ -370,18 +372,22 @@ public abstract class AbstractObserveService implements ObserveService { this.childBinder = childBinder; } - public void prepareSave(P parent, Collection<E> toSaves) { + public void prepareSave(P parentToSave, Collection<E> toSaves) { // par defaut, rien de specifique a faire avant de faire la sauvegarde } - public void onUpdateFinalize(P parent, Collection<E> oldChilds) throws TopiaException { + public void onUpdateFinalize(P parentSaved, Collection<E> oldChilds) throws TopiaException { // par défaut, rien à faire après la sauvegarde de la liste } - public P onUpdateParent(P parentToSave, P parentSaved) { + public P onUpdateParent(P parentToSave) { + TopiaDAO<P> dao = getDao(parentClass); + + P parentSaved = dao.findByTopiaId(parentToSave.getTopiaId()); parentBinder.copyExcluding(parentToSave, parentSaved, listUpdator.getPropertyName()); - parentSaved = getDao(parentClass).update(parentSaved); + parentSaved = dao.update(parentSaved); + return parentSaved; } @@ -390,20 +396,20 @@ public abstract class AbstractObserveService implements ObserveService { E childCreated = getDao(entityClass).create(); childBinder.load(childToCreate, childCreated, false); + return childCreated; } - public E onUpdateChild(E childToSave) { + public E onUpdateChild(E childToUpdate) { TopiaDAO<E> dao = getDao(entityClass); - E childSaved = dao.findByTopiaId(childToSave.getTopiaId()); - - childBinder.load(childToSave, childSaved, true); - childSaved = dao.update(childSaved); + E childUpdated = dao.findByTopiaId(childToUpdate.getTopiaId()); + childBinder.load(childToUpdate, childUpdated, true); + childUpdated = dao.update(childUpdated); - return childSaved; + return childUpdated; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java index 2f0c60a..361700e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -94,20 +94,20 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements @Override public CatchLongline onCreateChild(CatchLongline childToCreate) { - CatchLongline createdChild = super.onCreateChild(childToCreate); - saveSizeMeasures(childToCreate.getSizeMeasure(), createdChild); - saveWeightMeasures(childToCreate.getWeightMeasure(), createdChild); - return createdChild; + CatchLongline childCreated = super.onCreateChild(childToCreate); + saveSizeMeasures(childToCreate.getSizeMeasure(), childCreated); + saveWeightMeasures(childToCreate.getWeightMeasure(), childCreated); + return childCreated; } @Override - public CatchLongline onUpdateChild(CatchLongline childToSave) { + public CatchLongline onUpdateChild(CatchLongline childToUpdate) { - CatchLongline childSaved = super.onUpdateChild(childToSave); - saveSizeMeasures(childToSave.getSizeMeasure(), childSaved); - saveWeightMeasures(childToSave.getWeightMeasure(), childSaved); - return childSaved; + CatchLongline childUpdated = super.onUpdateChild(childToUpdate); + saveSizeMeasures(childToUpdate.getSizeMeasure(), childUpdated); + saveWeightMeasures(childToUpdate.getWeightMeasure(), childUpdated); + return childUpdated; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index 541605d..9013750 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -153,10 +153,10 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i } @Override - public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToSave) { - GearUseFeaturesLongline childSaved = super.onUpdateChild(childToSave); - saveMeasurement(childToSave.getGearUseFeaturesMeasurement(), childSaved); - return childSaved; + public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToUpdate) { + GearUseFeaturesLongline childUpdated = super.onUpdateChild(childToUpdate); + saveMeasurement(childToUpdate.getGearUseFeaturesMeasurement(), childUpdated); + return childUpdated; } protected void saveMeasurement(List<GearUseFeaturesMeasurementLongline> measurementsToSave, GearUseFeaturesLongline childSaved) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index 69f9044..6b6df6e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -107,7 +107,7 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T } @Override - public TripLongline onUpdate(Program parentBean, TripLongline toUpdate, TripLongline updated) { + public TripLongline onUpdate(Program parent, TripLongline toUpdate, TripLongline updated) { copyExcluding(TripLongline.class, BinderService.EDIT, toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); return updated; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index 49d0f1c..6118209 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -142,6 +142,7 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public GearUseFeaturesSeine onCreateChild(GearUseFeaturesSeine childToCreate) { + GearUseFeaturesSeine childCreated = getDao(entityClass).create( GearUseFeaturesSeine.PROPERTY_GEAR, childToCreate.getGear(), GearUseFeaturesSeine.PROPERTY_NUMBER, childToCreate.getNumber()); @@ -152,10 +153,12 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl } @Override - public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToSave) { - GearUseFeaturesSeine childSaved = super.onUpdateChild(childToSave); - saveMeasurement(childToSave.getGearUseFeaturesMeasurement(), childSaved); - return childSaved; + public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToUpdate) { + + GearUseFeaturesSeine childUpdated = super.onUpdateChild(childToUpdate); + saveMeasurement(childToUpdate.getGearUseFeaturesMeasurement(), childUpdated); + return childUpdated; + } protected void saveMeasurement(List<GearUseFeaturesMeasurementSeine> measurementsToSave, GearUseFeaturesSeine childSaved) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java index 51d5711..b77ea2f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java @@ -65,7 +65,7 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements SetSeine.class, NonTargetCatch.class, getListUpdator(), parentBinder, childbinder) { @Override - public void prepareSave(SetSeine parent, Collection<NonTargetCatch> toSaves) { + public void prepareSave(SetSeine parentToSave, Collection<NonTargetCatch> toSaves) { // mise a jour de la propriete nonTargetDiscarded @@ -77,11 +77,13 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements break; } } - parent.setNonTargetDiscarded(hasRejet); + + parentToSave.setNonTargetDiscarded(hasRejet); + } @Override - public void onUpdateFinalize(SetSeine parent, Collection<NonTargetCatch> oldChilds) throws TopiaException { + public void onUpdateFinalize(SetSeine parentSaved, Collection<NonTargetCatch> oldChilds) throws TopiaException { if (CollectionUtils.isNotEmpty(nonTargetLengthsToDelete)) { @@ -91,7 +93,7 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements log.info("Will remove " + nonTargetLengthsToDelete.size() + " obsolete nonTargetSample(s)."); } - NonTargetSample echantillon = parent.getNonTargetSample().get(0); + NonTargetSample echantillon = parentSaved.getNonTargetSample().get(0); // on supprime les echantillons obsoletes echantillon.getNonTargetLength().removeAll(nonTargetLengthsToDelete); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java deleted file mode 100644 index 1423c61..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java +++ /dev/null @@ -1,17 +0,0 @@ -package fr.ird.observe.services.data.seine; - -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.services.Commit; -import fr.ird.observe.services.ObserveService; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public interface NonTargetLengthService extends ObserveService { - - NonTargetSample loadForEdit(String setId); - - @Commit - void save(NonTargetSample parent); - -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java deleted file mode 100644 index a70b69e..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package fr.ird.observe.services.data.seine; - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.NonTargetLength; -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.List; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class NonTargetLengthServiceImpl extends AbstractObserveService implements NonTargetLengthService { - - @Override - public NonTargetSample loadForEdit(String setId) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setId); - - NonTargetSample toLoad; - - if (setSeine.isNonTargetSampleEmpty()) { - - toLoad = null; - - } else { - - List<NonTargetSample> nonTargetSamples = setSeine.getNonTargetSample(); - toLoad = nonTargetSamples.get(0); - - } - - NonTargetSample loaded = getDao(NonTargetSample.class).newInstance(); - - if (toLoad != null) { - - copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - - if (!toLoad.isNonTargetLengthEmpty()) { - - TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); - TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); - - for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { - - NonTargetLength childLoaded = dao.newInstance(); - binder.load(childToLoad, childLoaded, true); - loaded.addNonTargetLength(childLoaded); - - } - } - } - - return loaded; - } - - @Override - public void save(NonTargetSample parent) { - - TopiaEntityBinder<NonTargetSample> parentBinder = getBinder(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH); - TopiaEntityBinder<NonTargetLength> childbinder = getBinder(NonTargetLength.class, BinderService.EDIT); - - doSaveList(parent, new SaveCollectionAction<NonTargetSample, NonTargetLength>( - NonTargetSample.class, NonTargetLength.class, getListUpdator(), parentBinder, childbinder)); - } - - protected EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - NonTargetSample.class, - NonTargetLength.class, - NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - } -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java index e433ab6..077c23c 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java @@ -19,16 +19,16 @@ public interface NonTargetSampleService extends ObserveService { List<Species> getAvailableSpeciesForNonTargetSample(String setSeineId); - NonTargetSample getNonTargetSample(String setSeineId); + NonTargetSample loadForEdit(String setSeineId); boolean canUseNonTargetSample(String setSeineId); List<NonTargetLength> getObsoleteNonTargetLengths(String setSeineId, Set<String> speciesIdsUsed); @Commit - String save(String setId, NonTargetSample editBean); + String save(String setSeineId, NonTargetSample nonTargetSampleToSave); @Commit - void delete(String setId, NonTargetSample editBean); + void delete(String setSeineId, NonTargetSample nonTargetSampleToDelete); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index d7a0983..caec214 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -1,6 +1,8 @@ package fr.ird.observe.services.data.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; @@ -8,6 +10,7 @@ import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.NonTargetSampleDAO; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaDAO; @@ -59,7 +62,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public NonTargetSample getNonTargetSample(String setSeineId) { + public NonTargetSample loadForEdit(String setSeineId) { SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); @@ -76,7 +79,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } - NonTargetSample loaded = getDao().newInstance(); + NonTargetSample loaded = getDao(NonTargetSample.class).newInstance(); if (toLoad != null) { @@ -97,9 +100,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } } - return loaded; - } @Override @@ -111,7 +112,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public List<NonTargetLength> getObsoleteNonTargetLengths(String setSeineId, Set<String> speciessUsed) { + public List<NonTargetLength> getObsoleteNonTargetLengths(String setSeineId, Set<String> speciesIdsUsed) { SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); @@ -126,7 +127,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement for (NonTargetLength taille : nonTargetSample.getNonTargetLength()) { Species species = taille.getSpecies(); - if (!speciessUsed.contains(species.getTopiaId())) { + if (!speciesIdsUsed.contains(species.getTopiaId())) { // l'espèce n'existe plus dans les rejet faune, on doit le supprimer nonTargetLengthsToDelete.add(taille); @@ -147,9 +148,9 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public String save(String setSeineId, NonTargetSample toSave) { + public String save(String setSeineId, NonTargetSample nonTargetSampleToSave) { - String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + String savedId = doSave(setSeineId, nonTargetSampleToSave, new SaveAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { @Override public NonTargetSample onCreate(SetSeine parent, NonTargetSample toCreate) { @@ -158,19 +159,62 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement NonTargetSample created = dao.create(); copyExcluding(NonTargetSample.class, BinderService.EDIT, toCreate, created, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); parent.addNonTargetSample(created); + + saveTargetLengths(toCreate.getNonTargetLength(), created); + dao.update(created); return created; } @Override - public NonTargetSample onUpdate(SetSeine parentBean, NonTargetSample toUpdate, NonTargetSample updated) { + public NonTargetSample onUpdate(SetSeine parent, NonTargetSample toUpdate, NonTargetSample updated) { copyExcluding(NonTargetSample.class, BinderService.EDIT, toUpdate, updated, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + + saveTargetLengths(toUpdate.getNonTargetLength(), updated); + getDao().update(updated); return updated; } + + protected void saveTargetLengths(Collection<NonTargetLength> nonTargetLengthsToSave, NonTargetSample childSaved) { + + List<NonTargetLength> nonTargetLengthsSaved = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(nonTargetLengthsToSave)) { + + TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); + TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); + + for (NonTargetLength nonTargetLengthToSave : nonTargetLengthsToSave) { + + NonTargetLength nonTargetLengthSaved; + + if (Entities.isNew(nonTargetLengthToSave)) { + + nonTargetLengthSaved = dao.create(); + binder.load(nonTargetLengthToSave, nonTargetLengthSaved, false); + + } else { + + nonTargetLengthSaved = dao.findByTopiaId(nonTargetLengthToSave.getTopiaId()); + binder.load(nonTargetLengthToSave, nonTargetLengthSaved, true); + + } + + nonTargetLengthsSaved.add(nonTargetLengthSaved); + + } + + } + + childSaved.clearNonTargetLength(); + childSaved.addAllNonTargetLength(nonTargetLengthsSaved); + + } + }); return savedId; @@ -178,9 +222,9 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public void delete(String setId, NonTargetSample toDelete) { + public void delete(String setSeineId, NonTargetSample nonTargetSampleToDelete) { - doDelete(setId, toDelete.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + doDelete(setSeineId, nonTargetSampleToDelete.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { @Override public void onDelete(SetSeine parent, NonTargetSample toDelete) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java index e2155d1..f8d00ee 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java @@ -114,7 +114,7 @@ public class TargetCatchServiceImpl extends AbstractObserveService implements Ta SetSeine.class, TargetCatch.class, getListUpdator(), parentBinder, childBinder) { @Override - public void onUpdateFinalize(SetSeine parent, Collection<TargetCatch> oldChilds) throws TopiaException { + public void onUpdateFinalize(SetSeine parentSaved, Collection<TargetCatch> oldChilds) throws TopiaException { if (CollectionUtils.isNotEmpty(oldChilds)) { @@ -131,7 +131,7 @@ public class TargetCatchServiceImpl extends AbstractObserveService implements Ta } - parent.addAllTargetCatch(targetCatchesToReinject); + parentSaved.addAllTargetCatch(targetCatchesToReinject); } @@ -143,7 +143,7 @@ public class TargetCatchServiceImpl extends AbstractObserveService implements Ta log.info("Will remove " + targetLengthsToDelete.size() + " obsolete targetLength(s)."); } - TargetSample targetSample = parent.getTargetSample().get(0); + TargetSample targetSample = parentSaved.getTargetSample().get(0); // on supprime les echantillons obsoletes targetSample.getTargetLength().removeAll(targetLengthsToDelete); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java deleted file mode 100644 index 4201f7f..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java +++ /dev/null @@ -1,17 +0,0 @@ -package fr.ird.observe.services.data.seine; - -import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.services.Commit; -import fr.ird.observe.services.ObserveService; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public interface TargetLengthService extends ObserveService { - - TargetSample loadForEdit(String setId, boolean discarded); - - @Commit - void save(TargetSample parent); - -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java deleted file mode 100644 index e6fa067..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -package fr.ird.observe.services.data.seine; - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.Collection; -import java.util.List; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class TargetLengthServiceImpl extends AbstractObserveService implements TargetLengthService { - - @Override - public TargetSample loadForEdit(String setId, boolean discarded) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setId); - - TargetSample toLoad = null; - - if (!setSeine.isNonTargetSampleEmpty()) { - - List<TargetSample> targetSamples = setSeine.getTargetSample(); - for (TargetSample targetSample : targetSamples) { - - Boolean isDiscarded = targetSample.getDiscarded(); - - if (discarded == (isDiscarded != null && isDiscarded)) { - toLoad = targetSample; - } - - } - - } - - TargetSample loaded = getDao(TargetSample.class).newInstance(); - - if (toLoad != null) { - - copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); - - - if (!toLoad.isTargetLengthEmpty()) { - - TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); - TopiaDAO<TargetLength> dao = getDao(TargetLength.class); - - for (TargetLength childToLoad : toLoad.getTargetLength()) { - - TargetLength childLoaded = dao.newInstance(); - binder.load(childToLoad, childLoaded, true); - loaded.addTargetLength(childLoaded); - - } - } - } - - - return loaded; - } - - @Override - public void save(TargetSample parent) { - - TopiaEntityBinder<TargetSample> parentBinder = getBinder(TargetSample.class, BinderService.EDIT_TARGET_LENGTH); - TopiaEntityBinder<TargetLength> childbinder = getBinder(TargetLength.class, BinderService.EDIT); - - doSaveList(parent, new SaveCollectionAction<TargetSample, TargetLength>( - TargetSample.class, TargetLength.class, getListUpdator(), parentBinder, childbinder) { - - @Override - public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { - - for (TargetLength targetLength : tosaves) { - - // on attache a l'echantillon - targetLength.setTargetSample(parent); - } - - } - }); - } - - protected EntityListUpdator<TargetSample, TargetLength> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - TargetSample.class, - TargetLength.class, - TargetSample.PROPERTY_TARGET_LENGTH); - } -} diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java index c1b2d32..40bfd62 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java @@ -21,7 +21,7 @@ public interface TargetSampleService extends ObserveService { List<TargetLength> getObsoleteTargetLengths(String setSeineId, Set<String> speciesIdsUsed, boolean discarded); - TargetSample getTargetSample(String setSeineId, boolean discarded); + TargetSample loadForEdit(String setSeineId, boolean discarded); boolean canUseTargetSample(String setSeineId, boolean discarded); @@ -29,6 +29,6 @@ public interface TargetSampleService extends ObserveService { String save(String setSeineId, TargetSample toSave); @Commit - void delete(String setId, TargetSample bean); + void delete(String setSeineId, TargetSample bean); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 8735b1b..67953b1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -1,6 +1,8 @@ package fr.ird.observe.services.data.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; @@ -9,8 +11,11 @@ import fr.ird.observe.entities.seine.TargetLengthDAO; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.entities.seine.TargetSampleDAO; import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; @@ -29,14 +34,6 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T /** Logger. */ private static final Log log = LogFactory.getLog(TargetSampleServiceImpl.class); - protected TargetSampleDAO getDao() { - return (TargetSampleDAO) getDao(TargetSample.class); - } - - protected TargetLengthDAO getChildDao() { - return (TargetLengthDAO) getDao(TargetLength.class); - } - @Override public List<Species> getAvailableSpeciesForTargetSample(String setSeineId, boolean discarded) { @@ -79,9 +76,8 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } - @Override - public TargetSample getTargetSample(String setSeineId, boolean discarded) { + public TargetSample loadForEdit(String setSeineId, boolean discarded) { SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); @@ -108,14 +104,15 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); + if (!toLoad.isTargetLengthEmpty()) { - TargetLengthDAO childDao = getChildDao(); TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); + TopiaDAO<TargetLength> dao = getDao(TargetLength.class); for (TargetLength childToLoad : toLoad.getTargetLength()) { - TargetLength childLoaded = childDao.newInstance(); + TargetLength childLoaded = dao.newInstance(); binder.load(childToLoad, childLoaded, true); loaded.addTargetLength(childLoaded); @@ -125,7 +122,6 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T return loaded; - } @Override @@ -180,18 +176,63 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T TargetSample created = getDao().create(); copyExcluding(TargetSample.class, BinderService.EDIT, toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); parent.addTargetSample(created); + + saveTargetLengths(toCreate.getTargetLength(), created); + getDao().update(created); return created; + } @Override - public TargetSample onUpdate(SetSeine parentBean, TargetSample toUpdate, TargetSample updated) { + public TargetSample onUpdate(SetSeine parent, TargetSample toUpdate, TargetSample updated) { copyExcluding(TargetSample.class, BinderService.EDIT, toUpdate, updated, TargetSample.PROPERTY_TARGET_LENGTH); + + saveTargetLengths(toUpdate.getTargetLength(), updated); + getDao().update(updated); return updated; } + + protected void saveTargetLengths(Collection<TargetLength> targetLengthsToSave, TargetSample childSaved) { + + List<TargetLength> targetLengthsSaved = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(targetLengthsToSave)) { + + TopiaDAO<TargetLength> dao = getDao(TargetLength.class); + TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); + + for (TargetLength targetLengthToSave : targetLengthsToSave) { + + TargetLength targetLengthSaved; + + if (Entities.isNew(targetLengthToSave)) { + + targetLengthSaved = dao.create(); + binder.load(targetLengthToSave, targetLengthSaved, false); + + } else { + + targetLengthSaved = dao.findByTopiaId(targetLengthToSave.getTopiaId()); + binder.load(targetLengthToSave, targetLengthSaved, true); + + } + + targetLengthsSaved.add(targetLengthSaved); + + } + + } + + childSaved.clearTargetLength(); + childSaved.addAllTargetLength(targetLengthsSaved); + + } + + }); return savedId; @@ -199,15 +240,33 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } @Override - public void delete(String setId, TargetSample bean) { - doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { + public void delete(String setSeineId, TargetSample bean) { + + doDelete(setSeineId, bean.getTopiaId(), new DeleteAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { @Override public void onDelete(SetSeine parent, TargetSample toDelete) { + super.onDelete(parent, toDelete); parent.removeTargetSample(toDelete); + } }); } + protected TargetSampleDAO getDao() { + return (TargetSampleDAO) getDao(TargetSample.class); + } + + protected TargetLengthDAO getChildDao() { + return (TargetLengthDAO) getDao(TargetLength.class); + } + + protected EntityListUpdator<TargetSample, TargetLength> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + TargetSample.class, + TargetLength.class, + TargetSample.PROPERTY_TARGET_LENGTH); + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index f910d1f..4f59498 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -110,7 +110,7 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip } @Override - public TripSeine onUpdate(Program parentBean, TripSeine toUpdate, TripSeine updated) { + public TripSeine onUpdate(Program parent, TripSeine toUpdate, TripSeine updated) { copyExcluding(TripSeine.class, BinderService.EDIT, toUpdate, updated, TripSeine.PROPERTY_ROUTE); return updated; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java index f25ad5d..0112839 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java @@ -63,39 +63,6 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void onOpenUI(ContentMode mode) { - - String setLonglineId = getDataContext().getSelectedSetId(); - - BaitsCompositionService service = getService(BaitsCompositionService.class); - - SetLongline loaded = service.loadForEdit(setLonglineId); - - copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, loaded, getBean()); - - } - - @Override - protected void doPersist(SetLongline editBean) { - - BaitsCompositionService service = getService(BaitsCompositionService.class); - service.save(editBean); - - } - - @Override - protected void onSelectedRowChanged(int editingRow, BaitsComposition bean, boolean create) { - - if (getTableModel().isEditable()) { - if (log.isDebugEnabled()) { - log.debug("Row has changed to " + editingRow); - } - getUi().getBaitType().requestFocus(); - } - - } - - @Override protected void initTableUI(DefaultTableCellRenderer renderer) { JTable table = getUi().getTable(); @@ -131,6 +98,39 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void onOpenUI(ContentMode mode) { + + String setLonglineId = getDataContext().getSelectedSetId(); + + BaitsCompositionService service = getService(BaitsCompositionService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, loaded, getBean()); + + } + + @Override + protected void onSelectedRowChanged(int editingRow, BaitsComposition bean, boolean create) { + + if (getTableModel().isEditable()) { + if (log.isDebugEnabled()) { + log.debug("Row has changed to " + editingRow); + } + getUi().getBaitType().requestFocus(); + } + + } + + @Override + protected void doPersist(SetLongline editBean) { + + BaitsCompositionService service = getService(BaitsCompositionService.class); + service.save(editBean); + + } + + @Override public void afterSave(boolean refresh) { super.afterSave(refresh); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java index 8911e36..c65d4bb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java @@ -63,18 +63,6 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override - protected void onSelectedRowChanged(int editingRow, BranchlinesComposition bean, boolean create) { - - if (getTableModel().isEditable()) { - if (log.isDebugEnabled()) { - log.debug("Row has changed to " + editingRow); - } - getUi().getTopType().requestFocus(); - } - - } - - @Override protected void initTableUI(DefaultTableCellRenderer renderer) { JTable table = getUi().getTable(); @@ -120,6 +108,21 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override + protected void onSelectedRowChanged(int editingRow, BranchlinesComposition bean, boolean create) { + + if (log.isDebugEnabled()) { + log.debug("Row has changed to " + editingRow); + } + + if (getTableModel().isEditable()) { + + getUi().getTopType().requestFocus(); + + } + + } + + @Override protected void doPersist(SetLongline editBean) { BranchlinesCompositionService service = getService(BranchlinesCompositionService.class); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 030c1fe..62818c6 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -148,86 +148,212 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected void onOpenUI(ContentMode mode) { + protected CatchLonglineTableModel getTableModel() { + return (CatchLonglineTableModel) super.getTableModel(); + } - String setLonglineId = getDataContext().getSelectedSetId(); + @Override + public void initUI() throws Exception { - CatchLonglineService service = getService(CatchLonglineService.class); + // add a listPredicate to get only species from the correct configured speciesList + ObserveConfig config = getUi().getContextValue(ObserveConfig.class); - SetLongline loaded = service.loadForEdit(setLonglineId); + { + String speciesListId = config.getSpeciesListLonglineCatchId(); + prepareSpeciesList(speciesListId, getUi().getSpeciesCatch(), n("observe.error.speciesList.longline.catch.notFound")); + } - copy(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE, loaded, getBean()); + { + String speciesListId = config.getSpeciesListLonglineDepredatorId(); + prepareSpeciesList(speciesListId, getUi().getPredator(), n("observe.error.speciesList.longline.depredator.notFound")); + } - // reset size measures - getModel().getSizeMeasuresTableModel().clear(); + CatchLonglineContentTableUIInitializer uiInitializer = new CatchLonglineContentTableUIInitializer(getUi()); + uiInitializer.initUI(ObserveContext.get().getServices()); - // reset weight measures - getModel().getWeightMeasuresTableModel().clear(); + getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_SHOW_INDIVIDUAL_TABS, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean newValue = (Boolean) evt.getNewValue(); + showIndividualTabs(newValue); + } + }); - // load sections (and baskets and branchlines) - SetLonglineService setLonglineService = getService(SetLonglineService.class); - List<Section> sections = setLonglineService.getSections(setLonglineId); + getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean newValue = (Boolean) evt.getNewValue(); + setTableModelEditable(newValue); + } + }); - LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); - positionHelper.initSections(sections, getTableModel().getData()); + setTableModelEditable(getModel().isEditable()); + + LonglinePositionHelper<CatchLongline> positionHelper = new LonglinePositionHelper<CatchLongline>( + getUi().getSection(), + getUi().getBasket(), + getUi().getBranchline(), + getTableEditBean()); + + POSITION_HELPER_ENTRY.setContextValue(getUi(), positionHelper); } @Override - protected void doPersist(SetLongline editBean) { - - List<CatchLongline> catchLonglines = editBean.getCatchLongline(); + protected void initTableUI(DefaultTableCellRenderer renderer) { { - SizeMeasuresTableModel tableModel = getModel().getSizeMeasuresTableModel(); + // init main table - Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); + JTable table = getUi().getTable(); - for (Integer row : rowsChanged) { + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.catchlongline.table.sectionHaulingId"), + n("observe.catchlongline.table.sectionHaulingId.tip"), + n("observe.catchlongline.table.basketHaulingId"), + n("observe.catchlongline.table.basketHaulingId.tip"), + n("observe.catchlongline.table.branchlineHaulingId"), + n("observe.catchlongline.table.branchlineHaulingId.tip"), - CatchLongline catchLongline = catchLonglines.get(row); + n("observe.catchlongline.table.speciesCatch"), + n("observe.catchlongline.table.speciesCatch.tip"), + n("observe.catchlongline.table.acquisitionMode"), + n("observe.catchlongline.table.acquisitionMode.tip"), + n("observe.catchlongline.table.count"), + n("observe.catchlongline.table.count.tip"), + n("observe.catchlongline.table.catchHealthness"), + n("observe.catchlongline.table.catchHealthness.tip"), + n("observe.catchlongline.table.catchFateLongline"), + n("observe.catchlongline.table.catchFateLongline.tip"), + n("observe.catchlongline.table.discardHealthness"), + n("observe.catchlongline.table.discardHealthness.tip"), + n("observe.catchlongline.table.depredated"), + n("observe.catchlongline.table.depredated.tip"), + n("observe.catchlongline.table.comment"), + n("observe.catchlongline.table.comment.tip")); - List<SizeMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); - catchLongline.clearSizeMeasure(); - catchLongline.addAllSizeMeasure(measurements); + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Section.class, DecoratorService.HAULING_IDENTIFIER)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, Basket.class, DecoratorService.HAULING_IDENTIFIER)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newDecorateTableCellRenderer(renderer, Branchline.class, DecoratorService.HAULING_IDENTIFIER)); + + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); + UIHelper.setTableColumnRenderer(table, 4, UIHelper.newEnumTableCellRenderer(renderer, CatchAcquisitionModeEnum.class)); + UIHelper.setTableColumnRenderer(table, 5, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 6, UIHelper.newDecorateTableCellRenderer(renderer, Healthness.class)); + UIHelper.setTableColumnRenderer(table, 7, UIHelper.newDecorateTableCellRenderer(renderer, CatchFateLongline.class)); + UIHelper.setTableColumnRenderer(table, 8, UIHelper.newDecorateTableCellRenderer(renderer, Healthness.class)); + UIHelper.setTableColumnRenderer(table, 9, UIHelper.newBooleanTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 10, UIHelper.newStringTableCellRenderer(renderer, 10, true)); - } } + ReferentialService service = getService(ReferentialService.class); { - WeightMeasuresTableModel tableModel = getModel().getWeightMeasuresTableModel(); + // init size measures table + JTable table = getUi().getSizeMeasuresTable(); - Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); + UIHelper.setI18nTableHeaderRenderer(table, + n("observe.catchlongline.table.sizeMeasureType"), + n("observe.catchlongline.table.sizeMeasureType.tip"), + n("observe.catchlongline.table.size"), + n("observe.catchlongline.table.size.tip")); - for (Integer row : rowsChanged) { + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, SizeMeasureType.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - CatchLongline catchLongline = catchLonglines.get(row); + Decorator<SizeMeasureType> decorator = ObserveContext.get().getDecorator(SizeMeasureType.class); - List<WeightMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); - catchLongline.clearWeightMeasure(); - catchLongline.addAllWeightMeasure(measurements); + List<SizeMeasureType> list = service.loadAndDecorateList(SizeMeasureType.class); + UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); + UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); + + SizeMeasuresTableModel tableModel = getModel().getSizeMeasuresTableModel(); + tableModel.installTableKeyListener(getUi().getSizeMeasuresTable()); + tableModel.addPropertyChangeListener(SizeMeasuresTableModel.MODIFIED_PROPERTY, sizeTableModelModified); - } } - CatchLonglineService service = getService(CatchLonglineService.class); - service.save(editBean); + { + // init weight measures table + JTable table = getUi().getWeightMeasuresTable(); + + UIHelper.setI18nTableHeaderRenderer(table, + n("observe.catchlongline.table.weightMeasureType"), + n("observe.catchlongline.table.weightMeasureType.tip"), + n("observe.catchlongline.table.weight"), + n("observe.catchlongline.table.weight.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, WeightMeasureType.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + + Decorator<WeightMeasureType> decorator = ObserveContext.get().getDecorator(WeightMeasureType.class); + List<WeightMeasureType> list = service.loadAndDecorateList(WeightMeasureType.class); + UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); + UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); + + WeightMeasuresTableModel tableModel = getModel().getWeightMeasuresTableModel(); + tableModel.installTableKeyListener(getUi().getWeightMeasuresTable()); + tableModel.addPropertyChangeListener(WeightMeasuresTableModel.MODIFIED_PROPERTY, weightTableModelModified); + + } + + getTableModel().addPropertyChangeListener(ContentTableModel.CREATE_PROPERTY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean oldValue = (Boolean) evt.getOldValue(); + Boolean newValue = (Boolean) evt.getNewValue(); + setTableModelCreate(oldValue, newValue); + } + }); } - public void saveBranchline() { + @Override + public void openUI() throws Exception { if (log.isInfoEnabled()) { - log.info("Saved modified branchline"); + log.info("OpenUI: " + getModel()); } - Branchline branchline = getTableEditBean().getBranchline(); + super.openUI(); + + // Reset all sections + LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); + getUi().getSection().setData(positionHelper.getSectionUniverse()); + + SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); + + // listen messages to see if required to add + reloadTableModelListener(errorTableModel, computeTabValidStateListener); + + computeTabValidState(errorTableModel); + + } + + @Override + protected void onOpenUI(ContentMode mode) { + + String setLonglineId = getDataContext().getSelectedSetId(); CatchLonglineService service = getService(CatchLonglineService.class); - Branchline beanSaved = service.saveBranchline(branchline); - getTableEditBean().setBranchline(beanSaved); - getUi().getBranchlineValidator().setChanged(false); + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE, loaded, getBean()); + + // reset size measures + getModel().getSizeMeasuresTableModel().clear(); + + // reset weight measures + getModel().getWeightMeasuresTableModel().clear(); + + // load sections (and baskets and branchlines) + SetLonglineService setLonglineService = getService(SetLonglineService.class); + List<Section> sections = setLonglineService.getSections(setLonglineId); + + LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); + positionHelper.initSections(sections, getTableModel().getData()); } @@ -386,208 +512,87 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - - { - // init main table - - JTable table = getUi().getTable(); - - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.catchlongline.table.sectionHaulingId"), - n("observe.catchlongline.table.sectionHaulingId.tip"), - n("observe.catchlongline.table.basketHaulingId"), - n("observe.catchlongline.table.basketHaulingId.tip"), - n("observe.catchlongline.table.branchlineHaulingId"), - n("observe.catchlongline.table.branchlineHaulingId.tip"), - - n("observe.catchlongline.table.speciesCatch"), - n("observe.catchlongline.table.speciesCatch.tip"), - n("observe.catchlongline.table.acquisitionMode"), - n("observe.catchlongline.table.acquisitionMode.tip"), - n("observe.catchlongline.table.count"), - n("observe.catchlongline.table.count.tip"), - n("observe.catchlongline.table.catchHealthness"), - n("observe.catchlongline.table.catchHealthness.tip"), - n("observe.catchlongline.table.catchFateLongline"), - n("observe.catchlongline.table.catchFateLongline.tip"), - n("observe.catchlongline.table.discardHealthness"), - n("observe.catchlongline.table.discardHealthness.tip"), - n("observe.catchlongline.table.depredated"), - n("observe.catchlongline.table.depredated.tip"), - n("observe.catchlongline.table.comment"), - n("observe.catchlongline.table.comment.tip")); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Section.class, DecoratorService.HAULING_IDENTIFIER)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, Basket.class, DecoratorService.HAULING_IDENTIFIER)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newDecorateTableCellRenderer(renderer, Branchline.class, DecoratorService.HAULING_IDENTIFIER)); - - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); - UIHelper.setTableColumnRenderer(table, 4, UIHelper.newEnumTableCellRenderer(renderer, CatchAcquisitionModeEnum.class)); - UIHelper.setTableColumnRenderer(table, 5, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 6, UIHelper.newDecorateTableCellRenderer(renderer, Healthness.class)); - UIHelper.setTableColumnRenderer(table, 7, UIHelper.newDecorateTableCellRenderer(renderer, CatchFateLongline.class)); - UIHelper.setTableColumnRenderer(table, 8, UIHelper.newDecorateTableCellRenderer(renderer, Healthness.class)); - UIHelper.setTableColumnRenderer(table, 9, UIHelper.newBooleanTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 10, UIHelper.newStringTableCellRenderer(renderer, 10, true)); - - } - - ReferentialService service = getService(ReferentialService.class); - { - // init size measures table - JTable table = getUi().getSizeMeasuresTable(); - - UIHelper.setI18nTableHeaderRenderer(table, - n("observe.catchlongline.table.sizeMeasureType"), - n("observe.catchlongline.table.sizeMeasureType.tip"), - n("observe.catchlongline.table.size"), - n("observe.catchlongline.table.size.tip")); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, SizeMeasureType.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - - Decorator<SizeMeasureType> decorator = ObserveContext.get().getDecorator(SizeMeasureType.class); - - List<SizeMeasureType> list = service.loadAndDecorateList(SizeMeasureType.class); - UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); - UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); - - SizeMeasuresTableModel tableModel = getModel().getSizeMeasuresTableModel(); - tableModel.installTableKeyListener(getUi().getSizeMeasuresTable()); - tableModel.addPropertyChangeListener(SizeMeasuresTableModel.MODIFIED_PROPERTY, sizeTableModelModified); + protected void closeSafeUI() { + if (log.isInfoEnabled()) { + log.info("CloseUI: " + getModel()); } + super.closeSafeUI(); - { - // init weight measures table - JTable table = getUi().getWeightMeasuresTable(); + // remove listener + getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); - UIHelper.setI18nTableHeaderRenderer(table, - n("observe.catchlongline.table.weightMeasureType"), - n("observe.catchlongline.table.weightMeasureType.tip"), - n("observe.catchlongline.table.weight"), - n("observe.catchlongline.table.weight.tip")); + } - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, WeightMeasureType.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + @Override + protected void resetEditBean() { - Decorator<WeightMeasureType> decorator = ObserveContext.get().getDecorator(WeightMeasureType.class); + UIHelper.stopEditing(getUi().getSizeMeasuresTable()); + UIHelper.stopEditing(getUi().getWeightMeasuresTable()); - List<WeightMeasureType> list = service.loadAndDecorateList(WeightMeasureType.class); - UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); - UIHelper.setTableColumnEditor(table, 1, ContentUIInitializer.newFloatColumnEditor(table)); + onBranchlineChanged(null); - WeightMeasuresTableModel tableModel = getModel().getWeightMeasuresTableModel(); - tableModel.installTableKeyListener(getUi().getWeightMeasuresTable()); - tableModel.addPropertyChangeListener(WeightMeasuresTableModel.MODIFIED_PROPERTY, weightTableModelModified); + super.resetEditBean(); - } + onBranchlineChanged(getTableEditBean().getBranchline()); - getTableModel().addPropertyChangeListener(ContentTableModel.CREATE_PROPERTY, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Boolean oldValue = (Boolean) evt.getOldValue(); - Boolean newValue = (Boolean) evt.getNewValue(); - setTableModelCreate(oldValue, newValue); - } - }); } @Override - public void initUI() throws Exception { + protected void doPersist(SetLongline editBean) { - // add a listPredicate to get only species from the correct configured speciesList - ObserveConfig config = getUi().getContextValue(ObserveConfig.class); + List<CatchLongline> catchLonglines = editBean.getCatchLongline(); { - String speciesListId = config.getSpeciesListLonglineCatchId(); - prepareSpeciesList(speciesListId, getUi().getSpeciesCatch(), n("observe.error.speciesList.longline.catch.notFound")); - } + SizeMeasuresTableModel tableModel = getModel().getSizeMeasuresTableModel(); - { - String speciesListId = config.getSpeciesListLonglineDepredatorId(); - prepareSpeciesList(speciesListId, getUi().getPredator(), n("observe.error.speciesList.longline.depredator.notFound")); - } + Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); - CatchLonglineContentTableUIInitializer uiInitializer = new CatchLonglineContentTableUIInitializer(getUi()); - uiInitializer.initUI(ObserveContext.get().getServices()); + for (Integer row : rowsChanged) { - getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_SHOW_INDIVIDUAL_TABS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Boolean newValue = (Boolean) evt.getNewValue(); - showIndividualTabs(newValue); - } - }); + CatchLongline catchLongline = catchLonglines.get(row); + + List<SizeMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); + catchLongline.clearSizeMeasure(); + catchLongline.addAllSizeMeasure(measurements); - getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Boolean newValue = (Boolean) evt.getNewValue(); - setTableModelEditable(newValue); } - }); + } - setTableModelEditable(getModel().isEditable()); + { + WeightMeasuresTableModel tableModel = getModel().getWeightMeasuresTableModel(); - LonglinePositionHelper<CatchLongline> positionHelper = new LonglinePositionHelper<CatchLongline>( - getUi().getSection(), - getUi().getBasket(), - getUi().getBranchline(), - getTableEditBean()); + Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); - POSITION_HELPER_ENTRY.setContextValue(getUi(), positionHelper); + for (Integer row : rowsChanged) { - } + CatchLongline catchLongline = catchLonglines.get(row); - @Override - public void openUI() throws Exception { + List<WeightMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); + catchLongline.clearWeightMeasure(); + catchLongline.addAllWeightMeasure(measurements); - if (log.isInfoEnabled()) { - log.info("OpenUI: " + getModel()); + } } - super.openUI(); - - // Reset all sections - LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); - getUi().getSection().setData(positionHelper.getSectionUniverse()); - - SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); - - // listen messages to see if required to add - reloadTableModelListener(errorTableModel, computeTabValidStateListener); - - computeTabValidState(errorTableModel); + CatchLonglineService service = getService(CatchLonglineService.class); + service.save(editBean); } - @Override - protected void closeSafeUI() { + public void saveBranchline() { if (log.isInfoEnabled()) { - log.info("CloseUI: " + getModel()); + log.info("Saved modified branchline"); } - super.closeSafeUI(); - - // remove listener - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); - - } - - @Override - protected void resetEditBean() { - - UIHelper.stopEditing(getUi().getSizeMeasuresTable()); - UIHelper.stopEditing(getUi().getWeightMeasuresTable()); - onBranchlineChanged(null); + Branchline branchline = getTableEditBean().getBranchline(); - super.resetEditBean(); + CatchLonglineService service = getService(CatchLonglineService.class); - onBranchlineChanged(getTableEditBean().getBranchline()); + Branchline beanSaved = service.saveBranchline(branchline); + getTableEditBean().setBranchline(beanSaved); + getUi().getBranchlineValidator().setChanged(false); } @@ -842,9 +847,4 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } - @Override - protected CatchLonglineTableModel getTableModel() { - return (CatchLonglineTableModel) super.getTableModel(); - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java index 7d335cb..9652fa7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java @@ -62,34 +62,15 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void onOpenUI(ContentMode mode) { - - String activityLonglineId = getDataContext().getSelectedActivityId(); - - EncounterService service = getService(EncounterService.class); - - ActivityLongline loaded = service.loadForEdit(activityLonglineId); - - copy(ActivityLongline.class, BinderService.EDIT_ENCOUNTER, loaded, getBean()); - - } - - @Override - protected void doPersist(ActivityLongline editBean) { + public void initUI() throws Exception { - EncounterService service = getService(EncounterService.class); - service.save(editBean); + // add a listPredicate to get only species from the correct configured speciesList + ObserveConfig config = getUi().getContextValue(ObserveConfig.class); + String speciesListId = config.getSpeciesListLonglineEncounterId(); + prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.longline.encounter.notFound")); - } + super.initUI(); - @Override - protected void onSelectedRowChanged(int editingRow, Encounter bean, boolean create) { - if (getTableModel().isEditable()) { - if (log.isDebugEnabled()) { - log.debug("Row has changed to " + editingRow); - } - getUi().getEncounterType().requestFocus(); - } } @Override @@ -113,14 +94,36 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - public void initUI() throws Exception { + protected void onOpenUI(ContentMode mode) { - // add a listPredicate to get only species from the correct configured speciesList - ObserveConfig config = getUi().getContextValue(ObserveConfig.class); - String speciesListId = config.getSpeciesListLonglineEncounterId(); - prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.longline.encounter.notFound")); + String activityLonglineId = getDataContext().getSelectedActivityId(); - super.initUI(); + EncounterService service = getService(EncounterService.class); + + ActivityLongline loaded = service.loadForEdit(activityLonglineId); + + copy(ActivityLongline.class, BinderService.EDIT_ENCOUNTER, loaded, getBean()); + + } + + @Override + protected void onSelectedRowChanged(int editingRow, Encounter bean, boolean create) { + + if (log.isDebugEnabled()) { + log.debug("Row has changed to " + editingRow); + } + + if (getTableModel().isEditable()) { + getUi().getEncounterType().requestFocus(); + } + + } + + @Override + protected void doPersist(ActivityLongline editBean) { + + EncounterService service = getService(EncounterService.class); + service.save(editBean); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java index 48926bd..bfc9366 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java @@ -62,23 +62,45 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override - protected void onOpenUI(ContentMode mode) { + protected void initTableUI(DefaultTableCellRenderer renderer) { - String setLonglineId = getDataContext().getSelectedSetId(); + JTable table = getUi().getTable(); - FloatlinesCompositionService service = getService(FloatlinesCompositionService.class); + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.floatlinesComposition.table.lineType"), + n("observe.floatlinesComposition.table.lineType.tip"), + n("observe.floatlinesComposition.table.length"), + n("observe.floatlinesComposition.table.length.tip"), + n("observe.floatlinesComposition.table.proportion"), + n("observe.floatlinesComposition.table.proportion.tip")); - SetLongline loaded = service.loadForEdit(setLonglineId); + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, LineType.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, loaded, getBean()); + // when model change in table, let's recompute the proportion sum + table.getModel().addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + + int proportionSum = getBean().getFloatlinesCompositionProportionSum(); + getBean().setFloatlinesCompositionProportionSum(proportionSum); + } + }); } @Override - protected void doPersist(SetLongline editBean) { + protected void onOpenUI(ContentMode mode) { + + String setLonglineId = getDataContext().getSelectedSetId(); FloatlinesCompositionService service = getService(FloatlinesCompositionService.class); - service.save(editBean); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, loaded, getBean()); } @@ -95,32 +117,10 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - - JTable table = getUi().getTable(); - - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.floatlinesComposition.table.lineType"), - n("observe.floatlinesComposition.table.lineType.tip"), - n("observe.floatlinesComposition.table.length"), - n("observe.floatlinesComposition.table.length.tip"), - n("observe.floatlinesComposition.table.proportion"), - n("observe.floatlinesComposition.table.proportion.tip")); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, LineType.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - - // when model change in table, let's recompute the proportion sum - table.getModel().addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { + protected void doPersist(SetLongline editBean) { - int proportionSum = getBean().getFloatlinesCompositionProportionSum(); - getBean().setFloatlinesCompositionProportionSum(proportionSum); - } - }); + FloatlinesCompositionService service = getService(FloatlinesCompositionService.class); + service.save(editBean); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 89cde36..001e0a2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -116,6 +116,115 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override + protected GearUseFeaturesLonglineTableModel getTableModel() { + return (GearUseFeaturesLonglineTableModel) super.getTableModel(); + } + + @Override + public void initUI() throws Exception { + + super.initUI(); + + getModel().addPropertyChangeListener(GearUseFeaturesLonglineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean newValue = (Boolean) evt.getNewValue(); + setTableModelEditable(newValue); + } + }); + + setTableModelEditable(getModel().isEditable()); + + getTableModel().setGearUseFeaturesLonglineUIHandler(this); + + } + + @Override + protected void initTableUI(DefaultTableCellRenderer renderer) { + + { + JTable table = getUi().getTable(); + + UIHelper.setI18nTableHeaderRenderer(table, + n("observe.gearUseFeaturesLongline.table.gear"), + n("observe.gearUseFeaturesLongline.table.gear.tip"), + n("observe.gearUseFeaturesLongline.table.number"), + n("observe.gearUseFeaturesLongline.table.number.tip"), + n("observe.gearUseFeaturesLongline.table.usedInTrip"), + n("observe.gearUseFeaturesLongline.table.usedInTrip.tip"), + n("observe.gearUseFeaturesLongline.table.comment"), + n("observe.gearUseFeaturesLongline.table.comment.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Gear.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newBooleanTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newStringTableCellRenderer(renderer, 10, true)); + } + + { + // init measurements table + JTable table = getUi().getMeasurementsTable(); + + UIHelper.setI18nTableHeaderRenderer(table, + n("observe.gearUseFeaturesLongline.table.gearCaracteristic"), + n("observe.gearUseFeaturesLongline.table.gearCaracteristic.tip"), + n("observe.gearUseFeaturesLongline.table.value"), + n("observe.gearUseFeaturesLongline.table.value.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, GearCaracteristic.class)); + UIHelper.setTableColumnRenderer(table, 1, new GearUseFeatureMeasurementCellRenderer(0, renderer)); + + table.getTableHeader().setReorderingAllowed(false); + + Decorator<GearCaracteristic> decorator = ObserveContext.get().getDecorator(GearCaracteristic.class); + + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); + List<GearCaracteristic> list = service.getList(GearCaracteristic.class); + UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); + UIHelper.setTableColumnEditor(table, 1, new GearUseFeatureMeasurementCellEditor(0)); + + GearUseFeaturesMeasurementLonglinesTableModel tableModel = getModel().getMeasurementsTableModel(); + tableModel.installTableKeyListener(getUi().getMeasurementsTable()); + tableModel.addPropertyChangeListener(GearUseFeaturesMeasurementLonglinesTableModel.MODIFIED_PROPERTY, measurementsTableModelModified); + + ListSelectionModel selectionModel = table.getSelectionModel(); + selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tableModel.installSelectionListener(table); + + new SectionTemplatesAutotSelectRowAndShowPopupAction(getUi(), getUi().getMeasurementsScrollPane(), table, getUi().getMeasurementsTablePopup()); + + } + + // Adapt layout to let more place for the editor + + getUi().getShowForm().remove(1); + getUi().getShowForm().add(SwingUtil.boxComponentWithJxLayer(getUi().getEditor()), new GridBagConstraints(0, 1, 1, 1, 1.0, 0.3, 10, 1, new Insets(0, 0, 0, 0), 0, 0), 1); + getUi().getEditor().remove(0); + getUi().getEditor().add(SwingUtil.boxComponentWithJxLayer(getUi().getEditorPanel()), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 10, 1, new Insets(0, 0, 0, 0), 0, 0), 0); + + + } + + @Override + public void openUI() throws Exception { + + if (log.isInfoEnabled()) { + log.info("OpenUI: " + getModel()); + } + + super.openUI(); + + // To be sure always remove listener (could prevent some leaks) + getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); + // listen messages to see if required to add + getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); + + SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); + computeTabValidState(errorTableModel); + + } + + @Override protected void onOpenUI(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedTripLonglineId(); @@ -132,31 +241,32 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected void doPersist(TripLongline editBean) { + protected ContentMode getContentMode(DataContext dataContext) { - List<GearUseFeaturesLongline> gearUseFeatures = editBean.getGearUseFeaturesLongline(); + // par defaut, on suppose qu'on peut afficher les données + getModel().setShowData(true); - GearUseFeaturesLonglineUIModel model = getModel(); + String selectedTripId = dataContext.getSelectedTripId(); - GearUseFeaturesMeasurementLonglinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); + if (selectedTripId.equals(dataContext.getOpenTripId())) { - Set<Integer> rowsChanged = measurementsTableModel.getCacheRowsChanged(); + // mode mise a jour + return ContentMode.UPDATE; + } - for (Integer row : rowsChanged) { + // mode lecture - GearUseFeaturesLongline gearUseFeaturesLongline = gearUseFeatures.get(row); + if (dataContext.isSelectedTripLongline()) { - List<GearUseFeaturesMeasurementLongline> measurements = measurementsTableModel.getCacheForRowNotEmpty(row); + addInfoMessage(t("observe.tripLongline.message.not.open")); - gearUseFeaturesLongline.clearGearUseFeaturesMeasurement(); + } else { - gearUseFeaturesLongline.addAllGearUseFeaturesMeasurement(measurements); + addInfoMessage(t("observe.tripLongline.message.not.open")); } - GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); - service.save(editBean); - + return ContentMode.READ; } @Override @@ -247,128 +357,61 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - - { - JTable table = getUi().getTable(); - - UIHelper.setI18nTableHeaderRenderer(table, - n("observe.gearUseFeaturesLongline.table.gear"), - n("observe.gearUseFeaturesLongline.table.gear.tip"), - n("observe.gearUseFeaturesLongline.table.number"), - n("observe.gearUseFeaturesLongline.table.number.tip"), - n("observe.gearUseFeaturesLongline.table.usedInTrip"), - n("observe.gearUseFeaturesLongline.table.usedInTrip.tip"), - n("observe.gearUseFeaturesLongline.table.comment"), - n("observe.gearUseFeaturesLongline.table.comment.tip")); + protected void closeSafeUI() { - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Gear.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newBooleanTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newStringTableCellRenderer(renderer, 10, true)); + if (log.isInfoEnabled()) { + log.info("CloseUI: " + getModel()); } + super.closeSafeUI(); - { - // init measurements table - JTable table = getUi().getMeasurementsTable(); - - UIHelper.setI18nTableHeaderRenderer(table, - n("observe.gearUseFeaturesLongline.table.gearCaracteristic"), - n("observe.gearUseFeaturesLongline.table.gearCaracteristic.tip"), - n("observe.gearUseFeaturesLongline.table.value"), - n("observe.gearUseFeaturesLongline.table.value.tip")); - - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, GearCaracteristic.class)); - UIHelper.setTableColumnRenderer(table, 1, new GearUseFeatureMeasurementCellRenderer(0, renderer)); - - table.getTableHeader().setReorderingAllowed(false); - - Decorator<GearCaracteristic> decorator = ObserveContext.get().getDecorator(GearCaracteristic.class); - - GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); - List<GearCaracteristic> list = service.getList(GearCaracteristic.class); - UIHelper.setTableColumnEditor(table, 0, ContentUIInitializer.newDataColumnEditor(list, decorator)); - UIHelper.setTableColumnEditor(table, 1, new GearUseFeatureMeasurementCellEditor(0)); - - GearUseFeaturesMeasurementLonglinesTableModel tableModel = getModel().getMeasurementsTableModel(); - tableModel.installTableKeyListener(getUi().getMeasurementsTable()); - tableModel.addPropertyChangeListener(GearUseFeaturesMeasurementLonglinesTableModel.MODIFIED_PROPERTY, measurementsTableModelModified); - - ListSelectionModel selectionModel = table.getSelectionModel(); - selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - tableModel.installSelectionListener(table); - - new SectionTemplatesAutotSelectRowAndShowPopupAction(getUi(), getUi().getMeasurementsScrollPane(), table, getUi().getMeasurementsTablePopup()); + // remove listener + getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); - } + } - // Adapt layout to let more place for the editor + @Override + public void startEditUI(String... binding) { - getUi().getShowForm().remove(1); - getUi().getShowForm().add(SwingUtil.boxComponentWithJxLayer(getUi().getEditor()), new GridBagConstraints(0, 1, 1, 1, 1.0, 0.3, 10, 1, new Insets(0, 0, 0, 0), 0, 0), 1); - getUi().getEditor().remove(0); - getUi().getEditor().add(SwingUtil.boxComponentWithJxLayer(getUi().getEditorPanel()), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 10, 1, new Insets(0, 0, 0, 0), 0, 0), 0); + getModel().getMeasurementsTableModel().setEditable(true); + super.startEditUI(binding); } @Override - public void initUI() throws Exception { - - super.initUI(); - - getModel().addPropertyChangeListener(GearUseFeaturesLonglineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Boolean newValue = (Boolean) evt.getNewValue(); - setTableModelEditable(newValue); - } - }); + protected void resetEditBean() { - setTableModelEditable(getModel().isEditable()); + UIHelper.stopEditing(getUi().getMeasurementsTable()); - getTableModel().setGearUseFeaturesLonglineUIHandler(this); + super.resetEditBean(); } @Override - public void openUI() throws Exception { - - if (log.isInfoEnabled()) { - log.info("OpenUI: " + getModel()); - } + protected void doPersist(TripLongline editBean) { - super.openUI(); + List<GearUseFeaturesLongline> gearUseFeatures = editBean.getGearUseFeaturesLongline(); - // To be sure always remove listener (could prevent some leaks) - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); - // listen messages to see if required to add - getUi().getErrorTableModel().addTableModelListener(computeTabValidStateListener); + GearUseFeaturesLonglineUIModel model = getModel(); - SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); - computeTabValidState(errorTableModel); + GearUseFeaturesMeasurementLonglinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); - } + Set<Integer> rowsChanged = measurementsTableModel.getCacheRowsChanged(); - @Override - protected void closeSafeUI() { + for (Integer row : rowsChanged) { - if (log.isInfoEnabled()) { - log.info("CloseUI: " + getModel()); - } - super.closeSafeUI(); + GearUseFeaturesLongline gearUseFeaturesLongline = gearUseFeatures.get(row); - // remove listener - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); + List<GearUseFeaturesMeasurementLongline> measurements = measurementsTableModel.getCacheForRowNotEmpty(row); - } + gearUseFeaturesLongline.clearGearUseFeaturesMeasurement(); - @Override - public void startEditUI(String... binding) { + gearUseFeaturesLongline.addAllGearUseFeaturesMeasurement(measurements); - getModel().getMeasurementsTableModel().setEditable(true); + } - super.startEditUI(binding); + GearUseFeaturesLonglineService service = getService(GearUseFeaturesLonglineService.class); + service.save(editBean); } @@ -407,49 +450,6 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } - @Override - protected void resetEditBean() { - - UIHelper.stopEditing(getUi().getMeasurementsTable()); - - super.resetEditBean(); - - } - - @Override - protected ContentMode getContentMode(DataContext dataContext) { - - // par defaut, on suppose qu'on peut afficher les données - getModel().setShowData(true); - - String selectedTripId = dataContext.getSelectedTripId(); - - if (selectedTripId.equals(dataContext.getOpenTripId())) { - - // mode mise a jour - return ContentMode.UPDATE; - } - - // mode lecture - - if (dataContext.isSelectedTripLongline()) { - - addInfoMessage(t("observe.tripLongline.message.not.open")); - - } else { - - addInfoMessage(t("observe.tripLongline.message.not.open")); - - } - - return ContentMode.READ; - } - - @Override - protected GearUseFeaturesLonglineTableModel getTableModel() { - return (GearUseFeaturesLonglineTableModel) super.getTableModel(); - } - protected void setTableModelEditable(Boolean newValue) { getModel().getMeasurementsTableModel().setEditable(newValue); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java index ca49581..d29cfc2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java @@ -63,39 +63,6 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void onOpenUI(ContentMode mode) { - - String setLonglineId = getDataContext().getSelectedSetId(); - - HooksCompositionService service = getService(HooksCompositionService.class); - - SetLongline loaded = service.loadForEdit(setLonglineId); - - copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, loaded, getBean()); - - } - - @Override - protected void doPersist(SetLongline editBean) { - - HooksCompositionService service = getService(HooksCompositionService.class); - service.save(editBean); - - } - - @Override - protected void onSelectedRowChanged(int editingRow, HooksComposition bean, boolean create) { - - if (getTableModel().isEditable()) { - if (log.isDebugEnabled()) { - log.debug("Row has changed to " + editingRow); - } - getUi().getHookType().requestFocus(); - } - - } - - @Override protected void initTableUI(DefaultTableCellRenderer renderer) { JTable table = getUi().getTable(); @@ -128,6 +95,42 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override + protected void onOpenUI(ContentMode mode) { + + String setLonglineId = getDataContext().getSelectedSetId(); + + HooksCompositionService service = getService(HooksCompositionService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, loaded, getBean()); + + } + + @Override + protected void onSelectedRowChanged(int editingRow, HooksComposition bean, boolean create) { + + if (log.isDebugEnabled()) { + log.debug("Row has changed to " + editingRow); + } + + if (getTableModel().isEditable()) { + + getUi().getHookType().requestFocus(); + + } + + } + + @Override + protected void doPersist(SetLongline editBean) { + + HooksCompositionService service = getService(HooksCompositionService.class); + service.save(editBean); + + } + + @Override public void afterSave(boolean refresh) { super.afterSave(refresh); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java index dd46581..a074cf4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java @@ -80,37 +80,6 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void onOpenUI(ContentMode mode) { - - String activityLonglineId = getDataContext().getSelectedActivityId(); - - SensorUsedService service = getService(SensorUsedService.class); - - ActivityLongline loaded = service.loadForEdit(activityLonglineId); - - copy(ActivityLongline.class, BinderService.EDIT_SENSOR_USED, loaded, getBean()); - - } - - @Override - protected void doPersist(ActivityLongline editBean) { - - SensorUsedService service = getService(SensorUsedService.class); - service.save(editBean); - - } - - @Override - protected void onSelectedRowChanged(int editingRow, SensorUsed bean, boolean create) { - if (getTableModel().isEditable()) { - if (log.isDebugEnabled()) { - log.debug("Row has changed to " + editingRow); - } - getUi().getSensorType().requestFocus(); - } - } - - @Override protected void initTableUI(DefaultTableCellRenderer renderer) { JTable table = getUi().getTable(); @@ -141,6 +110,37 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, UIHelper.setTableColumnRenderer(table, 5, UIHelper.newStringTableCellRenderer(renderer, 10, true)); } + @Override + protected void onOpenUI(ContentMode mode) { + + String activityLonglineId = getDataContext().getSelectedActivityId(); + + SensorUsedService service = getService(SensorUsedService.class); + + ActivityLongline loaded = service.loadForEdit(activityLonglineId); + + copy(ActivityLongline.class, BinderService.EDIT_SENSOR_USED, loaded, getBean()); + + } + + @Override + protected void onSelectedRowChanged(int editingRow, SensorUsed bean, boolean create) { + if (getTableModel().isEditable()) { + if (log.isDebugEnabled()) { + log.debug("Row has changed to " + editingRow); + } + getUi().getSensorType().requestFocus(); + } + } + + @Override + protected void doPersist(ActivityLongline editBean) { + + SensorUsedService service = getService(SensorUsedService.class); + service.save(editBean); + + } + public void importData() { File file = UIHelper.chooseFile((Component) ui, diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java index ac05514..016e344 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java @@ -121,80 +121,27 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override - protected void onOpenUI(ContentMode mode) { - - String setLonglineId = getDataContext().getSelectedSetId(); - - TdrService service = getService(TdrService.class); - - SetLongline loaded = service.loadForEdit(setLonglineId); - - copy(SetLongline.class, BinderService.EDIT_TDR, loaded, getBean()); - - // load sections (and baskets and branchlines) - SetLonglineService setLonglineService = getService(SetLonglineService.class); - List<Section> sections = setLonglineService.getSections(setLonglineId); - - LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); - positionHelper.initSections(sections, getTableModel().getData()); - - } - - @Override - protected void doPersist(SetLongline editBean) { - - TdrService service = getService(TdrService.class); - service.save(editBean); - - } - - @Override - protected void onSelectedRowChanged(int editingRow, Tdr bean, boolean create) { - - ContentTableModel<SetLongline, Tdr> model = getTableModel(); - - TdrUI ui = getUi(); - - boolean withTimestamp = bean.getFishingStart() != null; - ui.getEnableTimestamp().setSelected(withTimestamp); - - if (!model.isEditable()) { - return; - } - - String homeId = bean.getHomeId(); - - if (log.isDebugEnabled()) { - log.debug("selected tdr " + homeId); - } - JComponent requestFocus = ui.getHomeId(); - - if (create) { - - // set date - time - - SetLongline setLongline = getBean(); - - Date settingStartTimeStamp = setLongline.getSettingStartTimeStamp(); - setTimestamp(bean, settingStartTimeStamp); - - // go back to first tab - ui.getEditTabPane().setSelectedIndex(0); - - // enable timestamps - ui.getEnableTimestamp().setSelected(true); + public void initUI() throws Exception { - } else if (!withTimestamp) { + // add a listPredicate to get only species from the correct configured speciesList + ObserveConfig config = getUi().getContextValue(ObserveConfig.class); + String speciesListId = config.getSpeciesListLonglineCatchId(); + prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.longline.catch.notFound")); - // clean timestamps - setTimestamp(bean, null); + super.initUI(); - } + LonglinePositionHelper<Tdr> positionHelper = new LonglinePositionHelper<Tdr>( + getUi().getSection(), + getUi().getBasket(), + getUi().getBranchline(), + getTableEditBean()); - LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(ui); - positionHelper.resetPosition(bean); + POSITION_HELPER_ENTRY.setContextValue(getUi(), positionHelper); - requestFocus.requestFocus(); + getUi().getDeployementStart().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); + getUi().getDeployementEnd().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); + getUi().getFishingStart().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); + getUi().getFishingEnd().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); } @@ -226,31 +173,6 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override - public void initUI() throws Exception { - - // add a listPredicate to get only species from the correct configured speciesList - ObserveConfig config = getUi().getContextValue(ObserveConfig.class); - String speciesListId = config.getSpeciesListLonglineCatchId(); - prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.longline.catch.notFound")); - - super.initUI(); - - LonglinePositionHelper<Tdr> positionHelper = new LonglinePositionHelper<Tdr>( - getUi().getSection(), - getUi().getBasket(), - getUi().getBranchline(), - getTableEditBean()); - - POSITION_HELPER_ENTRY.setContextValue(getUi(), positionHelper); - - getUi().getDeployementStart().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); - getUi().getDeployementEnd().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); - getUi().getFishingStart().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); - getUi().getFishingEnd().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); - - } - - @Override public void openUI() throws Exception { if (log.isInfoEnabled()) { @@ -272,6 +194,76 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override + protected void onOpenUI(ContentMode mode) { + + String setLonglineId = getDataContext().getSelectedSetId(); + + TdrService service = getService(TdrService.class); + + SetLongline loaded = service.loadForEdit(setLonglineId); + + copy(SetLongline.class, BinderService.EDIT_TDR, loaded, getBean()); + + // load sections (and baskets and branchlines) + SetLonglineService setLonglineService = getService(SetLonglineService.class); + List<Section> sections = setLonglineService.getSections(setLonglineId); + + LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); + positionHelper.initSections(sections, getTableModel().getData()); + + } + + @Override + protected void onSelectedRowChanged(int editingRow, Tdr bean, boolean create) { + + ContentTableModel<SetLongline, Tdr> model = getTableModel(); + + TdrUI ui = getUi(); + + boolean withTimestamp = bean.getFishingStart() != null; + ui.getEnableTimestamp().setSelected(withTimestamp); + + if (model.isEditable()) { + + String homeId = bean.getHomeId(); + + if (log.isDebugEnabled()) { + log.debug("selected tdr " + homeId); + } + JComponent requestFocus = ui.getHomeId(); + + if (create) { + + // set date - time + + SetLongline setLongline = getBean(); + + Date settingStartTimeStamp = setLongline.getSettingStartTimeStamp(); + setTimestamp(bean, settingStartTimeStamp); + + // go back to first tab + ui.getEditTabPane().setSelectedIndex(0); + + // enable timestamps + ui.getEnableTimestamp().setSelected(true); + + } else if (!withTimestamp) { + + // clean timestamps + setTimestamp(bean, null); + + } + + LonglinePositionHelper<Tdr> positionHelper = POSITION_HELPER_ENTRY.getContextValue(ui); + positionHelper.resetPosition(bean); + + requestFocus.requestFocus(); + + } + + } + + @Override protected void closeSafeUI() { if (log.isInfoEnabled()) { log.info("CloseUI: " + getModel()); @@ -284,6 +276,14 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override + protected void doPersist(SetLongline editBean) { + + TdrService service = getService(TdrService.class); + service.save(editBean); + + } + + @Override protected void resetEditBean() { super.resetEditBean(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index ad6c5b1..1bb029c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -114,88 +114,26 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected void onSelectedRowChanged(int editingRow, GearUseFeaturesSeine bean, boolean create) { - - if (log.isInfoEnabled()) { - log.info("Selected row changed: " + editingRow + ", create? " + create); - } - - GearUseFeaturesSeineUI ui = getUi(); - - UIHelper.stopEditing(ui.getMeasurementsTable()); - - GearUseFeaturesSeineTableModel tableModel = getTableModel(); - GearUseFeaturesSeineUIModel model = getModel(); - - boolean emptySelection = editingRow == -1; - - // load size measures - - GearUseFeaturesMeasurementSeinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); - List<GearUseFeaturesMeasurementSeine> measurements = emptySelection ? Collections.<GearUseFeaturesMeasurementSeine>emptyList() : measurementsTableModel.getCacheForRow(editingRow); - if (measurements == null) { - - if (log.isInfoEnabled()) { - log.info("init measurements for row " + editingRow); - } - - // first time coming on this row - - if (tableModel.isCreate()) { - - // create mode: just init with empty list - measurements = Collections.emptyList(); - - if (log.isInfoEnabled()) { - log.info("create mode, use an empty list"); - } - - } else { - - // updating mode: loading from db - GearUseFeaturesSeineService service = getService(GearUseFeaturesSeineService.class); - measurements = service.loadGearUseFeaturesMeasurementSeineForEdit(bean.getTopiaId()); - if (log.isInfoEnabled()) { - log.info("Loaded measurements (" + bean.getTopiaId() + "): " + measurements.size()); - } - - } + protected GearUseFeaturesSeineTableModel getTableModel() { + return (GearUseFeaturesSeineTableModel) super.getTableModel(); + } - // init measurements - measurementsTableModel.initCacheForRow(editingRow, measurements); + @Override + public void initUI() throws Exception { - } else { + super.initUI(); - if (log.isInfoEnabled()) { - log.info("Using existing measurements for row " + editingRow + " : " + measurements.size()); + getModel().addPropertyChangeListener(GearUseFeaturesSeineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean newValue = (Boolean) evt.getNewValue(); + setTableModelEditable(newValue); } - } - - measurementsTableModel.setData(measurements); - - measurementsTableModel.setModified(false); - measurementsTableModel.setEditable(tableModel.isEditable()); - - if (!tableModel.isEditable()) { - return; - } - - JComponent requestFocus; - - if (tableModel.isCreate()) { - - // go back to first pane - ui.getGearUseFeaturesTabPane().setSelectedIndex(0); - - requestFocus = ui.getGear(); - - } else { - - requestFocus = ui.getGear(); + }); - } + setTableModelEditable(getModel().isEditable()); - requestFocus.requestFocus(); + getTableModel().setGearUseFeaturesSeineUIHandler(this); } @@ -266,25 +204,6 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - public void initUI() throws Exception { - - super.initUI(); - - getModel().addPropertyChangeListener(GearUseFeaturesSeineUIModel.PROPERTY_EDITABLE, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - Boolean newValue = (Boolean) evt.getNewValue(); - setTableModelEditable(newValue); - } - }); - - setTableModelEditable(getModel().isEditable()); - - getTableModel().setGearUseFeaturesSeineUIHandler(this); - - } - - @Override public void openUI() throws Exception { if (log.isInfoEnabled()) { @@ -297,7 +216,7 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei // listen messages to see to compute tab valid states reloadTableModelListener(errorTableModel, computeTabValidStateListener); - + computeTabValidState(errorTableModel); } @@ -317,62 +236,148 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected void closeSafeUI() { + protected ContentMode getContentMode(DataContext dataContext) { - if (log.isInfoEnabled()) { - log.info("CloseUI: " + getModel()); + // par defaut, on suppose qu'on peut afficher les données + getModel().setShowData(true); + + String selectedTripId = dataContext.getSelectedTripId(); + + if (selectedTripId.equals(dataContext.getOpenTripId())) { + + // mode mise a jour + return ContentMode.UPDATE; } - super.closeSafeUI(); - // remove listener - getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); + // mode lecture - } + if (dataContext.isSelectedTripLongline()) { - @Override - public void startEditUI(String... binding) { + addInfoMessage(t("observe.tripLongline.message.not.open")); - getModel().getMeasurementsTableModel().setEditable(true); + } else { - super.startEditUI(binding); + addInfoMessage(t("observe.tripSeine.message.not.open")); + + } + return ContentMode.READ; } - public void deleteSelectedMeasurement() { + @Override + protected void onSelectedRowChanged(int editingRow, GearUseFeaturesSeine bean, boolean create) { - GearUseFeaturesMeasurementSeinesTableModel tableModel = getUi().getMeasurementsTableModel(); + if (log.isInfoEnabled()) { + log.info("Selected row changed: " + editingRow + ", create? " + create); + } - boolean selectionEmpty = tableModel.isSelectionEmpty(); + GearUseFeaturesSeineUI ui = getUi(); - if (!selectionEmpty) { + UIHelper.stopEditing(ui.getMeasurementsTable()); - GearUseFeaturesMeasurementSeine data = tableModel.getSelectedRow(); + GearUseFeaturesSeineTableModel tableModel = getTableModel(); + GearUseFeaturesSeineUIModel model = getModel(); + + boolean emptySelection = editingRow == -1; + + // load size measures + + GearUseFeaturesMeasurementSeinesTableModel measurementsTableModel = model.getMeasurementsTableModel(); + List<GearUseFeaturesMeasurementSeine> measurements = emptySelection ? Collections.<GearUseFeaturesMeasurementSeine>emptyList() : measurementsTableModel.getCacheForRow(editingRow); + if (measurements == null) { if (log.isInfoEnabled()) { - log.info("Delete: " + data); + log.info("init measurements for row " + editingRow); } - ObserveMainUI mainUI = ObserveContext.get().getObserveMainUI(); - int response = UIHelper.askUser(mainUI, - t("observe.title.delete"), - t("observe.measurement.delete.message"), - JOptionPane.WARNING_MESSAGE, - new Object[]{t("observe.choice.confirm.delete"), - t("observe.choice.cancel")}, - 1); + // first time coming on this row - if (response != 0) { + if (tableModel.isCreate()) { + + // create mode: just init with empty list + measurements = Collections.emptyList(); + + if (log.isInfoEnabled()) { + log.info("create mode, use an empty list"); + } + + } else { + + // updating mode: loading from db + GearUseFeaturesSeineService service = getService(GearUseFeaturesSeineService.class); + measurements = service.loadGearUseFeaturesMeasurementSeineForEdit(bean.getTopiaId()); + if (log.isInfoEnabled()) { + log.info("Loaded measurements (" + bean.getTopiaId() + "): " + measurements.size()); + } - // user cancel - return; } - tableModel.removeSelectedRow(); + // init measurements + measurementsTableModel.initCacheForRow(editingRow, measurements); + + } else { + + if (log.isInfoEnabled()) { + log.info("Using existing measurements for row " + editingRow + " : " + measurements.size()); + } + } + + measurementsTableModel.setData(measurements); + + measurementsTableModel.setModified(false); + measurementsTableModel.setEditable(tableModel.isEditable()); + + if (!tableModel.isEditable()) { + return; + } + + JComponent requestFocus; + + if (tableModel.isCreate()) { + + // go back to first pane + ui.getGearUseFeaturesTabPane().setSelectedIndex(0); + + requestFocus = ui.getGear(); + + } else { + + requestFocus = ui.getGear(); + + } + + requestFocus.requestFocus(); + } + + @Override + protected void closeSafeUI() { + + if (log.isInfoEnabled()) { + log.info("CloseUI: " + getModel()); } + super.closeSafeUI(); + + // remove listener + getUi().getErrorTableModel().removeTableModelListener(computeTabValidStateListener); + + } + + @Override + public void startEditUI(String... binding) { + + getModel().getMeasurementsTableModel().setEditable(true); + super.startEditUI(binding); } + @Override + protected void resetEditBean() { + + UIHelper.stopEditing(getUi().getMeasurementsTable()); + super.resetEditBean(); + + } @Override protected void doPersist(TripSeine editBean) { @@ -401,47 +406,39 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } - @Override - protected void resetEditBean() { - - UIHelper.stopEditing(getUi().getMeasurementsTable()); - - super.resetEditBean(); - - } - - @Override - protected ContentMode getContentMode(DataContext dataContext) { + public void deleteSelectedMeasurement() { - // par defaut, on suppose qu'on peut afficher les données - getModel().setShowData(true); + GearUseFeaturesMeasurementSeinesTableModel tableModel = getUi().getMeasurementsTableModel(); - String selectedTripId = dataContext.getSelectedTripId(); + boolean selectionEmpty = tableModel.isSelectionEmpty(); - if (selectedTripId.equals(dataContext.getOpenTripId())) { + if (!selectionEmpty) { - // mode mise a jour - return ContentMode.UPDATE; - } + GearUseFeaturesMeasurementSeine data = tableModel.getSelectedRow(); - // mode lecture + if (log.isInfoEnabled()) { + log.info("Delete: " + data); + } - if (dataContext.isSelectedTripLongline()) { + ObserveMainUI mainUI = ObserveContext.get().getObserveMainUI(); + int response = UIHelper.askUser(mainUI, + t("observe.title.delete"), + t("observe.measurement.delete.message"), + JOptionPane.WARNING_MESSAGE, + new Object[]{t("observe.choice.confirm.delete"), + t("observe.choice.cancel")}, + 1); - addInfoMessage(t("observe.tripLongline.message.not.open")); + if (response != 0) { - } else { + // user cancel + return; + } - addInfoMessage(t("observe.tripSeine.message.not.open")); + tableModel.removeSelectedRow(); } - return ContentMode.READ; - } - - @Override - protected GearUseFeaturesSeineTableModel getTableModel() { - return (GearUseFeaturesSeineTableModel) super.getTableModel(); } protected void setTableModelEditable(Boolean newValue) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 482db1f..9ed6a04 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -43,6 +43,7 @@ import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; @@ -74,7 +75,7 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non /** * L'entrée dans le contexte pour récupérer la liste complete des espèces. */ - protected final JAXXContextEntryDef<List<Species>> ALL_ESPECES_ENTRY = + protected final JAXXContextEntryDef<List<Species>> ALL_SPECIES_ENTRY = UIHelper.newListContextEntryDef("NonTargetCatchUI-all-speciess"); /** @@ -219,7 +220,7 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non speciesList = new ArrayList<Species>(); } - ALL_ESPECES_ENTRY.setContextValue(getUi(), speciesList); + ALL_SPECIES_ENTRY.setContextValue(getUi(), speciesList); if (log.isDebugEnabled()) { log.debug("speciesList = " + speciesList.size()); } @@ -235,40 +236,38 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non @Override protected void onSelectedRowChanged(int editingRow, NonTargetCatch bean, boolean create) { - NonTargetCatchUI ui = getUi(); - ContentTableModel<SetSeine, NonTargetCatch> model = getTableModel(); if (!model.isEditable()) { - // rien a faire - return; - } + List<Species> availableSpecies; + JComponent requestFocus; - List<Species> availableSpecies; - JComponent requestFocus; + BeanComboBox<Species> speciesComboBox = getUi().getSpecies(); - if (create) { + if (create) { - availableSpecies = new ArrayList<Species>(ALL_ESPECES_ENTRY.getContextValue(ui)); - requestFocus = ui.getSpecies(); + availableSpecies = new ArrayList<Species>(ALL_SPECIES_ENTRY.getContextValue(ui)); + requestFocus = speciesComboBox; - } else { + } else { - Species species = bean.getSpecies(); - availableSpecies = Collections.singletonList(species); - requestFocus = ui.getTable(); + Species species = bean.getSpecies(); + availableSpecies = Collections.singletonList(species); + requestFocus = getUi().getTable(); - } + } + + speciesComboBox.setData(availableSpecies); + requestFocus.requestFocus(); - ui.getSpecies().setData(availableSpecies); - requestFocus.requestFocus(); + NonTargetCatch tableEditBean = getTableEditBean(); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_TOTAL_COUNT, totalCountChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_CATCH_WEIGHT, catchWeightChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_MEAN_WEIGHT, meanWeightChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_MEAN_LENGTH, meanLengthChanged); - NonTargetCatch tableEditBean = getTableEditBean(); - reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_TOTAL_COUNT, totalCountChanged); - reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_CATCH_WEIGHT, catchWeightChanged); - reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_MEAN_WEIGHT, meanWeightChanged); - reloadPropertyChangeListener(tableEditBean, NonTargetCatch.PROPERTY_MEAN_LENGTH, meanLengthChanged); + } } @@ -339,12 +338,12 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non @Override protected void doPersist(SetSeine editBean) { - List<NonTargetLength> tailleToDelete = ALL_NON_TARGET_LENGTH_TO_DELETE_ENTRY.getContextValue(getUi()); + List<NonTargetLength> lengthsToDelete = ALL_NON_TARGET_LENGTH_TO_DELETE_ENTRY.getContextValue(getUi()); try { NonTargetCatchService service = getService(NonTargetCatchService.class); - service.save(editBean, tailleToDelete); + service.save(editBean, lengthsToDelete); } finally { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index 58f949c..5d15a06 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -24,19 +24,21 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.Sex; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.data.seine.NonTargetLengthService; import fr.ird.observe.services.data.seine.NonTargetSampleService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.JAXXButtonGroup; import jaxx.runtime.swing.editor.NumberEditor; +import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.NuitonValidatorScope; @@ -141,58 +143,43 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam String setId = getDataContext().getSelectedSetId(); - NonTargetSample nonTargetSample = getService(NonTargetLengthService.class).loadForEdit(setId); + NonTargetSampleService service = getService(NonTargetSampleService.class); + NonTargetSample nonTargetSample = service.loadForEdit(setId); copy(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, nonTargetSample, getBean()); - List<Species> speciesList; - if (ContentMode.UPDATE == mode) { - NonTargetSampleService service = getService(NonTargetSampleService.class); - speciesList = service.getAvailableSpeciesForNonTargetSample(setId); - + List<Species> speciesList = service.getAvailableSpeciesForNonTargetSample(setId); ALL_SPECIES_ENTRY.setContextValue(getUi(), speciesList); + } } @Override - protected void doPersist(NonTargetSample editBean) { + protected ContentMode getContentMode(DataContext dataContext) { - String setId = getDataContext().getSelectedSetId(); + ContentMode mode = super.getContentMode(dataContext); + String setId = getDataContext().getSelectedSetId(); NonTargetSampleService service = getService(NonTargetSampleService.class); + boolean showData = service.canUseNonTargetSample(setId); - if (editBean.getTopiaId() != null && editBean.isNonTargetLengthEmpty()) { - - // remove orphan target sample - if (log.isInfoEnabled()) { - log.info("Remove obsolete nonTargetSample " + editBean.getTopiaId() + " from Set: " + setId); - } - - //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) - service.delete(setId, editBean); + getUi().getModel().setShowData(showData); - } else { + if (ContentMode.UPDATE == mode && !showData) { - //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) - String savedId = service.save(setId, editBean); - editBean.setTopiaId(savedId); + // on repasse en mode resteint car on ne peut pas éditer l'écran + mode = ContentMode.READ; - getService(NonTargetLengthService.class).save(editBean); + addMessage(getUi(), + NuitonValidatorScope.INFO, + getEntityLabel(SetSeine.class), + t("observe.setSeine.message.no.nonTargetDiscarded")); } - } - - public void resetWeightSource() { - getTableEditBean().setWeightSource(false); - getUi().getWeight().grabFocus(); - } - - public void resetLengthSource() { - getTableEditBean().setLengthSource(false); - getUi().getLength().grabFocus(); + return mode; } @Override @@ -200,78 +187,90 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam ContentTableModel<NonTargetSample, NonTargetLength> model = getTableModel(); - if (!model.isEditable()) { - return; - } + if (model.isEditable()) { - Species species = bean.getSpecies(); - NonTargetSampleUI ui = getUi(); - if (log.isDebugEnabled()) { - log.debug("selected species " + species); - } - List<Species> availableEspeces; - JComponent requestFocus; + Species species = bean.getSpecies(); + if (log.isDebugEnabled()) { + log.debug("selected species " + species); + } - if (create) { + NonTargetSampleUI ui = getUi(); - if (model.isCreate()) { + JAXXButtonGroup acquisitionModeGroup = ui.getAcquisitionModeGroup(); + BeanComboBox<Species> speciesComboBox = ui.getSpecies(); - // on passe le mode de saisie en count - ui.getAcquisitionModeGroup().setSelectedValue(null); - ui.getAcquisitionModeGroup().setSelectedValue(ModeSaisieEchantillonEnum.byEffectif); - } + List<Species> availableSpecies; + JComponent requestFocus; - availableEspeces = new ArrayList<Species>(ALL_SPECIES_ENTRY.getContextValue(ui)); - requestFocus = ui.getSpecies(); + if (create) { - } else { + if (model.isCreate()) { - // on passe le mode de saisie - int acquisitionMode = bean.getAcquisitionMode(); - ModeSaisieEchantillonEnum enumValue = - ModeSaisieEchantillonEnum.valueOf(acquisitionMode); - ui.getAcquisitionModeGroup().setSelectedValue(null); - ui.getAcquisitionModeGroup().setSelectedValue(enumValue); + // on passe le mode de saisie en count + acquisitionModeGroup.setSelectedValue(null); + acquisitionModeGroup.setSelectedValue(ModeSaisieEchantillonEnum.byEffectif); + } - availableEspeces = Collections.singletonList(species); - requestFocus = ui.getCount(); + availableSpecies = new ArrayList<Species>(ALL_SPECIES_ENTRY.getContextValue(ui)); + requestFocus = speciesComboBox; - } + } else { + + // on passe le mode de saisie + int acquisitionMode = bean.getAcquisitionMode(); + ModeSaisieEchantillonEnum enumValue = ModeSaisieEchantillonEnum.valueOf(acquisitionMode); - ui.getSpecies().setData(availableEspeces); - requestFocus.requestFocus(); + acquisitionModeGroup.setSelectedValue(null); + acquisitionModeGroup.setSelectedValue(enumValue); + + availableSpecies = Collections.singletonList(species); + requestFocus = ui.getCount(); + + } - NonTargetLength tableEditBean = getTableEditBean(); - tableEditBean.removePropertyChangeListener(NonTargetLength.PROPERTY_WEIGHT, weightChanged); - tableEditBean.addPropertyChangeListener(NonTargetLength.PROPERTY_WEIGHT, weightChanged); + speciesComboBox.setData(availableSpecies); + requestFocus.requestFocus(); - tableEditBean.removePropertyChangeListener(NonTargetLength.PROPERTY_LENGTH, lengthChanged); - tableEditBean.addPropertyChangeListener(NonTargetLength.PROPERTY_LENGTH, lengthChanged); + NonTargetLength tableEditBean = getTableEditBean(); + reloadPropertyChangeListener(tableEditBean, NonTargetLength.PROPERTY_WEIGHT, weightChanged); + reloadPropertyChangeListener(tableEditBean, NonTargetLength.PROPERTY_LENGTH, lengthChanged); + + } } @Override - protected ContentMode getContentMode(DataContext dataContext) { - - ContentMode mode = super.getContentMode(dataContext); + protected void doPersist(NonTargetSample editBean) { String setId = getDataContext().getSelectedSetId(); + NonTargetSampleService service = getService(NonTargetSampleService.class); - boolean showData = service.canUseNonTargetSample(setId); - getUi().getModel().setShowData(showData); + if (!Entities.isNew(editBean) && editBean.isNonTargetLengthEmpty()) { - if (mode == ContentMode.UPDATE && !showData) { + // remove orphan target sample + if (log.isInfoEnabled()) { + log.info("Remove obsolete nonTargetSample " + editBean.getTopiaId() + " from Set: " + setId); + } - // on repasse en mode resteint car on ne peut pas éditer l'écran - mode = ContentMode.READ; + service.delete(setId, editBean); + + } else { + + String savedId = service.save(setId, editBean); + editBean.setTopiaId(savedId); - addMessage(getUi(), - NuitonValidatorScope.INFO, - getEntityLabel(SetSeine.class), - t("observe.setSeine.message.no.nonTargetDiscarded")); } - return mode; + } + + public void resetWeightSource() { + getTableEditBean().setWeightSource(false); + getUi().getWeight().grabFocus(); + } + + public void resetLengthSource() { + getTableEditBean().setLengthSource(false); + getUi().getLength().grabFocus(); } /** @@ -313,6 +312,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam editBean.setWeight(null); // on supprime aussi l'count (pour forcer la saisie) editBean.setCount(null); + } break; @@ -328,6 +328,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam // on positionne l'count à 1 (seule valeur possible) editBean.setCount(1); + } break; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index b1369e3..cf5fe8f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -59,30 +59,20 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati } @Override - protected void onOpenUI(ContentMode mode) { - - String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); - - ObjectObservedSpeciesService service = getService(ObjectObservedSpeciesService.class); - - FloatingObject loaded = service.loadForEdit(floatingObjectId); + public void initUI() throws Exception { - copy(FloatingObject.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES, loaded, getBean()); + // add a listPredicate to get only species from the correct configured speciesList + ObserveConfig config = getUi().getContextValue(ObserveConfig.class); + String speciesListId = config.getSpeciesListSeineObjectObservedSpeciesId(); + prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.seine.objectObservedSpecies.notFound")); - } + super.initUI(); - @Override - protected void onSelectedRowChanged(int editingRow, ObjectObservedSpecies bean, boolean create) { - if (log.isDebugEnabled()) { - log.debug("Row has changed to " + editingRow); - } - if (getTableModel().isEditable()) { - getUi().getSpecies().requestFocus(); - } } @Override protected void initTableUI(DefaultTableCellRenderer renderer) { + JTable table = getUi().getTable(); UIHelper.setI18nTableHeaderRenderer(table, @@ -96,17 +86,31 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); UIHelper.setTableColumnRenderer(table, 1, UIHelper.newDecorateTableCellRenderer(renderer, SpeciesStatus.class)); UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + } @Override - public void initUI() throws Exception { + protected void onOpenUI(ContentMode mode) { - // add a listPredicate to get only species from the correct configured speciesList - ObserveConfig config = getUi().getContextValue(ObserveConfig.class); - String speciesListId = config.getSpeciesListSeineObjectObservedSpeciesId(); - prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.seine.objectObservedSpecies.notFound")); + String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); - super.initUI(); + ObjectObservedSpeciesService service = getService(ObjectObservedSpeciesService.class); + + FloatingObject loaded = service.loadForEdit(floatingObjectId); + + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES, loaded, getBean()); + + } + + @Override + protected void onSelectedRowChanged(int editingRow, ObjectObservedSpecies bean, boolean create) { + + if (log.isDebugEnabled()) { + log.debug("Row has changed to " + editingRow); + } + if (getTableModel().isEditable()) { + getUi().getSpecies().requestFocus(); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java index 8c6b3b8..63d2f59 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java @@ -57,32 +57,21 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin return (ObjectSchoolEstimateUI) super.getUi(); } - @Override - protected void onOpenUI(ContentMode mode) { - - String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); - - ObjectSchoolEstimateService service = getService(ObjectSchoolEstimateService.class); - - FloatingObject loaded = service.loadForEdit(floatingObjectId); + public void initUI() throws Exception { - copy(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE, loaded, getBean()); + // add a listPredicate to get only species from the correct configured speciesList + ObserveConfig config = getUi().getContextValue(ObserveConfig.class); + String speciesListId = config.getSpeciesListSeineObjectSchoolEstimateId(); + prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.seine.objectSchoolEstimate.notFound")); - } + super.initUI(); - @Override - protected void onSelectedRowChanged(int editingRow, ObjectSchoolEstimate bean, boolean create) { - if (getTableModel().isEditable()) { - if (log.isDebugEnabled()) { - log.debug("Row has changed to " + editingRow); - } - getUi().getSpecies().requestFocus(); - } } @Override protected void initTableUI(DefaultTableCellRenderer renderer) { + JTable table = getUi().getTable(); UIHelper.setI18nTableHeaderRenderer(table, @@ -93,17 +82,31 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + } @Override - public void initUI() throws Exception { + protected void onOpenUI(ContentMode mode) { - // add a listPredicate to get only species from the correct configured speciesList - ObserveConfig config = getUi().getContextValue(ObserveConfig.class); - String speciesListId = config.getSpeciesListSeineObjectSchoolEstimateId(); - prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.seine.objectSchoolEstimate.notFound")); + String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); - super.initUI(); + ObjectSchoolEstimateService service = getService(ObjectSchoolEstimateService.class); + + FloatingObject loaded = service.loadForEdit(floatingObjectId); + + copy(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE, loaded, getBean()); + + } + + @Override + protected void onSelectedRowChanged(int editingRow, ObjectSchoolEstimate bean, boolean create) { + + if (log.isDebugEnabled()) { + log.debug("Row has changed to " + editingRow); + } + if (getTableModel().isEditable()) { + getUi().getSpecies().requestFocus(); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index 663544d..ec76626 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -38,6 +38,7 @@ import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,7 +46,7 @@ import javax.swing.JComponent; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -72,6 +73,26 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } @Override + protected void initTableUI(DefaultTableCellRenderer renderer) { + + JTable table = getUi().getTable(); + + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.schoolEstimate.table.speciesThon"), + n("observe.schoolEstimate.table.speciesThon.tip"), + n("observe.schoolEstimate.table.weight"), + n("observe.schoolEstimate.table.weight.tip"), + n("observe.schoolEstimate.table.meanWeight"), + n("observe.schoolEstimate.table.meanWeight.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + + } + + @Override protected void onOpenUI(ContentMode mode) { String setSeineId = getDataContext().getSelectedSetId(); @@ -118,55 +139,43 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch ContentTableModel<SetSeine, SchoolEstimate> model = getTableModel(); - if (!model.isEditable()) { + if (model.isEditable()) { - // rien a faire - return; - } + BeanComboBox<Species> speciesComboBox = getUi().getSpecies(); - SchoolEstimateUI ui = getUi(); - List<Species> availableEspeces; - JComponent requestFocus; + List<Species> availableSpecies; + JComponent requestFocus; - if (create) { - availableEspeces = new ArrayList<Species>( - ALL_SPECIES_ENTRY.getContextValue(ui)); + if (create) { - List<Species> list = model.getColumnValues(0); - availableEspeces.removeAll(list); - list.clear(); + availableSpecies = new ArrayList<Species>(ALL_SPECIES_ENTRY.getContextValue(ui)); - requestFocus = ui.getSpecies(); - } else { - Species species = bean.getSpecies(); - availableEspeces = Arrays.asList(species); - requestFocus = ui.getTotalWeight(); - } - ui.getSpecies().setData(availableEspeces); - requestFocus.requestFocus(); - } + List<Species> list = model.getColumnValues(0); + availableSpecies.removeAll(list); + list.clear(); + requestFocus = speciesComboBox; - @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { - JTable table = getUi().getTable(); + } else { - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.schoolEstimate.table.speciesThon"), - n("observe.schoolEstimate.table.speciesThon.tip"), - n("observe.schoolEstimate.table.weight"), - n("observe.schoolEstimate.table.weight.tip"), - n("observe.schoolEstimate.table.meanWeight"), - n("observe.schoolEstimate.table.meanWeight.tip")); + Species species = bean.getSpecies(); + availableSpecies= Collections.singletonList(species); + requestFocus = getUi().getTotalWeight(); + + } + + speciesComboBox.setData(availableSpecies); + requestFocus.requestFocus(); + + } - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); } @Override protected void doPersist(SetSeine editBean) { - getService(SchoolEstimateService.class).save(editBean); + + SchoolEstimateService service = getService(SchoolEstimateService.class); + service.save(editBean); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java index 39a8e98..9e89625 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java @@ -211,6 +211,54 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } @Override + protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { + + TargetCatchUI ui = getUi(); + + WeightCategory weightCategory = bean.getWeightCategory(); + Species species = weightCategory == null ? null : weightCategory.getSpecies(); + + BeanComboBox<Species> speciesComboBox = ui.getSpecies(); + BeanComboBox<WeightCategory> weightCategoryComboBox = ui.getWeightCategory(); + + JComponent requestFocus; + if (create) { + + // on reinitilise toujours l'espèce (pour reinitialiser la liste des categories) + speciesComboBox.setSelectedItem(null); + + if (!getTableModel().isCreate()) { + // on repositionne l'espèce (cela reconstruira la liste des categories) + speciesComboBox.setSelectedItem(species); + // on repositionne la categorie + weightCategoryComboBox.setSelectedItem(weightCategory); + } + + requestFocus = speciesComboBox; + + } else { + + // en mode mise a jour, on restreint la liste des categories + // au singleton de sa valeur correspondante dans le bean + // puisque dans ce mode, pas possibilite de modifier de cette + // valeur (clef metier) + speciesComboBox.setSelectedItem(species); + weightCategoryComboBox.setData(Collections.singletonList(weightCategory)); + weightCategoryComboBox.setSelectedItem(weightCategory); + + requestFocus = ui.getCatchWeight(); + + } + + if (log.isDebugEnabled()) { + log.debug("selected categoriePoid " + weightCategory); + log.debug("selected species " + species); + } + requestFocus.requestFocus(); + + } + + @Override protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) { // on recupere les espèces acceptables pour des echantillonnages @@ -289,12 +337,12 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target @Override protected void doPersist(SetSeine editBean) { - List<TargetLength> tailleToDelete = ALL_TARGET_LENGTH_TO_DELETE_ENTRY.getContextValue(getUi()); + List<TargetLength> targetLengthsToDelete = ALL_TARGET_LENGTH_TO_DELETE_ENTRY.getContextValue(getUi()); try { TargetCatchService service = getService(TargetCatchService.class); - service.save(editBean, tailleToDelete); + service.save(editBean, targetLengthsToDelete); } finally { @@ -305,54 +353,6 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } - @Override - protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { - - TargetCatchUI ui = getUi(); - - WeightCategory weightCategory = bean.getWeightCategory(); - Species species = weightCategory == null ? null : weightCategory.getSpecies(); - - BeanComboBox<Species> speciesComboBox = ui.getSpecies(); - BeanComboBox<WeightCategory> weightCategoryComboBox = ui.getWeightCategory(); - - JComponent requestFocus; - if (create) { - - // on reinitilise toujours l'espèce (pour reinitialiser la liste des categories) - speciesComboBox.setSelectedItem(null); - - if (!getTableModel().isCreate()) { - // on repositionne l'espèce (cela reconstruira la liste des categories) - speciesComboBox.setSelectedItem(species); - // on repositionne la categorie - weightCategoryComboBox.setSelectedItem(weightCategory); - } - - requestFocus = speciesComboBox; - - } else { - - // en mode mise a jour, on restreint la liste des categories - // au singleton de sa valeur correspondante dans le bean - // puisque dans ce mode, pas possibilite de modifier de cette - // valeur (clef metier) - speciesComboBox.setSelectedItem(species); - weightCategoryComboBox.setData(Collections.singletonList(weightCategory)); - weightCategoryComboBox.setSelectedItem(weightCategory); - - requestFocus = ui.getCatchWeight(); - - } - - if (log.isDebugEnabled()) { - log.debug("selected categoriePoid " + weightCategory); - log.debug("selected species " + species); - } - requestFocus.requestFocus(); - - } - @SuppressWarnings("unchecked") protected void onSpeciesChanged(Species species) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java index 739fcc5..22333ea 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java @@ -247,6 +247,73 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } @Override + protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { + + WeightCategory beanWeightCategory = bean.getWeightCategory(); + Species beanEspece = beanWeightCategory == null ? null : beanWeightCategory.getSpecies(); + ReasonForDiscard beanReasonForDiscard = bean.getReasonForDiscard(); + + if (log.isDebugEnabled()) { + log.debug("selected categoriePoid " + beanWeightCategory); + log.debug("selected species " + beanEspece); + log.debug("selected reasonForDiscard " + beanReasonForDiscard); + } + + TargetDiscardCatchUI ui = getUi(); + + BeanComboBox<Species> speciesComboBox = ui.getSpecies(); + BeanComboBox<WeightCategory> weightCategoryComboBox = ui.getWeightCategory(); + BeanComboBox<ReasonForDiscard> reasonForDiscardComboBox = ui.getReasonForDiscard(); + + JComponent requestFocus; + if (create) { + + ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); + if (model.isCreate()) { + // par défaut, on considère que l'espèce a été monté sur le pont + // c'est le cas le plus fréquent. + bean.setBroughtOnDeck(true); + } + + // on recalcule la liste des speciess disponibles + List<Species> availableEspeces = buildSpeciesList(beanEspece, beanWeightCategory); + speciesComboBox.setData(availableEspeces); + + // on reinitilise toujours la liste des espèces (pour reinitialiser la liste des categories) + speciesComboBox.setSelectedItem(null); + + if (!model.isCreate()) { + // on repositionne l'species (cela reconstruira la liste + // des categories) + speciesComboBox.setSelectedItem(beanEspece); + // on repositionne la categorie + weightCategoryComboBox.setSelectedItem(beanWeightCategory); + reasonForDiscardComboBox.setSelectedItem(beanReasonForDiscard); + } + + requestFocus = speciesComboBox; + + } else { + + // en mode mise a jour, on restreint la liste des categories + // au singleton de sa valeur correspondante dans le bean + // puisque dans ce mode, pas possibilite de modifier de cette + // valeur (clef metier) + speciesComboBox.setSelectedItem(beanEspece); + weightCategoryComboBox.setData(Collections.singletonList(beanWeightCategory)); + weightCategoryComboBox.setSelectedItem(beanWeightCategory); + reasonForDiscardComboBox.setData(Collections.singletonList(beanReasonForDiscard)); + reasonForDiscardComboBox.setSelectedItem(beanReasonForDiscard); + + requestFocus = ui.getCatchWeight(); + + } + + requestFocus.requestFocus(); + + } + + @Override protected boolean prepareSave(SetSeine editBean, List<TargetCatch> objets) { // on recupere les espèces acceptables pour des echantillonnages @@ -346,69 +413,6 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } - @Override - protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { - - TargetDiscardCatchUI ui = getUi(); - - WeightCategory beanWeightCategory = bean.getWeightCategory(); - Species beanEspece = beanWeightCategory == null ? null : beanWeightCategory.getSpecies(); - ReasonForDiscard beanReasonForDiscard = bean.getReasonForDiscard(); - if (log.isDebugEnabled()) { - log.debug("selected categoriePoid " + beanWeightCategory); - log.debug("selected species " + beanEspece); - log.debug("selected reasonForDiscard " + beanReasonForDiscard); - } - - BeanComboBox<Species> speciesComboBox = ui.getSpecies(); - - JComponent requestFocus; - if (create) { - - ContentTableModel<SetSeine, TargetCatch> model = getTableModel(); - if (model.isCreate()) { - // par défaut, on considère que l'espèce a été monté sur le pont - // c'est le cas le plus fréquent. - bean.setBroughtOnDeck(true); - } - - // on recalcule la liste des speciess disponibles - List<Species> availableEspeces = buildSpeciesList(beanEspece, beanWeightCategory); - speciesComboBox.setData(availableEspeces); - - // on reinitilise toujours la liste des espèces (pour reinitialiser la liste des categories) - speciesComboBox.setSelectedItem(null); - - if (!model.isCreate()) { - // on repositionne l'species (cela reconstruira la liste - // des categories) - speciesComboBox.setSelectedItem(beanEspece); - // on repositionne la categorie - ui.getWeightCategory().setSelectedItem(beanWeightCategory); - ui.getReasonForDiscard().setSelectedItem(beanReasonForDiscard); - } - - requestFocus = speciesComboBox; - - } else { - - // en mode mise a jour, on restreint la liste des categories - // au singleton de sa valeur correspondante dans le bean - // puisque dans ce mode, pas possibilite de modifier de cette - // valeur (clef metier) - speciesComboBox.setSelectedItem(beanEspece); - ui.getWeightCategory().setData(Collections.singletonList(beanWeightCategory)); - ui.getWeightCategory().setSelectedItem(beanWeightCategory); - ui.getReasonForDiscard().setData(Collections.singletonList(beanReasonForDiscard)); - ui.getReasonForDiscard().setSelectedItem(beanReasonForDiscard); - - requestFocus = ui.getCatchWeight(); - - } - - requestFocus.requestFocus(); - } - protected void onSpeciesChanged(TargetCatch bean, Species species) { WeightCategory weightCategory = null; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index 0cfa053..adae963 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -29,13 +29,15 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.services.data.seine.TargetLengthService; import fr.ird.observe.services.data.seine.TargetSampleService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUI; import fr.ird.observe.ui.content.table.ContentTableUIHandler; +import jaxx.runtime.swing.JAXXButtonGroup; +import jaxx.runtime.swing.editor.EnumEditor; +import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.validator.NuitonValidatorScope; @@ -60,8 +62,7 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T static private Log log = LogFactory.getLog(TargetSampleUIHandler.class); /** - * Pour différencier positionner l'invariant de l'écran - * {@link TargetSample#getDiscarded()}. + * Pour différencier positionner l'invariant de l'écran {@link TargetSample#getDiscarded()}. * * @since 1.5 */ @@ -69,8 +70,7 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T /** * Ecoute les modifications de la propriété {@link TargetLength#getWeight()}, - * et repasser alors le flag {@link TargetLength#isWeightSource()} à - * {@code false}. + * et repasser alors le flag {@link TargetLength#isWeightSource()} à {@code false}. * * @since 3.0 */ @@ -84,8 +84,7 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T /** * Ecoute les modifications de la propriété {@link TargetLength#getLength()}, - * et repasser alors le flag {@link TargetLength#isLengthSource()} à - * {@code false}. + * et repasser alors le flag {@link TargetLength#isLengthSource()} à {@code false}. * * @since 3.0 */ @@ -97,8 +96,7 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T } }; - public TargetSampleUIHandler(ContentTableUI<TargetSample, TargetLength> ui, - boolean discarded) { + public TargetSampleUIHandler(ContentTableUI<TargetSample, TargetLength> ui, boolean discarded) { super(ui, DataContextType.SetSeine); this.discarded = discarded; } @@ -108,14 +106,33 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T return (TargetSampleUI) super.getUi(); } - public void resetWeightSource() { - getTableEditBean().setWeightSource(false); - getUi().getWeight().grabFocus(); - } + @Override + protected void initTableUI(DefaultTableCellRenderer renderer) { + + JTable table = getUi().getTable(); + + UIHelper.setI18nTableHeaderRenderer( + table, + n("observe.targetSample.table.speciesThon"), + n("observe.targetSample.table.speciesThon.tip"), + n("observe.targetSample.table.measureType"), + n("observe.targetSample.table.measureType.tip"), + n("observe.targetSample.table.length"), + n("observe.targetSample.table.length.tip"), + n("observe.targetSample.table.meanWeight"), + n("observe.targetSample.table.meanWeight.tip"), + n("observe.targetSample.table.count"), + n("observe.targetSample.table.count.tip"), + n("observe.targetSample.table.totalWeight"), + n("observe.targetSample.table.totalWeight.tip")); + + UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); + UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEnumTableCellRenderer(renderer, CodeMesureEnum.class)); + UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 4, UIHelper.newEmptyNumberTableCellRenderer(renderer)); + UIHelper.setTableColumnRenderer(table, 5, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - public void resetLengthSource() { - getTableEditBean().setLengthSource(false); - getUi().getLength().grabFocus(); } @Override @@ -123,170 +140,157 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T String setId = getDataContext().getSelectedSetId(); - TargetSample targetSample = getService(TargetLengthService.class).loadForEdit(setId, discarded); + TargetSampleService service = getService(TargetSampleService.class); + + TargetSample targetSample = service.loadForEdit(setId, discarded); copy(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, targetSample, getBean()); if (ContentMode.UPDATE == mode) { - // on ne charge les speciess uniquement si on est en mode édition - List<Species> speciesList = getService(TargetSampleService.class).getAvailableSpeciesForTargetSample(setId, discarded); - + // on charge les espèces uniquement si on est en mode édition + List<Species> speciesList = service.getAvailableSpeciesForTargetSample(setId, discarded); getUi().getSpecies().setData(speciesList); } - getModel().setMode(mode); - - - // initialisation du modèle du tableau - getUi().getTableModel().attachModel(); - } @Override - protected void doPersist(TargetSample editBean) { + protected ContentMode getContentMode(DataContext dataContext) { - String setId = getDataContext().getSelectedSetId(); + ContentMode mode = super.getContentMode(dataContext); + String setId = getDataContext().getSelectedSetId(); TargetSampleService service = getService(TargetSampleService.class); + boolean showData = service.canUseTargetSample(setId, discarded); - if (!Entities.isNew(editBean) && editBean.isTargetLengthEmpty()) { - - // remove orphan target sample - if (log.isInfoEnabled()) { - log.info("Remove obsolete targetSample " + editBean.getTopiaId() + " from Set: " + setId); - } + getModel().setShowData(showData); - //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) - service.delete(setId, editBean); + if (mode == ContentMode.UPDATE && !showData) { - } else { + mode = ContentMode.READ; - String savedId = service.save(setId, editBean); - editBean.setTopiaId(savedId); - //FIXME Non, la sauvegarde doit être faite par un seul appel au service (sinon fait dans 2 transactions) - getService(TargetLengthService.class).save(editBean); + addMessage(getUi(), + NuitonValidatorScope.INFO, + getEntityLabel(SetSeine.class), + discarded ? + t("observe.setSeine.message.no.targetCatch") : + t("observe.setSeine.message.no.targetDiscarded")); } + + return mode; + } @Override protected void onSelectedRowChanged(int editingRow, TargetLength bean, boolean create) { ContentTableModel<TargetSample, TargetLength> model = getTableModel(); - TargetSampleUI ui = getUi(); - if (!model.isEditable()) { - return; - } - Species species = bean.getSpecies(); - JComponent requestFocus; + if (model.isEditable()) { - if (create) { + Species species = bean.getSpecies(); -// if (model.isCreate() && editingRow > 0) { - if (model.isCreate()) { + TargetSampleUI ui = getUi(); + JAXXButtonGroup acquisitionModeGroup = ui.getAcquisitionModeGroup(); + BeanComboBox<Species> speciesComboBox = ui.getSpecies(); - if (editingRow > 0) { - // on recupere l'species de la ligne precedente - TargetLength editBean = model.getValueAt(editingRow - 1); - species = editBean.getSpecies(); - } + JComponent requestFocus; - // on passe le mode de saisie en count - ui.getAcquisitionModeGroup().setSelectedValue(null); - ui.getAcquisitionModeGroup().setSelectedValue(ModeSaisieEchantillonEnum.byEffectif); + if (create) { - // on utilise par défaut le code mesure lf - ui.getMeasureType().setSelectedItem(null); - ui.getMeasureType().setSelectedItem(CodeMesureEnum.lf); - } + if (model.isCreate()) { - requestFocus = ui.getSpecies(); + if (editingRow > 0) { - } else { + // on recupere l'espèce de la ligne precedente + TargetLength editBean = model.getValueAt(editingRow - 1); + species = editBean.getSpecies(); - requestFocus = ui.getCount(); + } - // on passe le mode de saisie - int acquisitionMode = bean.getAcquisitionMode(); - ModeSaisieEchantillonEnum enumValue = - ModeSaisieEchantillonEnum.valueOf(acquisitionMode); - ui.getAcquisitionModeGroup().setSelectedValue(null); - ui.getAcquisitionModeGroup().setSelectedValue(enumValue); - } + // on passe le mode de saisie en count + acquisitionModeGroup.setSelectedValue(null); + acquisitionModeGroup.setSelectedValue(ModeSaisieEchantillonEnum.byEffectif); - // on met a jour l'espce - ui.getSpecies().setSelectedItem(null); + // on utilise par défaut le code mesure lf + EnumEditor measureType = ui.getMeasureType(); + measureType.setSelectedItem(null); + measureType.setSelectedItem(CodeMesureEnum.lf); + + } + + requestFocus = speciesComboBox; + + } else { + + requestFocus = ui.getCount(); + + // on passe le mode de saisie + int acquisitionMode = bean.getAcquisitionMode(); + ModeSaisieEchantillonEnum enumValue = ModeSaisieEchantillonEnum.valueOf(acquisitionMode); + acquisitionModeGroup.setSelectedValue(null); + acquisitionModeGroup.setSelectedValue(enumValue); - if (species != null) { - if (log.isDebugEnabled()) { - log.debug("species to use " + species); } - ui.getSpecies().setSelectedItem(species); - } - requestFocus.requestFocus(); - TargetLength tableEditBean = getTableEditBean(); - reloadPropertyChangeListener(tableEditBean, TargetLength.PROPERTY_WEIGHT, weightChanged); - reloadPropertyChangeListener(tableEditBean, TargetLength.PROPERTY_LENGTH, lengthChanged); + // on met a jour l'espèce + speciesComboBox.setSelectedItem(null); - } + if (species != null) { - @Override - protected void initTableUI(DefaultTableCellRenderer renderer) { + if (log.isDebugEnabled()) { + log.debug("species to use " + species); + } + speciesComboBox.setSelectedItem(species); - JTable table = getUi().getTable(); + } - UIHelper.setI18nTableHeaderRenderer( - table, - n("observe.targetSample.table.speciesThon"), - n("observe.targetSample.table.speciesThon.tip"), - n("observe.targetSample.table.measureType"), - n("observe.targetSample.table.measureType.tip"), - n("observe.targetSample.table.length"), - n("observe.targetSample.table.length.tip"), - n("observe.targetSample.table.meanWeight"), - n("observe.targetSample.table.meanWeight.tip"), - n("observe.targetSample.table.count"), - n("observe.targetSample.table.count.tip"), - n("observe.targetSample.table.totalWeight"), - n("observe.targetSample.table.totalWeight.tip")); + requestFocus.requestFocus(); + + TargetLength tableEditBean = getTableEditBean(); + reloadPropertyChangeListener(tableEditBean, TargetLength.PROPERTY_WEIGHT, weightChanged); + reloadPropertyChangeListener(tableEditBean, TargetLength.PROPERTY_LENGTH, lengthChanged); + + } - UIHelper.setTableColumnRenderer(table, 0, UIHelper.newDecorateTableCellRenderer(renderer, Species.class)); - UIHelper.setTableColumnRenderer(table, 1, UIHelper.newEnumTableCellRenderer(renderer, CodeMesureEnum.class)); - UIHelper.setTableColumnRenderer(table, 2, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 3, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 4, UIHelper.newEmptyNumberTableCellRenderer(renderer)); - UIHelper.setTableColumnRenderer(table, 5, UIHelper.newEmptyNumberTableCellRenderer(renderer)); } @Override - protected ContentMode getContentMode(DataContext dataContext) { - ContentMode mode = super.getContentMode(dataContext); - + protected void doPersist(TargetSample editBean) { String setId = getDataContext().getSelectedSetId(); + TargetSampleService service = getService(TargetSampleService.class); - boolean showData = service.canUseTargetSample(setId, discarded); - getModel().setShowData(showData); + if (!Entities.isNew(editBean) && editBean.isTargetLengthEmpty()) { - if (mode == ContentMode.UPDATE && !showData) { + // remove orphan target sample + if (log.isInfoEnabled()) { + log.info("Remove obsolete targetSample " + editBean.getTopiaId() + " from Set: " + setId); + } - mode = ContentMode.READ; + service.delete(setId, editBean); + + } else { + + String savedId = service.save(setId, editBean); + editBean.setTopiaId(savedId); - addMessage(getUi(), - NuitonValidatorScope.INFO, - getEntityLabel(SetSeine.class), - discarded ? - t("observe.setSeine.message.no.targetCatch") : - t("observe.setSeine.message.no.targetDiscarded") - ); } - return mode; + } + + public void resetWeightSource() { + getTableEditBean().setWeightSource(false); + getUi().getWeight().grabFocus(); + } + + public void resetLengthSource() { + getTableEditBean().setLengthSource(false); + getUi().getLength().grabFocus(); } /** @@ -351,6 +355,8 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T // on propage le mode de saisie dans le bean editBean.setAcquisitionMode(newMode.ordinal()); + } + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 9683356ba63aa405c2df81ec3f665c13350f79a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun May 3 17:21:07 2015 +0200 - suppression de tout code utilisant des transaction du module swing (refs #7017) --- .../src/main/java/fr/ird/observe/DataService.java | 2483 -------------------- .../java/fr/ird/observe/db/DataServiceTest.java | 339 --- .../referentiel/LengthWeightParameterDAOImpl.java | 4 + .../observe/entities/referentiel/SexDAOImpl.java | 7 + .../ird/observe/services/ReplicationService.java | 11 + .../observe/services/ReplicationServiceImpl.java | 11 + .../services/operation/ComputeDataService.java | 18 + .../services/operation/ComputeDataServiceImpl.java | 479 ++-- .../services/operation/GpsImportService.java | 11 + .../services/operation/GpsImportServiceImpl.java | 11 + .../operation/ObsoleteReferenceToReplace.java | 111 + .../services/operation/SynchronizeService.java | 11 + .../services/operation/SynchronizeServiceImpl.java | 11 + .../services/operation/ValidationService.java | 18 + .../services/operation/ValidationServiceImpl.java | 94 + 15 files changed, 540 insertions(+), 3079 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/DataService.java b/observe-business/src/main/java/fr/ird/observe/DataService.java deleted file mode 100644 index aee4dc3..0000000 --- a/observe-business/src/main/java/fr/ird/observe/DataService.java +++ /dev/null @@ -1,2483 +0,0 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.constants.DataSourceState; -import fr.ird.observe.db.util.TopiaExecutor; -import fr.ird.observe.db.util.TopiaExecutor2; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.LengthWeightParameter; -import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; -import fr.ird.observe.entities.referentiel.Ocean; -import fr.ird.observe.entities.referentiel.ReferenceEntities; -import fr.ird.observe.entities.referentiel.Sex; -import fr.ird.observe.entities.referentiel.Species; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.event.TopiaTransactionEvent; -import org.nuiton.topia.event.TopiaTransactionListener; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.DiffState; -import org.nuiton.topia.persistence.util.EntityOperator; -import org.nuiton.topia.persistence.util.Loador; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeListenerProxy; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.List; - -import static org.nuiton.i18n.I18n.t; - -/** - * Le contrat du service de données. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class DataService { - - /** Logger */ - private static final Log log = LogFactory.getLog(DataService.class); - - String PARENT_BEAN = "parentBean"; - - String BEAN = "bean"; - - protected DecoratorService decoratorService; - - protected DataContext dataContext; - - protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - -// private boolean skipTransactionListener; - - private TopiaTransactionListener transactionListener = new TopiaTransactionListener() { - - public void commit(TopiaTransactionEvent event) { - -// if (skipTransactionListener) { -// return; -// } - - java.util.Set<TopiaEntity> entities = event.getEntities(); - - // pour recenser les referentiels modifies - EnumSet<ObserveEntityEnum> referentiel = - EnumSet.noneOf(ObserveEntityEnum.class); - - // pour referencer les types openables modifies -// boolean touchOpenContext = false; - - // pour referencer les donnees observers modifiees - java.util.Set<TopiaEntity> data = new HashSet<TopiaEntity>(); - - for (TopiaEntity entity : entities) { - if (log.isDebugEnabled()) { - if (event.isLoad(entity)) { - - if (log.isDebugEnabled()) { - log.debug("loaded entity [" + entity.getTopiaId() + "]"); - } - } else if (event.isCreate(entity)) { - if (log.isInfoEnabled()) { - log.info("created entitiy [" + entity.getTopiaId() + "]"); - } - - } else if (event.isUpdate(entity)) { - if (log.isDebugEnabled()) { - log.debug("updated entitiy [" + entity.getTopiaId() + "]"); - } - - } else if (event.isDelete(entity)) { - if (log.isDebugEnabled()) { - log.debug("deleted entitiy [" + entity.getTopiaId() + "]"); - } - } - } - - if (!event.isModification(entity)) { - - // pas de modification, on ne fait rien - continue; - } - - // l'entite a ete modifiee, cree ou supprimee - ObserveEntityEnum constant = - ObserveEntityEnum.valueOf(entity); - - if (constant == null) { - - // non gere (peut-etre une entite technique) - continue; - } - - if (Entities.isReferentielClass(constant)) { - - // c'est un objet du référentiel - referentiel.add(constant); - continue; - } - - // il s'agit d'une donnée utilisateur - data.add(entity); - -// if (OpenableEntities.isOpenable(entity)) { -// touchOpenContext = true; -// } - } - - DataSource source = ObserveServiceHelper.get().getDataSource(); - if (source == null) { - throw new IllegalStateException("No source service registred."); - } - source.checkState(DataSourceState.OPEN); - - if (!referentiel.isEmpty()) { - - // notification de modification de reférentiels - fireReferentielChanged( - source, - referentiel.toArray( - new ObserveEntityEnum[referentiel.size()]) - ); - } - - if (!data.isEmpty()) { - - // notification de modification de reférentiels - fireDataChanged(source, - data.toArray(new TopiaEntity[data.size()]) - ); - } - -// if (touchOpenContext) { -// fireOpenChanged(source); -// } - } - - public void rollback(TopiaTransactionEvent event) { - } - }; - -// protected PropertyChangeListener openListener = new PropertyChangeListener() { -// -// public void propertyChange(PropertyChangeEvent evt) { -// DataService source = (DataService) evt.getSource(); -// DataContext dataContext = source.getDataContext(); -// String[] value = (String[]) evt.getNewValue(); -// if (log.isDebugEnabled()) { -// log.debug("open context changed in data service, will propagate it to " + dataContext); -// log.debug("new open ids : " + Arrays.toString(value)); -// } -// dataContext.populateOpens(value); -// } -// }; - - - public void registerDataSource(DataSource source) { - - ObserveServiceHelper.get().setDataSource(source); - -// addPropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); - } - - - public void unregisterDataSource(DataSource source) { - - ObserveServiceHelper.get().setDataSource(null); - -// removePropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); - - // remove all listeners for the referentiel - //FIXMe tchemit 2010-11-30 Perharps we should remove all listeners ? - removeReferentielPropertyChangeListeners(); - } - - - public DecoratorService getDecoratorService() { - if (decoratorService == null) { - decoratorService = ObserveServiceHelper.getDecoratorService(); - } - return decoratorService; - } - - - public DataContext getDataContext() { - if (dataContext == null) { - dataContext = ObserveServiceHelper.getDataContext(); - } - return dataContext; - } - - // ------------------------------------------------------------------------ - // -- Méthodes de gestion des transactions - // ------------------------------------------------------------------------ - - - public TopiaContext beginTransaction(DataSource source, - String methodName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - if (log.isDebugEnabled()) { - log.debug("begin tx " + methodName); - } - TopiaContext tx = source.beginTransaction(methodName); - tx.addTopiaTransactionListener(transactionListener); - if (log.isDebugEnabled()) { - log.debug("after begin tx " + methodName); - } - return tx; - } - - - public void rollbackTransaction(DataSource source, - TopiaContext tx, - String txName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - source.rollbackTransaction(tx, txName); - } - - - public void commitTransaction(DataSource source, - TopiaContext tx, - String txName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - if (log.isDebugEnabled()) { - log.debug("commit tx " + txName); - } - source.commitTransaction(tx, txName); - if (log.isDebugEnabled()) { - log.debug("after commit tx " + txName); - } - } - - - public void closeTransaction(DataSource source, - TopiaContext tx, - String txName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - if (log.isDebugEnabled()) { - log.debug("close tx " + txName); - } - tx.removeTopiaTransactionListener(transactionListener); - source.closeTransaction(tx, txName); - if (log.isDebugEnabled()) { - log.debug("after close tx " + txName); - } - } - - // ------------------------------------------------------------------------ - // -- Méthodes métiers de récupération de données - // ------------------------------------------------------------------------ - - -// public String[] getOpenIds(DataSource source) throws DataSourceException { -// -// String[] result = null; -// TopiaContext tx = beginTransaction(source, "getOpenIds"); -// try { -// -// result = source.getOpenIds(tx); -// } finally { -// closeTransaction(source, tx, "getOpenIds"); -// } -// return result; -// } - - - public <E extends TopiaEntity> List<E> getList(DataSource source, Class<E> klass) throws DataSourceException { - - List<E> list = getList(source, klass, null, null); - return list; - } - -// public <E extends TopiaEntity> List<E> getList(DataSource source, Class<E> klass, Predicate<E> predicate) throws DataSourceException { -// List<E> result = getList(source, klass, predicate, null); -// return result; -// } - - - public <E extends TopiaEntity> List<E> getList(DataSource source, - Class<E> klass, - TopiaEntityBinder<E> loador) throws DataSourceException { - List<E> result = getList(source, klass, null, loador); - return result; - } - - - public <E extends TopiaEntity> List<E> getList(DataSource source, - Class<E> klass, - Predicate<E> predicate, - TopiaEntityBinder<E> loador) throws DataSourceException { - if (Entities.isDataClass(klass)) { - // on verifie que l'on a le droit de lire la donnee - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data, no read credential"); - } - return new ArrayList<E>(); - } - } - - if (Entities.isReferentielClass(klass)) { - // on verifie que l'on a le droit de lire la donnee - if (!source.canReadReferentiel()) { - if (log.isDebugEnabled()) { - log.debug("Can not read referentiel, no read credential"); - } - return new ArrayList<E>(); - } - } - - List<E> result; - try { - - result = getList0(source, klass, predicate, loador); - - //TC-20100208 : on peut modifier la liste (pour supprimer par - // exemple les entites non active), on doit donc toujours travailler - // sur une copie de la liste - return new ArrayList<E>(result); - } catch (Exception e) { - throw new DataSourceException(e, "getList"); - } - } - -// public <E extends TopiaEntity> EntityMap findAllUsages(DataSource source, -// E entity) throws DataSourceException { -// -// String txName = "findAllUsages"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<E> dao; -// dao = source.getDAO(tx, entity); -// -// // always get a fresh version of object -// entity = dao.findByTopiaId(entity.getTopiaId()); -// EntityMap result; -// result = new EntityMap(dao.findAllUsages(entity)); -// if (decoratorService != null) { -// // on charge les entites -// for (Class<? extends TopiaEntity> aClass : result.keySet()) { -// Decorator<? extends TopiaEntity> decorator = -// decoratorService.getDecoratorByType(aClass); -// for (TopiaEntity e : result.get(aClass)) { -// decorator.toString(e); -// } -// } -// } -// return result; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - -// public <E extends OpenableEntity & TopiaEntity> E getOpen(DataSource source, -// Class<E> klass) throws DataSourceException { -// -// if (!source.canReadData()) { -// if (log.isInfoEnabled()) { -// log.info("Can not read data!"); -// } -// return null; -// } -// String txName = "getOpen"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// E result = source.getOpen(tx, klass); -// if (result != null && klass.equals(TripSeine.class)) { -// ((TripSeine) result).getProgram(); -// } -// return result; -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Program> getAllProgramStub(DataSource source) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getAllProgramStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<Program> result = dao.findAllStub(referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public Program getProgramStub(DataSource source, String programId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getProgramStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// Program result = dao.findStubByTopiaId(programId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<TripSeine> getTripSeineStubByProgram(DataSource source, String programId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getTripSeineStubByProgram"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<TripSeine> result = dao.findAllStubByProgramId(programId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public TripSeine getTripSeineStub(DataSource source, String tripId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getTripSeineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// TripSeine result = dao.findStubByTopiaId(tripId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - -// public List<Route> getRouteStubByTrip(DataSource source, String tripSeineId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getRouteStubByTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); -// List<Route> result = dao.findAllStubByTripId(tripSeineId); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public Route getRouteStub(DataSource source, String routeId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getRouteStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); -// Route result = dao.findStubByTopiaId(routeId); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<ActivitySeine> getActivitySeineStubByRoute(DataSource source, String routeId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getActivitySeineStubByRoute"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<ActivitySeine> result = dao.findAllStubByRouteId(routeId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public ActivitySeine getActivitySeineStub(DataSource source, String activityId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getActivitySeineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// ActivitySeine result = dao.findStubByTopiaId(activityId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<FloatingObject> getFloatinObjectStubByActivitySeine(DataSource source, String activitySeineId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getFloatinObjectStubByActivitySeine"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<FloatingObject> result = dao.findAllStubByActivityId(activitySeineId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public FloatingObject getFloatinObjectStub(DataSource source, String floatingObjectId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getFloatinObjectStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// FloatingObject result = dao.findStubByTopiaId(floatingObjectId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<TripLongline> getTripLonglineStubByProgram(DataSource source, String programId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getTripLonglineStubByProgram"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<TripLongline> result = dao.findAllStubByProgramId(programId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public TripLongline getTripLonglineStub(DataSource source, String tripId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getTripLonglineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// TripLongline result = dao.findStubByTopiaId(tripId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public List<ActivityLongline> getActivityLonglineStubByTrip(DataSource source, String tripId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getActivityLonglineStubByTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<ActivityLongline> result = dao.findAllStubByTripId(tripId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public ActivityLongline getActivityLonglineStub(DataSource source, String activityId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getActivityLonglineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// ActivityLongline result = dao.findStubByTopiaId(activityId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public Ocean getTripOcean(DataSource source, String tripId) throws DataSourceException { -// -// String txName = "getTripOcean"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// TripSeine result = dao.findByTopiaId(tripId); -// return result.getOcean(); -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - /** - * Recherche d'un {@link LengthWeightParameter} à partir des paramètres donnés. - * <p/> - * La recherche peut ne peut être aussi exacte que les paramètres donnés : - * <p/> - * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son - * speciesGroup d'espèce. - * <p/> - * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on - * recherche avec un ocean vide. - * <p/> - * Si non trouvé sur le gender (et que le gender n'est pas indéterminé) , alors - * on recherche avec le gender indéterminé (gender=0). - * - * @param tx la transaction en cours d'utilisation - * @param species l'espèce sur lequel on recherche le paramétrage - * @param ocean l'ocean recherché (peut être null) - * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) - * @param date le jour recherché - * @return le paramétrage adéquate - * @throws DataSourceException pour toute erreur - * @since 1.5 - */ - public <P extends LengthWeightParameter> P findLengthWeightParameter( - TopiaContext tx, - Species species, - Ocean ocean, - Sex sex, - Date date) throws DataSourceException { - - try { - - List<P> list = LengthWeightParemeterHelper.findBySpecies( - (TopiaContextImplementor) tx, - species - ); - - if (CollectionUtils.isEmpty(list)) { - - // aucun parametrage pour le type donne - return null; - } - - // filtrage par ocean - list = LengthWeightParemeterHelper.filterByOcean(list, ocean); - - if (CollectionUtils.isEmpty(list) && ocean != null) { - - // filtre par ocean null - list = LengthWeightParemeterHelper.filterByOcean(list, null); - } - - if (CollectionUtils.isEmpty(list)) { - - // pas d'ocean adequate - return null; - } - - // filtrage par sexe - list = LengthWeightParemeterHelper.filterBySexe(list, sex); - - if (CollectionUtils.isEmpty(list)) { - - Sex unkwonSex = ObserveDAOHelper.getSexDAO(tx).findByCode("0"); - - if (unkwonSex.equals(sex)) { - - // filtrage par sexe indetermine - list = LengthWeightParemeterHelper.filterBySexe(list, unkwonSex); - } - - - } - - if (CollectionUtils.isEmpty(list)) { - - // pas de sexe adequate - return null; - } - - // filtrage par startDate de validite - list = LengthWeightParemeterHelper.filterByDateDebutValidite(list, - date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de debut adequate - return null; - } - - // filtrage par endDate de validite - list = LengthWeightParemeterHelper.filterByDateFinValidite(list, - date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de fin adequate - return null; - } - - // au final il ne devrait en rester qu'un - - if (list.size() > 1) { - StringBuilder sb = new StringBuilder("Il existe plusieurs paramétrages possibles pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(getDecoratorService().decorate(species)); - sb.append("\nOcean : "); - sb.append(getDecoratorService().decorate(ocean)); - sb.append("\nSex : "); - sb.append(getDecoratorService().decorate(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrages trouvés : "); - for (P p : list) { - sb.append("\n - ").append(getDecoratorService().decorate(p)); - } - throw new DataSourceException(sb.toString(), "findLengthWeightParameter"); - } - - P result = list.get(0); - if (log.isDebugEnabled()) { - StringBuilder sb = new StringBuilder("Paramétrage trouvé pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(getDecoratorService().decorate(species)); - sb.append("\nOcean : "); - sb.append(getDecoratorService().decorate(ocean)); - sb.append("\nSex : "); - sb.append(getDecoratorService().decorate(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrage: ").append(getDecoratorService().decorate(result)); - log.debug(sb.toString()); - } - return result; - - } catch (Exception e) { - throw new DataSourceException(e, "findLengthWeightParameter"); - } - } - -// protected Sex getUnknownSex(TopiaContext tx) throws TopiaException { -// return ObserveDAOHelper.getSexDAO(tx).findByCode("0"); -// } - -// public int getOpenablePosition(DataSource source, -// String containerId, -// String childId) throws DataSourceException { -// if (childId.startsWith(TripSeine.class.getName())) { -// return getTripSeinePosition(source, containerId, childId); -// } -// if (childId.startsWith(TripLongline.class.getName())) { -// return getTripLonglinePosition(source, containerId, childId); -// } -// if (childId.startsWith(Route.class.getName())) { -// return getRoutePosition(source, containerId, childId); -// } -// if (childId.startsWith(ActivitySeine.class.getName())) { -// return getActivitySeinePosition(source, containerId, childId); -// } -// if (childId.startsWith(ActivityLongline.class.getName())) { -// return getActivityLonglinePosition(source, containerId, childId); -// } -// throw new IllegalStateException("Can not come here!"); -// } - -// protected int getTripSeinePosition(DataSource source, -// String programId, -// String tripId) throws DataSourceException { -// -// String txName = "getTripSeinePosition [" + tripId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// int pos = dao.findPositionByProgramId(programId, tripId); -// return pos; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getTripLonglinePosition(DataSource source, -// String programId, -// String tripId) throws DataSourceException { -// -// String txName = "getTripLonglinePosition [" + tripId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// int pos = dao.findPositionByProgramId(programId, tripId); -// return pos; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getRoutePosition(DataSource source, -// String tripId, -// String routeId) throws DataSourceException { -// -// String txName = "getRoutePosition [" + tripId + "/" + routeId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripSeine maree = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); -// Route route = maree.getRouteByTopiaId(routeId); -// List<Route> routes = maree.getRoute(); -// Routes.sort(routes); -// return routes.indexOf(route); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getActivitySeinePosition(DataSource source, -// String routeId, -// String activityId) throws DataSourceException { -// -// String txName = "getActivitySeinePosition [" + routeId + "/" + activityId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// Route route = source.getDAO(tx, Route.class).findByTopiaId(routeId); -// ActivitySeine activitySeine = route.getActivitySeineByTopiaId(activityId); -// List<ActivitySeine> activitySeines = route.getActivitySeine(); -// ActivitySeines.sort(activitySeines); -// return activitySeines.indexOf(activitySeine); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getActivityLonglinePosition(DataSource source, -// String tripId, -// String activityId) throws DataSourceException { -// -// String txName = "getActivityLonglinePosition [" + tripId + "/" + activityId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripLongline trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); -// ActivityLongline activity = trip.getActivityLonglineByTopiaId(activityId); -// List<ActivityLongline> activities = trip.getActivityLongline(); -// ActivityLonglines.sort(activities); -// return activities.indexOf(activity); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public String getTargetSampleId(DataSource source, -// String setId, -// boolean discarded) throws DataSourceException { -// -// String txName = "getTargetSampleId [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// List<TargetSample> list = set.getTargetSample(); -// if (list == null || list.isEmpty()) { -// return null; -// } -// for (TargetSample targetSample : list) { -// if (discarded) { -// if (targetSample.getDiscarded() != null && -// targetSample.getDiscarded()) { -// return targetSample.getTopiaId(); -// } -// } else if (targetSample.getDiscarded() == null || -// !targetSample.getDiscarded()) { -// return targetSample.getTopiaId(); -// } -// } -// return null; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public String getNonTargetSampleId(DataSource source, -// String setId) throws DataSourceException { -// -// String txName = "getNonTargetSampleId [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// List<NonTargetSample> list = set.getNonTargetSample(); -// if (list == null || list.isEmpty()) { -// return null; -// } -// return list.get(0).getTopiaId(); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Species> getAvailableEspeceForTargetSample(DataSource source, -// String setId, -// boolean discarded) throws DataSourceException { -// -// String txName = "getAvailableEspeceForTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// List<Species> speciess = new ArrayList<Species>(); -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// // on recupere la liste des species thon utilisees dans le rejet -// Collection<TargetCatch> discardeds = set.getTargetCatch(); -// -// // on filtre sur les speciess monté sur le pont et rejetée -// -// if (discardeds != null) { -// for (TargetCatch discardedt : discardeds) { -// boolean keep; -// -// if (discarded) { -// -// // on ne conserve que les speciess des discardeds montees sur le pont et discardedes -// keep = discardedt.isDiscarded() && discardedt.getBroughtOnDeck(); -// -// } else { -// -// // on ne conserve que les species des discardeds -// keep = !discardedt.isDiscarded(); -// } -// -// if (keep && -// !speciess.contains(discardedt.getWeightCategory().getSpecies())) { -// speciess.add(discardedt.getWeightCategory().getSpecies()); -// } -// } -// } -// return speciess; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Species> getAvailableEspeceForNonTargetSample(DataSource source, -// String setId) throws DataSourceException { -// -// String txName = "getAvailableEspeceForNonTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// List<Species> speciess = new ArrayList<Species>(); -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// // on recupere la liste des species faune utilisees dans le rejet -// Collection<NonTargetCatch> discardeds = set.getNonTargetCatch(); -// -// if (discardeds != null) { -// for (NonTargetCatch discarded : discardeds) { -// // on retient toute les speciess (capturées ou rejetées) -// if (!speciess.contains(discarded.getSpecies())) { -// speciess.add(discarded.getSpecies()); -// } -// } -// } -// -// return speciess; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Section> getSections(DataSource source, String setLonglineId) throws DataSourceException { -// String txName = "getSections [" + setLonglineId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<Section> dao = source.getDAO(tx, Section.class); -// -// List<Section> sections = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); -// -// if (!sections.isEmpty()) { -// -// Decorator<Section> sectionDecorator = getDecoratorService().getDecoratorByType(Section.class); -// Decorator<Basket> basketDecorator = getDecoratorService().getDecoratorByType(Basket.class); -// Decorator<Branchline> branchlineDecorator = getDecoratorService().getDecoratorByType(Branchline.class); -// -// for (Section section : sections) { -// -// sectionDecorator.toString(section); -// -// if (!section.isBasketEmpty()) { -// -// for (Basket basket : section.getBasket()) { -// -// basketDecorator.toString(basket); -// -// if (!basket.isBranchlineEmpty()) { -// -// for (Branchline branchline : basket.getBranchline()) { -// -// branchlineDecorator.toString(branchline); -// -// } -// } -// -// } -// } -// } -// } -// -// return sections; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public List<Species> loadDecoratedSpecies(DataSource source, String speciesListCode) throws DataSourceException { -// String txName = "loadDecoratedSpecies [" + speciesListCode + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// List<Species> speciess = new ArrayList<Species>(); -// -// SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); -// SpeciesList speciesList = dao.findByTopiaId(speciesListCode); -// -// speciess.addAll(speciesList.getSpecies()); -// -// Decorator<Species> decorator = getDecoratorService().getDecoratorByType(Species.class); -// -// for (Species species : speciess) { -// decorator.toString(species); -// } -// -// return speciess; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - -// public java.util.Set<String> getSpeciesListSpeciesIds(DataSource source, String speciesListId) throws DataSourceException { -// String txName = "getSpeciesListSpeciesIds [" + speciesListId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// -// SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); -// SpeciesList speciesList = dao.findByTopiaId(speciesListId); -// -// java.util.Set<String> ids = -// Sets.newHashSet( -// TopiaEntityHelper.getTopiaIdList( -// speciesList.getSpecies())); -// -// return ids; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public boolean canUseNonTargetSample(DataSource source, -// String setId) throws DataSourceException { -// -// String txName = "canUseNonTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// return set.canUseNonTargetSample(); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public boolean canUseTargetSample(DataSource source, -// String setId, -// boolean discarded) throws DataSourceException { -// -// String txName = "canUseTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// return set.canUseTargetSample(discarded); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public void getObsoleteEspeceForNonTargetSample(DataSource source, -// String setId, -// List<Species> speciessUsed, -// Collection<Species> speciessToDelete, -// List<NonTargetLength> tailleToDelete) throws DataSourceException { -// -// String txName = "getObsoleteEspeceForNonTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// -// if (set.isNonTargetSampleEmpty()) { -// return; -// } -// -// NonTargetSample echantillon = set.getNonTargetSample().get(0); -// -// if (echantillon.isNonTargetLengthEmpty()) { -// return; -// } -// -// for (NonTargetLength taille : echantillon.getNonTargetLength()) { -// Species tailleEspece = taille.getSpecies(); -// if (!speciessUsed.contains(tailleEspece)) { -// // l'species n'existe plus dans les rejet faune, -// // on doit le supprimer -// tailleToDelete.add(taille); -// speciessToDelete.add(tailleEspece); -// if (log.isDebugEnabled()) { -// log.debug("remove obsolote echantillon " + taille + -// " for species " + tailleEspece); -// } -// } -// } -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public void getObsoleteEspeceForTargetSample(DataSource source, -// String setId, -// Collection<Species> speciessUsed, -// Collection<Species> speciessToDelete, -// List<TargetLength> tailleToDelete, boolean discarded) throws DataSourceException { -// -// String txName = "getObsoleteEspeceForTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// if (set.isTargetSampleEmpty()) { -// return; -// } -// -// TargetSample echantillon = set.getTargetSample(discarded); -// -// if (echantillon == null || echantillon.isTargetLengthEmpty()) { -// return; -// } -// -// for (TargetLength taille : echantillon.getTargetLength()) { -// Species tailleEspece = taille.getSpecies(); -// if (!speciessUsed.contains(tailleEspece)) { -// // l'species n'existe plus dans les rejet faune, -// // on doit le supprimer -// tailleToDelete.add(taille); -// speciessToDelete.add(tailleEspece); -// if (log.isDebugEnabled()) { -// log.debug("remove obsolote echantillon " + taille + -// " for species " + tailleEspece); -// } -// } -// } -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Program> getPossibleProgramsForTrip(DataSource source, String tripId) throws DataSourceException { -// -// final GearType gearType; -// -// String txName = "getPossibleProgramsForTrip : " + tripId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// Trip trip; -// -// if (tripId.contains(TripSeine.class.getSimpleName())) { -// trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); -// } else { -// trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); -// } -// -// gearType = trip.getProgram().getGearType(); -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// -// List<Program> programs = dao.findAllByGearType(gearType); -// -// for (Program program : programs) { -// decoratorService.decorate(program); -// } -// -// return programs; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public void moveTripToProgram(DataSource source, String tripId, String programId) throws DataSourceException { -// -// String txName = "moveTripToProgram : " + tripId + " :: " + programId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// Trip trip; -// -// if (tripId.contains(TripSeine.class.getSimpleName())) { -// trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); -// } else { -// trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); -// } -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// -// Program program = dao.findByTopiaId(programId); -// -// trip.setProgram(program); -// -// tx.commitTransaction(); -// -// if (trip.isOpen()) { -// -// // refresh the dataContext -// dataContext.setOpenProgramId(programId); -// -// } -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public List<SizeMeasure> getCatchLonglineSizeMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<SizeMeasure> binder) throws DataSourceException { -// -// String txName = "getSections : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); -// CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); -// List<SizeMeasure> result = new ArrayList<SizeMeasure>(); -// for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { -// SizeMeasure target = new SizeMeasureImpl(); -// binder.load(sizeSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public List<WeightMeasure> getCatchLonglineWeightMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<WeightMeasure> binder) throws DataSourceException { -// -// String txName = "getSections : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); -// CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); -// List<WeightMeasure> result = new ArrayList<WeightMeasure>(); -// for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { -// WeightMeasure target = new WeightMeasureImpl(); -// binder.load(weightSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(DataSource source, String gearId) throws DataSourceException { -// -// String txName = "getDefaultGearUseFeaturesMeasurementSeine : " + gearId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); -// Gear gear = gearDao.findByTopiaId(gearId); -// -// Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); -// List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); -// for (GearCaracteristic caracteristic : gearCaracteristic) { -// GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); -// target.setGearCaracteristic(caracteristic); -// result.add(target); -// } -// -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeine(DataSource source, GearUseFeaturesSeine bean, final TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder) throws DataSourceException { -// -// String txName = "getGearUseFeaturesMeasurementSeine : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<GearUseFeaturesSeine> dao = source.getDAO(tx, GearUseFeaturesSeine.class); -// GearUseFeaturesSeine gearUseFeaturesSeine = dao.findByTopiaId(bean.getTopiaId()); -// List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); -// for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { -// GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); -// measurementSource.getGearCaracteristic().getGearCaracteristicType(); -// binder.load(measurementSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(DataSource source, String gearId) throws DataSourceException { -// -// String txName = "getDefaultGearUseFeaturesMeasurementLongline : " + gearId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); -// Gear gear = gearDao.findByTopiaId(gearId); -// -// Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); -// List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); -// for (GearCaracteristic caracteristic : gearCaracteristic) { -// GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); -// target.setGearCaracteristic(caracteristic); -// result.add(target); -// } -// -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLongline(DataSource source, GearUseFeaturesLongline bean, final TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder) throws DataSourceException { -// -// String txName = "getGearUseFeaturesMeasurementLongline : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<GearUseFeaturesLongline> dao = source.getDAO(tx, GearUseFeaturesLongline.class); -// GearUseFeaturesLongline gearUseFeaturesLongline = dao.findByTopiaId(bean.getTopiaId()); -// List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); -// for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { -// GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); -// measurementSource.getGearCaracteristic().getGearCaracteristicType(); -// binder.load(measurementSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - public <E extends TopiaEntity> List<String> getEntityIds(DataSource source, Class<E> refClass) - throws DataSourceException { - - String txName = "getEntityIds : " + refClass; - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<E> dao = source.getDAO(tx, refClass); - List<String> result = dao.findAllIds(); - return result; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - -// public List<TripMapPoint> loadTripMapActivityPoints(DataSource source, String id) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "loadTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// -// List<TripMapPoint> tripMapPoints; -// -// try { -// if (Entities.isSeineId(id)) { -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// -// tripMapPoints = dao.extractTripMapActivityPoints(id); -// -// } else if (Entities.isLonglineId(id)) { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// -// tripMapPoints = dao.extractTripMapActivityPoints(id); -// -// } else { -// throw new ObserveTechnicalException(String.format("id '%s' is not seine id or longe line id", id)); -// } -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally{ -// closeTransaction(source, tx, txName); -// } -// return tripMapPoints; -// } - - - // ------------------------------------------------------------------------ - // -- Méthodes de chargement de données - // ------------------------------------------------------------------------ - - -// public TopiaEntity loadEntity(DataSource source, -// String id, -// boolean decorate) throws DataSourceException { -// -// String txName = "loadEntity : " + id; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaEntity result = tx.findByTopiaId(id); -// //FIXME Find a better way to do this... -// if (result instanceof ActivitySeine) { -// -// // on charge toujours sa calée -// ((ActivitySeine) result).getSetSeine(); -// } -// if (result instanceof ActivityLongline) { -// -// // on charge toujours sa calée -// ((ActivityLongline) result).getSetLongline(); -// } -// if (decorate) { -// Decorator<TopiaEntity> decorator = -// getDecoratorService().getDecorator(result); -// if (decorator == null) { -// if (log.isWarnEnabled()) { -// log.warn("Decorateur non trouvé pour l'objet " + result); -// } -// } else { -// decorator.toString(result); -// } -// } -// return result; -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - - public <E extends TopiaEntity> void loadEditEntity(DataSource source, - String entityId, - TopiaExecutor<E> updator) throws DataSourceException { - - String txName = "loadEditEntity :: " + entityId; - TopiaContext tx = beginTransaction(source, txName); - try { - E bean = source.findByTopiaId(tx, entityId); - updator.execute(tx, bean); - } catch (Exception e) { - throw new DataSourceException("Can not load edit entity " + entityId, e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - -// public <E extends TopiaEntity> List<E> loadEntityAssociation(DataSource source, -// Class<E> entityClass, -// String property, -// String parentId) throws DataSourceException { -// -// TopiaContext tx = beginTransaction(source, "loadEntitiesWithProperties"); -// try { -// -// Class<TopiaEntity> parentclass = TopiaId.getClassName(parentId); -// -// TopiaDAO<?> parentDao = source.getDAO(tx, parentclass); -// -// // get parent entity -// TopiaEntity parent = parentDao.findByTopiaId(parentId); -// -// // get parent operator -// EntityOperator<TopiaEntity> operator = -// ObserveDAOHelper.getOperator(parentclass); -// -// // get property from parent -// List<E> result = (List<E>) operator.get(property, parent); -// -// DecoratorService decoratorService = getDecoratorService(); -// -// if (decoratorService != null) { -// -// // chargement des rendus -// Decorator<E> decorator = -// decoratorService.getDecoratorByType(entityClass); -// for (E e : result) { -// decorator.toString(e); -// } -// } -// return result; -// } catch (TopiaException e) { -// throw new DataSourceException( -// "Can not obtain topiaentity " + -// parentId, e, "loadEntitiesWithProperties"); -// } finally { -// closeTransaction(source, tx, "loadEntitiesWithProperties"); -// } -// } - - public <E extends TopiaEntity, C extends TopiaEntity> void copyAssociation(Class<E> entityType, - Class<C> childEntityType, - String propertyName, - E source, - E target, - TopiaContext targetTx) throws TopiaException { - - EntityOperator<E> operator = ObserveDAOHelper.getOperator(entityType); - - Collection<C> sourceList = (Collection<C>) operator.get(propertyName, source); - - TopiaDAO<C> dao = ObserveDAOHelper.getDAO(targetTx, childEntityType); - - List<C> targetList = Lists.newArrayListWithCapacity(sourceList.size()); - for (C sourceC : sourceList) { - - C targetC = dao.findByTopiaId(sourceC.getTopiaId()); - targetList.add(targetC); - } - operator.set(propertyName, target, targetList); - - } - -// public String getSensorUsedDataFilename(DataSource source, SensorUsed sensorUSed) throws DataSourceException { -// -// String txName = "getSensorUsedDataFilename"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLongline tripLongline = source.getOpen(tx, TripLongline.class); -// -// StringBuilder filenameBuilder = new StringBuilder("sensorData"); -// String code = tripLongline.getVessel().getCode(); -// filenameBuilder.append("-").append(code); -// -// Date startDate = tripLongline.getStartDate(); -// filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); -// -// SensorType sensorType = sensorUSed.getSensorType(); -// if (sensorType != null && sensorType.getCode() != null) { -// filenameBuilder.append("-").append(sensorType.getCode()); -// } -// -// String sensorSerialNo = sensorUSed.getSensorSerialNo(); -// if (sensorSerialNo != null) { -// filenameBuilder.append("-").append(sensorSerialNo); -// } -// filenameBuilder.append("-").append(sensorUSed.getDataFilename()); -// -// String filename = filenameBuilder.toString(); -// return filename; -// -// } finally { -// -// closeTransaction(source, tx, txName); -// -// } -// -// } - -// public String getTdrDataFilename(DataSource source, Tdr tdr) throws DataSourceException { -// -// String txName = "getTdrDataFilename"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLongline tripLongline = source.getOpen(tx, TripLongline.class); -// -// StringBuilder filenameBuilder = new StringBuilder("tdr"); -// String code = tripLongline.getVessel().getCode(); -// filenameBuilder.append("-").append(code); -// -// Date startDate = tripLongline.getStartDate(); -// filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); -// -// String homeId = tdr.getHomeId(); -// if (homeId != null) { -// filenameBuilder.append("-").append(homeId); -// } -// -// String serialNo = tdr.getSerialNo(); -// if (serialNo != null) { -// filenameBuilder.append("-").append(serialNo); -// } -// filenameBuilder.append("-").append(tdr.getDataFilename()); -// -// String filename = filenameBuilder.toString(); -// return filename; -// -// } finally { -// -// closeTransaction(source, tx, txName); -// -// } -// -// } - -// public <E extends TopiaEntity> List<E> loadDecoratedEntities(DataSource source, -// Class<E> entityClass) throws DataSourceException { -// -// String txName = "loadEntities :: " + entityClass.getName(); -// TopiaContext tx = beginTransaction(source, txName); -// Decorator<E> decorator = getDecoratorService().getDecoratorByType(entityClass); -// try { -// List<E> result = -// source.loadDecoratedEntities(tx, entityClass, decorator); -// return result; -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - - public <E extends TopiaEntity> List<E> loadDecoratedEntities(DataSource source, - Class<E> entityClass, - TopiaExecutor<E> loador) throws DataSourceException { - - String txName = "loadDecoratedEntities :: " + entityClass.getName(); - TopiaContext tx = beginTransaction(source, txName); - Decorator<E> decorator = getDecoratorService().getDecoratorByType(entityClass); - try { - List<E> result = - source.loadDecoratedEntities(tx, entityClass, decorator); - - if (CollectionUtils.isNotEmpty(result)) { - for (E e : result) { - try { - loador.execute(tx, e); - } catch (TopiaException e1) { - throw new DataSourceException( - "Can not obtain load entity " + e.getTopiaId(), e1, txName); - } - } - } - return result; - } finally { - closeTransaction(source, tx, txName); - } - } - - // ------------------------------------------------------------------------ - // -- Méthodes de création - mise à jour - suppression de données - // ------------------------------------------------------------------------ - - - public <E extends TopiaEntity, P extends TopiaEntity> E preCreate(DataSource source, - String parentBeanId, - E bean, - Loador<E> binder, - TopiaExecutor2<P, E> creator) throws DataSourceException { - - String txName = "preCreate"; - TopiaContext tx = beginTransaction(source, txName); - try { - P parentBean = null; - - if (parentBeanId != null) { - - // il y a un parent a recuperer - try { - parentBean = source.<P>findByTopiaId(tx, parentBeanId); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(PARENT_BEAN, parentBean); - } - - // on charge le bean - binder.load(null, bean, true); - - checkNotNullAndNoneExistingEntity(BEAN, bean); - - E result; - if (creator == null) { - result = bean; - } else { - try { - result = creator.execute(tx, parentBean, bean); - } catch (TopiaException ex) { - throw new DataSourceException(ex, txName); - } - } - return result; - } finally { - closeTransaction(source, tx, txName); - } - } - - - public <E extends TopiaEntity, P extends TopiaEntity> E create(DataSource source, - String parentBeanId, - E bean, - Loador<E> binder, - TopiaExecutor2<P, E> creator) throws DataSourceException { - - checkNotNullAndNoneExistingEntity("bean", bean); - - String txName = "create"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - P parentBean = null; - - if (parentBeanId != null) { - - // il y a un parent a recuperer - try { - parentBean = source.<P>findByTopiaId(tx, parentBeanId); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(PARENT_BEAN, parentBean); - } - - E beanToSave = creator.execute(tx, parentBean, bean); - - if (binder != null) { - binder.load(bean, beanToSave, false); - } - - if (parentBean == null) { - - // sauvegarde de l'entité autolastNamee - TopiaDAO<E> dao = source.getDAO(tx, beanToSave); - dao.update(beanToSave); - } else { - - // sauvegarde du père de l'entité - TopiaDAO<P> dao = source.getDAO(tx, parentBean); - dao.update(parentBean); - } - - commitTransaction(source, tx, txName); - return beanToSave; - } catch (Exception e) { - rollbackTransaction(source, tx, txName); - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public <E extends TopiaEntity, P extends TopiaEntity> E update(DataSource source, - String parentBeanId, - E bean, - TopiaExecutor2<P, E> updator) throws DataSourceException { - - checkNotNullAndExistingEntity("bean", bean); - - String txName = "update"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - P parentBean = null; - - if (parentBeanId != null) { - - // il y a un parent a recuperer - try { - parentBean = source.<P>findByTopiaId(tx, parentBeanId); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(PARENT_BEAN, parentBean); - } - - E beanToSave; - - try { - beanToSave = source.<E>findByTopiaId(tx, bean.getTopiaId()); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(BEAN, beanToSave); - - beanToSave = updator.execute(tx, parentBean, beanToSave); - - if (parentBean == null) { - - // sauvegarde de l'entité autolastNamee - TopiaDAO<E> dao = source.getDAO(tx, beanToSave); - dao.update(beanToSave); - } else { - - // sauvegarde du père de l'entité - TopiaDAO<P> dao = source.getDAO(tx, parentBean); - dao.update(parentBean); - } - - commitTransaction(source, tx, txName); - return beanToSave; - } catch (Exception e) { - rollbackTransaction(source, tx, txName); - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - -// public void updateOpenProperty(DataSource source, -// String id, -// boolean newValue) throws DataSourceException { -// -// if (!source.canWriteData()) { -// -// // pas autorisé à écrire des données observer -// return; -// } -// -// String txName = "updateOpenProperty :: " + id + " - " + newValue; -// TopiaContext tx = null; -// try { -// tx = beginTransaction(source, txName); -// OpenableEntity beanToSave = source.findByTopiaId(tx, id); -// beanToSave.setOpen(newValue); -// commitTransaction(source, tx, txName); -// } catch (TopiaException e) { -// throw new DataSourceException( -// "Can not update open state for " + id, e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - - @SuppressWarnings({"unchecked"}) - public <P extends TopiaEntity, E extends TopiaEntity> void delete(DataSource source, - String parentBeanId, - E bean, - TopiaExecutor2<P, E> deletor) throws DataSourceException { - - checkNotNullAndExistingEntity("bean", bean); - - String txName = "delete"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - P parentBean = null; - - TopiaDAO<TopiaEntity> parentDao = null; - - if (parentBeanId != null) { - parentBean = (P) tx.findByTopiaId(parentBeanId); - - checkNotNullAndExistingEntity("parentBean", parentBean); - - parentDao = source.getDAO(tx, (TopiaEntity) parentBean); - } - - E beanToDelete = (E) tx.findByTopiaId(bean.getTopiaId()); - - deletor.execute(tx, parentBean, beanToDelete); - - if (parentBeanId != null) { - - parentDao.update(parentBean); - } - - commitTransaction(source, tx, txName); - } catch (Exception e) { - rollbackTransaction(source, tx, "create"); - if (e instanceof DataSourceException) { - throw (DataSourceException) e; - } - throw new DataSourceException(e, txName); - } - } - - - public void close() { - decoratorService = null; - dataContext = null; - } - - - public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { - TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); - } - - - public <E extends TopiaEntity> void checkNotNullAndExistingEntity(String variableName, E entity) { - TopiaEntityHelper.checkNotNullAndExistingEntity(variableName, entity); - } - - - public DiffState.DiffStateMap buildReferentielDifferentiel(final DataSource srcService, - final DataSource dstService, - final SendMessageAble messanger) - throws DataSourceException { - try { - final DiffState.DiffStateMap result = DiffState.newMap(); - ReferenceEntities.walk(new ReferenceEntities.ReferentielWalker() { - - - public <E extends TopiaEntity> void walk( - Class<E> contractClass) throws Exception { - - String s = t(DecoratorService.getEntityLabel(contractClass)); - String message = - t("observe.service.build.synchro.referentiel", s); - if (messanger != null) { - messanger.sendMessage(message); - } - if (log.isInfoEnabled()) { - log.info(message); - } - List<E> list = getList(srcService, contractClass); - List<E> list2 = getList(dstService, contractClass); - DiffState.DiffStateMap tmp; - // recuperation du differentiel pour le type d'entitétmp = - tmp = TopiaEntityHelper.buildDifferentiel(list, list2); - // ajout au resultat - DiffState.addAll(result, tmp); - // on nettoie - DiffState.clear(tmp); - } - }); - DiffState.removeEmptyStates(result); - return result; - } catch (DataSourceException ex) { - throw ex; - } catch (Exception ex) { - throw new DataSourceException(ex, "buildReferentielDifferentiel"); - } - } - - protected <E extends TopiaEntity> List<E> getList0(DataSource source, - Class<E> klass, - Predicate<E> predicate, - TopiaEntityBinder<E> loador) throws Exception { - - TopiaContext tx = beginTransaction(source, "getList0 : " + klass); - try { - TopiaDAO<E> dao = source.getDAO(tx, klass); - List<E> result = dao.findAll(); - - if (predicate != null) { - - // use a filter - result = Lists.newArrayList(Iterables.filter(result, predicate)); - - } - if (loador != null) { - for (E e : result) { - loador.obtainProperties(e); - } - } - return result; - } finally { - closeTransaction(source, tx, "getList0 : " + klass); - } - } - - // ------------------------------------------------------------------------ - // -- Property change support - // ------------------------------------------------------------------------ - - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - -// public void removePropertyChangeListeners() { -// for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) { -// removePropertyChangeListener(listener); -// } -// } - - public <E extends TopiaEntity> void addReferentielPropertyChangeListener(Class<E> entitClass, PropertyChangeListener listener) { - ObserveEntityEnum constant = ObserveEntityEnum.valueOf(entitClass); - String propertyName = getReferentielPropertyName(constant); - log.info(propertyName + " :" + listener); - addPropertyChangeListener(propertyName, listener); - } - -// public <E extends TopiaEntity> void addDataPropertyChangeListener(Class<E> entitClass, PropertyChangeListener listener) { -// ObserveEntityEnum constant = ObserveEntityEnum.valueOf(entitClass); -// String propertyName = getDataPropertyName(constant); -// addPropertyChangeListener(propertyName, listener); -// } - - public void removeReferentielPropertyChangeListeners() { - for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { - String propertyName = getReferentielPropertyName(constant); - PropertyChangeListener[] changeListeners = pcs.getPropertyChangeListeners(propertyName); - if (log.isDebugEnabled()) { - log.debug(propertyName + " :" + changeListeners.length); - } - for (PropertyChangeListener listener : - changeListeners) { - if (log.isDebugEnabled()) { - log.debug(propertyName + " :" + listener); - } - removePropertyChangeListener(propertyName, listener); - } - } - } - - protected String getReferentielPropertyName(ObserveEntityEnum constant) { - return DataSource.REFERENTIEL_PROPERTY_KEY + "#" + constant.name(); - } - - protected String getDataPropertyName(ObserveEntityEnum constant) { - return DataSource.DATA_PROPERTY_KEY + "#" + constant.name(); - } - - protected void firePropertyChangedEvent(PropertyChangeEvent event, - String message, - PropertyChangeListener... listeners) { - for (PropertyChangeListener listener : listeners) { - if (log.isInfoEnabled()) { - log.info(message + ", notifiy listener " + listener); - } - listener.propertyChange(event); - } - } - - protected PropertyChangeListener[] getPropertyChangeListener(String propertyName) { - List<PropertyChangeListener> result = new ArrayList<PropertyChangeListener>(); - for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) { - if (listener instanceof PropertyChangeListenerProxy) { - PropertyChangeListenerProxy proxy = - (PropertyChangeListenerProxy) listener; - if (!propertyName.equals(proxy.getPropertyName())) { - continue; - } - } - result.add(listener); - } - return result.toArray(new PropertyChangeListener[result.size()]); - } - -// public void fireOpenChanged(DataSource source) { -// -// String propertyName = DataSource.OPEN_PROPERTY_KEY; -// -// if (log.isInfoEnabled()) { -// log.info("Open context changed, will notifiy listeners [" + propertyName + "]..."); -// } -// -// // obtain all opens ids -// try { -// -// String[] ids = getOpenIds(source); -// -// String message = Arrays.toString(ids); -// -// PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); -// if (listeners.length == 0) { -// // pas de listener, on ne fait rien -// -// -// if (log.isInfoEnabled()) { -// log.info("Open context " + message + ", No listener, skip"); -// } -// return; -// } -// -// PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, ids); -// firePropertyChangedEvent(event, "Open context " + message + " changed", listeners); -// -// } catch (DataSourceException e) { -// if (log.isErrorEnabled()) { -// log.error("Could not fire open changed", e); -// } -// } -// } - - protected void fireReferentielChanged(DataSource source, ObserveEntityEnum... types) { - for (ObserveEntityEnum constant : types) { - try { - String propertyName = getReferentielPropertyName(constant); - if (log.isInfoEnabled()) { - log.info("Referentiel [" + constant + "] changed, will notifiy listeners [" + propertyName + "]..."); - } - - PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); - if (listeners.length == 0) { - // pas de listener, on ne fait rien - - if (log.isInfoEnabled()) { - log.info("Referentiel [" + constant + "] No listener, skip"); - } - return; - } - - List<? extends TopiaEntity> entities = getList(source, constant.getContract()); - if (log.isInfoEnabled()) { - log.info("Referentiel [" + constant + "] new size " + entities.size()); - } - - PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, entities); - firePropertyChangedEvent(event, "Referentiel [" + constant + "] changed", listeners); - } catch (DataSourceException e) { - if (log.isErrorEnabled()) { - log.error("Could not fire referentiel [" + constant + "] changed"); - } - } - } - } - - protected void fireDataChanged(DataSource source, TopiaEntity... types) { - for (TopiaEntity entity : types) { - - ObserveEntityEnum constant = - ObserveEntityEnum.valueOf(entity); - - // une entite donnee observer a ete modifiee, supprimer ou cree - // on notifie tous les écouteurs des données observer - - String propertyName = getDataPropertyName(constant); - if (log.isInfoEnabled()) { - log.info("Data [" + entity.getTopiaId() + "] changed, will notifiy listeners [" + propertyName + "]..."); - } - - PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); - if (listeners.length == 0) { - // pas de listener, on ne fait rien - - if (log.isDebugEnabled()) { - log.debug("Data [" + entity.getTopiaId() + "] No listener, skip"); - } - return; - } - - PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, entity); - firePropertyChangedEvent(event, "Data [" + entity + "] changed", listeners); - } - } - -// public void deleteTrip(DataSource source, String tripId) throws DataSourceException { -// -// String txName = "deleteTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// if (Entities.isSeineId(tripId)) { -// -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// TripSeine result = dao.findByTopiaId(tripId); -// dao.delete(result); -// -// } else { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// TripLongline result = dao.findByTopiaId(tripId); -// dao.delete(result); -// -// } -// -// skipTransactionListener = true; -// try { -// -// commitTransaction(source, tx, txName); -// -// } finally { -// skipTransactionListener = false; -// } -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } -} diff --git a/observe-business/src/test/java/fr/ird/observe/db/DataServiceTest.java b/observe-business/src/test/java/fr/ird/observe/db/DataServiceTest.java deleted file mode 100644 index d720a02..0000000 --- a/observe-business/src/test/java/fr/ird/observe/db/DataServiceTest.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.db; - -import fr.ird.observe.DataService; -import fr.ird.observe.IObserveConfig; -import fr.ird.observe.db.impl.H2DataSourceConfig; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.test.TestHelper; -import fr.ird.observe.util.Scripts; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.event.TopiaEntityEvent; -import org.nuiton.topia.event.TopiaEntityListener; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; - -/** - * Tests the {@link DataService}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class DataServiceTest { - - - /** Logger */ - private static final Log log = - LogFactory.getLog(DataServiceTest.class); - - - @BeforeClass - public static void init() throws Exception { - - TestHelper.initTest(DataServiceTest.class); - - TestHelper.createApplicationContext(); - - TestHelper.setConfig(IObserveConfig.DB_VERSION, - Scripts.V_LAST.toString()); - } - - @Before - public void setUp() { - hits = 0; - } - - @After - public void tearDown() throws Exception { - DataSourceFactory.dispose(); - } - - @Test - public void testSetDataSource2() throws Exception { - - DataService service = new DataService(); - - service.addReferentielPropertyChangeListener(Program.class, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - increment(); - } - }); - - File dir = TestHelper.newLocalDB("testSetDataSource2"); - - H2DataSourceConfig config = DataSourceFactory.newH2ConfigEmpty( - "testSetDataSource2", - dir, - TestHelper.TEST_H2_LOGIN, - TestHelper.TEST_H2_PASSWORD - ); - - Assert.assertNotNull(config); - - DataSource dataSource = DataSourceFactory.newService(config); - - dataSource.doOpen(); - - Assert.assertTrue(dataSource.isOpen()); - - DBTestHelper.assertSchemaCreated( - dataSource, - true - ); - - service.registerDataSource(dataSource); - -// Assert.assertTrue(service.isEnabled()); - - dataSource.getRootCtxt().addTopiaEntityListener(listener); - - Assert.assertEquals(0, hits); - - Program program; - TopiaContext tx = service.beginTransaction(dataSource, "createProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.create(Program.PROPERTY_CODE, "1", Program.PROPERTY_LABEL1, "label1", Program.PROPERTY_LABEL2, "label2"); - - service.commitTransaction(dataSource, tx, "createProgram"); - } finally { - service.closeTransaction(dataSource, tx, "createProgram"); - } - - // un hit de creation - Assert.assertEquals(1, hits); - - tx = service.beginTransaction(dataSource, "loadProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - - } finally { - service.closeTransaction(dataSource, tx, "loadProgram"); - } - - // pas de hit de load - Assert.assertEquals(1, hits); - - - tx = service.beginTransaction(dataSource, "updateProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.findByTopiaId(program.getTopiaId()); - - program.setLabel3("label3"); - dao.update(program); - - service.commitTransaction(dataSource, tx, "updateProgram"); - } finally { - service.closeTransaction(dataSource, tx, "updateProgram"); - } - - // un hit de update - Assert.assertEquals(2, hits); - - tx = service.beginTransaction(dataSource, "deleteProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - dao.delete(program); - - service.commitTransaction(dataSource, tx, "deleteProgram"); - } finally { - service.closeTransaction(dataSource, tx, "deleteProgram"); - } - - - // un hit de delete - Assert.assertEquals(3, hits); - - } - - @Test - public void testSetDataSource() throws Exception { - - DataService service = new DataService(); - - File dir = TestHelper.newLocalDB("testSetDataSource"); - - H2DataSourceConfig config = DataSourceFactory.newH2ConfigEmpty( - "testCreateH2ConfigEmpty", - dir, - TestHelper.TEST_H2_LOGIN, - TestHelper.TEST_H2_PASSWORD - ); - - Assert.assertNotNull(config); - - DataSource dataSource = DataSourceFactory.newService(config); - - dataSource.doOpen(); - - Assert.assertTrue(dataSource.isOpen()); - - DBTestHelper.assertSchemaCreated( - dataSource, - true - ); - - service.registerDataSource(dataSource); - -// Assert.assertTrue(service.isEnabled()); - - dataSource.getRootCtxt().addTopiaEntityListener(listener); - - Assert.assertEquals(0, hits); - Program program; - TopiaContext tx = service.beginTransaction(dataSource, "createProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.create(Program.PROPERTY_CODE, "1", Program.PROPERTY_LABEL1, "label1", Program.PROPERTY_LABEL2, "label2"); - - service.commitTransaction(dataSource, tx, "createProgram"); - } finally { - service.closeTransaction(dataSource, tx, "createProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de creation - Assert.assertEquals(1, hits); - - tx = service.beginTransaction(dataSource, "loadProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - - } finally { - service.closeTransaction(dataSource, tx, "loadProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de load -// Assert.assertEquals(1, hits); - Assert.assertEquals(2, hits); - - - tx = service.beginTransaction(dataSource, "updateProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - - program.setLabel3("label3"); - dao.update(program); - - service.commitTransaction(dataSource, tx, "updateProgram"); - } finally { - service.closeTransaction(dataSource, tx, "updateProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de load + update -// Assert.assertEquals(2, hits); - Assert.assertEquals(4, hits); - - tx = service.beginTransaction(dataSource, "deleteProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.findByTopiaId(program.getTopiaId()); - dao.delete(program); - - service.commitTransaction(dataSource, tx, "deleteProgram"); - } finally { - service.closeTransaction(dataSource, tx, "deleteProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de load + delete -// Assert.assertEquals(3, hits); - Assert.assertEquals(6, hits); - - } - - protected int hits; - - public void increment() { - hits++; - } - - final TopiaEntityListener listener = new TopiaEntityListener() { - - @Override - public void create(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - - @Override - public void load(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - - @Override - public void update(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - - @Override - public void delete(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - }; -} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java new file mode 100644 index 0000000..d079a72 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java @@ -0,0 +1,4 @@ +package fr.ird.observe.entities.referentiel; + +public class LengthWeightParameterDAOImpl<E extends LengthWeightParameter> extends LengthWeightParameterDAOAbstract<E> { +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java new file mode 100644 index 0000000..97f220e --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java @@ -0,0 +1,7 @@ +package fr.ird.observe.entities.referentiel; + +import javax.annotation.Generated; + +@Generated(value = "org.nuiton.topia.generator.EntityDAOTransformer", date = "Sat May 02 12:01:39 CEST 2015") +public class SexDAOImpl<E extends Sex> extends SexDAOAbstract<E> { +} //SexDAOImpl<E extends Sex> diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java new file mode 100644 index 0000000..865a5c5 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public interface ReplicationService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java new file mode 100644 index 0000000..dcac5bc --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class ReplicationServiceImpl implements ReplicationService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java new file mode 100644 index 0000000..9b58b2e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java @@ -0,0 +1,18 @@ +package fr.ird.observe.services.operation; + +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.services.ObserveService; + +import java.util.Set; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ComputeDataService extends ObserveService{ + + void consolidateTrips(SendMessageAble messager, Set<String> tripIds); + +} diff --git a/observe-business/src/main/java/fr/ird/observe/ConsolidateDataService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java similarity index 80% rename from observe-business/src/main/java/fr/ird/observe/ConsolidateDataService.java rename to observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java index ef0999e..e56a919 100644 --- a/observe-business/src/main/java/fr/ird/observe/ConsolidateDataService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java @@ -1,32 +1,14 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe; +package fr.ird.observe.services.operation; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.LengthWeightComputable; import fr.ird.observe.entities.constants.seine.NonTargetCatchComputedValueSource; import fr.ird.observe.entities.constants.seine.SchoolType; @@ -43,11 +25,12 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.referential.ReferentialService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.topia.persistence.util.TopiaEntityRef; @@ -58,25 +41,24 @@ import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.SortedMap; import static org.nuiton.i18n.I18n.t; /** - * Le service pour consolider les données observers. - * <p/> - * Il s'agit de pouvoir calculer le type de banc d'une activité et de calculer - * les données déductibles des données observées (sur les discardeds faune et les - * échantillons via les relations taille-weight et autres...). + * FIXME A revoir, utiliser un context pour ne pas avoir d'état dans le service + on ne peut plus utiliser de messager + * On retounera un objet de type result. + * + * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since 1.8 + * @since 4.0 */ -public class ConsolidateDataService { +public class ComputeDataServiceImpl extends AbstractObserveService implements ComputeDataService { - /** Logger */ - private static final Log log = - LogFactory.getLog(ConsolidateDataService.class); + /** Logger. */ + private static final Log log = LogFactory.getLog(ComputeDataServiceImpl.class); private static final String MESSAGE_FORMAT_3 = "[%1$s] %2$s calculé : %3$s (%4$s:%5$s, %6$s:%7$s)"; @@ -87,7 +69,7 @@ public class ConsolidateDataService { TargetLength.PROPERTY_WEIGHT, TargetLength.PROPERTY_WEIGHT_SOURCE); - protected final BeanMonitor nonTargetSampleMonitor = new BeanMonitor( + protected final BeanMonitor nonTargetLengthMonitor = new BeanMonitor( NonTargetLength.PROPERTY_LENGTH, NonTargetLength.PROPERTY_LENGTH_SOURCE, NonTargetLength.PROPERTY_WEIGHT, @@ -104,40 +86,27 @@ public class ConsolidateDataService { NonTargetCatch.PROPERTY_TOTAL_COUNT_COMPUTED_SOURCE ); - protected final BeanMonitor speciesMonitor = new BeanMonitor( - NonTargetLength.PROPERTY_LENGTH_SOURCE, - NonTargetLength.PROPERTY_WEIGHT, - NonTargetLength.PROPERTY_WEIGHT_SOURCE); - - protected Decorator<TripSeine> mareeDecorator; - - protected Decorator<Species> speciesDecorator; - - protected Decorator<ActivitySeine> activityDecorator; - protected String nonTargetCatcheLabel; protected String speciesLabel; - protected String speciesThonLabel; + protected ReferentialService referentialService; - protected final SendMessageAble LOG_ESSAGER = new SendMessageAble() { - @Override - public void sendMessage(String message) { - if (log.isInfoEnabled()) { - log.info(message); - } + protected ReferentialService getReferentialService() { + if (referentialService == null) { + referentialService = newService(ReferentialService.class); } - }; + return referentialService; + } - public String getNonTargetCatcheLabel() { + protected String getNonTargetCatcheLabel() { if (nonTargetCatcheLabel == null) { nonTargetCatcheLabel = t(DecoratorService.getEntityLabel(NonTargetCatch.class)); } return nonTargetCatcheLabel; } - public String getSpeciesLabel() { + protected String getSpeciesLabel() { if (speciesLabel == null) { speciesLabel = t(DecoratorService.getEntityLabel(Species.class)); } @@ -145,45 +114,77 @@ public class ConsolidateDataService { } - public String decorate(TripSeine maree) { - if (mareeDecorator == null) { - mareeDecorator = getDecoratorService().getDecoratorByType(TripSeine.class); - } - return mareeDecorator.toString(maree); + protected void clear() { + + nonTargetLengthMonitor.setBean(null); + targetLengthMonitor.setBean(null); + nonTargetCatchMonitor.setBean(null); + nonTargetCatcheLabel = null; + speciesLabel = null; + } - public String decorate(Species species) { - if (speciesDecorator == null) { - speciesDecorator = - getDecoratorService().getDecoratorByType(Species.class); + @Override + public void consolidateTrips(SendMessageAble messager, Set<String> tripIds) { + + if (messager==null) { + + messager = new SendMessageAble() { + + @Override + public void sendMessage(String message) { + if (log.isInfoEnabled()) { + log.info(message); + } + } + }; + } - return speciesDecorator.toString(species); - } -// public String decorate(Species species) { -// if (speciesThonDecorator == null) { -// speciesThonDecorator = -// getDecoratorService().getDecoratorByType(Species.class); -// } -// return speciesThonDecorator.toString(species); -// } + TopiaDAO<TripSeine> dao = getDao(TripSeine.class); + + List<TripSeine> toUpdate = new ArrayList<TripSeine>(tripIds.size()); + + for (String tripId : tripIds) { + + if (Entities.isSeineId(tripId)) { + + TripSeine trip = dao.findByTopiaId(tripId); + + boolean needUpdate = consolidateTripSeine(messager, trip); + if (needUpdate) { + + // on met a jour la maree en base + dao.update(trip); + + // on conserve une reference sur la maree mise à jour + toUpdate.add(trip); + + } + + } + + } + + // on commite si quelque chose a ete mise a jour + boolean needCommit = !toUpdate.isEmpty(); + + if (needCommit) { + + messager.sendMessage(t("observe.message.consolidate.save.changes", toUpdate.size())); + getTransaction().commitTransaction(); - public String decorate(ActivitySeine activitySeine) { - if (activityDecorator == null) { - activityDecorator = - getDecoratorService().getDecoratorByType(ActivitySeine.class); } - return activityDecorator.toString(activitySeine); + } - public boolean consolidateTrip(SendMessageAble messager, - TopiaContext tx, - TripSeine maree) throws Exception { - String mareeStr = decorate(maree); + protected boolean consolidateTripSeine(SendMessageAble messager, TripSeine maree) { + + clear(); - SendMessageAble messager1 = getMessager(messager); - messager1.sendMessage( - t("observe.message.consolidate.start.maree", mareeStr)); + String mareeStr = decorateEntity(maree); + + messager.sendMessage(t("observe.message.consolidate.start.maree", mareeStr)); // recuperation des ids des sets de la maree String[] activityIds = getActivityIds(maree); @@ -191,9 +192,7 @@ public class ConsolidateDataService { if (activityIds.length == 0) { // pas de set dans cette maree, donc rien a sauvegarder - messager1.sendMessage( - t("observe.message.consolidate.no.activity.from.maree", - mareeStr)); + messager.sendMessage(t("observe.message.consolidate.no.activity.from.maree", mareeStr)); return false; } @@ -212,7 +211,6 @@ public class ConsolidateDataService { TopiaEntity[] path = ref.getPath(); Route route = (Route) path[path.length - 2]; boolean needUpdate = consolidateActivity(messager, - tx, maree, route, activitySeine @@ -224,38 +222,24 @@ public class ConsolidateDataService { if (toUpdate.isEmpty()) { // rien n'a ete modifie - messager1.sendMessage(t("observe.message.consolidate.nothing.to.save.for.maree", - mareeStr)); + messager.sendMessage(t("observe.message.consolidate.nothing.to.save.for.maree", mareeStr)); return false; + } // on devra mettre a jour en base la maree - messager1.sendMessage(t("observe.message.consolidate.maree.need.update", - mareeStr)); - return true; - } + messager.sendMessage(t("observe.message.consolidate.maree.need.update", mareeStr)); - public void clear() { + return true; - nonTargetSampleMonitor.setBean(null); - targetLengthMonitor.setBean(null); - nonTargetCatchMonitor.setBean(null); - mareeDecorator = null; - activityDecorator = null; - speciesDecorator = null; - nonTargetCatcheLabel = null; - speciesLabel = null; - speciesThonLabel = null; } protected boolean consolidateActivity(SendMessageAble messager, - TopiaContext tx, TripSeine maree, Route route, - ActivitySeine activity) throws Exception { + ActivitySeine activity) { - getMessager(messager).sendMessage(t("observe.message.consolidate.start.activity", - decorate(activity))); + messager.sendMessage(t("observe.message.consolidate.start.activity", decorateEntity(activity))); boolean needUpdate = false; SetSeine set = activity.getSetSeine(); @@ -279,7 +263,6 @@ public class ConsolidateDataService { targetLengthMonitor.setBean(targetLength); updateLengthWeightAble( - tx, maree, route.getDate(), targetLength.getSpecies(), @@ -305,17 +288,16 @@ public class ConsolidateDataService { for (NonTargetLength nonTargetLength : nonTargetSample.getNonTargetLength()) { - nonTargetSampleMonitor.setBean(nonTargetLength); + nonTargetLengthMonitor.setBean(nonTargetLength); updateLengthWeightAble( - tx, maree, route.getDate(), nonTargetLength.getSpecies(), nonTargetLength.getSex(), nonTargetLength ); - if (nonTargetSampleMonitor.wasModified()) { + if (nonTargetLengthMonitor.wasModified()) { needUpdate = true; } } @@ -353,7 +335,6 @@ public class ConsolidateDataService { } updateNonTargetCatch( - tx, maree, set, route.getDate(), @@ -368,30 +349,18 @@ public class ConsolidateDataService { return needUpdate; } - protected boolean allNonTargetCatchDataFilled(NonTargetCatch nonTargetCatch) { - return Iterables.all( - Sets.newHashSet(nonTargetCatch.getCatchWeight(), - nonTargetCatch.getTotalCount(), - nonTargetCatch.getMeanWeight(), - nonTargetCatch.getMeanLength()), - Predicates.notNull()); - } - - protected void updateNonTargetCatch(TopiaContext tx, - TripSeine maree, + protected void updateNonTargetCatch(TripSeine maree, SetSeine set, Date jour, - NonTargetCatch nonTargetCatch) throws DataSourceException { + NonTargetCatch nonTargetCatch) { final Species species = nonTargetCatch.getSpecies(); // récupération du référentiel - LengthWeightParameter parametrage = - getDataService().findLengthWeightParameter(tx, - species, - maree.getOcean(), - null, // pas de sexe spécifié - jour); + LengthWeightParameter parametrage = getReferentialService().findLengthWeightParameter(species, + maree.getOcean(), + null, // pas de sexe spécifié + jour); // -- Cas n°1 (calcul uniquement à partir des relations taille - poids) updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); @@ -408,6 +377,7 @@ public class ConsolidateDataService { if (!set.isNonTargetSampleEmpty()) { samples = Collections2.filter(set.getNonTargetSample().iterator().next().getNonTargetLength(), new Predicate<NonTargetLength>() { + @Override public boolean apply(NonTargetLength input) { return species.equals(input.getSpecies()); @@ -448,7 +418,7 @@ public class ConsolidateDataService { } protected void updateNonTargetCatchByLengthWeightRelation(NonTargetCatch nonTargetCatch, - LengthWeightParameter parametrage) throws DataSourceException { + LengthWeightParameter parametrage) { // calcul via le paramétrage taille - poids updateLengthWeightAble( @@ -470,109 +440,7 @@ public class ConsolidateDataService { ); } - protected void computeNonTargetCatchTailleMoyenne(NonTargetCatch nonTargetCatch, - Collection<NonTargetLength> samples, - LengthWeightParameter parametrage) throws DataSourceException { - - Float meanLength = null; - NonTargetCatchComputedValueSource computedSource = null; - - if (CollectionUtils.isNotEmpty(samples)) { - - // on calcul la taille moyenne à partir des échantillons - float totalTaille = 0f; - int nbIndividus = 0; - for (NonTargetLength sample : samples) { - - Integer count = sample.getCount(); - Float length = sample.getLength(); - - if (count != null && length != null) { - nbIndividus += count; - totalTaille += length * count; - } - } - - if (nbIndividus != 0) { - - meanLength = totalTaille / nbIndividus; - - computedSource = NonTargetCatchComputedValueSource.FROM_SAMPLE; - } - } - - if (meanLength == null && parametrage != null) { - - // on prend directement la valeur fournie par le référentiel - - meanLength = parametrage.getMeanLength(); - computedSource = NonTargetCatchComputedValueSource.FROM_REFERENTIEL; - } - - if (meanLength != null) { - - // la taille moyenne a pu etre calculee, on la pousse alors - nonTargetCatch.setMeanLength(meanLength); - nonTargetCatch.setMeanLengthComputedSource(computedSource); - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - - } - - private void computeNonTargetCatchNombreEstime(NonTargetCatch nonTargetCatch, - Collection<NonTargetLength> samples, - LengthWeightParameter parametrage) throws DataSourceException { - - - if (CollectionUtils.isNotEmpty(samples)) { - - // on calcul la taille moyenne à partir des échantillons - int nbIndividus = 0; - for (NonTargetLength sample : samples) { - - Integer count = sample.getCount(); - - if (count != null) { - nbIndividus += count; - } - } - - if (nbIndividus != 0) { - - nonTargetCatch.setTotalCount(nbIndividus); - nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_SAMPLE); - - if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - } - } - } - - private void computeNonTargetCatchMeanValues(NonTargetCatch nonTargetCatch, - LengthWeightParameter parametrage) throws DataSourceException { - - if (parametrage != null) { - - nonTargetCatch.setMeanLength(parametrage.getMeanLength()); - nonTargetCatch.setMeanLengthComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); - - nonTargetCatch.setMeanWeight(parametrage.getMeanWeight()); - nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); - - if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - } - } - - protected void updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(NonTargetCatch nonTargetCatch) throws DataSourceException { + protected void updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(NonTargetCatch nonTargetCatch) { Float meanWeight = nonTargetCatch.getMeanWeight(); Float catchWeight = nonTargetCatch.getCatchWeight(); @@ -641,12 +509,11 @@ public class ConsolidateDataService { } } - protected void updateLengthWeightAble(TopiaContext tx, - TripSeine maree, + protected void updateLengthWeightAble(TripSeine maree, Date jour, Species species, Sex sex, - LengthWeightComputable e) throws DataSourceException { + LengthWeightComputable e) { Ocean ocean = maree.getOcean(); @@ -677,8 +544,7 @@ public class ConsolidateDataService { // recherche du parametrage adequate LengthWeightParameter parametrage = - getDataService().findLengthWeightParameter( - tx, + getReferentialService().findLengthWeightParameter( species, ocean, sex, @@ -691,7 +557,7 @@ public class ConsolidateDataService { String message = t("observe.message.consolidate.no.parametrage.found", t(entityLabel), - decorate(species) + decorateEntity(species) ); if (log.isWarnEnabled()) { log.warn(message); @@ -746,7 +612,7 @@ public class ConsolidateDataService { protected void updateLengthWeightAble(Species species, LengthWeightComputable e, - LengthWeightParameter parametrage) throws DataSourceException { + LengthWeightParameter parametrage) { String entityLabel = getSpeciesLabel(); @@ -779,7 +645,7 @@ public class ConsolidateDataService { String message = t("observe.message.consolidate.no.parametrage.found", t(entityLabel), - decorate(species) + decorateEntity(species) ); if (log.isWarnEnabled()) { log.warn(message); @@ -832,6 +698,109 @@ public class ConsolidateDataService { } } + protected void computeNonTargetCatchTailleMoyenne(NonTargetCatch nonTargetCatch, + Collection<NonTargetLength> samples, + LengthWeightParameter parametrage) { + + Float meanLength = null; + NonTargetCatchComputedValueSource computedSource = null; + + if (CollectionUtils.isNotEmpty(samples)) { + + // on calcul la taille moyenne à partir des échantillons + float totalTaille = 0f; + int nbIndividus = 0; + for (NonTargetLength sample : samples) { + + Integer count = sample.getCount(); + Float length = sample.getLength(); + + if (count != null && length != null) { + nbIndividus += count; + totalTaille += length * count; + } + } + + if (nbIndividus != 0) { + + meanLength = totalTaille / nbIndividus; + + computedSource = NonTargetCatchComputedValueSource.FROM_SAMPLE; + } + } + + if (meanLength == null && parametrage != null) { + + // on prend directement la valeur fournie par le référentiel + + meanLength = parametrage.getMeanLength(); + computedSource = NonTargetCatchComputedValueSource.FROM_REFERENTIEL; + } + + if (meanLength != null) { + + // la taille moyenne a pu etre calculee, on la pousse alors + nonTargetCatch.setMeanLength(meanLength); + nonTargetCatch.setMeanLengthComputedSource(computedSource); + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); + } + + } + + private void computeNonTargetCatchNombreEstime(NonTargetCatch nonTargetCatch, + Collection<NonTargetLength> samples, + LengthWeightParameter parametrage) { + + + if (CollectionUtils.isNotEmpty(samples)) { + + // on calcul la taille moyenne à partir des échantillons + int nbIndividus = 0; + for (NonTargetLength sample : samples) { + + Integer count = sample.getCount(); + + if (count != null) { + nbIndividus += count; + } + } + + if (nbIndividus != 0) { + + nonTargetCatch.setTotalCount(nbIndividus); + nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_SAMPLE); + + if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); + } + } + } + } + + private void computeNonTargetCatchMeanValues(NonTargetCatch nonTargetCatch, + LengthWeightParameter parametrage) { + + if (parametrage != null) { + + nonTargetCatch.setMeanLength(parametrage.getMeanLength()); + nonTargetCatch.setMeanLengthComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); + + nonTargetCatch.setMeanWeight(parametrage.getMeanWeight()); + nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); + + if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); + } + } + } + + //FIXME Use a simple sql query protected String[] getActivityIds(TripSeine maree) { List<String> tmpIds = new ArrayList<String>(); if (!maree.isRouteEmpty()) { @@ -851,17 +820,13 @@ public class ConsolidateDataService { return result; } - protected DataService getDataService() { - DataService service = ObserveServiceHelper.getDataService(); - return service; - } - - protected DecoratorService getDecoratorService() { - DecoratorService service = ObserveServiceHelper.getDecoratorService(); - return service; + protected boolean allNonTargetCatchDataFilled(NonTargetCatch nonTargetCatch) { + return Iterables.all( + Sets.newHashSet(nonTargetCatch.getCatchWeight(), + nonTargetCatch.getTotalCount(), + nonTargetCatch.getMeanWeight(), + nonTargetCatch.getMeanLength()), + Predicates.notNull()); } - protected SendMessageAble getMessager(SendMessageAble messager) { - return messager == null ? LOG_ESSAGER : messager; - } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java new file mode 100644 index 0000000..57770f9 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class GpsImportService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java new file mode 100644 index 0000000..5390ca1 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class GpsImportServiceImpl implements GpsImportService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java new file mode 100644 index 0000000..08234a6 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java @@ -0,0 +1,111 @@ +package fr.ird.observe.services.operation; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.util.TopiaEntityRef; + +import java.util.List; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ObsoleteReferenceToReplace { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ObsoleteReferenceToReplace.class); + + /** l'id de l'entité à remplacer */ + String obsoleteId; + + /** l'id de l'entité de remplacement */ + String safeId; + + /** la liste des références à traiter */ + TopiaEntityRef[] refs; + + public String getSafeId() { + return safeId; + } + + public TopiaEntityRef[] getRefs() { + return refs; + } + + public ObsoleteReferenceToReplace(String obsoleteId, String safeId, List<TopiaEntityRef> refs) { + this.obsoleteId = obsoleteId; + this.refs = refs.toArray(new TopiaEntityRef[refs.size()]); + this.safeId = safeId; + } + + public String getObsoleteId() { + return obsoleteId; + } + +// public void doAction(TopiaContext tx) throws TopiaException { +// +// if (log.isInfoEnabled()) { +// log.info("load obsolete object " + obsoleteId); +// } +// +// if (log.isInfoEnabled()) { +// log.info("load safe object " + safeId); +// } +// +// TopiaEntity safeRef = tx.findByTopiaId(safeId); +// +// // on remplace les references +// for (TopiaEntityRef ref : refs) { +// TopiaEntity invoker = ref.getInvoker(); +// +// if (invoker == null) { +// throw new NullPointerException( +// "can not have a null invoker in " + ref); +// } +// +// if (log.isInfoEnabled()) { +// log.info("load invoker object " + invoker.getTopiaId()); +// } +// +// invoker = tx.findByTopiaId(invoker.getTopiaId()); +// +// // switch entity +// +// String path = ref.getInvokerProperty(); +// +// JXPathContext jxcontext = JXPathContext.newContext(invoker); +// +// TopiaEntity oldValue = (TopiaEntity) jxcontext.getValue(path); +// +// if (log.isDebugEnabled()) { +// log.debug("property to switch " + path + " old : " + +// oldValue); +// } +// +// if (log.isInfoEnabled()) { +// log.info("change path : " + path); +// log.info("old value : " + oldValue.getTopiaId()); +// } +// +// jxcontext.setValue(path, safeRef); +// +// TopiaEntity newValue = (TopiaEntity) jxcontext.getValue(path); +// +// if (log.isInfoEnabled()) { +// log.info("new value : " + newValue.getTopiaId()); +// } +// if (log.isDebugEnabled()) { +// log.debug("property to switch " + path + " new : " + +// safeRef); +// log.debug("property to switch " + path + " new Check : " + +// newValue); +// } +// TopiaDAO<TopiaEntity> dao = getDAO(tx, invoker); +// +// dao.update(invoker); +// } +// } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java new file mode 100644 index 0000000..8051a13 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public interface SynchronizeService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java new file mode 100644 index 0000000..ecba6db --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class SynchronizeServiceImpl implements SynchronizeService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java new file mode 100644 index 0000000..76f84b5 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java @@ -0,0 +1,18 @@ +package fr.ird.observe.services.operation; + +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.services.ObserveService; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.validation.ValidationMessageDetector; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ValidationService extends ObserveService { + + void validate(SendMessageAble messager, ValidationMessageDetector detector, DataSelectionModel dataModel); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java new file mode 100644 index 0000000..6fe70a6 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java @@ -0,0 +1,94 @@ +package fr.ird.observe.services.operation; + +import fr.ird.observe.DecoratorService; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.entities.Trip; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.validation.ValidationMessageDetector; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n.t; + +/** + * //FIXME A revoir, on doit utiliser un pattern de Request, Context et Result + * //FIXME Le detector doit être interne + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ValidationServiceImpl extends AbstractObserveService implements ValidationService { + + @Override + public void validate(SendMessageAble messager, ValidationMessageDetector detector, DataSelectionModel dataModel) { + + if (dataModel.isUseReferentiel()) { + + // validation des referentiels selectionnes + + validateReferentiel(messager, detector, dataModel); + } + + if (dataModel.isUseData()) { + + // validation des donnees observateur selectionnee + + validateData(messager, detector, dataModel); + } + + } + + protected void validateData(SendMessageAble messager, + ValidationMessageDetector detector, + DataSelectionModel dataModel) { + + Set<String> tripIds = dataModel.getSelectedData(); + + TripService tripService = newService(TripService.class); + + for (String tripId : tripIds) { + + Trip trip = tripService.getTrip(tripId); + Program program = trip.getProgram(); + + messager.sendMessage(t("observe.message.validation.start.maree", decorateEntity(trip), decorateEntity(program))); + detector.detectMessages(trip); + + } + + } + + protected void validateReferentiel(SendMessageAble messager, + ValidationMessageDetector detector, + DataSelectionModel dataModel) { + + Set<Class<?>> classes = dataModel.getSelectedReferentiel(); + + for (Class<?> klass : classes) { + + Class<? extends TopiaEntity> refClass = (Class<? extends TopiaEntity>) klass; + TopiaDAO<? extends TopiaEntity> dao = getDao(refClass); + + List<String> ids = dao.findAllIds(); + String entityLabel = t(DecoratorService.getEntityLabel(klass)); + messager.sendMessage(t("observe.message.validation.start.referentiel", entityLabel, ids.size())); + + for (String id : ids) { + TopiaEntity entity = dao.findByTopiaId(id); + detector.detectMessages(entity); + } + + ids.clear(); + + } + + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 39cf9b8cbbd4d54d6464f6e2ac0a074c56c94cbb Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun May 3 17:22:18 2015 +0200 suppression de tout le code utilisant des transactions sur module swing (refs #7017) --- .../fr/ird/observe/ObserveApplicationContext.java | 46 +-- .../java/fr/ird/observe/ObserveServiceHelper.java | 82 +--- .../main/java/fr/ird/observe/db/DataSource.java | 12 - .../java/fr/ird/observe/db/ReplicationService.java | 7 +- .../fr/ird/observe/db/impl/AbstractDataSource.java | 76 ---- .../test/java/fr/ird/observe/db/DBTestHelper.java | 39 +- .../fr/ird/observe/db/ReplicationServiceTest.java | 15 +- .../its/migration/H2DataSourceMigrationIT.java | 6 +- .../ird/observe/its/report/AbstractReportIT.java | 2 +- .../fr/ird/observe/entities/OpenableEntities.java | 117 +++--- .../referentiel/LengthWeightParameterDAOImpl.java | 32 ++ .../referentiel/LengthWeightParemeterHelper.java | 4 +- .../entities/referentiel/ReferenceEntities.java | 4 +- .../observe/entities/referentiel/SexDAOImpl.java | 12 +- .../observe/services/AbstractObserveService.java | 50 ++- .../ird/observe/services/ReplicationService.java | 25 +- .../observe/services/ReplicationServiceImpl.java | 416 ++++++++++++++++++++- .../fr/ird/observe/services/data/TripService.java | 3 + .../ird/observe/services/data/TripServiceImpl.java | 27 +- .../data/seine/ActivitySeineServiceImpl.java | 2 +- .../services/operation/ComputeDataServiceImpl.java | 2 +- .../services/operation/GpsImportService.java | 20 +- .../services/operation/GpsImportServiceImpl.java | 126 ++++++- .../services/operation/SynchronizeService.java | 31 +- .../services/operation/SynchronizeServiceImpl.java | 232 +++++++++++- .../services/referential/ReferentialService.java | 22 ++ .../referential/ReferentialServiceImpl.java | 331 +++++++++++++++- .../main/java/fr/ird/observe/ObserveContext.java | 4 +- .../main/java/fr/ird/observe/ObserveRunner.java | 17 +- .../fr/ird/observe/ui/ObserveMainUIHandler.java | 7 +- .../fr/ird/observe/ui/admin/AdminTabUIHandler.java | 112 +----- .../java/fr/ird/observe/ui/admin/AdminUIModel.java | 31 +- .../ui/admin/consolidate/ConsolidateModel.java | 55 +-- .../ui/admin/consolidate/ConsolidateUIHandler.java | 129 ++----- .../ird/observe/ui/admin/export/ExportModel.java | 19 + .../observe/ui/admin/export/ExportUIHandler.java | 44 +-- .../observe/ui/admin/gps/ImportGPSUIHandler.java | 131 ++----- .../observe/ui/admin/save/SaveLocalUIHandler.java | 208 +---------- .../ui/admin/synchronize/SynchronizeModel.java | 75 ++-- .../ui/admin/synchronize/SynchronizeUIHandler.java | 352 ++++------------- .../ui/admin/validate/ValidateUIHandler.java | 173 ++++----- .../java/fr/ird/observe/ui/content/ContentUI.jaxx | 4 - .../ird/observe/ui/content/ContentUIHandler.java | 12 - .../observe/ui/content/ContentUIInitializer.java | 11 +- .../ref/ReferentialContentUIInitializer.java | 8 +- .../ird/observe/ui/storage/RemoteUILauncher.java | 8 +- .../ui/storage/StorageBackupUILauncher.java | 7 +- .../ird/observe/ui/storage/StorageUIHandler.java | 46 ++- .../ui/tree/loadors/AbstractNodeChildLoador.java | 12 +- 49 files changed, 1832 insertions(+), 1374 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java b/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java index bd17f13..69426b7 100644 --- a/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java +++ b/observe-business/src/main/java/fr/ird/observe/ObserveApplicationContext.java @@ -66,14 +66,6 @@ public class ObserveApplicationContext extends DefaultApplicationContext { public static final JAXXContextEntryDef<GPSService> GPS_SERVICE_ENTRY_DEF = JAXXUtil.newContextEntryDef(GPSService.class); - /** the jaxx context entry to store the consolidate data service */ - public static final JAXXContextEntryDef<ConsolidateDataService> CONSOLIDATE_DATA_SERVICE_ENTRY_DEF = - JAXXUtil.newContextEntryDef(ConsolidateDataService.class); - - /** the jaxx context entry to store the data service */ - public static final JAXXContextEntryDef<DataService> DATA_SERVICE_ENTRY_DEF = - JAXXUtil.newContextEntryDef(DataService.class); - /** the jaxx context entry to store the data service */ public static final JAXXContextEntryDef<DataContext> DATA_CONTEXT_ENTRY_DEF = JAXXUtil.newContextEntryDef(DataContext.class); @@ -135,15 +127,15 @@ public class ObserveApplicationContext extends DefaultApplicationContext { return decoratorService; } - public final DataService getDataService() { - DataService dataService = - DATA_SERVICE_ENTRY_DEF.getContextValue(this); - if (dataService == null) { - dataService = new DataService(); - DATA_SERVICE_ENTRY_DEF.setContextValue(this, dataService); - } - return dataService; - } +// public final DataService getDataService() { +// DataService dataService = +// DATA_SERVICE_ENTRY_DEF.getContextValue(this); +// if (dataService == null) { +// dataService = new DataService(); +// DATA_SERVICE_ENTRY_DEF.setContextValue(this, dataService); +// } +// return dataService; +// } public final BinderService getBinderService() { BinderService service = @@ -166,16 +158,16 @@ public class ObserveApplicationContext extends DefaultApplicationContext { return service; } - public ConsolidateDataService getConsolidateDataService() { - - ConsolidateDataService service = - CONSOLIDATE_DATA_SERVICE_ENTRY_DEF.getContextValue(this); - if (service == null) { - service = new ConsolidateDataService(); - CONSOLIDATE_DATA_SERVICE_ENTRY_DEF.setContextValue(this, service); - } - return service; - } +// public ConsolidateDataService getConsolidateDataService() { +// +// ConsolidateDataService service = +// CONSOLIDATE_DATA_SERVICE_ENTRY_DEF.getContextValue(this); +// if (service == null) { +// service = new ConsolidateDataService(); +// CONSOLIDATE_DATA_SERVICE_ENTRY_DEF.setContextValue(this, service); +// } +// return service; +// } public final DataContext getDataContext() { DataContext result = DATA_CONTEXT_ENTRY_DEF.getContextValue(this); diff --git a/observe-business/src/main/java/fr/ird/observe/ObserveServiceHelper.java b/observe-business/src/main/java/fr/ird/observe/ObserveServiceHelper.java index a904bc1..54b2303 100644 --- a/observe-business/src/main/java/fr/ird/observe/ObserveServiceHelper.java +++ b/observe-business/src/main/java/fr/ird/observe/ObserveServiceHelper.java @@ -25,13 +25,10 @@ import com.google.common.base.Supplier; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceFactory; -import fr.ird.observe.db.ReplicationService; import fr.ird.observe.db.impl.H2DataSource; import fr.ird.observe.db.impl.H2DataSourceConfig; import fr.ird.observe.entities.migration.AbstractDataSourceMigration; -import fr.ird.observe.gps.GPSService; import fr.ird.observe.validation.ValidationContext; -import fr.ird.observe.validation.ValidationService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.config.ApplicationConfig; @@ -91,6 +88,7 @@ public class ObserveServiceHelper { ObserveServiceHelper.context = context; AbstractDataSourceMigration.setApplicationConfigSupplier(new Supplier<ApplicationConfig>() { + @Override public ApplicationConfig get() { return ObserveServiceHelper.context.getContextValue(ApplicationConfig.class); @@ -112,24 +110,6 @@ public class ObserveServiceHelper { closed = true; } - /** - * Pour instancier un nouveau service de réplication. - * - * @return le nouveau service de réplication - */ - public static ReplicationService newReplicationService() { - return new ReplicationService(); - } - - /** - * Pour instancier un nouveau service de validation. - * - * @return le nouveau service de validation - */ - public static ValidationService newValidationService() { - return new ValidationService(); - } - public static DataContext getDataContext() { checkInit(); ObserveApplicationContext context = get(); @@ -145,43 +125,6 @@ public class ObserveServiceHelper { } /** - * Pour instancier un nouveau service GPS. - * - * @return le service GPS partagé - */ - public static GPSService getGPSService() { - checkInit(); - ObserveApplicationContext context = get(); - GPSService service = context.getGPSService(); - return service; - } - - /** - * Pour récupérer le service de consolidation des données. - * - * @return le service de consolidation des données partagé - */ - public static ConsolidateDataService getConsolidateDataService() { - checkInit(); - ObserveApplicationContext context = get(); - ConsolidateDataService service = context.getConsolidateDataService(); - return service; - - } - - /** - * Pour obtenir l'unique service haut niveau de manipulation des données. - * - * @return le service haut niveau de manipulation des donées. - */ - public static DataService getDataService() { - checkInit(); - ObserveApplicationContext context = get(); - DataService service = context.getDataService(); - return service; - } - - /** * Pour obtenir l'unique service de décoration. * * @return l'instance partagé du service de décoration @@ -223,28 +166,6 @@ public class ObserveServiceHelper { } /** - * Creates a new local temp storage. - * - * @param dir the directory to use to store database - * @param label label of storage - * @return the new service NOT opened - * @throws IOException if any pb while configuring the service - */ - public static DataSource newEmptyTempStorage(File dir, - String label) throws IOException { - - H2DataSourceConfig conf = DataSourceFactory.newH2ConfigEmpty( - label, - dir, - "sa", - "sa".toCharArray() - ); - - H2DataSource service = DataSourceFactory.newService(conf); - return service; - } - - /** * Construit une source de données sur la base locale de l'application. * <p/> * <b>Note:</b> La base locale doit exister, sinon on soulève une @@ -328,4 +249,5 @@ public class ObserveServiceHelper { public static void setUseJMX(boolean useJMX) { ObserveServiceHelper.useJMX = useJMX; } + } diff --git a/observe-business/src/main/java/fr/ird/observe/db/DataSource.java b/observe-business/src/main/java/fr/ird/observe/db/DataSource.java index a99ea23..959d3c5 100644 --- a/observe-business/src/main/java/fr/ird/observe/db/DataSource.java +++ b/observe-business/src/main/java/fr/ird/observe/db/DataSource.java @@ -24,7 +24,6 @@ package fr.ird.observe.db; import fr.ird.observe.db.constants.DataSourceState; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListener; -import fr.ird.observe.entities.OpenableEntity; import org.nuiton.decorator.Decorator; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -45,12 +44,6 @@ import java.util.Properties; */ public interface DataSource { - String OPEN_PROPERTY_KEY = "open"; - - String REFERENTIEL_PROPERTY_KEY = "referentiel"; - - String DATA_PROPERTY_KEY = "data"; - // ------------------------------------------------------------------------- // Methodes de démarrage et fermeture de la source de données // ------------------------------------------------------------------------- @@ -166,11 +159,6 @@ public interface DataSource { <P extends TopiaEntity> TopiaDAO<P> getDAO(TopiaContext context, P entity) throws TopiaException; - <E extends OpenableEntity & TopiaEntity> E getOpen(TopiaContext tx, - Class<E> klass) throws DataSourceException; - - String[] getOpenIds(TopiaContext tx) throws DataSourceException; - /** * Exporte la base de données dans un script gzip-compresse. * <p/> diff --git a/observe-business/src/main/java/fr/ird/observe/db/ReplicationService.java b/observe-business/src/main/java/fr/ird/observe/db/ReplicationService.java index c531527..0c35d49 100644 --- a/observe-business/src/main/java/fr/ird/observe/db/ReplicationService.java +++ b/observe-business/src/main/java/fr/ird/observe/db/ReplicationService.java @@ -153,15 +153,12 @@ public class ReplicationService { TripSeineDAO srcTripDAO = ObserveDAOHelper.getTripSeineDAO(srcCtxt); List<String> allIds = srcTripDAO.findAllIds(); -// List<TripSeine> srcTripSeines = srcTripDAO.findAll(); - if (CollectionUtils.isEmpty(allIds)) { // aucune donnee a repliquer srcService.fireNewMessage( t("observe.storage.message.replicate.data.no.data")); return; } -// topiaIds = TopiaEntityHelper.getTopiaIdArray(srcTripSeines); topiaIds = allIds.toArray(new String[allIds.size()]); } catch (TopiaException e) { @@ -191,9 +188,7 @@ public class ReplicationService { * @param ids les ids des entités à répliquer * @throws DataSourceException if pb */ - public void replicateData(DataSource srcService, - DataSource dstService, - String... ids) throws DataSourceException { + public void replicateData(DataSource srcService, DataSource dstService, String... ids) throws DataSourceException { if (srcService == null) { throw new NullPointerException("srcService can not be null"); } diff --git a/observe-business/src/main/java/fr/ird/observe/db/impl/AbstractDataSource.java b/observe-business/src/main/java/fr/ird/observe/db/impl/AbstractDataSource.java index 0ee2567..21243f8 100644 --- a/observe-business/src/main/java/fr/ird/observe/db/impl/AbstractDataSource.java +++ b/observe-business/src/main/java/fr/ird/observe/db/impl/AbstractDataSource.java @@ -34,16 +34,7 @@ import fr.ird.observe.db.constants.CommonDataSourceConfigParam; import fr.ird.observe.db.constants.DataSourceState; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListener; -import fr.ird.observe.entities.OpenableEntity; -import fr.ird.observe.entities.OpenableEntityDAOImpl; -import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.migration.AbstractDataSourceMigration; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TripSeine; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.SessionFactory; @@ -74,7 +65,6 @@ import java.lang.management.ManagementFactory; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Hashtable; @@ -263,72 +253,6 @@ public abstract class AbstractDataSource implements DataSource { } @Override - public <E extends OpenableEntity & TopiaEntity> E getOpen(TopiaContext tx, Class<E> klass) throws DataSourceException { - if (!canReadData()) { - if (log.isInfoEnabled()) { - log.info("Can not read data!"); - } - return null; - } - try { - - TopiaDAO<E> dao = getDAO(tx, klass); - E result = (E) ((OpenableEntityDAOImpl) dao).findByOpen(true); - return result; - - } catch (Exception e) { - throw new DataSourceException(e, "getOpen"); - } - } - - @Override - public String[] getOpenIds(TopiaContext tx) throws DataSourceException { - - List<String> result = new ArrayList<String>(); - - { - TripSeine trip = getOpen(tx, TripSeine.class); - if (trip != null) { - if (trip.getProgram() != null) { - result.add(trip.getProgram().getTopiaId()); - } - result.add(trip.getTopiaId()); - Route route = getOpen(tx, Route.class); - if (route != null) { - result.add(route.getTopiaId()); - ActivitySeine activity = getOpen(tx, ActivitySeine.class); - if (activity != null) { - result.add(activity.getTopiaId()); - SetSeine set = activity.getSetSeine(); - if (set != null) { - result.add(set.getTopiaId()); - } - } - } - } - } - - { - TripLongline trip = getOpen(tx, TripLongline.class); - if (trip != null) { - if (trip.getProgram() != null) { - result.add(trip.getProgram().getTopiaId()); - } - result.add(trip.getTopiaId()); - ActivityLongline activity = getOpen(tx, ActivityLongline.class); - if (activity != null) { - result.add(activity.getTopiaId()); - SetLongline set = activity.getSetLongline(); - if (set != null) { - result.add(set.getTopiaId()); - } - } - } - } - return result.toArray(new String[result.size()]); - } - - @Override public void addDataSourceListener(DataSourceListener listener) { listenerList.add(DataSourceListener.class, listener); } diff --git a/observe-business/src/test/java/fr/ird/observe/db/DBTestHelper.java b/observe-business/src/test/java/fr/ird/observe/db/DBTestHelper.java index 983b894..a89f5e3 100644 --- a/observe-business/src/test/java/fr/ird/observe/db/DBTestHelper.java +++ b/observe-business/src/test/java/fr/ird/observe/db/DBTestHelper.java @@ -21,8 +21,10 @@ */ package fr.ird.observe.db; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import fr.ird.observe.DataService; import fr.ird.observe.IObserveConfig; import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.ObserveEntityEnum; @@ -41,8 +43,10 @@ import org.apache.commons.logging.LogFactory; import org.hibernate.jdbc.Work; import org.junit.Assert; import org.junit.Assume; +import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.version.Version; @@ -80,7 +84,7 @@ public class DBTestHelper { if (Modifier.isAbstract(c.getModifiers())) { continue; } - List<?> r = dataService.getList(service, c); + List<?> r = getList(service, c, null); Assert.assertNotNull(r); if (noData) { Assert.assertEquals(0, r.size()); @@ -88,8 +92,6 @@ public class DBTestHelper { } } - static DataService dataService = new DataService(); - public static void assertReferentiel(DataSource localService, DataSource importService, ObserveEntityEnum... empty) @@ -102,10 +104,9 @@ public class DBTestHelper { List<ObserveEntityEnum> observeEntityEnums = Arrays.asList(empty); // on verifie que le referentiel existe sur la nouvelle base - for (ObserveEntityEnum constant : - Entities.REFERENCE_ENTITIES) { + for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { Class<? extends TopiaEntity> c = constant.getContract(); - List<?> actual = dataService.getList(localService, c); + List<?> actual = getList(localService, c, null); Assert.assertNotNull(actual); if (!observeEntityEnums.contains(constant)) { // FIXME Remove the empty reference list when all references will be filled @@ -117,7 +118,7 @@ public class DBTestHelper { } // Assert.assertFalse(c.getName(), actual.isEmpty()); if (importService != null) { - List<?> expected = dataService.getList(importService, c); + List<?> expected = getList(importService, c, null); Assert.assertNotNull(expected); Assert.assertEquals(expected.size(), actual.size()); } @@ -129,6 +130,28 @@ public class DBTestHelper { } } + public static <E extends TopiaEntity> List<E> getList(DataSource source, + Class<E> klass, + Predicate<E> predicate) throws DataSourceException { + + TopiaContext tx = source.beginTransaction("getList0 : " + klass); + try { + TopiaDAO<E> dao = source.getDAO(tx, klass); + List<E> result = dao.findAll(); + + if (predicate != null) { + + // use a filter + result = Lists.newArrayList(Iterables.filter(result, predicate)); + + } + + return result; + } finally { + source.closeTransaction(tx, "getList0 : " + klass); + } + } + protected static final Set<ObserveEntityEnum> REFERENCE_TO_FILL = Sets.newHashSet( Arrays.asList(ObserveEntityEnum.FpaZone, ObserveEntityEnum.BaitHaulingStatus, diff --git a/observe-business/src/test/java/fr/ird/observe/db/ReplicationServiceTest.java b/observe-business/src/test/java/fr/ird/observe/db/ReplicationServiceTest.java index f5b8341..61b6ecd 100644 --- a/observe-business/src/test/java/fr/ird/observe/db/ReplicationServiceTest.java +++ b/observe-business/src/test/java/fr/ird/observe/db/ReplicationServiceTest.java @@ -21,8 +21,12 @@ */ package fr.ird.observe.db; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.impl.H2DataSource; +import fr.ird.observe.entities.referentiel.Country; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.referentiel.Vessel; +import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.NonTargetCatch; @@ -33,11 +37,6 @@ import fr.ird.observe.entities.seine.TargetCatch; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.entities.referentiel.Country; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.referentiel.Species; -import fr.ird.observe.entities.referentiel.Vessel; -import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.test.TestHelper; import org.apache.commons.io.FileUtils; import org.junit.After; @@ -235,7 +234,7 @@ public class ReplicationServiceTest { @Test public void replicateReferentiel() throws Exception { - ReplicationService service = ObserveServiceHelper.newReplicationService(); + ReplicationService service = new ReplicationService(); service.replicateReferentiel(localSource, dstSource); @@ -265,7 +264,7 @@ public class ReplicationServiceTest { @Test public void replicateData() throws Exception { - ReplicationService service = ObserveServiceHelper.newReplicationService(); + ReplicationService service = new ReplicationService(); service.replicateReferentiel(localSource, dstSource); diff --git a/observe-business/src/test/java/fr/ird/observe/its/migration/H2DataSourceMigrationIT.java b/observe-business/src/test/java/fr/ird/observe/its/migration/H2DataSourceMigrationIT.java index 793f752..df46597 100644 --- a/observe-business/src/test/java/fr/ird/observe/its/migration/H2DataSourceMigrationIT.java +++ b/observe-business/src/test/java/fr/ird/observe/its/migration/H2DataSourceMigrationIT.java @@ -23,8 +23,6 @@ package fr.ird.observe.its.migration; import com.google.common.base.Function; import com.google.common.collect.Maps; -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DBTestHelper; import fr.ird.observe.db.impl.H2DataSource; import fr.ird.observe.db.impl.H2DataSourceConfig; @@ -116,9 +114,7 @@ public class H2DataSourceMigrationIT extends AbstractDataSourceMigrationTest<H2D Assert.assertNotNull("could not find resource : " + csvFilepath, dbUrl); - DataService dataService = ObserveServiceHelper.get().getDataService(); - - List<Species> speciesList = dataService.getList(service, Species.class); + List<Species> speciesList = DBTestHelper.getList(service, Species.class, null); SpeciesImportModel importModel = new SpeciesImportModel(speciesList); diff --git a/observe-business/src/test/java/fr/ird/observe/its/report/AbstractReportIT.java b/observe-business/src/test/java/fr/ird/observe/its/report/AbstractReportIT.java index a453d50..54fbb1e 100644 --- a/observe-business/src/test/java/fr/ird/observe/its/report/AbstractReportIT.java +++ b/observe-business/src/test/java/fr/ird/observe/its/report/AbstractReportIT.java @@ -125,7 +125,7 @@ public abstract class AbstractReportIT { ); // recuperation de la maree a utiliser - List<TripSeine> marees = ObserveServiceHelper.getDataService().getList(dataSource, TripSeine.class); + List<TripSeine> marees = DBTestHelper.getList(dataSource, TripSeine.class, null); Assert.assertFalse("No maree found in " + dataSource.getLabel(), marees.isEmpty()); Assert.assertEquals("Should have found exactly one maree, but was " + marees.size(), 1, marees.size()); diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/OpenableEntities.java b/observe-entities/src/main/java/fr/ird/observe/entities/OpenableEntities.java index a3cb922..a78b2a3 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/OpenableEntities.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/OpenableEntities.java @@ -22,12 +22,6 @@ package fr.ird.observe.entities; * #L% */ -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.entities.seine.TripSeine; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaRuntimeException; - import java.util.Collection; /** @@ -38,72 +32,75 @@ import java.util.Collection; */ public class OpenableEntities { - /** - * @param o l'objet dont on veut tester le type - * @return {@code true} si l'objet est non null et de type {@link - * OpenableEntity}, {@code false} autrement. - */ - public static boolean isOpenable(Object o) { - if (o == null) { - return false; - } - Class<?> c; - if (!Class.class.equals(o.getClass())) { - c = o.getClass(); - } else { - c = (Class<?>) o; - } - return OpenableEntity.class.isAssignableFrom(c); - } +// /** +// * @param o l'objet dont on veut tester le type +// * @return {@code true} si l'objet est non null et de type {@link +// * OpenableEntity}, {@code false} autrement. +// */ +// public static boolean isOpenable(Object o) { +// if (o == null) { +// return false; +// } +// Class<?> c; +// if (!Class.class.equals(o.getClass())) { +// c = o.getClass(); +// } else { +// c = (Class<?>) o; +// } +// return OpenableEntity.class.isAssignableFrom(c); +// } - /** - * //FIXME Should use also a getOpenTrip for Longline model. - * @param ctxt le topia context - * @return la marée ouverte, ou <code>null</code> si pas de marée ouverte - * @throws TopiaException if any pb - */ - public static TripSeine getOpenTrip(TopiaContext ctxt) throws TopiaException { - if (ctxt == null) { - throw new TopiaRuntimeException("could not find a local topia" + - " context"); - } - TripSeine m = ObserveDAOHelper.getTripSeineDAO(ctxt).findByOpen(true); - return m; - } +// /** +// * //FIXME Should use also a getOpenTrip for Longline model. +// * @param ctxt le topia context +// * @return la marée ouverte, ou <code>null</code> si pas de marée ouverte +// * @throws TopiaException if any pb +// */ +// public static TripSeine getOpenTrip(TopiaContext ctxt) throws TopiaException { +// if (ctxt == null) { +// throw new TopiaRuntimeException("could not find a local topia context"); +// } +// TripSeine m = ObserveDAOHelper.getTripSeineDAO(ctxt).findByOpen(true); +// return m; +// } - /** - * @param <O> le type des données de type {@link OpenableEntity} - * @param openableEntity l'openableEntity ou rechercher dans ses chils - * @return l'objet dans la liste qui est ouvert, ou <code>null</code> si - * aucun objet ouvert. - */ - public static <O extends OpenableEntity> O getOpenChild(OpenableEntity openableEntity) { - Collection<?> openables = openableEntity.getOpenableChilds(); - if (openables != null) { - for (Object o : openables) { - if (((OpenableEntity) o).isOpen()) { - return (O) o; - } - } - } - return null; - } +// /** +// * @param <O> le type des données de type {@link OpenableEntity} +// * @param openableEntity l'openableEntity ou rechercher dans ses chils +// * @return l'objet dans la liste qui est ouvert, ou <code>null</code> si +// * aucun objet ouvert. +// */ +// public static <O extends OpenableEntity> O getOpenChild(OpenableEntity openableEntity) { +// Collection<?> openables = openableEntity.getOpenableChilds(); +// if (openables != null) { +// for (Object o : openables) { +// if (((OpenableEntity) o).isOpen()) { +// return (O) o; +// } +// } +// } +// return null; +// } /** * @param <O> le type des données de type {@link OpenableEntity} * @param openables une liste de données de type {@link OpenableEntity}. - * @return l'objet dans la liste qui est ouvert, ou <code>null</code> si - * aucun objet ouvert. + * @return l'objet dans la liste qui est ouvert, ou <code>null</code> si aucun objet ouvert. */ - public static <O extends OpenableEntity> O getOpenEntity( - Collection<O> openables) { + public static <O extends OpenableEntity> O getOpenEntity(Collection<O> openables) { + + O result = null; + if (openables != null) { for (O o : openables) { if (o.isOpen()) { - return o; + result = o; + break; } } } - return null; + + return result; + } } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java index d079a72..cb2c3e3 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java @@ -1,4 +1,36 @@ package fr.ird.observe.entities.referentiel; +import org.nuiton.topia.TopiaException; + +import java.util.Iterator; +import java.util.List; + public class LengthWeightParameterDAOImpl<E extends LengthWeightParameter> extends LengthWeightParameterDAOAbstract<E> { + + public List<E> findAllBySpecies(Species species) throws TopiaException { + + List<E> list = findAllByProperties(LengthWeightParameter.PROPERTY_SPECIES, species); + + // on supprime les paramétrages qui ont a=0 ou a=null ou b=0 ou b = null + Iterator<E> itr = list.iterator(); + while (itr.hasNext()) { + E p = itr.next(); + Double a = p.getCoefficientValue(LengthWeightParemeterHelper.COEFFICIENT_A); + if (a == null || a == 0) { + itr.remove(); + continue; + } + + Double b = p.getCoefficientValue(LengthWeightParemeterHelper.COEFFICIENT_B); + // on autorise d'avoir b à 0 (mais cela ne permet plus de calculer la taille à partir du poids) +// if (b == null || b == 0) { + if (b == null) { + itr.remove(); + } + } + + return list; + + } + } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java index cb5655d..1b82c47 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParemeterHelper.java @@ -68,9 +68,9 @@ public class LengthWeightParemeterHelper { /** variable taille à utiliser dans la relation weight */ public static final String VARIABLE_TAILLE = "L"; - private static final String COEFFICIENT_A = "a"; + public static final String COEFFICIENT_A = "a"; - private static final String COEFFICIENT_B = "b"; + public static final String COEFFICIENT_B = "b"; protected static ScriptEngine getScriptEngine() { if (scriptEngine == null) { diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java index 35ff744..2825219 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java @@ -95,7 +95,7 @@ public class ReferenceEntities { } }; - public static void walk(ReferentielWalker walker) throws Exception { + public static void walk(ReferentielWalker walker) { for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { Class<? extends TopiaEntity> contractClass = constant.getContract(); walker.walk(contractClass); @@ -116,7 +116,7 @@ public class ReferenceEntities { public interface ReferentielWalker { - <E extends TopiaEntity> void walk(Class<E> beanClass) throws Exception; + <E extends TopiaEntity> void walk(Class<E> beanClass) ; } } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java index 97f220e..c5c8e92 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java @@ -1,7 +1,11 @@ package fr.ird.observe.entities.referentiel; -import javax.annotation.Generated; - -@Generated(value = "org.nuiton.topia.generator.EntityDAOTransformer", date = "Sat May 02 12:01:39 CEST 2015") public class SexDAOImpl<E extends Sex> extends SexDAOAbstract<E> { -} //SexDAOImpl<E extends Sex> + + public E getUnknownSex() { + + E sex = findByCode("fr.ird.observe.entities.referentiel.Sex#1239832686121#0.0"); + return sex; + + } +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 127fd89..f7dab53 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -6,6 +6,7 @@ import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.IObserveConfig; import fr.ird.observe.ObserveEntityEnum; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceLocale; @@ -48,7 +49,7 @@ public abstract class AbstractObserveService implements ObserveService { @Override public <E extends TopiaEntity> EntityMap findAllUsages(E entity) { - Class<E> entityType = (Class<E>) ObserveEntityEnum.valueOf(entity).getContract(); + Class<E> entityType = getEntityContractClass(entity); TopiaDAO<E> dao = getDao(entityType); @@ -79,7 +80,7 @@ public abstract class AbstractObserveService implements ObserveService { if (Entities.isDataClass(klass)) { // on verifie que l'on a le droit de lire la donnee - if (!serviceContext.getDataSource().canReadData()) { + if (!getDataSource().canReadData()) { if (log.isDebugEnabled()) { log.debug("Can not read data, no read credential"); } @@ -89,7 +90,7 @@ public abstract class AbstractObserveService implements ObserveService { if (Entities.isReferentielClass(klass)) { // on verifie que l'on a le droit de lire la donnee - if (!serviceContext.getDataSource().canReadReferentiel()) { + if (!getDataSource().canReadReferentiel()) { if (log.isDebugEnabled()) { log.debug("Can not read referentiel, no read credential"); } @@ -151,13 +152,22 @@ public abstract class AbstractObserveService implements ObserveService { return getBinderService().getBinder(entityClass, contextName); } + protected <E extends TopiaEntity> TopiaDAO<E> getDao(E entity) { + Class<E> entityType = getEntityContractClass(entity); + return getDataSource().getDAO(getTransaction(), entityType); + } + + protected DataSource getDataSource() { + return serviceContext.getDataSource(); + } + protected <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityType) { - return serviceContext.getDataSource().getDAO(getTransaction(), entityType); + return getDataSource().getDAO(getTransaction(), entityType); } protected <E extends TopiaEntity> E findByTopiaId(Class<E> entityType, String topiaId) { - TopiaDAO<E> dao = serviceContext.getDataSource().getDAO(getTransaction(), entityType); + TopiaDAO<E> dao = getDataSource().getDAO(getTransaction(), entityType); return dao.findByTopiaId(topiaId); } @@ -183,6 +193,18 @@ public abstract class AbstractObserveService implements ObserveService { } + protected <E extends TopiaEntity> String decorateEntity(E entity) { + + Class<E> entityType = getEntityContractClass(entity); + Decorator<E> decorator = getDecoratorByType(entityType, null); + return decorator.toString(entity); + + } + + protected <E extends TopiaEntity> Class<E> getEntityContractClass(E entity) { + return (Class<E>) ObserveEntityEnum.valueOf(entity).getContract(); + } + protected <E extends TopiaEntity> List<E> getList0(Class<E> klass, Predicate<E> predicate) { TopiaDAO<E> dao = getDao(klass); @@ -199,7 +221,7 @@ public abstract class AbstractObserveService implements ObserveService { } - public <P extends TopiaEntity, E extends TopiaEntity> String doSave(String parentId, E toSave, SaveAction<P, E> saveAction) { + protected <P extends TopiaEntity, E extends TopiaEntity> String doSave(String parentId, E toSave, SaveAction<P, E> saveAction) { E saved; saveAction.beforeSave(parentId, toSave); @@ -268,7 +290,7 @@ public abstract class AbstractObserveService implements ObserveService { } - public <P extends TopiaEntity, E extends TopiaEntity> void doDelete(String parentId, String idToDelete, DeleteAction<P, E> deleteAction) { + protected <P extends TopiaEntity, E extends TopiaEntity> void doDelete(String parentId, String idToDelete, DeleteAction<P, E> deleteAction) { P parent = null; @@ -290,7 +312,6 @@ public abstract class AbstractObserveService implements ObserveService { getDao(deleteAction.parentClass).update(parent); } - } protected class DeleteAction<P extends TopiaEntity, E extends TopiaEntity> { @@ -310,7 +331,7 @@ public abstract class AbstractObserveService implements ObserveService { } - public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction) { + protected <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction) { Collection<E> childrenToSave = saveCollectionAction.listUpdator.getChilds(parentToSave); @@ -415,12 +436,12 @@ public abstract class AbstractObserveService implements ObserveService { } - public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { + protected <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); } - public <E extends TopiaEntity> void checkNotNullAndExistingEntity(String variableName, E entity) { + protected <E extends TopiaEntity> void checkNotNullAndExistingEntity(String variableName, E entity) { TopiaEntityHelper.checkNotNullAndExistingEntity(variableName, entity); } @@ -431,5 +452,12 @@ public abstract class AbstractObserveService implements ObserveService { } + protected ObserveServiceFactory newServiceFactory(DataSource dataSource) { + + ObserveServiceFactory serviceFactory = ObserveServiceFactory.newFactory(serviceContext.applicationContext, dataSource); + return serviceFactory; + + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java index 865a5c5..1a4d3cf 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java @@ -1,11 +1,32 @@ package fr.ird.observe.services; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.List; + /** * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since XXX + * @since 4.0 */ -public interface ReplicationService { +public interface ReplicationService extends ObserveService{ + + @Commit + void replicateObsoletesEntities(List<TopiaEntity> obsoleteEntities, DataSource source, SendMessageAble messanger) throws DataSourceException; + + @Commit + void replicateReferentiel(DataSource srcService) throws DataSourceException; + + @Commit + void replicateReferentiel(DataSource srcService, List<String> ids, SendMessageAble messanger) throws DataSourceException; + + @Commit + void replicateAllData(DataSource srcService) throws DataSourceException; + @Commit + void replicateData(DataSource srcService, String... ids) throws DataSourceException; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java index dcac5bc..d64ddc3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java @@ -1,11 +1,423 @@ package fr.ird.observe.services; +import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.ObserveEntityEnum; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.db.constants.DataSourceState; +import fr.ird.observe.entities.Entities; +import fr.ird.observe.entities.Trip; +import fr.ird.observe.entities.longline.TripLongline; +import fr.ird.observe.entities.longline.TripLonglines; +import fr.ird.observe.entities.seine.TripSeineDAO; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.replication.TopiaReplicationService; +import org.nuiton.topia.replication.model.ReplicationModel; +import org.nuiton.util.StringUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since XXX + * @since 4.0 */ -public class ReplicationServiceImpl implements ReplicationService { +public class ReplicationServiceImpl extends AbstractObserveService implements ReplicationService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ReplicationServiceImpl.class); + + @Override + public void replicateObsoletesEntities(List<TopiaEntity> obsoleteEntities, DataSource source, SendMessageAble messanger) throws DataSourceException { + + String txName = "replicateObsoletesEntities"; + TopiaContext sourceCtxt = source.beginTransaction(txName); + try { + + for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { + + Class<? extends TopiaEntity> contractClass = constant.getContract(); + List<TopiaEntity> toReplicate = new ArrayList<TopiaEntity>(); + for (Iterator<TopiaEntity> itr = obsoleteEntities.iterator(); itr.hasNext(); ) { + + TopiaEntity e = itr.next(); + if (contractClass.isAssignableFrom(e.getClass())) { + if (log.isDebugEnabled()) { + log.debug("obsolete to inject : " + e.getTopiaId()); + } + itr.remove(); + + // cet objet doit etre replique + toReplicate.add(e); + + messanger.sendMessage(t("observe.message.synchro.obsolete.data.to.duplicate", e)); + } + } + + if (toReplicate.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("no obsolete entity " + constant); + } + continue; + } + + if (log.isDebugEnabled()) { + log.debug("inject obsolete entity " + constant + " (" + toReplicate.size() + ")"); + } + + sourceCtxt.replicateEntities(getTransaction(), toReplicate); + + getTransaction().commitTransaction(); + + } + + } finally { + + source.closeTransaction(sourceCtxt, txName); + + } + + if (!obsoleteEntities.isEmpty()) { + throw new IllegalStateException("there is still obsolete entities to inject in synchro db : " + obsoleteEntities); + } + + } + + /** + * Duplication du référentiel depuis la source donnée en paramètre vers la source de ce service. + * + * @param srcService le service source qui contient les référentiels à repliquer + * @throws DataSourceException if pb + */ + public void replicateReferentiel(DataSource srcService) throws DataSourceException { + + if (srcService == null) { + throw new NullPointerException("srcService can not be null"); + } + + srcService.checkState(DataSourceState.OPEN); + + if (srcService.equals(getDataSource())) { + throw new IllegalArgumentException("can not duplicate to the same service..."); + } + long t0 = System.nanoTime(); + + Date date = new Date(); + srcService.fireNewMessage(t("observe.storage.message.replicate.referentiel.starting", date)); + + try { + + TopiaReplicationService service = srcService.getTopiaService(TopiaReplicationService.class); + + ReplicationModel model = service.prepareForAll(Entities.REFERENCE_ENTITIES); + + service.doReplicate(model, getTransaction()); + + String delay = StringUtil.convertTime(t0, System.nanoTime()); + srcService.fireNewMessage( + t("observe.storage.message.replicate.referentiel.done", delay)); + } catch (Exception e) { + throw new DataSourceException(e, "replicateReferentiel"); + } + } + + @Override + public void replicateReferentiel(DataSource srcService, List<String> ids, SendMessageAble messanger) throws DataSourceException { + + for (String id : ids) { + + String txName = "replicateReferentiel::" + id; + TopiaContext tx = srcService.beginTransaction(txName); + + try { + + TopiaEntity entity = tx.findByTopiaId(id); + String message = t("observe.synchro.add.object", id); + messanger.sendMessage(message); + tx.replicateEntity(getTransaction(), entity); + + // On est obligé de commiter à chaque ajout sinon si + // une autre entité à ajouter depend de celle là, on + // ne la retrouve pas + getTransaction().commitTransaction(); + if (log.isDebugEnabled()) { + log.debug("add [" + id + "] : "); + } + + } finally { + + // rollback context since we do not want to keep any modification + try { + srcService.rollbackTransaction(tx, txName); + } finally { + srcService.closeTransaction(tx, txName); + } + + } + + } + + } + + /** + * Duplication de toutes les données depuis le service passé en paramètre. + * + * @param srcService le service source + * @throws DataSourceException if pb + */ + public void replicateAllData(DataSource srcService) throws DataSourceException { + + srcService.checkState(DataSourceState.OPEN); + + // le service peut-être en cours d'ouverture + getDataSource().checkState(DataSourceState.INIT, DataSourceState.OPEN); + + if (srcService.equals(getDataSource())) { + throw new IllegalArgumentException("can not replcate to the same service..."); + } + + // recuperation des marees a repliquer + + String[] topiaIds = null; + + TopiaContext srcCtxt = srcService.beginTransaction("replicateData"); + try { + + TripSeineDAO srcTripDAO = ObserveDAOHelper.getTripSeineDAO(srcCtxt); + List<String> allIds = srcTripDAO.findAllIds(); + + if (CollectionUtils.isEmpty(allIds)) { + + // aucune donnee a repliquer + srcService.fireNewMessage(t("observe.storage.message.replicate.data.no.data")); + return; + + } + + topiaIds = allIds.toArray(new String[allIds.size()]); + + } catch (TopiaException e) { + + throw new DataSourceException(e, "replicateData"); + + } finally { + + // rollback context since we do not want to keep any modification + try { + srcService.rollbackTransaction(srcCtxt, "replicateData"); + } finally { + srcService.closeTransaction(srcCtxt, "replicateData"); + } + + } + + // replication des marees + replicateData(srcService, topiaIds); + + } + + /** + * Duplication de données observateur depuis la source passée en paramètre. + * + * @param srcService le service source + * @param ids les ids des entités à répliquer + * @throws DataSourceException if pb + */ + public void replicateData(DataSource srcService, String... ids) throws DataSourceException { + + if (srcService == null) { + throw new NullPointerException("srcService can not be null"); + } + + srcService.checkState(DataSourceState.OPEN); + // le service peut-être en cours d'ouverture + getDataSource().checkState(DataSourceState.INIT, DataSourceState.OPEN); + + if (srcService.equals(getDataSource())) { + throw new IllegalArgumentException("can not replcate to the same service..."); + } + + long t0 = System.nanoTime(); + + srcService.fireNewMessage(t("observe.storage.message.replicate.entities.starting", now())); + + for (String id : ids) { + replicateOneData(srcService, id); + } + + String time = StringUtil.convertTime(t0, System.nanoTime()); + srcService.fireNewMessage(t("observe.storage.message.replicate.entities.done", time)); + + } + + /** + * Duplication de l'unique donnée observateur depuis ce service vers le service donné. + * <p/> + * La duplication utilise une transaction dédiée afin de ne pas saturer le serveur + * et aussi une meilleure maitrise du rollback en cas d'une erreur. + * <p/> + * Voir http://forge.codelutin.com/issues/4837 + * + * @param srcService le service source + * @param id les ids des entités à répliquer + * @throws DataSourceException if pb + */ + protected void replicateOneData(DataSource srcService, String id) throws DataSourceException { + + String dstLabel = getDataSource().getShortLabel(); + + TopiaReplicationService service = srcService.getTopiaService(TopiaReplicationService.class); + + ReplicationModel model; + try { + model = service.prepare(Entities.DATA_ENTITIES, false, id); + } catch (TopiaException e) { + throw new DataSourceException(e, "replicateData"); + } + + // To fix missing tdr associations (see https://forge.codelutin.com/issues/6611) + List<Pair<String, String>> tdrAssociation = null; + + TopiaContext srcCtxt = srcService.beginTransaction("replicateData"); + try { + + TopiaEntity e = srcCtxt.findByTopiaId(id); + String label = t(DecoratorService.getEntityLabel(e.getClass())) + " :: " + id; + srcService.fireNewMessage(t("observe.storage.message.replicate.data.entity", label, dstLabel)); + + if (e instanceof Trip && Entities.isLonglineId(id)) { + + // Grab tdr missing associations (see https://forge.codelutin.com/issues/6611) + if (log.isInfoEnabled()) { + log.info("Should keep SetLongline - Tdr association ids for: " + id); + } + + tdrAssociation = getTdrAssociationIds(srcCtxt, (TripLongline) e); + + } + } catch (TopiaException e) { + throw new DataSourceException(e, "replicateData"); + } finally { + srcService.closeTransaction(srcCtxt, "replicateData"); + } + + TopiaContext dstCtxt = getTransaction(); + try { + + // do the replicate + service.doReplicate(model, dstCtxt); + + // Apply back tdr missing associations (see https://forge.codelutin.com/issues/6611) + applyTdrAssociationFix(dstCtxt, tdrAssociation); + + // commit the result + getTransaction().commitTransaction(); + + } catch (Exception e) { + getTransaction().rollbackTransaction(); + throw new DataSourceException(e, "replicateData"); + } finally { + + getTransaction().rollbackTransaction(); + + } + + } + + private void applyTdrAssociationFix(TopiaContext dstCtxt, List<Pair<String, String>> tdrAssociation) throws TopiaException { + + String request = "\nUPDATE OBSERVE_LONGLINE.TDR SET SET = '%s' WHERE topiaid = '%s';"; + + StringBuilder builder = new StringBuilder(); + + if (CollectionUtils.isNotEmpty(tdrAssociation)) { + for (Pair<String, String> entry : tdrAssociation) { + builder.append(String.format(request, entry.getKey(), entry.getValue())); + } + } + + dstCtxt.executeSQL(builder.toString()); + + } + + private List<Pair<String, String>> getTdrAssociationIds(TopiaContext srcCtxt, TripLongline e) throws TopiaException { + + List<Pair<String, String>> result = new ArrayList<Pair<String, String>>(); + + Set<String> setIds = TripLonglines.getSetIdsWithTdr(e); + + GetTdrIdsQuery query = new GetTdrIdsQuery(); + + for (String setId : setIds) { + + List<Pair<String, String>> multipleResult = query.execute((TopiaContextImplementor) srcCtxt, setId); + + if (log.isDebugEnabled()) { + log.debug("Found TDR associations: " + multipleResult); + } + result.addAll(multipleResult); + + } + + return result; + } + + + private static class GetTdrIdsQuery extends TopiaSQLQuery<Pair<String, String>> { + + private String setId; + + public List<Pair<String, String>> execute(TopiaContextImplementor tx, String setId) throws TopiaException { + try { + + this.setId = setId; + return findMultipleResult(tx); + + } finally { + + this.setId = null; + + } + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + String sql = "SELECT t.SET, t.topiaId " + + "FROM OBSERVE_LONGLINE.TDR t " + + "WHERE t.SET = ?"; + PreparedStatement ps = connection.prepareStatement(sql); + ps.setString(1, setId); + return ps; + } + + @Override + protected Pair<String, String> prepareResult(ResultSet set) throws SQLException { + Pair<String, String> result = + Pair.of(set.getString(1), set.getString(2)); + return result; + } + + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java index 9595f78..9f0933b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java @@ -1,5 +1,6 @@ package fr.ird.observe.services.data; +import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.services.Commit; @@ -18,6 +19,8 @@ public interface TripService extends ObserveService { List<Program> getPossibleProgramsForTrip(String tripId); + Trip getTrip(String tripId); + Ocean getTripOcean(String tripId); List<TripMapPoint> loadTripMapActivityPoints(String tripId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java index 96a740b..d419ecb 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java @@ -28,13 +28,7 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi @Override public List<Program> getPossibleProgramsForTrip(String tripId) { - Trip trip; - - if (tripId.startsWith(TripSeine.class.getSimpleName())) { - trip = findByTopiaId(TripSeine.class, tripId); - } else { - trip = findByTopiaId(TripLongline.class, tripId); - } + Trip trip = getTrip(tripId); GearType gearType = trip.getProgram().getGearType(); @@ -51,7 +45,7 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi } @Override - public Ocean getTripOcean(String tripId) { + public Trip getTrip(String tripId) { Trip trip; @@ -61,6 +55,15 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi trip = findByTopiaId(TripLongline.class, tripId); } + return trip; + + } + + @Override + public Ocean getTripOcean(String tripId) { + + Trip trip = getTrip(tripId); + return trip.getOcean(); } @@ -68,13 +71,7 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi @Override public void moveTripToProgram(String tripId, String programId) { - Trip trip; - - if (tripId.startsWith(TripSeine.class.getName())) { - trip = findByTopiaId(TripSeine.class, tripId); - } else { - trip = findByTopiaId(TripLongline.class, tripId); - } + Trip trip = getTrip(tripId); Program program = findByTopiaId(Program.class, programId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 6dfb81e..b23bb1b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -129,7 +129,7 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); - copyExcluding(ActivitySeine.class, BinderService.EDIT, toUpdate, updated, true, ActivitySeine.PROPERTY_SET_SEINE); + copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, toUpdate, updated); if (needUpdateSet) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java index e56a919..8dab84f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java @@ -127,7 +127,7 @@ public class ComputeDataServiceImpl extends AbstractObserveService implements Co @Override public void consolidateTrips(SendMessageAble messager, Set<String> tripIds) { - if (messager==null) { + if (messager == null) { messager = new SendMessageAble() { diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java index 57770f9..1bf168b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java @@ -1,11 +1,27 @@ package fr.ird.observe.services.operation; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.gps.GPSPoint; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; + +import java.util.Map; + /** * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since XXX + * @since 4.0 */ -public class GpsImportService { +public interface GpsImportService extends ObserveService { + + TripSeine getOpenTrip(); + + Map<ActivitySeine, GPSPoint> getActivitiesForOpenRoute(String openTripSeineId); + + @Commit + void applyPoints(Map<ActivitySeine, GPSPoint> data, int[] selectedIndex, SendMessageAble messanger); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java index 5390ca1..4c59cdd 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java @@ -1,11 +1,133 @@ package fr.ird.observe.services.operation; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.entities.seine.TripSeineDAO; +import fr.ird.observe.gps.GPSPoint; +import fr.ird.observe.services.AbstractObserveService; +import org.apache.commons.collections.primitives.ArrayIntList; +import org.apache.commons.collections.primitives.IntIterator; +import org.apache.commons.collections.primitives.IntList; +import org.nuiton.decorator.Decorator; +import org.nuiton.topia.persistence.TopiaDAO; + +import java.util.HashMap; +import java.util.Map; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since XXX + * @since 4.0 */ -public class GpsImportServiceImpl implements GpsImportService { +public class GpsImportServiceImpl extends AbstractObserveService implements GpsImportService { + + @Override + public Map<ActivitySeine, GPSPoint> getActivitiesForOpenRoute(String openTripSeineId) { + + Map<ActivitySeine, GPSPoint> data; + + + TripSeine openTripSeine = findByTopiaId(TripSeine.class, openTripSeineId); + + if (openTripSeine.isRouteEmpty()) { + + // pas de route sur la maree ouverte + data = null; + + } else { + + data = new HashMap<ActivitySeine, GPSPoint>(); + + for (Route r : openTripSeine.getRoute()) { + if (!r.isActivitySeineEmpty()) { + // on enregistre les actitives + for (ActivitySeine a : r.getActivitySeine()) { + data.put(a, null); + } + } + } + } + + return data; + + } + + @Override + public void applyPoints(Map<ActivitySeine, GPSPoint> data, int[] selectedIndex, SendMessageAble messanger) { + + Decorator<ActivitySeine> dActivity = getDecoratorByType(ActivitySeine.class, "activity-gps"); + Decorator<GPSPoint> dGPSPoint = getDecoratorByType(GPSPoint.class, "gpsPoint-gps"); + + IntList lIndex = new ArrayIntList(selectedIndex.length); + + for (int i : selectedIndex) { + lIndex.add(i); + } + IntIterator indexItr = lIndex.iterator(); + + int currentActivityIndex = 0; + int nextActivityIndex = indexItr.next(); + + TopiaDAO<ActivitySeine> activityDAO = getDao(ActivitySeine.class); + + for (ActivitySeine a : data.keySet()) { + + if (currentActivityIndex == nextActivityIndex) { + + // l'activité courante a ete selectionne + GPSPoint p = data.get(a); + + messanger.sendMessage(t("observe.message.importGPS.apply.point", dGPSPoint.toString(p), dActivity.toString(a))); +// sendMessage(t("observe.message.importGPS.apply.point", p, a.getVesselActivity().getLabel2())); + float latitude = Math.abs(p.getLatitude()); + float longitude = Math.abs(p.getLongitude()); + int quadrant = p.getQuadrant(); + // application de la position + + ActivitySeine aa = activityDAO.findByTopiaId(a.getTopiaId()); + aa.setLatitude(latitude); + aa.setLongitude(longitude); + aa.setQuadrant(quadrant); + //TODO appliquer la vitesse ? + //a.setVesselSpeed(p.getVitesse()); + + // mise a jour de l'activité + + activityDAO.update(aa); + + if (indexItr.hasNext()) { + + // il reste au moins une activité a traiter + // recuperation du prochain index d'activité a traiter + nextActivityIndex = indexItr.next(); + + } else { + + // plus d'activité a traiter + break; + + } + + } + + currentActivityIndex++; + + } + + } + + @Override + public TripSeine getOpenTrip() { + + TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); + TripSeine openTrip = dao.findByOpen(true); + return openTrip; + + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java index 8051a13..a1595d2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java @@ -1,11 +1,38 @@ package fr.ird.observe.services.operation; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.services.Commit; +import fr.ird.observe.services.ObserveService; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.util.DiffState; +import org.nuiton.topia.persistence.util.TopiaEntityRef; + +import java.util.List; +import java.util.SortedMap; + /** + * Pour effectuer la synchronisation des référentiels. + * + * Le service doit être instancié par le service qui veut être mis à jour. Le service qui contient le référentiel à jour + * doit être passé en paramètre. + * * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since XXX + * @since 4.0 */ -public interface SynchronizeService { +public interface SynchronizeService extends ObserveService { + + DiffState.DiffStateMap buildReferentielDifferentiel(final DataSource centralDataSource, final SendMessageAble messanger); + + SortedMap<TopiaEntity, List<TopiaEntityRef>> detectObsoleteEntities(DiffState.DiffStateMap diff); + + @Commit + void saveReferentiel(DataSource centralDataSource, + DiffState.DiffStateMap diff, + List<ObsoleteReferenceToReplace> replaceActions, + SendMessageAble messanger) throws DataSourceException; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java index ecba6db..e87ec48 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java @@ -1,11 +1,239 @@ package fr.ird.observe.services.operation; +import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.ObserveEntityEnum; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.entities.Entities; +import fr.ird.observe.entities.referentiel.ReferenceEntities; +import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.ReplicationService; +import fr.ird.observe.services.referential.ReferentialService; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.jdbc.Work; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.util.DiffState; +import org.nuiton.topia.persistence.util.TopiaEntityHelper; +import org.nuiton.topia.persistence.util.TopiaEntityRef; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; + +import static org.nuiton.i18n.I18n.t; + /** + * FIXME Utiliser des pattern Request, Result, Context + * FIXME Ne plus utilisers des messanger + * * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since XXX + * @since 4.0 */ -public class SynchronizeServiceImpl implements SynchronizeService { +public class SynchronizeServiceImpl extends AbstractObserveService implements SynchronizeService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(SynchronizeServiceImpl.class); + + @Override + public DiffState.DiffStateMap buildReferentielDifferentiel(final DataSource centralDataSource, final SendMessageAble messanger) { + + ObserveServiceFactory centralDataSourceServices = newServiceFactory(centralDataSource); + + try { + + final DiffState.DiffStateMap result = DiffState.newMap(); + + final ReferentialService centralReferentialService = + centralDataSourceServices.getService(ReferentialService.class); + + ReferenceEntities.walk(new ReferenceEntities.ReferentielWalker() { + + + public <E extends TopiaEntity> void walk(Class<E> contractClass) { + + String s = t(DecoratorService.getEntityLabel(contractClass)); + String message = + t("observe.service.build.synchro.referentiel", s); + if (messanger != null) { + messanger.sendMessage(message); + } + if (log.isInfoEnabled()) { + log.info(message); + } + List<E> list = centralReferentialService.getList(contractClass); + List<E> list2 = getList(contractClass); + DiffState.DiffStateMap tmp; + // recuperation du differentiel pour le type d'entitétmp = + tmp = TopiaEntityHelper.buildDifferentiel(list, list2); + // ajout au resultat + DiffState.addAll(result, tmp); + // on nettoie + DiffState.clear(tmp); + } + }); + DiffState.removeEmptyStates(result); + return result; + + } finally { + + centralDataSourceServices.close(); + + } + + } + + @Override + public SortedMap<TopiaEntity, List<TopiaEntityRef>> detectObsoleteEntities(DiffState.DiffStateMap diff) { + + // detection des entites obsoletes + + List<String> removedList = diff.get(DiffState.REMOVED); + + String[] ids = removedList.toArray(new String[removedList.size()]); + + // detection des entites obsoletes + + // des suppressions ont ete detectees, on doit retrouver + // dans la base locale les entites utilisant ces entites obsoletes + List<TripSeine> marees = getDao(TripSeine.class).findAll(); + + ObserveEntityEnum[] contracts = ObserveDAOHelper.getContracts(); + + SortedMap<TopiaEntity, List<TopiaEntityRef>> result; + + result = TopiaEntityHelper.detectReferences(contracts, ids, marees); + return result; + + } + + @Override + public void saveReferentiel(DataSource centralDataSource, + DiffState.DiffStateMap diff, + List<ObsoleteReferenceToReplace> obsoleteReferencesToReplace, + SendMessageAble messanger) throws DataSourceException { + + Map<TopiaEntity, Long> versionsToUpdate = new HashMap<TopiaEntity, Long>(); + + List<String> ids; + + ObserveServiceFactory centralSourceFactory = newServiceFactory(centralDataSource); + + try { + + // ajout des nouvelles entites du referentiel + + ids = diff.get(DiffState.NEW); + if (CollectionUtils.isNotEmpty(ids)) { + + ReplicationService replicationService = newService(ReplicationService.class); + + replicationService.replicateReferentiel(centralDataSource, ids, messanger); + + } + + ReferentialService localReferentialService = newService(ReferentialService.class); + + // mis a jour des entites modifiees + + ids = diff.get(DiffState.MODIFIED); + if (CollectionUtils.isNotEmpty(ids)) { + + ReferentialService service = centralSourceFactory.getService(ReferentialService.class); + Collection<? extends TopiaEntity> entitiesToCopy = service.loadSimpleEntities(ids); + + localReferentialService.copySimpleEntities(entitiesToCopy); + + } + + // mise à jour des données utilisateurs (remplacements d'objets obsolètes) + + for (ObsoleteReferenceToReplace referenceToReplace : obsoleteReferencesToReplace) { + + String message = t("observe.synchro.replaceObsolete.object", referenceToReplace.getObsoleteId()); + messanger.sendMessage(message); + + localReferentialService.replaceObsoleteReference(referenceToReplace); + + } + + // si on ne commite pas ici, les modifications utilisateurs sont perdues + getTransaction().commitTransaction(); + + // suppression des entités obsoletes de la base source + + ids = diff.get(DiffState.REMOVED); + if (CollectionUtils.isNotEmpty(ids)) { + + localReferentialService.deleteEntities(ids); + + } + + if (MapUtils.isNotEmpty(versionsToUpdate)) { + + // on applique le patch sur les versions pour bien avoir + // la bonne version de topiaversion et pas seulement un incrément + // de 1 puisque ce champs est géré par hibernate et qu'il ne nous laisse + // pas la possibilité de choisir la valeur qu'on veut attribuer au champs... + patchTopiaVersions(versionsToUpdate); + } + + getTransaction().commitTransaction(); + + } finally { + + centralSourceFactory.close(); + + } + } + + private static final String UPDATE_VERSION_PATTERN = "UPDATE %1$s SET topiaversion = %2$d WHERE topiaid='%3$s';\n"; + + protected void patchTopiaVersions(Map<TopiaEntity, Long> versionsToUpdate) throws TopiaException { + + final StringBuilder buffer = new StringBuilder(); + + for (Map.Entry<TopiaEntity, Long> entry : + versionsToUpdate.entrySet()) { + TopiaEntity entity = entry.getKey(); + String id = entity.getTopiaId(); + Long version = entry.getValue(); + String tableName = Entities.getTableName(entity); + buffer.append(String.format(UPDATE_VERSION_PATTERN, tableName, version, id)); + + } + ((TopiaContextImplementor) getTransaction()).getHibernate().doWork(new Work() { + + @Override + public void execute(Connection connection) throws SQLException { + String sql = buffer.toString(); + PreparedStatement sta = connection.prepareStatement(sql); + try { + if (log.isDebugEnabled()) { + log.debug("Will execute sql code :\n" + sql); + } + sta.executeUpdate(); + } finally { + sta.close(); + } + } + }); + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java index 654a379..3349da2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java @@ -1,12 +1,20 @@ package fr.ird.observe.services.referential; +import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.entities.referentiel.LengthWeightParameter; +import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.entities.referentiel.Sex; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; +import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; +import org.nuiton.topia.persistence.TopiaEntity; +import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.Set; @@ -38,6 +46,13 @@ public interface ReferentialService extends ObserveService { Set<String> getSpeciesListSpeciesIds(String speciesListId); + LengthWeightParameter findLengthWeightParameter(Species species, Ocean ocean, Sex sex, Date date) throws ObserveTechnicalException; + + Collection<? extends TopiaEntity> loadSimpleEntities(Collection<String> entityIds); + + @Commit + void copySimpleEntities(Collection<? extends TopiaEntity> entities); + <R extends ReferenceEntity> R preCreate(Class<R> entityType); @Commit @@ -45,4 +60,11 @@ public interface ReferentialService extends ObserveService { @Commit <R extends ReferenceEntity> void delete(Class<R> entityType, String referentialId); + + @Commit + void deleteEntities(Collection<String> entityIds); + + @Commit + void replaceObsoleteReference(ObsoleteReferenceToReplace action); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index fa3c99a..0202565 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -4,23 +4,39 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveEntityEnum; +import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.ReferenceStatus; import fr.ird.observe.entities.referentiel.LengthWeightParameter; +import fr.ird.observe.entities.referentiel.LengthWeightParameterDAO; +import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; +import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ProgramDAO; import fr.ird.observe.entities.referentiel.Programs; import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.entities.referentiel.Sex; +import fr.ird.observe.entities.referentiel.SexDAO; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.SpeciesList; import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; +import org.nuiton.topia.persistence.util.TopiaEntityRef; import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,6 +50,9 @@ import java.util.Set; */ public class ReferentialServiceImpl extends AbstractObserveService implements ReferentialService { + /** Logger. */ + private static final Log log = LogFactory.getLog(ReferentialServiceImpl.class); + @Override public List<Program> getAllProgramStub() { @@ -78,7 +97,7 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re return Lists.newArrayList(entities); } - @Override + @Override public <E extends ReferenceEntity> List<E> loadAndDecorateList(Class<E> entityType) { List<E> entities = getDao(entityType).findAll(); @@ -131,6 +150,26 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } @Override + public Collection<? extends TopiaEntity> loadSimpleEntities(Collection<String> entityIds) { + + Collection<TopiaEntity> result = new ArrayList<TopiaEntity>(); + + for (String entityId : entityIds) { + + TopiaEntity entityToLoad = getTransaction().findByTopiaId(entityId); + TopiaDAO<TopiaEntity> dao = getDao(entityToLoad); + TopiaEntity entityLoaded = dao.newInstance(); + loadEntity(entityToLoad, entityLoaded); + + result.add(entityLoaded); + + } + + return result; + + } + + @Override public Set<String> getSpeciesListSpeciesIds(String speciesListId) { SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListId); @@ -141,6 +180,143 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } + /** + * Recherche d'un {@link LengthWeightParameter} à partir des paramètres donnés. + * <p/> + * La recherche peut ne peut être aussi exacte que les paramètres donnés : + * <p/> + * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son + * speciesGroup d'espèce. + * <p/> + * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on + * recherche avec un ocean vide. + * <p/> + * Si non trouvé sur le gender (et que le gender n'est pas indéterminé) , alors + * on recherche avec le gender indéterminé (gender=0). + * + * @param species l'espèce sur lequel on recherche le paramétrage + * @param ocean l'ocean recherché (peut être null) + * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) + * @param date le jour recherché + * @return le paramétrage adéquate + * @since 1.5 + */ + public LengthWeightParameter findLengthWeightParameter(Species species, Ocean ocean, Sex sex, Date date) throws ObserveTechnicalException { + + LengthWeightParameterDAO dao = (LengthWeightParameterDAO) getDao(LengthWeightParameter.class); + List<LengthWeightParameter> list = dao.findAllBySpecies(species); + + if (CollectionUtils.isEmpty(list)) { + + // aucun parametrage pour le type donne + return null; + + } + + // filtrage par ocean + list = LengthWeightParemeterHelper.filterByOcean(list, ocean); + + if (CollectionUtils.isEmpty(list) && ocean != null) { + + // filtre par ocean null + list = LengthWeightParemeterHelper.filterByOcean(list, null); + + } + + if (CollectionUtils.isEmpty(list)) { + + // pas d'ocean adequate + return null; + + } + + // filtrage par sexe + list = LengthWeightParemeterHelper.filterBySexe(list, sex); + + if (CollectionUtils.isEmpty(list)) { + + // Sex with code 0 + Sex unkwonSex = ((SexDAO) getDao(Sex.class)).getUnknownSex(); + + if (unkwonSex.equals(sex)) { + + // filtrage par sexe indetermine + list = LengthWeightParemeterHelper.filterBySexe(list, unkwonSex); + + } + + + } + + if (CollectionUtils.isEmpty(list)) { + + // pas de sexe adequate + return null; + + } + + // filtrage par startDate de validite + list = LengthWeightParemeterHelper.filterByDateDebutValidite(list, date); + + if (CollectionUtils.isEmpty(list)) { + + // pas de date de debut adequate + return null; + + } + + // filtrage par endDate de validite + list = LengthWeightParemeterHelper.filterByDateFinValidite(list, date); + + if (CollectionUtils.isEmpty(list)) { + + // pas de date de fin adequate + return null; + + } + + // au final il ne devrait en rester qu'un + + if (list.size() > 1) { + + StringBuilder sb = new StringBuilder("Il existe plusieurs paramétrages possibles pour les données suivantes :"); + sb.append("\nEspece : "); + sb.append(decorateEntity(species)); + sb.append("\nOcean : "); + sb.append(decorateEntity(ocean)); + sb.append("\nSex : "); + sb.append(decorateEntity(sex)); + sb.append("\nDate : ").append(date); + sb.append("\nParamétrages trouvés : "); + for (LengthWeightParameter p : list) { + sb.append("\n - ").append(decorateEntity(p)); + } + + //FIXME Use a specific exception for this + throw new ObserveTechnicalException(sb.toString()); + + } + + LengthWeightParameter result = list.get(0); + if (log.isDebugEnabled()) { + + StringBuilder sb = new StringBuilder("Paramétrage trouvé pour les données suivantes :"); + sb.append("\nEspece : "); + sb.append(decorateEntity(species)); + sb.append("\nOcean : "); + sb.append(decorateEntity(ocean)); + sb.append("\nSex : "); + sb.append(decorateEntity(sex)); + sb.append("\nDate : ").append(date); + sb.append("\nParamétrage: ").append(decorateEntity(result)); + log.debug(sb.toString()); + + } + + return result; + + } + @Override public <R extends ReferenceEntity> R preCreate(Class<R> entityType) { @@ -203,6 +379,159 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } + + @Override + public void deleteEntities(Collection<String> entityIds) { + + for (String entityId : entityIds) { + + TopiaEntity entityToDelete = getTransaction().findByTopiaId(entityId); + Class<TopiaEntity> entityType = getEntityContractClass(entityToDelete); + TopiaDAO<TopiaEntity> dao = getDao(entityType); + dao.delete(entityToDelete); + + } + } + + @Override + public void copySimpleEntities(Collection<? extends TopiaEntity> entities) { + + for (TopiaEntity entity : entities) { + + TopiaDAO<TopiaEntity> dao = getDao(entity); + + TopiaEntity entityLoaded = dao.findByTopiaId(entity.getTopiaId()); + loadEntity(entity, entityLoaded); + + } + + } + + @Override + public void replaceObsoleteReference(ObsoleteReferenceToReplace action) { + + String obsoleteId = action.getObsoleteId(); + String safeId = action.getSafeId(); + TopiaEntityRef[] refs = action.getRefs(); + + if (log.isInfoEnabled()) { + log.info("load obsolete object " + obsoleteId); + } + + if (log.isInfoEnabled()) { + log.info("load safe object " + safeId); + } + + TopiaEntity safeRef = getTransaction().findByTopiaId(safeId); + + // on remplace les references + for (TopiaEntityRef ref : refs) { + + TopiaEntity invoker = ref.getInvoker(); + + if (invoker == null) { + throw new NullPointerException("can not have a null invoker in " + ref); + } + + TopiaDAO<TopiaEntity> dao = getDao(invoker); + + + if (log.isInfoEnabled()) { + log.info("load invoker object " + invoker.getTopiaId()); + } + + invoker = dao.findByTopiaId(invoker.getTopiaId()); + + // switch entity + + String path = ref.getInvokerProperty(); + + JXPathContext jxcontext = JXPathContext.newContext(invoker); + + TopiaEntity oldValue = (TopiaEntity) jxcontext.getValue(path); + + if (log.isDebugEnabled()) { + log.debug("property to switch " + path + " old : " + + oldValue); + } + + if (log.isInfoEnabled()) { + log.info("change path : " + path); + log.info("old value : " + oldValue.getTopiaId()); + } + + jxcontext.setValue(path, safeRef); + + TopiaEntity newValue = (TopiaEntity) jxcontext.getValue(path); + + if (log.isInfoEnabled()) { + log.info("new value : " + newValue.getTopiaId()); + } + if (log.isDebugEnabled()) { + log.debug("property to switch " + path + " new : " + + safeRef); + log.debug("property to switch " + path + " new Check : " + + newValue); + } + + dao.update(invoker); + + } + + } + + protected <E extends TopiaEntity> void loadEntity(E source, E target) { + + getBinderService().simpleCopy(source, target, false); + + if (source instanceof Species) { + + // Need also to bind ocean + loadAssociation(Species.class, Ocean.class, Species.PROPERTY_OCEAN, (Species) source, (Species) target); + + } else if (source instanceof SpeciesList) { + + // Need also to bind species + loadAssociation(SpeciesList.class, Species.class, SpeciesList.PROPERTY_SPECIES, (SpeciesList) source, (SpeciesList) target); + + } + + } + + public <E extends TopiaEntity, C extends TopiaEntity> void loadAssociation(Class<E> entityType, + Class<C> childEntityType, + String propertyName, + E source, + E target) { + + EntityListUpdator<E, C> listUpdator = EntityListUpdator.newEntityListUpdator(entityType, childEntityType, propertyName); + + int size = listUpdator.size(source); + + List<C> targetList = Lists.newArrayListWithCapacity(size); + + if (size > 0) { + + TopiaDAO<C> dao = getDao(childEntityType); + + Collection<C> sourceList = listUpdator.getChilds(source); + + for (C childToLoad : sourceList) { + + C childLoaded = dao.newInstance(); + childLoaded.setTopiaId(childToLoad.getTopiaId()); + childLoaded.setTopiaVersion(childToLoad.getTopiaVersion()); + childLoaded.setTopiaCreateDate(childToLoad.getTopiaCreateDate()); + targetList.add(childLoaded); + + } + + } + + listUpdator.setChilds(target, targetList); + + } + protected static Map<Class<? extends ReferenceEntity>, String[]> NATURAL_IDS; protected static Map<Class<? extends ReferenceEntity>, String[]> getNaturalIds() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java index 750762e..4c88c27 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java @@ -429,7 +429,7 @@ public class ObserveContext extends ObserveApplicationContext { DataSource source = event.getSource(); // on désenregistre la source du service de données - getDataService().unregisterDataSource(source); + ObserveServiceHelper.get().setDataSource(null); // on dettache la validation getValidationContext().closeDataSource(); @@ -480,7 +480,7 @@ public class ObserveContext extends ObserveApplicationContext { protected void openOnUI(DataSource source) throws DataSourceException { // on rend le service disponible dans le service de données - getDataService().registerDataSource(source); + ObserveServiceHelper.get().setDataSource(source); // on rend le service disponible dans le service de validation getValidationContext().setDataSource(source); diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveRunner.java b/observe-swing/src/main/java/fr/ird/observe/ObserveRunner.java index 68a2118..fc1b404 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveRunner.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveRunner.java @@ -86,12 +86,12 @@ public abstract class ObserveRunner extends ApplicationRunner { return (ObserveRunner) ApplicationRunner.getRunner(); } - public static ObserveResourceManager getResourceManager() { - if (resourceManager == null) { - throw new IllegalStateException("No resourceManager initialized"); - } - return resourceManager; - } +// public static ObserveResourceManager getResourceManager() { +// if (resourceManager == null) { +// throw new IllegalStateException("No resourceManager initialized"); +// } +// return resourceManager; +// } public static ObserveActionExecutor getActionExecutor() { if (actionExecutor == null) { @@ -254,7 +254,6 @@ public abstract class ObserveRunner extends ApplicationRunner { context, ObserveContext.CONFIG_ENTRY_DEF, ObserveContext.ACTIONS_ENTRY_DEF, - ObserveContext.DATA_SERVICE_ENTRY_DEF, ObserveContext.DECORATOR_SERVICE_ENTRY_DEF ); @@ -602,8 +601,8 @@ public abstract class ObserveRunner extends ApplicationRunner { // add config ObserveContext.CONFIG_ENTRY_DEF.setContextValue(instance, config); - // add dataService - instance.getDataService(); +// // add dataService +// instance.getDataService(); // add data context instance.getDataContext(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/ObserveMainUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/ObserveMainUIHandler.java index 2360afa..19db078 100755 --- a/observe-swing/src/main/java/fr/ird/observe/ui/ObserveMainUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/ObserveMainUIHandler.java @@ -21,7 +21,6 @@ */ package fr.ird.observe.ui; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; @@ -274,9 +273,9 @@ public class ObserveMainUIHandler { return source; } - protected static DataService getDataService() { - return ObserveContext.get().getDataService(); - } +// protected static DataService getDataService() { +// return ObserveContext.get().getDataService(); +// } public static void restartEdit() { ContentUI<?> selectedUI = ObserveContext.get().getSelectedContentUI(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java index e5f1f1f..5195f51 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java @@ -21,34 +21,24 @@ */ package fr.ird.observe.ui.admin; -import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.ObserveRunner; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.SendMessageAble; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.ReplicationService; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListener; import fr.ird.observe.db.event.DataSourceListenerAdapter; -import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.gps.GPSService; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.admin.config.SelectDataUI; import fr.ird.observe.ui.admin.resume.ShowResumeUI; import fr.ird.observe.ui.tree.DataSelectionTreeSelectionModel; import fr.ird.observe.ui.tree.ObserveTreeHelper; -import fr.ird.observe.validation.ValidationService; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; import javax.swing.JTree; import javax.swing.tree.TreeModel; @@ -82,8 +72,7 @@ public class AdminTabUIHandler implements SendMessageAble { DataSource service = event.getSource(); if (event.getMessageLevel() == DataSourceEvent.MessageLevel.INFO) { - sendMessage(service.getShortLabel() + " : " + - event.getMessage()); + sendMessage(service.getShortLabel() + " : " + event.getMessage()); } } }; @@ -91,20 +80,6 @@ public class AdminTabUIHandler implements SendMessageAble { protected AdminUI parentUI; /** - * Service de replication. - * <p/> - * Note: le service est sans état et donc peut rester en état du handler. - */ - private ReplicationService replicationService; - - /** - * Service de replication. - * <p/> - * Note: le service est sans état et donc peut rester en état du handler. - */ - private ValidationService validationService; - - /** * Service de gps. * <p/> * Note: le service est sans état et donc peut rester en état du handler. @@ -114,12 +89,6 @@ public class AdminTabUIHandler implements SendMessageAble { /** Service de decoration. */ private DecoratorService decoratorService; - /** Service de manipulation de données depuis des bases. */ - private DataService dataService; - - /** Service de binders. */ - private BinderService binderService; - public AdminTabUIHandler(AdminTabUI ui) { this.ui = ui; model = ui.getModel(); @@ -133,20 +102,6 @@ public class AdminTabUIHandler implements SendMessageAble { return model; } - public final ReplicationService getReplicationService() { - if (replicationService == null) { - replicationService = ObserveServiceHelper.newReplicationService(); - } - return replicationService; - } - - public final ValidationService getValidationService() { - if (validationService == null) { - validationService = ObserveServiceHelper.newValidationService(); - } - return validationService; - } - public final DecoratorService getDecoratorService() { if (decoratorService == null) { decoratorService = ObserveContext.get().getDecoratorService(); @@ -154,20 +109,6 @@ public class AdminTabUIHandler implements SendMessageAble { return decoratorService; } - public final DataService getDataService() { - if (dataService == null) { - dataService = ObserveContext.get().getDataService(); - } - return dataService; - } - - public final BinderService getBinderService() { - if (binderService == null) { - binderService = ObserveContext.get().getBinderService(); - } - return binderService; - } - public final GPSService getGpsService() { if (gpsService == null) { gpsService = ObserveContext.get().getGPSService(); @@ -182,67 +123,28 @@ public class AdminTabUIHandler implements SendMessageAble { source = model.getSafeLocalSource(false); } return source; + } public final WizardState onCancel(Exception e) { + if (log.isDebugEnabled()) { log.debug(this, e); } sendMessage(t("observe.message.synchro.operation.canceled")); return WizardState.CANCELED; + } public final WizardState onError(Exception e) { + model.getStepModel(model.getOperation()).setError(e); if (log.isErrorEnabled()) { log.error(e.getMessage(), e); } sendMessage(t("observe.message.synchro.operation.failed")); return WizardState.FAILED; - } - - protected void replicateData(DataSource source, - DataSource target, - String... tripIds) throws DataSourceException { - ReplicationService service = getReplicationService(); - if (tripIds == null || tripIds.length == 0) { - - // on replique toutes les données - service.replicateAllData(source, target); - } else { - - // on replique les données specifiees - service.replicateData(source, target, tripIds); - } - } - - protected void replicateReferentiel(DataSource source, - DataSource target) throws DataSourceException { - getReplicationService().replicateReferentiel(source, target); - } - - protected TopiaContext beginTransaction(DataSource source, String methodName) throws DataSourceException { - TopiaContext ctxt = source.beginTransaction(methodName); - return ctxt; - } - - protected void commitTransaction(DataSource source, TopiaContext tx, String methodName) throws DataSourceException { - source.commitTransaction(tx, methodName); - } - - protected void closeTransaction(DataSource source, TopiaContext tx, String methodName) throws DataSourceException { - source.closeTransaction(tx, methodName); - } - - protected void rollbackTransaction(DataSource source, TopiaContext tx, String methodName) throws DataSourceException { - source.rollbackTransaction(tx, methodName); - } - - protected TopiaDAO<TopiaEntity> getDAO(TopiaContext tx, TopiaEntity entity) throws TopiaException { - TopiaDAO<TopiaEntity> dao = - ObserveDAOHelper.<TopiaEntity, TopiaDAO<TopiaEntity>>getDAO(tx, entity); - return dao; } public void initTabUI(AdminUI ui, AdminTabUI tabUI) { @@ -267,6 +169,7 @@ public class AdminTabUIHandler implements SendMessageAble { } public void updateState(AdminTabUI ui, WizardState newState) { + if (newState == null) { newState = WizardState.PENDING; } @@ -298,6 +201,7 @@ public class AdminTabUIHandler implements SendMessageAble { ui.CANCELED_progressionPane.setColumnHeaderView(ui.progressionTop); break; } + } public void sendMessage(String msg) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java index 823288e..92a6411 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java @@ -21,10 +21,10 @@ */ package fr.ird.observe.ui.admin; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveServiceHelper; +import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceConfig; import fr.ird.observe.db.DataSourceException; @@ -76,10 +76,6 @@ import static org.nuiton.i18n.I18n.t; */ public class AdminUIModel extends WizardExtModel<AdminStep> { - public static final String SHOW_RESUME_PROPERTY_NAME = "showResume"; - - public static final String NEED_LOCAL_SOURCE_PROPERTY_NAME = "needLocalSource"; - public static final String SELECTION_MODEL_CHANGED_PROPERTY_NAME = "selectionModelChanged"; public static final String SELECTED_TRIP_PROPERTY_NAME = "selectedTrip"; @@ -108,12 +104,11 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { /** le controleur pour configurer les sources */ protected StorageUIHandler storageHandler; - /** data service pour effectuer des opérations sur les sources */ - protected DataService dataService; - /** configuration de l'application */ protected ObserveConfig config; + private DataContext dataContext; + /** selection des donnees a valider */ protected DataSelectionModel selectionDataModel; @@ -121,6 +116,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { protected EnumSet<DbMode> availableIncomingModes; PropertyChangeListener listenStepChanged = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { @@ -229,6 +225,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { }; PropertyChangeListener listenValidationModified = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { ValidateModel source = (ValidateModel) evt.getSource(); @@ -248,6 +245,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { }; PropertyChangeListener listenReportModified = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { ReportModel source = (ReportModel) evt.getSource(); @@ -262,6 +260,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { }; PropertyChangeListener listenerSelectedDataForReport = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { @@ -275,6 +274,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { }; PropertyChangeListener listenConsolidateModified = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { ConsolidateModel source = (ConsolidateModel) evt.getSource(); @@ -289,6 +289,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { }; PropertyChangeListener listenGPSModified = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { if (log.isDebugEnabled()) { @@ -301,6 +302,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { }; PropertyChangeListener listenSaveLocalChanged = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { @@ -447,14 +449,14 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { return (AdminActionModel) super.getStepModel(operation); } - public DataService getDataService() { - return dataService; - } - public ObserveConfig getConfig() { return config; } + public DataContext getDataContext() { + return dataContext; + } + /** * Pour savoir si on a besoin d'une base source pour l'opération. * <p/> @@ -520,8 +522,9 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { availableIncomingModes.clear(); storageHandler = ui.getContextValue(StorageUIHandler.class); - dataService = ui.getContextValue(DataService.class); +// dataService = ui.getContextValue(DataService.class); config = ui.getContextValue(ObserveConfig.class); + dataContext = ui.getContextValue(DataContext.class); // demarrage du modèle : on fixe ici une fois pour toute les liste // des onglets visibles @@ -659,6 +662,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (log.isDebugEnabled()) { centralSourceModel.addPropertyChangeListener(new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); @@ -758,6 +762,7 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { if (log.isDebugEnabled()) { localSourceModel.addPropertyChangeListener(new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java index ed72580..7f35319 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java @@ -21,14 +21,12 @@ */ package fr.ird.observe.ui.admin.consolidate; +import com.google.common.base.Preconditions; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.admin.AdminActionModel; import fr.ird.observe.ui.admin.AdminStep; -import org.nuiton.decorator.Decorator; /** * Modele pour preparer une validation de donnees d'une base. @@ -41,13 +39,7 @@ public class ConsolidateModel extends AdminActionModel { /** la source de données où effectuer la consolidation des données */ private DataSource source; - private Decorator<Program> programDecorator; - - private Decorator<TripSeine> tripDecorator; - - private Decorator<SetSeine> setDecorator; - - private Decorator<ActivitySeine> activityDecorator; + protected ObserveServiceFactory serviceFactory; public ConsolidateModel() { super(AdminStep.CONSOLIDATE); @@ -59,43 +51,28 @@ public class ConsolidateModel extends AdminActionModel { public void setSource(DataSource source) { this.source = source; + if (serviceFactory != null) { + serviceFactory.close(); + serviceFactory = null; + } } - public Decorator<Program> getProgramDecorator() { - return programDecorator; - } - - public void setProgramDecorator(Decorator<Program> programDecorator) { - this.programDecorator = programDecorator; - } - - public Decorator<TripSeine> getTripDecorator() { - return tripDecorator; - } + public ObserveServiceFactory getServiceFactory() { - public void setTripDecorator(Decorator<TripSeine> tripDecorator) { - this.tripDecorator = tripDecorator; - } + if (serviceFactory == null) { - public Decorator<SetSeine> getSetDecorator() { - return setDecorator; - } + Preconditions.checkNotNull(source, "Can't create source service factory if source is null"); + serviceFactory = ObserveContext.newServiceFactory(source); - public void setSetDecorator(Decorator<SetSeine> setDecorator) { - this.setDecorator = setDecorator; - } + } + return serviceFactory; - public Decorator<ActivitySeine> getActivityDecorator() { - return activityDecorator; - } - - public void setActivityDecorator(Decorator<ActivitySeine> activityDecorator) { - this.activityDecorator = activityDecorator; } @Override public void destroy() { super.destroy(); - source = null; + setSource(null); } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java index be55ccb..d5da3d8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java @@ -21,17 +21,10 @@ */ package fr.ird.observe.ui.admin.consolidate; -import fr.ird.observe.ConsolidateDataService; -import fr.ird.observe.DecoratorService; -import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.model.DataSelectionModel; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.operation.ComputeDataService; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUI; import fr.ird.observe.ui.admin.AdminTabUIHandler; @@ -41,15 +34,11 @@ import fr.ird.observe.ui.admin.config.SelectDataUI; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.persistence.TopiaDAO; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; import java.util.Date; -import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; import static org.nuiton.i18n.I18n.t; @@ -83,32 +72,31 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { System.identityHashCode(ui)); } - tabUI.getStartButton().setText( - t("observe.action.synchro.launch.operation", - t(tabUI.getStep().getOperationLabel()))); + tabUI.getStartButton().setText(t("observe.action.synchro.launch.operation", t(tabUI.getStep().getOperationLabel()))); - final SelectDataUI selectTabUI = (SelectDataUI) - ui.getStepUI(AdminStep.SELECT_DATA); + final SelectDataUI selectTabUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); PropertyChangeListener listener = new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { - AdminUIModel model = (AdminUIModel) evt.getSource(); - if (!model.containsStep(selectTabUI.getStep())) { - // avoid multi-cast - return; - } - DataSelectionModel value = (DataSelectionModel) evt.getNewValue(); - if (log.isDebugEnabled()) { - log.debug("selection model changed to " + value); + + AdminUIModel source = (AdminUIModel) evt.getSource(); + if (source.containsStep(selectTabUI.getStep())) { + + DataSelectionModel value = (DataSelectionModel) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("selection model changed to " + value); + } + updateSelectionModel(selectTabUI); + } - updateSelectionModel(selectTabUI); + } }; - tabUI.getModel().addPropertyChangeListener( - AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, - listener - ); + + tabUI.getModel().addPropertyChangeListener(AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, listener); + } public void startAction() { @@ -116,12 +104,14 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { addAdminWorker( ((ConsolidateUI) ui).getStartButton().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return doAction(); } } ); + } public WizardState doAction() throws Exception { @@ -136,72 +126,27 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { // une erreur ou une annulation return init; } - java.util.Set<String> tripIds = model.getSelectionDataModel().getSelectedData(); - List<TripSeine> toUpdate = new ArrayList<TripSeine>(tripIds.size()); - - ConsolidateDataService service = - ObserveServiceHelper.getConsolidateDataService(); - - DataSource source = getStepModel().getSource(); - String txName = "consolidateData"; - - TopiaContext tx = source.beginTransaction(txName); - try { - TopiaDAO<TripSeine> dao = source.getDAO(tx, TripSeine.class); - for (String mareeId : tripIds) { - if (Entities.isSeineId(mareeId)) { + Set<String> tripIds = model.getSelectionDataModel().getSelectedData(); - TripSeine trip = (TripSeine) tx.findByTopiaId(mareeId); + ObserveServiceFactory serviceFactory = getStepModel().getServiceFactory(); - boolean needUpdate = service.consolidateTrip(this, tx, trip); - if (needUpdate) { + ComputeDataService service = serviceFactory.getService(ComputeDataService.class); - // on met a jour la maree en base - dao.update(trip); - - // on conserve une reference sur la maree mise à jour - toUpdate.add(trip); - } - - } - - } - - // on commite si quelque chose a ete mise a jour - boolean needCommit = !toUpdate.isEmpty(); - - if (needCommit) { - - sendMessage(t("observe.message.consolidate.save.changes", - toUpdate.size())); - source.commitTransaction(tx, txName); - } + try { - } catch (Exception eee) { - try { - source.rollbackTransaction(tx, txName); - } catch (DataSourceException e1) { + service.consolidateTrips(this, tripIds); - // une autre erreur lors du rollback, qui ne doit pas empecher - // de continuer le traitement - if (log.isErrorEnabled()) { - log.error(e1); - } - } - throw eee; } finally { - // clean service - service.clear(); + service.close(); - // toujours fermer la transaction - source.closeTransaction(tx, txName); } - sendMessage(t("observe.message.consolidate.operation.done", - new Date())); + sendMessage(t("observe.message.consolidate.operation.done", new Date())); + return WizardState.SUCCESSED; + } @@ -213,18 +158,6 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { openSource(source); - DecoratorService dProvider = getDecoratorService(); - ConsolidateModel stepModel = getStepModel(); - - Decorator<Program> p = dProvider.getDecoratorByType(Program.class); - Decorator<TripSeine> m = dProvider.getDecoratorByType(TripSeine.class); - Decorator<ActivitySeine> a = dProvider.getDecoratorByType(ActivitySeine.class); - Decorator<SetSeine> c = dProvider.getDecoratorByType(SetSeine.class); - stepModel.setProgramDecorator(p); - stepModel.setTripDecorator(m); - stepModel.setActivityDecorator(a); - stepModel.setSetDecorator(c); - return null; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java index 29ee79a..8233e85 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java @@ -21,8 +21,11 @@ */ package fr.ird.observe.ui.admin.export; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; +import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; @@ -64,6 +67,8 @@ public class ExportModel extends AdminActionModel { protected DataSource centralSource; + protected ObserveServiceFactory centralServiceFactory; + public ExportModel() { super(AdminStep.EXPORT_DATA); } @@ -140,6 +145,20 @@ public class ExportModel extends AdminActionModel { public void setCentralSource(DataSource centralSource) { this.centralSource = centralSource; + if (centralServiceFactory != null) { + centralServiceFactory.close(); + centralServiceFactory = null; + } + } + + public ObserveServiceFactory getCentraServiceFactory() { + + if (centralServiceFactory == null) { + Preconditions.checkNotNull(centralSource, "Can't create source service factory if centralSource is null"); + centralServiceFactory = ObserveContext.newServiceFactory(centralSource); + } + return centralServiceFactory; + } public void setProgramDecorator(Decorator<Program> programDecorator) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java index c47c714..12e9561 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java @@ -22,13 +22,13 @@ package fr.ird.observe.ui.admin.export; import fr.ird.observe.DecoratorService; -import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.data.TripService; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.UIHelper; @@ -86,6 +86,7 @@ public class ExportUIHandler extends AdminTabUIHandler { final SelectDataUI selectTabUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); tabUI.getModel().addPropertyChangeListener(AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { AdminUIModel model = (AdminUIModel) evt.getSource(); @@ -166,6 +167,7 @@ public class ExportUIHandler extends AdminTabUIHandler { addAdminWorker( ((ExportUI) ui).getPrepareAction().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return prepareAction(); @@ -184,6 +186,7 @@ public class ExportUIHandler extends AdminTabUIHandler { addAdminWorker( tabUI.getStartAction().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return doAction(); @@ -236,45 +239,44 @@ public class ExportUIHandler extends AdminTabUIHandler { List<TripEntry> entries = stepModel.getData(); if (entries.isEmpty()) { + // pas de données possible à exporter sendMessage(t("observe.message.exportData.not.possible")); sendMessage(t("observe.message.synchro.operation.done", new Date())); return WizardState.CANCELED; + } sendMessage(t("observe.message.exportData.operation.needFix", new Date())); // on rend la main à l'ui pour que l'utilisateur selectionne les marees a exporter return WizardState.NEED_FIX; + } public WizardState doAction() throws Exception { ExportModel stepModel = model.getExportModel(); - DataSource centralSource = stepModel.getCentralSource(); - DataSource localSource = stepModel.getSource(); - - ObserveServiceFactory centralServices = ObserveContext.newServiceFactory(centralSource); - ObserveServiceFactory localServices = ObserveContext.newServiceFactory(localSource ); - // on filtre les marées sélectionnées pour export List<TripEntry> tripEntries = stepModel.getSelectedTrips(); for (TripEntry tripEntry : tripEntries) { - processTrip(stepModel, tripEntry,localServices, centralServices); + processTrip(stepModel, tripEntry); } sendMessage(t("observe.message.synchro.operation.done", new Date())); return WizardState.SUCCESSED; + } - protected void processTrip(ExportModel stepModel, TripEntry tripEntry, ObserveServiceFactory localServices, ObserveServiceFactory centralServices) throws Exception { + protected void processTrip(ExportModel stepModel, TripEntry tripEntry) throws Exception { + + ObserveServiceFactory centralServices = stepModel.getCentraServiceFactory(); - DataSource centralSource = stepModel.getCentralSource(); DataSource source = stepModel.getSource(); Trip trip = tripEntry.getTrip(); @@ -303,26 +305,8 @@ public class ExportUIHandler extends AdminTabUIHandler { } sendMessage(t("observe.message.exportData.replicate.maree", tripDecorated, programDecorated)); - try { - replicateData(source, centralSource, tripId); - } catch (Exception e) { - //FIXME 20100726 : il faut supprimer tous les objets crées pour cette marée - -// tx = beginTransaction(centralSource, txName); -// -// // on supprime la maree qui n'a pas pu etre importee -// try { -// TopiaDAO<Trip> dao = ObserveDAOHelper.getTripSeineDAO(tx); -// // on recharge la données depuis la base centrale -// m = dao.findByTopiaId(m.getTopiaId()); -// dao.delete(m); -// commitTransaction(centralSource, tx, txName); -// } finally { -// closeTransaction(centralSource, tx, txName); -// } - - throw e; - } + ReplicationService service = centralServices.getService(ReplicationService.class); + service.replicateData(source, tripId); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java index b440c9c..516ad80 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java @@ -22,14 +22,15 @@ package fr.ird.observe.ui.admin.gps; import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.entities.OpenableEntities; import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.gps.GPSPoint; import fr.ird.observe.gps.GPSPointInterval; import fr.ird.observe.gps.GPSRoute; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.operation.GpsImportService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUIHandler; @@ -39,15 +40,9 @@ import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.swing.editor.MyDefaultCellEditor; import jaxx.runtime.swing.renderer.BooleanCellRenderer; import jaxx.runtime.swing.wizard.ext.WizardState; -import org.apache.commons.collections.primitives.ArrayIntList; -import org.apache.commons.collections.primitives.IntIterator; -import org.apache.commons.collections.primitives.IntList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListSelectionModel; @@ -81,10 +76,6 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { /** Logger */ private static final Log log = LogFactory.getLog(ImportGPSUIHandler.class); - - /** un drapeau pour savoir si on a deja initialise l'action */ - protected boolean wasInit; - /** la route ouverte */ protected TripSeine openTripSeine; @@ -140,6 +131,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { configUI.getExtraConfig().add(extraConfig); DefaultListCellRenderer listRenderer = new DefaultListCellRenderer() { + private static final long serialVersionUID = 1L; @Override @@ -181,6 +173,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { tabUI.setContextValue(renderer2, "defaultTableRenderer"); DefaultTableCellRenderer renderer3 = new DefaultTableCellRenderer() { + private static final long serialVersionUID = 1L; @Override @@ -254,6 +247,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { n("observe.synchro.table.importGPS.computed.label"), n("observe.synchro.table.importGPS.computed.label.tip")); DefaultTableCellRenderer renderer4 = new DefaultTableCellRenderer() { + private static final long serialVersionUID = 1L; @Override @@ -338,6 +332,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { addAdminWorker( getUi().getPrepareAction().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return prepareAction(); @@ -356,6 +351,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { addAdminWorker( tabUI.getStartAction().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return doAction(); @@ -378,38 +374,37 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { // ouverture de la base locale openSource(source); + ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(source); + + GpsImportService service = serviceFactory.getService(GpsImportService.class); + // récuperation de la marée ouverte - TopiaContext srcCtxt = beginTransaction(source, "beforeAction"); - try { - openTripSeine = OpenableEntities.getOpenTrip(srcCtxt); - } catch (TopiaException e) { - closeTransaction(source, srcCtxt, "beforeAction"); - } + openTripSeine = service.getOpenTrip(); if (openTripSeine == null) { - // pas de route ouverte + + // pas de marée ouverte sendMessage(t("observe.message.no.open.maree.detected")); return WizardState.FAILED; + } - if (openTripSeine.isRouteEmpty()) { + data = service.getActivitiesForOpenRoute(openTripSeine.getTopiaId()); + + if (data == null) { + // pas de route sur la maree ouverte sendMessage(t("observe.message.no.route.detected")); return WizardState.FAILED; - } - for (Route r : openTripSeine.getRoute()) { - if (!r.isActivitySeineEmpty()) { - // on enregistre les actitives - for (ActivitySeine a : r.getActivitySeine()) { - data.put(a, null); - } - } + } if (data.isEmpty()) { - // pas d'activity a traiter + + // pas d'activité a traiter sendMessage(t("observe.message.no.activity.detected")); return WizardState.FAILED; + } ImportGPSModel gpsModel = model.getImportGPSModel(); @@ -427,9 +422,11 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { List<GPSPointInterval> acceptedInterval = route.getAcceptedInterval(); if (acceptedInterval == null || acceptedInterval.isEmpty()) { + // pas d'intervalle acceptable sendMessage(t("observe.message.no.accepted.intervalle.detected")); return WizardState.FAILED; + } for (GPSPointInterval i : acceptedInterval) { @@ -440,23 +437,24 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { sendMessage(t("observe.message.detected.rejected.interval", i)); } - - // il s'agit de la première passe : detection des point gps - //des activitys + // il s'agit de la première passe : detection des point gps des activités sendMessage(t("observe.message.importGPS.detect.points")); detectPoints(); if (data.isEmpty()) { - // aucune activity modifiable + + // aucune activité modifiable sendMessage(t("observe.message.importGPS.nothing.to.do")); sendMessage(t("observe.message.synchro.operation.done", new Date())); return WizardState.SUCCESSED; + } sendMessage(t("observe.message.importGPS.operation.needFix", new Date())); return WizardState.NEED_FIX; + } public WizardState doAction() throws Exception { @@ -483,6 +481,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { sendMessage(t("observe.message.synchro.operation.done", new Date())); return WizardState.SUCCESSED; + } @@ -516,76 +515,21 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { for (ActivitySeine a : rejected) { data.remove(a); } + } protected void applyPoints() throws Exception { int[] selectedIndex = model.getImportGPSModel().getImportGPSSelectedIndex(); - IntList lIndex = new ArrayIntList(selectedIndex.length); - - String txName = "applyPoints"; - TopiaContext ctxt = beginTransaction(source, txName); - - try { + ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(source); + GpsImportService service = serviceFactory.getService(GpsImportService.class); + service.applyPoints(data, selectedIndex, this); - for (int i : selectedIndex) { - lIndex.add(i); - } - IntIterator indexItr = lIndex.iterator(); - - int currentActivityIndex = 0; - int nextActivityIndex = indexItr.next(); - - TopiaDAO<ActivitySeine> activityDAO = source.getDAO(ctxt, ActivitySeine.class); - for (ActivitySeine a : data.keySet()) { - if (currentActivityIndex == nextActivityIndex) { - // l'activity courante a ete selectionne - GPSPoint p = data.get(a); - - sendMessage(t("observe.message.importGPS.apply.point", dGPSPoint.toString(p), dActivity.toString(a))); -// sendMessage(t("observe.message.importGPS.apply.point", p, a.getVesselActivity().getLabel2())); - float latitude = Math.abs(p.getLatitude()); - float longitude = Math.abs(p.getLongitude()); - int quadrant = p.getQuadrant(); - // application de la position - - ActivitySeine aa = activityDAO.findByTopiaId(a.getTopiaId()); - aa.setLatitude(latitude); - aa.setLongitude(longitude); - aa.setQuadrant(quadrant); - //TODO appliquer la vitesse ? - //a.setVesselSpeed(p.getVitesse()); - - // mise a jour de l'activity - - activityDAO.update(aa); -// a.update(); - - if (indexItr.hasNext()) { - // il reste au moins une activity a traiter - // recuperation du prochain index d'activity a traiter - nextActivityIndex = indexItr.next(); - } else { - // plus d'activity a traiter - break; - } - } - currentActivityIndex++; - } - - commitTransaction(source, ctxt, txName); - } catch (Exception e) { - rollbackTransaction(source, ctxt, txName); - throw e; - } finally { - - closeTransaction(source, ctxt, txName); - lIndex.clear(); - } } public void chooseImportGPSFile() { + ImportGPSModel gpsModel = getModel().getImportGPSModel(); File f = UIHelper.chooseFile( ui, @@ -595,6 +539,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { "^.+\\.gpx$", t("observe.action.choose.importGPS.description")); gpsModel.setImportGPSFile(f); + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java index 699e5b1..3951628 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java @@ -21,38 +21,22 @@ */ package fr.ird.observe.ui.admin.save; -import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.Ocean; -import fr.ird.observe.entities.referentiel.Species; -import fr.ird.observe.entities.referentiel.SpeciesList; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.operation.SynchronizeService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUIHandler; import fr.ird.observe.ui.admin.AdminUI; import fr.ird.observe.ui.admin.synchronize.SynchronizeModel; -import fr.ird.observe.ui.admin.synchronize.SynchronizeUIHandler; import jaxx.runtime.swing.wizard.ext.WizardState; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hibernate.jdbc.Work; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.DiffState; import java.io.File; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; import java.util.Date; -import java.util.List; -import java.util.Map; import java.util.concurrent.Callable; import static org.nuiton.i18n.I18n.t; @@ -68,9 +52,6 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { /** Logger */ private static final Log log = LogFactory.getLog(SaveLocalUIHandler.class); - private static final String UPDATE_VERSION_PATTERN = - "UPDATE %1$s SET topiaversion = %2$d WHERE topiaid='%3$s';\n"; - protected DataSource source; public SaveLocalUIHandler(SaveLocalUI ui) { @@ -115,7 +96,7 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { public void skipOperation() { sendMessage(t("observe.synchro.message.saveLocal.skip")); getModel().setStepState(AdminStep.SAVE_LOCAL, WizardState.SUCCESSED); -// getUi().getProgression().setText(t("observe.synchro.message.saveLocal.skip")); + // on passe directement à l'opération suivante if (model.getNextStep() != null) { model.gotoNextStep(); @@ -145,6 +126,7 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { addAdminWorker( getUi().getStartAction().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return doAction(); @@ -192,8 +174,6 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { public void saveReferentiel() throws Exception { - List<String> ids; - SynchronizeModel stepModel = getModel().getSynchronizeReferentielModel(); DataSource referentielSource = stepModel.getTmpSource(); @@ -202,190 +182,26 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { // pas de base temporaire // on travaille directement sur la base central referentielSource = stepModel.getCentralSource(); - } - DataSource targetSource = stepModel.getSource(); - DiffState.DiffStateMap diff = stepModel.getDiff(); + } - String txName = "saveReferentiel"; - TopiaContext targetTx = beginTransaction(targetSource, txName); + ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(referentielSource); try { - TopiaContext sourceTx = beginTransaction(referentielSource, txName); - try { - // ajout des nouvelles entites du referentiel - - ids = diff.get(DiffState.NEW); - if (CollectionUtils.isNotEmpty(ids)) { - for (String id : ids) { - //FIXME on doit s'assurer de l'orde d'injection des entites - TopiaEntity entity = sourceTx.findByTopiaId(id); - String message = t("observe.synchro.add.object", id); - sendMessage(message); - sourceTx.replicateEntity(targetTx, entity); - - // On est obligé de commiter à chaque ajout sinon si - // une autre entité à ajouter depend de celle là, on - // ne la retrouve pas - // - commitTransaction(targetSource, targetTx, txName); - if (log.isDebugEnabled()) { - log.debug("add [" + id + "] : " + targetTx.findByTopiaId(id)); - } - } - } - - // mis a jour des entites modifiees - ids = diff.get(DiffState.MODIFIED); - if (CollectionUtils.isNotEmpty(ids)) { + SynchronizeService service = serviceFactory.getService(SynchronizeService.class); - for (String id : ids) { + DataSource targetSource = stepModel.getSource(); - copyEntity(stepModel, sourceTx, targetTx, id); - } - } + DiffState.DiffStateMap diff = stepModel.getDiff(); - // mise à jour des données utilisateurs (remplacements d'objets obsolètes) + service.saveReferentiel(targetSource, diff, stepModel.getReplaceActions(), this); - for (SynchronizeUIHandler.ObsoleteRefReplaceAction action : stepModel.getReplaceActions()) { - - String message = t("observe.synchro.replaceObsolete.object", action.getObsoleteId()); - sendMessage(message); - - action.doAction(targetTx); - } - - // si on ne commite pas ici, les modifications utilisateurs - // sont perdues - commitTransaction(targetSource, targetTx, txName); - - // suppression des entités obsoletes de la base source - - ids = diff.get(DiffState.REMOVED); - if (CollectionUtils.isNotEmpty(ids)) { - for (String id : ids) { - String message = t("observe.synchro.remove.object", id); - sendMessage(message); - TopiaEntity entity = targetTx.findByTopiaId(id); - getDAO(targetTx, entity).delete(entity); - } - } - - Map<TopiaEntity, Long> versionsToUpdate = - stepModel.getVersionsToUpdate(); - - if (MapUtils.isNotEmpty(versionsToUpdate)) { - - // on applique le patch sur les versions pour bien avoir - // la bonne version de topiaversion et pas seulement un incrément - // de 1 puisque ce champs est géré par hibernate et qu'il ne nous laisse - // pas la possibilité de choisir la valeur qu'on veut attribuer au champs... - patchTopiaVersions((TopiaContextImplementor) targetTx, versionsToUpdate); - } - - commitTransaction(targetSource, targetTx, txName); - } finally { - try { - rollbackTransaction(referentielSource, sourceTx, txName); - } finally { - closeTransaction(referentielSource, sourceTx, txName); - } - } - } catch (Exception e) { - rollbackTransaction(targetSource, targetTx, txName); - throw e; } finally { - closeTransaction(targetSource, targetTx, txName); - } - } - protected <E extends TopiaEntity> void copyEntity(SynchronizeModel synchronizeModel, - TopiaContext sourceTx, - TopiaContext targetTx, - String id) throws TopiaException { - - E source = (E) sourceTx.findByTopiaId(id); - - long sourceVersion = source.getTopiaVersion(); - - String message = t("observe.synchro.update.object", source.getTopiaId(), sourceVersion); - sendMessage(message); - - TopiaDAO<E> dao = ObserveDAOHelper.<E, TopiaDAO<E>>getDAO(targetTx, source); - - E target = dao.findByTopiaId(source.getTopiaId()); - - long targetVersion = target.getTopiaVersion(); - - // bind new entity to old one - copyEntity(targetTx, source, target); - - if (targetVersion < sourceVersion) { - //FIXME chemit : si la version n'est pas exactement celle voulue, - // on positionner à la main la version( hibernate ne nous permet - // pas de le faire - if (log.isDebugEnabled()) { - message = "register [" + source.getTopiaId() + - "] to update version " + sourceVersion + - " to " + targetVersion; - log.debug(message); - } - synchronizeModel.getVersionsToUpdate().put(target, sourceVersion); - } - - // wants to have exactly the same topiaversion after commit - target.setTopiaVersion(source.getTopiaVersion() - 1); - - dao.update(target); - } - - protected <E extends TopiaEntity> void copyEntity(TopiaContext targetTx, E source, E target) throws TopiaException { - - getBinderService().simpleCopy(source, target, false); - - if (source instanceof Species) { - - // Need also to bind ocean - getDataService().copyAssociation(Species.class, Ocean.class, Species.PROPERTY_OCEAN, (Species) source, (Species) target, targetTx); - - } else if (source instanceof SpeciesList) { - - // Need also to bind species - getDataService().copyAssociation(SpeciesList.class, Species.class, SpeciesList.PROPERTY_SPECIES, (SpeciesList) source, (SpeciesList) target, targetTx); + serviceFactory.close(); } } - protected void patchTopiaVersions(TopiaContextImplementor sourceCtxt, - Map<TopiaEntity, Long> versionsToUpdate) throws TopiaException { - - final StringBuilder buffer = new StringBuilder(); - - for (Map.Entry<TopiaEntity, Long> entry : - versionsToUpdate.entrySet()) { - TopiaEntity entity = entry.getKey(); - String id = entity.getTopiaId(); - Long version = entry.getValue(); - String tableName = Entities.getTableName(entity); - buffer.append(String.format(UPDATE_VERSION_PATTERN, tableName, version, id)); - - } - sourceCtxt.getHibernate().doWork(new Work() { - @Override - public void execute(Connection connection) throws SQLException { - String sql = buffer.toString(); - PreparedStatement sta = connection.prepareStatement(sql); - try { - if (log.isDebugEnabled()) { - log.debug("Will execute sql code :\n" + sql); - } - sta.executeUpdate(); - } finally { - sta.close(); - } - } - }); - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java index 9360bde..2e1a8bf 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java @@ -21,7 +21,11 @@ */ package fr.ird.observe.ui.admin.synchronize; +import com.google.common.base.Preconditions; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; import fr.ird.observe.ui.admin.AdminActionModel; import fr.ird.observe.ui.admin.AdminStep; import org.nuiton.topia.persistence.TopiaEntity; @@ -29,9 +33,7 @@ import org.nuiton.topia.persistence.util.DiffState; import org.nuiton.topia.persistence.util.TopiaEntityRef; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.SortedMap; /** @@ -49,10 +51,7 @@ public class SynchronizeModel extends AdminActionModel { protected DiffState.DiffStateMap diff; /** liste des actions utilisateurs */ - protected List<SynchronizeUIHandler.ObsoleteRefReplaceAction> replaceActions; - - /** Universe of entities to update and with their topiaVersion to set. */ - protected Map<TopiaEntity, Long> versionsToUpdate; + protected List<ObsoleteReferenceToReplace> replaceActions; /** data source we want to synchronize. */ protected DataSource source; @@ -60,9 +59,13 @@ public class SynchronizeModel extends AdminActionModel { /** data source which contains central referentiel. */ protected DataSource centralSource; - /** temporary source where to make objectOperations. */ + /** temporary source where to make operations. */ protected DataSource tmpSource; + protected ObserveServiceFactory serviceFactory; + + protected ObserveServiceFactory tmpServiceFactory; + public SynchronizeModel() { super(AdminStep.SYNCHRONIZE); } @@ -83,33 +86,22 @@ public class SynchronizeModel extends AdminActionModel { this.diff = diff; } - public List<SynchronizeUIHandler.ObsoleteRefReplaceAction> getReplaceActions() { + public List<ObsoleteReferenceToReplace> getReplaceActions() { if (replaceActions == null) { - replaceActions = new ArrayList<SynchronizeUIHandler.ObsoleteRefReplaceAction>(); + replaceActions = new ArrayList<ObsoleteReferenceToReplace>(); } return replaceActions; } - public void setReplaceActions(List<SynchronizeUIHandler.ObsoleteRefReplaceAction> replaceActions) { - this.replaceActions = replaceActions; - } - - public Map<TopiaEntity, Long> getVersionsToUpdate() { - if (versionsToUpdate == null) { - versionsToUpdate = new HashMap<TopiaEntity, Long>(); - } - return versionsToUpdate; - } - - public void setVersionsToUpdate(Map<TopiaEntity, Long> versionsToUpdate) { - this.versionsToUpdate = versionsToUpdate; - } - public DataSource getSource() { return source; } public void setSource(DataSource source) { + if (serviceFactory != null) { + serviceFactory.close(); + serviceFactory = null; + } this.source = source; } @@ -126,6 +118,41 @@ public class SynchronizeModel extends AdminActionModel { } public void setTmpSource(DataSource tmpSource) { + if (tmpServiceFactory != null) { + tmpServiceFactory.close(); + tmpServiceFactory = null; + } this.tmpSource = tmpSource; } + + public ObserveServiceFactory getServiceFactory() { + + if (serviceFactory == null) { + Preconditions.checkNotNull(source, "Can't create source service factory if source is null"); + serviceFactory = ObserveContext.newServiceFactory(source); + } + return serviceFactory; + + } + + public ObserveServiceFactory getTmpServiceFactory() { + + if (tmpServiceFactory == null) { + Preconditions.checkNotNull(source, "Can't create source service factory if tmpSource is null"); + tmpServiceFactory = ObserveContext.newServiceFactory(tmpSource); + } + return tmpServiceFactory; + + } + + @Override + public void destroy() { + + super.destroy(); + setSource(null); + setTmpSource(null); + setCentralSource(null); + + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java index c5671e0..17ccb98 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java @@ -22,12 +22,15 @@ package fr.ird.observe.ui.admin.synchronize; import fr.ird.observe.DecoratorService; -import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.ReplicationService; +import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; +import fr.ird.observe.services.operation.SynchronizeService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUI; @@ -38,17 +41,13 @@ import jaxx.runtime.swing.editor.MyDefaultCellEditor; import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.wizard.ext.WizardState; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.decorator.JXPathDecorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.DiffState; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.topia.persistence.util.TopiaEntityRef; import javax.swing.DefaultListModel; @@ -304,6 +303,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { box.addPropertyChangeListener( "selectedItem", new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { updateCanApply(); @@ -320,6 +320,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { addAdminWorker( getUi().getStartAction().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return doAction(); @@ -344,19 +345,16 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { openSource(source); openSource(centralSource); + ObserveServiceFactory sourceServiceFactory = getStepModel().getServiceFactory(); + SynchronizeService synchronizeService = sourceServiceFactory.getService(SynchronizeService.class); + // construction du différentiel - sendMessage(t("observe.message.synchro.build.diff", - centralSource.getLabel())); + sendMessage(t("observe.message.synchro.build.diff", centralSource.getLabel())); - DiffState.DiffStateMap diff = - getDataService().buildReferentielDifferentiel(centralSource, - source, - this - ); + DiffState.DiffStateMap diff = synchronizeService.buildReferentielDifferentiel(centralSource, this); getStepModel().setDiff(diff); - if (diff.isEmpty() || - CollectionUtils.isEmpty(diff.get(DiffState.REMOVED))) { + if (diff.isEmpty() || CollectionUtils.isEmpty(diff.get(DiffState.REMOVED))) { // aucune modification du référentiel // ou aucune entité obsolète @@ -370,16 +368,16 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { // detection des entités obsoletes - SortedMap<TopiaEntity, List<TopiaEntityRef>> obsoleteRefs = - detectObsoleteEntities(); + SortedMap<TopiaEntity, List<TopiaEntityRef>> obsoleteRefs = synchronizeService.detectObsoleteEntities(diff); getStepModel().setObsoleteRefs(obsoleteRefs); - if (obsoleteRefs == null || obsoleteRefs.isEmpty()) { + if (MapUtils.isNotEmpty(obsoleteRefs)) { reportSuccess(); // pas de reference obsolete a traiter return WizardState.SUCCESSED; + } // il existe des entités obsolètes utilisées dans la base locale @@ -387,11 +385,9 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { // on conserve la liste complète des entités qui utilisent des // référentiels obsolètes (on va les recopier plus tard) - List<TopiaEntity> obsoleteEntities = - new ArrayList<TopiaEntity>(obsoleteRefs.keySet()); + List<TopiaEntity> obsoleteEntities = new ArrayList<TopiaEntity>(obsoleteRefs.keySet()); - // on filtre les entités obsolètes directes (les seuls que l'utilisateur - // peut changer) + // on filtre les entités obsolètes directes (les seuls que l'utilisateur peut changer) removeUndirectObsoleteRefs(); @@ -401,29 +397,32 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { // pas de reference obsolete directe a traiter return WizardState.SUCCESSED; + } // dernier cas (le seul demandant une intervention humaine) - // il y a des références obsolètes directes sur des données observers + // il y a des références obsolètes directes sur des données - // on mets en place une base temporaire pour effectuer les corrections + // on met en place une base temporaire pour effectuer les corrections - sendMessage( - t("observe.message.synchro.create.temporary.db.to.resolve.obsoletes")); + sendMessage(t("observe.message.synchro.create.temporary.db.to.resolve.obsoletes")); DataSource tmpSource = model.getSafeTmpSource(false); getStepModel().setTmpSource(tmpSource); openSource(tmpSource); + ObserveServiceFactory tmpServiceFactory = getStepModel().getTmpServiceFactory(); + ReplicationService service = tmpServiceFactory.getService(ReplicationService.class); + // duplication du referentiel à jour vers la base temporaire - replicateReferentiel(centralSource, tmpSource); + service.replicateReferentiel(centralSource); // duplication des objets de la base locale qui utilisent les données obsolètes - replicateObsoletesEntities(obsoleteEntities, source, tmpSource); + service.replicateObsoletesEntities(obsoleteEntities, source, this); - // on injecte toutes les donnes utilisateurs dans la base de synchro - // car on va ensuite remplacer - replicateData(source, tmpSource); + //FIXME Il faut trouver exactement quelles données utilises des réferentiels obsolète et ne répliquer que ceux là + // on injecte toutes les donnes utilisateurs dans la base de synchro car on va ensuite remplacer + service.replicateAllData(source); // la synchronisation demande des modification de la base locale // on enregistre cette action aupres de l'action de sauvegarde @@ -432,9 +431,11 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { sendMessage(t("observe.message.synchro.operation.needFix")); return WizardState.NEED_FIX; + } public void reportSuccess() { + boolean needSave = false; DiffState.DiffStateMap diff = getStepModel().getDiff(); @@ -443,9 +444,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { if (!CollectionUtils.isEmpty(ids)) { // des doonées ont ete supprimées du referentiel distant needSave = true; - sendMessage( - t("observe.message.synchro.referentiel.was.removed", - ids.size())); + sendMessage(t("observe.message.synchro.referentiel.was.removed", ids.size())); for (String id : ids) { sendMessage(" - " + id); } @@ -455,8 +454,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { if (!CollectionUtils.isEmpty(ids)) { // des données ont ete ajoutees au referentiel distant needSave = true; - sendMessage(t("observe.message.synchro.referentiel.was.added", - ids.size())); + sendMessage(t("observe.message.synchro.referentiel.was.added", ids.size())); for (String id : ids) { sendMessage(" - " + id); } @@ -466,9 +464,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { if (!CollectionUtils.isEmpty(ids)) { // des doonées ont ete modifiees dans le referentiel distant needSave = true; - sendMessage( - t("observe.message.synchro.referentiel.was.modified", - ids.size())); + sendMessage(t("observe.message.synchro.referentiel.was.modified", ids.size())); for (String id : ids) { sendMessage(" - " + id); } @@ -476,64 +472,27 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { if (needSave) { // des données doivent être transférer vers la base locale - model.getSaveLocalModel().addStepForSave( - AdminStep.SYNCHRONIZE); + model.getSaveLocalModel().addStepForSave(AdminStep.SYNCHRONIZE); sendMessage(t("observe.message.synchro.local.modification")); - sendMessage( - t("observe.message.synchro.no.referentiel.conflict")); + sendMessage(t("observe.message.synchro.no.referentiel.conflict")); } else { sendMessage(t("observe.message.synchro.ref.is.updtodate")); } - sendMessage( - t("observe.message.synchro.operation.done", new Date())); - } - - protected SortedMap<TopiaEntity, List<TopiaEntityRef>> detectObsoleteEntities() throws Exception { - - DiffState.DiffStateMap diff = getStepModel().getDiff(); - - DataSource source = getStepModel().getSource(); - - // detection des entites obsoletes - - List<String> removedList = diff.get(DiffState.REMOVED); - - String[] ids = removedList.toArray(new String[removedList.size()]); - - TopiaContext tx = beginTransaction(source, "detectObsoleteRefs"); - - // detection des entites obsoletes - - try { - // des suppressions ont ete detectees, on doit retrouver - // dans la base locale les entites utilisant ces entites - // obsoletes - List<TripSeine> marees = ObserveDAOHelper.getTripSeineDAO(tx).findAll(); - - ObserveEntityEnum[] contracts = ObserveDAOHelper.getContracts(); - - SortedMap<TopiaEntity, List<TopiaEntityRef>> result; + sendMessage(t("observe.message.synchro.operation.done", new Date())); - result = TopiaEntityHelper.detectReferences(contracts, ids, marees); - return result; - } finally { - closeTransaction(source, tx, "detectObsoleteRefs"); - } } protected void removeUndirectObsoleteRefs() { Iterator<Map.Entry<TopiaEntity, List<TopiaEntityRef>>> itr; - SortedMap<TopiaEntity, List<TopiaEntityRef>> obsoleteRefs = - getStepModel().getObsoleteRefs(); + SortedMap<TopiaEntity, List<TopiaEntityRef>> obsoleteRefs = getStepModel().getObsoleteRefs(); for (itr = obsoleteRefs.entrySet().iterator(); itr.hasNext(); ) { Map.Entry<TopiaEntity, List<TopiaEntityRef>> entry = itr.next(); - for (Iterator<TopiaEntityRef> itrRef = - entry.getValue().iterator(); itrRef.hasNext(); ) { + for (Iterator<TopiaEntityRef> itrRef = entry.getValue().iterator(); itrRef.hasNext(); ) { TopiaEntityRef ref = itrRef.next(); TopiaEntity refInvoker = ref.getInvoker(); if (refInvoker == null) { @@ -546,10 +505,8 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { continue; } - ObserveEntityEnum refConstant = - ObserveEntityEnum.valueOf(refInvoker); - if (!Entities.DATA_ENTITIES_LIST.contains( - refConstant)) { + ObserveEntityEnum refConstant = ObserveEntityEnum.valueOf(refInvoker); + if (!Entities.DATA_ENTITIES_LIST.contains(refConstant)) { // on peut supprimer cette référence itrRef.remove(); if (log.isTraceEnabled()) { @@ -562,132 +519,59 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { // references dessus itr.remove(); if (log.isDebugEnabled()) { - log.debug("remove obsolete entity (not direct " + - "referentiel) : " + - entry.getKey().getTopiaId()); + log.debug("remove obsolete entity (not direct referentiel) : " + entry.getKey().getTopiaId()); } } } } - protected void replicateObsoletesEntities( - List<TopiaEntity> obsoleteEntities, - DataSource source, - DataSource tmpSource) throws Exception { - - String txName = "replicateObsoletesEntities"; - TopiaContext sourceCtxt = beginTransaction(source, txName); - try { - TopiaContext tmpCtxt = beginTransaction(tmpSource, txName); - try { - for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { - Class<? extends TopiaEntity> contractClass = - constant.getContract(); - List<TopiaEntity> toReplicate = new ArrayList<TopiaEntity>(); - for (Iterator<TopiaEntity> itr = - obsoleteEntities.iterator(); itr.hasNext(); ) { - TopiaEntity e = itr.next(); - if (contractClass.isAssignableFrom(e.getClass())) { - if (log.isDebugEnabled()) { - log.debug("obsolete to inject : " + - e.getTopiaId()); - } - itr.remove(); - - // cet objet doit etre replique - toReplicate.add(e); - - sendMessage(t("observe.message.synchro.obsolete.data.to.duplicate", e)); - } - } - if (toReplicate.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("no obsolete entity " + constant); - } - continue; - } + public List<?> getEntityListFromSynchroDB(Class<?> type, boolean removeObsoletes) { - if (log.isDebugEnabled()) { - log.debug("inject obsolete entity " + constant + " (" + - toReplicate.size() + ")"); - } - sourceCtxt.replicateEntities(tmpCtxt, toReplicate); - commitTransaction(tmpSource, tmpCtxt, txName); - } + ObserveServiceFactory tmpServiceFactory = getStepModel().getTmpServiceFactory(); - } finally { - closeTransaction(tmpSource, tmpCtxt, txName); - } - } finally { - closeTransaction(source, sourceCtxt, txName); - } + ReferentialService service = tmpServiceFactory.getService(ReferentialService.class); + ObserveEntityEnum constant = ObserveEntityEnum.valueOf(type); + List<?> list = service.getList(constant.getContract()); - if (!obsoleteEntities.isEmpty()) { - throw new IllegalStateException( - "there is still obsolete entities to inject in " + - "synchro db : " + obsoleteEntities); - } - } - - public List<?> getEntityListFromSynchroDB(Class<?> type, - boolean removeObsoletes) { - - DataSource tmpSource = getStepModel().getTmpSource(); - List<?> list; - try { - ObserveEntityEnum constant = ObserveEntityEnum.valueOf(type); - list = getDataService().getList(tmpSource, constant.getContract()); - } catch (DataSourceException ex) { - //TODO should do better... - if (log.isErrorEnabled()) { - log.error(ex); - } - list = new ArrayList(); - } if (removeObsoletes) { DiffState.DiffStateMap diff = getStepModel().getDiff(); List<String> removedList = diff.get(DiffState.REMOVED); for (Iterator<?> itr = list.iterator(); itr.hasNext(); ) { + TopiaEntity e = (TopiaEntity) itr.next(); if (removedList.contains(e.getTopiaId())) { - // c'est une entite qui est obsolete, l'utilisateur - // ne peut pas l'utiliser + // c'est une entite qui est obsolete, l'utilisateur ne peut pas l'utiliser itr.remove(); } + } + } + return list; + } - public void resolvObsoleteReferences(TopiaEntity obsoleteRef, - List<TopiaEntityRef> refs, - TopiaEntity safeRef) { + public void resolvObsoleteReferences(TopiaEntity obsoleteRef, List<TopiaEntityRef> refs, TopiaEntity safeRef) { - ObsoleteRefReplaceAction action = new ObsoleteRefReplaceAction( - obsoleteRef.getTopiaId(), - safeRef.getTopiaId(), - refs); + ObsoleteReferenceToReplace action = new ObsoleteReferenceToReplace(obsoleteRef.getTopiaId(), safeRef.getTopiaId(), refs); SynchronizeModel stepModel = getStepModel(); stepModel.getReplaceActions().add(action); - SortedMap<TopiaEntity, List<TopiaEntityRef>> obsoleteRefs = - stepModel.getObsoleteRefs(); + SortedMap<TopiaEntity, List<TopiaEntityRef>> obsoleteRefs = stepModel.getObsoleteRefs(); List<TopiaEntityRef> globalRefs = obsoleteRefs.get(obsoleteRef); DataSource tmpSource = stepModel.getTmpSource(); - String txName = "resolvObsoleteReferences"; - TopiaContext tx = null; + ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(tmpSource); try { - tx = beginTransaction(tmpSource, txName); + ReferentialService service = serviceFactory.getService(ReferentialService.class); - action.doAction(tx); - - commitTransaction(tmpSource, tx, txName); + service.replaceObsoleteReference(action); // on supprime toutes les références traitées globalRefs.removeAll(refs); @@ -701,129 +585,33 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { obsoleteRefs.remove(obsoleteRef); if (log.isDebugEnabled()) { - log.debug("remove resolved obsolete property from temp " + - "db : " + obsoleteRef.getTopiaId()); + log.debug("remove resolved obsolete property from temp db : " + obsoleteRef.getTopiaId()); } - obsoleteRef = tx.findByTopiaId(obsoleteRef.getTopiaId()); - - // on peut la supprimer de la base temporaire - getDAO(tx, obsoleteRef).delete(obsoleteRef); + service.deleteEntities(Collections.singletonList(obsoleteRef.getTopiaId())); ui.firePropertyChange("obsoleteResolved", null, obsoleteRef); } - commitTransaction(tmpSource, tx, txName); - if (obsoleteRefs.isEmpty()) { - sendMessage( - t("observe.message.synchro.operation.done", new Date())); + sendMessage(t("observe.message.synchro.operation.done", new Date())); - // plus de references obsoletes a resoudre, l'action est - // terminée + // plus de references obsoletes a resoudre, l'action est terminée model.setStepState(WizardState.SUCCESSED); - } - } catch (Exception e) { - model.setStepState(onError(e)); - } finally { - try { - if (tx != null) { - closeTransaction(tmpSource, tx, txName); - } - } catch (DataSourceException e) { - model.setStepState(onError(e)); } - } - } - - public class ObsoleteRefReplaceAction { - - /** l'id de l'entité à remplacer */ - String obsoleteId; - - /** l'id de l'entité de remplacement */ - String safeId; - - /** la liste des références à traiter */ - TopiaEntityRef[] refs; - - ObsoleteRefReplaceAction(String obsoleteId, - String safeId, - List<TopiaEntityRef> refs) { - this.obsoleteId = obsoleteId; - this.refs = refs.toArray(new TopiaEntityRef[refs.size()]); - this.safeId = safeId; - } - - public void doAction(TopiaContext tx) throws TopiaException { - - if (log.isInfoEnabled()) { - log.info("load obsolete object " + obsoleteId); - } - - if (log.isInfoEnabled()) { - log.info("load safe object " + safeId); - } - - TopiaEntity safeRef = tx.findByTopiaId(safeId); - // on remplace les references - for (TopiaEntityRef ref : refs) { - TopiaEntity invoker = ref.getInvoker(); - - if (invoker == null) { - throw new NullPointerException( - "can not have a null invoker in " + ref); - } - - if (log.isInfoEnabled()) { - log.info("load invoker object " + invoker.getTopiaId()); - } - - invoker = tx.findByTopiaId(invoker.getTopiaId()); - - // switch entity - - String path = ref.getInvokerProperty(); - - JXPathContext jxcontext = JXPathContext.newContext(invoker); - - TopiaEntity oldValue = (TopiaEntity) jxcontext.getValue(path); - - if (log.isDebugEnabled()) { - log.debug("property to switch " + path + " old : " + - oldValue); - } + } catch (Exception e) { - if (log.isInfoEnabled()) { - log.info("change path : " + path); - log.info("old value : " + oldValue.getTopiaId()); - } + model.setStepState(onError(e)); - jxcontext.setValue(path, safeRef); + } finally { - TopiaEntity newValue = (TopiaEntity) jxcontext.getValue(path); + serviceFactory.close(); - if (log.isInfoEnabled()) { - log.info("new value : " + newValue.getTopiaId()); - } - if (log.isDebugEnabled()) { - log.debug("property to switch " + path + " new : " + - safeRef); - log.debug("property to switch " + path + " new Check : " + - newValue); - } - TopiaDAO<TopiaEntity> dao = getDAO(tx, invoker); - - dao.update(invoker); - } } - public String getObsoleteId() { - return obsoleteId; - } } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java index f6b84da..f8abf5c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java @@ -22,14 +22,15 @@ package fr.ird.observe.ui.admin.validate; import com.google.common.base.Charsets; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.operation.ValidationService; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUI; @@ -50,9 +51,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityRef; import org.nuiton.validator.NuitonValidatorScope; import org.nuiton.validator.bean.simple.SimpleBeanValidator; @@ -137,6 +135,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { final SelectDataUI selectTabUI = (SelectDataUI) ui.getStepUI(AdminStep.SELECT_DATA); getModel().getValidateModel().addPropertyChangeListener(ValidateModel.PROPERTY_MODEL_MODE, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { ValidationModelMode value = (ValidationModelMode) evt.getNewValue(); @@ -169,6 +168,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { }); selectTabUI.getModel().addPropertyChangeListener(AdminUIModel.SELECTION_MODEL_CHANGED_PROPERTY_NAME, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { AdminUIModel model = (AdminUIModel) evt.getSource(); @@ -305,6 +305,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { addAdminWorker( ((ValidateUI) ui).getStartButton().getToolTipText(), new Callable<WizardState>() { + @Override public WizardState call() throws Exception { return doAction(); @@ -348,7 +349,6 @@ public class ValidateUIHandler extends AdminTabUIHandler { protected WizardState initDB() throws Exception { - // on recupere la source de données source = getSource(); @@ -365,8 +365,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { ValidateModel validationModel = model.getValidateModel(); ValidatorsMap validators = validationModel.getValidators(); - sendMessage(t("observe.message.validation.use.storage", - source.getLabel())); + sendMessage(t("observe.message.validation.use.storage", source.getLabel())); sendMessage(t("observe.message.validation.prepare.validators")); @@ -378,14 +377,18 @@ public class ValidateUIHandler extends AdminTabUIHandler { String label = t(DecoratorService.getEntityLabel(v.getType())); sendMessage(t("observe.message.validation.detected", label)); } + } else { + sendMessage(t("observe.message.no.validation.detected")); + } return null; + } - public void launchValidation() throws Exception { + public void launchValidation() { // on vide les anciens messages ValidateModel stepModel = model.getValidateModel(); @@ -393,101 +396,117 @@ public class ValidateUIHandler extends AdminTabUIHandler { ValidatorsMap validators = stepModel.getValidators(); - ValidationMessageDetector detector = - new ValidationMessageDetector(validators); + ValidationMessageDetector detector = new ValidationMessageDetector(validators); DataSelectionModel dataModel = model.getSelectionDataModel(); ValidationContext context = ObserveServiceHelper.getValidationContext(); context.setDataSource(model.getLocalSource()); - context.setDataContext(model.getDataService().getDataContext()); + context.setDataContext(model.getDataContext()); - TopiaContext ctxt = beginTransaction(source, "launchValidation"); + ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(source); +// TopiaContext ctxt = beginTransaction(source, "launchValidation"); try { + ValidationService service = serviceFactory.getService(ValidationService.class); - if (dataModel.isUseReferentiel()) { - - // validation des referentiels selectionnes - - validateReferentiel(detector, ctxt, dataModel); - } + service.validate(this, detector, dataModel); - if (dataModel.isUseData()) { +// if (dataModel.isUseReferentiel()) { +// +// // validation des referentiels selectionnes +// +// validateReferentiel(detector, ctxt, dataModel); +// } +// +// if (dataModel.isUseData()) { +// +// // validation des donnees observateur selectionnee +// +// validateData(detector, ctxt, dataModel); +// } - // validation des donnees observateur selectionnee + } finally { - validateData(detector, ctxt, dataModel); - } + serviceFactory.close(); - } finally { context.setDataSource(null); SortedMap<TopiaEntityRef, List<SimpleBeanValidatorMessage<?>>> refs = detector.getRefs(); stepModel.setMessages(refs); detector.clear(); - closeTransaction(source, ctxt, "launchValidation"); - } - } - - private void validateData(ValidationMessageDetector detector, - TopiaContext ctxt, - DataSelectionModel dataModel) throws TopiaException { - Set<String> data = dataModel.getSelectedData(); +// closeTransaction(source, ctxt, "launchValidation"); - for (String id : data) { - TripSeine e = (TripSeine) ctxt.findByTopiaId(id); - Program p = e.getProgram(); - sendMessage(t("observe.message.validation.start.maree", dTrip.toString(e), dProgram.toString(p))); - detector.detectMessages(e); } } - protected void validateReferentiel(ValidationMessageDetector detector, - TopiaContext ctxt, - DataSelectionModel dataModel) throws DataSourceException, TopiaException { - - DataService dataService = getDataService(); - Set<Class<?>> classes = dataModel.getSelectedReferentiel(); - - for (Class<?> klass : classes) { - // on recupere la liste des ids a valider - Class<? extends TopiaEntity> refClass = (Class<? extends TopiaEntity>) klass; - List<String> ids = dataService.getEntityIds(source, refClass); - String entityLabel = t(DecoratorService.getEntityLabel(klass)); - sendMessage(t("observe.message.validation.start.referentiel", entityLabel, ids.size())); - for (String id : ids) { - TopiaEntity e = ctxt.findByTopiaId(id); - detector.detectMessages(e); - } - ids.clear(); - } - } +// private void validateData(ValidationMessageDetector detector, +// TopiaContext ctxt, +// DataSelectionModel dataModel) throws TopiaException { +// Set<String> data = dataModel.getSelectedData(); +// +// for (String id : data) { +// TripSeine e = (TripSeine) ctxt.findByTopiaId(id); +// Program p = e.getProgram(); +// sendMessage(t("observe.message.validation.start.maree", dTrip.toString(e), dProgram.toString(p))); +// detector.detectMessages(e); +// } +// } +// +// protected void validateReferentiel(ValidationMessageDetector detector, +// TopiaContext ctxt, +// DataSelectionModel dataModel) throws DataSourceException, TopiaException { +// +// DataService dataService = getDataService(); +// Set<Class<?>> classes = dataModel.getSelectedReferentiel(); +// +// for (Class<?> klass : classes) { +// // on recupere la liste des ids a valider +// Class<? extends TopiaEntity> refClass = (Class<? extends TopiaEntity>) klass; +// List<String> ids = dataService.getEntityIds(source, refClass); +// String entityLabel = t(DecoratorService.getEntityLabel(klass)); +// sendMessage(t("observe.message.validation.start.referentiel", entityLabel, ids.size())); +// for (String id : ids) { +// TopiaEntity e = ctxt.findByTopiaId(id); +// detector.detectMessages(e); +// } +// ids.clear(); +// } +// } public void saveReport() { + WizardState finalState = null; ValidateModel validationModel = model.getValidateModel(); try { - if (validationModel.isGenerateReport()) { - sendMessage( - t("observe.message.validation.save.report", validationModel.getReportFile())); + if (validationModel.isGenerateReport()) { + sendMessage(t("observe.message.validation.save.report", validationModel.getReportFile())); generateReportFile(validationModel); + } else { - sendMessage( - t("observe.message.validation.not.save.report")); + + sendMessage(t("observe.message.validation.not.save.report")); + } finalState = WizardState.SUCCESSED; + } catch (Exception e) { + validationModel.setError(e); finalState = WizardState.FAILED; + } finally { + model.setStepState(AdminStep.VALIDATE, finalState); + } + } public void generateReportFile(ValidateModel validationModel) throws IOException { + File reportFile = validationModel.getReportFile(); if (log.isInfoEnabled()) { log.info("save report in " + reportFile); @@ -507,8 +526,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { TopiaEntityRef ref = entry.getKey(); String refStr = service.decorate(ref.getRef()); List<SimpleBeanValidatorMessage<?>> refMessages = entry.getValue(); - EnumSet<NuitonValidatorScope> scopes = - SimpleBeanValidators.getScopes(refMessages); + EnumSet<NuitonValidatorScope> scopes = SimpleBeanValidators.getScopes(refMessages); builder.append(t("observe.validation.report.entity", ref.getRef().getTopiaId(), refStr, refMessages.size(), scopes)).append('\n'); for (NuitonValidatorScope scope : scopes) { List<SimpleBeanValidatorMessage<?>> messagesByScope = filterMessages(scope, refMessages); @@ -525,9 +543,11 @@ public class ValidateUIHandler extends AdminTabUIHandler { log.info(content); } FileUtils.write(reportFile, content, Charsets.UTF_8.name()); + } private List<SimpleBeanValidatorMessage<?>> filterMessages(NuitonValidatorScope scope, List<SimpleBeanValidatorMessage<?>> refMessages) { + List<SimpleBeanValidatorMessage<?>> result = new ArrayList<SimpleBeanValidatorMessage<?>>(); for (SimpleBeanValidatorMessage<?> message : refMessages) { if (message.getScope().equals(scope)) { @@ -535,13 +555,15 @@ public class ValidateUIHandler extends AdminTabUIHandler { } } return result; + } // ------------------------------------------------------------------------ - // -- ValidateConfgUI methods + // -- ValidateConfigUI methods // ------------------------------------------------------------------------ public void updateValidationScopes(JCheckBox checkBox) { + NuitonValidatorScope scope = getValidatorScope(checkBox); ValidateModel validateModel = getModel().getValidateModel(); if (checkBox.isSelected()) { @@ -551,6 +573,7 @@ public class ValidateUIHandler extends AdminTabUIHandler { // supprime le scope validateModel.removeScope(scope); } + } public ComboBoxModel updateComboModel(Object... datas) { @@ -570,10 +593,6 @@ public class ValidateUIHandler extends AdminTabUIHandler { return t("observe.common.selected.validators", validateModel.getValidators().size()); } - public AdminStep getObjectOperation(JCheckBox checkBox) { - return AdminStep.valueOf(checkBox.getName()); - } - public NuitonValidatorScope getValidatorScope(JCheckBox checkBox) { return (NuitonValidatorScope) checkBox.getClientProperty("value"); } @@ -583,11 +602,6 @@ public class ValidateUIHandler extends AdminTabUIHandler { return scopes.contains(scope); } - public boolean isObjectOperationSelected(Set<AdminStep> objectOperations, JCheckBox checkBox) { - AdminStep scope = getObjectOperation(checkBox); - return objectOperations.contains(getObjectOperation(checkBox)); - } - public void chooseValidationReportFile(ValidateConfigUI configUI) { File f = UIHelper.chooseDirectory( configUI, @@ -606,13 +620,4 @@ public class ValidateUIHandler extends AdminTabUIHandler { getModel().getValidateModel().setReportFile(new File(configUI.validationReportDirectoryText.getText(), filename)); } - public String updateReferentielPolicy(boolean valid) { - if (!valid) { - return t("observe.common.storage.not.valid"); - } else { - return model.getCentralSourceModel().getPgConfig().getPolicyLabel(); - } - } - - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUI.jaxx b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUI.jaxx index d88d4d8..b67bef9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUI.jaxx +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUI.jaxx @@ -35,7 +35,6 @@ <import> fr.ird.observe.db.DataContext - fr.ird.observe.DataService fr.ird.observe.db.DataSource fr.ird.observe.ObserveConfig fr.ird.observe.ObserveContext @@ -61,9 +60,6 @@ <SwingValidatorMessageTableModel id='errorTableModel' initializer='getContextValue(SwingValidatorMessageTableModel.class)'/> - <DataService id='dataService' - initializer='getContextValue(DataService.class)'/> - <DataSource id='dataSource' initializer='ObserveContext.get().getDataSource()'/> diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 97a049e..23e3d01 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -50,8 +50,6 @@ import org.nuiton.decorator.Decorator; import org.nuiton.decorator.DecoratorUtil; import org.nuiton.decorator.JXPathDecorator; import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; @@ -357,16 +355,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return icon; } - protected void onLoad(TopiaContext tx, E bean) throws TopiaException { - - // par defaut on charge l'objet de la base dans le bean d'édition - getLoadBinder().load(bean, getBean(), true); - } - - protected E onPreCreate(TopiaContext tx, Object parentBean, E bean) throws TopiaException { - return bean; - } - public void startEditUI(String... binding) { E editBean = getBean(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java index 7d426a0..49ed247 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java @@ -24,7 +24,6 @@ package fr.ird.observe.ui.content; import com.google.common.base.Predicate; import com.google.common.collect.Lists; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSourceException; @@ -679,8 +678,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte new EntityDoubleListPropertyChangeListener<E>(entityClass, list); //FIXME Remove this - DataService service = context.getDataService(); - service.addReferentielPropertyChangeListener(entityClass, listener); +// DataService service = context.getDataService(); +// service.addReferentielPropertyChangeListener(entityClass, listener); } /** @@ -735,8 +734,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte EntityListPropertyChangeListener<E> listener = new EntityListPropertyChangeListener<E>(entityClass, list); //FIXME Remove this!!! - DataService service = context.getDataService(); - service.addReferentielPropertyChangeListener(entityClass, listener); +// DataService service = context.getDataService(); +// service.addReferentielPropertyChangeListener(entityClass, listener); } /** @@ -838,7 +837,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte }; //FIXME Remove this - context.getDataService().addReferentielPropertyChangeListener(entityClass, listener); +// context.getDataService().addReferentielPropertyChangeListener(entityClass, listener); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java index f8abdd4..3ac17f4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.content.ref; * #L% */ -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSourceException; @@ -102,10 +101,9 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten //FIXME Remove this!!! // listen on cache modification - EntityListPropertyChangeListener<E> listener = - new EntityListPropertyChangeListener<E>(entityClass, list); - DataService dataService = ObserveContext.get().getDataService(); - dataService.addReferentielPropertyChangeListener(entityClass, listener); +// EntityListPropertyChangeListener<E> listener = new EntityListPropertyChangeListener<E>(entityClass, list); +// DataService dataService = ObserveContext.get().getDataService(); +// dataService.addReferentielPropertyChangeListener(entityClass, listener); } @SuppressWarnings("unchecked") diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java index 01958be..03d750e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java @@ -21,8 +21,6 @@ */ package fr.ird.observe.ui.storage; -import fr.ird.observe.ObserveContext; -import fr.ird.observe.DataService; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.util.PGInstall; import fr.ird.observe.db.util.SecurityModel; @@ -160,7 +158,7 @@ public abstract class RemoteUILauncher extends StorageUILauncher { protected void applySecurity(PGInstall task) throws Exception { } - protected DataService getDataService() { - return ObserveContext.get().getDataService(); - } +// protected DataService getDataService() { +// return ObserveContext.get().getDataService(); +// } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java index 5983460..ec33e90 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.storage; import fr.ird.observe.ObserveContext; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.H2DataSource; @@ -111,7 +110,7 @@ public class StorageBackupUILauncher extends StorageUILauncher { return source; } - protected DataService getDataService() { - return ObserveContext.get().getDataService(); - } +// protected DataService getDataService() { +// return ObserveContext.get().getDataService(); +// } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java index e34ad30..a90ebf8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java @@ -32,7 +32,6 @@ import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceConfig; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.DataSourceFactory; -import fr.ird.observe.db.ReplicationService; import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.event.DataSourceEvent; @@ -95,14 +94,6 @@ public class StorageUIHandler { private static final Log log = LogFactory.getLog(StorageUIHandler.class); /** - * Service de replication. - * <p/> - * Note: le service est sans état et donc peut rester en état du handler. - */ - protected ReplicationService replicationService = - ObserveServiceHelper.newReplicationService(); - - /** * Prépare une service de persistance à partir d'un modèle. * <p/> * Le service ne sera pas ouvert. @@ -635,12 +626,23 @@ public class StorageUIHandler { tempStorage = ObserveServiceHelper.newEmptyTempStorage( config, t("observe.storage.label.backup"), - "tmpBackup_" + dst.getName() - ); + "tmpBackup_" + dst.getName()); tempStorage.doOpen(); - replicationService.replicateReferentiel(service, tempStorage); - replicationService.replicateAllData(service, tempStorage); + + ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(tempStorage); + + try { + + fr.ird.observe.services.ReplicationService replicationService = serviceFactory.getService(fr.ird.observe.services.ReplicationService.class); + replicationService.replicateReferentiel(service); + replicationService.replicateAllData(service); + + } finally { + + serviceFactory.close(); + + } tempStorage.storeDB(dst); @@ -714,13 +716,23 @@ public class StorageUIHandler { tempStorage = ObserveServiceHelper.newEmptyTempStorage( config, t("observe.storage.label.backup"), - "tmpBackup_" + dst.getName() - ); + "tmpBackup_" + dst.getName()); tempStorage.doOpen(); - replicationService.replicateReferentiel(service, tempStorage); - replicationService.replicateData(service, tempStorage, mareeIds); + ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(tempStorage); + + try { + + fr.ird.observe.services.ReplicationService replicationService = serviceFactory.getService(fr.ird.observe.services.ReplicationService.class); + replicationService.replicateReferentiel(service); + replicationService.replicateData(service, mareeIds); + + } finally { + + serviceFactory.close(); + + } tempStorage.storeDB(dst); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java index 489e9c4..42409b3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java @@ -21,7 +21,6 @@ */ package fr.ird.observe.ui.tree.loadors; -import fr.ird.observe.DataService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; import fr.ird.observe.services.model.DataSelectionModel; @@ -40,8 +39,6 @@ public abstract class AbstractNodeChildLoador<O> extends NavTreeNodeChildLoador< private static final long serialVersionUID = 1L; - protected transient DataService dataService; - protected AbstractNodeChildLoador(Class<O> beanType) { super(beanType); } @@ -52,15 +49,8 @@ public abstract class AbstractNodeChildLoador<O> extends NavTreeNodeChildLoador< return result; } - protected DataService getDataService() { - if (dataService == null) { - dataService = ObserveContext.get().getDataService(); - } - return dataService; - } - protected DecoratorService getDecoratorService() { - return getDataService().getDecoratorService(); + return ObserveContext.get().getDecoratorService(); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit d6dae3857b5806453d14c22941d88d16609d025e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun May 3 17:35:04 2015 +0200 amélioration de l'algorithme de sauvegarde (refs #7017) --- .../fr/ird/observe/services/AbstractObserveService.java | 13 ++++++++++--- .../services/data/longline/ActivityLonglineServiceImpl.java | 7 +++++-- .../services/data/longline/SetLonglineServiceImpl.java | 4 +++- .../services/data/longline/TripLonglineServiceImpl.java | 9 ++++++++- .../services/data/seine/ActivitySeineServiceImpl.java | 9 +++++++-- .../services/data/seine/FloatingObjectServiceImpl.java | 5 ++++- .../services/data/seine/NonTargetSampleServiceImpl.java | 5 ++++- .../ird/observe/services/data/seine/RouteServiceImpl.java | 5 ++++- .../observe/services/data/seine/SetSeineServiceImpl.java | 5 ++++- .../services/data/seine/TargetSampleServiceImpl.java | 5 ++++- .../observe/services/data/seine/TripSeineServiceImpl.java | 10 +++++++++- .../services/referential/ReferentialServiceImpl.java | 4 +++- 12 files changed, 65 insertions(+), 16 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index f7dab53..40e6f0f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -245,11 +245,10 @@ public abstract class AbstractObserveService implements ObserveService { checkNotNullAndExistingEntity(BEAN, toSave); - saved = findByTopiaId(saveAction.entityClass, toSave.getTopiaId()); + saved = saveAction.onUpdate(parent, toSave); checkNotNullAndExistingEntity(BEAN, saved); - saved = saveAction.onUpdate(parent, toSave, saved); } if (parent == null) { @@ -286,7 +285,13 @@ public abstract class AbstractObserveService implements ObserveService { public abstract E onCreate(P parent, E toCreate); - public abstract E onUpdate(P parent, E toSave, E beanToSave); + public E onUpdate(P parent, E toSave) { + + E saved = findByTopiaId(entityClass, toSave.getTopiaId()); + checkNotNullAndExistingEntity(BEAN, saved); + return saved; + + } } @@ -299,6 +304,7 @@ public abstract class AbstractObserveService implements ObserveService { parent = findByTopiaId(deleteAction.parentClass, parentId); checkNotNullAndExistingEntity(PARENT_BEAN, parent); + } E toDelete = findByTopiaId(deleteAction.entityClass, idToDelete); @@ -310,6 +316,7 @@ public abstract class AbstractObserveService implements ObserveService { if (parentId != null) { getDao(deleteAction.parentClass).update(parent); + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index 20a96c5..d2bb21a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -107,14 +107,16 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } @Override - public ActivityLongline onUpdate(TripLongline parent, ActivityLongline toUpdate, ActivityLongline updated) { + public ActivityLongline onUpdate(TripLongline parent, ActivityLongline toUpdate) { + + ActivityLongline updated = super.onUpdate(parent, toUpdate); copyExcluding(ActivityLongline.class, BinderService.EDIT, toUpdate, updated, ActivityLongline.PROPERTY_ENCOUNTER, ActivityLongline.PROPERTY_SENSOR_USED); - return updated; + } }); @@ -125,6 +127,7 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen @Override public void delete(String tripLonglineId, String activityLonglineId) { doDelete(tripLonglineId, activityLonglineId, new DeleteAction<TripLongline, ActivityLongline>(TripLongline.class, ActivityLongline.class) { + @Override public void onDelete(TripLongline parent, ActivityLongline toDelete) { super.onDelete(parent, toDelete); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index b6e88aa..ad7c4da 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -133,7 +133,9 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se } @Override - public SetLongline onUpdate(ActivityLongline parent, SetLongline toUpdate, SetLongline updated) { + public SetLongline onUpdate(ActivityLongline parent, SetLongline toUpdate) { + + SetLongline updated = super.onUpdate(parent, toUpdate); copyExcluding(SetLongline.class, BinderService.EDIT, toUpdate, updated, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index 6b6df6e..0ee1ac1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.ActivityLonglines; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.TripLonglineDAO; @@ -90,6 +91,7 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T @Override public void beforeSave(String parentId, TripLongline toSave) { + super.beforeSave(parentId, toSave); Date startDate = DateUtil.getDay(toSave.getStartDate()); toSave.setStartDate(startDate); @@ -101,15 +103,20 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T @Override public TripLongline onCreate(Program parent, TripLongline toCreate) { + TripLongline created = getDao().create(); copy(TripLongline.class, BinderService.EDIT, toCreate, created, false); return created; + } @Override - public TripLongline onUpdate(Program parent, TripLongline toUpdate, TripLongline updated) { + public TripLongline onUpdate(Program parent, TripLongline toUpdate) { + + TripLongline updated = super.onUpdate(parent, toUpdate); copyExcluding(TripLongline.class, BinderService.EDIT, toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); return updated; + } }); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index b23bb1b..75a2b9e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -3,6 +3,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.seine.SchoolType; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.FpaZone; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeineDAO; @@ -155,18 +156,22 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements parent.addActivitySeine(created); return created; + } @Override - public ActivitySeine onUpdate(Route parent, ActivitySeine toUpdate, ActivitySeine updated) { + public ActivitySeine onUpdate(Route parent, ActivitySeine toUpdate) { + + ActivitySeine updated = super.onUpdate(parent, toUpdate); + Date d = DateUtil.getDateAndTime(parent.getDate(), toUpdate.getTime(), false, false); toUpdate.setTime(d); copyExcluding(ActivitySeine.class, BinderService.EDIT, toUpdate, updated, true, ActivitySeine.PROPERTY_OBSERVED_SYSTEM, ActivitySeine.PROPERTY_FLOATING_OBJECT); - return updated; + } }); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index 7d937af..2d4a927 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -3,6 +3,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Country; import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation; import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType; @@ -121,7 +122,9 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements } @Override - public FloatingObject onUpdate(ActivitySeine parent, FloatingObject toUpdate, FloatingObject updated) { + public FloatingObject onUpdate(ActivitySeine parent, FloatingObject toUpdate) { + + FloatingObject updated = super.onUpdate(parent, toUpdate); copy(FloatingObject.class, BinderService.EDIT, toUpdate, updated, true); return updated; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index caec214..48808fd 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -3,6 +3,7 @@ package fr.ird.observe.services.data.seine; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.Entities; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; @@ -168,7 +169,9 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public NonTargetSample onUpdate(SetSeine parent, NonTargetSample toUpdate, NonTargetSample updated) { + public NonTargetSample onUpdate(SetSeine parent, NonTargetSample toUpdate) { + + NonTargetSample updated = super.onUpdate(parent, toUpdate); copyExcluding(NonTargetSample.class, BinderService.EDIT, toUpdate, updated, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index 533f3a7..20de28b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -1,6 +1,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.seine.ActivitySeines; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.RouteDAO; @@ -107,7 +108,9 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer } @Override - public Route onUpdate(TripSeine parent, Route toUpdate, Route updated) { + public Route onUpdate(TripSeine parent, Route toUpdate) { + + Route updated = super.onUpdate(parent, toUpdate); // on conserve l'ancienne date d'observation Date oldDate = DateUtil.getDay(toUpdate.getDate()); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java index 87b0113..3d6dd56 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.seine.SchoolType; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.Route; @@ -108,7 +109,9 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe } @Override - public SetSeine onUpdate(ActivitySeine parent, SetSeine toUpdate, SetSeine updated) { + public SetSeine onUpdate(ActivitySeine parent, SetSeine toUpdate) { + + SetSeine updated = super.onUpdate(parent, toUpdate); copyExcluding(SetSeine.class, BinderService.EDIT, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 67953b1..fc4682b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -3,6 +3,7 @@ package fr.ird.observe.services.data.seine; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.Entities; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; @@ -185,7 +186,9 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T } @Override - public TargetSample onUpdate(SetSeine parent, TargetSample toUpdate, TargetSample updated) { + public TargetSample onUpdate(SetSeine parent, TargetSample toUpdate) { + + TargetSample updated = super.onUpdate(parent, toUpdate); copyExcluding(TargetSample.class, BinderService.EDIT, toUpdate, updated, TargetSample.PROPERTY_TARGET_LENGTH); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index 4f59498..8109c1e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.Routes; import fr.ird.observe.entities.seine.TripSeine; @@ -94,25 +95,32 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip @Override public void beforeSave(String parentId, TripSeine toSave) { + super.beforeSave(parentId, toSave); Date startDate = DateUtil.getDay(toSave.getStartDate()); toSave.setStartDate(startDate); // mise a jour de la date de fin toSave.updateDateFin(); + } @Override public TripSeine onCreate(Program parent, TripSeine toCreate) { + TripSeine created = getDao().create(); copy(TripSeine.class, BinderService.EDIT, toCreate, created); return created; + } @Override - public TripSeine onUpdate(Program parent, TripSeine toUpdate, TripSeine updated) { + public TripSeine onUpdate(Program parent, TripSeine toUpdate) { + + TripSeine updated = super.onUpdate(parent, toUpdate); copyExcluding(TripSeine.class, BinderService.EDIT, toUpdate, updated, TripSeine.PROPERTY_ROUTE); return updated; + } }); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 0202565..66eb904 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -7,6 +7,7 @@ import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.ReferenceStatus; +import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.LengthWeightParameter; import fr.ird.observe.entities.referentiel.LengthWeightParameterDAO; import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; @@ -360,8 +361,9 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } @Override - public R onUpdate(R parentBean, R toUpdate, R updated) { + public R onUpdate(R parent, R toUpdate) { + R updated = super.onUpdate(parent, toUpdate); copyExcluding(entityClass, BinderService.EDIT, toUpdate, updated); return updated; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit e9061e9f103a620be13a3ce800a7bc0bc6d19c86 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 07:55:23 2015 +0200 reformat code + improve TransmittingBuoyOperation api (refs #7017) --- .../seine/TypeTransmittingBuoyOperation.java | 33 +++++++++--------- .../seine/TransmittingBuoyOperations.java | 39 ++++++++++++++++++++++ .../main/java/fr/ird/observe/services/Commit.java | 1 + .../fr/ird/observe/services/NoTransaction.java | 1 + .../fr/ird/observe/services/ObserveService.java | 4 +-- .../observe/services/ObserveServiceContext.java | 4 +-- .../observe/services/ObserveServiceFactory.java | 3 +- .../ird/observe/services/ReplicationService.java | 2 +- .../data/longline/CatchLonglineServiceImpl.java | 34 +++++++++---------- .../GearUseFeaturesLonglineServiceImpl.java | 6 ++-- .../longline/LonglineGlobalCompositionService.java | 2 +- .../data/longline/TripLonglineServiceImpl.java | 1 - .../data/seine/ActivitySeineServiceImpl.java | 2 +- .../services/data/seine/FloatingObjectService.java | 4 +-- .../data/seine/FloatingObjectServiceImpl.java | 36 ++++++++++---------- .../seine/GearUseFeaturesSeineServiceImpl.java | 8 ++--- .../data/seine/NonTargetCatchServiceImpl.java | 4 +-- .../data/seine/NonTargetSampleServiceImpl.java | 3 +- .../seine/ObjectSchoolEstimateServiceImpl.java | 6 ++-- .../services/data/seine/RouteServiceImpl.java | 2 +- .../data/seine/SchoolEstimateServiceImpl.java | 1 - .../services/data/seine/SetSeineServiceImpl.java | 11 +++--- .../data/seine/TargetSampleServiceImpl.java | 3 +- .../services/data/seine/TripSeineServiceImpl.java | 1 - .../services/operation/ComputeDataService.java | 2 +- .../services/operation/GpsImportService.java | 2 +- .../referential/ReferentialServiceImpl.java | 1 - .../FloatingObjectTransmittingBuoyOperationUI.css | 4 +-- .../FloatingObjectTransmittingBuoyOperationUI.jaxx | 1 + ...ngObjectTransmittingBuoyOperationUIHandler.java | 39 ++++++---------------- .../ird/observe/ui/storage/StorageUIHandler.java | 33 +++++++++--------- 31 files changed, 158 insertions(+), 135 deletions(-) diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/constants/seine/TypeTransmittingBuoyOperation.java b/observe-entities/src/main/java/fr/ird/observe/entities/constants/seine/TypeTransmittingBuoyOperation.java index 7f5732f..5bcfb49 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/constants/seine/TypeTransmittingBuoyOperation.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/constants/seine/TypeTransmittingBuoyOperation.java @@ -21,35 +21,38 @@ */ package fr.ird.observe.entities.constants.seine; +import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperations; + import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; /** @author Tony Chemit - chemit@codelutin.com */ public enum TypeTransmittingBuoyOperation { + // pas de balise lue pasDeBalise(n("observe.common.balise.objectOperation.no.balise")), // une balise lue - visite(n("observe.common.balise.objectOperation.visite"), "1"), - recuperation(n("observe.common.balise.objectOperation.recupere"), "2"), - pose(n("observe.common.balise.objectOperation.pose"), "3"), + visite(n("observe.common.balise.objectOperation.visite"), TransmittingBuoyOperations.VISITE_ID), + recuperation(n("observe.common.balise.objectOperation.recupere"), TransmittingBuoyOperations.RECUPERATION_ID), + pose(n("observe.common.balise.objectOperation.pose"), TransmittingBuoyOperations.POSE_ID), // deux balises lues - recuperationEtRemplacement(n("observe.common.balise.objectOperation.recupere.et.change"), "2", "3"); + recuperationEtRemplacement(n("observe.common.balise.objectOperation.recupere.et.change"), TransmittingBuoyOperations.RECUPERATION_ID, TransmittingBuoyOperations.POSE_ID); /** clef i18n du type d'opération sur balise */ private String i18nKey; /** les codes des opérations sur balise */ - private String[] codeOperation; + private String[] operationIds; /** le count de balises lues */ private int nbBalises; - TypeTransmittingBuoyOperation(String i18nKey, String... codeOperation) { + TypeTransmittingBuoyOperation(String i18nKey, String... operationIds) { this.i18nKey = i18nKey; - this.codeOperation = codeOperation; - nbBalises = codeOperation.length; + this.operationIds = operationIds; + this.nbBalises = operationIds.length; } public String getI18nKey() { @@ -60,8 +63,8 @@ public enum TypeTransmittingBuoyOperation { return nbBalises; } - public String[] getCodeOperation() { - return codeOperation; + public String[] getOperationIds() { + return operationIds; } @Override @@ -69,16 +72,14 @@ public enum TypeTransmittingBuoyOperation { return t(i18nKey); } - public static TypeTransmittingBuoyOperation valueOf(int ordinal) - throws IllegalArgumentException { + public static TypeTransmittingBuoyOperation valueOf(int ordinal) throws IllegalArgumentException { + for (TypeTransmittingBuoyOperation o : values()) { if (o.ordinal() == ordinal) { return o; } } - throw new IllegalArgumentException( - "could not find a " + - TypeTransmittingBuoyOperation.class.getSimpleName() + - " value for ordinal " + ordinal); + throw new IllegalArgumentException("could not find a " + TypeTransmittingBuoyOperation.class.getSimpleName() + " value for ordinal " + ordinal); + } } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/seine/TransmittingBuoyOperations.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/seine/TransmittingBuoyOperations.java new file mode 100644 index 0000000..e351025 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/seine/TransmittingBuoyOperations.java @@ -0,0 +1,39 @@ +package fr.ird.observe.entities.referentiel.seine; + +import java.util.List; + +/** + * Created on 5/4/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class TransmittingBuoyOperations { + + public static final String VISITE_ID = "fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation#1239832686237#0.4947461794167761"; + + public static final String RECUPERATION_ID = "fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation#1239832686238#0.38090479793636556"; + + public static final String POSE_ID = "fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation#1239832686238#0.4755624782839416"; + + public static boolean isBalisePose(TransmittingBuoyOperation operation) { + return operation != null && POSE_ID.equals(operation.getTopiaId()); + } + + public static TransmittingBuoyOperation getObjectOperation(List<TransmittingBuoyOperation> objectOperations, String operationId) { + + TransmittingBuoyOperation objectOperation = null; + for (TransmittingBuoyOperation op : objectOperations) { + if (operationId.equals(op.getTopiaId())) { + objectOperation = op; + break; + } + } + if (objectOperation == null) { + throw new IllegalArgumentException("could not find a " + TransmittingBuoyOperation.class + " with code " + operationId); + } + return objectOperation; + + } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/Commit.java b/observe-services/src/main/java/fr/ird/observe/services/Commit.java index f99b536..0e52dc6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/Commit.java +++ b/observe-services/src/main/java/fr/ird/observe/services/Commit.java @@ -16,4 +16,5 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Commit { + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java b/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java index fc34b8e..6839d32 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java +++ b/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java @@ -16,4 +16,5 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface NoTransaction { + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java index 27e9ac4..a214822 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java @@ -18,9 +18,9 @@ public interface ObserveService extends Closeable { <E extends TopiaEntity> EntityMap findAllUsages(E entity); - <E extends TopiaEntity> List<E> getList(Class<E> klass) ; + <E extends TopiaEntity> List<E> getList(Class<E> klass); - <E extends TopiaEntity> List<E> getList(Class<E> klass, Predicate<E> predicate) ; + <E extends TopiaEntity> List<E> getList(Class<E> klass, Predicate<E> predicate); void setServiceContext(ObserveServiceContext serviceContext); diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java index cba9e5d..320d53e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java @@ -43,7 +43,7 @@ public class ObserveServiceContext { protected ObserveApplicationContext applicationContext; public ObserveServiceContext(ObserveApplicationContext applicationContext, DataSource dataSource) { - this.applicationContext=applicationContext; + this.applicationContext = applicationContext; this.config = applicationContext.getConfig(); this.dataSource = dataSource; this.decoratorService = applicationContext.getDecoratorService(); @@ -59,7 +59,7 @@ public class ObserveServiceContext { } public ReferenceLocale getReferentielLocale() { - return applicationContext.getDecoratorService().getReferentielLocale(); + return decoratorService.getReferentielLocale(); } public Date now() { diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index 3e6af98..c48e040 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -52,6 +52,7 @@ public class ObserveServiceFactory implements Closeable { protected ObserveServiceFactory(ObserveApplicationContext applicationContext) { this.applicationContext = applicationContext; this.services = CacheBuilder.newBuilder().build(new CacheLoader<Class<? extends ObserveService>, ObserveService>() { + @Override public ObserveService load(Class<? extends ObserveService> key) throws Exception { Preconditions.checkNotNull(key, "service key can't be null"); @@ -111,7 +112,7 @@ public class ObserveServiceFactory implements Closeable { ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); S service = newProxyService(serviceType, serviceContext); - return service ; + return service; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java index 1a4d3cf..d87328e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java @@ -13,7 +13,7 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public interface ReplicationService extends ObserveService{ +public interface ReplicationService extends ObserveService { @Commit void replicateObsoletesEntities(List<TopiaEntity> obsoleteEntities, DataSource source, SendMessageAble messanger) throws DataSourceException; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java index 361700e..4703ac7 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -95,8 +95,8 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements public CatchLongline onCreateChild(CatchLongline childToCreate) { CatchLongline childCreated = super.onCreateChild(childToCreate); - saveSizeMeasures(childToCreate.getSizeMeasure(), childCreated); - saveWeightMeasures(childToCreate.getWeightMeasure(), childCreated); + saveSizeMeasures(childCreated, childToCreate.getSizeMeasure()); + saveWeightMeasures(childCreated, childToCreate.getWeightMeasure()); return childCreated; } @@ -104,23 +104,23 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements @Override public CatchLongline onUpdateChild(CatchLongline childToUpdate) { - CatchLongline childUpdated = super.onUpdateChild(childToUpdate); - saveSizeMeasures(childToUpdate.getSizeMeasure(), childUpdated); - saveWeightMeasures(childToUpdate.getWeightMeasure(), childUpdated); + CatchLongline childUpdated = super.onUpdateChild(childToUpdate); + saveSizeMeasures(childUpdated, childToUpdate.getSizeMeasure()); + saveWeightMeasures(childUpdated, childToUpdate.getWeightMeasure()); return childUpdated; } - protected void saveSizeMeasures(Collection<SizeMeasure> sizeMeasurementsToSave, CatchLongline childSaved) { + protected void saveSizeMeasures(CatchLongline childSaved, Collection<SizeMeasure> sizeMeasuresToSave) { - List<SizeMeasure> sizeMeasuresToSave = Lists.newArrayList(); + List<SizeMeasure> sizeMeasuresSaveds = Lists.newArrayList(); - if (CollectionUtils.isNotEmpty(sizeMeasurementsToSave)) { + if (CollectionUtils.isNotEmpty(sizeMeasuresToSave)) { TopiaDAO<SizeMeasure> dao = getDao(SizeMeasure.class); TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); - for (SizeMeasure sizeMeasureToSave : sizeMeasurementsToSave) { + for (SizeMeasure sizeMeasureToSave : sizeMeasuresToSave) { SizeMeasure sizeMeasureSaved; @@ -136,27 +136,27 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements } - sizeMeasuresToSave.add(sizeMeasureSaved); + sizeMeasuresSaveds.add(sizeMeasureSaved); } } childSaved.clearSizeMeasure(); - childSaved.addAllSizeMeasure(sizeMeasuresToSave); + childSaved.addAllSizeMeasure(sizeMeasuresSaveds); } - protected void saveWeightMeasures(Collection<WeightMeasure> weightMeasurementsTosave, CatchLongline childSaved) { + protected void saveWeightMeasures(CatchLongline childSaved, Collection<WeightMeasure> weightMeasuresToSave) { - List<WeightMeasure> weightMeasuresToSave = Lists.newArrayList(); + List<WeightMeasure> weightMeasuresSaved = Lists.newArrayList(); - if (CollectionUtils.isNotEmpty(weightMeasurementsTosave)) { + if (CollectionUtils.isNotEmpty(weightMeasuresToSave)) { TopiaDAO<WeightMeasure> dao = getDao(WeightMeasure.class); TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); - for (WeightMeasure weightMeasureToSave : weightMeasurementsTosave) { + for (WeightMeasure weightMeasureToSave : weightMeasuresToSave) { WeightMeasure weightMeasureSaved; @@ -172,14 +172,14 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements } - weightMeasuresToSave.add(weightMeasureSaved); + weightMeasuresSaved.add(weightMeasureSaved); } } childSaved.clearWeightMeasure(); - childSaved.addAllWeightMeasure(weightMeasuresToSave); + childSaved.addAllWeightMeasure(weightMeasuresSaved); } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index 9013750..e15cd70 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -147,7 +147,7 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i GearUseFeaturesLongline.PROPERTY_NUMBER, childToCreate.getNumber() ); childBinder.load(childToCreate, childCreated, false); - saveMeasurement(childToCreate.getGearUseFeaturesMeasurement(), childCreated); + saveMeasurement(childCreated, childToCreate.getGearUseFeaturesMeasurement()); return childCreated; } @@ -155,11 +155,11 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToUpdate) { GearUseFeaturesLongline childUpdated = super.onUpdateChild(childToUpdate); - saveMeasurement(childToUpdate.getGearUseFeaturesMeasurement(), childUpdated); + saveMeasurement(childUpdated, childToUpdate.getGearUseFeaturesMeasurement()); return childUpdated; } - protected void saveMeasurement(List<GearUseFeaturesMeasurementLongline> measurementsToSave, GearUseFeaturesLongline childSaved) { + protected void saveMeasurement(GearUseFeaturesLongline childSaved, List<GearUseFeaturesMeasurementLongline> measurementsToSave) { List<GearUseFeaturesMeasurementLongline> measurementsSaved = Lists.newArrayList(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java index 9c245c2..97baf3e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java @@ -7,7 +7,7 @@ import fr.ird.observe.services.ObserveService; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com */ -public interface LonglineGlobalCompositionService extends ObserveService{ +public interface LonglineGlobalCompositionService extends ObserveService { SetLongline loadForEdit(String setLonglineId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index 0ee1ac1..0d522b6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -2,7 +2,6 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.ActivityLonglines; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.longline.TripLonglineDAO; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 75a2b9e..c83dad2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -3,7 +3,6 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.seine.SchoolType; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.FpaZone; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.ActivitySeineDAO; @@ -182,6 +181,7 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements @Override public void delete(String routeId, String activitySeineId) { doDelete(routeId, activitySeineId, new DeleteAction<Route, ActivitySeine>(Route.class, ActivitySeine.class) { + @Override public void onDelete(Route parent, ActivitySeine toDelete) { super.onDelete(parent, toDelete); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java index c4c6ba2..20b1aaf 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java @@ -20,7 +20,7 @@ public interface FloatingObjectService extends ObserveService { FloatingObject loadForEdit(String floatingObjectId); - FloatingObject loadForEditTransmittingBuoyOperation(String floatingObjectId); + FloatingObject loadForTransmittingBuoyOperation(String floatingObjectId); FloatingObject preCreate(String activitySeineId); @@ -28,7 +28,7 @@ public interface FloatingObjectService extends ObserveService { String save(String activitySeineId, FloatingObject toSave); @Commit - FloatingObject updateTransmittingBuoyOperation(FloatingObject toUpdate); + void saveForTransmittingBuoyOperation(FloatingObject toUpdate); @Commit void delete(String activitySeineId, String floatingObjectId); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index 2d4a927..6a1df52 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -3,7 +3,6 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Country; import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation; import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType; @@ -60,7 +59,7 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements } @Override - public FloatingObject loadForEditTransmittingBuoyOperation(String floatingObjectId) { + public FloatingObject loadForTransmittingBuoyOperation(String floatingObjectId) { FloatingObjectDAO dao = getDao(); @@ -136,42 +135,45 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements } @Override - public FloatingObject updateTransmittingBuoyOperation(FloatingObject toUpdate) { + public void saveForTransmittingBuoyOperation(FloatingObject toSave) { - FloatingObject updated = getDao().findByTopiaId(toUpdate.getTopiaId()); - updated.setComment(toUpdate.getComment()); - updated.clearTransmittingBuoy(); + FloatingObject saved = getDao().findByTopiaId(toSave.getTopiaId()); + saved.setComment(toSave.getComment()); + saved.clearTransmittingBuoy(); - if (!toUpdate.isTransmittingBuoyEmpty()) { + if (!toSave.isTransmittingBuoyEmpty()) { TopiaEntityBinder<TransmittingBuoy> binder = getBinder(TransmittingBuoy.class, BinderService.EDIT); TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = getDao(TransmittingBuoy.class); - for (TransmittingBuoy transmittingBuoy : toUpdate.getTransmittingBuoy()) { + List<TransmittingBuoy> transmittingBuoys = new ArrayList<TransmittingBuoy>(); + + for (TransmittingBuoy transmittingBuoyToSave : toSave.getTransmittingBuoy()) { - TransmittingBuoy newTransmittingBuoy; + TransmittingBuoy transmittingBuoySaved; - if (Entities.isNew(transmittingBuoy)) { + if (Entities.isNew(transmittingBuoyToSave)) { // creation de la balise - Map<String, Object> map = binder.obtainProperties(transmittingBuoy); - newTransmittingBuoy = transmittingBuoyDAO.create(map); + Map<String, Object> map = binder.obtainProperties(transmittingBuoyToSave); + transmittingBuoySaved = transmittingBuoyDAO.create(map); } else { // mise a jour de la balise - newTransmittingBuoy = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); - binder.load(transmittingBuoy, newTransmittingBuoy, true); + transmittingBuoySaved = transmittingBuoyDAO.findByTopiaId(transmittingBuoyToSave.getTopiaId()); + binder.load(transmittingBuoyToSave, transmittingBuoySaved, true); } - updated.addTransmittingBuoy(newTransmittingBuoy); + transmittingBuoys.add(transmittingBuoySaved); } - } - return updated; + saved.addAllTransmittingBuoy(transmittingBuoys); + + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index 6118209..3c2b147 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -146,8 +146,8 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl GearUseFeaturesSeine childCreated = getDao(entityClass).create( GearUseFeaturesSeine.PROPERTY_GEAR, childToCreate.getGear(), GearUseFeaturesSeine.PROPERTY_NUMBER, childToCreate.getNumber()); - childBinder.load(childToCreate, childCreated, false); - saveMeasurement(childToCreate.getGearUseFeaturesMeasurement(), childCreated); + this.childBinder.load(childToCreate, childCreated, false); + saveMeasurement(childCreated, childToCreate.getGearUseFeaturesMeasurement()); return childCreated; } @@ -156,12 +156,12 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToUpdate) { GearUseFeaturesSeine childUpdated = super.onUpdateChild(childToUpdate); - saveMeasurement(childToUpdate.getGearUseFeaturesMeasurement(), childUpdated); + saveMeasurement(childUpdated, childToUpdate.getGearUseFeaturesMeasurement()); return childUpdated; } - protected void saveMeasurement(List<GearUseFeaturesMeasurementSeine> measurementsToSave, GearUseFeaturesSeine childSaved) { + protected void saveMeasurement(GearUseFeaturesSeine childSaved, List<GearUseFeaturesMeasurementSeine> measurementsToSave) { List<GearUseFeaturesMeasurementSeine> measurementsSaved = Lists.newArrayList(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java index b77ea2f..af19eee 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java @@ -65,12 +65,12 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements SetSeine.class, NonTargetCatch.class, getListUpdator(), parentBinder, childbinder) { @Override - public void prepareSave(SetSeine parentToSave, Collection<NonTargetCatch> toSaves) { + public void prepareSave(SetSeine parentToSave, Collection<NonTargetCatch> nonTargetCatchesToSave) { // mise a jour de la propriete nonTargetDiscarded boolean hasRejet = false; - for (NonTargetCatch c : toSaves) { + for (NonTargetCatch c : nonTargetCatchesToSave) { if (c.getReasonForDiscard() != null) { // on a trouve un rejet de faune hasRejet = true; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index 48808fd..90189f1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -3,7 +3,6 @@ package fr.ird.observe.services.data.seine; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; @@ -152,6 +151,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement public String save(String setSeineId, NonTargetSample nonTargetSampleToSave) { String savedId = doSave(setSeineId, nonTargetSampleToSave, new SaveAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + @Override public NonTargetSample onCreate(SetSeine parent, NonTargetSample toCreate) { @@ -228,6 +228,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement public void delete(String setSeineId, NonTargetSample nonTargetSampleToDelete) { doDelete(setSeineId, nonTargetSampleToDelete.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { + @Override public void onDelete(SetSeine parent, NonTargetSample toDelete) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java index 10913c3..a5c55b6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java @@ -15,14 +15,14 @@ import java.util.List; * @author Sylvain Bavencoff - bavencoff@codelutin.com */ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService implements ObjectSchoolEstimateService { - + @Override public FloatingObject loadForEdit(String floatingObjectId) { - + FloatingObject parentToLoad = findByTopiaId(FloatingObject.class, floatingObjectId); FloatingObject parentLoaded = getDao(FloatingObject.class).newInstance(); - + copy(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE, parentToLoad, parentLoaded); if (!parentToLoad.isObjectSchoolEstimateEmpty()) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index 20de28b..83425be 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -1,7 +1,6 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.seine.ActivitySeines; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.RouteDAO; @@ -141,6 +140,7 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer @Override public void delete(String tripSeineId, String routeId) { doDelete(tripSeineId, routeId, new DeleteAction<TripSeine, Route>(TripSeine.class, Route.class) { + @Override public void onDelete(TripSeine parent, Route toDelete) { super.onDelete(parent, toDelete); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java index 045a27d..8661272 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -69,5 +69,4 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements } - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java index 3d6dd56..d988099 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java @@ -2,7 +2,6 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.seine.SchoolType; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.Route; @@ -114,11 +113,11 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe SetSeine updated = super.onUpdate(parent, toUpdate); copyExcluding(SetSeine.class, - BinderService.EDIT, - toUpdate, - updated, - SetSeine.PROPERTY_TARGET_SAMPLE, - SetSeine.PROPERTY_NON_TARGET_SAMPLE); + BinderService.EDIT, + toUpdate, + updated, + SetSeine.PROPERTY_TARGET_SAMPLE, + SetSeine.PROPERTY_NON_TARGET_SAMPLE); return updated; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index fc4682b..976a4cf 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -3,7 +3,6 @@ package fr.ird.observe.services.data.seine; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; @@ -171,6 +170,7 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T public String save(String setSeineId, TargetSample toSave) { String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { + @Override public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { @@ -246,6 +246,7 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T public void delete(String setSeineId, TargetSample bean) { doDelete(setSeineId, bean.getTopiaId(), new DeleteAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { + @Override public void onDelete(SetSeine parent, TargetSample toDelete) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index 8109c1e..8d75881 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -2,7 +2,6 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.BinderService; import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.Routes; import fr.ird.observe.entities.seine.TripSeine; diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java index 9b58b2e..898f8c3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java @@ -11,7 +11,7 @@ import java.util.Set; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public interface ComputeDataService extends ObserveService{ +public interface ComputeDataService extends ObserveService { void consolidateTrips(SendMessageAble messager, Set<String> tripIds); diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java index 1bf168b..d5c73be 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java @@ -15,7 +15,7 @@ import java.util.Map; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public interface GpsImportService extends ObserveService { +public interface GpsImportService extends ObserveService { TripSeine getOpenTrip(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 66eb904..232fada 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -7,7 +7,6 @@ import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.ReferenceStatus; -import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.referentiel.LengthWeightParameter; import fr.ird.observe.entities.referentiel.LengthWeightParameterDAO; import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.css b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.css index eb9d468..5601483 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.css +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.css @@ -85,7 +85,7 @@ #ownership1 { selectedItem:{transmittingBuoy1.getOwnership()}; - enabled: {!getHandler().isBalisePose(transmittingBuoy1.getTransmittingBuoyOperation())} + enabled: {!TransmittingBuoyOperations.isBalisePose(transmittingBuoy1.getTransmittingBuoyOperation())} } #country1Label { @@ -150,7 +150,7 @@ #ownership2 { selectedItem:{transmittingBuoy2.getOwnership()}; - enabled: {!getHandler().isBalisePose(transmittingBuoy2.getTransmittingBuoyOperation())} + enabled: {!TransmittingBuoyOperations.isBalisePose(transmittingBuoy2.getTransmittingBuoyOperation())} } #country2Label { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.jaxx b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.jaxx index 4d8b676..67ec1ce 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.jaxx +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUI.jaxx @@ -31,6 +31,7 @@ fr.ird.observe.entities.constants.seine.TypeTransmittingBuoyOperation fr.ird.observe.entities.referentiel.Country fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation + fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperations fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType fr.ird.observe.ui.actions.shared.ResetEditUIAction fr.ird.observe.ui.actions.shared.SaveEditUIAction diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java index 186d458..b030899 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java @@ -28,6 +28,7 @@ import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.constants.seine.Ownership; import fr.ird.observe.entities.constants.seine.TypeTransmittingBuoyOperation; import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation; +import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperations; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.TransmittingBuoy; @@ -115,7 +116,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH getModel().setEditing(false); FloatingObjectService service = getService(FloatingObjectService.class); - FloatingObject loaded = service.loadForEditTransmittingBuoyOperation(floatingObjectId); + FloatingObject loaded = service.loadForTransmittingBuoyOperation(floatingObjectId); copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, loaded, bean); getUi().processDataBinding(FloatingObjectTransmittingBuoyOperationUI.BINDING_TYPE_OPERATION_SELECTED_ITEM); @@ -177,17 +178,11 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH getModel().setModified(false); } - public boolean isBalisePose(TransmittingBuoyOperation operation) { - return operation != null && "3".equals(operation.getCode()); - } - @Override protected boolean doSave(FloatingObject bean) { - //FIXME On ne doit pas retourner l'objet... FloatingObjectService service = getService(FloatingObjectService.class); - FloatingObject saved = service.updateTransmittingBuoyOperation(bean); - copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, saved, bean); + service.saveForTransmittingBuoyOperation(bean); //FIXME, il faut declancher un evenement dans le cache du storage pour pouvoir redessiner le noeud return true; @@ -228,7 +223,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH JPanel editorPanel = ui.getTransmittingBuoys(); editorPanel.removeAll(); - String[] codeOperations = typeOperation.getCodeOperation(); + String[] operationIds = typeOperation.getOperationIds(); List<TransmittingBuoyOperation> operations = ui.getTransmittingBuoyOperation1().getData(); TransmittingBuoy transmittingBuoy; @@ -248,7 +243,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH transmittingBuoy = reset ? null : objets.get(0); - objectOperation = reset ? getObjectOperation(operations, codeOperations[0]) : null; + objectOperation = reset ? TransmittingBuoyOperations.getObjectOperation(operations, operationIds[0]) : null; bindEditBalise(ui.getTransmittingBuoy1(), objectOperation, transmittingBuoy); editorPanel.setLayout(new GridLayout(1, 0)); @@ -261,11 +256,11 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH case 2: transmittingBuoy = reset ? null : objets.get(0); - objectOperation = reset ? getObjectOperation(operations, codeOperations[0]) : null; + objectOperation = reset ? TransmittingBuoyOperations.getObjectOperation(operations, operationIds[0]) : null; bindEditBalise(ui.getTransmittingBuoy1(), objectOperation, transmittingBuoy); transmittingBuoy = reset ? null : objets.get(1); - objectOperation = reset ? getObjectOperation(operations, codeOperations[1]) : null; + objectOperation = reset ? TransmittingBuoyOperations.getObjectOperation(operations, operationIds[1]) : null; bindEditBalise(ui.getTransmittingBuoy2(), objectOperation, transmittingBuoy); editorPanel.setLayout(new GridLayout(2, 0)); @@ -279,9 +274,11 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH } SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { + //FIXME la disposition n'est pas bien recalculée // recalcul de la disposition getUi().revalidate(); } @@ -304,7 +301,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH transmittingBuoyOperation.getLabel1()); } - if (isBalisePose(transmittingBuoyOperation)) { + if (TransmittingBuoyOperations.isBalisePose(transmittingBuoyOperation)) { // objectOperation de pose // toujours appartient au navire @@ -318,23 +315,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH bean.setTransmittingBuoy(new ArrayList<TransmittingBuoy>()); } bean.getTransmittingBuoy().add(editBean); - } - protected TransmittingBuoyOperation getObjectOperation(List<TransmittingBuoyOperation> objectOperations, - String codeOperation) { - TransmittingBuoyOperation objectOperation = null; - for (TransmittingBuoyOperation op : objectOperations) { - if (codeOperation.equals(op.getCode())) { - objectOperation = op; - break; - } - } - if (objectOperation == null) { - throw new IllegalArgumentException( - "could not find a " + - TransmittingBuoyOperation.class + " with code " + codeOperation); - } - return objectOperation; } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java index a90ebf8..5a158d1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java @@ -45,6 +45,7 @@ import fr.ird.observe.db.util.SecurityModel; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; @@ -634,7 +635,7 @@ public class StorageUIHandler { try { - fr.ird.observe.services.ReplicationService replicationService = serviceFactory.getService(fr.ird.observe.services.ReplicationService.class); + ReplicationService replicationService = serviceFactory.getService(ReplicationService.class); replicationService.replicateReferentiel(service); replicationService.replicateAllData(service); @@ -677,38 +678,36 @@ public class StorageUIHandler { * * @param service le service locale qui encapsule la base locale * @param dst le fichier de sauvegarde - * @param marees les marees a exporter (si {@code null} on exporte tout) + * @param trips les marees a exporter (si {@code null} on exporte tout) */ - public void backupLocalDatabase(DataSource service, - File dst, - Set<String> marees) { - if (marees == null) { + public void backupLocalDatabase(DataSource service, File dst, Set<String> trips) { + + if (trips == null) { if (log.isInfoEnabled()) { log.info("will export all datas."); } backupLocalDatabase(service, dst); return; } + if (dst == null) { - throw new IllegalArgumentException( - "file where to backup can not be null"); + throw new IllegalArgumentException("file where to backup can not be null"); } if (log.isInfoEnabled()) { - log.info("will export " + marees.size() + " marees to " + dst); + log.info("will export " + trips.size() + " marees to " + dst); } if (log.isDebugEnabled()) { - log.debug(marees); + log.debug(trips); } - // on doit dumper la base distante dans une base h2 et en faire - // la sauvegarde + // on doit dumper la base distante dans une base h2 et en faire la sauvegarde ObserveConfig config = ObserveContext.get().getConfig(); - String[] mareeIds = new String[marees.size()]; + String[] tripIds = new String[trips.size()]; int index = 0; - for (String m : marees) { - mareeIds[index++] = m; + for (String m : trips) { + tripIds[index++] = m; } DataSource tempStorage = null; @@ -724,9 +723,9 @@ public class StorageUIHandler { try { - fr.ird.observe.services.ReplicationService replicationService = serviceFactory.getService(fr.ird.observe.services.ReplicationService.class); + ReplicationService replicationService = serviceFactory.getService(ReplicationService.class); replicationService.replicateReferentiel(service); - replicationService.replicateData(service, mareeIds); + replicationService.replicateData(service, tripIds); } finally { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 4b770be9c4b6fd62e2ab78cb8e383dd07a852a7e Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 07:58:07 2015 +0200 remove EntityAssociation (refs #7017) --- .../fr/ird/observe/services/EntityAssociation.java | 39 ---------------------- 1 file changed, 39 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/EntityAssociation.java b/observe-services/src/main/java/fr/ird/observe/services/EntityAssociation.java deleted file mode 100644 index bac1fa9..0000000 --- a/observe-services/src/main/java/fr/ird/observe/services/EntityAssociation.java +++ /dev/null @@ -1,39 +0,0 @@ -package fr.ird.observe.services; - -import org.nuiton.topia.persistence.TopiaEntity; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * Represents an entity with one of his association. - * - * Created on 4/28/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class EntityAssociation<P extends TopiaEntity, C extends TopiaEntity> { - - protected final P parentEntity; - - protected final Collection<C> childEntities; - - public EntityAssociation(P parentEntity) { - this.parentEntity = parentEntity; - this.childEntities = new ArrayList<C>(); - } - - public P getParentEntity() { - return parentEntity; - } - - public Collection<C> getChildEntities() { - return childEntities; - } - - public void addChildEntity(C entity) { - childEntities.add(entity); - } - -} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit a17990fd553f7992ff9f207699cce52a62a0e460 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 09:20:35 2015 +0200 - creation du module observe-services-api - amélioration de la service factory pour ne plus utiliser la datasource en état refs #7017 --- {observe-services => observe-services-api}/pom.xml | 7 +- .../main/java/fr/ird/observe/services/Commit.java | 0 .../fr/ird/observe/services/NoTransaction.java | 0 .../fr/ird/observe/services/ObserveService.java | 0 .../observe/services/ObserveServiceContext.java | 0 .../observe/services/ObserveServiceFactory.java | 342 +++++++++++++++++++++ .../services/ObserveServiceFactoryProvider.java | 17 + .../ird/observe/services/ReplicationService.java | 0 .../ird/observe/services/data/OpenableService.java | 0 .../fr/ird/observe/services/data/TripService.java | 0 .../data/longline/ActivityLonglineService.java | 0 .../data/longline/BaitsCompositionService.java | 0 .../longline/BranchlinesCompositionService.java | 0 .../data/longline/CatchLonglineService.java | 0 .../services/data/longline/EncounterService.java | 0 .../longline/FloatlinesCompositionService.java | 0 .../longline/GearUseFeaturesLonglineService.java | 0 .../data/longline/HooksCompositionService.java | 0 .../longline/LonglineDetailCompositionService.java | 0 .../longline/LonglineGlobalCompositionService.java | 0 .../services/data/longline/SensorUsedService.java | 0 .../services/data/longline/SetLonglineService.java | 0 .../observe/services/data/longline/TdrService.java | 0 .../data/longline/TripLonglineService.java | 0 .../services/data/seine/ActivitySeineService.java | 0 .../services/data/seine/FloatingObjectService.java | 0 .../data/seine/GearUseFeaturesSeineService.java | 0 .../services/data/seine/NonTargetCatchService.java | 0 .../data/seine/NonTargetSampleService.java | 0 .../data/seine/ObjectObservedSpeciesService.java | 0 .../data/seine/ObjectSchoolEstimateService.java | 0 .../observe/services/data/seine/RouteService.java | 0 .../services/data/seine/SchoolEstimateService.java | 0 .../services/data/seine/SetSeineService.java | 0 .../services/data/seine/TargetCatchService.java | 0 .../services/data/seine/TargetSampleService.java | 0 .../services/data/seine/TripSeineService.java | 0 .../observe/services/model/DataSelectionModel.java | 9 +- .../services/operation/ComputeDataService.java | 0 .../services/operation/GpsImportService.java | 0 .../operation/ObsoleteReferenceToReplace.java | 0 .../services/operation/SynchronizeService.java | 0 .../services/operation/ValidationService.java | 0 .../services/referential/ReferentialService.java | 0 observe-services/pom.xml | 5 + .../observe/services/AbstractObserveService.java | 10 +- ...ava => ObserveServiceFactoryProviderTopia.java} | 116 ++----- .../services/operation/SynchronizeServiceImpl.java | 141 ++++----- ....observe.services.ObserveServiceFactoryProvider | 1 + .../main/java/fr/ird/observe/ObserveContext.java | 228 +++++--------- .../java/fr/ird/observe/ui/admin/AdminUIModel.java | 24 +- .../ui/admin/consolidate/ConsolidateModel.java | 21 -- .../ui/admin/consolidate/ConsolidateUIHandler.java | 6 +- .../ird/observe/ui/admin/export/ExportModel.java | 20 +- .../observe/ui/admin/export/ExportUIHandler.java | 9 +- .../observe/ui/admin/gps/ImportGPSUIHandler.java | 8 +- .../observe/ui/admin/save/SaveLocalUIHandler.java | 18 +- .../ui/admin/synchronize/SynchronizeModel.java | 35 --- .../ui/admin/synchronize/SynchronizeUIHandler.java | 18 +- .../ui/admin/validate/ValidateUIHandler.java | 6 +- .../ird/observe/ui/storage/StorageUIHandler.java | 39 +-- .../ui/tree/AbstractObserveTreeCellRenderer.java | 4 +- .../ird/observe/ui/tree/ActivityLonglineNode.java | 7 +- .../fr/ird/observe/ui/tree/ActivitySeineNode.java | 7 +- .../fr/ird/observe/ui/tree/EntityNodeSupport.java | 8 +- .../observe/ui/tree/FloatingObjectSeineNode.java | 7 +- .../ird/observe/ui/tree/ObserveDataProvider.java | 17 +- .../fr/ird/observe/ui/tree/ObserveTreeHelper.java | 6 +- .../ird/observe/ui/tree/ProgramLonglineNode.java | 7 +- .../fr/ird/observe/ui/tree/ProgramSeineNode.java | 7 +- .../fr/ird/observe/ui/tree/RouteSeineNode.java | 7 +- .../fr/ird/observe/ui/tree/SetLonglineNode.java | 7 +- .../java/fr/ird/observe/ui/tree/SetSeineNode.java | 7 +- .../fr/ird/observe/ui/tree/TripLonglineNode.java | 7 +- .../java/fr/ird/observe/ui/tree/TripSeineNode.java | 7 +- .../loadors/ActivityLonglineNodeChildLoador.java | 2 +- .../tree/loadors/ActivitySeineNodeChildLoador.java | 2 +- pom.xml | 1 + 78 files changed, 630 insertions(+), 560 deletions(-) diff --git a/observe-services/pom.xml b/observe-services-api/pom.xml similarity index 95% copy from observe-services/pom.xml copy to observe-services-api/pom.xml index 1b85d2d..7d7da42 100644 --- a/observe-services/pom.xml +++ b/observe-services-api/pom.xml @@ -10,10 +10,10 @@ <version>4.0-RC5-SNAPSHOT</version> </parent> - <artifactId>observe-services</artifactId> + <artifactId>observe-services-api</artifactId> - <name>ObServe :: Services</name> - <description>ObServe services module</description> + <name>ObServe :: Services API</name> + <description>ObServe services API module</description> <dependencies> @@ -118,7 +118,6 @@ <artifactId>junit</artifactId> </dependency> - </dependencies> diff --git a/observe-services/src/main/java/fr/ird/observe/services/Commit.java b/observe-services-api/src/main/java/fr/ird/observe/services/Commit.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/Commit.java rename to observe-services-api/src/main/java/fr/ird/observe/services/Commit.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java b/observe-services-api/src/main/java/fr/ird/observe/services/NoTransaction.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/NoTransaction.java rename to observe-services-api/src/main/java/fr/ird/observe/services/NoTransaction.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveService.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/ObserveService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/ObserveService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceContext.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/ObserveServiceContext.java rename to observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceContext.java diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java new file mode 100644 index 0000000..951d040 --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -0,0 +1,342 @@ +package fr.ird.observe.services; + +import com.google.common.base.Preconditions; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import fr.ird.observe.ObserveApplicationContext; +import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.db.DataSource; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.Closeable; +import java.util.HashSet; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.concurrent.ExecutionException; + +/** + * Created on 4/24/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ObserveServiceFactory implements Closeable { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ObserveServiceFactory.class); + + protected final ObserveApplicationContext applicationContext; + + protected static Set<ObserveServiceFactoryProvider> providers; + + protected static Set<ObserveServiceFactoryProvider> getProviders() { + + if (providers == null) { + providers = new HashSet<ObserveServiceFactoryProvider>(); + + ServiceLoader<ObserveServiceFactoryProvider> load = ServiceLoader.load(ObserveServiceFactoryProvider.class); + for (ObserveServiceFactoryProvider observeServiceFactoryProvider : load) { + + providers.add(observeServiceFactoryProvider); + } + } + + return providers; + + } + + protected static ObserveServiceFactoryProvider getProvider(DataSource dataSource) { + + ObserveServiceFactoryProvider result = null; + for (ObserveServiceFactoryProvider provider : getProviders()) { + if (provider.acceptDataSource(dataSource)) { + result = provider; + break; + } + } + + Preconditions.checkState(result != null, "No provider found for dataSource: " + dataSource); + return result; + + } + + protected final LoadingCache<ServiceKey<? extends ObserveService>, ObserveService> services; + + public static ObserveServiceFactory newFactory(ObserveApplicationContext applicationContext) { + return new ObserveServiceFactory(applicationContext); + } + + protected ObserveServiceFactory(ObserveApplicationContext applicationContext) { + + this.applicationContext = applicationContext; + this.services = CacheBuilder.newBuilder().build(new CacheLoader<ServiceKey<? extends ObserveService>, ObserveService>() { + + @Override + public ObserveService load(ServiceKey<? extends ObserveService> key) throws Exception { + Preconditions.checkNotNull(key, "service key can't be null"); + + Class<? extends ObserveService> serviceType = key.serviceType; + + ObserveServiceFactoryProvider provider = getProvider(key.dataSource); + + ObserveServiceContext serviceContext = new ObserveServiceContext(ObserveServiceFactory.this.applicationContext, key.dataSource); + ObserveService service = provider.newService(serviceType, serviceContext); + + if (log.isDebugEnabled()) { + log.debug("New service " + service); + } + + return service; + } + }); + + } + + public <S extends ObserveService> S getService(DataSource dataSource, Class<S> serviceType) { + + Preconditions.checkNotNull(dataSource, "dataSource can't be null."); + Preconditions.checkNotNull(serviceType, "serviceType can't be null."); + Preconditions.checkNotNull(dataSource, "dataSource can't be null."); + + ServiceKey<S> key = new ServiceKey<S>(dataSource, serviceType); + + try { + + S s = (S) services.get(key); + return s; + + } catch (ExecutionException e) { + throw new ObserveTechnicalException("Could not get service: " + serviceType, e); + } + + } + + static class ServiceKey<S extends ObserveService> { + + final DataSource dataSource; + + final Class<S> serviceType; + + ServiceKey(DataSource dataSource, Class<S> serviceType) { + + Preconditions.checkNotNull(dataSource, "dataSource can't be null."); + Preconditions.checkNotNull(serviceType, "serviceType can't be null."); + this.dataSource = dataSource; + this.serviceType = serviceType; + + } + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (!(o instanceof ServiceKey)) return false; + + ServiceKey<?> that = (ServiceKey<?>) o; + + return dataSource.equals(that.dataSource) + && serviceType.equals(that.serviceType); + + } + + @Override + public int hashCode() { + + int result = dataSource.hashCode(); + result = 31 * result + serviceType.hashCode(); + return result; + + } + } + +// public <S extends ObserveService> S getService(Class<S> serviceType) { +// +// Preconditions.checkNotNull(serviceType, "serviceType can't be null."); +// Preconditions.checkNotNull(dataSource, "dataSource can't be null."); +// +// try { +// S s = (S) services.get(serviceType); +// return s; +// } catch (ExecutionException e) { +// throw new ObserveTechnicalException("Could not get service: " + serviceType, e); +// } +// } + + public void unregisterDataSource(DataSource dataSource) { + //FIXME Remove all service using this dataSource + } + + public void clear() { + services.invalidateAll(); + } + + @Override + public void close() { + + for (ObserveService service : services.asMap().values()) { + if (log.isDebugEnabled()) { + log.debug("Close service " + service); + } + IOUtils.closeQuietly(service); + } + services.invalidateAll(); + + } + +// public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { +// +// Preconditions.checkNotNull(serviceType, "serviceType can't be null"); +// Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); +// Preconditions.checkNotNull(applicationContext, "applicationContext can't be null"); +// +// ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); +// +// S service = newProxyService(serviceType, serviceContext); +// return service; +// +// } +// +// public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveServiceContext serviceContext) { +// +// Preconditions.checkNotNull(serviceType, "serviceType can't be null"); +// Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); +// Preconditions.checkNotNull(serviceContext, "serviceContext can't be null"); +// +// S service = newService(serviceType, serviceContext); +// S proxyService = addProxyService(serviceType, service, serviceContext); +// return proxyService; +// +// } +// +// public static <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { +// +// Class<S> serviceImpl; +// try { +// //FIXME Cela devrait dépendre de la datasource ? +// serviceImpl = (Class<S>) Class.forName(serviceType.getName() + "Impl"); +// } catch (ClassNotFoundException e) { +// throw new IllegalStateException("Could not find implementation class for " + serviceType); +// } +// +// try { +// +// // Instanciate concrete service +// S service = ConstructorUtils.invokeConstructor(serviceImpl); +// service.setServiceContext(serviceContext); +// +// return service; +// +// } catch (Exception e) { +// throw new ObserveTechnicalException("Could not create service: " + serviceType, e); +// } +// +// } +// +// protected <S extends ObserveService> S addProxyService(Class<S> serviceType, S service, ObserveServiceContext serviceContext) { +// +// // Instanciate transactional proxied service +// ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); +// S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); +// +// return proxyService; +// +// } +// +// protected static class ServiceInvocationHandler implements InvocationHandler { +// +// private final ObserveServiceContext serviceContext; +// +// private final ObserveService target; +// +// private final Set<String> methodNamesToByPass; +// +// protected ServiceInvocationHandler(ObserveServiceContext serviceContext, ObserveService target) { +// this.serviceContext = serviceContext; +// this.target = target; +// this.methodNamesToByPass = Sets.newHashSet( +// "equals", +// "hashCode", +// "finalize", +// "toString", +// "clone", +// "getClass" +// ); +// } +// +// @Override +// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { +// +// Object result; +// +// if (methodNamesToByPass.contains(method.getName()) || method.isAnnotationPresent(NoTransaction.class)) { +// +// result = invokeMethod(method, args); +// +// } else { +// +// result = invokeMethodWithTransaction(method, args); +// +// } +// +// return result; +// +// } +// +// protected Object invokeMethod(Method method, Object... args) throws Throwable { +// try { +// Object result = method.invoke(target, args); +// return result; +// } catch (InvocationTargetException e) { +// throw e.getCause(); +// } +// } +// +// +// protected Object invokeMethodWithTransaction(Method method, Object... args) throws Throwable { +// +// String methodName = method.getName(); +// +// DataSource source = serviceContext.getDataSource(); +// +// TopiaContext tx = source.beginTransaction(methodName); +// +// try { +// +// serviceContext.setTransaction(tx); +// +// Object invoke = invokeMethod(method, args); +// +// if (method.isAnnotationPresent(Commit.class)) { +// +// // do commit +// source.commitTransaction(tx, methodName); +// +// } +// +// return invoke; +// +// } finally { +// +// try { +// +// // always rollback transaction to avoid dirty transactions +// source.rollbackTransaction(tx, methodName); +// +// +// } finally { +// +// serviceContext.setTransaction(null); +// source.closeTransaction(tx, methodName); +// +// } +// +// } +// +// } +// +// } + +} diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProvider.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProvider.java new file mode 100644 index 0000000..abc3386 --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProvider.java @@ -0,0 +1,17 @@ +package fr.ird.observe.services; + +import fr.ird.observe.db.DataSource; + +/** + * Created on 5/4/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ObserveServiceFactoryProvider { + + boolean acceptDataSource(DataSource dataSource); + + <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java b/observe-services-api/src/main/java/fr/ird/observe/services/ReplicationService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/ReplicationService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/OpenableService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/OpenableService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/OpenableService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/OpenableService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/TripService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/BaitsCompositionService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/EncounterService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/EncounterService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/SensorUsedService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/TdrService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/TdrService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/longline/TripLonglineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/RouteService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/RouteService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/SetSeineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/TargetCatchService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/TargetCatchService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/TargetSampleService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/seine/TripSeineService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java b/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java similarity index 98% rename from observe-services/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java rename to observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java index abb314a..c3ea1f0 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.services.model; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.Trips; @@ -59,16 +60,16 @@ import java.util.TreeMap; */ public class DataSelectionModel implements Serializable { - public static void populate(DataSelectionModel model, ObserveServiceFactory services) throws Exception { + public static void populate(DataSelectionModel model, ObserveServiceFactory services, DataSource dataSource) throws Exception { // source.checkState(DataSourceState.OPEN); Map<String, List<String>> datas = new HashMap<String, List<String>>(); - TripSeineService tripSeineService = services.getService(TripSeineService.class); - TripLonglineService tripLonglineService = services.getService(TripLonglineService.class); + TripSeineService tripSeineService = services.getService(dataSource, TripSeineService.class); + TripLonglineService tripLonglineService = services.getService(dataSource, TripLonglineService.class); - List<Program> programs = services.getService(ReferentialService.class).getAllProgramStub(); + List<Program> programs = services.getService(dataSource, ReferentialService.class).getAllProgramStub(); for (Program program : programs) { if (Programs.isProgramSeine(program)) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java b/observe-services-api/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java b/observe-services-api/src/main/java/fr/ird/observe/services/operation/GpsImportService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/operation/GpsImportService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java b/observe-services-api/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java rename to observe-services-api/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java b/observe-services-api/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java b/observe-services-api/src/main/java/fr/ird/observe/services/operation/ValidationService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/operation/ValidationService.java diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services-api/src/main/java/fr/ird/observe/services/referential/ReferentialService.java similarity index 100% rename from observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java rename to observe-services-api/src/main/java/fr/ird/observe/services/referential/ReferentialService.java diff --git a/observe-services/pom.xml b/observe-services/pom.xml index 1b85d2d..821a17d 100644 --- a/observe-services/pom.xml +++ b/observe-services/pom.xml @@ -28,6 +28,11 @@ <artifactId>observe-business</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>observe-services-api</artifactId> + <version>${project.version}</version> + </dependency> <!-- commons dependencies --> diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 40e6f0f..b14e6fa 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -454,17 +454,17 @@ public abstract class AbstractObserveService implements ObserveService { protected <S extends ObserveService> S newService(Class<S> serviceType) { - S service = ObserveServiceFactory.newService(serviceType, serviceContext); + S service = new ObserveServiceFactoryProviderTopia().newService(serviceType, serviceContext); return service; } - protected ObserveServiceFactory newServiceFactory(DataSource dataSource) { + protected <S extends ObserveService> S newService(DataSource dataSource, Class<S> serviceType) { - ObserveServiceFactory serviceFactory = ObserveServiceFactory.newFactory(serviceContext.applicationContext, dataSource); - return serviceFactory; + ObserveServiceContext serviceContext1 = new ObserveServiceContext(serviceContext.applicationContext, dataSource); + S service = new ObserveServiceFactoryProviderTopia().newService(serviceType, serviceContext1); + return service; } - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java similarity index 53% rename from observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java rename to observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java index c48e040..8e8b951 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java @@ -1,138 +1,65 @@ package fr.ird.observe.services; import com.google.common.base.Preconditions; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.common.collect.Sets; -import fr.ird.observe.ObserveApplicationContext; import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataSource; -import org.apache.commons.io.IOUtils; +import fr.ird.observe.db.impl.H2DataSource; +import fr.ird.observe.db.impl.PGDataSource; import org.apache.commons.lang3.reflect.ConstructorUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; -import java.io.Closeable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Set; -import java.util.concurrent.ExecutionException; /** - * Created on 4/24/15. + * Created on 5/4/15. * * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class ObserveServiceFactory implements Closeable { +public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactoryProvider { - /** Logger. */ - private static final Log log = LogFactory.getLog(ObserveServiceFactory.class); - - protected final ObserveApplicationContext applicationContext; - - protected DataSource dataSource; - - protected final LoadingCache<Class<? extends ObserveService>, ObserveService> services; - - public static ObserveServiceFactory newFactory(ObserveApplicationContext applicationContext) { - return new ObserveServiceFactory(applicationContext); - } - - public static ObserveServiceFactory newFactory(ObserveApplicationContext applicationContext, DataSource dataSource) { - ObserveServiceFactory factory = newFactory(applicationContext); - factory.setDataSource(dataSource); - return factory; - } - - protected ObserveServiceFactory(ObserveApplicationContext applicationContext) { - this.applicationContext = applicationContext; - this.services = CacheBuilder.newBuilder().build(new CacheLoader<Class<? extends ObserveService>, ObserveService>() { - - @Override - public ObserveService load(Class<? extends ObserveService> key) throws Exception { - Preconditions.checkNotNull(key, "service key can't be null"); - Preconditions.checkNotNull(dataSource, "can't ask a service if not datasource is setted"); - ObserveService service = newProxyService(key, ObserveServiceFactory.this.applicationContext, ObserveServiceFactory.this.dataSource); - if (log.isDebugEnabled()) { - log.debug("New service " + service); - } - - return service; - } - }); - } - - public DataSource getDataSource() { - return dataSource; - } - - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } - - public <S extends ObserveService> S getService(Class<S> serviceType) { - if (serviceType == null) { - return null; - } - try { - S s = (S) services.get(serviceType); - return s; - } catch (ExecutionException e) { - throw new ObserveTechnicalException("Could not get service: " + serviceType, e); - } - } - - public void clear() { - services.invalidateAll(); - } +// private ObserveApplicationContext applicationContext; +// +// public void setApplicationContext(ObserveApplicationContext applicationContext) { +// this.applicationContext = applicationContext; +// } @Override - public void close() { + public boolean acceptDataSource(DataSource dataSource) { - for (ObserveService service : services.asMap().values()) { - if (log.isDebugEnabled()) { - log.debug("Close service " + service); - } - IOUtils.closeQuietly(service); + boolean result = false; + if (dataSource instanceof H2DataSource) { + result = true; + } else if (dataSource instanceof PGDataSource) { + result = true; } - services.invalidateAll(); - } - - public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { - - Preconditions.checkNotNull(serviceType, "serviceType can't be null"); - Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); - Preconditions.checkNotNull(applicationContext, "applicationContext can't be null"); - - ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); - - S service = newProxyService(serviceType, serviceContext); - return service; + return result; } - public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveServiceContext serviceContext) { + @Override + public <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { Preconditions.checkNotNull(serviceType, "serviceType can't be null"); Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); Preconditions.checkNotNull(serviceContext, "serviceContext can't be null"); - S service = newService(serviceType, serviceContext); + S service = newSimpleService(serviceType, serviceContext); S proxyService = addProxyService(serviceType, service, serviceContext); return proxyService; } - public static <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { + public static <S extends ObserveService> S newSimpleService(Class<S> serviceType, ObserveServiceContext serviceContext) { + //FIXME Rename implementation to TopiaImpl Class<S> serviceImpl; try { - //FIXME Cela devrait dépendre de la datasource ? serviceImpl = (Class<S>) Class.forName(serviceType.getName() + "Impl"); } catch (ClassNotFoundException e) { throw new IllegalStateException("Could not find implementation class for " + serviceType); @@ -160,7 +87,6 @@ public class ObserveServiceFactory implements Closeable { return proxyService; - } protected static class ServiceInvocationHandler implements InvocationHandler { diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java index e87ec48..0079de3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java @@ -10,7 +10,6 @@ import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.referential.ReferentialService; import org.apache.commons.collections.CollectionUtils; @@ -53,48 +52,37 @@ public class SynchronizeServiceImpl extends AbstractObserveService implements Sy @Override public DiffState.DiffStateMap buildReferentielDifferentiel(final DataSource centralDataSource, final SendMessageAble messanger) { - ObserveServiceFactory centralDataSourceServices = newServiceFactory(centralDataSource); + final DiffState.DiffStateMap result = DiffState.newMap(); - try { + final ReferentialService centralReferentialService = newService(centralDataSource, ReferentialService.class); - final DiffState.DiffStateMap result = DiffState.newMap(); + ReferenceEntities.walk(new ReferenceEntities.ReferentielWalker() { - final ReferentialService centralReferentialService = - centralDataSourceServices.getService(ReferentialService.class); - ReferenceEntities.walk(new ReferenceEntities.ReferentielWalker() { + public <E extends TopiaEntity> void walk(Class<E> contractClass) { - - public <E extends TopiaEntity> void walk(Class<E> contractClass) { - - String s = t(DecoratorService.getEntityLabel(contractClass)); - String message = - t("observe.service.build.synchro.referentiel", s); - if (messanger != null) { - messanger.sendMessage(message); - } - if (log.isInfoEnabled()) { - log.info(message); - } - List<E> list = centralReferentialService.getList(contractClass); - List<E> list2 = getList(contractClass); - DiffState.DiffStateMap tmp; - // recuperation du differentiel pour le type d'entitétmp = - tmp = TopiaEntityHelper.buildDifferentiel(list, list2); - // ajout au resultat - DiffState.addAll(result, tmp); - // on nettoie - DiffState.clear(tmp); + String s = t(DecoratorService.getEntityLabel(contractClass)); + String message = + t("observe.service.build.synchro.referentiel", s); + if (messanger != null) { + messanger.sendMessage(message); } - }); - DiffState.removeEmptyStates(result); - return result; - - } finally { - - centralDataSourceServices.close(); - - } + if (log.isInfoEnabled()) { + log.info(message); + } + List<E> list = centralReferentialService.getList(contractClass); + List<E> list2 = getList(contractClass); + DiffState.DiffStateMap tmp; + // recuperation du differentiel pour le type d'entitétmp = + tmp = TopiaEntityHelper.buildDifferentiel(list, list2); + // ajout au resultat + DiffState.addAll(result, tmp); + // on nettoie + DiffState.clear(tmp); + } + }); + DiffState.removeEmptyStates(result); + return result; } @@ -132,74 +120,65 @@ public class SynchronizeServiceImpl extends AbstractObserveService implements Sy List<String> ids; - ObserveServiceFactory centralSourceFactory = newServiceFactory(centralDataSource); - - try { - - // ajout des nouvelles entites du referentiel + // ajout des nouvelles entites du referentiel - ids = diff.get(DiffState.NEW); - if (CollectionUtils.isNotEmpty(ids)) { + ids = diff.get(DiffState.NEW); + if (CollectionUtils.isNotEmpty(ids)) { - ReplicationService replicationService = newService(ReplicationService.class); + ReplicationService replicationService = newService(centralDataSource, ReplicationService.class); - replicationService.replicateReferentiel(centralDataSource, ids, messanger); + replicationService.replicateReferentiel(centralDataSource, ids, messanger); - } - - ReferentialService localReferentialService = newService(ReferentialService.class); + } - // mis a jour des entites modifiees + ReferentialService localReferentialService = newService(ReferentialService.class); - ids = diff.get(DiffState.MODIFIED); - if (CollectionUtils.isNotEmpty(ids)) { + // mis a jour des entites modifiees - ReferentialService service = centralSourceFactory.getService(ReferentialService.class); - Collection<? extends TopiaEntity> entitiesToCopy = service.loadSimpleEntities(ids); + ids = diff.get(DiffState.MODIFIED); + if (CollectionUtils.isNotEmpty(ids)) { - localReferentialService.copySimpleEntities(entitiesToCopy); + ReferentialService service = newService(centralDataSource, ReferentialService.class); + Collection<? extends TopiaEntity> entitiesToCopy = service.loadSimpleEntities(ids); - } + localReferentialService.copySimpleEntities(entitiesToCopy); - // mise à jour des données utilisateurs (remplacements d'objets obsolètes) - - for (ObsoleteReferenceToReplace referenceToReplace : obsoleteReferencesToReplace) { + } - String message = t("observe.synchro.replaceObsolete.object", referenceToReplace.getObsoleteId()); - messanger.sendMessage(message); + // mise à jour des données utilisateurs (remplacements d'objets obsolètes) - localReferentialService.replaceObsoleteReference(referenceToReplace); + for (ObsoleteReferenceToReplace referenceToReplace : obsoleteReferencesToReplace) { - } + String message = t("observe.synchro.replaceObsolete.object", referenceToReplace.getObsoleteId()); + messanger.sendMessage(message); - // si on ne commite pas ici, les modifications utilisateurs sont perdues - getTransaction().commitTransaction(); + localReferentialService.replaceObsoleteReference(referenceToReplace); - // suppression des entités obsoletes de la base source + } - ids = diff.get(DiffState.REMOVED); - if (CollectionUtils.isNotEmpty(ids)) { + // si on ne commite pas ici, les modifications utilisateurs sont perdues + getTransaction().commitTransaction(); - localReferentialService.deleteEntities(ids); + // suppression des entités obsoletes de la base source - } + ids = diff.get(DiffState.REMOVED); + if (CollectionUtils.isNotEmpty(ids)) { - if (MapUtils.isNotEmpty(versionsToUpdate)) { + localReferentialService.deleteEntities(ids); - // on applique le patch sur les versions pour bien avoir - // la bonne version de topiaversion et pas seulement un incrément - // de 1 puisque ce champs est géré par hibernate et qu'il ne nous laisse - // pas la possibilité de choisir la valeur qu'on veut attribuer au champs... - patchTopiaVersions(versionsToUpdate); - } + } - getTransaction().commitTransaction(); + if (MapUtils.isNotEmpty(versionsToUpdate)) { - } finally { + // on applique le patch sur les versions pour bien avoir + // la bonne version de topiaversion et pas seulement un incrément + // de 1 puisque ce champs est géré par hibernate et qu'il ne nous laisse + // pas la possibilité de choisir la valeur qu'on veut attribuer au champs... + patchTopiaVersions(versionsToUpdate); + } - centralSourceFactory.close(); + getTransaction().commitTransaction(); - } } private static final String UPDATE_VERSION_PATTERN = "UPDATE %1$s SET topiaversion = %2$d WHERE topiaid='%3$s';\n"; diff --git a/observe-services/src/main/resources/META-INF/services/fr.ird.observe.services.ObserveServiceFactoryProvider b/observe-services/src/main/resources/META-INF/services/fr.ird.observe.services.ObserveServiceFactoryProvider new file mode 100644 index 0000000..d88eed8 --- /dev/null +++ b/observe-services/src/main/resources/META-INF/services/fr.ird.observe.services.ObserveServiceFactoryProvider @@ -0,0 +1 @@ +fr.ird.observe.services.ObserveServiceFactoryProviderTopia \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java index 4c88c27..5f1713a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java @@ -24,7 +24,6 @@ package fr.ird.observe; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListenerAdapter; import fr.ird.observe.db.impl.H2DataSource; @@ -32,10 +31,8 @@ import fr.ird.observe.services.ObserveService; import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.OpenableService; import fr.ird.observe.ui.ObserveMainUI; -import fr.ird.observe.ui.ObserveMainUIHandler; import fr.ird.observe.ui.ObserveUIMode; import fr.ird.observe.ui.UIHelper; -import fr.ird.observe.ui.actions.ChangeStorageAction; import fr.ird.observe.ui.actions.shared.AbstractUIAction; import fr.ird.observe.ui.actions.shared.CancelCreateUIAction; import fr.ird.observe.ui.actions.shared.CloseAndCreateUIAction; @@ -66,7 +63,6 @@ import java.awt.Component; import java.util.Arrays; import java.util.List; -import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; /** @@ -236,12 +232,13 @@ public class ObserveContext extends ObserveApplicationContext { ObserveRunner.getRunner().setReload(true); } - public static ObserveServiceFactory newServiceFactory(DataSource dataSource) { - return ObserveServiceFactory.newFactory(get(), dataSource); + public <S extends ObserveService> S getService(Class<S> serviceType) { + S service = services.getService(getDataSource(), serviceType); + return service; } - public <S extends ObserveService> S getService(Class<S> serviceType) { - S service = services.getService(serviceType); + public static <S extends ObserveService> S getService(DataSource dataSource, Class<S> serviceType) { + S service = get().services.getService(dataSource, serviceType); return service; } @@ -249,78 +246,78 @@ public class ObserveContext extends ObserveApplicationContext { return services; } - public void initStorage(ObserveConfig config, - ObserveMainUI mainUI, - boolean askToCreate) { - try { - if (config.isLocalStorageExist()) { - - // une base locale existe, on l'ouvre - loadLocalStorage(); - - // on peut retourner sur cette base - mainUI.setMode(ObserveUIMode.DB); - } else { - - // on peut retourner sur cette base - mainUI.setMode(ObserveUIMode.NO_DB); - - if (askToCreate) { - - // demande à l'utilisateur s'il veut créer la base locale - createStorage(config, mainUI.getHandler()); - } - } - if (log.isInfoEnabled()) { - log.info(t("observe.init.storage.done")); - } - } catch (Exception e) { - ErrorDialogUI.showError(e); - if (log.isErrorEnabled()) { - log.error(e.getMessage(), e); - } - } - } - - protected void createStorage(ObserveConfig config, - ObserveMainUIHandler uiHandler) { - - int reponse = UIHelper.askUser( - t("observe.title.no.local.db.found"), - t("observe.message.no.local.db.found", - config.getLocalDBDirectory()), - JOptionPane.QUESTION_MESSAGE, - new Object[]{ - t("observe.choice.useRemoteStorage"), - t("observe.choice.createLocalStorage"), - t("observe.choice.doNothing") - }, - 1 - ); - if (log.isDebugEnabled()) { - log.debug("response : " + reponse); - } - - DbMode dbMode = null; - String title = null; - if (reponse != JOptionPane.CLOSED_OPTION && reponse < 2) { - - if (reponse == 1) { - // creation de la base locale - dbMode = DbMode.CREATE_LOCAL; - title = n("observe.title.create.local.db"); - } else { - // connexion à une base distante - dbMode = DbMode.USE_REMOTE; - title = n("observe.title.load.remote.db"); - } - } - if (dbMode != null) { -// uiHandler.launchChangeStorage(getObserveMainUI(), dbMode, title); +// public void initStorage(ObserveConfig config, +// ObserveMainUI mainUI, +// boolean askToCreate) { +// try { +// if (config.isLocalStorageExist()) { +// +// // une base locale existe, on l'ouvre +// loadLocalStorage(); +// +// // on peut retourner sur cette base +// mainUI.setMode(ObserveUIMode.DB); +// } else { +// +// // on peut retourner sur cette base +// mainUI.setMode(ObserveUIMode.NO_DB); +// +// if (askToCreate) { +// +// // demande à l'utilisateur s'il veut créer la base locale +// createStorage(config, mainUI.getHandler()); +// } +// } +// if (log.isInfoEnabled()) { +// log.info(t("observe.init.storage.done")); +// } +// } catch (Exception e) { +// ErrorDialogUI.showError(e); +// if (log.isErrorEnabled()) { +// log.error(e.getMessage(), e); +// } +// } +// } - new ChangeStorageAction(getObserveMainUI(), dbMode, title).run(); - } - } +// protected void createStorage(ObserveConfig config, +// ObserveMainUIHandler uiHandler) { +// +// int reponse = UIHelper.askUser( +// t("observe.title.no.local.db.found"), +// t("observe.message.no.local.db.found", +// config.getLocalDBDirectory()), +// JOptionPane.QUESTION_MESSAGE, +// new Object[]{ +// t("observe.choice.useRemoteStorage"), +// t("observe.choice.createLocalStorage"), +// t("observe.choice.doNothing") +// }, +// 1 +// ); +// if (log.isDebugEnabled()) { +// log.debug("response : " + reponse); +// } +// +// DbMode dbMode = null; +// String title = null; +// if (reponse != JOptionPane.CLOSED_OPTION && reponse < 2) { +// +// if (reponse == 1) { +// // creation de la base locale +// dbMode = DbMode.CREATE_LOCAL; +// title = n("observe.title.create.local.db"); +// } else { +// // connexion à une base distante +// dbMode = DbMode.USE_REMOTE; +// title = n("observe.title.load.remote.db"); +// } +// } +// if (dbMode != null) { +//// uiHandler.launchChangeStorage(getObserveMainUI(), dbMode, title); +// +// new ChangeStorageAction(getObserveMainUI(), dbMode, title).run(); +// } +// } protected void loadLocalStorage() throws Exception { @@ -454,12 +451,6 @@ public class ObserveContext extends ObserveApplicationContext { // references vers le service DataSource source = event.getSource(); - // gestion JMX -// if (ObserveServiceHelper.isUseJMX()) { -// -// dettachHibernateMBean(source); -// } - ObserveMainUI mainUI = getObserveMainUI(); // nettoyage de l'ui ( suppression navigation et autres ) @@ -479,6 +470,7 @@ public class ObserveContext extends ObserveApplicationContext { } protected void openOnUI(DataSource source) throws DataSourceException { + // on rend le service disponible dans le service de données ObserveServiceHelper.get().setDataSource(source); @@ -495,18 +487,12 @@ public class ObserveContext extends ObserveApplicationContext { config.setLocalStorageExist(true); } - // gestion JMX -// if (ObserveServiceHelper.isUseJMX()) { -// createHibernateMBean(source); -// } - // remplissage de l'ui ObserveMainUI mainUI = getObserveMainUI(); if (mainUI != null) { if (log.isDebugEnabled()) { - log.debug("loading ui for storage " + source.getLabel() + - ": " + mainUI.getName()); + log.debug("loading ui for storage " + source.getLabel() + ": " + mainUI.getName()); } DataContext dataContext = mainUI.getDataContext(); @@ -516,58 +502,19 @@ public class ObserveContext extends ObserveApplicationContext { treeHelper.cleanNavigationUI(mainUI); - String[] openIds = getService(OpenableService.class).getOpenIds(); mainUI.getDataContext().populateOpens(openIds); treeHelper.loadNavigationUI(source, mainUI); mainUI.setMode(ObserveUIMode.DB); - mainUI.getStatus().setStatus( - t("observe.message.db.loaded", source.getLabel())); + mainUI.getStatus().setStatus(t("observe.message.db.loaded", source.getLabel())); } } }); } -// protected void createHibernateMBean(DataSource source) { -// try { -// ObjectName on = createMBean(source); -// if (log.isInfoEnabled()) { -// log.info("attach MBean " + on); -// } -// MBeanServer server = ManagementFactory.getPlatformMBeanServer(); -// // MBean implementation -// StatisticsService stats = new StatisticsService(); -// // Bind the stats to a SessionFactory -// stats.setSessionFactory(((TopiaContextImplementor) source.getRootCtxt()).getHibernateFactory()); -// // Register the Mbean on the server -// server.registerMBean(stats, on); -// } catch (Exception e) { -// if (log.isErrorEnabled()) { -// log.error("Could not attach hibernate session to JMX...", e); -// } -// } -// } - -// public void dettachHibernateMBean(DataSource source) { -// // suppression MBean sur la session hibernate -// try { -// MBeanServer server = ManagementFactory.getPlatformMBeanServer(); -// ObjectName on = createMBean(source); -// if (log.isInfoEnabled()) { -// log.info("dettach MBean " + on); -// } -// // UnRegister the Mbean on the server -// server.unregisterMBean(on); -// } catch (Exception e) { -// if (log.isErrorEnabled()) { -// log.error("Could not dettach hibernate session from JMX...", e); -// } -// } -// } - public void registerShareActions(ObserveMainUI ui) { ActionMap actionMap = ui.getRootPane().getActionMap(); @@ -596,23 +543,6 @@ public class ObserveContext extends ObserveApplicationContext { actionMap.put(actionId, action); } -// @SuppressWarnings({"UseOfObsoleteCollectionType"}) -// protected ObjectName createMBean(DataSource source) throws MalformedObjectNameException { -// Hashtable<String, String> tb = new Hashtable<String, String>(); -// tb.put("type", "statistics"); -// String name = source.getLabel(); -// tb.put("sessionFactory", name.replaceAll(":", "_")); -// // MBean object name -// ObjectName on = new ObjectName("hibernate", tb); -// return on; -// } - private final ObserveServiceFactory services = ObserveServiceFactory.newFactory(this); - @Override - public void setDataSource(DataSource dataSource) { - super.setDataSource(dataSource); - services.close(); - services.setDataSource(dataSource); - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java index 92a6411..28e36fc 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java @@ -34,7 +34,6 @@ import fr.ird.observe.db.impl.PGDataSource; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.Trips; import fr.ird.observe.report.model.Report; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.admin.consolidate.ConsolidateModel; import fr.ird.observe.ui.admin.export.ExportModel; @@ -179,12 +178,8 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { // on doit aussi calculer les ids des marées distantes DataSource safeCentralSource = getSafeCentralSource(true); - ObserveServiceFactory services = ObserveContext.newServiceFactory(safeCentralSource); - try { - computeExistingTrips(services); - } finally { - services.close(); - } + + computeExistingTrips(safeCentralSource); } @@ -193,13 +188,8 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { log.debug("Will refill selectionModel [" + newStep + "] : " + selectModel); } DataSource dataSource = getSafeLocalSource(true); + populateSelectionModel(dataSource); - ObserveServiceFactory services = ObserveContext.newServiceFactory(dataSource); - try { - populateSelectionModel(services); - } finally { - services.close(); - } } }; @@ -1284,9 +1274,9 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } } - public void populateSelectionModel(ObserveServiceFactory services) { + public void populateSelectionModel(DataSource dataSource) { try { - DataSelectionModel.populate(getSelectionDataModel(), services); + DataSelectionModel.populate(getSelectionDataModel(), ObserveContext.get().getServices(), dataSource); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("could not populate selected model", e); @@ -1299,12 +1289,12 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } } - protected void computeExistingTrips(ObserveServiceFactory services) { + protected void computeExistingTrips(DataSource dataSource) { DataSelectionModel selectionModel = new DataSelectionModel(); selectionModel.setUseOpenData(true); try { - DataSelectionModel.populate(selectionModel, services); + DataSelectionModel.populate(selectionModel, ObserveContext.get().getServices(), dataSource); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("could not populate selected model", e); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java index 7f35319..b909441 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateModel.java @@ -21,10 +21,7 @@ */ package fr.ird.observe.ui.admin.consolidate; -import com.google.common.base.Preconditions; -import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.admin.AdminActionModel; import fr.ird.observe.ui.admin.AdminStep; @@ -39,8 +36,6 @@ public class ConsolidateModel extends AdminActionModel { /** la source de données où effectuer la consolidation des données */ private DataSource source; - protected ObserveServiceFactory serviceFactory; - public ConsolidateModel() { super(AdminStep.CONSOLIDATE); } @@ -51,22 +46,6 @@ public class ConsolidateModel extends AdminActionModel { public void setSource(DataSource source) { this.source = source; - if (serviceFactory != null) { - serviceFactory.close(); - serviceFactory = null; - } - } - - public ObserveServiceFactory getServiceFactory() { - - if (serviceFactory == null) { - - Preconditions.checkNotNull(source, "Can't create source service factory if source is null"); - serviceFactory = ObserveContext.newServiceFactory(source); - - } - return serviceFactory; - } @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java index d5da3d8..f153528 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java @@ -21,8 +21,8 @@ */ package fr.ird.observe.ui.admin.consolidate; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.services.operation.ComputeDataService; import fr.ird.observe.ui.admin.AdminStep; @@ -129,9 +129,7 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { Set<String> tripIds = model.getSelectionDataModel().getSelectedData(); - ObserveServiceFactory serviceFactory = getStepModel().getServiceFactory(); - - ComputeDataService service = serviceFactory.getService(ComputeDataService.class); + ComputeDataService service = ObserveContext.get().getServices().getService(getStepModel().getSource(), ComputeDataService.class); try { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java index 8233e85..b6bf549 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java @@ -21,16 +21,14 @@ */ package fr.ird.observe.ui.admin.export; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.services.ObserveServiceFactory; -import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.admin.AdminActionModel; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminUIModel; @@ -145,20 +143,6 @@ public class ExportModel extends AdminActionModel { public void setCentralSource(DataSource centralSource) { this.centralSource = centralSource; - if (centralServiceFactory != null) { - centralServiceFactory.close(); - centralServiceFactory = null; - } - } - - public ObserveServiceFactory getCentraServiceFactory() { - - if (centralServiceFactory == null) { - Preconditions.checkNotNull(centralSource, "Can't create source service factory if centralSource is null"); - centralServiceFactory = ObserveContext.newServiceFactory(centralSource); - } - return centralServiceFactory; - } public void setProgramDecorator(Decorator<Program> programDecorator) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java index 12e9561..6d5d320 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java @@ -22,12 +22,12 @@ package fr.ird.observe.ui.admin.export; import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.data.TripService; import fr.ird.observe.services.model.DataSelectionModel; @@ -275,8 +275,7 @@ public class ExportUIHandler extends AdminTabUIHandler { protected void processTrip(ExportModel stepModel, TripEntry tripEntry) throws Exception { - ObserveServiceFactory centralServices = stepModel.getCentraServiceFactory(); - + DataSource centralSource = stepModel.getCentralSource(); DataSource source = stepModel.getSource(); Trip trip = tripEntry.getTrip(); @@ -295,7 +294,7 @@ public class ExportUIHandler extends AdminTabUIHandler { } sendMessage(t("observe.message.exportData.delete.remote.maree", tripDecorated, programDecorated)); - TripService service = centralServices.getService(TripService.class); + TripService service = ObserveContext.getService(centralSource, TripService.class); service.deleteTrip(tripId); } @@ -305,7 +304,7 @@ public class ExportUIHandler extends AdminTabUIHandler { } sendMessage(t("observe.message.exportData.replicate.maree", tripDecorated, programDecorated)); - ReplicationService service = centralServices.getService(ReplicationService.class); + ReplicationService service = ObserveContext.getService(centralSource,ReplicationService.class); service.replicateData(source, tripId); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java index 516ad80..c2ef087 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/gps/ImportGPSUIHandler.java @@ -29,7 +29,6 @@ import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.gps.GPSPoint; import fr.ird.observe.gps.GPSPointInterval; import fr.ird.observe.gps.GPSRoute; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.operation.GpsImportService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; @@ -374,9 +373,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { // ouverture de la base locale openSource(source); - ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(source); - - GpsImportService service = serviceFactory.getService(GpsImportService.class); + GpsImportService service = ObserveContext.getService(source, GpsImportService.class); // récuperation de la marée ouverte openTripSeine = service.getOpenTrip(); @@ -522,8 +519,7 @@ public class ImportGPSUIHandler extends AdminTabUIHandler { int[] selectedIndex = model.getImportGPSModel().getImportGPSSelectedIndex(); - ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(source); - GpsImportService service = serviceFactory.getService(GpsImportService.class); + GpsImportService service = ObserveContext.getService(source, GpsImportService.class); service.applyPoints(data, selectedIndex, this); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java index 3951628..eefb8fa 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/save/SaveLocalUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.admin.save; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.operation.SynchronizeService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; @@ -185,22 +184,13 @@ public class SaveLocalUIHandler extends AdminTabUIHandler { } - ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(referentielSource); - try { + SynchronizeService service = ObserveContext.getService(referentielSource, SynchronizeService.class); - SynchronizeService service = serviceFactory.getService(SynchronizeService.class); + DataSource targetSource = stepModel.getSource(); - DataSource targetSource = stepModel.getSource(); + DiffState.DiffStateMap diff = stepModel.getDiff(); - DiffState.DiffStateMap diff = stepModel.getDiff(); - - service.saveReferentiel(targetSource, diff, stepModel.getReplaceActions(), this); - - } finally { - - serviceFactory.close(); - - } + service.saveReferentiel(targetSource, diff, stepModel.getReplaceActions(), this); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java index 2e1a8bf..96863b8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeModel.java @@ -21,10 +21,7 @@ */ package fr.ird.observe.ui.admin.synchronize; -import com.google.common.base.Preconditions; -import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; import fr.ird.observe.ui.admin.AdminActionModel; import fr.ird.observe.ui.admin.AdminStep; @@ -62,10 +59,6 @@ public class SynchronizeModel extends AdminActionModel { /** temporary source where to make operations. */ protected DataSource tmpSource; - protected ObserveServiceFactory serviceFactory; - - protected ObserveServiceFactory tmpServiceFactory; - public SynchronizeModel() { super(AdminStep.SYNCHRONIZE); } @@ -98,10 +91,6 @@ public class SynchronizeModel extends AdminActionModel { } public void setSource(DataSource source) { - if (serviceFactory != null) { - serviceFactory.close(); - serviceFactory = null; - } this.source = source; } @@ -118,33 +107,9 @@ public class SynchronizeModel extends AdminActionModel { } public void setTmpSource(DataSource tmpSource) { - if (tmpServiceFactory != null) { - tmpServiceFactory.close(); - tmpServiceFactory = null; - } this.tmpSource = tmpSource; } - public ObserveServiceFactory getServiceFactory() { - - if (serviceFactory == null) { - Preconditions.checkNotNull(source, "Can't create source service factory if source is null"); - serviceFactory = ObserveContext.newServiceFactory(source); - } - return serviceFactory; - - } - - public ObserveServiceFactory getTmpServiceFactory() { - - if (tmpServiceFactory == null) { - Preconditions.checkNotNull(source, "Can't create source service factory if tmpSource is null"); - tmpServiceFactory = ObserveContext.newServiceFactory(tmpSource); - } - return tmpServiceFactory; - - } - @Override public void destroy() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java index 17ccb98..0f5f8f8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java @@ -26,7 +26,6 @@ import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.Entities; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; import fr.ird.observe.services.operation.SynchronizeService; @@ -345,8 +344,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { openSource(source); openSource(centralSource); - ObserveServiceFactory sourceServiceFactory = getStepModel().getServiceFactory(); - SynchronizeService synchronizeService = sourceServiceFactory.getService(SynchronizeService.class); + SynchronizeService synchronizeService = ObserveContext.getService(source, SynchronizeService.class); // construction du différentiel sendMessage(t("observe.message.synchro.build.diff", centralSource.getLabel())); @@ -411,8 +409,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { getStepModel().setTmpSource(tmpSource); openSource(tmpSource); - ObserveServiceFactory tmpServiceFactory = getStepModel().getTmpServiceFactory(); - ReplicationService service = tmpServiceFactory.getService(ReplicationService.class); + ReplicationService service = ObserveContext.getService(tmpSource, ReplicationService.class); // duplication du referentiel à jour vers la base temporaire service.replicateReferentiel(centralSource); @@ -527,9 +524,7 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { public List<?> getEntityListFromSynchroDB(Class<?> type, boolean removeObsoletes) { - ObserveServiceFactory tmpServiceFactory = getStepModel().getTmpServiceFactory(); - - ReferentialService service = tmpServiceFactory.getService(ReferentialService.class); + ReferentialService service = ObserveContext.getService(getStepModel().getTmpSource(), ReferentialService.class); ObserveEntityEnum constant = ObserveEntityEnum.valueOf(type); List<?> list = service.getList(constant.getContract()); @@ -567,9 +562,8 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { DataSource tmpSource = stepModel.getTmpSource(); - ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(tmpSource); try { - ReferentialService service = serviceFactory.getService(ReferentialService.class); + ReferentialService service = ObserveContext.getService(tmpSource, ReferentialService.class); service.replaceObsoleteReference(action); @@ -606,10 +600,6 @@ public class SynchronizeUIHandler extends AdminTabUIHandler { model.setStepState(onError(e)); - } finally { - - serviceFactory.close(); - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java index f8abf5c..7255057 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java @@ -405,11 +405,9 @@ public class ValidateUIHandler extends AdminTabUIHandler { context.setDataSource(model.getLocalSource()); context.setDataContext(model.getDataContext()); - ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(source); -// TopiaContext ctxt = beginTransaction(source, "launchValidation"); try { - ValidationService service = serviceFactory.getService(ValidationService.class); + ValidationService service = ObserveContext.getService(source, ValidationService.class); service.validate(this, detector, dataModel); @@ -429,8 +427,6 @@ public class ValidateUIHandler extends AdminTabUIHandler { } finally { - serviceFactory.close(); - context.setDataSource(null); SortedMap<TopiaEntityRef, List<SimpleBeanValidatorMessage<?>>> refs = detector.getRefs(); stepModel.setMessages(refs); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java index 5a158d1..b873656 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java @@ -44,7 +44,6 @@ import fr.ird.observe.db.util.PGInstall; import fr.ird.observe.db.util.SecurityModel; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.ObserveMainUI; @@ -168,6 +167,7 @@ public class StorageUIHandler { // on écoute les changements d'étapes model.addPropertyChangeListener(StorageUIModel.STEP_PROPERTY_NAME, new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { StorageUIModel model = (StorageUIModel) evt.getSource(); @@ -631,19 +631,9 @@ public class StorageUIHandler { tempStorage.doOpen(); - ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(tempStorage); - - try { - - ReplicationService replicationService = serviceFactory.getService(ReplicationService.class); - replicationService.replicateReferentiel(service); - replicationService.replicateAllData(service); - - } finally { - - serviceFactory.close(); - - } + ReplicationService replicationService = ObserveContext.getService(tempStorage, ReplicationService.class); + replicationService.replicateReferentiel(service); + replicationService.replicateAllData(service); tempStorage.storeDB(dst); @@ -678,7 +668,7 @@ public class StorageUIHandler { * * @param service le service locale qui encapsule la base locale * @param dst le fichier de sauvegarde - * @param trips les marees a exporter (si {@code null} on exporte tout) + * @param trips les marees a exporter (si {@code null} on exporte tout) */ public void backupLocalDatabase(DataSource service, File dst, Set<String> trips) { @@ -719,19 +709,9 @@ public class StorageUIHandler { tempStorage.doOpen(); - ObserveServiceFactory serviceFactory = ObserveContext.newServiceFactory(tempStorage); - - try { - - ReplicationService replicationService = serviceFactory.getService(ReplicationService.class); - replicationService.replicateReferentiel(service); - replicationService.replicateData(service, tripIds); - - } finally { - - serviceFactory.close(); - - } + ReplicationService replicationService = ObserveContext.getService(tempStorage, ReplicationService.class); + replicationService.replicateReferentiel(service); + replicationService.replicateData(service, tripIds); tempStorage.storeDB(dst); @@ -1199,8 +1179,7 @@ public class StorageUIHandler { dataModel.setUseData(true); dataModel.setUseOpenData(true); dataModel.setUseReferentiel(false); - ObserveServiceFactory services = ObserveContext.newServiceFactory(source); - DataSelectionModel.populate(dataModel,services); + DataSelectionModel.populate(dataModel, ObserveContext.get().getServices(), source); // positionnement du model de selection de données // dans le model du wizard diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java index fba1ddb..5af9513 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/AbstractObserveTreeCellRenderer.java @@ -112,7 +112,7 @@ public abstract class AbstractObserveTreeCellRenderer extends AbstractNavTreeCel if (provider == null) { DataSource source = ObserveContext.get().getDataSource(); if (source != null) { - provider = new ObserveDataProvider(ObserveContext.get().getServices()); + provider = new ObserveDataProvider(source); setDataProvider(provider); } } @@ -291,7 +291,7 @@ public abstract class AbstractObserveTreeCellRenderer extends AbstractNavTreeCel if (node instanceof EntityNodeSupport) { EntityNodeSupport entityNodeSupport = (EntityNodeSupport) node; - TopiaEntity entity = entityNodeSupport.getEntity(); + TopiaEntity entity = entityNodeSupport.loadEntity(); Preconditions.checkNotNull(entity, "L'entité doit être chargée dans le noeud: " + node); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java index c1b7181..60aab80 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivityLonglineNode.java @@ -22,9 +22,10 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.longline.ActivityLonglineService; import fr.ird.observe.ui.tree.loadors.ActivityLonglineNodeChildLoador; @@ -43,8 +44,8 @@ public class ActivityLonglineNode extends EntityNodeSupport<ActivityLongline> { } @Override - protected ActivityLongline getEntity(ObserveServiceFactory services) throws DataSourceException { - ActivityLonglineService service = services.getService(ActivityLonglineService.class); + protected ActivityLongline loadEntity(DataSource dataSource) throws DataSourceException { + ActivityLonglineService service = ObserveContext.getService(dataSource, ActivityLonglineService.class); return service.getActivityLonglineStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java index 90949a4..55e6067 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ActivitySeineNode.java @@ -22,9 +22,10 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.seine.ActivitySeineService; import fr.ird.observe.ui.tree.loadors.ActivitySeineNodeChildLoador; @@ -43,8 +44,8 @@ public class ActivitySeineNode extends EntityNodeSupport<ActivitySeine> { } @Override - protected ActivitySeine getEntity(ObserveServiceFactory services) throws DataSourceException { - ActivitySeineService service = services.getService(ActivitySeineService.class); + protected ActivitySeine loadEntity(DataSource dataSource) throws DataSourceException { + ActivitySeineService service = ObserveContext.getService(dataSource, ActivitySeineService.class); return service.getActivitySeineStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java index 01bcd73..82fde6d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/EntityNodeSupport.java @@ -22,9 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.OpenableEntity; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.tree.loadors.AbstractNodeChildLoador; import jaxx.runtime.swing.nav.NavBridge; import jaxx.runtime.swing.nav.NavDataProvider; @@ -59,7 +59,7 @@ public abstract class EntityNodeSupport<E extends TopiaEntity> extends ObserveNo private boolean reloadEntity; - protected abstract E getEntity(ObserveServiceFactory services) throws DataSourceException; + protected abstract E loadEntity(DataSource dataSource) throws DataSourceException; protected EntityNodeSupport(ObserveDataProvider dataProvider, Class<E> internalClass, E entity) { this(dataProvider, internalClass, entity, null); @@ -118,7 +118,7 @@ public abstract class EntityNodeSupport<E extends TopiaEntity> extends ObserveNo } - public E getEntity() { + public E loadEntity() { return entity; } @@ -144,7 +144,7 @@ public abstract class EntityNodeSupport<E extends TopiaEntity> extends ObserveNo } try { - entity = getEntity(oProvider.getServices()); + entity = loadEntity(oProvider.getDataSource()); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java index 3471e0b..f3c773f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/FloatingObjectSeineNode.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.seine.FloatingObjectService; import fr.ird.observe.ui.tree.loadors.FloatingObjectNodeChildLoador; @@ -42,8 +43,8 @@ public class FloatingObjectSeineNode extends EntityNodeSupport<FloatingObject> { } @Override - protected FloatingObject getEntity(ObserveServiceFactory services) { - FloatingObjectService service = services.getService(FloatingObjectService.class); + protected FloatingObject loadEntity(DataSource dataSource) { + FloatingObjectService service = ObserveContext.getService(dataSource, FloatingObjectService.class); return service.getFloatinObjectStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java index 53839b4..958be96 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java @@ -21,9 +21,9 @@ */ package fr.ird.observe.ui.tree; +import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.services.ObserveService; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.model.DataSelectionModel; import jaxx.runtime.swing.nav.NavDataProvider; import org.apache.commons.logging.Log; @@ -40,14 +40,14 @@ public class ObserveDataProvider implements NavDataProvider { /** Logger */ static private final Log log = LogFactory.getLog(ObserveDataProvider.class); - protected final ObserveServiceFactory services; + protected final DataSource dataSource; protected DataSelectionModel selectionModel; private boolean creating; - public ObserveDataProvider(ObserveServiceFactory services) { - this.services = services; + public ObserveDataProvider(DataSource dataSource) { + this.dataSource = dataSource; } public void setSelectionModel(DataSelectionModel selectionModel) { @@ -59,7 +59,6 @@ public class ObserveDataProvider implements NavDataProvider { @Override public boolean isEnabled() { - DataSource dataSource = services.getDataSource(); return dataSource != null && dataSource.isOpen() || selectionModel != null; } @@ -75,15 +74,11 @@ public class ObserveDataProvider implements NavDataProvider { this.creating = creating; } - public ObserveServiceFactory getServices() { - return services; - } - public <S extends ObserveService> S getService(Class<S> serviceType) { - return services.getService(serviceType); + return ObserveContext.getService(dataSource, serviceType); } public DataSource getDataSource() { - return services.getDataSource(); + return dataSource; } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java index 765efa8..f9f1baf 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java @@ -36,7 +36,6 @@ import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.ObserveMainUI; @@ -114,7 +113,7 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { DataSource source = ObserveContext.get().getDataSource(); if (source != null) { - provider = new ObserveDataProvider(ObserveContext.get().getServices()); + provider = new ObserveDataProvider(source); setDataProvider(provider); } } @@ -515,8 +514,7 @@ public class ObserveTreeHelper extends NavTreeHelper<ObserveNode> { void setDataSource(DataSource source) { ObserveDataProvider provider = null; if (source != null) { - ObserveServiceFactory services = ObserveContext.newServiceFactory(source); - provider = new ObserveDataProvider(services); + provider = new ObserveDataProvider(source); } setDataProvider(provider); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java index c49db36..34a9a97 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramLonglineNode.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.tree.loadors.ProgramLonglineNodeChildLoador; @@ -43,8 +44,8 @@ public class ProgramLonglineNode extends EntityNodeSupport<Program> { } @Override - protected Program getEntity(ObserveServiceFactory services) { - ReferentialService service = services.getService(ReferentialService.class); + protected Program loadEntity(DataSource dataSource) { + ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); return service.getProgramStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java index 5eb32b3..40840ab 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ProgramSeineNode.java @@ -22,9 +22,10 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.tree.loadors.ProgramSeineNodeChildLoador; @@ -43,8 +44,8 @@ public class ProgramSeineNode extends EntityNodeSupport<Program> { } @Override - protected Program getEntity(ObserveServiceFactory services) throws DataSourceException { - ReferentialService service = services.getService(ReferentialService.class); + protected Program loadEntity(DataSource dataSource) throws DataSourceException { + ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); return service.getProgramStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java index 4c76293..ddb031c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/RouteSeineNode.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.seine.RouteService; /** @@ -41,8 +42,8 @@ public class RouteSeineNode extends EntityNodeSupport<Route> { } @Override - protected Route getEntity(ObserveServiceFactory services) { - RouteService service = services.getService(RouteService.class); + protected Route loadEntity(DataSource dataSource) { + RouteService service = ObserveContext.getService(dataSource, RouteService.class); return service.getRouteStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java index 570f852..02bbf58 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetLonglineNode.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.ui.tree.loadors.SetLonglineNodeChildLoador; @@ -42,8 +43,8 @@ public class SetLonglineNode extends EntityNodeSupport<SetLongline> { } @Override - protected SetLongline getEntity(ObserveServiceFactory services) { - SetLonglineService service = services.getService(SetLonglineService.class); + protected SetLongline loadEntity(DataSource dataSource) { + SetLonglineService service = ObserveContext.getService(dataSource, SetLonglineService.class); return service.loadForDisplay(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java index 25df6af..43ba7ba 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/SetSeineNode.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.seine.SetSeineService; import fr.ird.observe.ui.tree.loadors.SetSeineNodeChildLoador; @@ -42,8 +43,8 @@ public class SetSeineNode extends EntityNodeSupport<SetSeine> { } @Override - protected SetSeine getEntity(ObserveServiceFactory services) { - SetSeineService service = services.getService(SetSeineService.class); + protected SetSeine loadEntity(DataSource dataSource) { + SetSeineService service = ObserveContext.getService(dataSource, SetSeineService.class); return service.loadSet(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java index 22469d3..a9f1313 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripLonglineNode.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.longline.TripLonglineService; /** @@ -41,8 +42,8 @@ public class TripLonglineNode extends EntityNodeSupport<TripLongline> { } @Override - protected TripLongline getEntity(ObserveServiceFactory services) { - TripLonglineService service = services.getService(TripLonglineService.class); + protected TripLongline loadEntity(DataSource dataSource) { + TripLonglineService service = ObserveContext.getService(dataSource, TripLonglineService.class); return service.getTripLonglineStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java index 101b50a..ff853c4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/TripSeineNode.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.tree; * #L% */ +import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.seine.TripSeineService; /** @@ -41,8 +42,8 @@ public class TripSeineNode extends EntityNodeSupport<TripSeine> { } @Override - protected TripSeine getEntity(ObserveServiceFactory services) { - TripSeineService service = services.getService(TripSeineService.class); + protected TripSeine loadEntity(DataSource dataSource) { + TripSeineService service = ObserveContext.getService(dataSource, TripSeineService.class); return service.getTripSeineStub(id); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java index 4e70b81..2649852 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivityLonglineNodeChildLoador.java @@ -70,7 +70,7 @@ public class ActivityLonglineNodeChildLoador extends AbstractNodeChildLoador<Str { - ActivityLongline activity = ((ActivityLonglineNode) parentNode).getEntity(); + ActivityLongline activity = ((ActivityLonglineNode) parentNode).loadEntity(); SetLongline setLongline = activity.getSetLongline(); if (setLongline != null) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java index 3eb0898..b709497 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ActivitySeineNodeChildLoador.java @@ -74,7 +74,7 @@ public class ActivitySeineNodeChildLoador extends AbstractNodeChildLoador<Floati parentNode.add(child); - ActivitySeine activitySeine = ((ActivitySeineNode) parentNode).getEntity(); + ActivitySeine activitySeine = ((ActivitySeineNode) parentNode).loadEntity(); SetSeine set = activitySeine.getSetSeine(); if (set != null) { diff --git a/pom.xml b/pom.xml index 5971a43..f3e32b7 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,7 @@ <modules> <module>observe-entities</module> <module>observe-business</module> + <module>observe-services-api</module> <module>observe-services</module> <module>observe-validation</module> <module>observe-swing</module> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit e31061633ca6b01bcf8a6b72cbcb7022ea035023 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 09:33:39 2015 +0200 add missing files + fix API --- observe-swing/pom.xml | 6 ++ .../ird/observe/ui/content/ContentUIHandler.java | 2 +- .../observe/ui/content/ContentUIInitializer.java | 86 ++++++++++++---------- .../LonglineDetailCompositionUIHandler.java | 2 +- .../LonglineDetailCompositionUIInitializer.java | 6 +- .../ui/content/ref/ContentReferenceUIHandler.java | 2 +- .../ui/content/table/ContentTableUIHandler.java | 2 +- .../content/table/ContentTableUIInitializer.java | 8 +- .../impl/longline/CatchLonglineUIHandler.java | 2 +- 9 files changed, 66 insertions(+), 50 deletions(-) diff --git a/observe-swing/pom.xml b/observe-swing/pom.xml index 652d1ca..7745ab5 100644 --- a/observe-swing/pom.xml +++ b/observe-swing/pom.xml @@ -92,8 +92,14 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>observe-services-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>observe-services</artifactId> <version>${project.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>${project.groupId}</groupId> diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 23e3d01..68732e2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -316,7 +316,7 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { public void initUI() throws Exception { ContentUIInitializer<E, ObserveContentUI<E>> uiInitializer = new ContentUIInitializer<E, ObserveContentUI<E>>(ui); - uiInitializer.initUI(ObserveContext.get().getServices()); + uiInitializer.initUI(getDataSource()); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java index 49ed247..ac16b84 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java @@ -26,11 +26,11 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; +import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.entities.constants.ReferenceStatus; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.ReferenceEntity; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.actions.shared.AbstractUIAction; @@ -133,8 +133,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte this.ui = ui; } - protected static void attachTopiaContext(ObserveServiceFactory serviceFactory, TopiaEntityAbstract entity) { - DBHelper.attachTopiaContext(serviceFactory.getDataSource().getRootCtxt(), entity); + protected static void attachTopiaContext(DataSource dataSource, TopiaEntityAbstract entity) { + DBHelper.attachTopiaContext(dataSource.getRootCtxt(), entity); } public static TableCellEditor newFloatColumnEditor(JTable table) { @@ -196,7 +196,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } - public void initUI(ObserveServiceFactory serviceFactory) throws Exception { + public void initUI(DataSource dataSource) throws Exception { if (log.isDebugEnabled()) { log.debug("ui " + getClass()); @@ -206,7 +206,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte // initialisation des éditeurs - init(serviceFactory); + init(dataSource); Set<String> doNotBlockComponentIds = new HashSet<String>(); @@ -220,7 +220,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } if (o instanceof TopiaEntityAbstract) { - init(serviceFactory, (TopiaEntityAbstract) o); + init(dataSource, (TopiaEntityAbstract) o); continue; } @@ -244,17 +244,17 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } if (o instanceof BeanComboBox<?>) { - init(serviceFactory, (BeanComboBox<?>) o); + init(dataSource, (BeanComboBox<?>) o); continue; } if (o instanceof BeanListHeader<?>) { - init(serviceFactory, decoratorService, (BeanListHeader<?>) o); + init(dataSource, decoratorService, (BeanListHeader<?>) o); continue; } if (o instanceof FilterableDoubleList<?>) { - init(serviceFactory, (FilterableDoubleList<?>) o); + init(dataSource, (FilterableDoubleList<?>) o); continue; } @@ -322,13 +322,13 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte ); } - protected void init(ObserveServiceFactory serviceFactory) { + protected void init(DataSource dataSource) { - init(serviceFactory, (TopiaEntityAbstract) getBean()); + init(dataSource, (TopiaEntityAbstract) getBean()); } - protected void init(ObserveServiceFactory serviceFactory, TopiaEntityAbstract bean) { + protected void init(DataSource dataSource, TopiaEntityAbstract bean) { if (bean == null) { return; @@ -336,7 +336,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte if (log.isDebugEnabled()) { log.debug("init entity " + bean.getClass()); } - attachTopiaContext(serviceFactory, bean); + attachTopiaContext(dataSource, bean); } protected void init(ActionMap actionMap, AbstractButton editor) { @@ -347,6 +347,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte final String propertyName = (String) editor.getClientProperty(CLIENT_PROPERTY_RESET_PROPERTY_NAME); if (propertyName != null) { editor.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { JavaBeanObjectUtil.setProperty(getBean(), propertyName, null); @@ -383,18 +384,18 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } @SuppressWarnings("unchecked") - protected void init(ObserveServiceFactory serviceFactory, BeanComboBox beanComboBox) { + protected void init(DataSource dataSource, BeanComboBox beanComboBox) { Class<ReferenceEntity> klass = (Class<ReferenceEntity>) beanComboBox.getHandler().getBeanType(); if (log.isDebugEnabled()) { log.debug("init combobox for " + klass); } beanComboBox.setI18nPrefix("observe.common."); beanComboBox.setMinimumSize(new Dimension(0, 24)); - prepareBeanComboBox(serviceFactory, klass, beanComboBox); + prepareBeanComboBox(dataSource, klass, beanComboBox); } @SuppressWarnings("unchecked") - protected void init(ObserveServiceFactory serviceFactory, DecoratorService decoratorService, BeanListHeader beanList) { + protected void init(DataSource dataSource, DecoratorService decoratorService, BeanListHeader beanList) { beanList.setI18nPrefix("observe.common."); @@ -402,7 +403,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte log.info("init list for " + beanList.getBeanType()); } - prepareEntityList(serviceFactory, beanList.getBeanType(), beanList); + prepareEntityList(dataSource, beanList.getBeanType(), beanList); JList jlist = beanList.getList(); @@ -428,7 +429,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } @SuppressWarnings("unchecked") - protected void init(ObserveServiceFactory serviceFactory, FilterableDoubleList beanList) throws DataSourceException { + protected void init(DataSource dataSource, FilterableDoubleList beanList) throws DataSourceException { beanList.setI18nPrefix("observe.common."); @@ -436,7 +437,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte log.info("init list for " + beanList.getBeanType()); } - prepareEntityList(serviceFactory, beanList.getBeanType(), beanList); + prepareEntityList(dataSource, beanList.getBeanType(), beanList); } @@ -484,6 +485,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte final String propertyName = (String) editor.getClientProperty(CLIENT_PROPERTY_PROPERTY_NAME); if (propertyName != null) { editor.addKeyListener(new KeyAdapter() { + @Override public void keyReleased(KeyEvent e) { JTextField source = (JTextField) e.getSource(); @@ -499,6 +501,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte final String propertyName = (String) editor.getClientProperty(CLIENT_PROPERTY_PROPERTY_NAME); if (propertyName != null) { editor.addKeyListener(new KeyAdapter() { + @Override public void keyReleased(KeyEvent e) { JTextArea source = (JTextArea) e.getSource(); @@ -516,6 +519,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte final String propertyName = (String) editor.getClientProperty(CLIENT_PROPERTY_PROPERTY_NAME); if (propertyName != null) { editor.addItemListener(new ItemListener() { + @Override public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { @@ -552,6 +556,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte final String propertyName = (String) editor.getClientProperty(CLIENT_PROPERTY_PROPERTY_NAME); if (propertyName != null) { editor.addItemListener(new ItemListener() { + @Override public void itemStateChanged(ItemEvent event) { Boolean newValue = ((JCheckBox) event.getSource()).isSelected(); @@ -576,6 +581,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte final String propertyName = (String) picker.getClientProperty(CLIENT_PROPERTY_PROPERTY_NAME); if (propertyName != null) { picker.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { JXDatePicker source = (JXDatePicker) e.getSource(); @@ -594,9 +600,11 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte protected void addAutoSelectOnFocus(JTextField jTextField) { jTextField.addFocusListener(new FocusAdapter() { + @Override public void focusGained(final FocusEvent e) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { JTextField source = (JTextField) e.getSource(); @@ -628,14 +636,14 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param serviceFactory le service de persistance à utiliser pour - * récupérer les entités - * @param entityClass le type de l'entité - * @param list le component graphique à initialiser + * @param dataSource le service de persistance à utiliser pour + * récupérer les entités + * @param entityClass le type de l'entité + * @param list le component graphique à initialiser * @since 1.5 */ @SuppressWarnings("unchecked") - protected <E extends TopiaEntity> void prepareEntityList(ObserveServiceFactory serviceFactory, Class<E> entityClass, FilterableDoubleList<E> list) { + protected <E extends TopiaEntity> void prepareEntityList(DataSource dataSource, Class<E> entityClass, FilterableDoubleList<E> list) { ObserveContext context = ObserveContext.get(); @@ -651,7 +659,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte if (ReferenceEntity.class.isAssignableFrom(entityClass)) { Predicate<E> predicate = (Predicate<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - ReferentialService service = serviceFactory.getService(ReferentialService.class); + ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); data = service.getList(entityClass, predicate); } else { @@ -686,14 +694,14 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param serviceFactory le service de persistance à utiliser pour - * récupérer les entités - * @param entityClass le type de l'entité - * @param list le component graphique à initialiser + * @param dataSource le service de persistance à utiliser pour + * récupérer les entités + * @param entityClass le type de l'entité + * @param list le component graphique à initialiser * @since 1.5 */ @SuppressWarnings("unchecked") - protected <E extends TopiaEntity> void prepareEntityList(ObserveServiceFactory serviceFactory, Class<E> entityClass, BeanListHeader<E> list) { + protected <E extends TopiaEntity> void prepareEntityList(DataSource dataSource, Class<E> entityClass, BeanListHeader<E> list) { ObserveContext context = ObserveContext.get(); @@ -709,7 +717,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte if (ReferenceEntity.class.isAssignableFrom(entityClass)) { Predicate<E> predicate = (Predicate<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - ReferentialService service = serviceFactory.getService(ReferentialService.class); + ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); data = service.getList(entityClass, predicate); } else { @@ -742,14 +750,14 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte * Prépare un component de choix d'entités pour un type d'entité donné et * pour un service de persistance donné. * - * @param <E> le type de l'entité - * @param serviceFactory le service de persistance à utiliser pour récupérer - * les entités - * @param entityClass le type de l'entité - * @param comboBox le component graphique à initialiser + * @param <E> le type de l'entité + * @param dataSource le service de persistance à utiliser pour récupérer + * les entités + * @param entityClass le type de l'entité + * @param comboBox le component graphique à initialiser */ @SuppressWarnings("unchecked") - protected <E extends TopiaEntity> void prepareBeanComboBox(ObserveServiceFactory serviceFactory, Class<E> entityClass, BeanComboBox<E> comboBox) { + protected <E extends TopiaEntity> void prepareBeanComboBox(DataSource dataSource, Class<E> entityClass, BeanComboBox<E> comboBox) { ObserveContext context = ObserveContext.get(); @@ -771,7 +779,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte // get complete data list from service Predicate<E> predicate = (Predicate<E>) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - ReferentialService service = serviceFactory.getService(ReferentialService.class); + ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); data = service.getList(entityClass, predicate); } @@ -796,6 +804,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte final ListCellRenderer renderer = comboBox.getCombobox().getRenderer(); ListCellRenderer toolTipRenderer = new ListCellRenderer() { + @Override public Component getListCellRendererComponent(JList list, Object value, @@ -827,6 +836,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte // listen on cache modification BeanComboBoxPropertyChangeListener listener = new BeanComboBoxPropertyChangeListener(entityClass, comboBox) { + @Override public void propertyChange(PropertyChangeEvent evt) { if (log.isDebugEnabled()) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java index 641ebf5..9433d66 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java @@ -314,7 +314,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong this.branchlineDecorator = getDecoratorService().getDecoratorByType(Branchline.class); LonglineDetailCompositionUIInitializer uiInitializer = new LonglineDetailCompositionUIInitializer(getUi()); - uiInitializer.initUI(ObserveContext.get().getServices()); + uiInitializer.initUI(getDataSource()); LonglineDetailCompositionUI ui1 = getUi(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java index 9e40047..1dec3b2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java @@ -23,9 +23,9 @@ package fr.ird.observe.ui.content.impl.longline; */ import fr.ird.observe.DecoratorService; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.longline.SectionTemplate; import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentUIInitializer; import fr.ird.observe.ui.util.table.AutotSelectRowAndShowPopupActionSupport; @@ -58,8 +58,8 @@ public class LonglineDetailCompositionUIInitializer extends ContentUIInitializer } @Override - public void initUI(ObserveServiceFactory serviceFactory) throws Exception { - super.initUI(serviceFactory); + public void initUI(DataSource dataSource) throws Exception { + super.initUI(dataSource); LonglineDetailCompositionUIModel model = ui.getModel(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java index 7e64197..c30a337 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java @@ -379,7 +379,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten public void initUI() throws Exception { ReferentialContentUIInitializer<E, ContentReferenceUI<E>> uiInitializer = new ReferentialContentUIInitializer<E, ContentReferenceUI<E>>(getUi()); - uiInitializer.initUI(ObserveContext.get().getServices()); + uiInitializer.initUI(getDataSource()); ContentReferenceUI<E> ui = getUi(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index f72ccdf..4884b24 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -166,7 +166,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top public void initUI() throws Exception { ContentTableUIInitializer<E, D, ObserveContentTableUI<E, D>> uiInitializer = createInitializer(); - uiInitializer.initUI(ObserveContext.get().getServices()); + uiInitializer.initUI(getDataSource()); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java index 879e5e0..51d8a56 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIInitializer.java @@ -22,8 +22,8 @@ package fr.ird.observe.ui.content.table; * #L% */ +import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.ui.content.ContentUIInitializer; import fr.ird.observe.ui.util.BooleanEditor; import jaxx.runtime.SwingUtil; @@ -84,11 +84,11 @@ public class ContentTableUIInitializer<E extends TopiaEntity, D extends TopiaEnt } @Override - public void initUI(ObserveServiceFactory serviceFactory) throws Exception { + public void initUI(DataSource dataSource) throws Exception { - attachTopiaContext(serviceFactory, (TopiaEntityAbstract) getTableEditBean()); + attachTopiaContext(dataSource, (TopiaEntityAbstract) getTableEditBean()); - super.initUI(serviceFactory); + super.initUI(dataSource); ContentTableModel<?, ?> tableModel = ui.getTableModel(); ui.setContextValue(tableModel); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 62818c6..b98435a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -169,7 +169,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } CatchLonglineContentTableUIInitializer uiInitializer = new CatchLonglineContentTableUIInitializer(getUi()); - uiInitializer.initUI(ObserveContext.get().getServices()); + uiInitializer.initUI(getDataSource()); getModel().addPropertyChangeListener(CatchLonglineUIModel.PROPERTY_SHOW_INDIVIDUAL_TABS, new PropertyChangeListener() { @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit dcdc613b854f3dbc2e45c2bc4def6368bdd7d0d0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 09:38:28 2015 +0200 add missing files + fix API --- observe-services-api/LICENSE.txt | 0 observe-services-api/README.txt | 0 .../observe/services/ObserveServiceFactory.java | 166 --------------------- .../ref/ReferentialContentUIInitializer.java | 22 ++- 4 files changed, 9 insertions(+), 179 deletions(-) diff --git a/observe-services-api/LICENSE.txt b/observe-services-api/LICENSE.txt new file mode 100644 index 0000000..e69de29 diff --git a/observe-services-api/README.txt b/observe-services-api/README.txt new file mode 100644 index 0000000..e69de29 diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index 951d040..345052d 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -152,19 +152,6 @@ public class ObserveServiceFactory implements Closeable { } } -// public <S extends ObserveService> S getService(Class<S> serviceType) { -// -// Preconditions.checkNotNull(serviceType, "serviceType can't be null."); -// Preconditions.checkNotNull(dataSource, "dataSource can't be null."); -// -// try { -// S s = (S) services.get(serviceType); -// return s; -// } catch (ExecutionException e) { -// throw new ObserveTechnicalException("Could not get service: " + serviceType, e); -// } -// } - public void unregisterDataSource(DataSource dataSource) { //FIXME Remove all service using this dataSource } @@ -186,157 +173,4 @@ public class ObserveServiceFactory implements Closeable { } -// public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { -// -// Preconditions.checkNotNull(serviceType, "serviceType can't be null"); -// Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); -// Preconditions.checkNotNull(applicationContext, "applicationContext can't be null"); -// -// ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); -// -// S service = newProxyService(serviceType, serviceContext); -// return service; -// -// } -// -// public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveServiceContext serviceContext) { -// -// Preconditions.checkNotNull(serviceType, "serviceType can't be null"); -// Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); -// Preconditions.checkNotNull(serviceContext, "serviceContext can't be null"); -// -// S service = newService(serviceType, serviceContext); -// S proxyService = addProxyService(serviceType, service, serviceContext); -// return proxyService; -// -// } -// -// public static <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { -// -// Class<S> serviceImpl; -// try { -// //FIXME Cela devrait dépendre de la datasource ? -// serviceImpl = (Class<S>) Class.forName(serviceType.getName() + "Impl"); -// } catch (ClassNotFoundException e) { -// throw new IllegalStateException("Could not find implementation class for " + serviceType); -// } -// -// try { -// -// // Instanciate concrete service -// S service = ConstructorUtils.invokeConstructor(serviceImpl); -// service.setServiceContext(serviceContext); -// -// return service; -// -// } catch (Exception e) { -// throw new ObserveTechnicalException("Could not create service: " + serviceType, e); -// } -// -// } -// -// protected <S extends ObserveService> S addProxyService(Class<S> serviceType, S service, ObserveServiceContext serviceContext) { -// -// // Instanciate transactional proxied service -// ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); -// S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); -// -// return proxyService; -// -// } -// -// protected static class ServiceInvocationHandler implements InvocationHandler { -// -// private final ObserveServiceContext serviceContext; -// -// private final ObserveService target; -// -// private final Set<String> methodNamesToByPass; -// -// protected ServiceInvocationHandler(ObserveServiceContext serviceContext, ObserveService target) { -// this.serviceContext = serviceContext; -// this.target = target; -// this.methodNamesToByPass = Sets.newHashSet( -// "equals", -// "hashCode", -// "finalize", -// "toString", -// "clone", -// "getClass" -// ); -// } -// -// @Override -// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { -// -// Object result; -// -// if (methodNamesToByPass.contains(method.getName()) || method.isAnnotationPresent(NoTransaction.class)) { -// -// result = invokeMethod(method, args); -// -// } else { -// -// result = invokeMethodWithTransaction(method, args); -// -// } -// -// return result; -// -// } -// -// protected Object invokeMethod(Method method, Object... args) throws Throwable { -// try { -// Object result = method.invoke(target, args); -// return result; -// } catch (InvocationTargetException e) { -// throw e.getCause(); -// } -// } -// -// -// protected Object invokeMethodWithTransaction(Method method, Object... args) throws Throwable { -// -// String methodName = method.getName(); -// -// DataSource source = serviceContext.getDataSource(); -// -// TopiaContext tx = source.beginTransaction(methodName); -// -// try { -// -// serviceContext.setTransaction(tx); -// -// Object invoke = invokeMethod(method, args); -// -// if (method.isAnnotationPresent(Commit.class)) { -// -// // do commit -// source.commitTransaction(tx, methodName); -// -// } -// -// return invoke; -// -// } finally { -// -// try { -// -// // always rollback transaction to avoid dirty transactions -// source.rollbackTransaction(tx, methodName); -// -// -// } finally { -// -// serviceContext.setTransaction(null); -// source.closeTransaction(tx, methodName); -// -// } -// -// } -// -// } -// -// } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java index 3ac17f4..bd4aea1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java @@ -24,9 +24,8 @@ package fr.ird.observe.ui.content.ref; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.referentiel.ReferenceEntity; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentUIInitializer; import jaxx.runtime.swing.editor.bean.BeanListHeader; @@ -60,15 +59,12 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param serviceFactory le service de persistance à utiliser pour - * récupérer les entités - * @param entityClass le type de l'entité - * @param list le component graphique à initialiser - * @throws DataSourceException si un problème lors de la récupération - * des entités + * @param dataSource la data source + * @param entityClass le type de l'entité + * @param list le component graphique à initialiser * @since 1.5 */ - public static <E extends ReferenceEntity> void prepareMainEntityList(ObserveServiceFactory serviceFactory, + public static <E extends ReferenceEntity> void prepareMainEntityList(DataSource dataSource, Class<E> entityClass, BeanListHeader<E> list) { @@ -81,7 +77,7 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten } list.putClientProperty("decorator", decorator); - ReferentialService service = serviceFactory.getService(ReferentialService.class); + ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); List<E> data = service.loadListForEdit(entityClass); @@ -107,7 +103,7 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten } @SuppressWarnings("unchecked") - protected void init(ObserveServiceFactory serviceFactory, DecoratorService decoratorService, BeanListHeader beanList) { + protected void init(DataSource dataSource, DecoratorService decoratorService, BeanListHeader beanList) { beanList.setI18nPrefix("observe.common."); @@ -118,11 +114,11 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten if ("listHeader".equals(beanList.getName())) { // use the binder for loading - prepareMainEntityList(serviceFactory, beanList.getBeanType(), beanList); + prepareMainEntityList(dataSource, beanList.getBeanType(), beanList); } else { - super.init(serviceFactory, decoratorService, beanList); + super.init(dataSource, decoratorService, beanList); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 18e070f1cf5ce4e089268788d2a6b3fcee8a1836 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 13:56:24 2015 +0200 correction de la sauvegarde sur le détail de composition de la palangure (refs #7017) --- .../longline/LonglineDetailCompositionServiceImpl.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java index 40dd524..b256d17 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java @@ -39,10 +39,6 @@ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService @Override public void save(SetLongline toSave, List<SectionWithTemplate> sections) { - Map<String, Section> existingSectionsByTopiaId = Entities.toIdMap(toSave.getSection()); - - toSave.clearSection(); - SetLongline saved = findByTopiaId(SetLongline.class, toSave.getTopiaId()); copyExcluding(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION, toSave, saved, SetLongline.PROPERTY_SECTION); @@ -65,7 +61,6 @@ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService sectionsDao, basketDao, branchlineDao, - existingSectionsByTopiaId, section); sectionsToSave.add(sectionToSave); sectionToSave.setSetLongline(saved); @@ -83,12 +78,11 @@ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService TopiaDAO<Section> sectionsDao, TopiaDAO<Basket> basketDao, TopiaDAO<Branchline> branchlineDao, - Map<String, Section> existingSectionsByTopiaId, Section section) throws TopiaException { Section sectionToSave; - if (section.getTopiaId() == null) { + if (Entities.isNew(section)) { // create sectionToSave = sectionsDao.create( @@ -97,7 +91,7 @@ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService } else { - sectionToSave = existingSectionsByTopiaId.get(section.getTopiaId()); + sectionToSave = sectionsDao.findByTopiaId(section.getTopiaId()); } @@ -133,7 +127,7 @@ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService Basket basketToSave; - if (basket.getTopiaId() == null) { + if (Entities.isNew(basket)) { // create basketToSave = basketDao.create( @@ -157,7 +151,9 @@ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService for (Branchline branchline : branchlines) { Branchline branchlineToSave = persistBranchline(branchlineBinder, - branchlineDao, existingBranchlinesByTopiaId, branchline); + branchlineDao, + existingBranchlinesByTopiaId, + branchline); basketToSave.addBranchline(branchlineToSave); } @@ -173,7 +169,7 @@ public class LonglineDetailCompositionServiceImpl extends AbstractObserveService Branchline branchlineToSave; - if (branchline.getTopiaId() == null) { + if (Entities.isNew(branchline)) { // create branchlineToSave = branchlineDao.create( -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 5e692f74bcbfac64660c606a611e1dac881db457 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 4 15:26:42 2015 +0200 correction initStorage, toujour utilisé les valeurs des combobox pour la positiond'une ligne --- .../ObserveServiceFactoryProviderTopia.java | 11 +- .../data/longline/ActivityLonglineServiceImpl.java | 2 +- .../data/longline/SetLonglineServiceImpl.java | 35 ++--- .../main/java/fr/ird/observe/ObserveContext.java | 149 +++++++++++---------- .../impl/longline/LonglinePositionHelper.java | 48 +++++-- 5 files changed, 142 insertions(+), 103 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java index 8e8b951..da22f6a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java @@ -7,6 +7,8 @@ import fr.ird.observe.db.DataSource; import fr.ird.observe.db.impl.H2DataSource; import fr.ird.observe.db.impl.PGDataSource; import org.apache.commons.lang3.reflect.ConstructorUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; import java.lang.reflect.InvocationHandler; @@ -23,11 +25,7 @@ import java.util.Set; */ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactoryProvider { -// private ObserveApplicationContext applicationContext; -// -// public void setApplicationContext(ObserveApplicationContext applicationContext) { -// this.applicationContext = applicationContext; -// } + private static final Log log = LogFactory.getLog(ObserveServiceFactoryProviderTopia.class); @Override public boolean acceptDataSource(DataSource dataSource) { @@ -134,6 +132,9 @@ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactory Object result = method.invoke(target, args); return result; } catch (InvocationTargetException e) { + if (log.isErrorEnabled()) { + log.error("Error in method " + method.getName(), e); + } throw e.getCause(); } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index d2bb21a..43b3dd8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -100,7 +100,7 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen public ActivityLongline onCreate(TripLongline parent, ActivityLongline toCreate) { ActivityLongline created = getDao().create(); - copy(ActivityLongline.class, BinderService.EDIT, toCreate, created); + copy(ActivityLongline.class, BinderService.EDIT, toCreate, created, false); parent.addActivityLongline(created); return created; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index ad7c4da..1ed6810 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -1,5 +1,6 @@ package fr.ird.observe.services.data.longline; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Basket; @@ -9,7 +10,6 @@ import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SetLonglineDAO; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.lang3.time.DateUtils; -import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDAO; import java.util.Date; @@ -27,36 +27,37 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se TopiaDAO<Section> dao = getDao(Section.class); - List<Section> sections = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); + List<Section> sectionsSaved = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); - if (!sections.isEmpty()) { + List<Section> sections = Lists.newLinkedList(); - Decorator<Section> sectionDecorator = getDecoratorByType(Section.class, null); - Decorator<Basket> basketDecorator = getDecoratorByType(Basket.class, null); - Decorator<Branchline> branchlineDecorator = getDecoratorByType(Branchline.class, null); + for (Section sectionSaved : sectionsSaved) { - for (Section section : sections) { + Section section = dao.newInstance(); - sectionDecorator.toString(section); + copyExcluding(Section.class, BinderService.EDIT_DETAIL_COMPOSITION, sectionSaved, section, Section.PROPERTY_BASKET); - if (!section.isBasketEmpty()) { + for (Basket basketSaved : sectionSaved.getBasket()) { - for (Basket basket : section.getBasket()) { + Basket basket = getDao(Basket.class).newInstance(); - basketDecorator.toString(basket); + copyExcluding(Basket.class, BinderService.EDIT_DETAIL_COMPOSITION, basketSaved, basket, Basket.PROPERTY_BRANCHLINE); - if (!basket.isBranchlineEmpty()) { + for (Branchline branchlineSaved : basketSaved.getBranchline()) { - for (Branchline branchline : basket.getBranchline()) { + Branchline branchline = getDao(Branchline.class).newInstance(); - branchlineDecorator.toString(branchline); + copy(Branchline.class, BinderService.EDIT_DETAIL_COMPOSITION, branchlineSaved, branchline); - } - } + basket.addBranchline(branchline); - } } + + section.addBasket(basket); + } + + sections.add(section); } return sections; diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java index 5f1713a..0d05c39 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java @@ -24,6 +24,7 @@ package fr.ird.observe; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListenerAdapter; import fr.ird.observe.db.impl.H2DataSource; @@ -31,8 +32,10 @@ import fr.ird.observe.services.ObserveService; import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.data.OpenableService; import fr.ird.observe.ui.ObserveMainUI; +import fr.ird.observe.ui.ObserveMainUIHandler; import fr.ird.observe.ui.ObserveUIMode; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.actions.ChangeStorageAction; import fr.ird.observe.ui.actions.shared.AbstractUIAction; import fr.ird.observe.ui.actions.shared.CancelCreateUIAction; import fr.ird.observe.ui.actions.shared.CloseAndCreateUIAction; @@ -63,6 +66,7 @@ import java.awt.Component; import java.util.Arrays; import java.util.List; +import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; /** @@ -246,78 +250,79 @@ public class ObserveContext extends ObserveApplicationContext { return services; } -// public void initStorage(ObserveConfig config, -// ObserveMainUI mainUI, -// boolean askToCreate) { -// try { -// if (config.isLocalStorageExist()) { -// -// // une base locale existe, on l'ouvre -// loadLocalStorage(); -// -// // on peut retourner sur cette base -// mainUI.setMode(ObserveUIMode.DB); -// } else { -// -// // on peut retourner sur cette base -// mainUI.setMode(ObserveUIMode.NO_DB); -// -// if (askToCreate) { -// -// // demande à l'utilisateur s'il veut créer la base locale -// createStorage(config, mainUI.getHandler()); -// } -// } -// if (log.isInfoEnabled()) { -// log.info(t("observe.init.storage.done")); -// } -// } catch (Exception e) { -// ErrorDialogUI.showError(e); -// if (log.isErrorEnabled()) { -// log.error(e.getMessage(), e); -// } -// } -// } - -// protected void createStorage(ObserveConfig config, -// ObserveMainUIHandler uiHandler) { -// -// int reponse = UIHelper.askUser( -// t("observe.title.no.local.db.found"), -// t("observe.message.no.local.db.found", -// config.getLocalDBDirectory()), -// JOptionPane.QUESTION_MESSAGE, -// new Object[]{ -// t("observe.choice.useRemoteStorage"), -// t("observe.choice.createLocalStorage"), -// t("observe.choice.doNothing") -// }, -// 1 -// ); -// if (log.isDebugEnabled()) { -// log.debug("response : " + reponse); -// } -// -// DbMode dbMode = null; -// String title = null; -// if (reponse != JOptionPane.CLOSED_OPTION && reponse < 2) { -// -// if (reponse == 1) { -// // creation de la base locale -// dbMode = DbMode.CREATE_LOCAL; -// title = n("observe.title.create.local.db"); -// } else { -// // connexion à une base distante -// dbMode = DbMode.USE_REMOTE; -// title = n("observe.title.load.remote.db"); -// } -// } -// if (dbMode != null) { -//// uiHandler.launchChangeStorage(getObserveMainUI(), dbMode, title); -// -// new ChangeStorageAction(getObserveMainUI(), dbMode, title).run(); -// } -// } + public void initStorage(ObserveConfig config, + ObserveMainUI mainUI, + boolean askToCreate) { + try { + if (config.isLocalStorageExist()) { + + // une base locale existe, on l'ouvre + loadLocalStorage(); + + // on peut retourner sur cette base + mainUI.setMode(ObserveUIMode.DB); + } else { + + // on peut retourner sur cette base + mainUI.setMode(ObserveUIMode.NO_DB); + + if (askToCreate) { + + // demande à l'utilisateur s'il veut créer la base locale + createStorage(config, mainUI.getHandler()); + } + } + if (log.isInfoEnabled()) { + log.info(t("observe.init.storage.done")); + } + } catch (Exception e) { + ErrorDialogUI.showError(e); + if (log.isErrorEnabled()) { + log.error(e.getMessage(), e); + } + } + } + + protected void createStorage(ObserveConfig config, + ObserveMainUIHandler uiHandler) { + + int reponse = UIHelper.askUser( + t("observe.title.no.local.db.found"), + t("observe.message.no.local.db.found", + config.getLocalDBDirectory()), + JOptionPane.QUESTION_MESSAGE, + new Object[]{ + t("observe.choice.useRemoteStorage"), + t("observe.choice.createLocalStorage"), + t("observe.choice.doNothing") + }, + 1 + ); + if (log.isDebugEnabled()) { + log.debug("response : " + reponse); + } + + DbMode dbMode = null; + String title = null; + if (reponse != JOptionPane.CLOSED_OPTION && reponse < 2) { + + if (reponse == 1) { + // creation de la base locale + dbMode = DbMode.CREATE_LOCAL; + title = n("observe.title.create.local.db"); + } else { + // connexion à une base distante + dbMode = DbMode.USE_REMOTE; + title = + n("observe.title.load.remote.db"); + } + } + if (dbMode != null) { +// uiHandler.launchChangeStorage(getObserveMainUI(), dbMode, title); + + new ChangeStorageAction(getObserveMainUI(), dbMode, title).run(); + } + } protected void loadLocalStorage() throws Exception { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java index f2f9e31..69c4b5d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java @@ -22,6 +22,9 @@ package fr.ird.observe.ui.content.table.impl.longline; * #L% */ +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Baskets; @@ -32,6 +35,7 @@ import fr.ird.observe.entities.longline.LonglinePositionAware; import fr.ird.observe.entities.longline.Section; import jaxx.runtime.swing.editor.bean.BeanComboBox; import org.apache.commons.collections4.CollectionUtils; +import org.nuiton.topia.persistence.TopiaEntity; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -56,6 +60,9 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { // To avoid any propagation when doing some works on locations protected boolean locationIsAdjusting; + // si l'entité est en cour de modification + protected boolean entityAdjusting; + List<Section> sectionUniverse; List<Basket> basketUniverse; @@ -72,7 +79,9 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { PropertyChangeListener sectionChanged = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - onSectionChanged((Section) evt.getNewValue(), (E) evt.getSource()); + if (! entityAdjusting) { + onSectionChanged((Section) evt.getNewValue(), (E) evt.getSource()); + } } }; tableEditBean.addPropertyChangeListener(CatchLongline.PROPERTY_SECTION, sectionChanged); @@ -215,7 +224,10 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { protected void onSectionChanged(Section newValue, E entity) { + Preconditions.checkState(! entityAdjusting, "entity should not be adjusting"); + locationIsAdjusting = true; + entityAdjusting = true; try { @@ -236,25 +248,31 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { if (newValue != null) { + Section newValueInUniverse = findInList(sectionUniverse, newValue.getTopiaId()); + entity.setSection(newValueInUniverse); + // une section est sélectionnée // on remplit uniquement les paniers de cette section - List<Basket> baskets = newValue.getBasket(); + List<Basket> baskets = newValueInUniverse.getBasket(); uiBasket.setData(baskets); if (basket != null && baskets.contains(basket)) { // un panier est sélectionné + Basket basketInUniverse = findInList(baskets, basket.getTopiaId()); + // on repmlit uniquement les avançons du panier - List<Branchline> branchlines = basket.getBranchline(); + List<Branchline> branchlines = basketInUniverse.getBranchline(); uiBranchline.setData(branchlines); - entity.setBasket(basket); + entity.setBasket(basketInUniverse); if (branchline != null && branchlines.contains(branchline)) { // un avançon est sélectionné - entity.setBranchline(branchline); + Branchline branchlineInUniverse = findInList(branchlines, branchline.getTopiaId()); + entity.setBranchline(branchlineInUniverse); } @@ -263,13 +281,25 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { } } finally { - + entityAdjusting = false; locationIsAdjusting = false; } } + protected <F extends TopiaEntity> F findInList(List<F> entities, final String topiaId) { + F result = Iterables.find(entities, new Predicate<F>() { + @Override + public boolean apply(F input) { + return topiaId.equals(input.getTopiaId()); + + } + }, null); + return result; + } + + protected void onBasketChanged(Basket newValue, E entity) { if (!locationIsAdjusting) { @@ -282,12 +312,14 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { // on vide l'ensemble des avançons uiBranchline.setData(Collections.<Branchline>emptyList()); - if (newValue != null) { + if (newValue != null && ! uiBasket.isEmpty()) { // un panier est selectionne + Basket newValueInUniverse = findInList(uiBasket.getData(), newValue.getTopiaId()); + // on remplit uniquement les avançons des paniers - List<Branchline> branchlines = newValue.getBranchline(); + List<Branchline> branchlines = newValueInUniverse.getBranchline(); uiBranchline.setData(branchlines); if (branchline != null && branchlines.contains(branchline)) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit d36d5fe7421014f7cb95a5e8772f4974c8d69ba6 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 15:55:19 2015 +0200 - Amélioration du cache de services - Ajout API pour créer un modèle de sélection refs #7017 --- .../observe/services/ObserveServiceFactory.java | 148 ++++------------ .../ird/observe/services/ObserveServicesCache.java | 191 +++++++++++++++++++++ .../fr/ird/observe/services/data/TripService.java | 3 + .../observe/services/model/DataSelectionModel.java | 103 ++--------- .../ObserveServiceFactoryProviderTopia.java | 11 +- .../ird/observe/services/data/TripServiceImpl.java | 88 ++++++++++ .../main/java/fr/ird/observe/ObserveContext.java | 17 +- .../java/fr/ird/observe/ui/admin/AdminUIModel.java | 25 ++- .../ui/admin/consolidate/ConsolidateUIHandler.java | 2 +- .../ird/observe/ui/admin/export/ExportModel.java | 3 - .../ird/observe/ui/storage/StorageUIHandler.java | 63 +++---- 11 files changed, 381 insertions(+), 273 deletions(-) diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index 345052d..25dcb33 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -1,21 +1,14 @@ package fr.ird.observe.services; import com.google.common.base.Preconditions; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import fr.ird.observe.ObserveApplicationContext; -import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataSource; -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.Closeable; import java.util.HashSet; import java.util.ServiceLoader; import java.util.Set; -import java.util.concurrent.ExecutionException; /** * Created on 4/24/15. @@ -23,7 +16,7 @@ import java.util.concurrent.ExecutionException; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class ObserveServiceFactory implements Closeable { +public class ObserveServiceFactory { /** Logger. */ private static final Log log = LogFactory.getLog(ObserveServiceFactory.class); @@ -32,6 +25,34 @@ public class ObserveServiceFactory implements Closeable { protected static Set<ObserveServiceFactoryProvider> providers; + public ObserveServiceFactory(ObserveApplicationContext applicationContext) { + this.applicationContext = applicationContext; + if (log.isInfoEnabled()) { + log.info("Init new ServiceFactory for applicationContext: " + applicationContext); + } + } + + public <S extends ObserveService> S newService(DataSource dataSource, Class<S> serviceType) { + + Preconditions.checkNotNull(dataSource, "dataSource can't be null."); + Preconditions.checkNotNull(serviceType, "serviceType can't be null."); + Preconditions.checkNotNull(dataSource, "dataSource can't be null."); + + ObserveServiceFactoryProvider provider = getProvider(dataSource); + + if (log.isDebugEnabled()) { + log.debug("Using provider: " + provider); + } + ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); + + S service = provider.newService(serviceType, serviceContext); + if (log.isInfoEnabled()) { + log.info("New service created: " + service + " for dataSource: " + toString(dataSource)); + } + return service; + + } + protected static Set<ObserveServiceFactoryProvider> getProviders() { if (providers == null) { @@ -63,114 +84,7 @@ public class ObserveServiceFactory implements Closeable { } - protected final LoadingCache<ServiceKey<? extends ObserveService>, ObserveService> services; - - public static ObserveServiceFactory newFactory(ObserveApplicationContext applicationContext) { - return new ObserveServiceFactory(applicationContext); - } - - protected ObserveServiceFactory(ObserveApplicationContext applicationContext) { - - this.applicationContext = applicationContext; - this.services = CacheBuilder.newBuilder().build(new CacheLoader<ServiceKey<? extends ObserveService>, ObserveService>() { - - @Override - public ObserveService load(ServiceKey<? extends ObserveService> key) throws Exception { - Preconditions.checkNotNull(key, "service key can't be null"); - - Class<? extends ObserveService> serviceType = key.serviceType; - - ObserveServiceFactoryProvider provider = getProvider(key.dataSource); - - ObserveServiceContext serviceContext = new ObserveServiceContext(ObserveServiceFactory.this.applicationContext, key.dataSource); - ObserveService service = provider.newService(serviceType, serviceContext); - - if (log.isDebugEnabled()) { - log.debug("New service " + service); - } - - return service; - } - }); - - } - - public <S extends ObserveService> S getService(DataSource dataSource, Class<S> serviceType) { - - Preconditions.checkNotNull(dataSource, "dataSource can't be null."); - Preconditions.checkNotNull(serviceType, "serviceType can't be null."); - Preconditions.checkNotNull(dataSource, "dataSource can't be null."); - - ServiceKey<S> key = new ServiceKey<S>(dataSource, serviceType); - - try { - - S s = (S) services.get(key); - return s; - - } catch (ExecutionException e) { - throw new ObserveTechnicalException("Could not get service: " + serviceType, e); - } - - } - - static class ServiceKey<S extends ObserveService> { - - final DataSource dataSource; - - final Class<S> serviceType; - - ServiceKey(DataSource dataSource, Class<S> serviceType) { - - Preconditions.checkNotNull(dataSource, "dataSource can't be null."); - Preconditions.checkNotNull(serviceType, "serviceType can't be null."); - this.dataSource = dataSource; - this.serviceType = serviceType; - - } - - @Override - public boolean equals(Object o) { - - if (this == o) return true; - if (!(o instanceof ServiceKey)) return false; - - ServiceKey<?> that = (ServiceKey<?>) o; - - return dataSource.equals(that.dataSource) - && serviceType.equals(that.serviceType); - - } - - @Override - public int hashCode() { - - int result = dataSource.hashCode(); - result = 31 * result + serviceType.hashCode(); - return result; - - } - } - - public void unregisterDataSource(DataSource dataSource) { - //FIXME Remove all service using this dataSource + protected String toString(DataSource dataSource) { + return dataSource.getClass().getName() + "#" + System.identityHashCode(dataSource); } - - public void clear() { - services.invalidateAll(); - } - - @Override - public void close() { - - for (ObserveService service : services.asMap().values()) { - if (log.isDebugEnabled()) { - log.debug("Close service " + service); - } - IOUtils.closeQuietly(service); - } - services.invalidateAll(); - - } - } diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServicesCache.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServicesCache.java new file mode 100644 index 0000000..788589f --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServicesCache.java @@ -0,0 +1,191 @@ +package fr.ird.observe.services; + +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.Iterables; +import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.event.DataSourceEvent; +import fr.ird.observe.db.event.DataSourceListener; +import fr.ird.observe.db.event.DataSourceListenerAdapter; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.Closeable; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutionException; + +/** + * Created on 5/4/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ObserveServicesCache implements Closeable { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ObserveServicesCache.class); + + protected final ObserveServiceFactory factory; + + protected final LoadingCache<ServiceKey<? extends ObserveService>, ObserveService> cache; + + protected final Set<DataSource> usedDataSource; + + protected final DataSourceListener dataSourceListener; + + public ObserveServicesCache(ObserveServiceFactory factory) { + + this.factory = factory; + + this.usedDataSource = new HashSet<DataSource>(); + + this.cache = CacheBuilder.newBuilder().build(new CacheLoader<ServiceKey<? extends ObserveService>, ObserveService>() { + + @Override + public ObserveService load(ServiceKey<? extends ObserveService> key) throws Exception { + + Preconditions.checkNotNull(key, "service key can't be null"); + + boolean add = usedDataSource.add(key.dataSource); + if (add) { + registerDataSource(key.dataSource); + } + ObserveService service = ObserveServicesCache.this.factory.newService(key.dataSource, key.serviceType); + + if (log.isInfoEnabled()) { + log.info("Adding service " + service + "in cache"); + } + return service; + + } + }); + this.dataSourceListener = new DataSourceListenerAdapter() { + + @Override + public void onClosed(DataSourceEvent event) { + + // remove any cache entry using this dataSource + DataSource source = event.getSource(); + unregisterDataSource(source); + + } + }; + } + + public <S extends ObserveService> S getService(DataSource dataSource, Class<S> serviceType) { + + Preconditions.checkNotNull(dataSource, "dataSource can't be null."); + Preconditions.checkNotNull(serviceType, "serviceType can't be null."); + + ServiceKey<S> key = new ServiceKey<S>(dataSource, serviceType); + + try { + + S s = (S) cache.get(key); + return s; + + } catch (ExecutionException e) { + throw new ObserveTechnicalException("Could not get service: " + serviceType, e); + } + + } + + @Override + public void close() { + + removeDataSource(cache.asMap().keySet()); + usedDataSource.clear(); + + } + + protected void registerDataSource(DataSource dataSource) { + + if (log.isInfoEnabled()) { + log.info("Register new dataSource: " + factory.toString(dataSource)); + } + usedDataSource.add(dataSource); + dataSource.addDataSourceListener(dataSourceListener); + + } + + protected void unregisterDataSource(final DataSource dataSource) { + + if (log.isInfoEnabled()) { + log.info("Unregister new dataSource: " + factory.toString(dataSource)); + } + + Iterable<ServiceKey<?>> keysToRemove = Iterables.filter(cache.asMap().keySet(), new Predicate<ServiceKey<? extends ObserveService>>() { + + @Override + public boolean apply(ServiceKey<? extends ObserveService> input) { + return input.dataSource == dataSource; + } + }); + removeDataSource(keysToRemove); + usedDataSource.remove(dataSource); + + } + + protected synchronized void removeDataSource(Iterable<ServiceKey<?>> keysToRemove) { + + Map<ServiceKey<? extends ObserveService>, ObserveService> map = cache.asMap(); + + for (ServiceKey<? extends ObserveService> serviceKey : keysToRemove) { + ObserveService service = map.get(serviceKey); + if (log.isInfoEnabled()) { + log.info("Close service: " + service); + } + IOUtils.closeQuietly(service); + } + cache.invalidateAll(keysToRemove); + + } + + + static class ServiceKey<S extends ObserveService> { + + protected final DataSource dataSource; + + protected final Class<S> serviceType; + + ServiceKey(DataSource dataSource, Class<S> serviceType) { + + Preconditions.checkNotNull(dataSource, "dataSource can't be null."); + Preconditions.checkNotNull(serviceType, "serviceType can't be null."); + + this.dataSource = dataSource; + this.serviceType = serviceType; + + } + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (!(o instanceof ServiceKey)) return false; + + ServiceKey<?> that = (ServiceKey<?>) o; + // On doit utiliser une égalité de référence pour la dataSource + return dataSource == that.dataSource && serviceType.equals(that.serviceType); + + } + + @Override + public int hashCode() { + + int result = dataSource.hashCode(); + result = 31 * result + serviceType.hashCode(); + return result; + + } + } + + +} diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java index 9f0933b..db47799 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java @@ -5,6 +5,7 @@ import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; +import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.tripMap.TripMapPoint; import java.util.List; @@ -17,6 +18,8 @@ import java.util.List; */ public interface TripService extends ObserveService { + DataSelectionModel loadDataSelectionModel(); + List<Program> getPossibleProgramsForTrip(String tripId); Trip getTrip(String tripId); diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java b/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java index c3ea1f0..f03fc98 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java @@ -21,18 +21,9 @@ */ package fr.ird.observe.services.model; -import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.Trips; -import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.referentiel.Programs; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.ObserveServiceFactory; -import fr.ird.observe.services.data.longline.TripLonglineService; -import fr.ird.observe.services.data.seine.TripSeineService; -import fr.ird.observe.services.referential.ReferentialService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -60,78 +51,6 @@ import java.util.TreeMap; */ public class DataSelectionModel implements Serializable { - public static void populate(DataSelectionModel model, ObserveServiceFactory services, DataSource dataSource) throws Exception { - -// source.checkState(DataSourceState.OPEN); - - Map<String, List<String>> datas = new HashMap<String, List<String>>(); - - TripSeineService tripSeineService = services.getService(dataSource, TripSeineService.class); - TripLonglineService tripLonglineService = services.getService(dataSource, TripLonglineService.class); - - List<Program> programs = services.getService(dataSource, ReferentialService.class).getAllProgramStub(); - for (Program program : programs) { - - if (Programs.isProgramSeine(program)) { - List<TripSeine> trips = tripSeineService.getTripSeineStubByProgram(program.getTopiaId()); - populate(model, program, trips, datas); - } - - if (Programs.isProgramLongline(program)) { - List<TripLongline> trips = tripLonglineService.getTripLonglineStubByProgram(program.getTopiaId()); - populate(model, program, trips, datas); - } - - } - model.setDatas(datas); - - } - - protected static <T extends Trip> void populate(DataSelectionModel model, - Program program, - List<T> trips, - Map<String, List<String>> datas) { - - model.cacheEntity(program); - - if (!trips.isEmpty()) { - List<String> tripIds = new ArrayList<String>(); - - if (model.isUseOpenData()) { - - // ajout de toutes les marées ouvertes ou non - for (T trip : trips) { - trip.setProgram(program); - model.cacheEntity(trip); - tripIds.add(trip.getTopiaId()); - } - - } else { - - // ajout de toutes les marées non ouvertes - for (T trip : trips) { - trip.setProgram(program); - if (!trip.isOpen()) { - model.cacheEntity(trip); - tripIds.add(trip.getTopiaId()); - } - } - - } - - if (!tripIds.isEmpty()) { - - datas.put(program.getTopiaId(), tripIds); - if (log.isDebugEnabled()) { - log.debug("Add program " + program.getLabel1() + " with " + tripIds.size() + " trip(s)."); - } - - } - - } - - } - public static final String PROPERTY_USE_REFERENTIEL = "useReferentiel"; public static final String PROPERTY_USE_DATA = "useData"; @@ -187,10 +106,6 @@ public class DataSelectionModel implements Serializable { protected final PropertyChangeSupport pcs; - public void populate() throws Exception { - throw new UnsupportedOperationException(); - } - public DataSelectionModel() { pcs = new PropertyChangeSupport(this); Class<?>[] classes = TopiaEntityHelper.getContracts(Entities.REFERENCE_ENTITIES); @@ -227,7 +142,7 @@ public class DataSelectionModel implements Serializable { return true; } - protected void cacheEntity(TopiaEntity entity) { + public void cacheEntity(TopiaEntity entity) { entityCache.put(entity.getTopiaId(), entity); } @@ -492,20 +407,22 @@ public class DataSelectionModel implements Serializable { } protected void checkReferentielType(Class<?> type) { + if (!referentiel.contains(type)) { - throw new IllegalArgumentException( - "given <" + type + "> is not in referentiel universe : " + - referentiel); + throw new IllegalArgumentException("given <" + type + "> is not in referentiel universe : " + referentiel); } + } public void destroy() { + removeAll(); // suppression de tous les listeners PropertyChangeListener[] listeners = pcs.getPropertyChangeListeners(); for (PropertyChangeListener l : listeners) { removePropertyChangeListener(l); } + } @Override @@ -513,4 +430,12 @@ public class DataSelectionModel implements Serializable { super.finalize(); destroy(); } + + public void copyDataTo(DataSelectionModel dataSelectionModel) { + + dataSelectionModel.setDatas(datas); + dataSelectionModel.entityCache.clear(); + dataSelectionModel.entityCache.putAll((Map) entityCache); + + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java index da22f6a..3ee2edc 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java @@ -25,8 +25,9 @@ import java.util.Set; */ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactoryProvider { + /** Logger. */ private static final Log log = LogFactory.getLog(ObserveServiceFactoryProviderTopia.class); - + @Override public boolean acceptDataSource(DataSource dataSource) { @@ -81,7 +82,7 @@ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactory // Instanciate transactional proxied service ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); - S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); + S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactoryProviderTopia.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); return proxyService; @@ -96,6 +97,7 @@ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactory private final Set<String> methodNamesToByPass; protected ServiceInvocationHandler(ObserveServiceContext serviceContext, ObserveService target) { + this.serviceContext = serviceContext; this.target = target; this.methodNamesToByPass = Sets.newHashSet( @@ -104,8 +106,9 @@ public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactory "finalize", "toString", "clone", - "getClass" - ); + "getClass", + "close"); + } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java index d419ecb..d7ed97b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java @@ -13,9 +13,18 @@ import fr.ird.observe.entities.referentiel.Programs; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.entities.seine.TripSeineDAO; import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.data.longline.TripLonglineService; +import fr.ird.observe.services.data.seine.TripSeineService; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.tripMap.TripMapPoint; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Created on 4/26/15. @@ -25,6 +34,39 @@ import java.util.List; */ public class TripServiceImpl extends AbstractObserveService implements TripService { + /** Logger. */ + private static final Log log = LogFactory.getLog(TripServiceImpl.class); + + @Override + public DataSelectionModel loadDataSelectionModel() { + + DataSelectionModel result = new DataSelectionModel(); + + Map<String, List<String>> datas = new HashMap<String, List<String>>(); + + TripSeineService tripSeineService = newService(TripSeineService.class); + TripLonglineService tripLonglineService = newService(TripLonglineService.class); + + List<Program> programs = newService(ReferentialService.class).getAllProgramStub(); + for (Program program : programs) { + + if (Programs.isProgramSeine(program)) { + List<TripSeine> trips = tripSeineService.getTripSeineStubByProgram(program.getTopiaId()); + populate(result, program, trips, datas); + } + + if (Programs.isProgramLongline(program)) { + List<TripLongline> trips = tripLonglineService.getTripLonglineStubByProgram(program.getTopiaId()); + populate(result, program, trips, datas); + } + + } + result.setDatas(datas); + + return result; + + } + @Override public List<Program> getPossibleProgramsForTrip(String tripId) { @@ -121,4 +163,50 @@ public class TripServiceImpl extends AbstractObserveService implements TripServi } } + + protected static <T extends Trip> void populate(DataSelectionModel model, + Program program, + List<T> trips, + Map<String, List<String>> datas) { + + model.cacheEntity(program); + + if (!trips.isEmpty()) { + List<String> tripIds = new ArrayList<String>(); + + if (model.isUseOpenData()) { + + // ajout de toutes les marées ouvertes ou non + for (T trip : trips) { + trip.setProgram(program); + model.cacheEntity(trip); + tripIds.add(trip.getTopiaId()); + } + + } else { + + // ajout de toutes les marées non ouvertes + for (T trip : trips) { + trip.setProgram(program); + if (!trip.isOpen()) { + model.cacheEntity(trip); + tripIds.add(trip.getTopiaId()); + } + } + + } + + if (!tripIds.isEmpty()) { + + datas.put(program.getTopiaId(), tripIds); + if (log.isDebugEnabled()) { + log.debug("Add program " + program.getLabel1() + " with " + tripIds.size() + " trip(s)."); + } + + } + + } + + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java index 0d05c39..8eafd51 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java @@ -30,6 +30,7 @@ import fr.ird.observe.db.event.DataSourceListenerAdapter; import fr.ird.observe.db.impl.H2DataSource; import fr.ird.observe.services.ObserveService; import fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.ObserveServicesCache; import fr.ird.observe.services.data.OpenableService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.ObserveMainUIHandler; @@ -237,22 +238,16 @@ public class ObserveContext extends ObserveApplicationContext { } public <S extends ObserveService> S getService(Class<S> serviceType) { - S service = services.getService(getDataSource(), serviceType); + S service = servicesCache.getService(getDataSource(), serviceType); return service; } public static <S extends ObserveService> S getService(DataSource dataSource, Class<S> serviceType) { - S service = get().services.getService(dataSource, serviceType); + S service = get().servicesCache.getService(dataSource, serviceType); return service; } - public ObserveServiceFactory getServices() { - return services; - } - - public void initStorage(ObserveConfig config, - ObserveMainUI mainUI, - boolean askToCreate) { + public void initStorage(ObserveConfig config, ObserveMainUI mainUI, boolean askToCreate) { try { if (config.isLocalStorageExist()) { @@ -548,6 +543,8 @@ public class ObserveContext extends ObserveApplicationContext { actionMap.put(actionId, action); } - private final ObserveServiceFactory services = ObserveServiceFactory.newFactory(this); + private final ObserveServiceFactory serviceFactory = new ObserveServiceFactory(this); + + protected final ObserveServicesCache servicesCache = new ObserveServicesCache(serviceFactory); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java index 28e36fc..79238c5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java @@ -34,6 +34,7 @@ import fr.ird.observe.db.impl.PGDataSource; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.Trips; import fr.ird.observe.report.model.Report; +import fr.ird.observe.services.data.TripService; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.admin.consolidate.ConsolidateModel; import fr.ird.observe.ui.admin.export.ExportModel; @@ -512,7 +513,6 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { availableIncomingModes.clear(); storageHandler = ui.getContextValue(StorageUIHandler.class); -// dataService = ui.getContextValue(DataService.class); config = ui.getContextValue(ObserveConfig.class); dataContext = ui.getContextValue(DataContext.class); @@ -1275,31 +1275,28 @@ public class AdminUIModel extends WizardExtModel<AdminStep> { } public void populateSelectionModel(DataSource dataSource) { + try { - DataSelectionModel.populate(getSelectionDataModel(), ObserveContext.get().getServices(), dataSource); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("could not populate selected model", e); - } + + TripService service = ObserveContext.getService(dataSource, TripService.class); + DataSelectionModel dataSelectionModel = service.loadDataSelectionModel(); + dataSelectionModel.copyDataTo(getSelectionDataModel()); + } finally { // on notifie que le modèle de sélection a changé // (il faut donc recalculé l'arbre de sélection) firePropertyChange(SELECTION_MODEL_CHANGED_PROPERTY_NAME, getSelectionDataModel()); + } + } protected void computeExistingTrips(DataSource dataSource) { - DataSelectionModel selectionModel = new DataSelectionModel(); + TripService service = ObserveContext.getService(dataSource, TripService.class); + DataSelectionModel selectionModel = service.loadDataSelectionModel(); selectionModel.setUseOpenData(true); - try { - DataSelectionModel.populate(selectionModel, ObserveContext.get().getServices(), dataSource); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("could not populate selected model", e); - } - } List<String> existingTripIds = new ArrayList<String>(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java index f153528..77aaa3d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java @@ -129,7 +129,7 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { Set<String> tripIds = model.getSelectionDataModel().getSelectedData(); - ComputeDataService service = ObserveContext.get().getServices().getService(getStepModel().getSource(), ComputeDataService.class); + ComputeDataService service = ObserveContext.getService(getStepModel().getSource(), ComputeDataService.class); try { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java index b6bf549..959dd3f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java @@ -27,7 +27,6 @@ import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.admin.AdminActionModel; import fr.ird.observe.ui.admin.AdminStep; @@ -65,8 +64,6 @@ public class ExportModel extends AdminActionModel { protected DataSource centralSource; - protected ObserveServiceFactory centralServiceFactory; - public ExportModel() { super(AdminStep.EXPORT_DATA); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java index b873656..9f98482 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java @@ -45,6 +45,7 @@ import fr.ird.observe.db.util.SecurityModel; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.ReplicationService; +import fr.ird.observe.services.data.TripService; import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; @@ -1077,10 +1078,8 @@ public class StorageUIHandler { try { source.doOpen(); - Decorator<Program> pDecorator = - getDecoratorService().getDecoratorByType(Program.class); - Decorator<TripSeine> mDecorator = - getDecoratorService().getDecoratorByType(TripSeine.class); + Decorator<Program> pDecorator = getDecoratorService().getDecoratorByType(Program.class); + Decorator<TripSeine> mDecorator = getDecoratorService().getDecoratorByType(TripSeine.class); Map<String, List<String>> dataByProgram = dataModel.getSelectedDataByProgram(); @@ -1171,43 +1170,36 @@ public class StorageUIHandler { StorageUIModel model = ui.getModel(); - try { - - Preconditions.checkState(source != null, "Can't select data on a null dataSource"); + Preconditions.checkState(source != null, "Can't select data on a null dataSource"); - DataSelectionModel dataModel = new DataSelectionModel(); - dataModel.setUseData(true); - dataModel.setUseOpenData(true); - dataModel.setUseReferentiel(false); - DataSelectionModel.populate(dataModel, ObserveContext.get().getServices(), source); + TripService service = ObserveContext.getService(source, TripService.class); + DataSelectionModel dataModel = service.loadDataSelectionModel(); + dataModel.setUseData(true); + dataModel.setUseOpenData(true); + dataModel.setUseReferentiel(false); - // positionnement du model de selection de données - // dans le model du wizard - model.setSelectDataModel(dataModel); + // positionnement du model de selection de données dans le model du wizard + model.setSelectDataModel(dataModel); - // initialisation de l'ui dedié - ui.getSELECT_DATA().initTree(source); - - } catch (Exception e) { - throw new RuntimeException("Could not grab data to select", e); - } + // initialisation de l'ui dedié + ui.getSELECT_DATA().initTree(source); } - protected void checkImportDbVersion(StorageUIModel model, DataSource dataSource) throws DataSourceException { - try { - dataSource.doOpen(); - - Version importServiceDbVersion = dataSource.getDbVersion(); - Version currentDbVersion = model.getDbVersion(); - if (importServiceDbVersion.before(currentDbVersion)) { - throw new IllegalStateException("Import db version (" + importServiceDbVersion + ") is not compatible with the current database version (" + currentDbVersion + ")"); - } - } finally { - dataSource.doClose(false); - } - - } +// protected void checkImportDbVersion(StorageUIModel model, DataSource dataSource) throws DataSourceException { +// try { +// dataSource.doOpen(); +// +// Version importServiceDbVersion = dataSource.getDbVersion(); +// Version currentDbVersion = model.getDbVersion(); +// if (importServiceDbVersion.before(currentDbVersion)) { +// throw new IllegalStateException("Import db version (" + importServiceDbVersion + ") is not compatible with the current database version (" + currentDbVersion + ")"); +// } +// } finally { +// dataSource.doClose(false); +// } +// +// } protected void initSelectData(StorageUI ui) { @@ -1238,6 +1230,7 @@ public class StorageUIHandler { log.error(e, e); } } + } protected void updateSecurity(StorageUIModel model, RolesTableModel roleModel) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 54f59c05abba19bb548b24c08dba60e5ee13d817 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 4 17:24:38 2015 +0200 demander l'enregistrement du detail de l'avançon modifié avant l'enregistrement de la composition de la palangre --- .../LonglineDetailCompositionUIHandler.java | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java index 9433d66..0a5416a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java @@ -473,22 +473,37 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong @Override protected boolean doSave(SetLongline bean) { - SectionsTableModel sectionsTableModel = getSectionsTableModel(); - SectionWithTemplate selectedSection = sectionsTableModel.getSelectedRow(); + BranchlineUI branchlineDetailUI = getUi().getBranchlineDetailUI(); + + boolean continueSave = true; - if (selectedSection != null) { + if (getUi().getFishingOperationTabPane().getSelectedIndex() == 2) { - // flush selected section before save - flushSection(selectedSection); + BranchlineUIHandler branchlineUIHandler = branchlineDetailUI.getHandler(); + + continueSave = branchlineUIHandler.tryToQuit(); } - List<SectionWithTemplate> sections = sectionsTableModel.getNotEmptyData(); + if (continueSave) { - LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); - service.save(bean, sections); + SectionsTableModel sectionsTableModel = getSectionsTableModel(); + SectionWithTemplate selectedSection = sectionsTableModel.getSelectedRow(); + + if (selectedSection != null) { + + // flush selected section before save + flushSection(selectedSection); + + } + + List<SectionWithTemplate> sections = sectionsTableModel.getNotEmptyData(); + + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + service.save(bean, sections); + } - return true; + return continueSave; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit f8957ffbf6cf2e9a0dfbb492048c67bed28a067a Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 4 17:56:03 2015 +0200 - suppression commons.collections - ajout Sylvain en tant que développeur - observe-validation est en dépendances sur observe-service-api - optimisation des dépendances - deplacement model --- observe-business/pom.xml | 4 -- .../fr/ird/observe/db/impl/PGDataSourceConfig.java | 2 +- .../java/fr/ird/observe/db/util/PGInstall.java | 2 +- observe-services-api/pom.xml | 79 ++-------------------- .../fr/ird/observe/services/ObserveService.java | 3 +- .../ird/observe/services/ObserveServicesCache.java | 4 +- .../{model => data}/DataSelectionModel.java | 5 +- .../fr/ird/observe/services/data/TripService.java | 1 - .../services/operation/ValidationService.java | 2 +- observe-services/pom.xml | 25 ++----- .../observe/services/AbstractObserveService.java | 5 -- .../ird/observe/services/data/TripServiceImpl.java | 1 - .../services/operation/ComputeDataServiceImpl.java | 2 +- .../services/operation/SynchronizeServiceImpl.java | 4 +- .../services/operation/ValidationServiceImpl.java | 2 +- .../referential/ReferentialServiceImpl.java | 2 +- observe-swing/pom.xml | 16 ----- .../fr/ird/observe/ui/admin/AdminTabUIHandler.java | 2 +- .../java/fr/ird/observe/ui/admin/AdminUIModel.java | 2 +- .../ird/observe/ui/admin/config/SelectDataUI.jaxx | 2 +- .../ui/admin/consolidate/ConsolidateUIHandler.java | 16 ++--- .../ird/observe/ui/admin/export/ExportModel.java | 2 +- .../observe/ui/admin/export/ExportUIHandler.java | 2 +- .../observe/ui/admin/report/ReportUIHandler.java | 2 +- .../ui/admin/synchronize/SynchronizeUIHandler.java | 2 +- .../ui/admin/validate/ValidateUIHandler.java | 3 +- .../impl/longline/CatchLonglineUIHandler.java | 6 +- .../ird/observe/ui/storage/ObstunaAdminAction.java | 2 +- .../ui/storage/StorageBackupUILauncher.java | 2 +- .../ird/observe/ui/storage/StorageUIHandler.java | 2 +- .../fr/ird/observe/ui/storage/StorageUIModel.java | 2 +- .../ui/storage/tabs/StorageTabUIHandler.java | 2 +- .../ui/tree/DataSelectionTreeSelectionModel.java | 2 +- .../ird/observe/ui/tree/ObserveDataProvider.java | 2 +- .../fr/ird/observe/ui/tree/ObserveTreeBridge.java | 2 +- .../fr/ird/observe/ui/tree/ObserveTreeHelper.java | 4 +- .../ui/tree/loadors/AbstractNodeChildLoador.java | 2 +- .../loadors/ProgramLonglineNodeChildLoador.java | 4 +- .../tree/loadors/ProgramSeineNodeChildLoador.java | 4 +- .../ui/tree/loadors/RootNodeChildLoador.java | 2 +- pom.xml | 15 +++- 41 files changed, 70 insertions(+), 175 deletions(-) diff --git a/observe-business/pom.xml b/observe-business/pom.xml index 4366577..9c20720 100644 --- a/observe-business/pom.xml +++ b/observe-business/pom.xml @@ -89,10 +89,6 @@ <artifactId>commons-logging</artifactId> </dependency> <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </dependency> - <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> diff --git a/observe-business/src/main/java/fr/ird/observe/db/impl/PGDataSourceConfig.java b/observe-business/src/main/java/fr/ird/observe/db/impl/PGDataSourceConfig.java index 134f57d..354d53d 100644 --- a/observe-business/src/main/java/fr/ird/observe/db/impl/PGDataSourceConfig.java +++ b/observe-business/src/main/java/fr/ird/observe/db/impl/PGDataSourceConfig.java @@ -28,7 +28,7 @@ import fr.ird.observe.db.constants.CommonDataSourceConfigParam; import fr.ird.observe.db.constants.ConnexionStatus; import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.constants.DataPolicy; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.version.Version; diff --git a/observe-business/src/main/java/fr/ird/observe/db/util/PGInstall.java b/observe-business/src/main/java/fr/ird/observe/db/util/PGInstall.java index d57a514..a60b91c 100644 --- a/observe-business/src/main/java/fr/ird/observe/db/util/PGInstall.java +++ b/observe-business/src/main/java/fr/ird/observe/db/util/PGInstall.java @@ -25,7 +25,7 @@ import com.google.common.collect.Sets; import fr.ird.observe.db.impl.PGDataSourceConfig; import fr.ird.observe.entities.Entities; import fr.ird.observe.util.Scripts; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-services-api/pom.xml b/observe-services-api/pom.xml index 7d7da42..87c1025 100644 --- a/observe-services-api/pom.xml +++ b/observe-services-api/pom.xml @@ -28,7 +28,12 @@ <artifactId>observe-business</artifactId> <version>${project.version}</version> </dependency> - + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>observe-validation</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> <!-- commons dependencies --> @@ -36,87 +41,17 @@ <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>commons-primitives</groupId> - <artifactId>commons-primitives</artifactId> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-collections4</artifactId> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - </dependency> - <dependency> - <groupId>commons-jxpath</groupId> - <artifactId>commons-jxpath</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> - <!-- Nuiton --> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-utils</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton.i18n</groupId> - <artifactId>nuiton-i18n</artifactId> - </dependency> - <!-- persistence --> <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - </dependency> - <dependency> <groupId>org.nuiton.topia</groupId> <artifactId>topia-persistence</artifactId> </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <dependency> - <groupId>postgresql</groupId> - <artifactId>postgresql</artifactId> - <scope>runtime</scope> - </dependency> - - <!-- Logging --> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-jcl</artifactId> - <scope>runtime</scope> - </dependency> - - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <scope>runtime</scope> - </dependency> - - <!-- test dependencies --> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> </dependencies> diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveService.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveService.java index a214822..335c670 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveService.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveService.java @@ -5,7 +5,6 @@ import com.google.common.base.Predicate; import fr.ird.observe.entities.EntityMap; import org.nuiton.topia.persistence.TopiaEntity; -import java.io.Closeable; import java.util.List; /** @@ -14,7 +13,7 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public interface ObserveService extends Closeable { +public interface ObserveService { <E extends TopiaEntity> EntityMap findAllUsages(E entity); diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServicesCache.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServicesCache.java index 788589f..e642827 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServicesCache.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServicesCache.java @@ -11,7 +11,6 @@ import fr.ird.observe.db.DataSource; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListener; import fr.ird.observe.db.event.DataSourceListenerAdapter; -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -140,9 +139,8 @@ public class ObserveServicesCache implements Closeable { for (ServiceKey<? extends ObserveService> serviceKey : keysToRemove) { ObserveService service = map.get(serviceKey); if (log.isInfoEnabled()) { - log.info("Close service: " + service); + log.info("Remove service : " + service); } - IOUtils.closeQuietly(service); } cache.invalidateAll(keysToRemove); diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/DataSelectionModel.java similarity index 98% rename from observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java rename to observe-services-api/src/main/java/fr/ird/observe/services/data/DataSelectionModel.java index f03fc98..f4d5bd7 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/model/DataSelectionModel.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/data/DataSelectionModel.java @@ -19,12 +19,11 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -package fr.ird.observe.services.model; +package fr.ird.observe.services.data; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.Trips; import fr.ird.observe.entities.referentiel.Program; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaEntity; @@ -220,7 +219,7 @@ public class DataSelectionModel implements Serializable { if (id.startsWith(Program.class.getName())) { // on doit verifier que toutes les marees du program sont sélectionnées List<String> tripIds = datas.get(id); - if (CollectionUtils.isEmpty(tripIds)) { + if (tripIds != null || tripIds.isEmpty()) { // pas de marées return false; diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java b/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java index db47799..dee420c 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/data/TripService.java @@ -5,7 +5,6 @@ import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.tripMap.TripMapPoint; import java.util.List; diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/operation/ValidationService.java b/observe-services-api/src/main/java/fr/ird/observe/services/operation/ValidationService.java index 76f84b5..ff3a0ce 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/operation/ValidationService.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/operation/ValidationService.java @@ -2,7 +2,7 @@ package fr.ird.observe.services.operation; import fr.ird.observe.SendMessageAble; import fr.ird.observe.services.ObserveService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.validation.ValidationMessageDetector; /** diff --git a/observe-services/pom.xml b/observe-services/pom.xml index 821a17d..a8ac043 100644 --- a/observe-services/pom.xml +++ b/observe-services/pom.xml @@ -42,26 +42,14 @@ <artifactId>commons-logging</artifactId> </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> <groupId>commons-primitives</groupId> <artifactId>commons-primitives</artifactId> </dependency> <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </dependency> - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> </dependency> <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - </dependency> - <dependency> <groupId>commons-jxpath</groupId> <artifactId>commons-jxpath</artifactId> </dependency> @@ -80,6 +68,10 @@ <artifactId>nuiton-utils</artifactId> </dependency> <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-decorator</artifactId> + </dependency> + <dependency> <groupId>org.nuiton.i18n</groupId> <artifactId>nuiton-i18n</artifactId> </dependency> @@ -94,13 +86,8 @@ <artifactId>topia-persistence</artifactId> </dependency> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <dependency> - <groupId>postgresql</groupId> - <artifactId>postgresql</artifactId> - <scope>runtime</scope> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-service-replication</artifactId> </dependency> <!-- Logging --> diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index b14e6fa..2fd2fe1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -107,11 +107,6 @@ public abstract class AbstractObserveService implements ObserveService { } - @Override - public void close() { - //TODO - } - public TopiaContext getTransaction() { return serviceContext.getTransaction(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java index d7ed97b..d820490 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/TripServiceImpl.java @@ -15,7 +15,6 @@ import fr.ird.observe.entities.seine.TripSeineDAO; import fr.ird.observe.services.AbstractObserveService; import fr.ird.observe.services.data.longline.TripLonglineService; import fr.ird.observe.services.data.seine.TripSeineService; -import fr.ird.observe.services.model.DataSelectionModel; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.tripMap.TripMapPoint; import org.apache.commons.logging.Log; diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java index 8dab84f..511b351 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java @@ -27,7 +27,7 @@ import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; import fr.ird.observe.services.referential.ReferentialService; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaDAO; diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java index 0079de3..379c0a4 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java @@ -12,8 +12,8 @@ import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.AbstractObserveService; import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.referential.ReferentialService; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.jdbc.Work; diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java index 6fe70a6..381336d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java @@ -6,7 +6,7 @@ import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.services.AbstractObserveService; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.validation.ValidationMessageDetector; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 232fada..0cf87f6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -22,7 +22,7 @@ import fr.ird.observe.entities.referentiel.SpeciesList; import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.AbstractObserveService; import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/pom.xml b/observe-swing/pom.xml index 7745ab5..be7fb50 100644 --- a/observe-swing/pom.xml +++ b/observe-swing/pom.xml @@ -154,14 +154,6 @@ <artifactId>commons-io</artifactId> </dependency> <dependency> - <groupId>commons-primitives</groupId> - <artifactId>commons-primitives</artifactId> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </dependency> - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> </dependency> @@ -170,10 +162,6 @@ <artifactId>commons-beanutils</artifactId> </dependency> <dependency> - <groupId>commons-jxpath</groupId> - <artifactId>commons-jxpath</artifactId> - </dependency> - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> @@ -232,10 +220,6 @@ <!-- persistence --> <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - </dependency> - <dependency> <groupId>org.nuiton.topia</groupId> <artifactId>topia-persistence</artifactId> </dependency> diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java index 5195f51..4d59113 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminTabUIHandler.java @@ -31,7 +31,7 @@ import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListener; import fr.ird.observe.db.event.DataSourceListenerAdapter; import fr.ird.observe.gps.GPSService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.admin.config.SelectDataUI; import fr.ird.observe.ui.admin.resume.ShowResumeUI; import fr.ird.observe.ui.tree.DataSelectionTreeSelectionModel; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java index 79238c5..bf5b478 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/AdminUIModel.java @@ -35,7 +35,7 @@ import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.Trips; import fr.ird.observe.report.model.Report; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.admin.consolidate.ConsolidateModel; import fr.ird.observe.ui.admin.export.ExportModel; import fr.ird.observe.ui.admin.gps.ImportGPSModel; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx b/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx index f55f2c7..88947f2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/config/SelectDataUI.jaxx @@ -27,7 +27,7 @@ <fr.ird.observe.ui.admin.AdminTabUI> <import> - fr.ird.observe.services.model.DataSelectionModel + fr.ird.observe.services.data.DataSelectionModel fr.ird.observe.ui.UIHelper fr.ird.observe.ui.admin.AdminUI fr.ird.observe.ui.admin.AdminStep diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java index 77aaa3d..05e81ae 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/consolidate/ConsolidateUIHandler.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.admin.consolidate; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.services.operation.ComputeDataService; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUI; @@ -115,6 +115,7 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { } public WizardState doAction() throws Exception { + if (log.isDebugEnabled()) { log.debug(this); } @@ -130,16 +131,7 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { Set<String> tripIds = model.getSelectionDataModel().getSelectedData(); ComputeDataService service = ObserveContext.getService(getStepModel().getSource(), ComputeDataService.class); - - try { - - service.consolidateTrips(this, tripIds); - - } finally { - - service.close(); - - } + service.consolidateTrips(this, tripIds); sendMessage(t("observe.message.consolidate.operation.done", new Date())); @@ -147,7 +139,6 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { } - protected WizardState initDB() throws Exception { // on recupere la source de données @@ -157,6 +148,7 @@ public class ConsolidateUIHandler extends AdminTabUIHandler { openSource(source); return null; + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java index 959dd3f..1de7455 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportModel.java @@ -27,7 +27,7 @@ import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.admin.AdminActionModel; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminUIModel; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java index 6d5d320..debdcb4 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/export/ExportUIHandler.java @@ -30,7 +30,7 @@ import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUI; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java index 1f62ecb..1136c41 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/report/ReportUIHandler.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.admin.report; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.report.model.DataMatrix; import fr.ird.observe.report.model.Report; import fr.ird.observe.report.model.ReportExecute; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java index 0f5f8f8..030b302 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/synchronize/SynchronizeUIHandler.java @@ -39,7 +39,7 @@ import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.editor.MyDefaultCellEditor; import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.wizard.ext.WizardState; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java index 7255057..591ba54 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/admin/validate/ValidateUIHandler.java @@ -28,9 +28,8 @@ import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.operation.ValidationService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.admin.AdminStep; import fr.ird.observe.ui.admin.AdminTabUI; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index b98435a..024908d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -740,7 +740,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C CatchLonglineUI ui = getUi(); - Branchline branchline = ui.getBranchlineBean(); + Branchline branchlineBean = ui.getBranchlineBean(); SwingValidator<Branchline> branchlineValidator = ui.getBranchlineValidator(); if (newValue == null) { @@ -757,11 +757,11 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C log.info("Use branchline: " + newValue); } - branchlineValidator.setBean(branchline); + branchlineValidator.setBean(branchlineBean); CatchLonglineService service = getService(CatchLonglineService.class); Branchline loadedBranchline = service.loadBranchlineForEdit(newValue.getTopiaId()); - copy(Branchline.class, BinderService.EDIT_CATCH_LONGLINE, loadedBranchline, getUi().getBranchlineBean()); + copy(Branchline.class, BinderService.EDIT_CATCH_LONGLINE, loadedBranchline, branchlineBean); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java index c46692a..dde779f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java @@ -28,7 +28,7 @@ import fr.ird.observe.db.DataSourceFactory; import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.impl.PGDataSource; import fr.ird.observe.db.impl.PGDataSourceConfig; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.db.util.PGInstall; import jaxx.runtime.JAXXContext; import org.apache.commons.logging.Log; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java index ec33e90..6204932 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageBackupUILauncher.java @@ -25,7 +25,7 @@ import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.H2DataSource; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import jaxx.runtime.JAXXContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java index 9f98482..25cfce6 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java @@ -46,7 +46,7 @@ import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.ReplicationService; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.storage.tabs.RolesTableModel; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java index e2ba79f..21fbb9a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java @@ -32,7 +32,7 @@ import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.H2DataSourceConfig; import fr.ird.observe.db.impl.PGDataSourceConfig; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.db.util.PGInstall; import fr.ird.observe.db.util.SecurityModel; import jaxx.runtime.JAXXContext; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java index 7883989..89df7d8 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java @@ -29,7 +29,7 @@ import fr.ird.observe.db.constants.ConnexionStatus; import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.impl.PGDataSourceConfig; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.storage.StorageStep; import fr.ird.observe.ui.storage.StorageUIHandler; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java index 003fcdc..26a91ad 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/DataSelectionTreeSelectionModel.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.tree; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java index 958be96..877fd62 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveDataProvider.java @@ -24,7 +24,7 @@ package fr.ird.observe.ui.tree; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.services.ObserveService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import jaxx.runtime.swing.nav.NavDataProvider; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeBridge.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeBridge.java index 36257a6..ab4aabb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeBridge.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeBridge.java @@ -22,7 +22,7 @@ package fr.ird.observe.ui.tree; import jaxx.runtime.swing.nav.tree.NavTreeBridge; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java index f9f1baf..11a32ce 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/ObserveTreeHelper.java @@ -36,7 +36,7 @@ import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.Route; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.tree.loadors.AbstractNodeChildLoador; @@ -51,7 +51,7 @@ import fr.ird.observe.ui.tree.loadors.RoutesNodeChildLoador; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.nav.tree.NavTreeHelper; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java index 42409b3..7a1b531 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/AbstractNodeChildLoador.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.tree.loadors; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import jaxx.runtime.swing.nav.NavDataProvider; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java index 41a85e7..479aed3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramLonglineNodeChildLoador.java @@ -24,14 +24,14 @@ package fr.ird.observe.ui.tree.loadors; import fr.ird.observe.entities.longline.TripLongline; import fr.ird.observe.services.data.longline.TripLonglineService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import fr.ird.observe.ui.tree.TripLonglineNode; import jaxx.runtime.swing.nav.NavDataProvider; import jaxx.runtime.swing.nav.tree.NavTreeBridge; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; import java.util.List; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java index edd8dae..acafac2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/ProgramSeineNodeChildLoador.java @@ -23,14 +23,14 @@ package fr.ird.observe.ui.tree.loadors; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.data.seine.TripSeineService; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; import fr.ird.observe.ui.tree.ObserveTreeHelper; import fr.ird.observe.ui.tree.TripSeineNode; import jaxx.runtime.swing.nav.NavDataProvider; import jaxx.runtime.swing.nav.tree.NavTreeBridge; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; import java.util.List; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java index 6b19743..1b5d6f1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/tree/loadors/RootNodeChildLoador.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.tree.loadors; import fr.ird.observe.entities.constants.GearType; import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.services.data.DataSelectionModel; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.tree.ObserveDataProvider; import fr.ird.observe.ui.tree.ObserveNode; diff --git a/pom.xml b/pom.xml index f3e32b7..f460a4f 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,19 @@ </developer> <developer> + <id>bavencoff</id> + <name>Sylvain Bavencoff</name> + <email>bavencoff@codelutin.com</email> + <organization>CodeLutin</organization> + <organizationUrl>http://codelutin.com</organizationUrl> + <roles> + <role>lead</role> + <role>developer</role> + </roles> + <timezone>Europe/Paris</timezone> + </developer> + + <developer> <id>couteau</id> <name>Jean Couteau</name> <email>couteau@codelutin.com</email> @@ -82,9 +95,9 @@ <modules> <module>observe-entities</module> <module>observe-business</module> + <module>observe-validation</module> <module>observe-services-api</module> <module>observe-services</module> - <module>observe-validation</module> <module>observe-swing</module> </modules> <!--scm> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 83ebc2c82bf27e38ad3ead3216f84f32490f5683 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 4 18:12:07 2015 +0200 fix propriété des equipements --- .../services/data/longline/GearUseFeaturesLonglineServiceImpl.java | 5 +++-- .../observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index e15cd70..8df0884 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -17,6 +17,7 @@ import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * Created on 4/26/15. @@ -174,8 +175,8 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i if (Entities.isNew(measurementToSave)) { - measurementSaved = dao.create(GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); - binder.load(measurementToSave, measurementSaved, false); + Map<String, Object> properties = binder.obtainProperties(measurementToSave); + measurementSaved = dao.create(properties); } else { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index 3c2b147..80e31d4 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -17,6 +17,7 @@ import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * Created on 4/26/15. @@ -176,8 +177,8 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl if (Entities.isNew(measurementToSave)) { - measurementSaved = dao.create(GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); - binder.load(measurementToSave, measurementSaved, false); + Map<String, Object> properties = binder.obtainProperties(measurementToSave); + measurementSaved = dao.create(properties); } else { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit bfd370b71e70860cecef055036fb34557cb8de70 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 08:37:08 2015 +0200 Amélioration du code pour créer des entities (on passe toujours par un binder.obtainProperties) (refs #7017) --- .../observe/services/AbstractObserveService.java | 9 +++- .../data/longline/ActivityLonglineServiceImpl.java | 5 ++- .../BranchlinesCompositionServiceImpl.java | 1 - .../data/longline/CatchLonglineServiceImpl.java | 9 ++-- .../GearUseFeaturesLonglineServiceImpl.java | 8 ++-- .../LonglineGlobalCompositionServiceImpl.java | 1 + .../data/longline/SetLonglineServiceImpl.java | 7 +-- .../data/longline/TripLonglineServiceImpl.java | 5 ++- .../data/seine/ActivitySeineServiceImpl.java | 11 +++-- .../data/seine/FloatingObjectServiceImpl.java | 11 +++-- .../seine/GearUseFeaturesSeineServiceImpl.java | 5 +-- .../data/seine/NonTargetSampleServiceImpl.java | 6 ++- .../services/data/seine/RouteServiceImpl.java | 5 ++- .../services/data/seine/SetSeineServiceImpl.java | 11 ++--- .../services/data/seine/TripSeineServiceImpl.java | 5 ++- .../referential/ReferentialServiceImpl.java | 50 +++------------------- 16 files changed, 60 insertions(+), 89 deletions(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 2fd2fe1..cb8290b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Map; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com @@ -143,6 +144,10 @@ public abstract class AbstractObserveService implements ObserveService { getBinderService().copy(type, context, source, target, bindTechnical); } + public <E extends TopiaEntity> Map<String, Object> obtainProperties(Class<E> type, String context, E source) { + return getBinder(type, context).obtainProperties(source); + } + public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> entityClass, String contextName) { return getBinderService().getBinder(entityClass, contextName); } @@ -417,8 +422,8 @@ public abstract class AbstractObserveService implements ObserveService { public E onCreateChild(E childToCreate) { - E childCreated = getDao(entityClass).create(); - childBinder.load(childToCreate, childCreated, false); + Map<String, Object> properties = childBinder.obtainProperties(childToCreate); + E childCreated = getDao(entityClass).create(properties); return childCreated; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index 43b3dd8..6540b46 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -10,6 +10,7 @@ import fr.ird.observe.services.AbstractObserveService; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Map; /** * Created on 4/25/15. @@ -99,8 +100,8 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen @Override public ActivityLongline onCreate(TripLongline parent, ActivityLongline toCreate) { - ActivityLongline created = getDao().create(); - copy(ActivityLongline.class, BinderService.EDIT, toCreate, created, false); + Map<String, Object> properties = obtainProperties(ActivityLongline.class, BinderService.EDIT, toCreate); + ActivityLongline created = getDao().create(properties); parent.addActivityLongline(created); return created; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java index 0eb34f6..d8c933e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java @@ -59,7 +59,6 @@ public class BranchlinesCompositionServiceImpl extends AbstractObserveService im doSaveList(setLongline, new SaveCollectionAction<SetLongline, BranchlinesComposition>( SetLongline.class, BranchlinesComposition.class, getListUpdator(), parentBinder, childBinder)); - } protected EntityListUpdator<SetLongline, BranchlinesComposition> getListUpdator() { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java index 4703ac7..511768d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -19,6 +19,7 @@ import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; /** * Created on 4/26/15. @@ -126,8 +127,8 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements if (Entities.isNew(sizeMeasureToSave)) { - sizeMeasureSaved = dao.create(); - binder.load(sizeMeasureToSave, sizeMeasureSaved, false); + Map<String, Object> properties = binder.obtainProperties(sizeMeasureToSave); + sizeMeasureSaved = dao.create(properties); } else { @@ -162,8 +163,8 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements if (Entities.isNew(weightMeasureToSave)) { - weightMeasureSaved = dao.create(); - binder.load(weightMeasureToSave, weightMeasureSaved, false); + Map<String, Object> properties = binder.obtainProperties(weightMeasureToSave); + weightMeasureSaved = dao.create(properties); } else { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index 8df0884..ec780c6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -143,11 +143,7 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public GearUseFeaturesLongline onCreateChild(GearUseFeaturesLongline childToCreate) { - GearUseFeaturesLongline childCreated = getDao(entityClass).create( - GearUseFeaturesLongline.PROPERTY_GEAR, childToCreate.getGear(), - GearUseFeaturesLongline.PROPERTY_NUMBER, childToCreate.getNumber() - ); - childBinder.load(childToCreate, childCreated, false); + GearUseFeaturesLongline childCreated = super.onCreateChild(childToCreate); saveMeasurement(childCreated, childToCreate.getGearUseFeaturesMeasurement()); return childCreated; @@ -155,9 +151,11 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToUpdate) { + GearUseFeaturesLongline childUpdated = super.onUpdateChild(childToUpdate); saveMeasurement(childUpdated, childToUpdate.getGearUseFeaturesMeasurement()); return childUpdated; + } protected void saveMeasurement(GearUseFeaturesLongline childSaved, List<GearUseFeaturesMeasurementLongline> measurementsToSave) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java index 9e5060f..3785293 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java @@ -59,6 +59,7 @@ public class LonglineGlobalCompositionServiceImpl extends AbstractObserveService newService(BaitsCompositionService.class).save(toSave); return saved.getTopiaId(); + } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index 1ed6810..7f7c1aa 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -14,6 +14,7 @@ import org.nuiton.topia.persistence.TopiaDAO; import java.util.Date; import java.util.List; +import java.util.Map; /** * Created on 4/26/15. @@ -125,9 +126,8 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se @Override public SetLongline onCreate(ActivityLongline parent, SetLongline toCreate) { - SetLongline created = getDao().create(); - copy(SetLongline.class, BinderService.EDIT, toCreate, created, false); - + Map<String, Object> properties = obtainProperties(SetLongline.class, BinderService.EDIT, toCreate); + SetLongline created = getDao().create(properties); parent.setSetLongline(created); return created; @@ -154,6 +154,7 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se }); return setLonglineId; + } @Override diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java index 0d522b6..6c505ca 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java @@ -11,6 +11,7 @@ import org.nuiton.util.DateUtil; import java.util.Date; import java.util.List; +import java.util.Map; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com @@ -103,8 +104,8 @@ public class TripLonglineServiceImpl extends AbstractObserveService implements T @Override public TripLongline onCreate(Program parent, TripLongline toCreate) { - TripLongline created = getDao().create(); - copy(TripLongline.class, BinderService.EDIT, toCreate, created, false); + Map<String, Object> properties = obtainProperties(TripLongline.class, BinderService.EDIT, toCreate); + TripLongline created = getDao().create(properties); return created; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index c83dad2..c5328ba 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -13,6 +13,7 @@ import org.nuiton.util.DateUtil; import java.util.Date; import java.util.List; +import java.util.Map; /** * Created on 4/24/15. @@ -78,7 +79,7 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements if (lastActivitySeine == null) { // première activité, on utilise l'heure courante - time = new Date(); + time = serviceContext.now(); } else { @@ -121,10 +122,11 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements SchoolType newTypeBanc = toUpdate.getSchoolType(); SetSeine set = toUpdate.getSetSeine(); if (set != null) { - // on regarde si le type de banc de la calée a changé + // on regarde si le type de banc de la calée a changé SchoolType oldTypeBanc = set.getSchoolType(); needUpdateSet = oldTypeBanc == null || newTypeBanc != oldTypeBanc; + } ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); @@ -135,6 +137,7 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements // mise à jour de la propriété schoolType dans la set updated.getSetSeine().setSchoolType(newTypeBanc); + } return updated; @@ -150,8 +153,8 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements @Override public ActivitySeine onCreate(Route parent, ActivitySeine toCreate) { - ActivitySeine created = getDao().create(); - copy(ActivitySeine.class, BinderService.EDIT, toCreate, created, false); + Map<String, Object> properties = obtainProperties(ActivitySeine.class, BinderService.EDIT, toCreate); + ActivitySeine created = getDao().create(properties); parent.addActivitySeine(created); return created; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index 6a1df52..d9174e3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -112,10 +112,9 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject onCreate(ActivitySeine parent, FloatingObject toCreate) { - FloatingObject created = getDao().create(); - copy(FloatingObject.class, BinderService.EDIT, toCreate, created, false); + Map<String, Object> properties = obtainProperties(FloatingObject.class, BinderService.EDIT, toCreate); + FloatingObject created = getDao().create(properties); parent.addFloatingObject(created); - return created; } @@ -124,9 +123,9 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements public FloatingObject onUpdate(ActivitySeine parent, FloatingObject toUpdate) { FloatingObject updated = super.onUpdate(parent, toUpdate); - copy(FloatingObject.class, BinderService.EDIT, toUpdate, updated, true); return updated; + } }); @@ -155,8 +154,8 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements if (Entities.isNew(transmittingBuoyToSave)) { // creation de la balise - Map<String, Object> map = binder.obtainProperties(transmittingBuoyToSave); - transmittingBuoySaved = transmittingBuoyDAO.create(map); + Map<String, Object> properties = binder.obtainProperties(transmittingBuoyToSave); + transmittingBuoySaved = transmittingBuoyDAO.create(properties); } else { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index 80e31d4..2d01767 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -144,10 +144,7 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public GearUseFeaturesSeine onCreateChild(GearUseFeaturesSeine childToCreate) { - GearUseFeaturesSeine childCreated = getDao(entityClass).create( - GearUseFeaturesSeine.PROPERTY_GEAR, childToCreate.getGear(), - GearUseFeaturesSeine.PROPERTY_NUMBER, childToCreate.getNumber()); - this.childBinder.load(childToCreate, childCreated, false); + GearUseFeaturesSeine childCreated = super.onCreateChild(childToCreate); saveMeasurement(childCreated, childToCreate.getGearUseFeaturesMeasurement()); return childCreated; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index 90189f1..31c52aa 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -19,6 +19,7 @@ import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -157,6 +158,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement NonTargetSampleDAO dao = getDao(); + //FIXME Use obtainPropertiesExcluding NonTargetSample created = dao.create(); copyExcluding(NonTargetSample.class, BinderService.EDIT, toCreate, created, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); parent.addNonTargetSample(created); @@ -197,8 +199,8 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement if (Entities.isNew(nonTargetLengthToSave)) { - nonTargetLengthSaved = dao.create(); - binder.load(nonTargetLengthToSave, nonTargetLengthSaved, false); + Map<String, Object> properties = binder.obtainProperties(nonTargetLengthToSave); + nonTargetLengthSaved = dao.create(properties); } else { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java index 83425be..7d86f73 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/RouteServiceImpl.java @@ -11,6 +11,7 @@ import org.nuiton.util.DateUtil; import java.util.Date; import java.util.List; +import java.util.Map; /** * Created on 4/24/15. @@ -95,8 +96,8 @@ public class RouteServiceImpl extends AbstractObserveService implements RouteSer @Override public Route onCreate(TripSeine parent, Route toCreate) { - Route created = getDao().create(); - copy(Route.class, BinderService.EDIT, toCreate, created); + Map<String, Object> properties = obtainProperties(Route.class, BinderService.EDIT, toCreate); + Route created = getDao().create(properties); parent.addRoute(created); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java index d988099..54d1384 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java @@ -12,6 +12,7 @@ import fr.ird.observe.services.AbstractObserveService; import org.nuiton.util.DateUtil; import java.util.Date; +import java.util.Map; /** * Created on 4/24/15. @@ -99,8 +100,8 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe @Override public SetSeine onCreate(ActivitySeine parent, SetSeine toCreate) { - SetSeine created = getDao().create(); - copy(SetSeine.class, BinderService.EDIT, toCreate, created); + Map<String, Object> properties = obtainProperties(SetSeine.class, BinderService.EDIT, toCreate); + SetSeine created = getDao().create(properties); parent.setSetSeine(created); @@ -124,6 +125,7 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe }); return setSeineId; + } @@ -131,13 +133,12 @@ public class SetSeineServiceImpl extends AbstractObserveService implements SetSe public void delete(String activitySeineId, String setSeineId) { // on doit supprimer physiquement la set - // car il n'y a pas de delete-orphan sur une telle - // relation + // car il n'y a pas de delete-orphan sur une telle relation SetSeineDAO dao = getDao(); SetSeine setSeine = dao.findByTopiaId(setSeineId); dao.delete(setSeine); - // supprime la reference sur l'activity + // supprime la reference sur l'activité ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); activitySeine.setSetSeine(null); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java index 8d75881..7c63b1b 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java @@ -11,6 +11,7 @@ import org.nuiton.util.DateUtil; import java.util.Date; import java.util.List; +import java.util.Map; /** * Created on 4/24/15. @@ -107,8 +108,8 @@ public class TripSeineServiceImpl extends AbstractObserveService implements Trip @Override public TripSeine onCreate(Program parent, TripSeine toCreate) { - TripSeine created = getDao().create(); - copy(TripSeine.class, BinderService.EDIT, toCreate, created); + Map<String, Object> properties = obtainProperties(TripSeine.class, BinderService.EDIT, toCreate); + TripSeine created = getDao().create(properties); return created; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 0cf87f6..9e220db 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -3,7 +3,6 @@ package fr.ird.observe.services.referential; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.ReferenceStatus; @@ -37,7 +36,6 @@ import org.nuiton.topia.persistence.util.TopiaEntityRef; import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -74,6 +72,7 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re result = allProgramStub.indexOf(programStub); } return result; + } @Override @@ -95,6 +94,7 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re binder.obtainProperties(entity); } return Lists.newArrayList(entities); + } @Override @@ -245,7 +245,6 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } - } if (CollectionUtils.isEmpty(list)) { @@ -329,31 +328,15 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re @Override public <R extends ReferenceEntity> String save(R toSave) { - Class<R> entityType = (Class<R>) ObserveEntityEnum.valueOf(toSave).getContract(); + Class<R> entityType = getEntityContractClass(toSave); String referentialId = doSave(null, toSave, new SaveAction<R, R>(entityType, entityType) { @Override public R onCreate(R parent, R toCreate) { - R created; - - if (getNaturalIds().containsKey(entityClass)) { - - // utilisation d'un clef naturelle - String[] naturalIdPropertyNames = getNaturalIds().get(entityClass); - TopiaEntityBinder<R> binder = getBinder(entityClass, BinderService.EDIT); - Map<String, Object> naturalIdValue = binder.obtainProperties(toCreate, naturalIdPropertyNames); - - created = getDao(entityClass).create(naturalIdValue); - copyExcluding(entityClass, BinderService.EDIT, toCreate, created, false, naturalIdPropertyNames); - - } else { - - created = getDao(entityClass).create(); - copy(entityClass, BinderService.EDIT, toCreate, created, false); - - } + Map<String, Object> properties = obtainProperties(entityClass, BinderService.EDIT, toCreate); + R created = getDao(entityClass).create(properties); return created; @@ -380,7 +363,6 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } - @Override public void deleteEntities(Collection<String> entityIds) { @@ -533,26 +515,4 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } - protected static Map<Class<? extends ReferenceEntity>, String[]> NATURAL_IDS; - - protected static Map<Class<? extends ReferenceEntity>, String[]> getNaturalIds() { - if (NATURAL_IDS == null) { - NATURAL_IDS = new HashMap<Class<? extends ReferenceEntity>, String[]>(); - - NATURAL_IDS.put(LengthWeightParameter.class, new String[]{ - LengthWeightParameter.PROPERTY_SEX, - LengthWeightParameter.PROPERTY_OCEAN, - LengthWeightParameter.PROPERTY_SPECIES, - LengthWeightParameter.PROPERTY_START_DATE, - }); - - NATURAL_IDS.put(WeightCategory.class, new String[]{ - WeightCategory.PROPERTY_CODE, - WeightCategory.PROPERTY_SPECIES - }); - - - } - return NATURAL_IDS; - } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 4aab2fdd4a75587f7c1cdd19bb7ca0d39076b747 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 09:05:51 2015 +0200 correction de la validation des onglets (refs #7017) --- .../ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java index 34e4f92..7c19348 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java @@ -145,9 +145,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { super.initUI(); - // listen messages to see if required to add - reloadTableModelListener(getUi().getErrorTableModel(), computeTabValidStateListener); - getUi().getSettingStartTimeStamp().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); getUi().getSettingEndTimeStamp().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); getUi().getHaulingStartTimeStamp().getSliderHidor().addPropertyChangeListener(HidorButton.PROPERTY_TARGET_VISIBLE, onToogleTimeEditorSliderChangedListener); @@ -230,6 +227,10 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { setContentMode(mode); SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); + + // ecoute les message pour savoir si les onglets sont valides + reloadTableModelListener(getUi().getErrorTableModel(), computeTabValidStateListener); + computeTabValidState(errorTableModel); if (ContentMode.READ != mode) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 5277cd7e1b9812eb98537e1ff990ce6585461a84 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 14:26:45 2015 +0200 Capture : enregistrement de l'avançon, désactivation du champs "santé au rejet", Enregistrement des profondeur : erreur au changement de ligne, Estimation banc : affectation de la seine au estimation des banc avant l'enregistrement. --- .../ui/content/table/impl/longline/CatchLonglineUIHandler.java | 4 +++- .../ui/content/table/impl/longline/LonglinePositionHelper.java | 2 +- .../ui/content/table/impl/seine/SchoolEstimateUIHandler.java | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 024908d..3c9a6b2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -501,6 +501,8 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } reloadPropertyChangeListener(bean, CatchLongline.PROPERTY_CATCH_FATE_LONGLINE, catchFateChanged); + onCatchFateChanged(bean.getCatchFateLongline(), bean); + reloadPropertyChangeListener(bean, CatchLongline.PROPERTY_BRANCHLINE, branchlineChanged); reloadPropertyChangeListener(bean, CatchLongline.PROPERTY_DEPREDATED, depredatedChanged); @@ -586,7 +588,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C log.info("Saved modified branchline"); } - Branchline branchline = getTableEditBean().getBranchline(); + Branchline branchline = getUi().getBranchlineBean(); CatchLonglineService service = getService(CatchLonglineService.class); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java index 69c4b5d..c94fe92 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/LonglinePositionHelper.java @@ -316,7 +316,7 @@ public class LonglinePositionHelper<E extends LonglinePositionAware> { // un panier est selectionne - Basket newValueInUniverse = findInList(uiBasket.getData(), newValue.getTopiaId()); + Basket newValueInUniverse = findInList(basketUniverse, newValue.getTopiaId()); // on remplit uniquement les avançons des paniers List<Branchline> branchlines = newValueInUniverse.getBranchline(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index ec76626..f64a372 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.constants.DataContextType; @@ -46,7 +47,6 @@ import javax.swing.JComponent; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -158,7 +158,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } else { Species species = bean.getSpecies(); - availableSpecies= Collections.singletonList(species); + availableSpecies= Lists.newArrayList(species); requestFocus = getUi().getTotalWeight(); } @@ -173,6 +173,10 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch @Override protected void doPersist(SetSeine editBean) { + for (SchoolEstimate schoolEstimate : editBean.getSchoolEstimate()) { + schoolEstimate.setSetSeine(editBean); + } + SchoolEstimateService service = getService(SchoolEstimateService.class); service.save(editBean); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 6ae8805caca7eae804cf5c1bc417c8019fde5afa Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 15:27:08 2015 +0200 correction sur la sauvegarde d'une entite du referentiel (refs #7017) --- .../fr/ird/observe/services/referential/ReferentialServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 9e220db..6e6017a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -346,7 +346,7 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re public R onUpdate(R parent, R toUpdate) { R updated = super.onUpdate(parent, toUpdate); - copyExcluding(entityClass, BinderService.EDIT, toUpdate, updated); + copy(entityClass, BinderService.EDIT, toUpdate, updated); return updated; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 6dd624e73ffe037bf5d06d354f306c4d0d00044c Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 5 15:27:29 2015 +0200 mise en place du cache sur les listes de référentiels (refs #7017) --- .../main/java/fr/ird/observe/ObserveContext.java | 30 +- .../ird/observe/ui/content/ContentUIHandler.java | 34 +- .../observe/ui/content/ContentUIInitializer.java | 513 +++++++++------------ .../ird/observe/ui/content/ObserveContentUI.java | 2 - .../ird/observe/ui/content/ReferentialCache.java | 115 +++++ .../ui/content/ref/ContentReferenceUIHandler.java | 76 ++- .../ref/ReferentialContentUIInitializer.java | 122 ++--- .../table/impl/longline/CatchLonglineUI.css | 3 - .../ui/content/table/impl/longline/TdrUI.css | 3 - .../ui/util/ReferentielListCellRenderer.java | 80 ++++ .../observe/ui/util/TooltipListCellRenderer.java | 44 ++ 11 files changed, 619 insertions(+), 403 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java index 8eafd51..e63103e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveContext.java @@ -28,6 +28,7 @@ import fr.ird.observe.db.constants.DbMode; import fr.ird.observe.db.event.DataSourceEvent; import fr.ird.observe.db.event.DataSourceListenerAdapter; import fr.ird.observe.db.impl.H2DataSource; +import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.services.ObserveService; import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.ObserveServicesCache; @@ -51,6 +52,7 @@ import fr.ird.observe.ui.actions.shared.SaveEditUIAction; import fr.ird.observe.ui.actions.shared.SelectNodeUIAction; import fr.ird.observe.ui.actions.shared.SelectOpenNodeUIAction; import fr.ird.observe.ui.content.ContentUI; +import fr.ird.observe.ui.content.ReferentialCache; import fr.ird.observe.ui.tree.ObserveTreeHelper; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.CardLayout2; @@ -106,6 +108,12 @@ public class ObserveContext extends ObserveApplicationContext { public static final JAXXContextEntryDef<List<String>> NODE_TO_RESELECT_ENTRY_DEF = UIHelper.newListContextEntryDef("nodeToReselect"); + protected final ObserveServiceFactory serviceFactory = new ObserveServiceFactory(this); + + protected final ObserveServicesCache servicesCache = new ObserveServicesCache(serviceFactory); + + protected final ReferentialCache referentialCache = new ReferentialCache(); + /** * Récupération du contexte applicatif. * @@ -247,6 +255,14 @@ public class ObserveContext extends ObserveApplicationContext { return service; } + public static <R extends ReferenceEntity> ReferentialCache.ReferentialList<R> getReferentialList(Class<R> referentialCache) { + return get().referentialCache.getReferentialList(referentialCache); + } + + public static <R extends ReferenceEntity> void invalidateReferentialList(Class<R> referentialCache) { + get().referentialCache.clearEntry(referentialCache); + } + public void initStorage(ObserveConfig config, ObserveMainUI mainUI, boolean askToCreate) { try { if (config.isLocalStorageExist()) { @@ -385,9 +401,10 @@ public class ObserveContext extends ObserveApplicationContext { @Override public void onOpening(DataSourceEvent event) { + DataSource s = event.getSource(); - UIHelper.displayInfo( - t("observe.message.db.loading", s.getLabel())); + UIHelper.displayInfo(t("observe.message.db.loading", s.getLabel())); + } @Override @@ -423,8 +440,6 @@ public class ObserveContext extends ObserveApplicationContext { super.onClosing(event); - DataSource source = event.getSource(); - // on désenregistre la source du service de données ObserveServiceHelper.get().setDataSource(null); @@ -440,6 +455,9 @@ public class ObserveContext extends ObserveApplicationContext { mainUI.getTreeHelper().cleanNavigationUI(mainUI); + // clear referential cache + referentialCache.clear(); + // on met a jour l'état dans la config getConfig().setMainStorageOpened(false); } @@ -543,8 +561,4 @@ public class ObserveContext extends ObserveApplicationContext { actionMap.put(actionId, action); } - private final ObserveServiceFactory serviceFactory = new ObserveServiceFactory(this); - - protected final ObserveServicesCache servicesCache = new ObserveServicesCache(serviceFactory); - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 68732e2..8dc2c90 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -40,6 +40,7 @@ import fr.ird.observe.ui.tree.ObserveTreeHelper; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.JAXXButtonGroup; +import jaxx.runtime.swing.editor.bean.BeanComboBox; import jaxx.runtime.swing.editor.bean.BeanListHeader; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import jaxx.runtime.validator.swing.SwingValidatorUtil; @@ -50,6 +51,7 @@ import org.nuiton.decorator.Decorator; import org.nuiton.decorator.DecoratorUtil; import org.nuiton.decorator.JXPathDecorator; import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor; +import org.nuiton.jaxx.widgets.select.FilterableDoubleList; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; @@ -67,6 +69,7 @@ import java.awt.Component; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; +import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -345,6 +348,8 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { ui.setContentIcon(render.getNavigationIcon(node)); updateActions(); + + updateReferentials(); } public Icon getErrorIconIfFalse(boolean valid) { @@ -637,9 +642,34 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } protected final String getValidatorContextName(ContentMode mode) { - String contextName = - mode == ContentMode.CREATE ? "n1-create" : "n1-update"; + + String contextName = mode == ContentMode.CREATE ? "n1-create" : "n1-update"; return contextName; + + } + + @SuppressWarnings("unchecked") + protected void updateReferentials() { + + Set<String> referentialComponantNames = (Set<String>) ((JComponent) getUi()).getClientProperty(ContentUIInitializer.CLIENT_PROPERTY_REFERENTIAL_COMPONANTS); + for (String referentialComponantName : referentialComponantNames) { + + Object o = getUi().get$objectMap().get(referentialComponantName); + if (o instanceof BeanComboBox) { + + ContentUIInitializer.reload((BeanComboBox<ReferenceEntity>) o); + + } else if (o instanceof BeanListHeader) { + + ContentUIInitializer.reload((BeanListHeader<ReferenceEntity>) o); + + } else if (o instanceof FilterableDoubleList) { + + ContentUIInitializer.reload((FilterableDoubleList<ReferenceEntity>) o); + + } + } + } protected final <S extends ObserveService> S getService(Class<S> serviceType) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java index ac16b84..bd78fdd 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIInitializer.java @@ -23,18 +23,19 @@ package fr.ird.observe.ui.content; */ import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.entities.constants.ReferenceStatus; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.ReferenceEntity; -import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.actions.shared.AbstractUIAction; import fr.ird.observe.ui.util.BooleanEditor; +import fr.ird.observe.ui.util.ReferentielListCellRenderer; +import fr.ird.observe.ui.util.TooltipListCellRenderer; import fr.ird.observe.ui.util.tripMap.ObserveMapPane; import fr.ird.observe.util.DBHelper; import fr.ird.observe.validation.ObserveValidator; @@ -73,7 +74,6 @@ import javax.swing.ActionMap; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; -import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JScrollBar; import javax.swing.JSpinner; @@ -85,7 +85,6 @@ import javax.swing.SwingUtilities; import javax.swing.border.LineBorder; import javax.swing.table.TableCellEditor; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -95,8 +94,6 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -104,8 +101,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import static org.nuiton.i18n.I18n.t; - /** * To initialize ui. * @@ -124,9 +119,17 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte public static final String CLIENT_PROPERTY_NOT_BLOCKING = "notBlocking"; + public static final String CLIENT_PROPERTY_REFERENTIAL_COMPONANTS = "referentialComponants"; + /** Logger. */ private static final Log log = LogFactory.getLog(ContentUIInitializer.class); + public static final String CLIENT_PROPERTY_REFERENTIAL_LIST_TIME_STAMP = "referentialListTimeStamp"; + + public static final String CLIENT_PROPERTY_DECORATOR = "decorator"; + + public static final String CLIENT_PROPERTY_DATA = "data"; + protected final UI ui; public ContentUIInitializer(UI ui) { @@ -212,6 +215,8 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte DecoratorService decoratorService = ObserveContext.get().getDecoratorService(); + Set<String> referentialLists = new HashSet<String>(); + for (String name : ui.get$objectMap().keySet()) { Object o = ui.getObjectById(name); @@ -244,17 +249,17 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } if (o instanceof BeanComboBox<?>) { - init(dataSource, (BeanComboBox<?>) o); + init(referentialLists, (BeanComboBox<?>) o); continue; } if (o instanceof BeanListHeader<?>) { - init(dataSource, decoratorService, (BeanListHeader<?>) o); + init(referentialLists, decoratorService, (BeanListHeader<?>) o); continue; } if (o instanceof FilterableDoubleList<?>) { - init(dataSource, (FilterableDoubleList<?>) o); + init(referentialLists, (FilterableDoubleList<?>) o); continue; } @@ -307,6 +312,9 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte initBlockLayerUI(acceptedComponentNames); } + + ((JComponent) ui).putClientProperty(CLIENT_PROPERTY_REFERENTIAL_COMPONANTS, referentialLists); + } protected void initBlockLayerUI(String... doNotBlockComponentIds) { @@ -384,18 +392,18 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte } @SuppressWarnings("unchecked") - protected void init(DataSource dataSource, BeanComboBox beanComboBox) { - Class<ReferenceEntity> klass = (Class<ReferenceEntity>) beanComboBox.getHandler().getBeanType(); + protected void init(Set<String> referentialLists, BeanComboBox beanComboBox) { + Class<TopiaEntity> klass = (Class<TopiaEntity>) beanComboBox.getHandler().getBeanType(); if (log.isDebugEnabled()) { log.debug("init combobox for " + klass); } beanComboBox.setI18nPrefix("observe.common."); beanComboBox.setMinimumSize(new Dimension(0, 24)); - prepareBeanComboBox(dataSource, klass, beanComboBox); + prepareBeanComboBox(referentialLists, klass, beanComboBox); } @SuppressWarnings("unchecked") - protected void init(DataSource dataSource, DecoratorService decoratorService, BeanListHeader beanList) { + protected void init(Set<String> referentialLists, DecoratorService decoratorService, BeanListHeader beanList) { beanList.setI18nPrefix("observe.common."); @@ -403,7 +411,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte log.info("init list for " + beanList.getBeanType()); } - prepareEntityList(dataSource, beanList.getBeanType(), beanList); + prepareEntityList(referentialLists, beanList.getBeanType(), beanList); JList jlist = beanList.getList(); @@ -411,25 +419,23 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte if (init != null) { Class<TopiaEntity> klass = (Class<TopiaEntity>) init; if (log.isDebugEnabled()) { - log.debug("addDecorator to list " + - jlist.getName()); + log.debug("addDecorator to list " + jlist.getName()); } Decorator<TopiaEntity> decorator = decoratorService.getDecoratorByType(klass); - jlist.putClientProperty("decorator", decorator); + jlist.putClientProperty(CLIENT_PROPERTY_DECORATOR, decorator); } init = jlist.getClientProperty("addToogleListSelectionModel"); if (init != null && init instanceof Boolean && (Boolean) init) { if (log.isDebugEnabled()) { - log.debug("addToogleListSelectionModel to list " + - jlist.getName()); + log.debug("addToogleListSelectionModel to list " + jlist.getName()); } prepareToogleListSelectionModel(jlist); } } @SuppressWarnings("unchecked") - protected void init(DataSource dataSource, FilterableDoubleList beanList) throws DataSourceException { + protected void init(Set<String> referentialLists, FilterableDoubleList beanList) throws DataSourceException { beanList.setI18nPrefix("observe.common."); @@ -437,7 +443,7 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte log.info("init list for " + beanList.getBeanType()); } - prepareEntityList(dataSource, beanList.getBeanType(), beanList); + prepareEntityList(referentialLists, beanList.getBeanType(), beanList); } @@ -636,41 +642,45 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param dataSource le service de persistance à utiliser pour - * récupérer les entités - * @param entityClass le type de l'entité - * @param list le component graphique à initialiser + * @param referentialLists l'ensemble pour conserver les noms des composants utilisant des listes de référentiels + * @param entityClass le type de l'entité + * @param list le component graphique à initialiser * @since 1.5 */ @SuppressWarnings("unchecked") - protected <E extends TopiaEntity> void prepareEntityList(DataSource dataSource, Class<E> entityClass, FilterableDoubleList<E> list) { + protected <EE extends TopiaEntity> void prepareEntityList(Set<String> referentialLists, Class<EE> entityClass, FilterableDoubleList<EE> list) { - ObserveContext context = ObserveContext.get(); + List<EE> data; - // init list - Decorator<E> decorator = context.getDecorator(entityClass); - if (log.isDebugEnabled()) { - log.debug("Will use decorator " + decorator); - } + if (ReferenceEntity.class.isAssignableFrom(entityClass)) { - list.putClientProperty("decorator", decorator); - List<E> data; + // On charge la liste depuis le cache de référentiels + ReferentialCache.ReferentialList referentialList = ObserveContext.getReferentialList((Class) entityClass); - if (ReferenceEntity.class.isAssignableFrom(entityClass)) { + data = getReferentialList(list, referentialList, false); - Predicate<E> predicate = (Predicate<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); - data = service.getList(entityClass, predicate); + // on conserve le widget (il sera rechargé si nécessaire à l'ouverture de l'écran) + referentialLists.add(list.getName()); } else { - data = new ArrayList<E>(); + + data = new ArrayList<EE>(); + + } + + ObserveContext context = ObserveContext.get(); + Decorator<EE> decorator = context.getDecorator(entityClass); + if (log.isDebugEnabled()) { + log.debug("Will use decorator " + decorator); } + list.putClientProperty(CLIENT_PROPERTY_DECORATOR, decorator); + // sort data from first decorator context - DecoratorUtil.sort((JXPathDecorator<E>) decorator, data, 0); + DecoratorUtil.sort((JXPathDecorator<EE>) decorator, data, 0); // set datas to list and init renderer - list.init((JXPathDecorator<E>) decorator, data, Collections.<E>emptyList()); + list.init((JXPathDecorator<EE>) decorator, data, Collections.<EE>emptyList()); // get the renderer initialized ListCellRenderer renderer = list.getSelectedList().getCellRenderer(); @@ -679,56 +689,59 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte list.getSelectedList().setCellRenderer(new ReferentielListCellRenderer(renderer)); list.getUniverseList().setCellRenderer(new ReferentielListCellRenderer(renderer)); - list.putClientProperty("data", data); - - // listen on cache modification - EntityDoubleListPropertyChangeListener<E> listener = - new EntityDoubleListPropertyChangeListener<E>(entityClass, list); + list.putClientProperty(CLIENT_PROPERTY_DATA, data); - //FIXME Remove this -// DataService service = context.getDataService(); -// service.addReferentielPropertyChangeListener(entityClass, listener); } /** * Remplit le modèle d'une liste graphique avec la liste des entités d'un * type donné sur un service de persistance donné. * - * @param dataSource le service de persistance à utiliser pour - * récupérer les entités - * @param entityClass le type de l'entité - * @param list le component graphique à initialiser + * @param referentialLists l'ensemble pour conserver les noms des composants utilisant des listes de référentiels + * @param entityClass le type de l'entité + * @param list le component graphique à initialiser * @since 1.5 */ @SuppressWarnings("unchecked") - protected <E extends TopiaEntity> void prepareEntityList(DataSource dataSource, Class<E> entityClass, BeanListHeader<E> list) { + protected <EE extends TopiaEntity> void prepareEntityList(Set<String> referentialLists, Class<EE> entityClass, BeanListHeader<EE> list) { - ObserveContext context = ObserveContext.get(); + List<EE> data; - // init list - Decorator<E> decorator = context.getDecorator(entityClass); - if (log.isDebugEnabled()) { - log.debug("Will use decorator " + decorator); - } + if (ReferenceEntity.class.isAssignableFrom(entityClass)) { - list.putClientProperty("decorator", decorator); - List<E> data; + // On charge la liste depuis le cache de référentiels + ReferentialCache.ReferentialList referentialList = ObserveContext.getReferentialList((Class) entityClass); - if (ReferenceEntity.class.isAssignableFrom(entityClass)) { + data = getReferentialList(list, referentialList, false); - Predicate<E> predicate = (Predicate<E>) list.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); - data = service.getList(entityClass, predicate); + // on conserve le widget (il sera rechargé si nécessaire à l'ouverture de l'écran) + referentialLists.add(list.getName()); } else { - data = new ArrayList<E>(); + + data = new ArrayList<EE>(); + } + if (log.isInfoEnabled()) { + log.info("entity list [" + entityClass.getName() + "] : " + data.size()); + } + + ObserveContext context = ObserveContext.get(); + + // init list + Decorator<EE> decorator = context.getDecorator(entityClass); + if (log.isDebugEnabled()) { + log.debug("Will use decorator " + decorator); + } + + list.putClientProperty(CLIENT_PROPERTY_DECORATOR, decorator); + // sort data from first decorator context - DecoratorUtil.sort((JXPathDecorator<E>) decorator, data, 0); + DecoratorUtil.sort((JXPathDecorator<EE>) decorator, data, 0); // set datas to list and init renderer - list.init((JXPathDecorator<E>) decorator, data); + list.init((JXPathDecorator<EE>) decorator, data); // get the renderer initialized ListCellRenderer renderer = list.getList().getCellRenderer(); @@ -736,342 +749,228 @@ public class ContentUIInitializer<E extends TopiaEntity, UI extends ObserveConte // add the specific renderer list.getList().setCellRenderer(new ReferentielListCellRenderer(renderer)); - list.putClientProperty("data", data); - - // listen on cache modification - EntityListPropertyChangeListener<E> listener = new EntityListPropertyChangeListener<E>(entityClass, list); + list.putClientProperty(CLIENT_PROPERTY_DATA, data); - //FIXME Remove this!!! -// DataService service = context.getDataService(); -// service.addReferentielPropertyChangeListener(entityClass, listener); } /** * Prépare un component de choix d'entités pour un type d'entité donné et * pour un service de persistance donné. * - * @param <E> le type de l'entité - * @param dataSource le service de persistance à utiliser pour récupérer - * les entités - * @param entityClass le type de l'entité - * @param comboBox le component graphique à initialiser + * @param <EE> le type de l'entité + * @param referentialLists l'ensemble pour conserver les noms des composants utilisant des listes de référentiels + * @param entityClass le type de l'entité + * @param comboBox le component graphique à initialiser */ @SuppressWarnings("unchecked") - protected <E extends TopiaEntity> void prepareBeanComboBox(DataSource dataSource, Class<E> entityClass, BeanComboBox<E> comboBox) { + protected <EE extends TopiaEntity> void prepareBeanComboBox(Set<String> referentialLists, Class<EE> entityClass, BeanComboBox<EE> comboBox) { - ObserveContext context = ObserveContext.get(); + List<EE> data; - // init combobox - Decorator<E> decorator = context.getDecorator(entityClass); + boolean referenceEntity = ReferenceEntity.class.isAssignableFrom(entityClass); - Boolean noLoad = (Boolean) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_NO_LOAD); + if (referenceEntity) { - List<E> data; + // On charge la liste depuis le cache de référentiels + ReferentialCache.ReferentialList referentialList = ObserveContext.getReferentialList((Class) entityClass); - if (noLoad != null && noLoad) { + data = getReferentialList(comboBox, referentialList, true); - if (log.isInfoEnabled()) { - log.info("Skip loading of entity list [" + entityClass.getName() + "] (listNoLoad property found)"); - } - data = Collections.emptyList(); + // on conserve le widget (il sera rechargé si nécessaire à l'ouverture de l'écran) + referentialLists.add(comboBox.getName()); } else { - // get complete data list from service - Predicate<E> predicate = (Predicate<E>) comboBox.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); - data = service.getList(entityClass, predicate); + if (log.isDebugEnabled()) { + log.debug("Skip loading of entity list [" + entityClass.getName() + "] (Not a referential type)"); + } + data = Collections.emptyList(); } - boolean referenceEntity = ReferenceEntity.class.isAssignableFrom(entityClass); - - if (referenceEntity) { - - //TC-20100208 : on ne veut pas voir les elements du referentiel non actif - ReferenceEntities.filterReferentielListByStatus((List) data); - + if (log.isInfoEnabled()) { + log.info("entity list: " + entityClass.getName() + "] : " + data.size()); } + ObserveContext context = ObserveContext.get(); - if (log.isInfoEnabled()) { - log.info("entity list [" + entityClass.getName() + "] : " + data.size()); - } + // init combobox + Decorator<EE> decorator = context.getDecorator(entityClass); // add data list to combo box - comboBox.init((JXPathDecorator<E>) decorator, data); + comboBox.init((JXPathDecorator<EE>) decorator, data); final ListCellRenderer renderer = comboBox.getCombobox().getRenderer(); - ListCellRenderer toolTipRenderer = new ListCellRenderer() { + ListCellRenderer toolTipRenderer = new TooltipListCellRenderer(renderer); - @Override - public Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus) { - Component comp = renderer.getListCellRendererComponent( - list, - value, - index, - isSelected, - cellHasFocus - ); - if (comp instanceof JLabel) { - JLabel jcomp = (JLabel) comp; - jcomp.setToolTipText(jcomp.getText()); - } - return comp; - } - }; comboBox.getCombobox().setRenderer(toolTipRenderer); if (log.isDebugEnabled()) { - log.debug("combo list [" + entityClass.getName() + "] : " + - comboBox.getData().size()); + log.debug("combo list [" + entityClass.getName() + "] : " + comboBox.getData().size()); } - if (referenceEntity) { - - // listen on cache modification - BeanComboBoxPropertyChangeListener listener = - new BeanComboBoxPropertyChangeListener(entityClass, comboBox) { + } - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (log.isDebugEnabled()) { - log.debug("entity list [" + evt.getPropertyName() + "]"); - } - super.propertyChange(evt); - } - }; + @SuppressWarnings("unchecked") + public static <EE extends ReferenceEntity> void reload(BeanListHeader<EE> list) { - //FIXME Remove this -// context.getDataService().addReferentielPropertyChangeListener(entityClass, listener); + Date timeStamp = (Date) list.getClientProperty(CLIENT_PROPERTY_REFERENTIAL_LIST_TIME_STAMP); - } + Class<EE> beanType = list.getBeanType(); - } + ReferentialCache.ReferentialList<EE> referentialList = ObserveContext.getReferentialList(beanType); - /** - * Un écouteur de changement les entités d'un type donné contenues dans une - * liste graphique donnée. - * - * @param <E> le type des entités - */ - protected static class EntityListPropertyChangeListener - <E extends TopiaEntity> implements PropertyChangeListener { + Date lastUpdate = referentialList.getTimeStamp(); - /** le type des entités */ - private Class<E> entityClass; + if (lastUpdate.after(timeStamp)) { - /** la liste graphique */ - private BeanListHeader<E> list; + // reload list + List<EE> data = getReferentialList(list, referentialList, false); - public EntityListPropertyChangeListener(Class<E> entityClass, - BeanListHeader<E> list) { - this.entityClass = entityClass; - this.list = list; - } + if (log.isInfoEnabled()) { + log.info("reloading entities list: " + referentialList); + } - @SuppressWarnings({"unchecked"}) - @Override - public void propertyChange(PropertyChangeEvent evt) { + Decorator<EE> decorator = (Decorator<EE>) list.getClientProperty(CLIENT_PROPERTY_DECORATOR); - List<E> newValue = (List<E>) evt.getNewValue(); + DecoratorUtil.sort((JXPathDecorator<EE>) decorator, data, 0); + EE selectedValue = list.getSelectedValue(); + list.putClientProperty(CLIENT_PROPERTY_DATA, data); + list.setData(Collections.<EE>emptyList()); + list.setData(data); + if (selectedValue != null && data.contains(selectedValue)) { - Decorator<E> decorator = (Decorator<E>) - list.getClientProperty("decorator"); + // reselect it + list.getList().setSelectedValue(selectedValue, true); - if (log.isDebugEnabled()) { - log.debug("reloading entities list for [" + entityClass + - "], size : " + newValue.size()); } - DecoratorUtil.sort((JXPathDecorator<E>) decorator, newValue, 0); - E selectedValue = list.getSelectedValue(); - list.putClientProperty("data", newValue); - list.setData(Collections.<E>emptyList()); - list.setData(newValue); - if (selectedValue != null && newValue.contains(selectedValue)) { + } else { - // reselect it - list.getList().setSelectedValue(selectedValue, true); + if (log.isInfoEnabled()) { + log.info("Up-to-date entities list: " + referentialList); } + } + } - /** - * Un écouteur de changement les entités d'un type donné contenues dans une - * liste graphique donnée. - * - * @param <E> le type des entités - */ - protected static class EntityDoubleListPropertyChangeListener - <E extends TopiaEntity> implements PropertyChangeListener { + @SuppressWarnings("unchecked") + public static <EE extends ReferenceEntity> void reload(FilterableDoubleList<EE> list) { - /** le type des entités */ - private Class<E> entityClass; + Date timeStamp = (Date) list.getClientProperty(CLIENT_PROPERTY_REFERENTIAL_LIST_TIME_STAMP); - /** la liste graphique */ - private FilterableDoubleList<E> list; + Class<EE> beanType = list.getBeanType(); - public EntityDoubleListPropertyChangeListener(Class<E> entityClass, - FilterableDoubleList<E> list) { - this.entityClass = entityClass; - this.list = list; - } + ReferentialCache.ReferentialList<EE> referentialList = ObserveContext.getReferentialList(beanType); - @SuppressWarnings({"unchecked"}) - @Override - public void propertyChange(PropertyChangeEvent evt) { + Date lastUpdate = referentialList.getTimeStamp(); - List<E> newValue = (List<E>) evt.getNewValue(); + if (lastUpdate.after(timeStamp)) { - Decorator<E> decorator = (Decorator<E>) - list.getClientProperty("decorator"); + // reload list + List<EE> data = getReferentialList(list, referentialList, false); - if (log.isDebugEnabled()) { - log.debug("reloading entities list for [" + entityClass + - "], size : " + newValue.size()); + if (log.isInfoEnabled()) { + log.info("reloading entities list: " + referentialList); } - DecoratorUtil.sort((JXPathDecorator<E>) decorator, newValue, 0); - list.putClientProperty("data", newValue); + Decorator<EE> decorator = (Decorator<EE>) list.getClientProperty(CLIENT_PROPERTY_DECORATOR); + DecoratorUtil.sort((JXPathDecorator<EE>) decorator, data, 0); - List<E> selectedValues = new ArrayList<E>(list.getModel().getSelected()); + List<EE> selectedValues = new ArrayList<EE>(list.getModel().getSelected()); - list.setUniverse(Collections.<E>emptyList()); - list.setUniverse(newValue); + list.setUniverse(Collections.<EE>emptyList()); + list.setUniverse(data); - selectedValues.retainAll(newValue); + selectedValues.retainAll(data); // reselect it list.setSelected(selectedValues); + } else { + + if (log.isInfoEnabled()) { + log.info("Up-to-date entities list: " + referentialList); + } + } + } - /** - * Un renderer de liste d'entites d'un referentiel dans le quel on veut - * differencier les entites qui sont desactivees. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.2 - */ - public static class ReferentielListCellRenderer implements ListCellRenderer { + @SuppressWarnings("unchecked") + public static <EE extends ReferenceEntity> void reload(BeanComboBox<EE> comboBox) { - /** la couleur normal pour les entites non desactivees */ - protected Color normalColor; + Date timeStamp = (Date) comboBox.getClientProperty(CLIENT_PROPERTY_REFERENTIAL_LIST_TIME_STAMP); - /** la couleur a utiliser pour les entites desactivees */ - protected Color disableColor = Color.LIGHT_GRAY; + Class<EE> beanType = comboBox.getBeanType(); - protected ListCellRenderer delegate; + ReferentialCache.ReferentialList<EE> referentialList = ObserveContext.getReferentialList(beanType); - public ReferentielListCellRenderer(ListCellRenderer delegate) { - this.delegate = delegate; - } + Date lastUpdate = referentialList.getTimeStamp(); + + if (lastUpdate.after(timeStamp)) { - @Override - public Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus) { - JComponent comp; - comp = (JComponent) delegate.getListCellRendererComponent( - list, - value, - index, - isSelected, - cellHasFocus); - if (normalColor == null) { - // premiere fois, on intialise la couleur dite normale - normalColor = comp.getForeground(); + // reload list + List<EE> data = getReferentialList(comboBox, referentialList, true); + + if (log.isInfoEnabled()) { + log.info("reloading entities list: " + referentialList); } - String tip = ((JLabel) comp).getText(); + EE selectedItem = (EE) comboBox.getSelectedItem(); + + comboBox.setData(data); + + if (selectedItem != null) { - // par defaut, on utilise la couleur normale - Color col = normalColor; - if (value != null && - value instanceof ReferenceEntity) { + // obtain back the selected item from the new list - ReferenceEntity e = (ReferenceEntity) value; - ReferenceStatus status = e.getStatus(); + EE newSelectedItem = UIHelper.getEntity(data, selectedItem); - if (status == ReferenceStatus.disabled) { - // l'entite est desactivee - // on la grise pour bien la differencier - col = disableColor; - tip = t("observe.common.obsolete.entity", tip); + comboBox.setSelectedItem(null); - } else { - tip = null; + if (newSelectedItem != null) { + comboBox.setSelectedItem(newSelectedItem); } - } else { - tip = null; } - comp.setForeground(col); - comp.setToolTipText(tip); - return comp; - } - } - /** - * Un écouteur de changement des entités d'un type donnés contenues dans le - * modèle d'une liste déroulante graphique donnée. - * - * @param <E> le type des entités - */ - protected static class BeanComboBoxPropertyChangeListener - <E extends ReferenceEntity> implements PropertyChangeListener { - - /** le type des entités à écouter */ - private final Class<E> entityClass; + } else { - /** la liste à choix graphique */ - private final BeanComboBox<E> comboBox; + if (log.isInfoEnabled()) { + log.info("Up-to-date entities list: " + referentialList); + } - public BeanComboBoxPropertyChangeListener(Class<E> entityClass, BeanComboBox<E> comboBox) { - this.entityClass = entityClass; - this.comboBox = comboBox; } - @SuppressWarnings({"unchecked"}) - @Override - public void propertyChange(PropertyChangeEvent evt) { + } - // recuperation de la liste des entites - //TC-20100209 : on veut une copie de la liste puisqu'on peut la - // modifer via le filtre sur les entites sur le caractère actif - List<E> newValue = new ArrayList<E>((List<E>) evt.getNewValue()); + @SuppressWarnings("unchecked") + public static <EE extends ReferenceEntity> List<EE> getReferentialList(JComponent component, ReferentialCache.ReferentialList<EE> referentialList, boolean removeObsolete) { - if (log.isDebugEnabled()) { - log.debug("reloading entities list for [" + entityClass + - "], size : " + newValue.size()); - } - //TC-20100208 : on ne veut pas voir les elements du referentiel non actif - ReferenceEntities.filterReferentielListByStatus(newValue); + List<EE> data = new ArrayList<EE>(referentialList.getData()); - E selectedItem = (E) comboBox.getSelectedItem(); + Predicate<EE> predicate = (Predicate<EE>) component.getClientProperty(ObserveContentUI.CLIENT_PROPERTY_LIST_PREDICATE); - comboBox.setData(newValue); + if (predicate != null) { - if (selectedItem != null) { + // on applique le prédicat + data = Lists.newArrayList(Iterables.filter(data, predicate)); - // obtain back the selected item from the new list + } - E newSelectedItem = UIHelper.getEntity(newValue, selectedItem); + if (removeObsolete) { - comboBox.setSelectedItem(null); + //TC-20100208 : on ne veut pas voir les elements du referentiel non actif + ReferenceEntities.filterReferentielListByStatus((List) data); - if (newSelectedItem != null) { - comboBox.setSelectedItem(newSelectedItem); - } - } } + + // on conserve aussi la date de dernière mise à jour + component.putClientProperty(CLIENT_PROPERTY_REFERENTIAL_LIST_TIME_STAMP, referentialList.getTimeStamp()); + + return data; + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java index 0c30ee3..ce9d974 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ObserveContentUI.java @@ -42,8 +42,6 @@ public interface ObserveContentUI<E extends TopiaEntity> extends JAXXObject { String CLIENT_PROPERTY_LIST_PREDICATE = "listPredicate"; - String CLIENT_PROPERTY_LIST_NO_LOAD = "listNoLoad"; - ContentUIModel<E> getModel(); DataContext getDataContext(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ReferentialCache.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ReferentialCache.java new file mode 100644 index 0000000..92ea2cc --- /dev/null +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ReferentialCache.java @@ -0,0 +1,115 @@ +package fr.ird.observe.ui.content; + +import com.google.common.base.Preconditions; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import fr.ird.observe.ObserveContext; +import fr.ird.observe.ObserveTechnicalException; +import fr.ird.observe.entities.referentiel.ReferenceEntity; +import fr.ird.observe.services.referential.ReferentialService; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Date; +import java.util.List; +import java.util.concurrent.ExecutionException; + +/** + * Pour gérer un cache de référentiel. + * + * Pour obtenir une liste d'un référentiel, on passe toujours dans cette classe qui gère les modifications de + * référentiels. + * + * Created on 5/5/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ReferentialCache { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ReferentialCache.class); + + protected final LoadingCache<Class<? extends ReferenceEntity>, ReferentialList<? extends ReferenceEntity>> cache; + + public ReferentialCache() { + this.cache = CacheBuilder.newBuilder().build(new CacheLoader<Class<? extends ReferenceEntity>, ReferentialList<? extends ReferenceEntity>>() { + + @SuppressWarnings("unchecked") + @Override + public ReferentialList<? extends ReferenceEntity> load(Class<? extends ReferenceEntity> key) throws Exception { + + Preconditions.checkNotNull(key, "key can't be null"); + + ReferentialService service = ObserveContext.get().getService(ReferentialService.class); + List<? extends ReferenceEntity> list = service.getList(key); + + if (log.isInfoEnabled()) { + log.info("Adding referential list " + key.getName() + " in cache"); + } + + ReferentialList<? extends ReferenceEntity> referentialList = new ReferentialList(key, list); + return referentialList; + + } + }); + + } + + @SuppressWarnings("unchecked") + public <R extends ReferenceEntity> ReferentialList<R> getReferentialList(Class<R> referentialType) { + + try { + + ReferentialList<R> result = (ReferentialList<R>) cache.get(referentialType); + return result; + + } catch (ExecutionException e) { + throw new ObserveTechnicalException("Could not get referential list: " + referentialType, e); + } + + } + + public void clearEntry(Class<? extends ReferenceEntity> referentialType) { + cache.invalidate(referentialType); + } + + public void clear() { + cache.invalidateAll(); + } + + public static class ReferentialList<R extends ReferenceEntity> { + + private final Date timeStamp; + + private final List<R> data; + + private final Class<R> entityType; + + ReferentialList(Class<R> entityType, List<R> data) { + this.entityType = entityType; + this.timeStamp = new Date(); + this.data = data; + } + + public Date getTimeStamp() { + return timeStamp; + } + + public List<R> getData() { + return data; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("entityType", entityType.getName()) + .append("timeStamp", timeStamp) + .append("size", data.size()) + .toString(); + } + } +} diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java index c30a337..a924eef 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java @@ -27,6 +27,7 @@ import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveServiceHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.constants.ReferenceStatus; @@ -182,6 +183,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } public void selectBean(E selectedBean) { + getModel().setSelectedBean(selectedBean); // copy right now the selected bean to the model bean to respect contract @@ -393,11 +395,11 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } }); -// UIHelper.getLayer(ui.getEditKeyTable()).setUI(ui.getEditKeyTableLayerUI()); } @Override public void openUI() throws Exception { + super.openUI(); ContentReferenceUIModel<E> model = getModel(); @@ -433,6 +435,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten ((JComponent) ui.getObjectById("libelle" + i)).setFont(font); } } + ContentMode mode = computeContentMode(); model.setMode(mode); if (mode != ContentMode.READ) { @@ -440,6 +443,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten ui.processDataBinding( ContentReferenceUI.BINDING_DELETE_FROM_LIST_ENABLED); } + } @Override @@ -467,6 +471,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten ContentMode mode = model.getMode(); boolean canEdit = mode != ContentMode.READ; if (canEdit) { + removeAllMessages(ui); String contextName = getValidatorContextName(mode); if (log.isDebugEnabled()) { @@ -475,26 +480,19 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten ui.getValidator().setContext(contextName); if (mode == ContentMode.CREATE) { + addInfoMessage(t("observe.message.creating.referentiel")); // creation mode - E preCreate = getService(ReferentialService.class).preCreate(model.getBeanType()); + ReferentialService service = getService(ReferentialService.class); + E preCreate = service.preCreate(model.getBeanType()); copy(model.getBeanType(), BinderService.EDIT, preCreate, bean, true); -// try { -// getDataService().preCreate(getDataSource(), -// null, -// bean, -// getLoadBinder(), -// getPreCreateExecutor() -// ); -// } catch (DataSourceException e) { -// ErrorDialogUI.showError(e); -// } - } else { + addInfoMessage(t("observe.message.updating.referentiel")); + } // do edit @@ -504,7 +502,9 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten // nothing has changed just after starting editing ui.getValidator().setChanged(false); + } + } else { // reset all validators @@ -515,12 +515,15 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten // pass in editing mode (without any modification possible) model.setEditing(true); + ObserveServiceHelper.get().getValidationContext().cleanCache(); + } } @Override protected void prepareValidationContext() { + super.prepareValidationContext(); BeanListHeader<E> jList = getUi().getListHeader(); List<E> data = jList.getData(); @@ -530,6 +533,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten log.debug("Set referentiel list [" + getBeanType().getSimpleName() + "] in validation context : " + data.size()); } validationContext.setEditingReferentielList(data); + } public final void createUI() { @@ -544,10 +548,10 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } copy(getModel().getBeanType(), BinderService.EDIT, null, getBean()); -// getLoadBinder().load(null, getBean(), true); // on demarre l'edition ui.startEdit(null); + } public void modifyUI() { @@ -560,13 +564,14 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } copy(getModel().getBeanType(), BinderService.EDIT, model.getSelectedBean(), getBean()); -// getLoadBinder().load(model.getSelectedBean(), getBean(), true); getUi().startEdit(null); + } @Override public void stopEditUI() { + super.stopEditUI(); ContentReferenceUI<E> ui = getUi(); @@ -578,7 +583,9 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten model.setMode(ContentMode.UPDATE); removeAllMessages(ui); addInfoMessage(t("observe.message.referentiel.editable")); + } + } @Override @@ -591,18 +598,23 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } else { modifyUI(); } + } public void backToList() { + ContentReferenceUIModel<E> model = getModel(); + if (!model.isModified() || checkEdit(getUi())) { + getUi().stopEdit(); - // then resynch the selected bean to edit bean (used for - // example to delete)... + // then resynch the selected bean to edit bean (used for example to delete)... // repush selected bean to bean getLoadBinder().load(model.getSelectedBean(), getBean(), true); + } + } @Override @@ -610,7 +622,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten ContentReferenceUIModel<E> model = getModel(); - boolean create = bean.getTopiaId() == null; + boolean create = Entities.isNew(bean); ReferentialService service = getService(ReferentialService.class); @@ -636,6 +648,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten log.info("No usage found, no warning to display"); } } else { + // some usages were found boolean willsave = showUsagesForDesactivated(getUi(), bean, usages); if (!willsave) { @@ -644,6 +657,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } return false; } + } } @@ -673,6 +687,7 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } return true; + } @Override @@ -718,33 +733,48 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten // remove the program in tree ObserveTreeHelper treeHelper = getTreeHelper(getUi()); treeHelper.removeProgram(beanId); + } + return true; + } @Override protected void afterDelete() { + + ObserveContext.invalidateReferentialList(getBeanType()); + + // Reload list + ReferentialContentUIInitializer.loadData(getUi().getListHeader(), false); + super.afterDelete(); } @Override protected void afterSave(boolean refresh) { + + ObserveContext.invalidateReferentialList(getBeanType()); + + // Reload list + ReferentialContentUIInitializer.loadData(getUi().getListHeader(), false); + super.afterSave(refresh); getUi().stopEdit(); + } public boolean canSeeI18nTable(E bean) { - return bean instanceof I18nReferenceEntity || - bean instanceof VesselSizeCategory; + return bean instanceof I18nReferenceEntity || bean instanceof VesselSizeCategory; } public String updateView(boolean editing) { + if (log.isDebugEnabled()) { log.debug("Editing has changed : " + editing); } - return editing ? - ContentReferenceUI.DETAIL_VIEW : - ContentReferenceUI.LIST_VIEW; + return editing ? ContentReferenceUI.DETAIL_VIEW : ContentReferenceUI.LIST_VIEW; + } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java index bd4aea1..e2a8130 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ReferentialContentUIInitializer.java @@ -24,10 +24,10 @@ package fr.ird.observe.ui.content.ref; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.content.ContentUIInitializer; +import fr.ird.observe.ui.util.ReferentielListCellRenderer; import jaxx.runtime.swing.editor.bean.BeanListHeader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,6 +39,7 @@ import org.nuiton.topia.persistence.TopiaEntity; import javax.swing.JList; import javax.swing.ListCellRenderer; import java.util.List; +import java.util.Set; /** * Created on 11/28/14. @@ -55,55 +56,8 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten super(ui); } - /** - * Remplit le modèle d'une liste graphique avec la liste des entités d'un - * type donné sur un service de persistance donné. - * - * @param dataSource la data source - * @param entityClass le type de l'entité - * @param list le component graphique à initialiser - * @since 1.5 - */ - public static <E extends ReferenceEntity> void prepareMainEntityList(DataSource dataSource, - Class<E> entityClass, - BeanListHeader<E> list) { - - ObserveContext context = ObserveContext.get(); - - // init list - Decorator<E> decorator = context.getDecorator(entityClass); - if (log.isDebugEnabled()) { - log.debug("Will use decorator " + decorator); - } - - list.putClientProperty("decorator", decorator); - ReferentialService service = ObserveContext.getService(dataSource, ReferentialService.class); - - List<E> data = service.loadListForEdit(entityClass); - - // sort data from first decorator context - DecoratorUtil.sort((JXPathDecorator<E>) decorator, data, 0); - - // set datas to list and init renderer - list.init((JXPathDecorator<E>) decorator, data); - - // get the renderer initialized - ListCellRenderer renderer = list.getList().getCellRenderer(); - - // add the specific renderer - list.getList().setCellRenderer(new ReferentielListCellRenderer(renderer)); - - list.putClientProperty("data", data); - - //FIXME Remove this!!! - // listen on cache modification -// EntityListPropertyChangeListener<E> listener = new EntityListPropertyChangeListener<E>(entityClass, list); -// DataService dataService = ObserveContext.get().getDataService(); -// dataService.addReferentielPropertyChangeListener(entityClass, listener); - } - @SuppressWarnings("unchecked") - protected void init(DataSource dataSource, DecoratorService decoratorService, BeanListHeader beanList) { + protected void init(Set<String> referentialLists, DecoratorService decoratorService, BeanListHeader beanList) { beanList.setI18nPrefix("observe.common."); @@ -114,11 +68,11 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten if ("listHeader".equals(beanList.getName())) { // use the binder for loading - prepareMainEntityList(dataSource, beanList.getBeanType(), beanList); + prepareMainEntityList(beanList); } else { - super.init(dataSource, decoratorService, beanList); + super.init(referentialLists, decoratorService, beanList); } @@ -128,8 +82,7 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten if (init != null) { Class<TopiaEntity> klass = (Class<TopiaEntity>) init; if (log.isDebugEnabled()) { - log.debug("addDecorator to list " + - jlist.getName()); + log.debug("addDecorator to list " + jlist.getName()); } Decorator<TopiaEntity> decorator; decorator = decoratorService.getDecoratorByType(klass); @@ -139,8 +92,7 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten init = jlist.getClientProperty("addToogleListSelectionModel"); if (init != null && init instanceof Boolean && (Boolean) init) { if (log.isDebugEnabled()) { - log.debug("addToogleListSelectionModel to list " + - jlist.getName()); + log.debug("addToogleListSelectionModel to list " + jlist.getName()); } prepareToogleListSelectionModel(jlist); } @@ -155,4 +107,64 @@ public class ReferentialContentUIInitializer<E extends ReferenceEntity, UI exten ui.getEditKeyTableLayerUI().setAcceptedComponentNames(doNotBlockComponentIds); } + + /** + * Remplit le modèle d'une liste graphique avec la liste des entités d'un + * type donné sur un service de persistance donné. + * + * @param list le component graphique à initialiser + * @since 1.5 + */ + @SuppressWarnings("unchecked") + public static <EE extends ReferenceEntity> void prepareMainEntityList(BeanListHeader<EE> list) { + + Class<EE> entityClass = list.getBeanType(); + ObserveContext context = ObserveContext.get(); + + // init list + Decorator<EE> decorator = context.getDecorator(entityClass); + if (log.isDebugEnabled()) { + log.debug("Will use decorator " + decorator); + } + + list.putClientProperty(CLIENT_PROPERTY_DECORATOR, decorator); + + // get the renderer initialized + ListCellRenderer renderer = list.getList().getCellRenderer(); + + // add the specific renderer + list.getList().setCellRenderer(new ReferentielListCellRenderer(renderer)); + + loadData(list, true); + + } + + @SuppressWarnings("unchecked") + public static <EE extends ReferenceEntity> void loadData(BeanListHeader<EE> list, boolean init) { + + Class<EE> entityClass = list.getBeanType(); + + ReferentialService service = ObserveContext.get().getService(ReferentialService.class); + + List<EE> data = service.loadListForEdit(entityClass); + + Decorator<EE> decorator = (Decorator<EE>) list.getClientProperty(CLIENT_PROPERTY_DECORATOR); + + // sort data from first decorator context + DecoratorUtil.sort((JXPathDecorator<EE>) decorator, data, 0); + + if (init) { + + // set datas to list and init renderer + list.init((JXPathDecorator<EE>) decorator, data); + + } else { + + list.setData(data); + + } + list.putClientProperty(CLIENT_PROPERTY_DATA, data); + + } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUI.css b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUI.css index e73822c..5a72b8c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUI.css +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUI.css @@ -73,7 +73,6 @@ #section { property:{CatchLongline.PROPERTY_SECTION}; selectedItem:{tableEditBean.getSection()}; - _listNoLoad:{true}; } #basketLabel { @@ -84,7 +83,6 @@ #basket { property:{CatchLongline.PROPERTY_BASKET}; selectedItem:{tableEditBean.getBasket()}; - _listNoLoad:{true}; } #branchlineLabel { @@ -95,7 +93,6 @@ #branchline { property:{CatchLongline.PROPERTY_BRANCHLINE}; selectedItem:{tableEditBean.getBranchline()}; - _listNoLoad:{true}; } #speciesCatchLabel { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUI.css b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUI.css index 209344f..5a00864 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUI.css +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUI.css @@ -133,7 +133,6 @@ #section { property:{Tdr.PROPERTY_SECTION}; selectedItem:{tableEditBean.getSection()}; - _listNoLoad:{true}; _validatorLabel: {t("observe.tdr.section")}; } @@ -145,7 +144,6 @@ #basket { property:{Tdr.PROPERTY_BASKET}; selectedItem:{tableEditBean.getBasket()}; - _listNoLoad:{true}; _validatorLabel: {t("observe.tdr.basket")}; } @@ -157,7 +155,6 @@ #branchline { property:{Tdr.PROPERTY_BRANCHLINE}; selectedItem:{tableEditBean.getBranchline()}; - _listNoLoad:{true}; _validatorLabel: {t("observe.tdr.branchline")}; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/util/ReferentielListCellRenderer.java b/observe-swing/src/main/java/fr/ird/observe/ui/util/ReferentielListCellRenderer.java new file mode 100644 index 0000000..a00402c --- /dev/null +++ b/observe-swing/src/main/java/fr/ird/observe/ui/util/ReferentielListCellRenderer.java @@ -0,0 +1,80 @@ +package fr.ird.observe.ui.util; + +import fr.ird.observe.entities.constants.ReferenceStatus; +import fr.ird.observe.entities.referentiel.ReferenceEntity; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import java.awt.Color; +import java.awt.Component; + +import static org.nuiton.i18n.I18n.t; + +/** + * Un renderer de liste d'entites d'un referentiel dans le quel on veut + * differencier les entites qui sont desactivees. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 1.2 + */ +public class ReferentielListCellRenderer implements ListCellRenderer { + + /** la couleur normal pour les entites non desactivees */ + protected Color normalColor; + + /** la couleur a utiliser pour les entites desactivees */ + protected Color disableColor = Color.LIGHT_GRAY; + + protected ListCellRenderer delegate; + + public ReferentielListCellRenderer(ListCellRenderer delegate) { + this.delegate = delegate; + } + + @Override + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + JComponent comp; + comp = (JComponent) delegate.getListCellRendererComponent( + list, + value, + index, + isSelected, + cellHasFocus); + if (normalColor == null) { + // premiere fois, on intialise la couleur dite normale + normalColor = comp.getForeground(); + } + + String tip = ((JLabel) comp).getText(); + + // par defaut, on utilise la couleur normale + Color col = normalColor; + if (value != null && + value instanceof ReferenceEntity) { + + ReferenceEntity e = (ReferenceEntity) value; + ReferenceStatus status = e.getStatus(); + + if (status == ReferenceStatus.disabled) { + // l'entite est desactivee + // on la grise pour bien la differencier + col = disableColor; + tip = t("observe.common.obsolete.entity", tip); + + } else { + tip = null; + } + } else { + tip = null; + } + comp.setForeground(col); + comp.setToolTipText(tip); + return comp; + } +} diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/util/TooltipListCellRenderer.java b/observe-swing/src/main/java/fr/ird/observe/ui/util/TooltipListCellRenderer.java new file mode 100644 index 0000000..6bc2f0e --- /dev/null +++ b/observe-swing/src/main/java/fr/ird/observe/ui/util/TooltipListCellRenderer.java @@ -0,0 +1,44 @@ +package fr.ird.observe.ui.util; + +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import java.awt.Component; + +/** + * Created on 5/5/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 1.0 + */ +public class TooltipListCellRenderer implements ListCellRenderer { + + private final ListCellRenderer renderer; + + public TooltipListCellRenderer(ListCellRenderer renderer) { + this.renderer = renderer; + } + + @Override + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + + Component comp = renderer.getListCellRendererComponent( + list, + value, + index, + isSelected, + cellHasFocus + ); + + if (comp instanceof JLabel) { + JLabel jcomp = (JLabel) comp; + jcomp.setToolTipText(jcomp.getText()); + } + return comp; + + } +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 748ea80260ecce2c1060b0add3cf427b64c90ef9 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 16:20:41 2015 +0200 remplacé l'utilisation des lists singlonton car elle doivent être triées, filtré les element de list a enregistrés, ajout d'un chans dans un binder --- .../main/java/fr/ird/observe/BinderService.java | 3 ++- .../observe/services/AbstractObserveService.java | 22 ++++++++++++++++++++++ .../data/seine/NonTargetSampleServiceImpl.java | 4 ++-- .../data/seine/TargetCatchServiceImpl.java | 2 +- .../data/seine/TargetSampleServiceImpl.java | 6 +++--- .../table/impl/seine/NonTargetCatchUIHandler.java | 4 ++-- .../table/impl/seine/NonTargetSampleUIHandler.java | 4 ++-- .../table/impl/seine/TargetCatchUIHandler.java | 3 ++- .../impl/seine/TargetDiscardCatchUIHandler.java | 5 +++-- .../table/impl/seine/TargetSampleUIHandler.java | 1 + 10 files changed, 40 insertions(+), 14 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index a0cfdba..31c9651 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -477,7 +477,8 @@ public class BinderService { BinderModelBuilder<TargetSample, TargetSample> builder = newBinderBuilder( TargetSample.class, TargetSample.PROPERTY_TARGET_LENGTH, - TargetSample.PROPERTY_COMMENT); + TargetSample.PROPERTY_COMMENT, + TargetSample.PROPERTY_DISCARDED); registerTopiaBinder(TargetSample.class, builder, EDIT); diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index cb8290b..7c59cd4 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -1,6 +1,7 @@ package fr.ird.observe.services; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import fr.ird.observe.BinderService; @@ -370,6 +371,10 @@ public abstract class AbstractObserveService implements ObserveService { } + for (E childNotSaved : Iterables.filter(oldChilds, Predicates.not(saveCollectionAction.childPredicate))) { + saveCollectionAction.listUpdator.addToList(parentSaved, childNotSaved); + } + // on donne la main aux implantations pour faire des traitements supplémentaires saveCollectionAction.onUpdateFinalize(parentSaved, oldChilds); @@ -388,6 +393,22 @@ public abstract class AbstractObserveService implements ObserveService { protected final TopiaEntityBinder<E> childBinder; + protected final Predicate<E> childPredicate; + + public SaveCollectionAction(Class<P> parentClass, + Class<E> entityClass, + EntityListUpdator<P, E> listUpdator, + TopiaEntityBinder<P> parentBinder, + TopiaEntityBinder<E> childBinder, + Predicate<E> childPredicate) { + this.parentClass = parentClass; + this.entityClass = entityClass; + this.listUpdator = listUpdator; + this.parentBinder = parentBinder; + this.childBinder = childBinder; + this.childPredicate = childPredicate; + } + public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass, EntityListUpdator<P, E> listUpdator, @@ -398,6 +419,7 @@ public abstract class AbstractObserveService implements ObserveService { this.listUpdator = listUpdator; this.parentBinder = parentBinder; this.childBinder = childBinder; + this.childPredicate = Predicates.alwaysTrue(); } public void prepareSave(P parentToSave, Collection<E> toSaves) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index 31c52aa..2404eec 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -160,7 +160,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement //FIXME Use obtainPropertiesExcluding NonTargetSample created = dao.create(); - copyExcluding(NonTargetSample.class, BinderService.EDIT, toCreate, created, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + copyExcluding(NonTargetSample.class, BinderService.EDIT, toCreate, created, false, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); parent.addNonTargetSample(created); saveTargetLengths(toCreate.getNonTargetLength(), created); @@ -175,7 +175,7 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement NonTargetSample updated = super.onUpdate(parent, toUpdate); - copyExcluding(NonTargetSample.class, BinderService.EDIT, toUpdate, updated, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); + copyExcluding(NonTargetSample.class, BinderService.EDIT, toUpdate, updated, false, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); saveTargetLengths(toUpdate.getNonTargetLength(), updated); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java index f8d00ee..39d45bf 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java @@ -111,7 +111,7 @@ public class TargetCatchServiceImpl extends AbstractObserveService implements Ta TopiaEntityBinder<TargetCatch> childBinder = getBinder(TargetCatch.class, binderContext); doSaveList(setSeinetoSave, new SaveCollectionAction<SetSeine, TargetCatch>( - SetSeine.class, TargetCatch.class, getListUpdator(), parentBinder, childBinder) { + SetSeine.class, TargetCatch.class, getListUpdator(), parentBinder, childBinder, predicate) { @Override public void onUpdateFinalize(SetSeine parentSaved, Collection<TargetCatch> oldChilds) throws TopiaException { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 976a4cf..5777067 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -83,7 +83,7 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T TargetSample toLoad = null; - if (!setSeine.isNonTargetSampleEmpty()) { + if (!setSeine.isTargetSampleEmpty()) { List<TargetSample> targetSamples = setSeine.getTargetSample(); for (TargetSample targetSample : targetSamples) { @@ -175,7 +175,7 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { TargetSample created = getDao().create(); - copyExcluding(TargetSample.class, BinderService.EDIT, toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); + copyExcluding(TargetSample.class, BinderService.EDIT, toCreate, created, false, TargetSample.PROPERTY_TARGET_LENGTH); parent.addTargetSample(created); saveTargetLengths(toCreate.getTargetLength(), created); @@ -190,7 +190,7 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T TargetSample updated = super.onUpdate(parent, toUpdate); - copyExcluding(TargetSample.class, BinderService.EDIT, toUpdate, updated, TargetSample.PROPERTY_TARGET_LENGTH); + copyExcluding(TargetSample.class, BinderService.EDIT, toUpdate, updated, false, TargetSample.PROPERTY_TARGET_LENGTH); saveTargetLengths(toUpdate.getTargetLength(), updated); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 9ed6a04..19b593d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.constants.DataContextType; @@ -55,7 +56,6 @@ import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -253,7 +253,7 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } else { Species species = bean.getSpecies(); - availableSpecies = Collections.singletonList(species); + availableSpecies = Lists.newArrayList(species); requestFocus = getUi().getTable(); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index 5d15a06..dc2d72d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; @@ -49,7 +50,6 @@ import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import static org.nuiton.i18n.I18n.n; @@ -223,7 +223,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam acquisitionModeGroup.setSelectedValue(null); acquisitionModeGroup.setSelectedValue(enumValue); - availableSpecies = Collections.singletonList(species); + availableSpecies = Lists.newArrayList(species); requestFocus = ui.getCount(); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java index 9e89625..bfcc9ab 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.constants.DataContextType; @@ -243,7 +244,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // puisque dans ce mode, pas possibilite de modifier de cette // valeur (clef metier) speciesComboBox.setSelectedItem(species); - weightCategoryComboBox.setData(Collections.singletonList(weightCategory)); + weightCategoryComboBox.setData(Lists.newArrayList(weightCategory)); weightCategoryComboBox.setSelectedItem(weightCategory); requestFocus = ui.getCatchWeight(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java index 22333ea..b4bd57e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.table.impl.seine; +import com.google.common.collect.Lists; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.db.constants.DataContextType; @@ -300,9 +301,9 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // puisque dans ce mode, pas possibilite de modifier de cette // valeur (clef metier) speciesComboBox.setSelectedItem(beanEspece); - weightCategoryComboBox.setData(Collections.singletonList(beanWeightCategory)); + weightCategoryComboBox.setData(Lists.newArrayList(beanWeightCategory)); weightCategoryComboBox.setSelectedItem(beanWeightCategory); - reasonForDiscardComboBox.setData(Collections.singletonList(beanReasonForDiscard)); + reasonForDiscardComboBox.setData(Lists.newArrayList(beanReasonForDiscard)); reasonForDiscardComboBox.setSelectedItem(beanReasonForDiscard); requestFocus = ui.getCatchWeight(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index adae963..e24f31d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -277,6 +277,7 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T } else { + editBean.setDiscarded(discarded); String savedId = service.save(setId, editBean); editBean.setTopiaId(savedId); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit ed66b0ebeaa52573a57947cede1305722e543e7f Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 16:22:40 2015 +0200 vérifie si le bean dans le validateur parent est bien présent. --- .../ui/content/table/impl/longline/CatchLonglineUIHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index 3c9a6b2..662e78a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -759,6 +759,14 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C log.info("Use branchline: " + newValue); } + /* FIXME sbavencoff 5/04/2015 le bean du validateur ne devrait jamais être null */ + if (ui.getValidator().getBean() == null) { + if (log.isWarnEnabled()) { + log.warn("Validator parent bean must be not null"); + } + ui.getValidator().setBean(ui.getBean()); + } + branchlineValidator.setBean(branchlineBean); CatchLonglineService service = getService(CatchLonglineService.class); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 9840500cf667dabbaf4010e87a50dcdb7b37474f Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue May 5 17:53:08 2015 +0200 correction de la recherche du sex indeterminé, ne pas crééer de service proxifié dans un service. --- .../src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java | 2 +- .../src/main/java/fr/ird/observe/services/AbstractObserveService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java index c5c8e92..e0fe0e6 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java @@ -4,7 +4,7 @@ public class SexDAOImpl<E extends Sex> extends SexDAOAbstract<E> { public E getUnknownSex() { - E sex = findByCode("fr.ird.observe.entities.referentiel.Sex#1239832686121#0.0"); + E sex = findByTopiaId("fr.ird.observe.entities.referentiel.Sex#1239832686121#0.0"); return sex; } diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index 7c59cd4..8fe48d5 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -476,7 +476,7 @@ public abstract class AbstractObserveService implements ObserveService { protected <S extends ObserveService> S newService(Class<S> serviceType) { - S service = new ObserveServiceFactoryProviderTopia().newService(serviceType, serviceContext); + S service = ObserveServiceFactoryProviderTopia.newSimpleService(serviceType, serviceContext); return service; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit f50756a17f635648eee057b654c9d545930062ce Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed May 6 09:41:27 2015 +0200 les dcp et les callées ne sont plus supprimées --- .../fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java | 2 +- .../java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java index 591d1e3..3fadb25 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java @@ -202,7 +202,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { boolean result; - if (!askToDelete(bean)) { + if (askToDelete(bean)) { result = false; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java index d8dc84c..ff00bdb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java @@ -285,7 +285,7 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { protected boolean doDelete(SetSeine bean) { boolean result; - if (!askToDelete(bean)) { + if (askToDelete(bean)) { result = false; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm