Commit bf56d9e1a44093cfb6b4437f9cf0785b6e108875
1 parent
d6370ed6
Customer Controller API description
Showing
3 changed files
with
61 additions
and
19 deletions
@@ -166,13 +166,13 @@ public abstract class BaseController { | @@ -166,13 +166,13 @@ public abstract class BaseController { | ||
166 | protected final String PAGE_SIZE_DESCRIPTION = "Maximum amount of entities in a one page"; | 166 | protected final String PAGE_SIZE_DESCRIPTION = "Maximum amount of entities in a one page"; |
167 | protected final String PAGE_NUMBER_DESCRIPTION = "Sequence number of page starting from 0"; | 167 | protected final String PAGE_NUMBER_DESCRIPTION = "Sequence number of page starting from 0"; |
168 | protected final String DEVICE_TYPE_DESCRIPTION = "Device type as the name of the device profile"; | 168 | protected final String DEVICE_TYPE_DESCRIPTION = "Device type as the name of the device profile"; |
169 | - protected final String DEVICE_TEXT_SEARCH_DESCRIPTION = "The search is performed by device special field 'textSearch' represented by device name"; | 169 | + protected final String DEVICE_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the device name."; |
170 | + protected final String CUSTOMER_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the customer name."; | ||
170 | protected final String SORT_PROPERTY_DESCRIPTION = "Property of device to sort by"; | 171 | protected final String SORT_PROPERTY_DESCRIPTION = "Property of device to sort by"; |
171 | protected final String SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, name, label, type"; | 172 | protected final String SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, name, label, type"; |
172 | protected final String SORT_ORDER_DESCRIPTION = "Sort order. ASC (ASCENDING) or DESCENDING (DESC)"; | 173 | protected final String SORT_ORDER_DESCRIPTION = "Sort order. ASC (ASCENDING) or DESCENDING (DESC)"; |
173 | protected final String SORT_ORDER_ALLOWABLE_VALUES = "ASC, DESC"; | 174 | protected final String SORT_ORDER_ALLOWABLE_VALUES = "ASC, DESC"; |
174 | - protected final String DEVICE_INFO_DESCRIPTION = "Device Info is an object which are an extension of default Device object. " + | ||
175 | - "Apart from Device object, Device Info provides additional information such as customer name and device profile name. "; | 175 | + protected final String DEVICE_INFO_DESCRIPTION = "Device Info is an extension of the default Device object that contains information about the assigned customer name and device profile name. "; |
176 | 176 | ||
177 | 177 | ||
178 | 178 |
@@ -18,6 +18,8 @@ package org.thingsboard.server.controller; | @@ -18,6 +18,8 @@ package org.thingsboard.server.controller; | ||
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | +import io.swagger.annotations.ApiOperation; | ||
22 | +import io.swagger.annotations.ApiParam; | ||
21 | import org.springframework.http.HttpStatus; | 23 | import org.springframework.http.HttpStatus; |
22 | import org.springframework.security.access.prepost.PreAuthorize; | 24 | import org.springframework.security.access.prepost.PreAuthorize; |
23 | import org.springframework.web.bind.annotation.PathVariable; | 25 | import org.springframework.web.bind.annotation.PathVariable; |
@@ -52,16 +54,22 @@ public class CustomerController extends BaseController { | @@ -52,16 +54,22 @@ public class CustomerController extends BaseController { | ||
52 | 54 | ||
53 | public static final String CUSTOMER_ID = "customerId"; | 55 | public static final String CUSTOMER_ID = "customerId"; |
54 | public static final String IS_PUBLIC = "isPublic"; | 56 | public static final String IS_PUBLIC = "isPublic"; |
57 | + public static final String CUSTOMER_SECURITY_CHECK = "If the user has the authority of 'Tenant Administrator', the server checks that the customer is owned by the same tenant. " + | ||
58 | + "If the user has the authority of 'Customer User', the server checks that the user belongs to the customer."; | ||
55 | 59 | ||
60 | + @ApiOperation(value = "Get Customer (getCustomerById)", | ||
61 | + notes = "Get the Customer object based on the provided Customer Id. " + CUSTOMER_SECURITY_CHECK) | ||
56 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 62 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
57 | @RequestMapping(value = "/customer/{customerId}", method = RequestMethod.GET) | 63 | @RequestMapping(value = "/customer/{customerId}", method = RequestMethod.GET) |
58 | @ResponseBody | 64 | @ResponseBody |
59 | - public Customer getCustomerById(@PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | 65 | + public Customer getCustomerById( |
66 | + @ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION) | ||
67 | + @PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | ||
60 | checkParameter(CUSTOMER_ID, strCustomerId); | 68 | checkParameter(CUSTOMER_ID, strCustomerId); |
61 | try { | 69 | try { |
62 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); | 70 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); |
63 | Customer customer = checkCustomerId(customerId, Operation.READ); | 71 | Customer customer = checkCustomerId(customerId, Operation.READ); |
64 | - if(!customer.getAdditionalInfo().isNull()) { | 72 | + if (!customer.getAdditionalInfo().isNull()) { |
65 | processDashboardIdFromAdditionalInfo((ObjectNode) customer.getAdditionalInfo(), HOME_DASHBOARD); | 73 | processDashboardIdFromAdditionalInfo((ObjectNode) customer.getAdditionalInfo(), HOME_DASHBOARD); |
66 | } | 74 | } |
67 | return customer; | 75 | return customer; |
@@ -70,10 +78,15 @@ public class CustomerController extends BaseController { | @@ -70,10 +78,15 @@ public class CustomerController extends BaseController { | ||
70 | } | 78 | } |
71 | } | 79 | } |
72 | 80 | ||
81 | + | ||
82 | + @ApiOperation(value = "Get short Customer info (getShortCustomerInfoById)", | ||
83 | + notes = "Get the short customer object that contains only the title and 'isPublic' flag. " + CUSTOMER_SECURITY_CHECK) | ||
73 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 84 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
74 | @RequestMapping(value = "/customer/{customerId}/shortInfo", method = RequestMethod.GET) | 85 | @RequestMapping(value = "/customer/{customerId}/shortInfo", method = RequestMethod.GET) |
75 | @ResponseBody | 86 | @ResponseBody |
76 | - public JsonNode getShortCustomerInfoById(@PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | 87 | + public JsonNode getShortCustomerInfoById( |
88 | + @ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION) | ||
89 | + @PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | ||
77 | checkParameter(CUSTOMER_ID, strCustomerId); | 90 | checkParameter(CUSTOMER_ID, strCustomerId); |
78 | try { | 91 | try { |
79 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); | 92 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); |
@@ -88,10 +101,14 @@ public class CustomerController extends BaseController { | @@ -88,10 +101,14 @@ public class CustomerController extends BaseController { | ||
88 | } | 101 | } |
89 | } | 102 | } |
90 | 103 | ||
104 | + @ApiOperation(value = "Get Customer Title (getCustomerTitleById)", | ||
105 | + notes = "Get the title of the customer. " + CUSTOMER_SECURITY_CHECK) | ||
91 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 106 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
92 | @RequestMapping(value = "/customer/{customerId}/title", method = RequestMethod.GET, produces = "application/text") | 107 | @RequestMapping(value = "/customer/{customerId}/title", method = RequestMethod.GET, produces = "application/text") |
93 | @ResponseBody | 108 | @ResponseBody |
94 | - public String getCustomerTitleById(@PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | 109 | + public String getCustomerTitleById( |
110 | + @ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION) | ||
111 | + @PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | ||
95 | checkParameter(CUSTOMER_ID, strCustomerId); | 112 | checkParameter(CUSTOMER_ID, strCustomerId); |
96 | try { | 113 | try { |
97 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); | 114 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); |
@@ -102,10 +119,14 @@ public class CustomerController extends BaseController { | @@ -102,10 +119,14 @@ public class CustomerController extends BaseController { | ||
102 | } | 119 | } |
103 | } | 120 | } |
104 | 121 | ||
122 | + @ApiOperation(value = "Create or update Customer (saveCustomer)", | ||
123 | + notes = "Creates or Updates the Customer. Platform generates random Customer Id during device creation. " + | ||
124 | + "The Customer Id will be present in the response. Specify the Customer Id when you would like to update the Customer. " + | ||
125 | + "Referencing non-existing Customer Id will cause an error.") | ||
105 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") | 126 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |
106 | @RequestMapping(value = "/customer", method = RequestMethod.POST) | 127 | @RequestMapping(value = "/customer", method = RequestMethod.POST) |
107 | @ResponseBody | 128 | @ResponseBody |
108 | - public Customer saveCustomer(@RequestBody Customer customer) throws ThingsboardException { | 129 | + public Customer saveCustomer(@ApiParam(value = "A JSON value representing the customer.") @RequestBody Customer customer) throws ThingsboardException { |
109 | try { | 130 | try { |
110 | customer.setTenantId(getCurrentUser().getTenantId()); | 131 | customer.setTenantId(getCurrentUser().getTenantId()); |
111 | 132 | ||
@@ -131,10 +152,13 @@ public class CustomerController extends BaseController { | @@ -131,10 +152,13 @@ public class CustomerController extends BaseController { | ||
131 | } | 152 | } |
132 | } | 153 | } |
133 | 154 | ||
155 | + @ApiOperation(value = "Delete Customer (deleteCustomer)", | ||
156 | + notes = "Deletes the Customer and all customer Users. All assigned Dashboards, Assets, Devices, etc. will be unassigned but not deleted. Referencing non-existing Customer Id will cause an error.") | ||
134 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") | 157 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |
135 | @RequestMapping(value = "/customer/{customerId}", method = RequestMethod.DELETE) | 158 | @RequestMapping(value = "/customer/{customerId}", method = RequestMethod.DELETE) |
136 | @ResponseStatus(value = HttpStatus.OK) | 159 | @ResponseStatus(value = HttpStatus.OK) |
137 | - public void deleteCustomer(@PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | 160 | + public void deleteCustomer(@ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION) |
161 | + @PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException { | ||
138 | checkParameter(CUSTOMER_ID, strCustomerId); | 162 | checkParameter(CUSTOMER_ID, strCustomerId); |
139 | try { | 163 | try { |
140 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); | 164 | CustomerId customerId = new CustomerId(toUUID(strCustomerId)); |
@@ -161,14 +185,23 @@ public class CustomerController extends BaseController { | @@ -161,14 +185,23 @@ public class CustomerController extends BaseController { | ||
161 | } | 185 | } |
162 | } | 186 | } |
163 | 187 | ||
188 | + @ApiOperation(value = "Get Tenant Customers (getCustomers)", | ||
189 | + notes = "Returns a page of customers owned by tenant. " + | ||
190 | + PAGE_DATA_PARAMETERS) | ||
164 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") | 191 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |
165 | @RequestMapping(value = "/customers", params = {"pageSize", "page"}, method = RequestMethod.GET) | 192 | @RequestMapping(value = "/customers", params = {"pageSize", "page"}, method = RequestMethod.GET) |
166 | @ResponseBody | 193 | @ResponseBody |
167 | - public PageData<Customer> getCustomers(@RequestParam int pageSize, | ||
168 | - @RequestParam int page, | ||
169 | - @RequestParam(required = false) String textSearch, | ||
170 | - @RequestParam(required = false) String sortProperty, | ||
171 | - @RequestParam(required = false) String sortOrder) throws ThingsboardException { | 194 | + public PageData<Customer> getCustomers( |
195 | + @ApiParam(value = PAGE_SIZE_DESCRIPTION) | ||
196 | + @RequestParam int pageSize, | ||
197 | + @ApiParam(value = PAGE_NUMBER_DESCRIPTION) | ||
198 | + @RequestParam int page, | ||
199 | + @ApiParam(value = CUSTOMER_TEXT_SEARCH_DESCRIPTION) | ||
200 | + @RequestParam(required = false) String textSearch, | ||
201 | + @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES) | ||
202 | + @RequestParam(required = false) String sortProperty, | ||
203 | + @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES) | ||
204 | + @RequestParam(required = false) String sortOrder) throws ThingsboardException { | ||
172 | try { | 205 | try { |
173 | PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); | 206 | PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
174 | TenantId tenantId = getCurrentUser().getTenantId(); | 207 | TenantId tenantId = getCurrentUser().getTenantId(); |
@@ -178,10 +211,13 @@ public class CustomerController extends BaseController { | @@ -178,10 +211,13 @@ public class CustomerController extends BaseController { | ||
178 | } | 211 | } |
179 | } | 212 | } |
180 | 213 | ||
214 | + @ApiOperation(value = "Get Tenant Customer by Customer title (getTenantCustomer)", | ||
215 | + notes = "Get the Customer using Customer Title. Available for users with 'Tenant Administrator' authority only.") | ||
181 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") | 216 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |
182 | @RequestMapping(value = "/tenant/customers", params = {"customerTitle"}, method = RequestMethod.GET) | 217 | @RequestMapping(value = "/tenant/customers", params = {"customerTitle"}, method = RequestMethod.GET) |
183 | @ResponseBody | 218 | @ResponseBody |
184 | public Customer getTenantCustomer( | 219 | public Customer getTenantCustomer( |
220 | + @ApiParam(value = "A string value representing the Customer title.") | ||
185 | @RequestParam String customerTitle) throws ThingsboardException { | 221 | @RequestParam String customerTitle) throws ThingsboardException { |
186 | try { | 222 | try { |
187 | TenantId tenantId = getCurrentUser().getTenantId(); | 223 | TenantId tenantId = getCurrentUser().getTenantId(); |
@@ -101,7 +101,9 @@ public class DeviceController extends BaseController { | @@ -101,7 +101,9 @@ public class DeviceController extends BaseController { | ||
101 | private final DeviceBulkImportService deviceBulkImportService; | 101 | private final DeviceBulkImportService deviceBulkImportService; |
102 | 102 | ||
103 | @ApiOperation(value = "Get Device (getDeviceById)", | 103 | @ApiOperation(value = "Get Device (getDeviceById)", |
104 | - notes = "If device with given Id exists in the system it will be present in the response, otherwise an empty object will be provided") | 104 | + notes = "Fetch the Device object based on the provided Device Id. " + |
105 | + "If the user has the authority of 'Tenant Administrator', the server checks that the device is owned by the same tenant. " + | ||
106 | + "If the user has the authority of 'Customer User', the server checks that the device is assigned to the same customer.") | ||
105 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 107 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
106 | @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.GET) | 108 | @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.GET) |
107 | @ResponseBody | 109 | @ResponseBody |
@@ -116,7 +118,10 @@ public class DeviceController extends BaseController { | @@ -116,7 +118,10 @@ public class DeviceController extends BaseController { | ||
116 | } | 118 | } |
117 | } | 119 | } |
118 | 120 | ||
119 | - @ApiOperation(value = "Get Device Info (getDeviceInfoById)", notes = DEVICE_INFO_DESCRIPTION) | 121 | + @ApiOperation(value = "Get Device Info (getDeviceInfoById)", |
122 | + notes = "Fetch the Device Info object based on the provided Device Id. " + | ||
123 | + "If the user has the authority of 'Tenant Administrator', the server checks that the device is owned by the same tenant. " + | ||
124 | + "If the user has the authority of 'Customer User', the server checks that the device is assigned to the same customer. " + DEVICE_INFO_DESCRIPTION) | ||
120 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 125 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
121 | @RequestMapping(value = "/device/info/{deviceId}", method = RequestMethod.GET) | 126 | @RequestMapping(value = "/device/info/{deviceId}", method = RequestMethod.GET) |
122 | @ResponseBody | 127 | @ResponseBody |
@@ -131,7 +136,8 @@ public class DeviceController extends BaseController { | @@ -131,7 +136,8 @@ public class DeviceController extends BaseController { | ||
131 | } | 136 | } |
132 | } | 137 | } |
133 | 138 | ||
134 | - @ApiOperation(value = "Create Or Update Device (saveDevice)", notes = "Platform generates random device Id and credentials (access token) during device creation. " + | 139 | + @ApiOperation(value = "Create Or Update Device (saveDevice)", |
140 | + notes = "Creates or Updates the Device. Platform generates random device Id and credentials (access token) during device creation. " + | ||
135 | "The device id will be present in the response. " + | 141 | "The device id will be present in the response. " + |
136 | "Specify the device id when you would like to update the device. Referencing non-existing device Id will cause an error.") | 142 | "Specify the device id when you would like to update the device. Referencing non-existing device Id will cause an error.") |
137 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 143 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
@@ -177,7 +183,7 @@ public class DeviceController extends BaseController { | @@ -177,7 +183,7 @@ public class DeviceController extends BaseController { | ||
177 | } | 183 | } |
178 | 184 | ||
179 | @ApiOperation(value = "Delete device (deleteDevice)", | 185 | @ApiOperation(value = "Delete device (deleteDevice)", |
180 | - notes = "Referencing non-existing device Id will cause an error.") | 186 | + notes = "Deletes the device and it's credentials. Referencing non-existing device Id will cause an error.") |
181 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") | 187 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |
182 | @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.DELETE) | 188 | @RequestMapping(value = "/device/{deviceId}", method = RequestMethod.DELETE) |
183 | @ResponseStatus(value = HttpStatus.OK) | 189 | @ResponseStatus(value = HttpStatus.OK) |
@@ -361,7 +367,7 @@ public class DeviceController extends BaseController { | @@ -361,7 +367,7 @@ public class DeviceController extends BaseController { | ||
361 | } | 367 | } |
362 | } | 368 | } |
363 | 369 | ||
364 | - @ApiOperation(value = "Get Tenant Devices (getEdgeDevices)", | 370 | + @ApiOperation(value = "Get Tenant Devices (getTenantDevices)", |
365 | notes = "Returns a page of devices owned by tenant. " + | 371 | notes = "Returns a page of devices owned by tenant. " + |
366 | PAGE_DATA_PARAMETERS) | 372 | PAGE_DATA_PARAMETERS) |
367 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") | 373 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |