Search in sources :

Example 1 with MarketplaceExtension

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

the class MarketplaceExtensionService method convertToExtension.

private MarketplaceExtension convertToExtension(Node node) {
    String extId = getExtensionId(node);
    String name = node.name;
    String desc = node.shortdescription;
    String version = StringUtils.isNotEmpty(node.version) ? node.version : "1.0";
    if (!validName(name) || !validDescription(desc)) {
        logger.debug("Ignoring node {} due to invalid content.", node.id);
        return null;
    }
    if (MP_PACKAGETYPE_BINDING.equals(node.packagetypes)) {
        MarketplaceExtension ext = new MarketplaceExtension(extId, MarketplaceExtension.EXT_TYPE_BINDING, name, version, node.supporturl, false, desc, null, node.image, node.updateurl, node.packageformat);
        return ext;
    } else if (MP_PACKAGETYPE_RULE_TEMPLATE.equals(node.packagetypes)) {
        MarketplaceExtension ext = new MarketplaceExtension(extId, MarketplaceExtension.EXT_TYPE_RULE_TEMPLATE, name, version, node.supporturl, false, desc, null, node.image, node.updateurl, node.packageformat);
        return ext;
    } else {
        return null;
    }
}
Also used : MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension)

Example 2 with MarketplaceExtension

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

the class MarketplaceExtensionService method getExtensions.

@Override
public List<Extension> getExtensions(Locale locale) {
    List<Node> nodes = proxy.getNodes();
    List<Extension> exts = new ArrayList<>(nodes.size());
    for (Node node : nodes) {
        if (node.id == null) {
            // workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=512493
            continue;
        }
        if (toMaturityLevel(node.status) < this.maturityLevel) {
            continue;
        }
        if (!includeBindings && node.packagetypes.equals(MP_PACKAGETYPE_BINDING)) {
            continue;
        }
        if (!includeRuleTemplates && node.packagetypes.equals(MP_PACKAGETYPE_RULE_TEMPLATE)) {
            continue;
        }
        MarketplaceExtension ext = convertToExtension(node);
        if (ext != null) {
            if (setInstalledFlag(ext)) {
                exts.add(ext);
            }
        }
    }
    return exts;
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension) MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension) MarketplaceExtension(org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension) Node(org.eclipse.smarthome.extensionservice.marketplace.internal.model.Node) ArrayList(java.util.ArrayList)

Example 3 with MarketplaceExtension

use of org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension 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 4 with MarketplaceExtension

use of org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension 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

MarketplaceExtension (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension)4 Extension (org.eclipse.smarthome.core.extension.Extension)3 MarketplaceExtensionHandler (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtensionHandler)2 MarketplaceHandlerException (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceHandlerException)2 ArrayList (java.util.ArrayList)1 Node (org.eclipse.smarthome.extensionservice.marketplace.internal.model.Node)1