diff --git a/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java b/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java index 448e3e3fa3..c623ac5eb2 100644 --- a/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java @@ -209,6 +209,7 @@ public class WidgetTypeController extends AutoCommitController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @RequestMapping(value = "/widgetTypes", params = {"isSystem", "bundleAlias"}, method = RequestMethod.GET) @ResponseBody + @Deprecated public List getBundleWidgetTypesByBundleAlias( @ApiParam(value = "System or Tenant", required = true) @RequestParam boolean isSystem, @@ -241,6 +242,7 @@ public class WidgetTypeController extends AutoCommitController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") @RequestMapping(value = "/widgetTypesDetails", params = {"isSystem", "bundleAlias"}, method = RequestMethod.GET) @ResponseBody + @Deprecated public List getBundleWidgetTypesDetailsByBundleAlias( @ApiParam(value = "System or Tenant", required = true) @RequestParam boolean isSystem, @@ -256,7 +258,7 @@ public class WidgetTypeController extends AutoCommitController { return checkNotNull(widgetTypeService.findWidgetTypesDetailsByWidgetsBundleId(getTenantId(), widgetsBundle.getId())); } - @ApiOperation(value = "Get all Widget types details for specified Bundle (getBundleWidgetTypes)", + @ApiOperation(value = "Get all Widget types details for specified Bundle (getBundleWidgetTypesDetails)", notes = "Returns an array of Widget Type Details objects that belong to specified Widget Bundle." + WIDGET_TYPE_DETAILS_DESCRIPTION + " " + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH) @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @RequestMapping(value = "/widgetTypesDetails", params = {"widgetsBundleId"}, method = RequestMethod.GET) @@ -292,6 +294,7 @@ public class WidgetTypeController extends AutoCommitController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @RequestMapping(value = "/widgetTypesInfos", params = {"isSystem", "bundleAlias"}, method = RequestMethod.GET) @ResponseBody + @Deprecated public List getBundleWidgetTypesInfosByBundleAlias( @ApiParam(value = "System or Tenant", required = true) @RequestParam boolean isSystem, @@ -345,6 +348,7 @@ public class WidgetTypeController extends AutoCommitController { @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") @RequestMapping(value = "/widgetType", params = {"isSystem", "bundleAlias", "alias"}, method = RequestMethod.GET) @ResponseBody + @Deprecated public WidgetType getWidgetTypeByBundleAliasAndTypeAlias( @ApiParam(value = "System or Tenant", required = true) @RequestParam boolean isSystem, diff --git a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java index 1b861b41a1..d19726e2f1 100644 --- a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java +++ b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java @@ -29,6 +29,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.client.support.HttpRequestWrapper; +import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpClientErrorException; @@ -160,6 +161,7 @@ import org.thingsboard.server.common.data.sync.vc.VersionLoadResult; import org.thingsboard.server.common.data.sync.vc.VersionedEntityInfo; import org.thingsboard.server.common.data.sync.vc.request.create.VersionCreateRequest; import org.thingsboard.server.common.data.sync.vc.request.load.VersionLoadRequest; +import org.thingsboard.server.common.data.widget.DeprecatedFilter; import org.thingsboard.server.common.data.widget.WidgetType; import org.thingsboard.server.common.data.widget.WidgetTypeDetails; import org.thingsboard.server.common.data.widget.WidgetTypeInfo; @@ -2713,15 +2715,33 @@ public class RestClient implements Closeable { return restTemplate.postForEntity(baseURL + "/api/widgetsBundle", widgetsBundle, WidgetsBundle.class).getBody(); } + public void updateWidgetsBundleWidgetTypes(WidgetsBundleId widgetsBundleId, List widgetTypeIds) { + var httpEntity = new HttpEntity<>(widgetTypeIds.stream() + .map(widgetTypeId -> widgetTypeId.getId().toString()) + .collect(Collectors.toList())); + restTemplate.exchange(baseURL + "/api/widgetsBundle/{widgetsBundleId}/widgetTypes", + HttpMethod.POST, httpEntity, Void.class, widgetsBundleId.getId()); + } + + public void updateWidgetsBundleWidgetFqns(WidgetsBundleId widgetsBundleId, List widgetTypeFqns) { + restTemplate.exchange(baseURL + "/api/widgetsBundle/{widgetsBundleId}/widgetTypeFqns", + HttpMethod.POST, new HttpEntity<>(widgetTypeFqns), Void.class, widgetsBundleId.getId()); + } + public void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId) { restTemplate.delete(baseURL + "/api/widgetsBundle/{widgetsBundleId}", widgetsBundleId.getId()); } public PageData getWidgetsBundles(PageLink pageLink) { + return getWidgetsBundles(pageLink, null, null); + } + + public PageData getWidgetsBundles(PageLink pageLink, Boolean tenantOnly, Boolean fullSearch) { Map params = new HashMap<>(); addPageLinkToParam(params, pageLink); + addTenantOnlyAndFullSearchToParams(tenantOnly, fullSearch, params); return restTemplate.exchange( - baseURL + "/api/widgetsBundles?" + getUrlParams(pageLink), + baseURL + "/api/widgetsBundles?" + getUrlParams(pageLink) + getTenantOnlyAndFullSearchUrlParams(tenantOnly, fullSearch), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -2751,14 +2771,54 @@ public class RestClient implements Closeable { } } + public Optional getWidgetTypeInfoById(WidgetTypeId widgetTypeId) { + try { + ResponseEntity widgetTypeInfo = + restTemplate.getForEntity(baseURL + "/api/widgetTypeInfo/{widgetTypeId}", WidgetTypeInfo.class, widgetTypeId.getId()); + return Optional.ofNullable(widgetTypeInfo.getBody()); + } catch (HttpClientErrorException exception) { + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } + throw exception; + } + } + public WidgetTypeDetails saveWidgetType(WidgetTypeDetails widgetTypeDetails) { - return restTemplate.postForEntity(baseURL + "/api/widgetType", widgetTypeDetails, WidgetTypeDetails.class).getBody(); + return saveWidgetType(widgetTypeDetails, null); + } + + public WidgetTypeDetails saveWidgetType(WidgetTypeDetails widgetTypeDetails, Boolean updateExistingByFqn) { + if (updateExistingByFqn == null) { + return restTemplate.postForEntity(baseURL + "/api/widgetType", widgetTypeDetails, WidgetTypeDetails.class).getBody(); + } + return restTemplate.postForEntity(baseURL + "/api/widgetType?updateExistingByFqn={updateExistingByFqn}", widgetTypeDetails, WidgetTypeDetails.class, updateExistingByFqn).getBody(); } public void deleteWidgetType(WidgetTypeId widgetTypeId) { restTemplate.delete(baseURL + "/api/widgetType/{widgetTypeId}", widgetTypeId.getId()); } + public PageData getWidgetTypes(PageLink pageLink) { + return getWidgetTypes(pageLink, null, null, null, null); + } + + public PageData getWidgetTypes(PageLink pageLink, Boolean tenantOnly, Boolean fullSearch, + DeprecatedFilter deprecatedFilter, List widgetTypeList) { + Map params = new HashMap<>(); + addPageLinkToParam(params, pageLink); + addWidgetInfoFiltersToParams(tenantOnly, fullSearch, deprecatedFilter, widgetTypeList, params); + return restTemplate.exchange( + baseURL + "/api/widgetTypes?" + getUrlParams(pageLink) + + getWidgetTypeInfoPageRequestUrlParams(tenantOnly, fullSearch, deprecatedFilter, widgetTypeList), + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, + params).getBody(); + } + + @Deprecated // current name in the controller: getBundleWidgetTypesByBundleAlias public List getBundleWidgetTypes(boolean isSystem, String bundleAlias) { return restTemplate.exchange( baseURL + "/api/widgetTypes?isSystem={isSystem}&bundleAlias={bundleAlias}", @@ -2770,6 +2830,17 @@ public class RestClient implements Closeable { bundleAlias).getBody(); } + public List getBundleWidgetTypes(WidgetsBundleId widgetsBundleId) { + return restTemplate.exchange( + baseURL + "/api/widgetTypes?widgetsBundleId={widgetsBundleId}", + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, + widgetsBundleId.getId()).getBody(); + } + + @Deprecated // current name in the controller: getBundleWidgetTypesDetailsByBundleAlias public List getBundleWidgetTypesDetails(boolean isSystem, String bundleAlias) { return restTemplate.exchange( baseURL + "/api/widgetTypesDetails?isSystem={isSystem}&bundleAlias={bundleAlias}", @@ -2781,6 +2852,28 @@ public class RestClient implements Closeable { bundleAlias).getBody(); } + public List getBundleWidgetTypesDetails(WidgetsBundleId widgetsBundleId, boolean inlineImages) { + return restTemplate.exchange( + baseURL + "/api/widgetTypesDetails?widgetsBundleId={widgetsBundleId}&inlineImages={inlineImages}", + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, + widgetsBundleId.getId(), + inlineImages).getBody(); + } + + public List getBundleWidgetTypeFqns(WidgetsBundleId widgetsBundleId) { + return restTemplate.exchange( + baseURL + "/api/widgetTypeFqns?widgetsBundleId={widgetsBundleId}", + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, + widgetsBundleId.getId()).getBody(); + } + + @Deprecated // current name in the controller: getBundleWidgetTypesInfosByBundleAlias public List getBundleWidgetTypesInfos(boolean isSystem, String bundleAlias) { return restTemplate.exchange( baseURL + "/api/widgetTypesInfos?isSystem={isSystem}&bundleAlias={bundleAlias}", @@ -2792,6 +2885,28 @@ public class RestClient implements Closeable { bundleAlias).getBody(); } + public PageData getBundleWidgetTypesInfos(WidgetsBundleId widgetsBundleId, PageLink pageLink) { + return getBundleWidgetTypesInfos(widgetsBundleId, pageLink, null, null, null, null); + } + + public PageData getBundleWidgetTypesInfos(WidgetsBundleId widgetsBundleId, PageLink pageLink, + Boolean tenantOnly, Boolean fullSearch, + DeprecatedFilter deprecatedFilter, List widgetTypeList) { + Map params = new HashMap<>(); + params.put("widgetsBundleId", widgetsBundleId.getId().toString()); + addPageLinkToParam(params, pageLink); + addWidgetInfoFiltersToParams(tenantOnly, fullSearch, deprecatedFilter, widgetTypeList, params); + return restTemplate.exchange( + baseURL + "/api/widgetTypesInfos?widgetsBundleId={widgetsBundleId}&" + getUrlParams(pageLink) + + getWidgetTypeInfoPageRequestUrlParams(tenantOnly, fullSearch, deprecatedFilter, widgetTypeList), + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, + params).getBody(); + } + + @Deprecated // current name in the controller: getWidgetTypeByBundleAliasAndTypeAlias public Optional getWidgetType(boolean isSystem, String bundleAlias, String alias) { try { ResponseEntity widgetType = @@ -2811,6 +2926,22 @@ public class RestClient implements Closeable { } } + public Optional getWidgetType(String fqn) { + try { + ResponseEntity widgetType = + restTemplate.getForEntity( + baseURL + "/api/widgetType?fqn={fqn}", + WidgetType.class, + fqn); + return Optional.ofNullable(widgetType.getBody()); + } catch (HttpClientErrorException exception) { + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } + throw exception; + } + } + public Boolean isEdgesSupportEnabled() { return restTemplate.getForEntity(baseURL + "/api/edges/enabled", Boolean.class).getBody(); } @@ -3645,6 +3776,30 @@ public class RestClient implements Closeable { return urlParams; } + private String getWidgetTypeInfoPageRequestUrlParams(Boolean tenantOnly, Boolean fullSearch, + DeprecatedFilter deprecatedFilter, + List widgetTypeList) { + String urlParams = getTenantOnlyAndFullSearchUrlParams(tenantOnly, fullSearch); + if (deprecatedFilter != null) { + urlParams += "&deprecatedFilter={deprecatedFilter}"; + } + if (!CollectionUtils.isEmpty(widgetTypeList)) { + urlParams += "&widgetTypeList={widgetTypeList}"; + } + return urlParams; + } + + private String getTenantOnlyAndFullSearchUrlParams(Boolean tenantOnly, Boolean fullSearch) { + String urlParams = ""; + if (tenantOnly != null) { + urlParams = "&tenantOnly={tenantOnly}"; + } + if (fullSearch != null) { + urlParams += "&fullSearch={fullSearch}"; + } + return urlParams; + } + private void addTimePageLinkToParam(Map params, TimePageLink pageLink) { this.addPageLinkToParam(params, pageLink); if (pageLink.getStartTime() != null) { @@ -3667,6 +3822,26 @@ public class RestClient implements Closeable { } } + private void addWidgetInfoFiltersToParams(Boolean tenantOnly, Boolean fullSearch, DeprecatedFilter deprecatedFilter, + List widgetTypeList, Map params) { + addTenantOnlyAndFullSearchToParams(tenantOnly, fullSearch, params); + if (deprecatedFilter != null) { + params.put("deprecatedFilter", deprecatedFilter.name()); + } + if (!CollectionUtils.isEmpty(widgetTypeList)) { + params.put("widgetTypeList", listToString(widgetTypeList)); + } + } + + private void addTenantOnlyAndFullSearchToParams(Boolean tenantOnly, Boolean fullSearch, Map params) { + if (tenantOnly != null) { + params.put("tenantOnly", tenantOnly.toString()); + } + if (fullSearch != null) { + params.put("fullSearch", fullSearch.toString()); + } + } + private String listToString(List list) { return String.join(",", list); }