/** * {@link PreferenceContext} setter for dependency injection. * * @param prefs the preference context * @see ome.services.util.BeanHelper#throwIfAlreadySet(Object, Object) */ public final void setPreferenceContext(PreferenceContext prefs) { getBeanHelper().throwIfAlreadySet(this.prefs, prefs); this.prefs = prefs; }
@PermitAll public Map<String, String> getClientConfigDefaults() { Map<String, String> rv = getConfigDefaults(); Map<String, String> copy = new HashMap<String, String>(); for (Map.Entry<String, String> e : rv.entrySet()) { if (e.getKey().startsWith("omero.client")) { copy.put(e.getKey(), e.getValue()); } } return copy; }
@PermitAll public Map<String, String> getClientConfigValues() { return getConfigValues("^omero\\.client\\."); }
/** * see {@link IConfig#setConfigValueIfEquals(String, String, String)} */ @RolesAllowed("user") @Transactional(readOnly = false) // see above public boolean setConfigValueIfEquals(String key, String value, String test) throws ApiUsageException, SecurityViolation { key = prefs.resolveAlias(key); lock.writeLock().lock(); try { String current = getInternalValue(key); if (test == null) { if (current != null) { return false; } } else { if (!test.equals(current)) { return false; } } setConfigValue(key, value); return true; } finally { lock.writeLock().unlock(); } }
/** * see {@link IConfig#getVersion()} */ @PermitAll // see above public String getVersion() { String version = getInternalValue("omero.version"); Pattern p = Pattern.compile(VERSION_REGEX); Matcher m = p.matcher(version); if (!m.matches()) { throw new InternalException("Bad version format:" + version); } return m.group(1); }
public String getInternalValue(String key) { key = prefs.resolveAlias(key); lock.readLock().lock(); try { String value = null; if (prefs.checkDatabase(key)) { value = fromDatabase(key); } if (value != null) { return value; } else { return prefs.getProperty(key); } } finally { lock.readLock().unlock(); } }
@PermitAll public Map<String, String> getConfigValues(String keyRegex) { if (keyRegex == null) { return Collections.emptyMap(); } Pattern p = Pattern.compile(keyRegex); Map<String, String> rv = new HashMap<String, String>(); Set<String> keys = prefs.getKeySet(); // Not resolving aliases since these come straight-from the prefs for (String key : keys) { if (p.matcher(key).find()) { if (prefs.canRead( currentDetails.getCurrentEventContext(), key)) { rv.put(key, getInternalValue(key)); } } } return rv; }
String current = fromDatabase(key); if (current != null && current.length() > 0) { int count = sql.updateConfiguration(key, value);
/** * {@link CurrentDetails} setter for dependency injection. * * @param currentDetails the details of the current thread's security context * @see ome.services.util.BeanHelper#throwIfAlreadySet(Object, Object) */ public final void setCurrentDetails(CurrentDetails currentDetails) { getBeanHelper().throwIfAlreadySet(this.currentDetails, currentDetails); this.currentDetails = currentDetails; }
/** * see {@link IConfig#getConfigValue(String)} */ @PermitAll // see above public String getConfigValue(String key) { if (key == null) { return ""; } key = prefs.resolveAlias(key); if (!prefs.canRead(currentDetails.getCurrentEventContext(), key)) { throw new SecurityViolation("Cannot read configuration: " + key); } return getInternalValue(key); }
/** * {@link SqlAction} setter for dependency injection. * * @param sql the SQL action instance * @see ome.services.util.BeanHelper#throwIfAlreadySet(Object, Object) */ /* * Developer notes: --------------- Because of the complicated lifecycle of * EJBs it is not possible to fully configure them with constructor * injection (which is safer). Instead, we have to provide public setters * for all properties which need to be injected. And since Java doesn't have * the concept of "friends" (yet), this opens up our classes for some weird * manipulations. Therefore we've made all bean setters "final" and added a * call to "throwIfAlreadySet" which will only allow previously null fields * to be set. */ public final void setSqlAction(SqlAction sql) { getBeanHelper().throwIfAlreadySet(this.sql, sql); this.sql = sql; }