Search in sources :

Example 1 with HomeDashboard

use of org.thingsboard.server.common.data.HomeDashboard in project thingsboard by thingsboard.

the class DashboardController method getHomeDashboard.

@ApiOperation(value = "Get Home Dashboard (getHomeDashboard)", notes = "Returns the home dashboard object that is configured as 'homeDashboardId' parameter in the 'additionalInfo' of the User. " + "If 'homeDashboardId' parameter is not set on the User level and the User has authority 'CUSTOMER_USER', check the same parameter for the corresponding Customer. " + "If 'homeDashboardId' parameter is not set on the User and Customer levels then checks the same parameter for the Tenant that owns the user. " + DASHBOARD_DEFINITION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/dashboard/home", method = RequestMethod.GET)
@ResponseBody
public HomeDashboard getHomeDashboard() throws ThingsboardException {
    try {
        SecurityUser securityUser = getCurrentUser();
        if (securityUser.isSystemAdmin()) {
            return null;
        }
        User user = userService.findUserById(securityUser.getTenantId(), securityUser.getId());
        JsonNode additionalInfo = user.getAdditionalInfo();
        HomeDashboard homeDashboard;
        homeDashboard = extractHomeDashboardFromAdditionalInfo(additionalInfo);
        if (homeDashboard == null) {
            if (securityUser.isCustomerUser()) {
                Customer customer = customerService.findCustomerById(securityUser.getTenantId(), securityUser.getCustomerId());
                additionalInfo = customer.getAdditionalInfo();
                homeDashboard = extractHomeDashboardFromAdditionalInfo(additionalInfo);
            }
            if (homeDashboard == null) {
                Tenant tenant = tenantService.findTenantById(securityUser.getTenantId());
                additionalInfo = tenant.getAdditionalInfo();
                homeDashboard = extractHomeDashboardFromAdditionalInfo(additionalInfo);
            }
        }
        return homeDashboard;
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : HomeDashboard(org.thingsboard.server.common.data.HomeDashboard) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) User(org.thingsboard.server.common.data.User) Tenant(org.thingsboard.server.common.data.Tenant) Customer(org.thingsboard.server.common.data.Customer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with HomeDashboard

use of org.thingsboard.server.common.data.HomeDashboard in project thingsboard by thingsboard.

the class DashboardController method extractHomeDashboardFromAdditionalInfo.

private HomeDashboard extractHomeDashboardFromAdditionalInfo(JsonNode additionalInfo) {
    try {
        if (additionalInfo != null && additionalInfo.has(HOME_DASHBOARD_ID) && !additionalInfo.get(HOME_DASHBOARD_ID).isNull()) {
            String strDashboardId = additionalInfo.get(HOME_DASHBOARD_ID).asText();
            DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
            Dashboard dashboard = checkDashboardId(dashboardId, Operation.READ);
            boolean hideDashboardToolbar = true;
            if (additionalInfo.has(HOME_DASHBOARD_HIDE_TOOLBAR)) {
                hideDashboardToolbar = additionalInfo.get(HOME_DASHBOARD_HIDE_TOOLBAR).asBoolean();
            }
            return new HomeDashboard(dashboard, hideDashboardToolbar);
        }
    } catch (Exception e) {
    }
    return null;
}
Also used : HomeDashboard(org.thingsboard.server.common.data.HomeDashboard) Dashboard(org.thingsboard.server.common.data.Dashboard) HomeDashboard(org.thingsboard.server.common.data.HomeDashboard) DashboardId(org.thingsboard.server.common.data.id.DashboardId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException)

Aggregations

HomeDashboard (org.thingsboard.server.common.data.HomeDashboard)2 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 Customer (org.thingsboard.server.common.data.Customer)1 Dashboard (org.thingsboard.server.common.data.Dashboard)1 Tenant (org.thingsboard.server.common.data.Tenant)1 User (org.thingsboard.server.common.data.User)1 DashboardId (org.thingsboard.server.common.data.id.DashboardId)1 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)1