1717
1818package org .apache .dolphinscheduler .api .service .impl ;
1919
20- import com .baomidou .mybatisplus .core .metadata .IPage ;
21- import com .baomidou .mybatisplus .extension .plugins .pagination .Page ;
22- import com .fasterxml .jackson .databind .SerializationFeature ;
23- import com .google .common .base .Joiner ;
24- import com .google .common .io .Files ;
25- import org .apache .commons .beanutils .BeanMap ;
26- import org .apache .commons .collections .CollectionUtils ;
27- import org .apache .commons .lang3 .StringUtils ;
20+ import static org .apache .dolphinscheduler .common .Constants .ALIAS ;
21+ import static org .apache .dolphinscheduler .common .Constants .CONTENT ;
22+ import static org .apache .dolphinscheduler .common .Constants .EMPTY_STRING ;
23+ import static org .apache .dolphinscheduler .common .Constants .FOLDER_SEPARATOR ;
24+ import static org .apache .dolphinscheduler .common .Constants .FORMAT_SS ;
25+ import static org .apache .dolphinscheduler .common .Constants .FORMAT_S_S ;
26+ import static org .apache .dolphinscheduler .common .Constants .JAR ;
27+ import static org .apache .dolphinscheduler .common .Constants .PERIOD ;
28+
2829import org .apache .dolphinscheduler .api .constants .ApiFuncIdentificationConstant ;
2930import org .apache .dolphinscheduler .api .dto .resources .ResourceComponent ;
3031import org .apache .dolphinscheduler .api .dto .resources .filter .ResourceFilter ;
5657import org .apache .dolphinscheduler .dao .mapper .UdfFuncMapper ;
5758import org .apache .dolphinscheduler .dao .mapper .UserMapper ;
5859import org .apache .dolphinscheduler .dao .utils .ResourceProcessDefinitionUtils ;
59- import org .apache .dolphinscheduler .api .permission .ResourcePermissionCheckService ;
6060import org .apache .dolphinscheduler .spi .enums .ResourceType ;
61- import org .slf4j .Logger ;
62- import org .slf4j .LoggerFactory ;
63- import org .springframework .beans .factory .annotation .Autowired ;
64- import org .springframework .dao .DuplicateKeyException ;
65- import org .springframework .stereotype .Service ;
66- import org .springframework .transaction .annotation .Transactional ;
67- import org .springframework .web .multipart .MultipartFile ;
61+
62+ import org .apache .commons .beanutils .BeanMap ;
63+ import org .apache .commons .collections .CollectionUtils ;
64+ import org .apache .commons .lang3 .StringUtils ;
6865
6966import java .io .IOException ;
7067import java .rmi .ServerException ;
8380import java .util .regex .Matcher ;
8481import java .util .stream .Collectors ;
8582
86- import static org .apache .dolphinscheduler .common .Constants .ALIAS ;
87- import static org .apache .dolphinscheduler .common .Constants .CONTENT ;
88- import static org .apache .dolphinscheduler .common .Constants .EMPTY_STRING ;
89- import static org .apache .dolphinscheduler .common .Constants .FOLDER_SEPARATOR ;
90- import static org .apache .dolphinscheduler .common .Constants .FORMAT_SS ;
91- import static org .apache .dolphinscheduler .common .Constants .FORMAT_S_S ;
92- import static org .apache .dolphinscheduler .common .Constants .JAR ;
93- import static org .apache .dolphinscheduler .common .Constants .PERIOD ;
83+ import org .slf4j .Logger ;
84+ import org .slf4j .LoggerFactory ;
85+ import org .springframework .beans .factory .annotation .Autowired ;
86+ import org .springframework .dao .DuplicateKeyException ;
87+ import org .springframework .stereotype .Service ;
88+ import org .springframework .transaction .annotation .Transactional ;
89+ import org .springframework .web .multipart .MultipartFile ;
90+
91+ import com .baomidou .mybatisplus .core .metadata .IPage ;
92+ import com .baomidou .mybatisplus .extension .plugins .pagination .Page ;
93+ import com .fasterxml .jackson .databind .SerializationFeature ;
94+ import com .google .common .base .Joiner ;
95+ import com .google .common .io .Files ;
9496
9597/**
9698 * resources service impl
@@ -121,8 +123,6 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
121123 @ Autowired (required = false )
122124 private StorageOperate storageOperate ;
123125
124- @ Autowired
125- private ResourcePermissionCheckService resourcePermissionCheckService ;
126126
127127 /**
128128 * create directory
@@ -146,7 +146,7 @@ public Result<Object> createDirectory(User loginUser,
146146 Result <Object > result = new Result <>();
147147 String funcPermissionKey = type .equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FOLDER_ONLINE_CREATE : ApiFuncIdentificationConstant .UDF_FOLDER_ONLINE_CREATE ;
148148 boolean canOperatorPermissions = canOperatorPermissions (loginUser , null , AuthorizationType .RESOURCE_FILE_ID , funcPermissionKey );
149- if (!canOperatorPermissions ){
149+ if (!canOperatorPermissions ) {
150150 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
151151 return result ;
152152 }
@@ -227,7 +227,7 @@ public Result<Object> createResource(User loginUser,
227227 Result <Object > result = new Result <>();
228228 String funcPermissionKey = type .equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_UPLOAD : ApiFuncIdentificationConstant .UDF_UPLOAD ;
229229 boolean canOperatorPermissions = canOperatorPermissions (loginUser , null , AuthorizationType .RESOURCE_FILE_ID , funcPermissionKey );
230- if (!canOperatorPermissions ){
230+ if (!canOperatorPermissions ) {
231231 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
232232 return result ;
233233 }
@@ -355,7 +355,7 @@ public Result<Object> updateResource(User loginUser,
355355 Result <Object > result = new Result <>();
356356 String funcPermissionKey = type .equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_UPDATE : ApiFuncIdentificationConstant .UDF_UPDATE ;
357357 boolean canOperatorPermissions = canOperatorPermissions (loginUser , new Object []{resourceId }, checkResourceType (type ), funcPermissionKey );
358- if (!canOperatorPermissions ){
358+ if (!canOperatorPermissions ) {
359359 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
360360 return result ;
361361 }
@@ -364,14 +364,13 @@ public Result<Object> updateResource(User loginUser,
364364 return result ;
365365 }
366366
367-
368367 Resource resource = resourcesMapper .selectById (resourceId );
369368 if (resource == null ) {
370369 putMsg (result , Status .RESOURCE_NOT_EXIST );
371370 return result ;
372371 }
373372
374- if (!PropertyUtils .getResUploadStartupState ()){
373+ if (!PropertyUtils .getResUploadStartupState ()) {
375374 putMsg (result , Status .STORAGE_NOT_STARTUP );
376375 return result ;
377376 }
@@ -744,7 +743,7 @@ public Result<Object> queryResourceByProgramType(User loginUser, ResourceType ty
744743 Result <Object > result = new Result <>();
745744
746745 Set <Integer > resourceIds = resourcePermissionCheckService .userOwnedResourceIdsAcquisition (checkResourceType (type ), loginUser .getId (), logger );
747- if (resourceIds .isEmpty ()){
746+ if (resourceIds .isEmpty ()) {
748747 result .setData (Collections .emptyList ());
749748 putMsg (result , Status .SUCCESS );
750749 return result ;
@@ -790,7 +789,7 @@ public Result<Object> delete(User loginUser, int resourceId) throws IOException
790789 }
791790 String funcPermissionKey = resource .getType ().equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_DELETE : ApiFuncIdentificationConstant .UDF_DELETE ;
792791 boolean canOperatorPermissions = canOperatorPermissions (loginUser , new Object []{resourceId }, checkResourceType (resource .getType ()), funcPermissionKey );
793- if (!canOperatorPermissions ){
792+ if (!canOperatorPermissions ) {
794793 putMsg (resultCheck , Status .NO_CURRENT_OPERATING_PERMISSION );
795794 return resultCheck ;
796795 }
@@ -873,7 +872,7 @@ public Result<Object> verifyResourceName(String fullName, ResourceType type, Use
873872 Result <Object > result = new Result <>();
874873 String funcPermissionKey = type .equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_RENAME : ApiFuncIdentificationConstant .UDF_FILE_VIEW ;
875874 boolean canOperatorPermissions = canOperatorPermissions (loginUser , null , AuthorizationType .RESOURCE_FILE_ID , funcPermissionKey );
876- if (!canOperatorPermissions ){
875+ if (!canOperatorPermissions ) {
877876 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
878877 return result ;
879878 }
@@ -941,7 +940,7 @@ public Result<Object> queryResource(User loginUser, String fullName, Integer id,
941940 }
942941 String funcPermissionKey = type .equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_VIEW : ApiFuncIdentificationConstant .UDF_FILE_VIEW ;
943942 boolean canOperatorPermissions = canOperatorPermissions (loginUser , new Object []{resource .getId ()}, checkResourceType (type ), funcPermissionKey );
944- if (!canOperatorPermissions ){
943+ if (!canOperatorPermissions ) {
945944 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
946945 return result ;
947946 }
@@ -965,7 +964,7 @@ public Result<Object> queryResourceById(User loginUser, Integer id) {
965964 }
966965 String funcPermissionKey = resource .getType ().equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_VIEW : ApiFuncIdentificationConstant .UDF_FILE_VIEW ;
967966 boolean canOperatorPermissions = canOperatorPermissions (loginUser , new Object []{id }, checkResourceType (resource .getType ()), funcPermissionKey );
968- if (!canOperatorPermissions ){
967+ if (!canOperatorPermissions ) {
969968 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
970969 return result ;
971970 }
@@ -996,7 +995,7 @@ public Result<Object> readResource(User loginUser, int resourceId, int skipLineN
996995 }
997996 String funcPermissionKey = resource .getType ().equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_VIEW : ApiFuncIdentificationConstant .UDF_FILE_VIEW ;
998997 boolean canOperatorPermissions = canOperatorPermissions (loginUser , new Object []{resourceId }, checkResourceType (resource .getType ()), funcPermissionKey );
999- if (!canOperatorPermissions ){
998+ if (!canOperatorPermissions ) {
1000999 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
10011000 return result ;
10021001 }
@@ -1060,7 +1059,7 @@ public Result<Object> readResource(User loginUser, int resourceId, int skipLineN
10601059 public Result <Object > onlineCreateResource (User loginUser , ResourceType type , String fileName , String fileSuffix , String desc , String content , int pid , String currentDir ) {
10611060 Result <Object > result = new Result <>();
10621061 boolean canOperatorPermissions = canOperatorPermissions (loginUser , null , AuthorizationType .RESOURCE_FILE_ID , ApiFuncIdentificationConstant .FILE_ONLINE_CREATE );
1063- if (!canOperatorPermissions ){
1062+ if (!canOperatorPermissions ) {
10641063 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
10651064 return result ;
10661065 }
@@ -1274,7 +1273,7 @@ public Result<Object> updateResourceContent(User loginUser, int resourceId, Stri
12741273 }
12751274 String funcPermissionKey = resource .getType ().equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_UPDATE : ApiFuncIdentificationConstant .UDF_UPDATE ;
12761275 boolean canOperatorPermissions = canOperatorPermissions (loginUser , new Object []{resourceId }, checkResourceType (resource .getType ()), funcPermissionKey );
1277- if (!canOperatorPermissions ){
1276+ if (!canOperatorPermissions ) {
12781277 putMsg (result , Status .NO_CURRENT_OPERATING_PERMISSION );
12791278 return result ;
12801279 }
@@ -1333,7 +1332,6 @@ private Result<Object> uploadContentToStorage(User loginUser,String resourceName
13331332 String resourcePath = storageOperate .getResDir (tenantCode );
13341333 logger .info ("resource path is {}, resource dir is {}" , storageFileName , resourcePath );
13351334
1336-
13371335 if (!storageOperate .exists (tenantCode , resourcePath )) {
13381336 // create if tenant dir not exists
13391337 storageOperate .createTenantDirIfNotExists (tenantCode );
@@ -1376,7 +1374,7 @@ public org.springframework.core.io.Resource downloadResource(User loginUser, int
13761374
13771375 String funcPermissionKey = resource .getType ().equals (ResourceType .FILE ) ? ApiFuncIdentificationConstant .FILE_DOWNLOAD : ApiFuncIdentificationConstant .UDF_DOWNLOAD ;
13781376 boolean canOperatorPermissions = canOperatorPermissions (loginUser , new Object []{resourceId }, checkResourceType (resource .getType ()), funcPermissionKey );
1379- if (!canOperatorPermissions ){
1377+ if (!canOperatorPermissions ) {
13801378 logger .error ("{}: {}" , Status .NO_CURRENT_OPERATING_PERMISSION .getMsg (), PropertyUtils .getResUploadStartupState ());
13811379 throw new ServiceException (Status .NO_CURRENT_OPERATING_PERMISSION .getMsg ());
13821380 }
@@ -1424,7 +1422,7 @@ public org.springframework.core.io.Resource downloadResource(User loginUser, int
14241422 @ Override
14251423 public Map <String , Object > authorizeResourceTree (User loginUser , Integer userId ) {
14261424 Map <String , Object > result = new HashMap <>();
1427- if (!resourcePermissionCheckService .functionDisabled ()){
1425+ if (!resourcePermissionCheckService .functionDisabled ()) {
14281426 putMsg (result , Status .FUNCTION_DISABLED );
14291427 return result ;
14301428 }
@@ -1494,7 +1492,7 @@ public Map<String, Object> unauthorizedFile(User loginUser, Integer userId) {
14941492 @ Override
14951493 public Map <String , Object > unauthorizedUDFFunction (User loginUser , Integer userId ) {
14961494 Map <String , Object > result = new HashMap <>();
1497- if (!resourcePermissionCheckService .functionDisabled ()){
1495+ if (!resourcePermissionCheckService .functionDisabled ()) {
14981496 putMsg (result , Status .FUNCTION_DISABLED );
14991497 return result ;
15001498 }
@@ -1532,7 +1530,7 @@ public Map<String, Object> unauthorizedUDFFunction(User loginUser, Integer userI
15321530 @ Override
15331531 public Map <String , Object > authorizedUDFFunction (User loginUser , Integer userId ) {
15341532 Map <String , Object > result = new HashMap <>();
1535- if (!resourcePermissionCheckService .functionDisabled ()){
1533+ if (!resourcePermissionCheckService .functionDisabled ()) {
15361534 putMsg (result , Status .FUNCTION_DISABLED );
15371535 return result ;
15381536 }
@@ -1552,7 +1550,7 @@ public Map<String, Object> authorizedUDFFunction(User loginUser, Integer userId)
15521550 @ Override
15531551 public Map <String , Object > authorizedFile (User loginUser , Integer userId ) {
15541552 Map <String , Object > result = new HashMap <>();
1555- if (!resourcePermissionCheckService .functionDisabled ()){
1553+ if (!resourcePermissionCheckService .functionDisabled ()) {
15561554 putMsg (result , Status .FUNCTION_DISABLED );
15571555 return result ;
15581556 }
@@ -1648,7 +1646,7 @@ void listAllChildren(int resourceId, List<Integer> childList) {
16481646 */
16491647 private List <Resource > queryAuthoredResourceList (User loginUser , ResourceType type ) {
16501648 Set <Integer > resourceIds = resourcePermissionCheckService .userOwnedResourceIdsAcquisition (checkResourceType (type ), loginUser .getId (), logger );
1651- if (resourceIds .isEmpty ()){
1649+ if (resourceIds .isEmpty ()) {
16521650 return Collections .emptyList ();
16531651 }
16541652 List <Resource > resources = resourcesMapper .selectBatchIds (resourceIds );
0 commit comments