Search in sources :

Example 1 with ExtensionType

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

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

the class ExtensionResource method getAllExtensionTypes.

private Set<ExtensionType> getAllExtensionTypes(Locale locale) {
    final Collator coll = Collator.getInstance(locale);
    coll.setStrength(Collator.PRIMARY);
    Set<ExtensionType> ret = new TreeSet<>(new Comparator<ExtensionType>() {

        @Override
        public int compare(ExtensionType o1, ExtensionType o2) {
            return coll.compare(o1.getLabel(), o2.getLabel());
        }
    });
    for (ExtensionService extensionService : extensionServices) {
        ret.addAll(extensionService.getTypes(locale));
    }
    return ret;
}
Also used : ExtensionService(org.eclipse.smarthome.core.extension.ExtensionService) TreeSet(java.util.TreeSet) ExtensionType(org.eclipse.smarthome.core.extension.ExtensionType) Collator(java.text.Collator)

Example 3 with ExtensionType

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

the class ExtensionResource method getTypes.

@GET
@Path("/types")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all extension types.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class) })
public Response getTypes(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language) {
    logger.debug("Received HTTP GET request at '{}'", uriInfo.getPath());
    Locale locale = LocaleUtil.getLocale(language);
    Stream<ExtensionType> extensionTypeStream = getAllExtensionTypes(locale).stream().distinct();
    return Response.ok(new Stream2JSONInputStream(extensionTypeStream)).build();
}
Also used : Locale(java.util.Locale) ExtensionType(org.eclipse.smarthome.core.extension.ExtensionType) Stream2JSONInputStream(org.eclipse.smarthome.io.rest.Stream2JSONInputStream) 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 ExtensionType

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

ExtensionType (org.eclipse.smarthome.core.extension.ExtensionType)4 Extension (org.eclipse.smarthome.core.extension.Extension)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Collator (java.text.Collator)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 TreeSet (java.util.TreeSet)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 MarketplaceExtension (org.eclipse.smarthome.extensionservice.marketplace.MarketplaceExtension)1 Stream2JSONInputStream (org.eclipse.smarthome.io.rest.Stream2JSONInputStream)1