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);
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations