Search in sources :

Example 21 with CustomerId

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

the class JpaUserDaoTest method saveUser.

private void saveUser(UUID tenantId, UUID customerId) {
    User user = new User();
    UUID id = UUIDs.timeBased();
    user.setId(new UserId(id));
    user.setTenantId(new TenantId(tenantId));
    user.setCustomerId(new CustomerId(customerId));
    if (customerId == NULL_UUID) {
        user.setAuthority(Authority.TENANT_ADMIN);
    } else {
        user.setAuthority(Authority.CUSTOMER_USER);
    }
    String idString = id.toString();
    String email = idString.substring(0, idString.indexOf('-')) + "@thingsboard.org";
    user.setEmail(email);
    userDao.save(user);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) User(org.thingsboard.server.common.data.User) UserId(org.thingsboard.server.common.data.id.UserId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) UUID(java.util.UUID)

Example 22 with CustomerId

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

the class AuditLogController method getAuditLogsByCustomerId.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/audit/logs/customer/{customerId}", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<AuditLog> getAuditLogsByCustomerId(@PathVariable("customerId") String strCustomerId, @RequestParam int limit, @RequestParam(required = false) Long startTime, @RequestParam(required = false) Long endTime, @RequestParam(required = false, defaultValue = "false") boolean ascOrder, @RequestParam(required = false) String offset) throws ThingsboardException {
    try {
        checkParameter("CustomerId", strCustomerId);
        TenantId tenantId = getCurrentUser().getTenantId();
        TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
        return checkNotNull(auditLogService.findAuditLogsByTenantIdAndCustomerId(tenantId, new CustomerId(UUID.fromString(strCustomerId)), pageLink));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 23 with CustomerId

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

the class DashboardController method assignDashboardToCustomer.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.POST)
@ResponseBody
public Dashboard assignDashboardToCustomer(@PathVariable("customerId") String strCustomerId, @PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    checkParameter(DASHBOARD_ID, strDashboardId);
    try {
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        Customer customer = checkCustomerId(customerId);
        DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
        checkDashboardId(dashboardId);
        Dashboard savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));
        logEntityAction(dashboardId, savedDashboard, customerId, ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName());
        return savedDashboard;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DASHBOARD), null, null, ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId, strCustomerId);
        throw handleException(e);
    }
}
Also used : CustomerId(org.thingsboard.server.common.data.id.CustomerId) DashboardId(org.thingsboard.server.common.data.id.DashboardId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 24 with CustomerId

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

the class DashboardController method addDashboardCustomers.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/dashboard/{dashboardId}/customers/add", method = RequestMethod.POST)
@ResponseBody
public Dashboard addDashboardCustomers(@PathVariable(DASHBOARD_ID) String strDashboardId, @RequestBody String[] strCustomerIds) throws ThingsboardException {
    checkParameter(DASHBOARD_ID, strDashboardId);
    try {
        DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
        Dashboard dashboard = checkDashboardId(dashboardId);
        Set<CustomerId> customerIds = new HashSet<>();
        if (strCustomerIds != null) {
            for (String strCustomerId : strCustomerIds) {
                CustomerId customerId = new CustomerId(toUUID(strCustomerId));
                if (!dashboard.isAssignedToCustomer(customerId)) {
                    customerIds.add(customerId);
                }
            }
        }
        if (customerIds.isEmpty()) {
            return dashboard;
        } else {
            Dashboard savedDashboard = null;
            for (CustomerId customerId : customerIds) {
                savedDashboard = checkNotNull(dashboardService.assignDashboardToCustomer(dashboardId, customerId));
                ShortCustomerInfo customerInfo = savedDashboard.getAssignedCustomerInfo(customerId);
                logEntityAction(dashboardId, savedDashboard, customerId, ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
            }
            return savedDashboard;
        }
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DASHBOARD), null, null, ActionType.ASSIGNED_TO_CUSTOMER, e, strDashboardId);
        throw handleException(e);
    }
}
Also used : DashboardId(org.thingsboard.server.common.data.id.DashboardId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) HashSet(java.util.HashSet) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 25 with CustomerId

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

the class DashboardController method unassignDashboardFromCustomer.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/{customerId}/dashboard/{dashboardId}", method = RequestMethod.DELETE)
@ResponseBody
public Dashboard unassignDashboardFromCustomer(@PathVariable("customerId") String strCustomerId, @PathVariable(DASHBOARD_ID) String strDashboardId) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    checkParameter(DASHBOARD_ID, strDashboardId);
    try {
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        Customer customer = checkCustomerId(customerId);
        DashboardId dashboardId = new DashboardId(toUUID(strDashboardId));
        Dashboard dashboard = checkDashboardId(dashboardId);
        Dashboard savedDashboard = checkNotNull(dashboardService.unassignDashboardFromCustomer(dashboardId, customerId));
        logEntityAction(dashboardId, dashboard, customerId, ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customer.getId().toString(), customer.getName());
        return savedDashboard;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DASHBOARD), null, null, ActionType.UNASSIGNED_FROM_CUSTOMER, e, strDashboardId);
        throw handleException(e);
    }
}
Also used : CustomerId(org.thingsboard.server.common.data.id.CustomerId) DashboardId(org.thingsboard.server.common.data.id.DashboardId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

CustomerId (org.thingsboard.server.common.data.id.CustomerId)59 TenantId (org.thingsboard.server.common.data.id.TenantId)30 Customer (org.thingsboard.server.common.data.Customer)24 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)22 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)21 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)18 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)17 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)12 Asset (org.thingsboard.server.common.data.asset.Asset)11 User (org.thingsboard.server.common.data.User)10 TypeReference (com.fasterxml.jackson.core.type.TypeReference)9 UserId (org.thingsboard.server.common.data.id.UserId)9 Device (org.thingsboard.server.common.data.Device)8 Tenant (org.thingsboard.server.common.data.Tenant)7 DashboardId (org.thingsboard.server.common.data.id.DashboardId)6 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)6 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)6 List (java.util.List)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4