From d2322d9b3dc3585baf57427d49724eb08f4ed54a Mon Sep 17 00:00:00 2001 From: romank-agfa Date: Mon, 1 Jun 2015 13:21:15 +0200 Subject: [PATCH] [DCMEEREQ-306] Upgrades/Migration of Configuration --- ...EE.java => DicomConfigurationEEAddon.java} | 50 +++++++++++-------- .../SemiSerializedDBConfigStorage.java | 5 ++ 2 files changed, 35 insertions(+), 20 deletions(-) rename dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/{DicomConfigurationExtenderEE.java => DicomConfigurationEEAddon.java} (66%) diff --git a/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationExtenderEE.java b/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationEEAddon.java similarity index 66% rename from dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationExtenderEE.java rename to dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationEEAddon.java index 25c4d91..b8648be 100644 --- a/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationExtenderEE.java +++ b/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationEEAddon.java @@ -39,10 +39,13 @@ */ package org.dcm4chee.conf.cdi; -import org.dcm4che3.conf.api.DicomConfigurationCustomizer; +import org.dcm4che3.conf.api.DicomConfigurationBuilderAddon; +import org.dcm4che3.conf.api.internal.DicomConfigurationManager; +import org.dcm4che3.conf.api.migration.MigrationScript; import org.dcm4che3.conf.core.api.Configuration; import org.dcm4che3.conf.core.api.ConfigurationException; import org.dcm4che3.conf.dicom.DicomConfigurationBuilder; +import org.dcm4che3.conf.migration.MigrationRunner; import org.dcm4che3.net.AEExtension; import org.dcm4che3.net.DeviceExtension; import org.dcm4che3.net.hl7.HL7ApplicationExtension; @@ -53,6 +56,9 @@ import javax.enterprise.inject.Instance; import javax.enterprise.inject.Produces; import javax.inject.Inject; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** * Centralized handling for all Java EE - based enhancements, @@ -61,10 +67,11 @@ * * @author Roman K */ -public class DicomConfigurationExtenderEE { +@ApplicationScoped +public class DicomConfigurationEEAddon implements DicomConfigurationBuilderAddon { private static Logger log = LoggerFactory - .getLogger(DicomConfigurationExtenderEE.class); + .getLogger(DicomConfigurationEEAddon.class); @Inject Instance deviceExtensions; @@ -78,27 +85,30 @@ public class DicomConfigurationExtenderEE { @Inject Instance customConfigStorage; - @Produces - @ApplicationScoped - public DicomConfigurationCustomizer getConfigurationEECustomizer() - throws ConfigurationException { + @Inject + Instance migrationScripts; - return new DicomConfigurationCustomizer() { - @Override - public void customize(DicomConfigurationBuilder builder) { + @Override + public void beforeBuild(DicomConfigurationBuilder builder) { + for (DeviceExtension ext : deviceExtensions) builder.registerDeviceExtension(ext.getClass()); + for (AEExtension ext : aeExtensions) builder.registerAEExtension(ext.getClass()); + for (HL7ApplicationExtension ext : hl7ApplicationExtensions) + builder.registerHL7ApplicationExtension(ext.getClass()); - for (DeviceExtension ext : deviceExtensions) builder.registerDeviceExtension(ext.getClass()); - for (AEExtension ext : aeExtensions) builder.registerAEExtension(ext.getClass()); - for (HL7ApplicationExtension ext : hl7ApplicationExtensions) - builder.registerHL7ApplicationExtension(ext.getClass()); + if (!customConfigStorage.isUnsatisfied()) { + builder.registerCustomConfigurationStorage(customConfigStorage.get()); + } + } - if (!customConfigStorage.isUnsatisfied()) { - builder.registerCustomConfigurationStorage(customConfigStorage.get()); - } + @Override + public void afterBuild(DicomConfigurationManager manager) throws ConfigurationException { - } - }; - } + // trigger migration + List scripts = new ArrayList<>(); + for (MigrationScript migrationScript : migrationScripts) scripts.add(migrationScript); + new MigrationRunner(manager.getConfigurationStorage(), scripts, manager).migrate(); + + } } diff --git a/dcm4chee-conf-db/src/main/java/org/dcm4chee/conf/storage/SemiSerializedDBConfigStorage.java b/dcm4chee-conf-db/src/main/java/org/dcm4chee/conf/storage/SemiSerializedDBConfigStorage.java index 4d879d5..c1a4596 100644 --- a/dcm4chee-conf-db/src/main/java/org/dcm4chee/conf/storage/SemiSerializedDBConfigStorage.java +++ b/dcm4chee-conf-db/src/main/java/org/dcm4chee/conf/storage/SemiSerializedDBConfigStorage.java @@ -136,4 +136,9 @@ public Iterator search(String liteXPathExpression) throws IllegalArgumentExcepti throw new RuntimeException("Not implemented"); } + @Override + public void lock() { + //TODO + } + }