use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.
the class MarketplaceStorageServiceRegistrationTest method testRegisterStorageServiceWithSlashHavingExistingWithoutSlash.
@Test
public void testRegisterStorageServiceWithSlashHavingExistingWithoutSlash() {
storageServices.provide("WithoutSlash", "https://api-test.example.org");
IMarketplaceStorageService registered = serviceLocator.registerStorageService(DefaultMarketplaceService.DEFAULT_SERVICE_LOCATION, "https://api-test.example.org/", null);
assertNotNull(registered);
assertEquals("https://api-test.example.org", registered.getServiceUri().toString());
IStorageService withSlash = IStorageService.Registry.INSTANCE.getService(URI.create("https://api-test.example.org/"));
assertNull(withSlash);
}
use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.
the class MarketplaceStorageServiceRegistrationTest method testRegisterStorageServiceWithoutSlashHavingExistingWithSlash.
@Test
public void testRegisterStorageServiceWithoutSlashHavingExistingWithSlash() {
storageServices.provide("WithSlash", "https://api-test.example.org/");
IMarketplaceStorageService registered = serviceLocator.registerStorageService(DefaultMarketplaceService.DEFAULT_SERVICE_LOCATION, "https://api-test.example.org", null);
assertNotNull(registered);
assertEquals("https://api-test.example.org/", registered.getServiceUri().toString());
IStorageService withoutSlash = IStorageService.Registry.INSTANCE.getService(URI.create("https://api-test.example.org"));
assertNull(withoutSlash);
}
use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.
the class MarketplaceStorageService method cleanupExtraStorageService.
private static IStorageService cleanupExtraStorageService(IStorageService service, IStorageService extraService) {
IStorageService.Dynamic removeDynamic;
IStorageService keepService;
if (extraService instanceof IStorageService.Dynamic) {
removeDynamic = (IStorageService.Dynamic) extraService;
keepService = service;
} else if (service instanceof IStorageService.Dynamic) {
removeDynamic = (IStorageService.Dynamic) service;
keepService = extraService;
} else {
return service;
}
if (removeDynamic instanceof StorageService && keepService instanceof StorageService) {
StorageService removeImpl = (StorageService) removeDynamic;
StorageService keepImpl = (StorageService) keepService;
ISecurePreferences removeSecurePreferences = removeImpl.getSecurePreferences();
ISecurePreferences keepSecurePreferences = keepImpl.getSecurePreferences();
try {
copySecurePreferences(removeSecurePreferences, keepSecurePreferences);
} catch (Exception e) {
MarketplaceClientCore.error(NLS.bind("Failed to migrate secure storage values from {0} to {1}", removeDynamic.getServiceURI(), keepService.getServiceURI()), e);
}
}
removeDynamic.remove();
return keepService;
}
use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.
the class MarketplaceStorageService method activate.
public void activate(BundleContext context, Map<?, ?> properties) {
Object serviceUrlValue = ServiceUtil.getOverridablePropertyValue(properties, STORAGE_SERVICE_URL_PROPERTY);
if (serviceUrlValue != null) {
URI serviceUri = URI.create(serviceUrlValue.toString());
String serviceName = getProperty(properties, STORAGE_SERVICE_NAME_PROPERTY, DEFAULT_STORAGE_SERVICE_NAME);
IStorageService registered = registerStorageService(serviceUri, serviceName);
setServiceUri(registered.getServiceURI());
}
String applicationToken = getProperty(properties, APPLICATION_TOKEN_PROPERTY, DEFAULT_APPLICATION_TOKEN);
this.applicationToken = applicationToken;
Object marketplaceBaseUri = ServiceUtil.getOverridablePropertyValue(properties, IMarketplaceService.BASE_URL);
if (marketplaceBaseUri != null) {
this.marketplaceBaseUri = marketplaceBaseUri.toString();
}
}
use of org.eclipse.userstorage.IStorageService in project epp.mpc by eclipse.
the class MarketplaceStorageService method registerStorageService.
private IStorageService registerStorageService(URI serviceUri, String serviceName) {
customStorageService = null;
URI normalizedUri = normalizePath(serviceUri);
URI denormalizedUri = normalizePath(serviceUri, false);
IStorageService service = IStorageService.Registry.INSTANCE.getService(normalizedUri);
IStorageService extraService = IStorageService.Registry.INSTANCE.getService(denormalizedUri);
if (service == null) {
if (extraService != null) {
return extraService;
}
customStorageService = IStorageService.Registry.INSTANCE.addService(serviceName, normalizedUri);
service = customStorageService;
return service;
}
if (extraService != null && extraService != service) {
service = cleanupExtraStorageService(service, extraService);
}
return service;
}
Aggregations