Search in sources :

Example 1 with IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService 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 IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService 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 IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method removeLoginListener.

public synchronized void removeLoginListener(LoginListener loginListener) {
    if (loginListeners != null) {
        loginListeners.remove(loginListener);
    }
    IUserFavoritesService favoritesService = marketplaceService.getUserFavoritesService();
    if (favoritesService != null) {
        IMarketplaceStorageService storageService = favoritesService.getStorageService();
        storageService.removeLoginListener(loginListener);
    }
}
Also used : IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Example 4 with IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService in project epp.mpc by eclipse.

the class ServiceLocator method registerStorageService.

public IMarketplaceStorageService registerStorageService(String marketplaceBaseUrl, String apiServerUrl, String apiKey) {
    MarketplaceStorageService marketplaceStorageService = new MarketplaceStorageService();
    Hashtable<String, Object> config = new Hashtable<String, Object>();
    config.put(IMarketplaceStorageService.STORAGE_SERVICE_URL_PROPERTY, apiServerUrl);
    if (apiKey != null) {
        config.put(IMarketplaceStorageService.APPLICATION_TOKEN_PROPERTY, apiKey);
    }
    ServiceRegistration<IMarketplaceStorageService> registration = registerService(marketplaceBaseUrl, IMarketplaceStorageService.class, marketplaceStorageService, config);
    BundleContext bundleContext = ServiceUtil.getBundleContext(registration);
    if (bundleContext != null) {
        marketplaceStorageService.activate(bundleContext, config);
    }
    return marketplaceStorageService;
}
Also used : Hashtable(java.util.Hashtable) MarketplaceStorageService(org.eclipse.epp.internal.mpc.core.service.MarketplaceStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) BundleContext(org.osgi.framework.BundleContext)

Example 5 with IMarketplaceStorageService

use of org.eclipse.epp.mpc.core.service.IMarketplaceStorageService in project epp.mpc by eclipse.

the class ServiceLocator method activate.

/**
 * OSGi service activation method. Activation will cause the locator to start managing individual marketplace
 * services and return the same instances per base url on subsequent calls to {@link #getMarketplaceService(String)}
 * .
 */
public synchronized void activate(BundleContext context, Map<?, ?> properties) {
    URL baseUrl = ServiceUtil.getUrl(properties, DEFAULT_URL, null);
    URL catalogUrl = ServiceUtil.getUrl(properties, CATALOG_URL, baseUrl);
    if (catalogUrl != null) {
        this.defaultCatalogUrl = catalogUrl;
    }
    // else the default value from the constructor is used
    URL marketplaceUrl = ServiceUtil.getUrl(properties, DEFAULT_MARKETPLACE_URL, baseUrl);
    if (marketplaceUrl != null) {
        this.defaultMarketplaceUrl = marketplaceUrl;
    }
    // else the default value from the constructor is used
    marketplaceServiceTracker = new ServiceTracker<IMarketplaceService, IMarketplaceService>(context, IMarketplaceService.class, null);
    marketplaceServiceTracker.open(true);
    catalogServiceTracker = new ServiceTracker<ICatalogService, ICatalogService>(context, ICatalogService.class, null);
    catalogServiceTracker.open(true);
    storageServiceTracker = new ServiceTracker<IMarketplaceStorageService, IMarketplaceStorageService>(context, IMarketplaceStorageService.class, new ServiceTrackerCustomizer<IMarketplaceStorageService, IMarketplaceStorageService>() {

        public IMarketplaceStorageService addingService(ServiceReference<IMarketplaceStorageService> reference) {
            IMarketplaceStorageService service = storageServiceTracker.addingService(reference);
            Object marketplaceUrl = ServiceUtil.getOverridablePropertyValue(reference, IMarketplaceService.BASE_URL);
            if (marketplaceUrl != null && service != null) {
                bindToUserFavoritesServices(marketplaceUrl.toString(), reference);
            }
            return service;
        }

        public void modifiedService(ServiceReference<IMarketplaceStorageService> reference, IMarketplaceStorageService service) {
            Object marketplaceUrl = ServiceUtil.getOverridablePropertyValue(reference, IMarketplaceService.BASE_URL);
            if (marketplaceUrl != null) {
                rebindToUserFavoritesServices(marketplaceUrl.toString(), reference, service);
            } else {
                unbindFromUserFavoritesServices(reference, service);
            }
        }

        public void removedService(ServiceReference<IMarketplaceStorageService> reference, IMarketplaceStorageService service) {
            unbindFromUserFavoritesServices(reference, service);
        }
    });
    storageServiceTracker.open(true);
    favoritesServiceTracker = new ServiceTracker<IUserFavoritesService, IUserFavoritesService>(context, IUserFavoritesService.class, new ServiceTrackerCustomizer<IUserFavoritesService, IUserFavoritesService>() {

        public IUserFavoritesService addingService(ServiceReference<IUserFavoritesService> reference) {
            return ServiceUtil.getService(reference);
        }

        public void modifiedService(ServiceReference<IUserFavoritesService> reference, IUserFavoritesService service) {
            if (!(service instanceof UserFavoritesService)) {
                return;
            }
            ServiceReference<?> storageServiceBinding = (ServiceReference<?>) reference.getProperty(STORAGE_SERVICE_BINDING_ID);
            if (storageServiceBinding != null && service.getStorageService() == null) {
                ((UserFavoritesService) service).bindStorageService((IMarketplaceStorageService) ServiceUtil.getService(storageServiceBinding));
            } else if (service.getStorageService() != null && getDynamicServiceInstance(reference) != null) {
                ((UserFavoritesService) service).setStorageService(null);
            }
        }

        public void removedService(ServiceReference<IUserFavoritesService> reference, IUserFavoritesService service) {
        // ignore
        }
    });
    favoritesServiceTracker.open(true);
}
Also used : ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) UserFavoritesService(org.eclipse.epp.internal.mpc.core.service.UserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Aggregations

IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)14 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)7 Test (org.junit.Test)6 IStorageService (org.eclipse.userstorage.IStorageService)5 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchElementException (java.util.NoSuchElementException)2 CoreException (org.eclipse.core.runtime.CoreException)2 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)2 UserFavoritesService (org.eclipse.epp.internal.mpc.core.service.UserFavoritesService)2 LoginListener (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService.LoginListener)2 BundleContext (org.osgi.framework.BundleContext)2 URL (java.net.URL)1 Hashtable (java.util.Hashtable)1 Callable (java.util.concurrent.Callable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1