Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: 5679ca6b by Tony Chemit at 2022-07-29T18:00:36+02:00 use cache of simplifiedObjectTypeSpecializedRules - - - - - 30faa65f by Tony Chemit at 2022-07-29T18:00:36+02:00 clean code and comment - - - - - 4 changed files: - client-configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java - client-core/src/main/java/fr/ird/observe/client/ui/admin/consolidate/ConsolidateUIHandler.java - client-core/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java - services-local/src/test/java/fr/ird/observe/services/local/service/actions/consolidate/dcp/SimplifiedObjectTypeManagerTest.java Changes: ===================================== client-configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java ===================================== @@ -30,6 +30,7 @@ import fr.ird.observe.dto.FloatingObjectPreset; import fr.ird.observe.dto.presets.RemoteDataSourceConfiguration; import fr.ird.observe.dto.presets.ServerDataSourceConfiguration; import fr.ird.observe.services.service.CleanTemporaryFilesTaskConfiguration; +import fr.ird.observe.services.service.actions.consolidate.dcp.SimplifiedObjectTypeSpecializedRules; import io.ultreia.java4all.config.ApplicationConfig; import io.ultreia.java4all.config.ApplicationConfigInit; import io.ultreia.java4all.config.ApplicationConfigScope; @@ -44,6 +45,8 @@ import org.nuiton.version.Version; import org.nuiton.version.Versions; import java.io.File; +import java.io.IOException; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -80,29 +83,19 @@ public class ClientConfig extends GeneratedClientConfig implements NavigationTre ClientConfigOption.MAP_LAYER8, ClientConfigOption.MAP_LAYER9, ClientConfigOption.MAP_LAYER10); - /** le pattern du fichier de sauvegarde d'une base locale */ + /** + * le pattern du fichier de sauvegarde d'une base locale + */ private static final String BACKUP_DB_PATTERN = "observe-v%1$s-%2$tF--%2$tk-%2$tM-%2$tS.sql.gz"; private static final String APPLICATION_VERSION = "application.version"; private static final String VERSION = "version"; - private static final String PROPERTY_LOCAL_STORAGE_EXIST = "localStorageExist"; - private static final String PROPERTY_INITIAL_DUMP_EXIST = "initialDumpExist"; - private static final String PROPERTY_MAIN_STORAGE_OPENED = "mainStorageOpened"; - /** Logger */ private static final Logger log = LogManager.getLogger(ClientConfig.class); private static final String DEFAULT_OBSERVE_SWING_CONFIGURATION_FILENAME = "observe-client.conf"; - /** - * Liste des options qu'on ne peut pas sauvegarder (les mots de passes, - * les options d'admin pour les simples utilisateurs,...). - * - * @since 1.5 - */ - private final String[] unsavables = new String[]{ -// ClientConfigOption.OBSTUNA_PASSWORD.getKey(), + private final String[] skipSaveProperties = new String[]{ ClientConfigOption.H2_PASSWORD.getKey(), ClientConfigOption.OBSTUNA_CAN_MIGRATE.getKey(), }; - //FIXME - private final ImmutableSet<String> longlinVesselTypeIds = ImmutableSet.copyOf( + private final ImmutableSet<String> longlineVesselTypeIds = ImmutableSet.copyOf( ImmutableSet.of("fr.ird.observe.entities.referentiel.VesselType#1239832675735#0.044156847891821505", "fr.ird.observe.entities.referentiel.VesselType#1239832675736#0.8708229847859869", "fr.ird.observe.entities.referentiel.VesselType#1239832686137#0.1")); @@ -118,14 +111,18 @@ public class ClientConfig extends GeneratedClientConfig implements NavigationTre * valeur peut être programmées lors des actions. */ private boolean displayMainUI = true; - /** drapeau pour savoir si une base locale existe */ + /** + * drapeau pour savoir si une base locale existe + */ private boolean localStorageExist; /** * drapeau pour savoir si le dump initial a ete chargée depuis la base * centrale */ private boolean initialDumpExist; - /** drapeau pour savoir si une source de données est ouverte */ + /** + * drapeau pour savoir si une source de données est ouverte + */ private boolean mainStorageOpened; /** * drapeau pour savoir si la source ouverte est locale (attention, lorsqu'il @@ -140,13 +137,19 @@ public class ClientConfig extends GeneratedClientConfig implements NavigationTre * trouvé. */ private boolean canUseUI = true; - /** La version de l'application */ + /** + * La version de l'application + */ private Version version; - /** Texte du copyright (calculé dynamiquement). */ + /** + * Texte du copyright (calculé dynamiquement). + */ private String copyrightText; private ImmutableList<ServerDataSourceConfiguration> serverDataSourceConfigurationList; private ImmutableList<RemoteDataSourceConfiguration> remoteDataSourceConfigurationList; + private SimplifiedObjectTypeSpecializedRules simplifiedObjectTypeSpecializedRules; + public ClientConfig() { this(DEFAULT_OBSERVE_SWING_CONFIGURATION_FILENAME); } @@ -372,41 +375,10 @@ public class ClientConfig extends GeneratedClientConfig implements NavigationTre public void saveForUser() { log.info(t("observe.message.save.configuration", get().getUserConfigFile())); - get().saveForUser(unsavables); + get().saveForUser(skipSaveProperties); } public void removeJaxxPropertyChangeListener() { -// pcs.getPropertyChangeListeners(); -// List<String> tmp = new ArrayList<>(); -// for (ClientConfigOption option : ClientConfigOption.values()) { -// String propertyName = option.getPropertyKey(); -// if (propertyName != null) { -// tmp.add(propertyName); -// } -// } -// if (log.isDebugEnabled()) { -// log.debug("property names to seek for options : " + tmp); -// } -// String[] propertyNames = tmp.toArray( -// new String[tmp.size()]); -// -// PropertyChangeListener[] toRemove = -// SwingUtil.findJaxxPropertyChangeListener( -// propertyNames, -// getPropertyChangeListeners()); -// if (toRemove == null || toRemove.length == 0) { -// return; -// } -// if (log.isDebugEnabled()) { -// log.debug("before remove : " + pcs.getPropertyChangeListeners().length); -//// log.debug("toRemove : " + toRemove.length); -// } -// for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) { -// removePropertyChangeListener(listener); -// } -// if (log.isDebugEnabled()) { -// log.debug("after remove : " + pcs.getPropertyChangeListeners().length); -// } } public Set<String> getSeineVesselTypeIds() { @@ -414,7 +386,20 @@ public class ClientConfig extends GeneratedClientConfig implements NavigationTre } public Set<String> getLonglineVesselTypeIds() { - return longlinVesselTypeIds; + return longlineVesselTypeIds; + } + + + public SimplifiedObjectTypeSpecializedRules getSimplifiedObjectTypeSpecializedRules() { + if (simplifiedObjectTypeSpecializedRules == null) { + URI uri = getSimplifiedObjectTypeSpecializedRulesFile().toURI(); + try { + simplifiedObjectTypeSpecializedRules = new SimplifiedObjectTypeSpecializedRules(uri.toURL()); + } catch (IOException e) { + throw new RuntimeException(String.format("Can't load simplifiedObjectTypeSpecializedRules from %s", uri), e); + } + } + return simplifiedObjectTypeSpecializedRules; } @Override ===================================== client-core/src/main/java/fr/ird/observe/client/ui/admin/consolidate/ConsolidateUIHandler.java ===================================== @@ -40,9 +40,6 @@ import org.apache.logging.log4j.Logger; import org.nuiton.jaxx.runtime.spi.UIHandler; import org.nuiton.jaxx.runtime.swing.wizard.ext.WizardState; -import java.io.File; -import java.io.IOException; -import java.net.URL; import java.util.Date; import java.util.Set; import java.util.stream.Collectors; @@ -57,7 +54,6 @@ import static io.ultreia.java4all.i18n.I18n.t; */ public class ConsolidateUIHandler extends AdminTabUIHandler<ConsolidateUI> implements UIHandler<ConsolidateUI> { - /** Logger */ private static final Logger log = LogManager.getLogger(ConsolidateUIHandler.class); @Override @@ -86,8 +82,8 @@ public class ConsolidateUIHandler extends AdminTabUIHandler<ConsolidateUI> imple Set<DataDtoReference<?, ?>> trips = getModel().getSelectDataModel().getSelectionDataModel().getSelectedData(); ImmutableSet<String> tripIds = ImmutableSet.copyOf(trips.stream() - .filter(input -> IdHelper.isTripSeineId(input.getId())) .map(DataDtoReference::getId) + .filter(IdHelper::isTripSeineId) .collect(Collectors.toSet())); ProgressModel progressModel = getStepModel().getProgressModel(); @@ -110,13 +106,7 @@ public class ConsolidateUIHandler extends AdminTabUIHandler<ConsolidateUI> imple request.setTripSeineId(tripId); request.setFailIfLengthWeightParameterNotFound(false); - SimplifiedObjectTypeSpecializedRules simplifiedObjectTypeSpecializedRules; - try { - File definition = ObserveSwingApplicationContext.get().getConfig().getSimplifiedObjectTypeSpecializedRulesFile(); - simplifiedObjectTypeSpecializedRules = new SimplifiedObjectTypeSpecializedRules(definition.toURI().toURL()); - } catch (IOException e) { - throw new RuntimeException(e); - } + SimplifiedObjectTypeSpecializedRules simplifiedObjectTypeSpecializedRules = ObserveSwingApplicationContext.get().getConfig().getSimplifiedObjectTypeSpecializedRules(); ConsolidateTripSeineDataResult result = consolidateDataService.consolidateTripSeine(simplifiedObjectTypeSpecializedRules, request); if (result != null) { ===================================== client-core/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java ===================================== @@ -71,8 +71,6 @@ import javax.swing.SwingUtilities; import javax.swing.event.TableModelListener; import java.awt.Component; import java.awt.Container; -import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -401,13 +399,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, private void recomputeComputedValues() { - SimplifiedObjectTypeSpecializedRules simplifiedObjectTypeSpecializedRules; - try { - File definition = ObserveSwingApplicationContext.get().getConfig().getSimplifiedObjectTypeSpecializedRulesFile(); - simplifiedObjectTypeSpecializedRules = new SimplifiedObjectTypeSpecializedRules(definition.toURI().toURL()); - } catch (IOException e) { - throw new RuntimeException(e); - } + SimplifiedObjectTypeSpecializedRules simplifiedObjectTypeSpecializedRules = ObserveSwingApplicationContext.get().getConfig().getSimplifiedObjectTypeSpecializedRules(); ConsolidateFloatingObjectResult result = getConsolidateDataService().consolidateFloatingObject(simplifiedObjectTypeSpecializedRules, new ConsolidateFloatingObjectRequest(getBean(), getModel().toParts())); if (result != null) { log.info("Flush consolidate dcp changes..."); ===================================== services-local/src/test/java/fr/ird/observe/services/local/service/actions/consolidate/dcp/SimplifiedObjectTypeManagerTest.java ===================================== @@ -45,11 +45,12 @@ import java.util.stream.Collectors; * * @author Tony Chemit - dev@tchemit.fr */ +@SuppressWarnings("SpellCheckingInspection") @DatabaseNameConfiguration(DatabaseName.referentiel) public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport { /** - * From https://gitlab.com/ultreiaio/ird-observe/issues/1412 (specific cases) + * From <a href="https://gitlab.com/ultreiaio/ird-observe/issues/1412">specific cases</a> */ @Test public void getSpecializedStandardCode() throws DatabaseNotFoundException, BabModelVersionException, DatabaseConnexionNotAuthorizedException, IOException { @@ -57,7 +58,7 @@ public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport { URL definition = getClass().getResource("/observe-specialized-fad-rules.properties"); SimplifiedObjectTypeManager simplifiedObjectTypeManager = localTestMethodResource.newService(ConsolidateDataService.class).newSimplifiedObjectTypeManager(new SimplifiedObjectTypeSpecializedRules(definition)); - SimplifiedObjectTypeNode fob = simplifiedObjectTypeManager.getNodeForStandardCode("FOB"); +// SimplifiedObjectTypeNode fob = simplifiedObjectTypeManager.getNodeForStandardCode("FOB"); SimplifiedObjectTypeNode fad = simplifiedObjectTypeManager.getNodeForStandardCode("FAD"); SimplifiedObjectTypeNode dfad = simplifiedObjectTypeManager.getNodeForStandardCode("DFAD"); SimplifiedObjectTypeNode afad = simplifiedObjectTypeManager.getNodeForStandardCode("AFAD"); View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/c6dafea84e2dc9f475363481c... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/c6dafea84e2dc9f475363481c... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT (@tchemit)