Search in sources :

Example 1 with Extension

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

the class SampleExtensionService method activate.

protected void activate() {
    types.add(new ExtensionType("binding", "Bindings"));
    types.add(new ExtensionType("ui", "User Interfaces"));
    types.add(new ExtensionType("persistence", "Persistence Services"));
    for (ExtensionType type : types) {
        for (int i = 0; i < 10; i++) {
            String id = type.getId() + Integer.toString(i);
            boolean installed = Math.random() > 0.5;
            String name = RandomStringUtils.randomAlphabetic(5);
            String label = name + " " + StringUtils.capitalize(type.getId());
            String typeId = type.getId();
            String version = "1.0";
            String link = (Math.random() < 0.5) ? null : "http://lmgtfy.com/?q=" + name;
            String description = createDescription();
            String imageLink = null;
            String backgroundColor = createRandomColor();
            Extension extension = new Extension(id, typeId, label, version, link, installed, description, backgroundColor, imageLink);
            extensions.put(extension.getId(), extension);
        }
    }
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension) ExtensionType(org.eclipse.smarthome.core.extension.ExtensionType)

Example 2 with Extension

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

the class SampleExtensionService method install.

@Override
public void install(String id) {
    try {
        Thread.sleep((long) (Math.random() * 10000));
        Extension extension = getExtension(id, null);
        extension.setInstalled(true);
        postInstalledEvent(id);
    } catch (InterruptedException e) {
    }
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension)

Example 3 with Extension

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

the class ExtensionResource method getById.

@GET
@Path("/{extensionId: [a-zA-Z_0-9-]*}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get extension with given ID.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class), @ApiResponse(code = 404, message = "Not found") })
public Response getById(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language, @PathParam("extensionId") @ApiParam(value = "extension ID", required = true) String extensionId) {
    logger.debug("Received HTTP GET request at '{}'.", uriInfo.getPath());
    Locale locale = LocaleUtil.getLocale(language);
    ExtensionService extensionService = getExtensionService(extensionId);
    Extension responseObject = extensionService.getExtension(extensionId, locale);
    if (responseObject != null) {
        return Response.ok(responseObject).build();
    }
    return Response.status(404).build();
}
Also used : Locale(java.util.Locale) ExtensionService(org.eclipse.smarthome.core.extension.ExtensionService) Extension(org.eclipse.smarthome.core.extension.Extension) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with Extension

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

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

the class SampleExtensionService method uninstall.

@Override
public void uninstall(String id) {
    try {
        Thread.sleep((long) (Math.random() * 5000));
        Extension extension = getExtension(id, null);
        extension.setInstalled(false);
        postUninstalledEvent(id);
    } catch (InterruptedException e) {
    }
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension)

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