Search in sources :

Example 1 with IStorageService

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);
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) Test(org.junit.Test)

Example 2 with IStorageService

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);
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) Test(org.junit.Test)

Example 3 with IStorageService

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;
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) URISyntaxException(java.net.URISyntaxException) StorageException(org.eclipse.equinox.security.storage.StorageException) IOException(java.io.IOException) IStorageService(org.eclipse.userstorage.IStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) StorageService(org.eclipse.userstorage.internal.StorageService)

Example 4 with IStorageService

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();
    }
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) URI(java.net.URI)

Example 5 with IStorageService

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;
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) URI(java.net.URI)

Aggregations

IStorageService (org.eclipse.userstorage.IStorageService)10 IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)6 Test (org.junit.Test)5 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)1 ServiceLocator (org.eclipse.epp.internal.mpc.core.ServiceLocator)1 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)1 StorageException (org.eclipse.equinox.security.storage.StorageException)1 Dynamic (org.eclipse.userstorage.IStorageService.Dynamic)1 StorageService (org.eclipse.userstorage.internal.StorageService)1 AbstractCredentialsProvider (org.eclipse.userstorage.spi.AbstractCredentialsProvider)1 Credentials (org.eclipse.userstorage.spi.Credentials)1 ICredentialsProvider (org.eclipse.userstorage.spi.ICredentialsProvider)1 Before (org.junit.Before)1