|
|
|
@ -113,6 +113,8 @@ import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityViewId; |
|
|
|
import org.thingsboard.server.common.data.id.MobileAppBundleId; |
|
|
|
import org.thingsboard.server.common.data.id.MobileAppId; |
|
|
|
import org.thingsboard.server.common.data.id.NotificationId; |
|
|
|
import org.thingsboard.server.common.data.id.NotificationRequestId; |
|
|
|
import org.thingsboard.server.common.data.id.OAuth2ClientId; |
|
|
|
import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationTemplateId; |
|
|
|
import org.thingsboard.server.common.data.id.OtaPackageId; |
|
|
|
@ -132,6 +134,13 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
|
|
import org.thingsboard.server.common.data.mobile.app.MobileApp; |
|
|
|
import org.thingsboard.server.common.data.mobile.bundle.MobileAppBundle; |
|
|
|
import org.thingsboard.server.common.data.mobile.bundle.MobileAppBundleInfo; |
|
|
|
import org.thingsboard.server.common.data.notification.Notification; |
|
|
|
import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; |
|
|
|
import org.thingsboard.server.common.data.notification.NotificationRequest; |
|
|
|
import org.thingsboard.server.common.data.notification.NotificationRequestInfo; |
|
|
|
import org.thingsboard.server.common.data.notification.NotificationRequestPreview; |
|
|
|
import org.thingsboard.server.common.data.notification.settings.NotificationSettings; |
|
|
|
import org.thingsboard.server.common.data.notification.settings.UserNotificationSettings; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2Client; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2ClientLoginInfo; |
|
|
|
@ -509,6 +518,99 @@ public class RestClient implements Closeable { |
|
|
|
params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<AlarmInfo> getAllAlarms(AlarmSearchStatus searchStatus, AlarmStatus status, TimePageLink pageLink, Boolean fetchOriginator) { |
|
|
|
String urlSecondPart = "/api/alarms?"; |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
if (fetchOriginator != null) { |
|
|
|
params.put("fetchOriginator", String.valueOf(fetchOriginator)); |
|
|
|
urlSecondPart += "&fetchOriginator={fetchOriginator}"; |
|
|
|
} |
|
|
|
if (searchStatus != null) { |
|
|
|
params.put("searchStatus", searchStatus.name()); |
|
|
|
urlSecondPart += "&searchStatus={searchStatus}"; |
|
|
|
} |
|
|
|
if (status != null) { |
|
|
|
params.put("status", status.name()); |
|
|
|
urlSecondPart += "&status={status}"; |
|
|
|
} |
|
|
|
|
|
|
|
addTimePageLinkToParam(params, pageLink); |
|
|
|
|
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + urlSecondPart + "&" + getTimeUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<AlarmInfo>>() { |
|
|
|
}, |
|
|
|
params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<AlarmInfo> getAlarmsV2(EntityId entityId, List<AlarmSearchStatus> statusList, List<AlarmSeverity> severityList, |
|
|
|
List<String> typeList, String assignedId, TimePageLink pageLink) { |
|
|
|
String urlSecondPart = "/api/v2/alarm/{entityType}/{entityId}?"; |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
if (!CollectionUtils.isEmpty(statusList)) { |
|
|
|
params.put("statusList", listEnumToString(statusList)); |
|
|
|
urlSecondPart += "&statusList={statusList}"; |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(severityList)) { |
|
|
|
params.put("severityList", listEnumToString(severityList)); |
|
|
|
urlSecondPart += "&severityList={severityList}"; |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(typeList)) { |
|
|
|
params.put("typeList", String.join(",", typeList)); |
|
|
|
urlSecondPart += "&typeList={typeList}"; |
|
|
|
} |
|
|
|
if (assignedId != null) { |
|
|
|
params.put("assignedId", assignedId); |
|
|
|
urlSecondPart += "&assignedId={assignedId}"; |
|
|
|
} |
|
|
|
|
|
|
|
addTimePageLinkToParam(params, pageLink); |
|
|
|
|
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + urlSecondPart + "&" + getTimeUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<AlarmInfo>>() { |
|
|
|
}, |
|
|
|
params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<AlarmInfo> getAllAlarmsV2(List<AlarmSearchStatus> statusList, List<AlarmSeverity> severityList, |
|
|
|
List<String> typeList, String assignedId, TimePageLink pageLink) { |
|
|
|
String urlSecondPart = "/api/v2/alarms?"; |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
if (!CollectionUtils.isEmpty(statusList)) { |
|
|
|
params.put("statusList", listEnumToString(statusList)); |
|
|
|
urlSecondPart += "&statusList={statusList}"; |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(severityList)) { |
|
|
|
params.put("severityList", listEnumToString(severityList)); |
|
|
|
urlSecondPart += "&severityList={severityList}"; |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(typeList)) { |
|
|
|
params.put("typeList", String.join(",", typeList)); |
|
|
|
urlSecondPart += "&typeList={typeList}"; |
|
|
|
} |
|
|
|
if (assignedId != null) { |
|
|
|
params.put("assignedId", assignedId); |
|
|
|
urlSecondPart += "&assignedId={assignedId}"; |
|
|
|
} |
|
|
|
|
|
|
|
addTimePageLinkToParam(params, pageLink); |
|
|
|
|
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + urlSecondPart + "&" + getTimeUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<AlarmInfo>>() { |
|
|
|
}, |
|
|
|
params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<AlarmSeverity> getHighestAlarmSeverity(EntityId entityId, AlarmSearchStatus searchStatus, AlarmStatus status) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
@ -1710,6 +1812,14 @@ public class RestClient implements Closeable { |
|
|
|
}).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public JsonNode findEntityTimeseriesAndAttributesKeysByQuery(EntityDataQuery query) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/entitiesQuery/find/keys", |
|
|
|
HttpMethod.POST, new HttpEntity<>(query), |
|
|
|
new ParameterizedTypeReference<JsonNode>() { |
|
|
|
}).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<AlarmData> findAlarmDataByQuery(AlarmDataQuery query) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/alarmsQuery/find", |
|
|
|
@ -2158,9 +2268,9 @@ public class RestClient implements Closeable { |
|
|
|
restTemplate.delete(baseURL + "/api/oauth2/client/{id}", oAuth2ClientId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<DomainInfo> getTenantDomainInfos() { |
|
|
|
public PageData<DomainInfo> getTenantDomainInfos(PageLink pageLink) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/domain/infos", |
|
|
|
baseURL + "/api/domain/infos?" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<DomainInfo>>() { |
|
|
|
@ -2192,9 +2302,9 @@ public class RestClient implements Closeable { |
|
|
|
restTemplate.postForLocation(baseURL + "/api/domain/{id}/oauth2Clients", oauth2ClientIds, domainId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<MobileApp> getTenantMobileApps() { |
|
|
|
public PageData<MobileApp> getTenantMobileApps(PageLink pageLink) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/mobile/app", |
|
|
|
baseURL + "/api/mobile/app?" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<MobileApp>>() { |
|
|
|
@ -2222,9 +2332,9 @@ public class RestClient implements Closeable { |
|
|
|
restTemplate.delete(baseURL + "/api/mobile/app/{id}", mobileAppId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<MobileAppBundleInfo> getTenantMobileBundleInfos() { |
|
|
|
public PageData<MobileAppBundleInfo> getTenantMobileBundleInfos(PageLink pageLink) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/mobile/bundle/infos", |
|
|
|
baseURL + "/api/mobile/bundle/infos?" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<MobileAppBundleInfo>>() { |
|
|
|
@ -2846,6 +2956,17 @@ public class RestClient implements Closeable { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<UserEmailInfo> getUsersByQuery(PageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/users/info?" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<UserEmailInfo>>() { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<User> getTenantAdmins(TenantId tenantId, PageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("tenantId", tenantId.getId().toString()); |
|
|
|
@ -4144,6 +4265,138 @@ public class RestClient implements Closeable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<Notification> getNotifications(PageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/notifications?" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<Notification>>() { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Integer getUnreadNotificationsCount(NotificationDeliveryMethod deliveryMethod) { |
|
|
|
String uri = "/api/notifications/unread/count?"; |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
if (deliveryMethod != null) { |
|
|
|
params.put("deliveryMethod", deliveryMethod.name()); |
|
|
|
uri += "&deliveryMethod={deliveryMethod}"; |
|
|
|
} |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + uri, |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
Integer.class, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public void markNotificationAsRead(NotificationId notificationId) { |
|
|
|
restTemplate.exchange( |
|
|
|
baseURL + "/api/notification/{id}/read", |
|
|
|
HttpMethod.PUT, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
Void.class, |
|
|
|
notificationId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public void markAllNotificationsAsRead(NotificationDeliveryMethod deliveryMethod) { |
|
|
|
String uri = "/api/notifications/read?"; |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
if (deliveryMethod != null) { |
|
|
|
params.put("deliveryMethod", deliveryMethod.name()); |
|
|
|
uri += "&deliveryMethod={deliveryMethod}"; |
|
|
|
} |
|
|
|
restTemplate.exchange( |
|
|
|
baseURL + uri, |
|
|
|
HttpMethod.PUT, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
Void.class); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void deleteNotification(NotificationId notificationId) { |
|
|
|
restTemplate.delete(baseURL + "/api/notification/{id}", notificationId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public NotificationRequest createNotificationRequest(NotificationRequest notificationRequest) { |
|
|
|
return restTemplate.postForEntity(baseURL + "/api/notification/request", notificationRequest, NotificationRequest.class).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public NotificationRequestPreview getNotificationRequestPreview(NotificationRequest notificationRequest, int recipientsPreviewSize) { |
|
|
|
return restTemplate.postForEntity(baseURL + "/api/notification/request/preview?recipientsPreviewSize={recipientsPreviewSize}", notificationRequest, NotificationRequestPreview.class, recipientsPreviewSize).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<NotificationRequestInfo> getNotificationRequestById(NotificationRequestId notificationRequestId) { |
|
|
|
try { |
|
|
|
ResponseEntity<NotificationRequestInfo> notificationRequest = restTemplate.getForEntity(baseURL + "/api/notification/request/{id}", NotificationRequestInfo.class, notificationRequestId.getId()); |
|
|
|
return Optional.ofNullable(notificationRequest.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public PageData<NotificationRequestInfo> getNotificationRequests(PageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/notification/requests?" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<PageData<NotificationRequestInfo>>() { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public void deleteNotificationRequest(NotificationRequestId notificationRequestId) { |
|
|
|
restTemplate.delete(baseURL + "/api/notification/request/{id}", notificationRequestId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public NotificationSettings saveNotificationSettings(NotificationSettings notificationSettings) { |
|
|
|
return restTemplate.postForEntity(baseURL + "/api/notification/settings", notificationSettings, NotificationSettings.class).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<NotificationSettings> getNotificationSettings() { |
|
|
|
try { |
|
|
|
ResponseEntity<NotificationSettings> notificationSettings = restTemplate.getForEntity(baseURL + "/api/notification/settings", NotificationSettings.class); |
|
|
|
return Optional.ofNullable(notificationSettings.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public List<NotificationDeliveryMethod> getAvailableDeliveryMethods() { |
|
|
|
return restTemplate.exchange(URI.create( |
|
|
|
baseURL + "/api/notification/deliveryMethods"), |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<List<NotificationDeliveryMethod>>() { |
|
|
|
}).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public UserNotificationSettings saveUserNotificationSettings(UserNotificationSettings userNotificationSettings) { |
|
|
|
return restTemplate.postForEntity(baseURL + "/api/notification/settings/user", userNotificationSettings, UserNotificationSettings.class).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<UserNotificationSettings> getUserNotificationSettings() { |
|
|
|
try { |
|
|
|
ResponseEntity<UserNotificationSettings> userNotificationSettings = restTemplate.getForEntity(baseURL + "/api/notification/settings/user", UserNotificationSettings.class); |
|
|
|
return Optional.ofNullable(userNotificationSettings.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String getTimeUrlParams(TimePageLink pageLink) { |
|
|
|
String urlParams = getUrlParams(pageLink); |
|
|
|
if (pageLink.getStartTime() != null) { |
|
|
|
|