Search in sources :

Example 1 with ExtensionService

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

the class ExtensionResource method uninstallExtension.

@POST
@Path("/{extensionId: [a-zA-Z_0-9-:]*}/uninstall")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK") })
public Response uninstallExtension(@PathParam("extensionId") @ApiParam(value = "extension ID", required = true) final String extensionId) {
    ThreadPoolManager.getPool(THREAD_POOL_NAME).submit(() -> {
        try {
            ExtensionService extensionService = getExtensionService(extensionId);
            extensionService.uninstall(extensionId);
        } catch (Exception e) {
            logger.error("Exception while uninstalling extension: {}", e.getMessage());
            postFailureEvent(extensionId, e.getMessage());
        }
    });
    return Response.ok(null, MediaType.TEXT_PLAIN).build();
}
Also used : ExtensionService(org.eclipse.smarthome.core.extension.ExtensionService) URISyntaxException(java.net.URISyntaxException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ExtensionService

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

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

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

the class ExtensionResource method installExtension.

@POST
@Path("/{extensionId: [a-zA-Z_0-9-:]*}/install")
@ApiOperation(value = "Installs the extension with the given ID.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK") })
public Response installExtension(@PathParam("extensionId") @ApiParam(value = "extension ID", required = true) final String extensionId) {
    ThreadPoolManager.getPool(THREAD_POOL_NAME).submit(() -> {
        try {
            ExtensionService extensionService = getExtensionService(extensionId);
            extensionService.install(extensionId);
        } catch (Exception e) {
            logger.error("Exception while installing extension: {}", e.getMessage());
            postFailureEvent(extensionId, e.getMessage());
        }
    });
    return Response.ok(null, MediaType.TEXT_PLAIN).build();
}
Also used : ExtensionService(org.eclipse.smarthome.core.extension.ExtensionService) URISyntaxException(java.net.URISyntaxException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ExtensionService (org.eclipse.smarthome.core.extension.ExtensionService)4 ApiResponses (io.swagger.annotations.ApiResponses)3 Path (javax.ws.rs.Path)3 ApiOperation (io.swagger.annotations.ApiOperation)2 URISyntaxException (java.net.URISyntaxException)2 POST (javax.ws.rs.POST)2 Collator (java.text.Collator)1 Locale (java.util.Locale)1 TreeSet (java.util.TreeSet)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Extension (org.eclipse.smarthome.core.extension.Extension)1 ExtensionType (org.eclipse.smarthome.core.extension.ExtensionType)1