@ -23,7 +23,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.PostMapping ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.springframework.web.bind.annotation.RequestMethod ;
@ -41,26 +40,27 @@ import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink ;
import org.thingsboard.server.common.data.page.PageLink ;
import org.thingsboard.server.common.data.security.Authority ;
import org.thingsboard.server.common.data.security.Authority ;
import org.thingsboard.server.common.data.widget.DeprecatedFilter ;
import org.thingsboard.server.common.data.widget.DeprecatedFilter ;
import org.thingsboard.server.common.data.widget.WidgetExportData ;
import org.thingsboard.server.common.data.widget.WidgetType ;
import org.thingsboard.server.common.data.widget.WidgetType ;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails ;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails ;
import org.thingsboard.server.common.data.widget.WidgetTypeFilter ;
import org.thingsboard.server.common.data.widget.WidgetTypeFilter ;
import org.thingsboard.server.common.data.widget.WidgetTypeInfo ;
import org.thingsboard.server.common.data.widget.WidgetTypeInfo ;
import org.thingsboard.server.common.data.widget.WidgetsBundle ;
import org.thingsboard.server.common.data.widget.WidgetsBundle ;
import org.thingsboard.server.common.data.widget.WidgetsExportData ;
import org.thingsboard.server.config.annotations.ApiOperation ;
import org.thingsboard.server.config.annotations.ApiOperation ;
import org.thingsboard.server.dao.model.ModelConstants ;
import org.thingsboard.server.dao.model.ModelConstants ;
import org.thingsboard.server.queue.util.TbCoreComponent ;
import org.thingsboard.server.queue.util.TbCoreComponent ;
import org.thingsboard.server.service.entitiy.widgets.type.TbWidgetTypeService ;
import org.thingsboard.server.service.entitiy.widgets.type.TbWidgetTypeService ;
import org.thingsboard.server.service.resource.TbResourceService ;
import org.thingsboard.server.service.security.model.SecurityUser ;
import org.thingsboard.server.service.security.permission.Operation ;
import org.thingsboard.server.service.security.permission.Operation ;
import org.thingsboard.server.service.security.permission.Resource ;
import org.thingsboard.server.service.security.permission.Resource ;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.List ;
import java.util.List ;
import java.util.UUID ;
import static org.thingsboard.server.controller.ControllerConstants.AVAILABLE_FOR_ANY_AUTHORIZED_USER ;
import static org.thingsboard.server.controller.ControllerConstants.AVAILABLE_FOR_ANY_AUTHORIZED_USER ;
import static org.thingsboard.server.controller.ControllerConstants.INCLUDE_RESOURCES ;
import static org.thingsboard.server.controller.ControllerConstants.INCLUDE_RESOURCES_DESCRIPTION ;
import static org.thingsboard.server.controller.ControllerConstants.PAGE_DATA_PARAMETERS ;
import static org.thingsboard.server.controller.ControllerConstants.PAGE_DATA_PARAMETERS ;
import static org.thingsboard.server.controller.ControllerConstants.PAGE_NUMBER_DESCRIPTION ;
import static org.thingsboard.server.controller.ControllerConstants.PAGE_NUMBER_DESCRIPTION ;
import static org.thingsboard.server.controller.ControllerConstants.PAGE_SIZE_DESCRIPTION ;
import static org.thingsboard.server.controller.ControllerConstants.PAGE_SIZE_DESCRIPTION ;
@ -78,6 +78,7 @@ import static org.thingsboard.server.controller.ControllerConstants.WIDGET_TYPE_
public class WidgetTypeController extends AutoCommitController {
public class WidgetTypeController extends AutoCommitController {
private final TbWidgetTypeService tbWidgetTypeService ;
private final TbWidgetTypeService tbWidgetTypeService ;
private final TbResourceService tbResourceService ;
private static final String WIDGET_TYPE_DESCRIPTION = "Widget Type represents the template for widget creation. Widget Type and Widget are similar to class and object in OOP theory." ;
private static final String WIDGET_TYPE_DESCRIPTION = "Widget Type represents the template for widget creation. Widget Type and Widget are similar to class and object in OOP theory." ;
private static final String WIDGET_TYPE_DETAILS_DESCRIPTION = "Widget Type Details extend Widget Type and add image and description properties. " +
private static final String WIDGET_TYPE_DETAILS_DESCRIPTION = "Widget Type Details extend Widget Type and add image and description properties. " +
@ -95,18 +96,16 @@ public class WidgetTypeController extends AutoCommitController {
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
@GetMapping ( value = "/widgetType/{widgetTypeId}" )
@GetMapping ( value = "/widgetType/{widgetTypeId}" )
public WidgetTypeDetails getWidgetTypeById ( @Parameter ( description = WIDGET_TYPE_ID_PARAM_DESCRIPTION , required = true )
public WidgetTypeDetails getWidgetTypeById ( @Parameter ( description = WIDGET_TYPE_ID_PARAM_DESCRIPTION , required = true )
@PathVariable ( "widgetTypeId" ) String strWidgetTypeId ) throws ThingsboardException {
@PathVariable ( "widgetTypeId" ) String strWidgetTypeId ,
@Parameter ( description = INCLUDE_RESOURCES_DESCRIPTION )
@RequestParam ( value = INCLUDE_RESOURCES , required = false ) boolean includeResources ) throws ThingsboardException {
checkParameter ( "widgetTypeId" , strWidgetTypeId ) ;
checkParameter ( "widgetTypeId" , strWidgetTypeId ) ;
WidgetTypeId widgetTypeId = new WidgetTypeId ( toUUID ( strWidgetTypeId ) ) ;
WidgetTypeId widgetTypeId = new WidgetTypeId ( toUUID ( strWidgetTypeId ) ) ;
return checkWidgetTypeId ( widgetTypeId , Operation . READ ) ;
WidgetTypeDetails widgetTypeDetails = checkWidgetTypeId ( widgetTypeId , Operation . READ ) ;
}
if ( includeResources ) {
widgetTypeDetails . setResources ( tbResourceService . exportResources ( widgetTypeDetails , getCurrentUser ( ) ) ) ;
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
}
@GetMapping ( value = "/widgetType/{widgetTypeId}/export" )
return widgetTypeDetails ;
public WidgetExportData exportWidgetType ( @Parameter ( description = WIDGET_TYPE_ID_PARAM_DESCRIPTION , required = true )
@PathVariable ( "widgetTypeId" ) UUID widgetTypeId ) throws ThingsboardException {
WidgetTypeDetails widgetTypeDetails = checkWidgetTypeId ( new WidgetTypeId ( widgetTypeId ) , Operation . READ ) ;
return tbWidgetTypeService . exportWidgetType ( getTenantId ( ) , widgetTypeDetails , getCurrentUser ( ) ) ;
}
}
@ApiOperation ( value = "Get Widget Type Info (getWidgetTypeInfoById)" ,
@ApiOperation ( value = "Get Widget Type Info (getWidgetTypeInfoById)" ,
@ -151,15 +150,6 @@ public class WidgetTypeController extends AutoCommitController {
return tbWidgetTypeService . save ( widgetTypeDetails , updateExistingByFqn ! = null & & updateExistingByFqn , currentUser ) ;
return tbWidgetTypeService . save ( widgetTypeDetails , updateExistingByFqn ! = null & & updateExistingByFqn , currentUser ) ;
}
}
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
@PostMapping ( value = "/widgetType/import" )
public WidgetTypeDetails importWidgetType ( @RequestBody WidgetExportData exportData ) throws Exception {
WidgetTypeDetails widgetTypeDetails = exportData . getWidgetTypeDetails ( ) ;
widgetTypeDetails . setTenantId ( getTenantId ( ) ) ;
checkEntity ( widgetTypeDetails . getId ( ) , widgetTypeDetails , Resource . WIDGET_TYPE ) ;
return tbWidgetTypeService . importWidgetType ( exportData , getCurrentUser ( ) ) ;
}
@ApiOperation ( value = "Delete widget type (deleteWidgetType)" ,
@ApiOperation ( value = "Delete widget type (deleteWidgetType)" ,
notes = "Deletes the Widget Type. Referencing non-existing Widget Type Id will cause an error." + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH )
notes = "Deletes the Widget Type. Referencing non-existing Widget Type Id will cause an error." + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
@ -283,26 +273,19 @@ public class WidgetTypeController extends AutoCommitController {
@ResponseBody
@ResponseBody
public List < WidgetTypeDetails > getBundleWidgetTypesDetails (
public List < WidgetTypeDetails > getBundleWidgetTypesDetails (
@Parameter ( description = "Widget Bundle Id" , required = true )
@Parameter ( description = "Widget Bundle Id" , required = true )
@RequestParam ( "widgetsBundleId" ) String strWidgetsBundleId
@RequestParam ( "widgetsBundleId" ) String strWidgetsBundleId ,
@Parameter ( description = INCLUDE_RESOURCES_DESCRIPTION )
@RequestParam ( value = INCLUDE_RESOURCES , required = false ) boolean includeResources
) throws ThingsboardException {
) throws ThingsboardException {
SecurityUser user = getCurrentUser ( ) ;
WidgetsBundleId widgetsBundleId = new WidgetsBundleId ( toUUID ( strWidgetsBundleId ) ) ;
WidgetsBundleId widgetsBundleId = new WidgetsBundleId ( toUUID ( strWidgetsBundleId ) ) ;
return checkNotNull ( widgetTypeService . findWidgetTypesDetailsByWidgetsBundleId ( getTenantId ( ) , widgetsBundleId ) ) ;
List < WidgetTypeDetails > result = checkNotNull ( widgetTypeService . findWidgetTypesDetailsByWidgetsBundleId ( getTenantId ( ) , widgetsBundleId ) ) ;
}
if ( includeResources ) {
for ( WidgetTypeDetails widgetTypeDetails : result ) {
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
widgetTypeDetails . setResources ( tbResourceService . exportResources ( widgetTypeDetails , user ) ) ;
@GetMapping ( value = "/widgetTypes/export" , params = { "widgetsBundleId" } )
}
public WidgetsExportData exportBundleWidgetTypes ( @Parameter ( description = "Widget Bundle Id" , required = true )
}
@RequestParam ( "widgetsBundleId" ) String strWidgetsBundleId ) throws ThingsboardException {
return result ;
WidgetsBundleId widgetsBundleId = new WidgetsBundleId ( toUUID ( strWidgetsBundleId ) ) ;
return tbWidgetTypeService . exportBundleWidgetTypes ( getTenantId ( ) , widgetsBundleId , getCurrentUser ( ) ) ;
}
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')" )
@PostMapping ( value = "/widgetTypes/import" , params = { "widgetsBundleId" } )
public List < WidgetTypeDetails > importBundleWidgetTypes ( @Parameter ( description = "Widget Bundle Id" , required = true )
@RequestParam ( "widgetsBundleId" ) String strWidgetsBundleId ) throws ThingsboardException {
// FIXME: determine how bundle widget types were imported before
throw new UnsupportedOperationException ( ) ;
}
}
@ApiOperation ( value = "Get all Widget type fqns for specified Bundle (getBundleWidgetTypeFqns)" ,
@ApiOperation ( value = "Get all Widget type fqns for specified Bundle (getBundleWidgetTypeFqns)" ,