mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 09:41:00 +00:00
First stubs to register PreferenceConverters on the UserStore
This commit is contained in:
1 parent
2b27ce2154
commit
37e47d5fdc
4 files changed
+65
No files matched your search
@@ -34,7 +34,9 @@ import com.sap.sse.common.TypeBasedServiceFinder;
|
|||||||
import com.sap.sse.common.Util;
|
import com.sap.sse.common.Util;
|
||||||
import com.sap.sse.osgi.CachedOsgiTypeBasedServiceFinderFactory;
|
import com.sap.sse.osgi.CachedOsgiTypeBasedServiceFinderFactory;
|
||||||
import com.sap.sse.replication.Replicable;
|
import com.sap.sse.replication.Replicable;
|
||||||
|
import com.sap.sse.security.UserStore;
|
||||||
import com.sap.sse.util.ClearStateTestSupport;
|
import com.sap.sse.util.ClearStateTestSupport;
|
||||||
|
import com.sap.sse.util.ServiceTrackerFactory;
|
||||||
|
|
||||||
public class Activator implements BundleActivator {
|
public class Activator implements BundleActivator {
|
||||||
|
|
||||||
@@ -108,6 +110,9 @@ public class Activator implements BundleActivator {
|
|||||||
// legacy type name; some DBs may still contain fixes marked with this old package name:
|
// legacy type name; some DBs may still contain fixes marked with this old package name:
|
||||||
properties.put(TypeBasedServiceFinder.TYPE, "com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl");
|
properties.put(TypeBasedServiceFinder.TYPE, "com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl");
|
||||||
registrations.add(context.registerService(GPSFixMongoHandler.class, gpsFixMovingMongoHandler, properties));
|
registrations.add(context.registerService(GPSFixMongoHandler.class, gpsFixMovingMongoHandler, properties));
|
||||||
|
|
||||||
|
registerPreferenceConvertersWhenUserStoreIsAvailable(context);
|
||||||
|
|
||||||
// Add an MBean for the service to the JMX bean server:
|
// Add an MBean for the service to the JMX bean server:
|
||||||
RacingEventServiceMXBean mbean = new RacingEventServiceMXBeanImpl(racingEventService);
|
RacingEventServiceMXBean mbean = new RacingEventServiceMXBeanImpl(racingEventService);
|
||||||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
@@ -117,6 +122,29 @@ public class Activator implements BundleActivator {
|
|||||||
Charset.defaultCharset());
|
Charset.defaultCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerPreferenceConvertersWhenUserStoreIsAvailable(BundleContext bundleContext) {
|
||||||
|
ServiceTracker<UserStore, UserStore> userStoreTracker = ServiceTrackerFactory.createAndOpen(bundleContext,
|
||||||
|
UserStore.class);
|
||||||
|
new Thread("ServiceTracker waiting for UserStore service") {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
logger.info("Waiting for UserStore service...");
|
||||||
|
UserStore userStore = userStoreTracker.waitForService(0);
|
||||||
|
logger.info("Obtained UserStore service " + userStore);
|
||||||
|
registerPreferenceConvertersForUserStore(userStore);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.log(Level.SEVERE, "Interrupted while waiting for UserStore service", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerPreferenceConvertersForUserStore(UserStore userStore) {
|
||||||
|
// TODO implement for favorite settings
|
||||||
|
// userStore.registerPreferenceConverter("TODO", new GenericJSONPreferenceConverter(null));
|
||||||
|
}
|
||||||
|
|
||||||
public void stop(BundleContext context) throws Exception {
|
public void stop(BundleContext context) throws Exception {
|
||||||
masterDataImportClassLoaderServiceTracker.close();
|
masterDataImportClassLoaderServiceTracker.close();
|
||||||
if (extenderBundleTracker != null) {
|
if (extenderBundleTracker != null) {
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package com.sap.sailing.server.impl;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.sap.sse.common.settings.generic.GenericSerializableSettings;
|
||||||
|
import com.sap.sse.security.PreferenceConverter;
|
||||||
|
import com.sap.sse.shared.settings.SettingsToJsonSerializer;
|
||||||
|
|
||||||
|
public class GenericJSONPreferenceConverter<PREF extends GenericSerializableSettings> implements PreferenceConverter<PREF> {
|
||||||
|
|
||||||
|
private final SettingsToJsonSerializer serializer = new SettingsToJsonSerializer();
|
||||||
|
private final Supplier<PREF> emptyInstanceFactory;
|
||||||
|
|
||||||
|
public GenericJSONPreferenceConverter(Supplier<PREF> emptyInstanceFactory) {
|
||||||
|
this.emptyInstanceFactory = emptyInstanceFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(PREF preference) {
|
||||||
|
return serializer.serializeToString(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PREF toPreference(String stringPreference) {
|
||||||
|
return serializer.deserialize(emptyInstanceFactory.get(), stringPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.sap.sse.security;
|
||||||
|
|
||||||
|
public interface PreferenceConverter<PREF> {
|
||||||
|
String toString(PREF preference);
|
||||||
|
|
||||||
|
PREF toPreference(String stringPreference);
|
||||||
|
}
|
||||||
@@ -106,4 +106,6 @@ public interface UserStore extends Named {
|
|||||||
* {@code username} no access token has previously been {@link #setAccessToken(String, String) set}.
|
* {@code username} no access token has previously been {@link #setAccessToken(String, String) set}.
|
||||||
*/
|
*/
|
||||||
String getAccessToken(String username);
|
String getAccessToken(String username);
|
||||||
|
|
||||||
|
// void registerPreferenceConverter(String preferenceKey, PreferenceConverter<?> converter);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user