Loading bundles/ch.elexis.core.services/src/ch/elexis/core/services/eenv/ElexisEnvironmentService.java 0 → 100644 +29 −0 Original line number Original line Diff line number Diff line package ch.elexis.core.services.eenv; import ch.elexis.core.eenv.IElexisEnvironmentService; import ch.elexis.core.services.holder.ConfigServiceHolder; public class ElexisEnvironmentService implements IElexisEnvironmentService { private String elexisEnvironmentHost; public ElexisEnvironmentService(String elexisEnvironmentHost){ this.elexisEnvironmentHost = elexisEnvironmentHost; } @Override public String getVersion(){ return "unused_unimplemented"; } @Override public String getProperty(String key){ return ConfigServiceHolder.get().get(key, null); } @Override public String getHostname(){ return elexisEnvironmentHost; } } bundles/ch.elexis.core.services/src/ch/elexis/core/services/eenv/ElexisEnvironmentServiceActivator.java 0 → 100644 +79 −0 Original line number Original line Diff line number Diff line package ch.elexis.core.services.eenv; import org.apache.commons.lang3.StringUtils; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.elexis.core.constants.ElexisEnvironmentPropertyConstants; import ch.elexis.core.constants.ElexisSystemPropertyConstants; import ch.elexis.core.eenv.IElexisEnvironmentService; import ch.elexis.core.services.IConfigService; /** * Programmatically register the {@link ElexisEnvironmentService} if conditions are met. That is, * an Elexis-Environment host value is passed. */ @Component public class ElexisEnvironmentServiceActivator { private ServiceRegistration<IElexisEnvironmentService> serviceRegistration; private String elexisEnvironmentHost; private Logger log = LoggerFactory.getLogger(getClass()); @Reference private IConfigService configService; @Activate public void activate(){ // 1. try via system property elexisEnvironmentHost = System.getProperty(ElexisSystemPropertyConstants.EE_HOSTNAME); // 2. if empty fetch via environment variable if(StringUtils.isBlank(elexisEnvironmentHost)) { elexisEnvironmentHost = System.getenv(ElexisEnvironmentPropertyConstants.EE_HOSTNAME); } // 3. if empty fetch via config service if (StringUtils.isBlank(elexisEnvironmentHost)) { elexisEnvironmentHost = configService.get(IElexisEnvironmentService.CFG_EE_HOSTNAME, null); } if (StringUtils.isNotBlank(elexisEnvironmentHost)) { try { // activate the service ElexisEnvironmentService elexisEnvironmentService = new ElexisEnvironmentService( elexisEnvironmentHost); serviceRegistration = FrameworkUtil.getBundle(ElexisEnvironmentServiceActivator.class) .getBundleContext().registerService(IElexisEnvironmentService.class, elexisEnvironmentService, null); log.info("Bound to elexis-environment v{} on [{}]", elexisEnvironmentService.getVersion(), elexisEnvironmentService.getHostname()); } catch (Exception e) { log.warn("Initializing elexis-environment failed", e); } } else { log.debug("No elexis-environment configured"); } } @Deactivate public void deactivate(){ if (serviceRegistration != null) { serviceRegistration.unregister(); } } } bundles/ch.elexis.core.services/src/ch/elexis/core/services/eenv/package-info.java 0 → 100644 +4 −0 Original line number Original line Diff line number Diff line /** * Elexis-Environment specific services. */ package ch.elexis.core.services.eenv; No newline at end of file bundles/ch.elexis.core/src/ch/elexis/core/constants/ElexisEnvironmentPropertyConstants.java +6 −1 Original line number Original line Diff line number Diff line Loading @@ -18,4 +18,9 @@ public class ElexisEnvironmentPropertyConstants { public static String DB_PASSWORD = "DB_PASSWORD"; public static String DB_PASSWORD = "DB_PASSWORD"; public static String DB_JDBC_PARAMETER_STRING = "DB_JDBC_PARAMETER_STRING"; public static String DB_JDBC_PARAMETER_STRING = "DB_JDBC_PARAMETER_STRING"; /** * Elexis-Environment: Entry hostname of the elexis environment */ public static String EE_HOSTNAME = "EE_HOSTNAME"; } } bundles/ch.elexis.core/src/ch/elexis/core/constants/ElexisSystemPropertyConstants.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -32,4 +32,10 @@ public class ElexisSystemPropertyConstants { * REST URL of the elexis server, e.g. http://localhost:8380/services" * REST URL of the elexis server, e.g. http://localhost:8380/services" */ */ public static final String ELEXIS_SERVER_REST_INTERFACE_URL = "elexisServerUrl"; public static final String ELEXIS_SERVER_REST_INTERFACE_URL = "elexisServerUrl"; /** * Elexis-Environment: Entry hostname of the elexis environment. If passed as system property, * overrides both environment variable and Config stored value. */ public static final String EE_HOSTNAME = "EE_HOSTNAME"; } } Loading
bundles/ch.elexis.core.services/src/ch/elexis/core/services/eenv/ElexisEnvironmentService.java 0 → 100644 +29 −0 Original line number Original line Diff line number Diff line package ch.elexis.core.services.eenv; import ch.elexis.core.eenv.IElexisEnvironmentService; import ch.elexis.core.services.holder.ConfigServiceHolder; public class ElexisEnvironmentService implements IElexisEnvironmentService { private String elexisEnvironmentHost; public ElexisEnvironmentService(String elexisEnvironmentHost){ this.elexisEnvironmentHost = elexisEnvironmentHost; } @Override public String getVersion(){ return "unused_unimplemented"; } @Override public String getProperty(String key){ return ConfigServiceHolder.get().get(key, null); } @Override public String getHostname(){ return elexisEnvironmentHost; } }
bundles/ch.elexis.core.services/src/ch/elexis/core/services/eenv/ElexisEnvironmentServiceActivator.java 0 → 100644 +79 −0 Original line number Original line Diff line number Diff line package ch.elexis.core.services.eenv; import org.apache.commons.lang3.StringUtils; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.elexis.core.constants.ElexisEnvironmentPropertyConstants; import ch.elexis.core.constants.ElexisSystemPropertyConstants; import ch.elexis.core.eenv.IElexisEnvironmentService; import ch.elexis.core.services.IConfigService; /** * Programmatically register the {@link ElexisEnvironmentService} if conditions are met. That is, * an Elexis-Environment host value is passed. */ @Component public class ElexisEnvironmentServiceActivator { private ServiceRegistration<IElexisEnvironmentService> serviceRegistration; private String elexisEnvironmentHost; private Logger log = LoggerFactory.getLogger(getClass()); @Reference private IConfigService configService; @Activate public void activate(){ // 1. try via system property elexisEnvironmentHost = System.getProperty(ElexisSystemPropertyConstants.EE_HOSTNAME); // 2. if empty fetch via environment variable if(StringUtils.isBlank(elexisEnvironmentHost)) { elexisEnvironmentHost = System.getenv(ElexisEnvironmentPropertyConstants.EE_HOSTNAME); } // 3. if empty fetch via config service if (StringUtils.isBlank(elexisEnvironmentHost)) { elexisEnvironmentHost = configService.get(IElexisEnvironmentService.CFG_EE_HOSTNAME, null); } if (StringUtils.isNotBlank(elexisEnvironmentHost)) { try { // activate the service ElexisEnvironmentService elexisEnvironmentService = new ElexisEnvironmentService( elexisEnvironmentHost); serviceRegistration = FrameworkUtil.getBundle(ElexisEnvironmentServiceActivator.class) .getBundleContext().registerService(IElexisEnvironmentService.class, elexisEnvironmentService, null); log.info("Bound to elexis-environment v{} on [{}]", elexisEnvironmentService.getVersion(), elexisEnvironmentService.getHostname()); } catch (Exception e) { log.warn("Initializing elexis-environment failed", e); } } else { log.debug("No elexis-environment configured"); } } @Deactivate public void deactivate(){ if (serviceRegistration != null) { serviceRegistration.unregister(); } } }
bundles/ch.elexis.core.services/src/ch/elexis/core/services/eenv/package-info.java 0 → 100644 +4 −0 Original line number Original line Diff line number Diff line /** * Elexis-Environment specific services. */ package ch.elexis.core.services.eenv; No newline at end of file
bundles/ch.elexis.core/src/ch/elexis/core/constants/ElexisEnvironmentPropertyConstants.java +6 −1 Original line number Original line Diff line number Diff line Loading @@ -18,4 +18,9 @@ public class ElexisEnvironmentPropertyConstants { public static String DB_PASSWORD = "DB_PASSWORD"; public static String DB_PASSWORD = "DB_PASSWORD"; public static String DB_JDBC_PARAMETER_STRING = "DB_JDBC_PARAMETER_STRING"; public static String DB_JDBC_PARAMETER_STRING = "DB_JDBC_PARAMETER_STRING"; /** * Elexis-Environment: Entry hostname of the elexis environment */ public static String EE_HOSTNAME = "EE_HOSTNAME"; } }
bundles/ch.elexis.core/src/ch/elexis/core/constants/ElexisSystemPropertyConstants.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -32,4 +32,10 @@ public class ElexisSystemPropertyConstants { * REST URL of the elexis server, e.g. http://localhost:8380/services" * REST URL of the elexis server, e.g. http://localhost:8380/services" */ */ public static final String ELEXIS_SERVER_REST_INTERFACE_URL = "elexisServerUrl"; public static final String ELEXIS_SERVER_REST_INTERFACE_URL = "elexisServerUrl"; /** * Elexis-Environment: Entry hostname of the elexis environment. If passed as system property, * overrides both environment variable and Config stored value. */ public static final String EE_HOSTNAME = "EE_HOSTNAME"; } }