Search in sources :

Example 36 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseRuleServiceTest method findTenantRules.

@Test
public void findTenantRules() throws Exception {
    TenantId tenantIdA = new TenantId(UUIDs.timeBased());
    TenantId tenantIdB = new TenantId(UUIDs.timeBased());
    PluginMetaData pluginA = generatePlugin(tenantIdA, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    PluginMetaData pluginB = generatePlugin(tenantIdB, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(pluginA);
    pluginService.savePlugin(pluginB);
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(3, foundA.getData().size());
    TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 37 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseRuleServiceTest method deleteRulesByTenantId.

@Test
public void deleteRulesByTenantId() throws Exception {
    TenantId tenantIdA = new TenantId(UUIDs.timeBased());
    TenantId tenantIdB = new TenantId(UUIDs.timeBased());
    PluginMetaData pluginA = generatePlugin(tenantIdA, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    PluginMetaData pluginB = generatePlugin(tenantIdB, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(pluginA);
    pluginService.savePlugin(pluginB);
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(3, foundA.getData().size());
    TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
    ruleService.deleteRulesByTenantId(tenantIdA);
    foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(0, foundA.getData().size());
    foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 38 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseRuleServiceTest method findSystemRules.

@Test
public void findSystemRules() throws Exception {
    // system tenant id
    TenantId systemTenant = new TenantId(ModelConstants.NULL_UUID);
    PluginMetaData plugin = generatePlugin(systemTenant, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(plugin);
    ruleService.saveRule(generateRule(systemTenant, null, plugin.getApiToken()));
    ruleService.saveRule(generateRule(systemTenant, null, plugin.getApiToken()));
    ruleService.saveRule(generateRule(systemTenant, null, plugin.getApiToken()));
    TextPageData<RuleMetaData> found = ruleService.findSystemRules(new TextPageLink(100));
    Assert.assertEquals(3, found.getData().size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 39 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class CustomerController method getCustomers.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customers", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<Customer> getCustomers(@RequestParam int limit, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    try {
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        TenantId tenantId = getCurrentUser().getTenantId();
        return checkNotNull(customerService.findCustomersByTenantId(tenantId, pageLink));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 40 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class DeviceController method getCustomerDevices.

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/devices", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<Device> getCustomerDevices(@PathVariable("customerId") String strCustomerId, @RequestParam int limit, @RequestParam(required = false) String type, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        checkCustomerId(customerId);
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        if (type != null && type.trim().length() > 0) {
            return checkNotNull(deviceService.findDevicesByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink));
        } else {
            return checkNotNull(deviceService.findDevicesByTenantIdAndCustomerId(tenantId, customerId, pageLink));
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)93 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)58 TenantId (org.thingsboard.server.common.data.id.TenantId)37 TypeReference (com.fasterxml.jackson.core.type.TypeReference)27 Tenant (org.thingsboard.server.common.data.Tenant)24 CustomerId (org.thingsboard.server.common.data.id.CustomerId)19 Customer (org.thingsboard.server.common.data.Customer)18 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)18 UUID (java.util.UUID)15 Asset (org.thingsboard.server.common.data.asset.Asset)14 Matchers.containsString (org.hamcrest.Matchers.containsString)13 User (org.thingsboard.server.common.data.User)13 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)11 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)11 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)11 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)10 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)10 Device (org.thingsboard.server.common.data.Device)7