Search in sources :

Example 1 with MarketplaceHandlerException

use of org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException in project smarthome by eclipse.

the class AutomationExtensionHandler method install.

@Override
public void install(MarketplaceExtension ext) throws MarketplaceHandlerException {
    String url = ext.getDownloadUrl();
    try {
        String template = getTemplate(url);
        marketplaceRuleTemplateProvider.addTemplateAsJSON(ext.getId(), template);
    } catch (IOException e) {
        logger.error("Rule template from marketplace cannot be downloaded: {}", e.getMessage());
        throw new MarketplaceHandlerException("Template cannot be downloaded.");
    } catch (Exception e) {
        logger.error("Rule template from marketplace is invalid: {}", e.getMessage());
        throw new MarketplaceHandlerException("Template is not valid.");
    }
}
Also used : MarketplaceHandlerException(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException) IOException(java.io.IOException) MarketplaceHandlerException(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException) IOException(java.io.IOException)

Example 2 with MarketplaceHandlerException

use of org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException in project smarthome by eclipse.

the class BindingExtensionHandler method install.

@Override
public void install(MarketplaceExtension ext) throws MarketplaceHandlerException {
    String url = ext.getDownloadUrl();
    try {
        Bundle bundle = bundleContext.installBundle(url);
        try {
            bundle.start();
        } catch (BundleException e) {
            logger.warn("Installed bundle, but failed to start it: {}", e.getMessage());
        }
        installedBindings.put(ext.getId(), bundle.getBundleId());
        persistInstalledBindingsMap(installedBindings);
    } catch (BundleException e) {
        logger.debug("Failed to install binding from marketplace.", e);
        throw new MarketplaceHandlerException("Binding cannot be installed: " + e.getMessage());
    }
}
Also used : MarketplaceHandlerException(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException)

Example 3 with MarketplaceHandlerException

use of org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException in project smarthome by eclipse.

the class BindingExtensionHandler method uninstall.

@Override
public void uninstall(MarketplaceExtension ext) throws MarketplaceHandlerException {
    Long id = installedBindings.get(ext.getId());
    if (id != null) {
        Bundle bundle = bundleContext.getBundle(id);
        if (bundle != null) {
            try {
                bundle.stop();
                bundle.uninstall();
                installedBindings.remove(ext.getId());
                persistInstalledBindingsMap(installedBindings);
            } catch (BundleException e) {
                throw new MarketplaceHandlerException("Failed deinstalling binding: " + e.getMessage());
            }
        } else {
            // we do not have such a bundle, so let's remove it from our internal map
            installedBindings.remove(ext.getId());
            persistInstalledBindingsMap(installedBindings);
            throw new MarketplaceHandlerException("Id not known.");
        }
    } else {
        throw new MarketplaceHandlerException("Id not known.");
    }
}
Also used : MarketplaceHandlerException(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException)

Example 4 with MarketplaceHandlerException

use of org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException in project smarthome by eclipse.

the class MarketplaceExtensionService method install.

@Override
public void install(String extensionId) {
    Extension ext = getExtension(extensionId, null);
    if (ext instanceof MarketplaceExtension) {
        MarketplaceExtension mpExt = (MarketplaceExtension) ext;
        for (MarketplaceExtensionHandler handler : extensionHandlers) {
            if (handler.supports(mpExt)) {
                if (!handler.isInstalled(mpExt)) {
                    try {
                        handler.install(mpExt);
                        postInstalledEvent(extensionId);
                    } catch (MarketplaceHandlerException e) {
                        postFailureEvent(extensionId, e.getMessage());
                    }
                } else {
                    postFailureEvent(extensionId, "Extension is already installed.");
                }
                return;
            }
        }
    }
    postFailureEvent(extensionId, "Extension not known.");
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension) MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension) MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension) MarketplaceHandlerException(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException) MarketplaceExtensionHandler(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtensionHandler)

Example 5 with MarketplaceHandlerException

use of org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException in project smarthome by eclipse.

the class MarketplaceExtensionService method uninstall.

@Override
public void uninstall(String extensionId) {
    Extension ext = getExtension(extensionId, null);
    if (ext instanceof MarketplaceExtension) {
        MarketplaceExtension mpExt = (MarketplaceExtension) ext;
        for (MarketplaceExtensionHandler handler : extensionHandlers) {
            if (handler.supports(mpExt)) {
                if (handler.isInstalled(mpExt)) {
                    try {
                        handler.uninstall(mpExt);
                        postUninstalledEvent(extensionId);
                    } catch (MarketplaceHandlerException e) {
                        postFailureEvent(extensionId, e.getMessage());
                    }
                } else {
                    postFailureEvent(extensionId, "Extension is not installed.");
                }
                return;
            }
        }
    }
    postFailureEvent(extensionId, "Extension not known.");
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension) MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension) MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension) MarketplaceHandlerException(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException) MarketplaceExtensionHandler(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtensionHandler)

Aggregations

MarketplaceHandlerException (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException)5 Extension (org.eclipse.smarthome.core.extension.Extension)2 MarketplaceExtension (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension)2 MarketplaceExtensionHandler (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtensionHandler)2 Bundle (org.osgi.framework.Bundle)2 BundleException (org.osgi.framework.BundleException)2 IOException (java.io.IOException)1