use of org.thingsboard.server.common.data.TenantProfile in project thingsboard by thingsboard.
the class BaseController method checkTenantProfileId.
TenantProfile checkTenantProfileId(TenantProfileId tenantProfileId, Operation operation) throws ThingsboardException {
try {
validateId(tenantProfileId, "Incorrect tenantProfileId " + tenantProfileId);
TenantProfile tenantProfile = tenantProfileService.findTenantProfileById(getTenantId(), tenantProfileId);
checkNotNull(tenantProfile, "Tenant profile with id [" + tenantProfileId + "] is not found");
accessControlService.checkPermission(getCurrentUser(), Resource.TENANT_PROFILE, operation);
return tenantProfile;
} catch (Exception e) {
throw handleException(e, false);
}
}
use of org.thingsboard.server.common.data.TenantProfile in project thingsboard by thingsboard.
the class BaseTenantProfileServiceTest method testSetDefaultTenantProfile.
@Test
public void testSetDefaultTenantProfile() {
TenantProfile tenantProfile1 = this.createTenantProfile("Tenant Profile 1");
TenantProfile tenantProfile2 = this.createTenantProfile("Tenant Profile 2");
TenantProfile savedTenantProfile1 = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile1);
TenantProfile savedTenantProfile2 = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile2);
boolean result = tenantProfileService.setDefaultTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile1.getId());
Assert.assertTrue(result);
TenantProfile defaultTenantProfile = tenantProfileService.findDefaultTenantProfile(TenantId.SYS_TENANT_ID);
Assert.assertNotNull(defaultTenantProfile);
Assert.assertEquals(savedTenantProfile1.getId(), defaultTenantProfile.getId());
result = tenantProfileService.setDefaultTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile2.getId());
Assert.assertTrue(result);
defaultTenantProfile = tenantProfileService.findDefaultTenantProfile(TenantId.SYS_TENANT_ID);
Assert.assertNotNull(defaultTenantProfile);
Assert.assertEquals(savedTenantProfile2.getId(), defaultTenantProfile.getId());
}
use of org.thingsboard.server.common.data.TenantProfile in project thingsboard by thingsboard.
the class BaseTenantProfileServiceTest method testFindTenantProfiles.
@Test
public void testFindTenantProfiles() {
List<TenantProfile> tenantProfiles = new ArrayList<>();
PageLink pageLink = new PageLink(17);
PageData<TenantProfile> pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantProfiles.addAll(pageData.getData());
for (int i = 0; i < 28; i++) {
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile" + i);
tenantProfiles.add(tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile));
}
List<TenantProfile> loadedTenantProfiles = new ArrayList<>();
pageLink = new PageLink(17);
do {
pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink);
loadedTenantProfiles.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantProfiles, idComparator);
Collections.sort(loadedTenantProfiles, idComparator);
Assert.assertEquals(tenantProfiles, loadedTenantProfiles);
for (TenantProfile tenantProfile : loadedTenantProfiles) {
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile.getId());
}
pageLink = new PageLink(17);
pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
use of org.thingsboard.server.common.data.TenantProfile in project thingsboard by thingsboard.
the class BaseTenantProfileServiceTest method testFindDefaultTenantProfileInfo.
@Test
public void testFindDefaultTenantProfileInfo() {
TenantProfile tenantProfile = this.createTenantProfile("Default Tenant Profile");
tenantProfile.setDefault(true);
TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile);
EntityInfo foundDefaultTenantProfileInfo = tenantProfileService.findDefaultTenantProfileInfo(TenantId.SYS_TENANT_ID);
Assert.assertNotNull(foundDefaultTenantProfileInfo);
Assert.assertEquals(savedTenantProfile.getId(), foundDefaultTenantProfileInfo.getId());
Assert.assertEquals(savedTenantProfile.getName(), foundDefaultTenantProfileInfo.getName());
}
use of org.thingsboard.server.common.data.TenantProfile in project thingsboard by thingsboard.
the class BaseTenantProfileServiceTest method testFindTenantProfileInfos.
@Test
public void testFindTenantProfileInfos() {
List<TenantProfile> tenantProfiles = new ArrayList<>();
for (int i = 0; i < 28; i++) {
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile" + i);
tenantProfiles.add(tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile));
}
List<EntityInfo> loadedTenantProfileInfos = new ArrayList<>();
PageLink pageLink = new PageLink(17);
PageData<EntityInfo> pageData;
do {
pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink);
loadedTenantProfileInfos.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantProfiles, idComparator);
Collections.sort(loadedTenantProfileInfos, tenantProfileInfoIdComparator);
List<EntityInfo> tenantProfileInfos = tenantProfiles.stream().map(tenantProfile -> new EntityInfo(tenantProfile.getId(), tenantProfile.getName())).collect(Collectors.toList());
Assert.assertEquals(tenantProfileInfos, loadedTenantProfileInfos);
for (EntityInfo tenantProfile : loadedTenantProfileInfos) {
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, new TenantProfileId(tenantProfile.getId().getId()));
}
pageLink = new PageLink(17);
pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
Aggregations