Search in sources :

Example 6 with IUserFavoritesService

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

the class ServiceLocator method unbindFromUserFavoritesService.

private void unbindFromUserFavoritesService(ServiceReference<IUserFavoritesService> reference, ServiceReference<IMarketplaceStorageService> serviceReference, IMarketplaceStorageService serviceInstance) {
    ServiceRegistration<IUserFavoritesService> registration = getDynamicServiceInstance(reference);
    if (registration == null) {
        return;
    }
    Object binding = reference.getProperty(STORAGE_SERVICE_BINDING_ID);
    if (binding != null && serviceReference.equals(binding)) {
        if (registration != null) {
            Dictionary<String, Object> properties = ServiceUtil.getProperties(reference);
            properties.remove(STORAGE_SERVICE_BINDING_ID);
            registration.setProperties(properties);
        }
    }
    IUserFavoritesService service = ServiceUtil.getService(registration);
    if (service.getStorageService() == serviceInstance) {
        ((UserFavoritesService) service).unbindStorageService(serviceInstance);
    }
}
Also used : UserFavoritesService(org.eclipse.epp.internal.mpc.core.service.UserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Example 7 with IUserFavoritesService

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

the class ServiceLocator method createMarketplaceService.

protected IMarketplaceService createMarketplaceService(String baseUrl) {
    IMarketplaceService service;
    URL base;
    try {
        base = URLUtil.toURL(baseUrl);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
    DefaultMarketplaceService defaultService = new DefaultMarketplaceService(base);
    Map<String, String> requestMetaParameters = computeDefaultRequestMetaParameters();
    defaultService.setRequestMetaParameters(requestMetaParameters);
    IUserFavoritesService favoritesService = getFavoritesService(baseUrl);
    // FIXME this should be a service reference!
    defaultService.setUserFavoritesService(favoritesService);
    service = new CachingMarketplaceService(defaultService);
    return service;
}
Also used : MalformedURLException(java.net.MalformedURLException) CachingMarketplaceService(org.eclipse.epp.internal.mpc.core.service.CachingMarketplaceService) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) URL(java.net.URL)

Example 8 with IUserFavoritesService

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

the class DefaultCatalogService method registerDynamicFavoritesService.

private void registerDynamicFavoritesService(String catalogUrl, String favoritesApiServer, String favoritesApiKey) {
    IMarketplaceServiceLocator marketplaceServiceLocator = ServiceHelper.getMarketplaceServiceLocator();
    IUserFavoritesService favoritesService = marketplaceServiceLocator.getFavoritesService(catalogUrl);
    if (favoritesService != null) {
        return;
    }
    ((ServiceLocator) marketplaceServiceLocator).registerFavoritesService(catalogUrl, favoritesApiServer, favoritesApiKey);
}
Also used : IMarketplaceServiceLocator(org.eclipse.epp.mpc.core.service.IMarketplaceServiceLocator) ServiceLocator(org.eclipse.epp.internal.mpc.core.ServiceLocator) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceServiceLocator(org.eclipse.epp.mpc.core.service.IMarketplaceServiceLocator)

Example 9 with IUserFavoritesService

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

Example 10 with IUserFavoritesService

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

the class ServiceLocator method registerFavoritesService.

public IUserFavoritesService registerFavoritesService(String marketplaceBaseUrl, String apiServerUrl, String apiKey) {
    IMarketplaceStorageService storageService = getStorageService(marketplaceBaseUrl);
    if (storageService == null) {
        storageService = registerStorageService(marketplaceBaseUrl, apiServerUrl, apiKey);
    }
    UserFavoritesService favoritesService = new UserFavoritesService();
    favoritesService.bindStorageService(storageService);
    registerService(marketplaceBaseUrl, IUserFavoritesService.class, favoritesService);
    return favoritesService;
}
Also used : UserFavoritesService(org.eclipse.epp.internal.mpc.core.service.UserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Aggregations

IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)20 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)7 IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)7 MalformedURLException (java.net.MalformedURLException)6 INode (org.eclipse.epp.mpc.core.model.INode)6 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 CoreException (org.eclipse.core.runtime.CoreException)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 UserFavoritesService (org.eclipse.epp.internal.mpc.core.service.UserFavoritesService)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NoSuchElementException (java.util.NoSuchElementException)2 Callable (java.util.concurrent.Callable)2 IStatus (org.eclipse.core.runtime.IStatus)2 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)2 LoginListener (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService.LoginListener)2