Search in sources :

Example 21 with TenantProfile

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);
    }
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 22 with TenantProfile

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());
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 23 with TenantProfile

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());
}
Also used : ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 24 with TenantProfile

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());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 25 with TenantProfile

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());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfileData(org.thingsboard.server.common.data.tenant.profile.TenantProfileData) Tenant(org.thingsboard.server.common.data.Tenant) Test(org.junit.Test) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) Collectors(java.util.stream.Collectors) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) List(java.util.List) TenantProfile(org.thingsboard.server.common.data.TenantProfile) After(org.junit.After) TenantProfileId(org.thingsboard.server.common.data.id.TenantProfileId) PageData(org.thingsboard.server.common.data.page.PageData) Assert(org.junit.Assert) Collections(java.util.Collections) EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfileId(org.thingsboard.server.common.data.id.TenantProfileId) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Aggregations

TenantProfile (org.thingsboard.server.common.data.TenantProfile)56 Test (org.junit.Test)33 Tenant (org.thingsboard.server.common.data.Tenant)10 DefaultTenantProfileConfiguration (org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)10 TenantId (org.thingsboard.server.common.data.id.TenantId)9 TenantProfileData (org.thingsboard.server.common.data.tenant.profile.TenantProfileData)9 ArrayList (java.util.ArrayList)8 EntityInfo (org.thingsboard.server.common.data.EntityInfo)7 List (java.util.List)6 TenantProfileId (org.thingsboard.server.common.data.id.TenantProfileId)6 ApiUsageState (org.thingsboard.server.common.data.ApiUsageState)5 EntityType (org.thingsboard.server.common.data.EntityType)5 Collections (java.util.Collections)4 Collectors (java.util.stream.Collectors)4 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)4 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)4 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)4 PageLink (org.thingsboard.server.common.data.page.PageLink)4 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)4 Map (java.util.Map)3