Search in sources :

Example 11 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(id));
    dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(id));
    if (tenantId != null) {
        dashboardInfo.setTenantId(new TenantId(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 12 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(this.getId()));
    dashboard.setCreatedTime(UUIDs.unixTimestamp(this.getId()));
    if (tenantId != null) {
        dashboard.setTenantId(new TenantId(toUUID(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 13 with DashboardId

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

the class JpaDashboardInfoDaoTest method createDashboard.

private void createDashboard(UUID tenantId, int index) {
    DashboardInfo dashboardInfo = new DashboardInfo();
    dashboardInfo.setId(new DashboardId(UUIDs.timeBased()));
    dashboardInfo.setTenantId(new TenantId(tenantId));
    dashboardInfo.setTitle("DASHBOARD_" + index);
    dashboardInfoDao.save(dashboardInfo);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DashboardId(org.thingsboard.server.common.data.id.DashboardId) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo)

Example 14 with DashboardId

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

the class DatabaseHelper method upgradeTo40_assignDashboards.

public static void upgradeTo40_assignDashboards(Path dashboardsDump, DashboardService dashboardService, boolean sql) throws Exception {
    JavaType assignedCustomersType = objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class);
    try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(dashboardsDump), CSV_DUMP_FORMAT.withFirstRecordAsHeader())) {
        csvParser.forEach(record -> {
            String customerIdString = record.get(CUSTOMER_ID);
            String assignedCustomersString = record.get(ASSIGNED_CUSTOMERS);
            DashboardId dashboardId = new DashboardId(toUUID(record.get(ID), sql));
            List<CustomerId> customerIds = new ArrayList<>();
            if (!StringUtils.isEmpty(assignedCustomersString)) {
                try {
                    Set<ShortCustomerInfo> assignedCustomers = objectMapper.readValue(assignedCustomersString, assignedCustomersType);
                    assignedCustomers.forEach((customerInfo) -> {
                        CustomerId customerId = customerInfo.getCustomerId();
                        if (!customerId.isNullUid()) {
                            customerIds.add(customerId);
                        }
                    });
                } catch (IOException e) {
                    log.error("Unable to parse assigned customers field", e);
                }
            }
            if (!StringUtils.isEmpty(customerIdString)) {
                CustomerId customerId = new CustomerId(toUUID(customerIdString, sql));
                if (!customerId.isNullUid()) {
                    customerIds.add(customerId);
                }
            }
            for (CustomerId customerId : customerIds) {
                dashboardService.assignDashboardToCustomer(dashboardId, customerId);
            }
        });
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ShortCustomerInfo(org.thingsboard.server.common.data.ShortCustomerInfo) CSVParser(org.apache.commons.csv.CSVParser) DashboardId(org.thingsboard.server.common.data.id.DashboardId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) IOException(java.io.IOException)

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