Search in sources :

Example 1 with DashboardId

use of org.thingsboard.server.common.data.id.DashboardId in project thingsboard by thingsboard.

the class DashboardInfoEntity method toData.

@Override
public DashboardInfo toData() {
    DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(getId()));
    dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(getId()));
    if (tenantId != null) {
        dashboardInfo.setTenantId(new TenantId(toUUID(tenantId)));
    }
    dashboardInfo.setTitle(title);
    if (!StringUtils.isEmpty(assignedCustomers)) {
        try {
            dashboardInfo.setAssignedCustomers(objectMapper.readValue(assignedCustomers, assignedCustomersType));
        } catch (IOException e) {
            log.warn("Unable to parse assigned customers!", e);
        }
    }
    return dashboardInfo;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DashboardId(org.thingsboard.server.common.data.id.DashboardId) IOException(java.io.IOException) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo)

Example 2 with DashboardId

use of org.thingsboard.server.common.data.id.DashboardId in project thingsboard by thingsboard.

the class DashboardEntity method toData.

@Override
public Dashboard toData() {
    Dashboard dashboard = new Dashboard(new DashboardId(id));
    dashboard.setCreatedTime(UUIDs.unixTimestamp(id));
    if (tenantId != null) {
        dashboard.setTenantId(new TenantId(tenantId));
    }
    dashboard.setTitle(title);
    if (!StringUtils.isEmpty(assignedCustomers)) {
        try {
            dashboard.setAssignedCustomers(objectMapper.readValue(assignedCustomers, assignedCustomersType));
        } catch (IOException e) {
            log.warn("Unable to parse assigned customers!", e);
        }
    }
    dashboard.setConfiguration(configuration);
    return dashboard;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Dashboard(org.thingsboard.server.common.data.Dashboard) DashboardId(org.thingsboard.server.common.data.id.DashboardId) IOException(java.io.IOException)

Example 3 with DashboardId

use of org.thingsboard.server.common.data.id.DashboardId in project thingsboard by thingsboard.

the class DashboardController method assignDashboardToCustomer.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.POST)
@ResponseBody
public Dashboard assignDashboardToCustomer(@PathVariable("customerId") String strCustomerId, @PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    checkParameter(DASHBOARD_ID, strDashboardId);
    try {
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        Customer customer = checkCustomerId(customerId);
        DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
        checkDashboardId(dashboardId);
        Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));
        logEntityAction(dashboardId, savedDashboard, customerId, ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName());
        return savedDashboard;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DASHBOARD), null, null, ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId, strCustomerId);
        throw handleException(e);
    }
}
Also used : CustomerId(org.thingsboard.server.common.data.id.CustomerId) DashboardId(org.thingsboard.server.common.data.id.DashboardId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with DashboardId

use of org.thingsboard.server.common.data.id.DashboardId in project thingsboard by thingsboard.

the class DashboardController method addDashboardCustomers.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/dashboard/{dashboardId}/customers/add", method = RequestMethod.POST)
@ResponseBody
public Dashboard addDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDashboardId, @RequestBody String[] strCustomerIds) throws ThingsboardException {
    checkParameter(DASHBOARD_ID, strDashboardId);
    try {
        DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
        Dashboard dashboard = checkDashboardId(dashboardId);
        Set<CustomerId> customerIds = new HashSet<>();
        if (strCustomerIds != null) {
            for (String strCustomerId : strCustomerIds) {
                CustomerId customerId = new CustomerId(toUUID(strCustomerId));
                if (!dashboard.isAssignedToCustomer(customerId)) {
                    customerIds.add(customerId);
                }
            }
        }
        if (customerIds.isEmpty()) {
            return dashboard;
        } else {
            Dashboard savedDashboard = null;
            for (CustomerId customerId : customerIds) {
                savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));
                ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
                logEntityAction(dashboardId, savedDashboard, customerId, ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
            }
            return savedDashboard;
        }
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DASHBOARD), null, null, ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
        throw handleException(e);
    }
}
Also used : DashboardId(org.thingsboard.server.common.data.id.DashboardId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) HashSet(java.util.HashSet) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with DashboardId

use of org.thingsboard.server.common.data.id.DashboardId in project thingsboard by thingsboard.

the class DashboardController method unassignDashboardFromCustomer.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.DELETE)
@ResponseBody
public Dashboard unassignDashboardFromCustomer(@PathVariable("customerId") String strCustomerId, @PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    checkParameter(DASHBOARD_ID, strDashboardId);
    try {
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        Customer customer = checkCustomerId(customerId);
        DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
        Dashboard dashboard = checkDashboardId(dashboardId);
        Dashboard savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(dashboardId, customerId));
        logEntityAction(dashboardId, dashboard, customerId, ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customer.getId().toString(), customer.getName());
        return savedDashboard;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DASHBOARD), null, null, ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);
        throw handleException(e);
    }
}
Also used : CustomerId(org.thingsboard.server.common.data.id.CustomerId) DashboardId(org.thingsboard.server.common.data.id.DashboardId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

DashboardId (org.thingsboard.server.common.data.id.DashboardId)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)8 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)8 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 IOException (java.io.IOException)5 TenantId (org.thingsboard.server.common.data.id.TenantId)5 HashSet (java.util.HashSet)3 DashboardInfo (org.thingsboard.server.common.data.DashboardInfo)3 Dashboard (org.thingsboard.server.common.data.Dashboard)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 CSVParser (org.apache.commons.csv.CSVParser)1 ShortCustomerInfo (org.thingsboard.server.common.data.ShortCustomerInfo)1