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;
}
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;
}
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);
}
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);
}
});
}
}
Aggregations