| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.preferences; |
| |
| import java.io.File; |
| import java.io.IOException; |
| import java.lang.reflect.InvocationTargetException; |
| import java.lang.reflect.Method; |
| import java.text.SimpleDateFormat; |
| import java.util.ArrayList; |
| import java.util.Collection; |
| import java.util.Comparator; |
| import java.util.Date; |
| import java.util.HashMap; |
| import java.util.HashSet; |
| import java.util.List; |
| import java.util.Locale; |
| import java.util.Map; |
| import java.util.Properties; |
| import java.util.Set; |
| import java.util.TreeMap; |
| import java.util.TreeSet; |
| |
| import javax.sql.CommonDataSource; |
| |
| import org.apache.commons.io.IOUtils; |
| import org.apache.commons.lang3.StringUtils; |
| import org.eclipse.core.internal.preferences.EclipsePreferences; |
| import org.eclipse.core.internal.preferences.InstancePreferences; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.resources.IWorkspace; |
| import org.eclipse.core.resources.IWorkspaceRoot; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.core.runtime.preferences.ConfigurationScope; |
| import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
| import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; |
| import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; |
| import org.eclipse.core.runtime.preferences.IPreferenceNodeVisitor; |
| import org.eclipse.core.runtime.preferences.IScopeContext; |
| import org.eclipse.core.variables.VariablesPlugin; |
| import org.eclipse.persistence.config.PersistenceUnitProperties; |
| import org.osgi.service.prefs.BackingStoreException; |
| import org.osgi.service.prefs.Preferences; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| class StringComparator implements Comparator<String> { |
| @Override |
| public int compare(String arg0, String arg1) { |
| return arg0.compareTo(arg1); |
| } |
| } |
| |
| /** |
| * Access to the Product Configuration!<br> |
| * <i>For now empty configuration data will be <u>auto-generated to hit our |
| * internal development configuration</u>!</i> |
| */ |
| public class ProductConfigurationPrefs implements IProductConfigurationPrefs { |
| |
| /* ========================= variables =========================== */ |
| |
| private String businessBundleClassNameReadOnly; |
| private String euroForeignExchangeReferenceRatesURLDaily; |
| private String euroForeignExchangeReferenceRatesURLPrevious; |
| private int authRESTfulApiPort = 0; |
| private int maxLoginAttempts = 0; |
| private String protocolDatasource; |
| private String protocolUnit; |
| private boolean identifyByUsername = true; |
| private boolean autoLogin = false; |
| private boolean encryptPasswords = true; |
| private boolean noRememberMe = false; |
| private String adminEmail = ""; |
| private String adminEmailUsername = ""; |
| private String adminEmailPassword = ""; //NOSONAR |
| private String activeMqBrokerServerName; |
| private int activeMqBrokerServerPort; |
| private int hybridRefresherMilliSecsActive; |
| private int hybridRefresherMilliSecsInactive; |
| private Map<String, IShiroConfiguration> shiros = new HashMap<>(); |
| private String dataSourceForAuthentication = DEFAULT_DATASOURCE_FOR_AUTHENTICATION; |
| private String dataSourceForBLOB = DEFAULT_DATASOURCE_FOR_BLOB; |
| private String dataSourceForBPM = DEFAULT_DATASOURCE_FOR_BPM; |
| private String dataSourceForBusinessData = DEFAULT_DATASOURCE_FOR_BUSINESSDATA; |
| private Map<String, DataSourceConfiguration> dataSources = new HashMap<>(); |
| private Map<String, PersistenceUnitConfiguration> persistenceUnits = new HashMap<>(); |
| private Map<String, Locale> languages = new TreeMap<>(new StringComparator()); |
| private boolean languagesAutotranslate; |
| private boolean languagesAutocreate; |
| private boolean uomoMetricUnit; |
| private boolean showLanguageSelectInRespectiveLocale; |
| private String bpmServerIp; |
| private int bpmServerPort; |
| private int bpmResponseTimeout; |
| private boolean bpmHibernateShowSql; |
| private boolean bpmHibernateFormatSql; |
| private int bpmHibernateMaxFetchDepth; |
| private String bpmHibernateSchemaName; |
| private boolean demoToolsTheme; |
| private boolean demoToolsLanguage; |
| private boolean demoToolsPrintService; |
| private boolean projectWizardAbsoluteLocation; |
| private boolean mavenActivated; |
| |
| /* ========================= internal utilities =========================== */ |
| |
| public static final String PREFERENCES_PATH = ".metadata/.plugins/org.eclipse.core.runtime/"+EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME+"/"; |
| public static final String PRODUCT_PREFERENCES = "org.eclipse.osbp.production"; |
| public static final String PREFERENCES_FULL_PATH = PREFERENCES_PATH+PRODUCT_PREFERENCES+"."+EclipsePreferences.PREFS_FILE_EXTENSION; |
| |
| private static final Logger LOGGER = LoggerFactory.getLogger(ProductConfigurationPrefs.class); |
| private boolean forceInitialize = true; |
| private final IScopeContext scopeContext; |
| /** listener triggered by preference changed due to user actions inside preference dialog */ |
| private final IPreferenceChangeListener preferenceChangedListener; |
| private final IProject project; |
| private final String name; |
| |
| private final IProductConfigurationPrefs defaultPrefs; |
| private String authenticationOrganizationId; |
| private String emailServerIp; |
| private Integer emailSmtpPort; |
| private Boolean emailUseSslOnConnect; |
| private String javaPosConfiguration; |
| private String datainterchangeConfiguration; |
| private String signalConfiguration; |
| |
| public static final String BUSINESS_BUNDLE_CLASS_NAME = "BUSINESS_BUNDLE_CLASS_NAME_read_only"; |
| |
| /* ========================= languages initializer =========================== */ |
| |
| private static final String LANGUAGES_NODE = "languages"; |
| private static final String LANGUAGES_SUPPORTED = "languages.supported"; |
| private static final String LANGUAGES_AUTOTRANSLATE = "languages.autotranslate"; |
| private static final String LANGUAGES_AUTOCREATE = "languages.autocreate"; |
| private static final String LANGUAGES_SHOW_SELECT_IN_RESPECTIVE_LOCALE = "lanuages.selectInRespectiveLocales"; |
| // See: |
| // http://code.google.com/apis/language/translate/v2/getting_started.html |
| private static final String LANGUAGES_GOOGLE_HTTP_REFERRER = "languages.google_http_referrer"; |
| private static final String LANGUAGES_GOOGLE_API_KEY = "languages.google_api_key"; |
| |
| private static final String LANGUAGES_LANGUAGE = "language"; |
| private static final String LANGUAGES_COUNTRY = "country"; |
| private static final String LANGUAGES_VARIANT = "variant"; |
| |
| /* ========================= uomounit initializer =========================== */ |
| |
| private static final String UOMOUNIT_NODE = "uomoUnits"; |
| |
| private static final String UOMOUNIT_METRIC = "uomoUnitMetric"; |
| |
| /* ========================= xref rates initializer =========================== */ |
| |
| private static final String EURO_X_REF_URL_NODE = "euroxrefurl"; |
| private static final String EURO_X_REF_URL_DAILY = "daily"; |
| private static final String EURO_X_REF_URL_PREVIOUS = "previous"; |
| |
| /* ========================= JavaPOS initializer =========================== */ |
| |
| private static final String JAVA_POS_NODE = "javaPOS"; |
| private static final String JAVA_POS_CONFIGURATION = "javaPosConfiguration"; |
| |
| /* ========================= Datainterchange initializer =========================== */ |
| |
| private static final String DATAINTERCHANGE_NODE = "datainterchange"; |
| private static final String DATAINTERCHANGE_CONFIGURATION = "datainterchangeConfiguration"; |
| |
| /* ========================= Signal initializer =========================== */ |
| |
| private static final String SIGNAL_NODE = "signal"; |
| private static final String SIGNAL_CONFIGURATION = "signalConfiguration"; |
| |
| /* ========================= authentication initializer =========================== */ |
| |
| public static final String AUTHENTICATION_NODE = "authentication"; |
| private static final String AUTH_RESTFUL_PORT = "authRESTfulPort"; |
| private static final String AUTHENTICATION_AUTOLOGIN = "autoLogin"; |
| private static final String AUTHENTICATION_ORGANIZATION_ID = "organizationId"; |
| public static final String AUTHENTICATION_ENCRYPT_PASSWORDS = "encryptPasswords"; //NOSONAR |
| private static final String AUTHENTICATION_HIDE_REMEMBER_ME = "noRememberMe"; |
| private static final String AUTHENTICATION_ADMIN_EMAIL_ACCOUNT = "adminEmail"; |
| private static final String AUTHENTICATION_ADMIN_EMAIL_USERNAME = "adminEmailUsername"; |
| private static final String AUTHENTICATION_ADMIN_EMAIL_PASSWORD = "adminEmailPassword"; //NOSONAR |
| |
| /* ========================= email initializer =========================== */ |
| |
| public static final String EMAIL_NODE = "emailService"; |
| private static final String EMAIL_SERVER_IP = "serverIp"; |
| private static final String EMAIL_SMTP_PORT = "smtpPort"; |
| private static final String EMAIL_USE_SSL_ON_CONNECT = "sslOnConnect"; |
| |
| /* ========================= authentication initializer =========================== */ |
| |
| private static final String ACTIVEMQBROKER_NODE = "activeMqBroker"; |
| private static final String ACTIVEMQBROKER_SERVER = "server"; |
| private static final String ACTIVEMQBROKER_PORT = "port"; |
| |
| /* ========================= hybrid connection initializer =========================== */ |
| |
| private static final String HYBRID_NODE = "hybrid"; |
| private static final String HYBRID_REFRESHER_MILLISECS_ACTIVE = "refresherMilliSecsActive"; |
| private static final String HYBRID_REFRESHER_MILLISECS_INACTIVE = "refresherMilliSecsInactive"; |
| /* ========================= hybrid connection initializer =========================== */ |
| |
| public static final String SHIRO_NODE = "shiro"; |
| public static final String SHIRO_DTO_REALM = "DTORealm"; |
| public static final String SHIRO_LDAP_REALM = "LDAPRealm"; |
| public static final String SHIRO_MAX_LOGIN_ATTEMPTS = "maxLoginAttempts"; |
| public static final String SHIRO_PROTOCOL_DATASOURCE = "datasource"; |
| public static final String SHIRO_PROTOCOL_UNIT = "persistenceunit"; |
| public static final String SHIRO_IDENTIFY_BY_USERNAME = "identifyByUsername"; |
| |
| public static final String SHIRO_DTO_REALM_CLASS = "org.eclipse.osbp.authentication.shiro.extensions.DTORealm"; |
| public static final String SHIRO_LDAP_REALM_CLASS = "org.eclipse.osbp.authentication.shiro.extensions.LDAPRealm"; |
| |
| private static final String DTO_PORTAL_ID = "portalId"; |
| private static final String LDAP_PORTAL_ID = "portalId"; |
| private static final String LDAP_URL = "contextFactoryUrl"; |
| private static final String LDAP_USERDNTEMPLATE = "userDnTemplate"; |
| |
| /* ========================= data source initializer =========================== */ |
| |
| public static final String DEFAULT_H2MEMORY_DATASOURCE = "h2memory"; |
| public static final String DEFAULT_H2LOCALFILE_DATASOURCE = "h2localfile"; |
| |
| public static final String DEFAULT_DERBYLOCALFILE_DATASOURCE = "derbylocalfile"; |
| public static final String DEFAULT_DERBYMEMORY_DATASOURCE = "derbymemory"; |
| public static final String DEFAULT_DERBYSERVER_DATASOURCE = "derbyserver"; |
| |
| private static final String DEFAULT_INITIAL_DATASOURCE = "oracle"; |
| |
| public static final String DEFAULT_DATASOURCE_FOR_AUTHENTICATION = DEFAULT_INITIAL_DATASOURCE; |
| public static final String DEFAULT_DATASOURCE_FOR_BLOB = DEFAULT_INITIAL_DATASOURCE; |
| public static final String DEFAULT_DATASOURCE_FOR_BPM = DEFAULT_INITIAL_DATASOURCE; |
| public static final String DEFAULT_DATASOURCE_FOR_BUSINESSDATA = DEFAULT_INITIAL_DATASOURCE; |
| |
| private static final String DATASOURCE_NODE = "datasource"; |
| private static final String DATASOURCE_ENUM_ITEM = "enum.item"; |
| private static final String DATASOURCE_DRIVER_VENDOR = "driver.vendor"; |
| private static final String DATASOURCE_DRIVER_TYPE = "driver.type"; |
| private static final String DATASOURCE_DRIVER_CLASS = "driver.class"; |
| private static final String DATASOURCE_SERVER_NAME = "server.name"; |
| private static final String DATASOURCE_SERVER_PORT = "server.port"; |
| private static final String DATASOURCE_DATABASE_NAME = "database.name"; |
| private static final String DATASOURCE_DATABASE_USER = "database.user"; |
| private static final String DATASOURCE_DATABASE_PASS = "database.pass"; |
| private static final String DATASOURCE_JDBC_URL_FORMAT = "database.jdbcUrlFormat"; |
| |
| /* ========================= bpm unit initializer =========================== */ |
| |
| public static final String BPM_NODE = "bpmEngine"; |
| private static final String BPM_SERVER_IP = "serverIp"; |
| private static final String BPM_SERVER_PORT = "serverPort"; |
| private static final String BPM_RESPONSE_TIMEOUT = "responseTimeout"; |
| private static final String BPM_HIBERNATE_SHOW_SQL = "hibernateShowSql"; |
| private static final String BPM_HIBERNATE_FORMAT_SQL = "hibernateFormatSql"; |
| private static final String BPM_HIBERNATE_MAX_FETCH_DEPTH = "hibernateMaxFetchDepth"; |
| private static final String BPM_HIBERNATE_SCHEMA_NAME = "hibernateSchemaName"; |
| |
| /* ========================= persistence unit initializer =========================== */ |
| |
| public static final String PERSISTENCE_UNIT_AUTHENTICATION = "authentication"; |
| public static final String PERSISTENCE_UNIT_BLOB = "blob"; |
| public static final String PERSISTENCE_UNIT_BPM = "bpm"; |
| public static final String PERSISTENCE_UNIT_BUSINESSDATA = "businessdata"; |
| |
| private static final String PERSISTENCE_NODE = "persistenceUnit"; |
| private static final String PERSISTENCE_DATASOURCE = "jndiName"; |
| private static final String PERSISTENCE_DEPLOYONSTARTUP = "deployOnStartup"; |
| private static final String PERSISTENCE_QUERYCACHE = "queryCache"; |
| private static final String PERSISTENCE_BATCHWRITING = "batchWriting"; |
| private static final String PERSISTENCE_BATCHWRITINGSIZE = "batchWritingSize"; |
| private static final String PERSISTENCE_CACHESTATEMENTS = "cacheStatements"; |
| private static final String PERSISTENCE_CACHESTATEMENTSSIZE = "cacheStatementsSize"; |
| private static final String PERSISTENCE_LOGGINGLEVEL = "loggingLevel"; |
| private static final String PERSISTENCE_DDLGENERATION = "ddlGeneration"; |
| private static final String PERSISTENCE_PERSISTENCEXMLPATH = "persistenceXMLPath"; |
| private static final String PERSISTENCE_WEAVING = "weaving"; |
| |
| /* ========================= mock data generator initializer =========================== */ |
| |
| private static final String MOCK_DATA_GENERATORS_DONE = "mockDataGeneratorsDone"; |
| /* ========================= project wizard initializer =========================== */ |
| |
| private static final String PROJECT_WIZARD_NODE = "projectWizard"; |
| private static final String PROJECT_WIZARD_ABSOLUTE_LOCATION = "absoluteLocation"; |
| /* ========================= demo settings initializer =========================== */ |
| private static final String DEMO_NODE = "demo"; |
| private static final String DEMO_TOOLS_THEME = "demoToolsTheme"; |
| private static final String DEMO_TOOLS_STRATEGY = "demoToolsStrategy"; |
| private static final String DEMO_TOOLS_LANGUAGE = "demoToolsLanguage"; |
| private static final String DEMO_TOOLS_PRINTSERVICE = "toolsPrintService"; |
| /* ========================= maven settings initializer =========================== */ |
| private static final String MAVEN_ACTIVATED = "mavenActivated"; |
| /* ========================= report printer settings initializer =========================== */ |
| private static final String REPORT_PRINTER_NODE = "reportPrinter"; |
| |
| public static enum DDL_GENERATION { |
| CREATE ("create-tables", "create"), |
| DROP_CREATE ("drop-and-create-tables", "create"), |
| UPDATE ("create-or-extend-tables", "update"), |
| NONE ("none", "validate"); |
| |
| private final String eclipseLink; |
| private final String hibernate; |
| |
| private DDL_GENERATION(String eclipseLink, String hibernate) { |
| this.eclipseLink = eclipseLink; |
| this.hibernate = hibernate; |
| } |
| |
| public String eclipseLink() { |
| return eclipseLink; |
| } |
| |
| public String hibernate() { |
| return hibernate; |
| } |
| |
| public static String hibernate(String eclipseLink) { |
| for (DDL_GENERATION step : values()) { |
| if (step.eclipseLink.equals(eclipseLink)) { |
| return step.hibernate; |
| } |
| } |
| return NONE.hibernate; |
| } |
| } |
| |
| public Set<EnumDatabaseVendor> getDataBaseVendors() { |
| TreeSet<EnumDatabaseVendor> result = new TreeSet<EnumDatabaseVendor>(); |
| for (String pu : getPersistenceUnitNames()) { |
| addDataBaseVendor(result, getPersistenceUnitJndiName(pu)); |
| } |
| return result; |
| } |
| |
| public Set<EnumDatabaseVendor> getDataBaseVendors(String... jndiNames) { |
| TreeSet<EnumDatabaseVendor> result = new TreeSet<EnumDatabaseVendor>(); |
| for (String jndiName : jndiNames) { |
| addDataBaseVendor(result, jndiName); |
| } |
| return result; |
| } |
| |
| private void addDataBaseVendor(TreeSet<EnumDatabaseVendor> result, String jndiName) { |
| DataSourceConfiguration ds = getDataSource(jndiName); |
| if (ds != null) { |
| result.add(ds.getDatabaseVendor()); |
| } |
| } |
| |
| public ProductConfigurationPrefs(String name, IScopeContext scopeContext, boolean watchRegister, IProject project) { |
| defaultPrefs = new ProductConfigurationDefaultPrefs(); |
| this.scopeContext = scopeContext; |
| this.name = name; |
| this.project = project; |
| if (watchRegister) { |
| preferenceChangedListener = new IPreferenceChangeListener() { |
| @Override |
| public void preferenceChange(PreferenceChangeEvent event) { |
| forceReloadConfiguration(); |
| } |
| }; |
| } |
| else { |
| preferenceChangedListener = null; |
| } |
| LOGGER.trace(getInformation()+" # constructed"); |
| } |
| |
| public IScopeContext getScopeContext() { |
| return scopeContext; |
| } |
| |
| public ProductConfigurationPrefs(String name, IScopeContext scopeContext, IProject project) { |
| this(name, scopeContext, false, project); |
| } |
| |
| public ProductConfigurationPrefs(String name, IScopeContext scopeContext) { |
| this(name, scopeContext, false, null); |
| } |
| |
| public IProject getProject() { |
| if (project instanceof IProject) { |
| return project; |
| } |
| else { |
| return null; |
| } |
| } |
| |
| public IPath getProjectPath() { |
| if (getProject() instanceof IProject) { |
| return getProject().getLocation(); |
| } |
| else { |
| return null; |
| } |
| } |
| |
| public static String getCloneWorkspaceProductConfiguration() { |
| Set<String> serialized = new TreeSet<>(); |
| serialize(ProductConfiguration.workspacePrefs().getProductPreferences(), "", serialized); |
| Set<String> result = new TreeSet<>(); |
| for (String item : serialized) { |
| if (!item.startsWith("persistenceUnit") && |
| !item.startsWith("datasource.") && |
| !item.startsWith("shiro/datasource") && |
| !item.startsWith("shiro/persistenceunit") |
| ) { |
| result.add(item); |
| } |
| } |
| return StringUtils.join(result, "\n"); |
| } |
| |
| private static void serialize(Preferences node, String prefix, Set<String> result) { |
| if (node != null) { |
| try { |
| for (String child : node.childrenNames()) { |
| serialize(node.node(child), prefix+child+"/", result); |
| } |
| for (String key : node.keys()) { |
| result.add(prefix+key+"="+node.get(key, "").replace("=", "\\=").replace(":", "\\:")); |
| } |
| } |
| catch (BackingStoreException e) { |
| LOGGER.error("serializing product configuration", e); |
| } |
| } |
| } |
| |
| public static IResource getPrefsFile(IProject project) { |
| IResource prefsFile = null; |
| try { |
| for (IResource resource : project.members()) { |
| if ((resource instanceof IFile) && "product".equals(resource.getFileExtension())) { |
| try { |
| String[] tokens = IOUtils.toString(((IFile)resource).getContents()).split("-DproductConfigurationFile="); |
| if (tokens.length > 1) { |
| String filePath = tokens[1].replace('\r', ' ').replace('\n', ' ').replace('\t', ' ').split(" ")[0].replace("DEFAULTFILE", PREFERENCES_FULL_PATH); |
| // The following line is required to perform a string substitution. |
| // In case of having a file path with placeholders this will replace them with the defined string in the eclipse string substitution preferences: |
| // Reference > Preferences > Run/Debug > String Substitution |
| filePath = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(filePath); |
| File handle = new File(filePath); |
| if (handle.exists()) { |
| String fileName = handle.getAbsolutePath(); |
| IWorkspace space = ResourcesPlugin.getWorkspace(); |
| IWorkspaceRoot root=space.getRoot(); |
| try { // NOSONAR |
| IFile[] resources = root.findFilesForLocationURI(new File(fileName).toURI()); |
| if (resources != null) { |
| prefsFile = resources[0]; |
| break; |
| } |
| } |
| catch (Exception e) { // NOSONAR |
| e.printStackTrace(); |
| } // NOSONAR |
| } |
| } |
| } catch (IOException e) { |
| e.printStackTrace(); // NOSONAR |
| } |
| } // NOSONAR |
| } |
| } |
| catch (CoreException e) { // NOSONAR |
| e.printStackTrace(); // NOSONAR |
| } |
| return prefsFile; |
| } |
| |
| |
| |
| public String getName() { |
| return name; |
| } |
| |
| /* ========================= getters =========================== */ |
| |
| /** |
| * @see http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html |
| * @return URL to server with the daily Euro Foreign Exchange Reference |
| * Rates |
| */ |
| public String getEuroXRefRatesURLDaily() { |
| initialize(); |
| return euroForeignExchangeReferenceRatesURLDaily; |
| } |
| |
| /** |
| * @see http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html |
| * @return URL to server with the previous Euro Foreign Exchange Reference |
| * Rates |
| */ |
| public String getEuroXRefRatesURLPrevious() { |
| initialize(); |
| return euroForeignExchangeReferenceRatesURLPrevious; |
| } |
| |
| /** |
| * @return name of the server running the ActiveMQ Broker Service |
| */ |
| public String getActiveMqBrokerServerName() { |
| initialize(); |
| return activeMqBrokerServerName; |
| } |
| |
| /** |
| * @return port of the server running the ActiveMQ Broker Service |
| */ |
| public int getActiveMqBrokerServerPort() { |
| initialize(); |
| return activeMqBrokerServerPort; |
| } |
| |
| /** |
| * @return milliseconds for refresher in an active hybrid ccng view |
| */ |
| public int getHybridRefresherMilliSecsActive() { |
| initialize(); |
| return hybridRefresherMilliSecsActive; |
| } |
| |
| /** |
| * @return milliseconds for refresher in an inactive hybrid ccng view |
| */ |
| public int getHybridRefresherMilliSecsInactive() { |
| initialize(); |
| return hybridRefresherMilliSecsInactive; |
| } |
| |
| /** |
| * @return list of name of all defined DataSources |
| */ |
| public Collection<DataSourceConfiguration> getDataSources() { |
| initialize(); |
| return dataSources.values(); |
| } |
| |
| /** |
| * @return list of name of all defined DataSources |
| */ |
| public Set<String> getDataSourceNames() { |
| initialize(); |
| return dataSources.keySet(); |
| } |
| |
| // /** |
| // * @return the name of the active DataSource |
| // */ |
| // public String getDataSourceNameForAuthentication() { |
| // initialize(); |
| // return dataSourceForAuthentication; |
| // } |
| // |
| // /** |
| // * @return the name of the active DataSource |
| // */ |
| // public String getDataSourceNameForBLOB() { |
| // initialize(); |
| // return dataSourceForBLOB; |
| // } |
| // |
| // /** |
| // * @return the name of the bpm DataSource |
| // */ |
| // public String getDataSourceNameForBPM() { |
| // initialize(); |
| // return dataSourceForBPM; |
| // } |
| // |
| // /** |
| // * @return the name of the bpm DataSource |
| // */ |
| // public String getDataSourceNameForBusinessData() { |
| // initialize(); |
| // return dataSourceForBusinessData; |
| // } |
| |
| /** |
| * @param jndiName |
| * the requested DataSource |
| * @return the properties to define a DataSource |
| */ |
| public Properties getDataSourceProperties(String jndiName) { |
| DataSourceConfiguration jndi = getDataSource(jndiName); |
| return (jndi == null) ? null : jndi.getDataSourceProperties(); |
| } |
| |
| public DataSourceConfiguration getDataSource(String jndiName) { |
| try { |
| initializeDataSources(); |
| } |
| catch (Exception e) { // NOSONAR |
| e.printStackTrace(); // NOSONAR |
| } |
| return dataSources.get(jndiName); |
| } |
| |
| /** |
| * @param jndiName |
| * the requested DataSource |
| * @return name of the JDBC driver class |
| */ |
| public EnumDatabaseVendor getDataSourceDatabaseVendor(String jndiName) { |
| initialize(); |
| DataSourceConfiguration jndi = dataSources.get(jndiName); |
| return (jndi == null) ? null : jndi.getDatabaseVendor(); |
| } |
| |
| /** |
| * @param jndiName |
| * the requested DataSource |
| * @return name of the JDBC driver class |
| */ |
| public String getDataSourceDriverClass(String jndiName) { |
| initialize(); |
| DataSourceConfiguration jndi = dataSources.get(jndiName); |
| return (jndi == null) ? null : jndi.getDriverClass(); |
| } |
| |
| /** |
| * @param jndiName |
| * the requested DataSource |
| * @return the properties to define a JPA connection |
| */ |
| public Properties getJpaProperties(String jndiName) { |
| initialize(); |
| DataSourceConfiguration jndi = dataSources.get(jndiName); |
| return (jndi == null) ? null : jndi.getJpaProperties(); |
| } |
| |
| /** |
| * @return list of name of all defined DataSources |
| */ |
| public Collection<PersistenceUnitConfiguration> getPersistenceUnits() { |
| initialize(); |
| return persistenceUnits.values(); |
| } |
| |
| /** |
| * @return list of name of all defined DataSources |
| */ |
| public Set<String> getPersistenceUnitNames() { |
| initialize(); |
| return persistenceUnits.keySet(); |
| } |
| |
| /** |
| * @return JNDI name for the given persistence unit |
| */ |
| public String getPersistenceUnitJndiName(String persistenceUnitName) { |
| initialize(); |
| PersistenceUnitConfiguration puConfig = persistenceUnits.get(persistenceUnitName); |
| if (puConfig!=null){ |
| return puConfig.getJndiName(); |
| } else { |
| LOGGER.error("No persistence unit named '" + persistenceUnitName + "' found. Check the defined persistence unit of your entity."); |
| return null; |
| } |
| } |
| |
| public String getPersistenceUnitHibernateDialect(String persistenceUnitName) { |
| return getJndiNameHibernateDialect(getPersistenceUnitJndiName(persistenceUnitName)); |
| } |
| |
| public String getJndiNameHibernateDialect(String jndiName) { |
| initialize(); |
| DataSourceConfiguration jndi = dataSources.get(jndiName); |
| return (jndi == null) ? null : jndi.getDatabaseVendor().getHibernateDialect(); |
| } |
| |
| /** |
| * Gets the paramterized ddl generation flag for the given persistence unit. |
| * |
| * @param persistenceUnitName the persistence unit name |
| * @return the ddl generation flag |
| */ |
| public String getPersistenceUnitParameterizedEclipseLinkDdlGeneration(String persistenceUnitName) { |
| return persistenceUnits.get(persistenceUnitName).getDdlGeneration(); |
| } |
| |
| /** |
| * Gets the effective ddl generation flag for the given persistence unit. |
| * <br> |
| * If an in-memory database is used, always <code>create-tables</code> will be returned. |
| * |
| * @param persistenceUnitName the persistence unit name |
| * @return the ddl generation flag |
| */ |
| public String getPersistenceUnitEffectiveEclipseLinkDdlGeneration(String persistenceUnitName) { |
| EnumDatabaseVendor vendor = getDataSourceDatabaseVendor(getPersistenceUnitJndiName(persistenceUnitName)); |
| if (vendor.isInMemory()) { |
| return DDL_GENERATION.CREATE.eclipseLink; |
| } |
| else { |
| switch (vendor) { |
| default: |
| return getPersistenceUnitParameterizedEclipseLinkDdlGeneration(persistenceUnitName); |
| } |
| } |
| } |
| |
| /** |
| * @param jndiName |
| * the requested DataSource |
| * @return the properties to define a DataSource |
| */ |
| public Properties getPersistenceUnitProperties( |
| String persistenceUnitName, CommonDataSource dataSource, ClassLoader classLoader) { |
| initialize(); |
| if (persistenceUnits.containsKey(persistenceUnitName)) { |
| return persistenceUnits.get(persistenceUnitName) |
| .getPersistenceUnitProperties(dataSource, classLoader); |
| } |
| return null; |
| } |
| |
| @Override |
| public String getAuthenticationOrganizationId() { |
| initialize(); |
| return authenticationOrganizationId; |
| } |
| |
| /** |
| * @return port of the RESTful authentication API, needed by the hybrid |
| * WebClient cxauth |
| */ |
| public final int getAuthRESTfulPort() { |
| initialize(); |
| return authRESTfulApiPort; |
| } |
| |
| /** |
| * @return decide remember-me function performs an auto-login or not |
| */ |
| public final boolean hasAutoLogin() { |
| initialize(); |
| return autoLogin; |
| } |
| |
| /** |
| * @return hide remember-me function if true |
| */ |
| public final boolean hasNoRememberMe() { |
| initialize(); |
| return noRememberMe; |
| } |
| |
| public final int getDtoRealmPortalId() { |
| initialize(); |
| try { |
| DtoConfiguration configuration = (DtoConfiguration) getShiroRealmConfiguration(SHIRO_DTO_REALM); |
| return configuration.getPortalId(); |
| } |
| catch (Exception e) { // NOSONAR |
| e.printStackTrace(); // NOSONAR |
| } |
| return 1; |
| } |
| |
| public final int getLdapRealmPortalId() { |
| initialize(); |
| try { |
| LdapConfiguration configuration = (LdapConfiguration) getShiroRealmConfiguration(SHIRO_LDAP_REALM); |
| return configuration.getPortalId(); |
| } |
| catch (Exception e) { // NOSONAR |
| e.printStackTrace(); // NOSONAR |
| } |
| return 1; |
| } |
| |
| public final String getLdapContextFactoryUrl() { |
| initialize(); |
| try { |
| LdapConfiguration configuration = (LdapConfiguration) getShiroRealmConfiguration(SHIRO_LDAP_REALM); |
| if(configuration != null) { |
| return configuration.getUrl(); |
| } |
| } |
| catch (Exception e) { // NOSONAR |
| e.printStackTrace(); // NOSONAR |
| } |
| return "ldap://<ldapserver>:389"; |
| } |
| |
| public final String getLdapUserDnTemplate() { |
| initialize(); |
| try { |
| LdapConfiguration configuration = (LdapConfiguration) getShiroRealmConfiguration(SHIRO_LDAP_REALM); |
| if(configuration != null) { |
| return configuration.getTemplate(); |
| } |
| } |
| catch (Exception e) { // NOSONAR |
| e.printStackTrace(); // NOSONAR |
| } |
| return "cn={0},ou=users,dc=<organisation>,dc=<countrycode>"; |
| } |
| |
| @Override |
| public final String getAdminEmail() { |
| initialize(); |
| return adminEmail; |
| } |
| |
| @Override |
| public final String getAdminEmailUsername() { |
| initialize(); |
| return adminEmailUsername; |
| } |
| |
| @Override |
| public final String getAdminEmailPassword() { |
| initialize(); |
| return adminEmailPassword; |
| } |
| |
| /** |
| * @return maximum failed login attempts |
| */ |
| public final int getMaxLoginAttempts() { |
| initialize(); |
| return maxLoginAttempts; |
| } |
| |
| public final String getProtocolDatasource() { |
| initialize(); |
| return protocolDatasource; |
| } |
| |
| public final String getProtocolUnit() { |
| initialize(); |
| return protocolUnit; |
| } |
| |
| public final boolean getIdentifyByUsername() { |
| initialize(); |
| return identifyByUsername; |
| } |
| |
| /** |
| * @return the corresponding INI string for all authentication realms needed |
| * for Shiro |
| */ |
| public final String getShiroConfiguration(String staticRealmClassName) { |
| initialize(); |
| String mainSection = "[main]" + IShiroConfiguration.INI_NEWLINE; |
| String realms = ""; |
| if (!shiros.containsKey(ProductConfiguration.SHIRO_STATIC_REALM)) { |
| shiros.put(ProductConfiguration.SHIRO_STATIC_REALM, new StaticConfiguration(staticRealmClassName, 1)); |
| } |
| for (String name : shiros.keySet()) { |
| mainSection += shiros.get(name).getShiroConfiguration(name); |
| if (!realms.isEmpty()) { |
| realms += ","; |
| } |
| realms += "$" + name; |
| } |
| mainSection += "securityManager.realms = " + realms + IShiroConfiguration.INI_NEWLINE; |
| return mainSection; |
| } |
| |
| |
| public String getPreferencesFile() { |
| if (getProductPreferences() instanceof InstancePreferences) { |
| InstancePreferences instance = (InstancePreferences)getProductPreferences(); |
| Class<?> instanceClass = instance.getClass(); |
| try { |
| Method getLocation = instanceClass.getDeclaredMethod("getLocation"); |
| getLocation.setAccessible(true); |
| IPath location = (IPath) getLocation.invoke(instance); |
| return location.toOSString(); |
| } |
| catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NullPointerException e) { |
| e.printStackTrace(); |
| } |
| } |
| return getLocation(); |
| } |
| |
| public String getLocation() { |
| IPath path = scopeContext.getLocation(); |
| if (path == null) { |
| path = ConfigurationScope.INSTANCE.getLocation(); |
| } |
| if (path == null) { |
| return null; |
| } |
| else { |
| return path.toOSString(); |
| } |
| } |
| |
| public Map<String, Locale> getLanguages() { |
| initialize(); |
| return languages; |
| } |
| |
| public boolean isLanguagesAutotranslate() { |
| initialize(); |
| return languagesAutotranslate; |
| } |
| |
| public boolean willLanguagesAutocreate() { |
| initialize(); |
| return languagesAutocreate; |
| } |
| |
| public boolean isUomoMetricUnit() { |
| initialize(); |
| return uomoMetricUnit; |
| } |
| |
| public boolean showLanguageSelectInRespectiveLocale() { |
| initialize(); |
| return showLanguageSelectInRespectiveLocale; |
| } |
| |
| /** |
| * @return show theme tool control if true |
| */ |
| public final boolean hasDemoToolsTheme() { |
| initialize(); |
| return demoToolsTheme; |
| } |
| |
| /** |
| * @return show langauge tool control if true |
| */ |
| public final boolean hasDemoToolsLanguage() { |
| initialize(); |
| return demoToolsLanguage; |
| } |
| |
| /** |
| * @return show print service tool control if true |
| */ |
| public final boolean hasToolsPrintService() { |
| initialize(); |
| return demoToolsPrintService; |
| } |
| |
| /** |
| * @return use absolute location for project wizard if true |
| */ |
| public final boolean projectWizardUsesAbsoluteLocation() { |
| initialize(); |
| return projectWizardAbsoluteLocation; |
| } |
| |
| /* ========================= setters =========================== */ |
| |
| public void setEuroForeignExchangeReferenceRatesURLDaily( |
| String euroForeignExchangeReferenceRatesURLDaily) { |
| this.euroForeignExchangeReferenceRatesURLDaily = put(EURO_X_REF_URL_NODE, EURO_X_REF_URL_DAILY, |
| euroForeignExchangeReferenceRatesURLDaily); |
| } |
| |
| public void setEuroForeignExchangeReferenceRatesURLPrevious( |
| String euroForeignExchangeReferenceRatesURLPrevious) { |
| this.euroForeignExchangeReferenceRatesURLPrevious = put(EURO_X_REF_URL_NODE, EURO_X_REF_URL_PREVIOUS, |
| euroForeignExchangeReferenceRatesURLPrevious); |
| } |
| |
| public void setAuthenticationOrganizationId(String value) { |
| authenticationOrganizationId = put(AUTHENTICATION_NODE, AUTHENTICATION_ORGANIZATION_ID, value); |
| } |
| |
| public void setAuthRESTfulApiPort(int authRESTfulApiPort) { |
| this.authRESTfulApiPort = put(AUTHENTICATION_NODE, AUTH_RESTFUL_PORT, authRESTfulApiPort); |
| } |
| |
| public void setAutoLogin(boolean autoLogin) { |
| this.autoLogin = put(AUTHENTICATION_NODE, AUTHENTICATION_AUTOLOGIN, autoLogin); |
| } |
| |
| public void setEncryptPasswords(boolean encryptPasswords) { |
| this.encryptPasswords = put(AUTHENTICATION_NODE, AUTHENTICATION_ENCRYPT_PASSWORDS, encryptPasswords); |
| } |
| |
| public void setNoRememberMe(boolean noRememberMe) { |
| this.noRememberMe = put(AUTHENTICATION_NODE, AUTHENTICATION_HIDE_REMEMBER_ME, noRememberMe); |
| } |
| |
| public void setAdminEmail(String adminEmail) { |
| this.adminEmail = put(AUTHENTICATION_NODE, AUTHENTICATION_ADMIN_EMAIL_ACCOUNT, adminEmail); |
| } |
| |
| public void setAdminEmailUsername(String value) { |
| this.adminEmailUsername = put(AUTHENTICATION_NODE, AUTHENTICATION_ADMIN_EMAIL_USERNAME, value); |
| } |
| |
| /** |
| * <b>Please be aware, that the password is stored as <u>plain-text</u> right now!</b> |
| * @param value the new administrator email password used to authenticate against the email server |
| */ |
| public void setAdminEmailPassword(String value) { |
| this.adminEmailPassword = put(AUTHENTICATION_NODE, AUTHENTICATION_ADMIN_EMAIL_PASSWORD, value); |
| } |
| |
| public void setMaxLoginAttempts(int maxLoginAttempts) { |
| this.maxLoginAttempts = put(SHIRO_NODE, SHIRO_MAX_LOGIN_ATTEMPTS, maxLoginAttempts); |
| } |
| |
| public void setDtoRealmPortalId(int dtoRealmPortalId) { |
| put(SHIRO_NODE, SHIRO_DTO_REALM_CLASS, DTO_PORTAL_ID, dtoRealmPortalId); |
| } |
| |
| public void setLdapRealmPortalId(int ldapRealmPortalId) { |
| put(SHIRO_NODE, SHIRO_LDAP_REALM_CLASS, LDAP_PORTAL_ID, ldapRealmPortalId); |
| } |
| |
| public void setLdapContextFactoryUrl(String url) { |
| put(SHIRO_NODE, SHIRO_LDAP_REALM_CLASS, LDAP_URL, url); |
| } |
| |
| public void setLdapUserDnTemplate(String template) { |
| put(SHIRO_NODE, SHIRO_LDAP_REALM_CLASS, LDAP_USERDNTEMPLATE, template); |
| } |
| |
| public void setProtocolDatasource(String datasource) { |
| this.protocolDatasource = put(SHIRO_NODE, SHIRO_PROTOCOL_DATASOURCE, datasource); |
| } |
| |
| public void setProtocolUnit(String protocolUnit) { |
| this.protocolUnit = put(SHIRO_NODE, SHIRO_PROTOCOL_UNIT, protocolUnit); |
| } |
| |
| public void setIdentifyByUsername(boolean identifyByUsername) { |
| this.identifyByUsername = put(SHIRO_NODE, SHIRO_IDENTIFY_BY_USERNAME, identifyByUsername); |
| } |
| |
| public void setActiveMqBrokerServerName( |
| String activeMqBrokerServerName) { |
| this.activeMqBrokerServerName = put(ACTIVEMQBROKER_NODE, ACTIVEMQBROKER_SERVER, |
| activeMqBrokerServerName); |
| } |
| |
| public void setActiveMqBrokerServerPort(int activeMqBrokerServerPort) { |
| if (activeMqBrokerServerPort < 1) { |
| activeMqBrokerServerPort = defaultPrefs.getActiveMqBrokerServerPort(); |
| } |
| this.activeMqBrokerServerPort = put(ACTIVEMQBROKER_NODE, ACTIVEMQBROKER_PORT, |
| activeMqBrokerServerPort); |
| } |
| |
| public void setHybridRefresherMilliSecsActive( |
| int hybridRefresherMilliSecsActive) { |
| this.hybridRefresherMilliSecsActive = put(HYBRID_NODE, HYBRID_REFRESHER_MILLISECS_ACTIVE, |
| hybridRefresherMilliSecsActive); |
| } |
| |
| public void setHybridRefresherMilliSecsInactive( |
| int hybridRefresherMilliSecsInactive) { |
| this.hybridRefresherMilliSecsInactive = put(HYBRID_NODE, HYBRID_REFRESHER_MILLISECS_INACTIVE, |
| hybridRefresherMilliSecsInactive); |
| } |
| |
| public void setRealms(Map<String, IShiroConfiguration> configs) { |
| this.shiros = configs; |
| Preferences realms = getNode(SHIRO_NODE); |
| if (realms != null) { |
| for (String name : shiros.keySet()) { |
| Preferences realm = realms.node(name); |
| if (configs.get(name) instanceof DtoConfiguration) { |
| } |
| else if (configs.get(name) instanceof LdapConfiguration) { |
| put(realm, LDAP_PORTAL_ID, ((LdapConfiguration) shiros.get(name)).getPortalId()); |
| put(realm, LDAP_URL, ((LdapConfiguration) shiros.get(name)).getUrl()); |
| put(realm, LDAP_USERDNTEMPLATE, ((LdapConfiguration) shiros.get(name)).getTemplate()); |
| } |
| } |
| try { |
| realms.flush(); |
| } |
| catch (BackingStoreException e) { // NOSONAR |
| LOGGER.error(e.getLocalizedMessage()); |
| } |
| } |
| } |
| |
| public void setDataSources(Map<String, DataSourceConfiguration> dataSources) { |
| forceReloadConfiguration(); |
| this.dataSources = dataSources; |
| Preferences datasourceNode = getNode(DATASOURCE_NODE); |
| clear(datasourceNode); |
| if (datasourceNode != null) { |
| for (String dataSourceName : dataSources.keySet()) { |
| Preferences dataSource = datasourceNode.node(dataSourceName); |
| DataSourceConfiguration dsc = dataSources.get(dataSourceName); |
| put(dataSource, DATASOURCE_ENUM_ITEM, dsc.getDatabaseVendor().name()); |
| put(dataSource, DATASOURCE_DRIVER_VENDOR, dsc.getDriverVendor()); |
| put(dataSource, DATASOURCE_DRIVER_TYPE, dsc.getDriverType()); |
| put(dataSource, DATASOURCE_DRIVER_CLASS, dsc.getDriverClass()); |
| put(dataSource, DATASOURCE_SERVER_NAME, dsc.getServerName()); |
| put(dataSource, DATASOURCE_SERVER_PORT, dsc.getServerPort()); |
| put(dataSource, DATASOURCE_DATABASE_NAME, dsc.getDatabaseName()); |
| put(dataSource, DATASOURCE_DATABASE_USER, dsc.getDatabaseUser()); |
| put(dataSource, DATASOURCE_DATABASE_PASS, dsc.getDatabasePass()); |
| } |
| try { |
| datasourceNode.flush(); |
| } |
| catch (BackingStoreException e) { // NOSONAR |
| LOGGER.error(e.getLocalizedMessage()); |
| } |
| } |
| } |
| |
| public void setPersistenceUnits(Map<String, PersistenceUnitConfiguration> persistenceUnits) { |
| forceReloadConfiguration(); |
| Preferences root = getProductPreferences(); |
| Preferences pus = getProductPreferencesNode(PERSISTENCE_NODE); |
| clear(pus); |
| for (PersistenceUnitConfiguration persistenceUnit : persistenceUnits.values()) { |
| try { |
| initializeIfNotExists(true, root, pus, |
| persistenceUnit.getName(), |
| persistenceUnit.getJndiName(), |
| persistenceUnit.getDeployOnStartup(), |
| persistenceUnit.getQueryCache(), |
| persistenceUnit.getBatchWriting(), |
| persistenceUnit.getBatchWritingSize(), |
| persistenceUnit.getCacheStatements(), |
| persistenceUnit.getCacheStatementsSize(), |
| persistenceUnit.getLoggingLevel(), |
| persistenceUnit.getDdlGeneration(), |
| persistenceUnit.getPersistenceXMLPath()); |
| } |
| catch (Exception e) { // NOSONAR |
| LOGGER.error(e.getLocalizedMessage()); |
| } |
| } |
| } |
| |
| public void setLanguages(Collection<Locale> languages) { |
| try { |
| this.languages = new TreeMap<>(); |
| int lSize = languages.size(); |
| Preferences languagesNode = getNode(LANGUAGES_NODE); |
| clear(languagesNode); |
| if (languagesNode != null) { |
| int index = 0; |
| for (Locale locale : languages) { |
| this.languages.put(locale.toString(), locale); |
| index++; |
| Preferences language = languagesNode.node(Integer.toString(index)); |
| put(language, LANGUAGES_LANGUAGE, locale.getLanguage()); |
| if(locale.getCountry().length() > 0) { |
| put(language, LANGUAGES_COUNTRY, locale.getCountry()); |
| } else { |
| put(language, LANGUAGES_COUNTRY, ""); |
| } |
| if(locale.getVariant().length() > 0) { |
| put(language, LANGUAGES_VARIANT, locale.getVariant()); |
| } else { |
| put(language, LANGUAGES_VARIANT, ""); |
| } |
| } |
| languagesNode.flush(); |
| } |
| put((String)null, LANGUAGES_SUPPORTED, lSize); |
| } |
| catch (Exception e) { // NOSONAR |
| LOGGER.error(e.getLocalizedMessage()); |
| } |
| } |
| |
| public void setLanguages(Map<String, Locale> languages) { |
| setLanguages(languages.values()); |
| } |
| |
| public void setLanguagesAutotranslate(boolean languagesAutotranslate) { |
| this.languagesAutotranslate = put((String)null, LANGUAGES_AUTOTRANSLATE, languagesAutotranslate); |
| } |
| |
| public void setLanguagesAutocreate(boolean languagesAutocreate) { |
| this.languagesAutocreate = put((String)null, LANGUAGES_AUTOCREATE, languagesAutocreate); |
| } |
| |
| public void setShowLanguageSelectInRespectiveLocale( |
| boolean showLanguageSelectInRespectiveLocale) { |
| this.showLanguageSelectInRespectiveLocale = put((String)null, LANGUAGES_SHOW_SELECT_IN_RESPECTIVE_LOCALE, |
| showLanguageSelectInRespectiveLocale); |
| } |
| |
| public String getBusinessBundleClassNameReadOnly() { |
| initialize(); |
| return businessBundleClassNameReadOnly; |
| } |
| |
| public String getBpmServerIp() { |
| initialize(); |
| return bpmServerIp; |
| } |
| |
| public int getBpmServerPort() { |
| initialize(); |
| return bpmServerPort; |
| } |
| |
| public int getBpmResponseTimeout() { |
| initialize(); |
| return bpmResponseTimeout; |
| } |
| |
| public void setBpmServerIp(String bpmServerIp) { |
| this.bpmServerIp = put(BPM_NODE, BPM_SERVER_IP, bpmServerIp); |
| } |
| |
| public void setBpmServerPort(int bpmServerPort) { |
| if (bpmServerPort < 1) { |
| bpmServerPort = defaultPrefs.getBpmServerPort(); |
| } |
| this.bpmServerPort = put(BPM_NODE, BPM_SERVER_PORT, bpmServerPort); |
| } |
| |
| public void setBpmResponseTimeout(int bpmResponseTimeout) { |
| this.bpmResponseTimeout = put(BPM_NODE, BPM_RESPONSE_TIMEOUT, bpmResponseTimeout); |
| } |
| |
| public void setDemoToolsTheme(boolean demoToolsTheme) { |
| this.demoToolsTheme = put(DEMO_NODE, DEMO_TOOLS_THEME, demoToolsTheme); |
| } |
| |
| public void setDemoToolsLanguage(boolean demoToolsLanguage) { |
| this.demoToolsLanguage = put(DEMO_NODE, DEMO_TOOLS_LANGUAGE, demoToolsLanguage); |
| } |
| |
| public void setToolsPrintService(boolean demoToolsPrintService) { |
| this.demoToolsPrintService = put(DEMO_NODE, DEMO_TOOLS_PRINTSERVICE, demoToolsPrintService); |
| } |
| |
| public void setProjectWizardUsingAbsoluteLocation(boolean projectWizardAbsoluteLocation) { |
| this.projectWizardAbsoluteLocation = put(PROJECT_WIZARD_NODE, PROJECT_WIZARD_ABSOLUTE_LOCATION, projectWizardAbsoluteLocation); |
| } |
| |
| private IEclipsePreferences applyCustomizedPreferenceDirectory(IEclipsePreferences preference) { |
| // if (project != null) { |
| // if (preference instanceof ProjectPreferences) { |
| // IResource prefsFile = getPrefsFile(project); |
| // if (prefsFile instanceof IFile) { |
| // try { |
| // Class<?> preferenceClass = preference.getClass(); |
| // Method getLoadLevel = preferenceClass.getDeclaredMethod("getLoadLevel"); |
| // getLoadLevel.setAccessible(true); |
| // ProjectPreferences loadLevelInstance = (ProjectPreferences) getLoadLevel.invoke(preference); |
| // Class<?>loadLevelClass = loadLevelInstance.getClass(); |
| // Field fileField = loadLevelClass.getDeclaredField("file"); |
| // fileField.setAccessible(true); |
| // IFile activeFile = (IFile) fileField.get(loadLevelInstance); |
| // if ((activeFile == null) || !activeFile.getFullPath().toOSString().equals(prefsFile.getFullPath().toOSString())) { |
| // fileField.set(loadLevelInstance, prefsFile); |
| // preference.sync(); |
| // forceReloadConfiguration(); |
| // } |
| // } |
| // catch (NoSuchFieldException x) { |
| // x.printStackTrace(); |
| // } |
| // catch (IllegalArgumentException x) { |
| // x.printStackTrace(); |
| // } |
| // catch (IllegalAccessException x) { |
| // x.printStackTrace(); |
| // } |
| // catch (BackingStoreException e) { |
| // e.printStackTrace(); |
| // } |
| // catch (NoSuchMethodException e) { |
| // e.printStackTrace(); |
| // } |
| // catch (SecurityException e) { |
| // e.printStackTrace(); |
| // } |
| // catch (InvocationTargetException e) { |
| // e.printStackTrace(); |
| // } |
| // } |
| // } |
| // } |
| return preference; |
| } |
| |
| protected IEclipsePreferences getProductPreferences() { |
| if (project != null) { |
| // IPreferencesService service = Platform.getPreferencesService(); |
| // Preferences root = service.getRootNode(); |
| // Preferences myInstanceNode = root.node(project.getName()).node(InstanceScope.SCOPE).node(PRODUCT_PREFERENCES); |
| // return (IEclipsePreferences) myInstanceNode; |
| //??? return applyCustomizedPreferenceDirectory((IEclipsePreferences) scopeContext.getNode(InstanceScope.SCOPE).node(PRODUCT_PREFERENCES)); |
| return applyCustomizedPreferenceDirectory((IEclipsePreferences) scopeContext.getNode(PRODUCT_PREFERENCES)); |
| } |
| else { |
| return scopeContext.getNode(PRODUCT_PREFERENCES); |
| } |
| } |
| |
| protected IEclipsePreferences getProductPreferencesNode(String nodeName) { |
| return applyCustomizedPreferenceDirectory((IEclipsePreferences) getProductPreferences().node(nodeName)); |
| } |
| |
| private Preferences getNode(String nodeName) { |
| if (nodeName == null) { |
| return getProductPreferences(); |
| } |
| else { |
| return getProductPreferencesNode(nodeName); |
| } |
| } |
| |
| private void clear(Preferences node) { |
| try { |
| for (String child : node.childrenNames()) { |
| clear(node.node(child)); |
| } |
| for (String key : node.keys()) { |
| node.put(key, ""); |
| } |
| node.clear(); |
| node.flush(); |
| } |
| catch (BackingStoreException e) { |
| LOGGER.error("clearing node "+node.absolutePath(), e); |
| } |
| } |
| |
| private String put(Preferences node, String key, String value) { |
| if ((node != null) && (key != null) && !key.isEmpty()) { |
| if (!value.equals(node.get(key, ""))) { |
| try { |
| forceReloadConfiguration(); |
| node.put(key, value); |
| node.flush(); |
| registerWatch(); |
| } |
| catch (Exception e) { // NOSONAR |
| LOGGER.error("node " + node.name() + " and key " + key // NOSONAR |
| + " could not be set or flushed because " |
| + e.getLocalizedMessage()); |
| } |
| } |
| } |
| else { |
| LOGGER.error("node " + (node != null?node.name():"null") + " and key " + key |
| + " are no valid arguments"); |
| } |
| return value; |
| } |
| |
| private String put(String nodeName, String subNodeName, String key, String value) { |
| return put(getNode(nodeName).node(subNodeName), key, value); |
| } |
| |
| private String put(String nodeName, String key, String value) { |
| return put(getNode(nodeName), key, value); |
| } |
| |
| private Boolean put(String nodeName, String key, Boolean value) { |
| put(nodeName, key, value.toString()); |
| return value; |
| } |
| |
| private Integer put(Preferences node, String key, Integer value) { |
| put(node, key, value.toString()); |
| return value; |
| } |
| |
| private Integer put(String nodeName, String subNodeName, String key, Integer value) { |
| put(nodeName, subNodeName, key, value.toString()); |
| return value; |
| } |
| |
| private Integer put(String nodeName, String key, Integer value) { |
| put(nodeName, key, value.toString()); |
| return value; |
| } |
| |
| // private Double put(String nodeName, String key, Double value) { |
| // put(nodeName, key, value.toString()); |
| // return value; |
| // } |
| |
| /** |
| * sets the flag, that the configuration has to be reloaded. Deregisters all |
| * watchers/listeners on preference changes due to preference dialog and |
| * file modification |
| */ |
| public void forceReloadConfiguration() { |
| forceInitialize = true; |
| deregisterWatch(); |
| } |
| |
| /** |
| * Deregisters all watchers/listeners on preference changes due to |
| * preference dialog and file modification |
| */ |
| protected void deregisterWatch() { |
| if (preferenceChangedListener != null) { |
| try { |
| getProductPreferences().accept(new IPreferenceNodeVisitor() { |
| @Override |
| public boolean visit(IEclipsePreferences node) |
| throws BackingStoreException { |
| node.removePreferenceChangeListener(preferenceChangedListener); |
| return true; |
| } |
| }); |
| } |
| catch (BackingStoreException e) { |
| LOGGER.info("deregistering file watch thread", e); |
| } |
| } |
| } |
| |
| /** |
| * Registers all watchers/listeners on preference changes due to preference |
| * dialog and file modification |
| */ |
| protected void registerWatch() { |
| if (preferenceChangedListener != null) { |
| try { |
| getProductPreferences().accept(new IPreferenceNodeVisitor() { |
| @Override |
| public boolean visit(IEclipsePreferences node) |
| throws BackingStoreException { |
| node.addPreferenceChangeListener(preferenceChangedListener); |
| return true; |
| } |
| }); |
| } |
| catch (BackingStoreException e) { |
| LOGGER.error("registering file watch thread", e); |
| } |
| } |
| } |
| |
| |
| /* ========================= mock data generator state =========================== */ |
| |
| /** |
| * @param generator class of the requested mock data generator |
| * @return either null, if no entry is set, or the timestamp as String |
| */ |
| public String isMockDataGeneratorDone(Object generator) { |
| return getMockDataGeneratorsDoneNode().get(mockDataGeneratorToKey(generator), ""); |
| } |
| |
| public void setMockDataGeneratorDone(Object generator) { |
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS"); |
| String timeStamp = dateFormat.format(new Date(System.currentTimeMillis())); |
| put(MOCK_DATA_GENERATORS_DONE, mockDataGeneratorToKey(generator), timeStamp); |
| } |
| |
| private String mockDataGeneratorToKey(Object generator) { |
| return generator.getClass().getCanonicalName(); |
| } |
| |
| private Preferences getMockDataGeneratorsDoneNode() { |
| return getProductPreferencesNode(MOCK_DATA_GENERATORS_DONE); |
| } |
| |
| |
| /* ========================= main initializer =========================== */ |
| |
| public String getInformation() { |
| return getName()+" @ "+scopeContext.getName()+" @ "+getLocation(); |
| } |
| |
| private void initialize() { // NOSONAR |
| Set<Exception> exceptions = new HashSet<>(); |
| // --- (re)load the configuration if something has changed or it has not |
| // been loaded by now --- |
| if (forceInitialize || (authRESTfulApiPort < 1)) { |
| LOGGER.trace(getInformation()+" # initialize"); |
| deregisterWatch(); |
| try { |
| initializeReadOnly(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeAuthentication(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeEmail(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeActiveMqBroker(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeHybridConnection(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeRealms(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeDataSources(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializePersistenceUnits(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeEuroXRefRates(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeJavaPOS(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeDatainterchange(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeSignal(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeLanguages(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeUomoUnits(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeBPM(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeDemo(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeMavenActivated(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| try { |
| initializeProjectWizard(); |
| } catch (Exception e) { |
| exceptions.add(e); |
| } |
| if (!exceptions.isEmpty()) { |
| Exception e = new ConfigurationException(exceptions); |
| LOGGER.error("exceptions caught while reading configuration", e); |
| System.exit(0); // NOSONAR |
| } |
| forceInitialize = false; |
| registerWatch(); |
| } |
| } |
| |
| |
| private void initializeMavenActivated() { |
| Preferences root = getProductPreferences(); |
| mavenActivated = root.getBoolean(MAVEN_ACTIVATED, defaultPrefs.isMavenActivated()); |
| } |
| |
| private void initializeLanguages() throws Exception { |
| Preferences root = getProductPreferences(); |
| int languagesSupported = root.getInt(LANGUAGES_SUPPORTED, 0); |
| if (languagesSupported < 1) { |
| setLanguages(defaultPrefs.getLanguages()); |
| } |
| Preferences languagesNode = getProductPreferencesNode(LANGUAGES_NODE); |
| // --- read all preferences --- |
| languagesAutotranslate = root.getBoolean(LANGUAGES_AUTOTRANSLATE, defaultPrefs.isLanguagesAutotranslate()); |
| languagesAutocreate = root.getBoolean(LANGUAGES_AUTOCREATE, defaultPrefs.willLanguagesAutocreate()); |
| showLanguageSelectInRespectiveLocale = root.getBoolean(LANGUAGES_SHOW_SELECT_IN_RESPECTIVE_LOCALE, defaultPrefs.showLanguageSelectInRespectiveLocale()); |
| languagesSupported = root.getInt(LANGUAGES_SUPPORTED, 0); |
| for (int i = 0; i < languagesSupported; i++) { |
| Preferences language = languagesNode.node(Integer.toString(i + 1)); |
| List<String> languageParts = new ArrayList<>(); |
| languageParts.add(language.get(LANGUAGES_LANGUAGE, "")); |
| if (language.get(LANGUAGES_VARIANT, "").length() > 0) { |
| languageParts.add(language.get(LANGUAGES_VARIANT, "")); |
| } |
| if (language.get(LANGUAGES_COUNTRY, "").length() > 0) { |
| languageParts.add(language.get(LANGUAGES_COUNTRY, "")); |
| } |
| Locale locale = null; |
| if (languageParts.size() == 1) { |
| locale = new Locale(languageParts.get(0)); |
| } else if (languageParts.size() == 2) { |
| locale = new Locale(languageParts.get(0), languageParts.get(1)); |
| } else if (languageParts.size() == 3) { |
| locale = new Locale(languageParts.get(0), languageParts.get(1), |
| languageParts.get(2)); |
| } |
| languages.put(StringUtils.join(languageParts, "_"), locale); |
| } |
| languages.put("default", null); |
| } |
| |
| |
| private void initializeUomoUnits() throws Exception { |
| Preferences uomounitsNode = getProductPreferencesNode(UOMOUNIT_NODE); |
| // --- read all preferences --- |
| uomoMetricUnit = uomounitsNode.getBoolean(UOMOUNIT_METRIC, defaultPrefs.isUomoMetricUnit()); |
| } |
| |
| private void initializeEuroXRefRates() throws Exception { |
| Preferences euroXRefURL = getProductPreferencesNode(EURO_X_REF_URL_NODE); |
| // --- read all preferences --- |
| euroForeignExchangeReferenceRatesURLDaily = euroXRefURL.get(EURO_X_REF_URL_DAILY, defaultPrefs.getEuroXRefRatesURLDaily()); |
| euroForeignExchangeReferenceRatesURLPrevious = euroXRefURL.get(EURO_X_REF_URL_PREVIOUS, defaultPrefs.getEuroXRefRatesURLPrevious()); |
| } |
| |
| private void initializeJavaPOS() throws Exception { |
| Preferences javaPos = getProductPreferencesNode(JAVA_POS_NODE); |
| // --- read all preferences --- |
| javaPosConfiguration = javaPos.get(JAVA_POS_CONFIGURATION, defaultPrefs.getJavaPosConfiguration()); |
| } |
| |
| private void initializeDatainterchange() throws Exception { |
| Preferences datainterchange = getProductPreferencesNode(DATAINTERCHANGE_NODE); |
| // --- read all preferences --- |
| datainterchangeConfiguration = datainterchange.get(DATAINTERCHANGE_CONFIGURATION, defaultPrefs.getDatainterchangeConfiguration()); |
| } |
| |
| private void initializeSignal() throws Exception { |
| Preferences signal = getProductPreferencesNode(SIGNAL_NODE); |
| // --- read all preferences --- |
| signalConfiguration = signal.get(SIGNAL_CONFIGURATION, defaultPrefs.getSignalConfiguration()); |
| } |
| |
| private void initializeReadOnly() throws Exception { |
| Preferences readOnly = getProductPreferences(); |
| businessBundleClassNameReadOnly = readOnly.get(BUSINESS_BUNDLE_CLASS_NAME, ""); |
| } |
| |
| private void initializeAuthentication() throws Exception { |
| Preferences authentication = getProductPreferencesNode(AUTHENTICATION_NODE); |
| authenticationOrganizationId = authentication.get(AUTHENTICATION_ORGANIZATION_ID, defaultPrefs.getAuthenticationOrganizationId()); |
| autoLogin = authentication.getBoolean(AUTHENTICATION_AUTOLOGIN, defaultPrefs.hasAutoLogin()); |
| noRememberMe = authentication.getBoolean(AUTHENTICATION_HIDE_REMEMBER_ME, defaultPrefs.hasNoRememberMe()); |
| // --- read all preferences --- |
| authRESTfulApiPort = authentication.getInt(AUTH_RESTFUL_PORT, defaultPrefs.getAuthRESTfulPort()); |
| } |
| |
| private void initializeActiveMqBroker() throws Exception { |
| Preferences activeMqBroker = getProductPreferencesNode(ACTIVEMQBROKER_NODE); |
| // --- read all preferences --- |
| activeMqBrokerServerName = activeMqBroker.get(ACTIVEMQBROKER_SERVER, defaultPrefs.getActiveMqBrokerServerName()); |
| activeMqBrokerServerPort = activeMqBroker.getInt(ACTIVEMQBROKER_PORT, 0); |
| if (activeMqBrokerServerPort < 1) { |
| activeMqBrokerServerPort = defaultPrefs.getActiveMqBrokerServerPort(); |
| } |
| } |
| |
| private void initializeHybridConnection() throws Exception { |
| Preferences hybridConnection = getProductPreferencesNode(HYBRID_NODE); |
| // --- read all preferences --- |
| hybridRefresherMilliSecsActive = hybridConnection.getInt(HYBRID_REFRESHER_MILLISECS_ACTIVE, defaultPrefs.getHybridRefresherMilliSecsActive()); |
| hybridRefresherMilliSecsInactive = hybridConnection.getInt(HYBRID_REFRESHER_MILLISECS_INACTIVE, defaultPrefs.getHybridRefresherMilliSecsInactive()); |
| } |
| |
| private void initializeRealms() throws Exception { |
| Preferences realms = getProductPreferencesNode(SHIRO_NODE); |
| maxLoginAttempts = realms.getInt(SHIRO_MAX_LOGIN_ATTEMPTS, defaultPrefs.getMaxLoginAttempts()); |
| protocolDatasource = realms.get(SHIRO_PROTOCOL_DATASOURCE, defaultPrefs.getProtocolDatasource()); |
| protocolUnit = realms.get(SHIRO_PROTOCOL_UNIT, defaultPrefs.getProtocolUnit()); |
| identifyByUsername = realms.getBoolean(SHIRO_IDENTIFY_BY_USERNAME, defaultPrefs.getIdentifyByUsername()); |
| |
| // --- generate reasonable default preferences for development product |
| if (realms.childrenNames().length == 0) { |
| Preferences dtoRealm = realms.node(SHIRO_DTO_REALM_CLASS); |
| dtoRealm.putInt(DTO_PORTAL_ID, defaultPrefs.getDtoRealmPortalId()); |
| |
| Preferences ldapRealm = realms.node(SHIRO_LDAP_REALM_CLASS); |
| ldapRealm.putInt(LDAP_PORTAL_ID, defaultPrefs.getLdapRealmPortalId()); |
| ldapRealm.put(LDAP_URL, defaultPrefs.getLdapContextFactoryUrl()); |
| ldapRealm.put(LDAP_USERDNTEMPLATE, defaultPrefs.getLdapUserDnTemplate()); |
| realms.flush(); |
| } |
| // --- read all preferences --- |
| for (String iname : realms.childrenNames()) { |
| Preferences realm = realms.node(iname); |
| if (iname.contains("DTO")) { |
| int portalId = realm.getInt(DTO_PORTAL_ID, defaultPrefs.getDtoRealmPortalId()); |
| DtoConfiguration configuration = new DtoConfiguration(iname, portalId); |
| shiros.put(SHIRO_DTO_REALM, configuration); |
| } |
| else if (iname.contains("LDAP")) { |
| int portalId = realm.getInt(LDAP_PORTAL_ID, defaultPrefs.getLdapRealmPortalId()); |
| String userDnTemplate = realm.get(LDAP_USERDNTEMPLATE, defaultPrefs.getLdapUserDnTemplate()); |
| String contextFactoryUrl = realm.get(LDAP_URL, defaultPrefs.getLdapContextFactoryUrl()); |
| if ((portalId > 0) && (portalId < 1000) // NOSONAR |
| && !userDnTemplate.isEmpty() |
| && !contextFactoryUrl.isEmpty() |
| && !contextFactoryUrl.contains("<") |
| && !contextFactoryUrl.contains(">")) { |
| LdapConfiguration configuration = new LdapConfiguration( |
| iname, portalId, contextFactoryUrl, userDnTemplate); |
| shiros.put(SHIRO_LDAP_REALM, configuration); |
| } |
| } |
| } |
| } |
| |
| public IShiroConfiguration getShiroRealmConfiguration(String key) { |
| return shiros.get(key); |
| } |
| |
| private void initializeIfNotExists(Preferences root, Preferences dataSourcesPrefs, // NOSONAR |
| String dataSource, String dataSourceConsumer, EnumDatabaseVendor vendor, |
| String serverName, int serverPort, |
| String database, String username, String password) throws Exception { |
| if (!dataSourcesPrefs.nodeExists(dataSource)) { |
| Preferences dataSourcePref = dataSourcesPrefs.node(dataSource); |
| if ((dataSourceConsumer != null) && !dataSourceConsumer.isEmpty()) { |
| root.put(dataSourceConsumer, dataSource); |
| } |
| put(dataSourcePref, DATASOURCE_ENUM_ITEM, vendor.name()); |
| put(dataSourcePref, DATASOURCE_DRIVER_VENDOR, vendor.getDriverVendor()); |
| put(dataSourcePref, DATASOURCE_DRIVER_TYPE, vendor.getDriverType()); |
| put(dataSourcePref, DATASOURCE_DRIVER_CLASS, vendor.getDriverClass()); |
| if ((serverName != null) && !serverName.isEmpty()) { |
| put(dataSourcePref, DATASOURCE_SERVER_NAME, serverName); |
| } |
| if (serverPort >= 0) { |
| put(dataSourcePref, DATASOURCE_SERVER_PORT, serverPort); |
| } |
| put(dataSourcePref, DATASOURCE_DATABASE_NAME, database); |
| put(dataSourcePref, DATASOURCE_DATABASE_USER, username); |
| put(dataSourcePref, DATASOURCE_DATABASE_PASS, password); |
| dataSourcesPrefs.flush(); |
| root.flush(); |
| } |
| } |
| |
| private void initializeDataSources() throws Exception { |
| Preferences root = getProductPreferences(); |
| Preferences dataSourcesPrefs = getProductPreferencesNode(DATASOURCE_NODE); |
| |
| /* === datasource using a Oracle database === */ |
| initializeIfNotExists (root, dataSourcesPrefs, ProductConfigurationDefaultPrefs.ORACLE, ProductConfigurationDefaultPrefs.ORACLE, |
| EnumDatabaseVendor.ORACLE, ProductConfigurationDefaultPrefs.IP_OR_HOST, 1521, ProductConfigurationDefaultPrefs.DATABASE_HINT, ProductConfigurationDefaultPrefs.USERNAME_HINT, ProductConfigurationDefaultPrefs.PASSWORD_HINT); |
| /* === datasource using a MySQL database === */ |
| initializeIfNotExists (root, dataSourcesPrefs, ProductConfigurationDefaultPrefs.MYSQL, null, |
| EnumDatabaseVendor.MYSQL, "<ip-or-host>", 3306, ProductConfigurationDefaultPrefs.DATABASE_HINT, ProductConfigurationDefaultPrefs.USERNAME_HINT, ""); |
| /* === datasource using a H2 in-Memory database === */ |
| initializeIfNotExists (root, dataSourcesPrefs, DEFAULT_H2MEMORY_DATASOURCE, null, |
| EnumDatabaseVendor.H2_IN_MEMORY, null, -1, ProductConfigurationDefaultPrefs.H2MEMORY, ProductConfigurationDefaultPrefs.H2MEMORY, ProductConfigurationDefaultPrefs.H2MEMORY); // NOSONAR |
| /* === datasource using a H2 local-file database === */ |
| initializeIfNotExists (root, dataSourcesPrefs, DEFAULT_H2LOCALFILE_DATASOURCE, null, |
| EnumDatabaseVendor.H2_LOCAL_FILE, null, -1, ProductConfigurationDefaultPrefs.H2LOCALFILE, ProductConfigurationDefaultPrefs.H2LOCALFILE, ProductConfigurationDefaultPrefs.H2LOCALFILE); |
| /* === datasource using a Derby in-Memory database === */ |
| initializeIfNotExists (root, dataSourcesPrefs, DEFAULT_DERBYMEMORY_DATASOURCE, null, |
| EnumDatabaseVendor.DERBY_IN_MEMORY, null, -1, ProductConfigurationDefaultPrefs.DERBYMEMORY, ProductConfigurationDefaultPrefs.DERBYMEMORY, ProductConfigurationDefaultPrefs.DERBYMEMORY); |
| /* === datasource using a Derby local-file database === */ |
| initializeIfNotExists (root, dataSourcesPrefs, DEFAULT_DERBYLOCALFILE_DATASOURCE, null, |
| EnumDatabaseVendor.DERBY_LOCAL_FILE, null, -1, ProductConfigurationDefaultPrefs.DERBYLOCALFILE, ProductConfigurationDefaultPrefs.DERBYLOCALFILE, ProductConfigurationDefaultPrefs.DERBYLOCALFILE); |
| /* === datasource using a Derby database === */ |
| initializeIfNotExists (root, dataSourcesPrefs, DEFAULT_DERBYSERVER_DATASOURCE, null, |
| EnumDatabaseVendor.DERBY_CLIENT, ProductConfigurationDefaultPrefs.IP_OR_HOST, 1527, ProductConfigurationDefaultPrefs.DATABASE_HINT, ProductConfigurationDefaultPrefs.USERNAME_HINT, ProductConfigurationDefaultPrefs.PASSWORD_HINT); |
| for (String dataSourceName : dataSourcesPrefs.childrenNames()) { |
| Preferences dataSource = dataSourcesPrefs.node(dataSourceName); |
| String vendorName = dataSource.get(DATASOURCE_ENUM_ITEM, ""); |
| String driverVendor = dataSource.get(DATASOURCE_DRIVER_VENDOR, ""); |
| String databaseName = dataSource.get(DATASOURCE_DATABASE_NAME, ""); |
| EnumDatabaseVendor vendor = EnumDatabaseVendor.byName(vendorName, driverVendor, databaseName); |
| String driverType = dataSource.get(DATASOURCE_DRIVER_TYPE, ""); |
| String driverClass = dataSource.get(DATASOURCE_DRIVER_CLASS, ""); |
| String serverName = dataSource.get(DATASOURCE_SERVER_NAME, ""); |
| int serverPort = dataSource.getInt(DATASOURCE_SERVER_PORT, 0); |
| String databaseUser = dataSource.get(DATASOURCE_DATABASE_USER, ""); |
| String databasePass = dataSource.get(DATASOURCE_DATABASE_PASS, ""); |
| String jdbcUrlFormat = dataSource.get(DATASOURCE_JDBC_URL_FORMAT, null); |
| if (!driverClass.isEmpty() && |
| !databaseName.isEmpty() && !databaseUser.isEmpty()) { |
| DataSourceConfiguration configuration = new DataSourceConfiguration( |
| dataSourceName, |
| vendor, |
| driverVendor, driverType, driverClass, serverName, |
| serverPort, databaseName, databaseUser, databasePass, |
| jdbcUrlFormat); |
| dataSources.put(dataSourceName, configuration); |
| } |
| } |
| } |
| |
| private void initializeEmail() throws Exception { |
| Preferences authentication = getProductPreferencesNode(AUTHENTICATION_NODE); |
| adminEmail = authentication.get(AUTHENTICATION_ADMIN_EMAIL_ACCOUNT, defaultPrefs.getAdminEmail()); |
| adminEmailUsername = authentication.get(AUTHENTICATION_ADMIN_EMAIL_USERNAME, defaultPrefs.getAdminEmailUsername()); |
| adminEmailPassword = authentication.get(AUTHENTICATION_ADMIN_EMAIL_PASSWORD, defaultPrefs.getAdminEmailPassword()); |
| Preferences email = getProductPreferencesNode(EMAIL_NODE); |
| emailServerIp = email.get(EMAIL_SERVER_IP, defaultPrefs.getEmailServerIp()); |
| emailSmtpPort = email.getInt(EMAIL_SMTP_PORT, 0); |
| if (emailSmtpPort < 1) { |
| emailSmtpPort = defaultPrefs.getEmailSmtpPort(); |
| } |
| emailUseSslOnConnect = email.getBoolean(EMAIL_USE_SSL_ON_CONNECT, defaultPrefs.isEmailUseSslOnConnect()); |
| } |
| |
| private void initializeBPM() throws Exception { |
| Preferences bpm = getProductPreferencesNode(BPM_NODE); |
| bpmServerIp = bpm.get(BPM_SERVER_IP, defaultPrefs.getBpmServerIp()); |
| bpmServerPort = bpm.getInt(BPM_SERVER_PORT, 0); |
| if (bpmServerPort < 1) { |
| bpmServerPort = defaultPrefs.getBpmServerPort(); |
| } |
| bpmResponseTimeout = bpm.getInt(BPM_RESPONSE_TIMEOUT, defaultPrefs.getBpmResponseTimeout()); |
| bpmHibernateShowSql = bpm.getBoolean(BPM_HIBERNATE_SHOW_SQL, defaultPrefs.isBpmEngineHibernateShowSql()); |
| bpmHibernateFormatSql = bpm.getBoolean(BPM_HIBERNATE_FORMAT_SQL, defaultPrefs.isBpmEngineHibernateFormatSql()); |
| bpmHibernateMaxFetchDepth = bpm.getInt(BPM_HIBERNATE_MAX_FETCH_DEPTH, defaultPrefs.getBpmEngineHibernateMaxFetchDepth()); |
| bpmHibernateSchemaName = bpm.get(BPM_HIBERNATE_SCHEMA_NAME, defaultPrefs.getBpmEngineHibernateSchemaName(defaultPrefs.getBpmEnginePersistenceUnit())); |
| } |
| |
| private void initializeIfNotExists(boolean force, Preferences root, Preferences pus, String persistenceUnit, |
| String dataSource, boolean deployOnStartup, boolean queryCache, |
| String batchWriting, int batchWritingSize, boolean cacheStatements, int cacheStatementsSize, |
| String loggingLevel, String dllGeneration, String xmlPath) throws Exception { // NOSONAR |
| if (force || !pus.nodeExists(persistenceUnit)) { |
| DataSourceConfiguration dataSourceConfiguration = getDataSource(dataSource); |
| Preferences pu = pus.node(persistenceUnit); |
| pu.put (PERSISTENCE_DATASOURCE, dataSource); |
| pu.putBoolean (PERSISTENCE_DEPLOYONSTARTUP, deployOnStartup); |
| pu.putBoolean (PERSISTENCE_QUERYCACHE, queryCache); |
| if (batchWriting == null) { |
| batchWriting = dataSourceConfiguration.getDefaultBatchWriting(); |
| } |
| pu.put (PERSISTENCE_BATCHWRITING, batchWriting); |
| pu.putInt (PERSISTENCE_BATCHWRITINGSIZE, batchWritingSize); |
| pu.putBoolean (PERSISTENCE_CACHESTATEMENTS, cacheStatements); |
| pu.putInt (PERSISTENCE_CACHESTATEMENTSSIZE, cacheStatementsSize); |
| pu.put (PERSISTENCE_LOGGINGLEVEL, loggingLevel); |
| pu.put (PERSISTENCE_DDLGENERATION, dllGeneration); |
| pu.put (PERSISTENCE_PERSISTENCEXMLPATH, xmlPath); |
| pus.flush(); |
| root.flush(); |
| } |
| } |
| |
| private void initializePersistenceUnits() throws Exception { |
| Preferences root = getProductPreferences(); |
| Preferences pus = getProductPreferencesNode(PERSISTENCE_NODE); |
| |
| // --- generate reasonable default preferences for development product |
| initializeIfNotExists (false, root, pus, PERSISTENCE_UNIT_AUTHENTICATION, |
| dataSourceForAuthentication, true, true, |
| null, 1000, |
| true, 200, |
| "off", "create-or-extend-tables", // NOSONAR |
| PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT); |
| initializeIfNotExists (false, root, pus, PERSISTENCE_UNIT_BLOB, |
| dataSourceForBLOB, true, true, |
| null, 1000, |
| true, 200, |
| "off", "create-or-extend-tables", |
| PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT); |
| initializeIfNotExists (false, root, pus, PERSISTENCE_UNIT_BPM, |
| dataSourceForBPM, true, true, |
| null, 1000, |
| true, 200, |
| "off", "none", |
| PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT); |
| initializeIfNotExists (false, root, pus, PERSISTENCE_UNIT_BUSINESSDATA, |
| dataSourceForBusinessData, true, true, |
| null, 1000, |
| true, 200, |
| "off", "create-or-extend-tables", |
| PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT); |
| |
| // --- read all preferences --- |
| for (String persistenceUnitName : pus.childrenNames()) { |
| Preferences pu = pus.node(persistenceUnitName); |
| String jndiName = pu.get(PERSISTENCE_DATASOURCE, ""); |
| boolean deployOnStartup = pu.getBoolean(PERSISTENCE_DEPLOYONSTARTUP, PersistenceUnitConfiguration.DEPLOY_ON_STARTUP); |
| boolean queryCache = pu.getBoolean(PERSISTENCE_QUERYCACHE, PersistenceUnitConfiguration.QUERY_CACHE); |
| String batchWriting = pu.get(PERSISTENCE_BATCHWRITING, "JDBC"); |
| int batchWritingSize = pu.getInt(PERSISTENCE_BATCHWRITINGSIZE, PersistenceUnitConfiguration.BATCH_WRITING_SIZE); |
| boolean cacheStatements = pu.getBoolean(PERSISTENCE_CACHESTATEMENTS, PersistenceUnitConfiguration.CACHE_STATEMENTS); |
| int cacheStatementSize = pu.getInt(PERSISTENCE_CACHESTATEMENTSSIZE, PersistenceUnitConfiguration.CACHE_STATEMENTS_SIZE); |
| String loggingLevel = pu.get(PERSISTENCE_LOGGINGLEVEL, PersistenceUnitConfiguration.LOGGING_LEVEL); |
| String ddlGeneration = pu.get(PERSISTENCE_DDLGENERATION, DDL_GENERATION.UPDATE.eclipseLink()); |
| String persistenceXMLPath = pu.get(PERSISTENCE_PERSISTENCEXMLPATH, PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML_DEFAULT); |
| PersistenceUnitConfiguration configuration = new PersistenceUnitConfiguration( |
| persistenceUnitName, |
| jndiName, deployOnStartup, |
| queryCache, batchWriting, batchWritingSize, |
| cacheStatements, cacheStatementSize, loggingLevel, |
| ddlGeneration, persistenceXMLPath); |
| persistenceUnits.put(persistenceUnitName, configuration); |
| } |
| } |
| |
| private void initializeProjectWizard() throws Exception { |
| Preferences projectWizard = getProductPreferencesNode(PROJECT_WIZARD_NODE); |
| // --- read all preferences --- |
| projectWizardAbsoluteLocation = projectWizard.getBoolean(PROJECT_WIZARD_ABSOLUTE_LOCATION, defaultPrefs.projectWizardUsesAbsoluteLocation()); |
| } |
| |
| private void initializeDemo() throws Exception { |
| Preferences demo = getProductPreferencesNode(DEMO_NODE); |
| demoToolsTheme = demo.getBoolean(DEMO_TOOLS_THEME, defaultPrefs.hasDemoToolsTheme()); |
| demoToolsLanguage = demo.getBoolean(DEMO_TOOLS_LANGUAGE, defaultPrefs.hasDemoToolsLanguage()); |
| demoToolsPrintService = demo.getBoolean(DEMO_TOOLS_PRINTSERVICE, defaultPrefs.hasToolsPrintService()); |
| } |
| |
| public void setBpmEngineHibernateShowSql(boolean value) { |
| bpmHibernateShowSql = put(BPM_NODE, BPM_HIBERNATE_SHOW_SQL, value); |
| } |
| |
| public void setBpmEngineHibernateFormatSql(boolean value) { |
| bpmHibernateFormatSql = put(BPM_NODE, BPM_HIBERNATE_FORMAT_SQL, value); |
| } |
| |
| public void setBpmEngineHibernateMaxFetchDepth(int value) { |
| bpmHibernateMaxFetchDepth = put(BPM_NODE, BPM_HIBERNATE_MAX_FETCH_DEPTH, value); |
| } |
| |
| public void setBpmEngineHibernateSchemaName(String value) { |
| bpmHibernateSchemaName = put(BPM_NODE, BPM_HIBERNATE_SCHEMA_NAME, value); |
| } |
| |
| @Override |
| public boolean isBpmEngineHibernateShowSql() { |
| initialize(); |
| return bpmHibernateShowSql; |
| } |
| |
| @Override |
| public boolean isBpmEngineHibernateFormatSql() { |
| initialize(); |
| return bpmHibernateFormatSql; |
| } |
| |
| @Override |
| public int getBpmEngineHibernateMaxFetchDepth() { |
| initialize(); |
| return bpmHibernateMaxFetchDepth; |
| } |
| |
| @Override |
| public String getBpmEnginePersistenceUnit() { |
| return ProductConfigurationDefaultPrefs.BPM_ENGINE_PERSISTENCE_UNIT; |
| } |
| |
| @Override |
| public String getBpmEngineHibernateSchemaName(String persistenceUnit) { |
| initialize(); |
| EnumDatabaseVendor vendor = getDataSourceDatabaseVendor(getPersistenceUnitJndiName(persistenceUnit)); |
| if (vendor != null) { |
| return vendor.applySchemaNameSpecifications(bpmHibernateSchemaName); |
| } |
| return bpmHibernateSchemaName; |
| } |
| |
| @Override |
| public String getEmailServerIp() { |
| initialize(); |
| return emailServerIp; |
| } |
| |
| @Override |
| public int getEmailSmtpPort() { |
| initialize(); |
| return emailSmtpPort; |
| } |
| |
| @Override |
| public boolean isEmailUseSslOnConnect() { |
| initialize(); |
| return emailUseSslOnConnect; |
| } |
| |
| public void setEmailServerIp(String emailServerIp) { |
| this.emailServerIp = put(EMAIL_NODE, EMAIL_SERVER_IP, emailServerIp); |
| } |
| |
| public void setEmailSmtpPort(int emailSmtpPort) { |
| if (emailSmtpPort < 1) { |
| emailSmtpPort = defaultPrefs.getEmailSmtpPort(); |
| } |
| this.emailSmtpPort = put(EMAIL_NODE, EMAIL_SMTP_PORT, emailSmtpPort); |
| } |
| |
| public void setEmailUseSslOnConnect(boolean emailUseSslOnConnect) { |
| this.emailUseSslOnConnect = put(EMAIL_NODE, EMAIL_USE_SSL_ON_CONNECT, emailUseSslOnConnect); |
| } |
| |
| public void setJavaPosConfiguration(String value) { |
| this.javaPosConfiguration = put(JAVA_POS_NODE, JAVA_POS_CONFIGURATION, value); |
| } |
| |
| @Override |
| public String getJavaPosConfiguration() { |
| return javaPosConfiguration; |
| } |
| |
| public void setDatainterchangeConfiguration(String value) { |
| this.datainterchangeConfiguration = put(DATAINTERCHANGE_NODE, DATAINTERCHANGE_CONFIGURATION, value); |
| } |
| |
| @Override |
| public String getDatainterchangeConfiguration() { |
| return datainterchangeConfiguration; |
| } |
| |
| @Override |
| public String getSignalConfiguration() { |
| return signalConfiguration; |
| } |
| |
| public void setSignalConfiguration(String value) { |
| this.signalConfiguration = put(SIGNAL_NODE, SIGNAL_CONFIGURATION, value); |
| } |
| |
| @Override |
| public boolean isMavenActivated() { |
| initialize(); |
| return mavenActivated; |
| } |
| |
| @Override |
| public String getReportPrinter(String reportName) { |
| return getNode(REPORT_PRINTER_NODE).get(reportName, "NaN"); |
| } |
| |
| @Override |
| public Preferences getReportPrinterPrefs() { |
| return getNode(REPORT_PRINTER_NODE); |
| } |
| |
| public void setReportPrinter(String reportName, String printerName) { |
| put(REPORT_PRINTER_NODE, reportName, printerName); |
| } |
| |
| public void removeReportPrinter(String reportName){ |
| Preferences node = getNode(REPORT_PRINTER_NODE); |
| remove(node, reportName); |
| } |
| |
| private void remove(Preferences node, String key){ |
| if ((node != null) && (key != null) && !key.isEmpty()) { |
| try { |
| forceReloadConfiguration(); |
| node.remove(key); |
| node.flush(); |
| registerWatch(); |
| } |
| catch (Exception e) { // NOSONAR |
| LOGGER.error("node " + node.name() + " and key " + key // NOSONAR |
| + " could not be set or flushed because " |
| + e.getLocalizedMessage()); |
| } |
| } |
| else { |
| LOGGER.error("node " + (node != null?node.name():"null") + " and key " + key |
| + " are no valid arguments"); |
| } |
| } |
| |
| } |