Search in sources :

Example 6 with Extension

use of org.eclipse.smarthome.core.extension.Extension 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 7 with Extension

use of org.eclipse.smarthome.core.extension.Extension 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)

Example 8 with Extension

use of org.eclipse.smarthome.core.extension.Extension in project smarthome by eclipse.

the class MarketplaceExtensionService method getTypes.

@Override
public List<ExtensionType> getTypes(Locale locale) {
    ArrayList<ExtensionType> types = new ArrayList<>(2);
    List<Extension> exts = getExtensions(locale);
    if (includeBindings) {
        for (Extension ext : exts) {
            if (ext.getType().equals(MarketplaceExtension.EXT_TYPE_BINDING)) {
                types.add(new ExtensionType(MarketplaceExtension.EXT_TYPE_BINDING, "Bindings"));
                break;
            }
        }
    }
    if (includeRuleTemplates) {
        for (Extension ext : exts) {
            if (ext.getType().equals(MarketplaceExtension.EXT_TYPE_RULE_TEMPLATE)) {
                types.add(new ExtensionType(MarketplaceExtension.EXT_TYPE_RULE_TEMPLATE, "Rule Templates"));
                break;
            }
        }
    }
    return Collections.unmodifiableList(types);
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension) MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension) ExtensionType(org.eclipse.smarthome.core.extension.ExtensionType) ArrayList(java.util.ArrayList)

Aggregations

Extension (org.eclipse.smarthome.core.extension.Extension)8 MarketplaceExtension (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension)4 ArrayList (java.util.ArrayList)2 ExtensionType (org.eclipse.smarthome.core.extension.ExtensionType)2 MarketplaceExtensionHandler (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtensionHandler)2 MarketplaceHandlerException (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Locale (java.util.Locale)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ExtensionService (org.eclipse.smarthome.core.extension.ExtensionService)1 Node (org.eclipse.smarthome.extensionservice.marketplace.internal.model.Node)1