From 4272405f0c8d29472c3f8255764a7e83476382ec Mon Sep 17 00:00:00 2001 From: xxxllluuu Date: Wed, 28 Oct 2020 18:02:30 +0800 Subject: [PATCH] https://github.com/edp963/davinci/issues/1965 https://github.com/edp963/davinci/issues/1954 1. fix them --- config/application.yml.example | 4 +- config/datasource_driver.yml.example | 2 +- .../main/java/edp/core/utils/DateUtils.java | 33 ++- .../controller/DashboardController.java | 8 +- .../davinci/controller/DisplayController.java | 9 +- .../davinci/controller/HomeController.java | 29 ++- .../davinci/controller/LoginController.java | 3 +- .../davinci/controller/ShareController.java | 14 +- .../davinci/controller/WidgetController.java | 9 +- .../edp/davinci/core/common/ErrorMsg.java | 2 +- .../core/config/RestExceptionHandler.java | 14 +- .../inteceptor/AuthenticationInterceptor.java | 4 +- .../inteceptor/PlatformAuthInterceptor.java | 4 +- .../java/edp/davinci/dao/CronJobMapper.java | 2 +- .../main/java/edp/davinci/dao/ViewMapper.java | 13 +- .../java/edp/davinci/dao/WidgetMapper.java | 18 +- .../dto/dashboardDto/DashboardWithMem.java | 6 +- .../davinci/dto/projectDto/ProjectDetail.java | 2 +- .../davinci/dto/shareDto/ShareDashboard.java | 5 +- .../davinci/dto/shareDto/ShareDisplay.java | 4 +- .../edp/davinci/dto/shareDto/ShareEntity.java | 11 +- .../edp/davinci/dto/shareDto/ShareView.java | 28 +++ .../edp/davinci/dto/shareDto/ShareWidget.java | 30 +++ .../shareDto/SimpleShareWidget.java} | 9 +- .../edp/davinci/dto/viewDto/SimpleView.java | 30 +++ .../edp/davinci/dto/viewDto/ViewBaseInfo.java | 1 - .../dto/viewDto/ViewWithProjectAndSource.java | 1 - .../runner/LoadSupportDataSourceRunner.java | 10 +- .../edp/davinci/schedule/SystemSchedule.java | 20 +- .../edp/davinci/service/DashboardService.java | 2 - .../edp/davinci/service/ShareService.java | 3 +- .../service/impl/BaseEntityService.java | 40 ++-- .../service/impl/BaseScheduleService.java | 91 ++++---- .../service/impl/DashboardServiceImpl.java | 63 +++--- .../service/impl/DisplayServiceImpl.java | 22 -- .../impl/EmailScheduleServiceImpl.java | 10 +- .../service/impl/ProjectServiceImpl.java | 18 +- .../service/impl/ShareServiceImpl.java | 207 ++++++++++++------ .../davinci/service/impl/ViewServiceImpl.java | 39 ++-- .../service/screenshot/ScreenshotUtil.java | 8 +- .../davinci/service/share/ShareFactor.java | 60 +++-- .../davinci/service/share/ShareResult.java | 1 + .../edp/davinci/service/share/ShareType.java | 19 +- .../service/share/aspect/ShareAuthAspect.java | 165 +++++++++----- server/src/main/resources/application.yml | 6 + .../resources/mybatis/mapper/ViewMapper.xml | 15 ++ 46 files changed, 672 insertions(+), 422 deletions(-) create mode 100644 server/src/main/java/edp/davinci/dto/shareDto/ShareView.java create mode 100644 server/src/main/java/edp/davinci/dto/shareDto/ShareWidget.java rename server/src/main/java/edp/davinci/{service/share/ShareWidget.java => dto/shareDto/SimpleShareWidget.java} (85%) create mode 100644 server/src/main/java/edp/davinci/dto/viewDto/SimpleView.java diff --git a/config/application.yml.example b/config/application.yml.example index d419ba502..c6c22c4f4 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -23,7 +23,7 @@ server: servlet: context-path: / - # Userd for mail and download services, can be empty, careful configuration + # Used for mail and download services, can be empty, careful configuration # By default, 'server.address' and 'server.port' is used as the string value. # access: # address: @@ -145,7 +145,7 @@ spring: username: password: base: - domainName: # domainName 指 企业邮箱后缀,如企业邮箱为:xxx@example.com, 这里值为 '@example.com' + domainName: # domainName 指 企业邮箱后缀,如企业邮箱为:xxx@example.com,这里值为 '@example.com' security: oauth2: diff --git a/config/datasource_driver.yml.example b/config/datasource_driver.yml.example index e8f49fb76..a0672e728 100644 --- a/config/datasource_driver.yml.example +++ b/config/datasource_driver.yml.example @@ -40,7 +40,7 @@ ## 2. add the corresponding dependency file (jar) in lib package, ## 3. restart your Davinci server ## In theory, all databases with jdbc drivers are supported, -## if you have problems during useing, please with contact us. +## if you have problems during using, please with contact us. ## Configuration is as follows: diff --git a/server/src/main/java/edp/core/utils/DateUtils.java b/server/src/main/java/edp/core/utils/DateUtils.java index 3d6b4be5a..37e305fb5 100644 --- a/server/src/main/java/edp/core/utils/DateUtils.java +++ b/server/src/main/java/edp/core/utils/DateUtils.java @@ -102,42 +102,42 @@ private static String prepare(String timeString) { } } - public static Date currentData() { + public static Date currentDate() { return new Date(); } public static long getNowMilliSecondTime() { - return currentData().getTime(); + return currentDate().getTime(); } public static String getNowDateYYYYMM() { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM"); - return formatter.format(currentData()); + return formatter.format(currentDate()); } public static String getNowDateYYYYMMDD() { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); - return formatter.format(currentData()); + return formatter.format(currentDate()); } - public static String getTheDayBeforNowDateYYYYMMDD() { + public static String getTheDayBeforeNowDateYYYYMMDD() { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); Calendar calendar = Calendar.getInstance(); - calendar.setTime(currentData()); + calendar.setTime(currentDate()); calendar.add(Calendar.DAY_OF_MONTH, -1); return formatter.format(calendar.getTime()); } - public static String getTheDayBeforAWeekYYYYMMDD() { + public static String getTheDayBeforeAWeekYYYYMMDD() { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); Calendar calendar = Calendar.getInstance(); - calendar.setTime(currentData()); + calendar.setTime(currentDate()); calendar.add(Calendar.DAY_OF_MONTH, -7); return formatter.format(calendar.getTime()); @@ -146,12 +146,12 @@ public static String getTheDayBeforAWeekYYYYMMDD() { public static String getNowDateFormatCustom(String format) { SimpleDateFormat formatter = new SimpleDateFormat(format); - return formatter.format(currentData()); + return formatter.format(currentDate()); } public static long getNowDaySecondTime0() { Calendar c = Calendar.getInstance(); - Date d = currentData(); + Date d = currentDate(); c.setTime(d); c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 0, 0, 0); @@ -340,4 +340,17 @@ public static String dateFormat(Date date, String dateFormat) { return ""; } + public static Date add(Date date, int field, int amount) { + + if (date == null) { + date = new Date(); + } + + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(field, amount); + + return cal.getTime(); + } + } diff --git a/server/src/main/java/edp/davinci/controller/DashboardController.java b/server/src/main/java/edp/davinci/controller/DashboardController.java index dc50efc67..63558d787 100644 --- a/server/src/main/java/edp/davinci/controller/DashboardController.java +++ b/server/src/main/java/edp/davinci/controller/DashboardController.java @@ -500,10 +500,16 @@ public ResponseEntity deleteMemDashboardWidget(@PathVariable Long relationId, @ApiOperation(value = "share dashboard", consumes = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/dashboards/{dashboardId}/share", consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity shareDashboard(@PathVariable Long dashboardId, - @RequestBody ShareEntity shareEntity, + @Valid @RequestBody ShareEntity shareEntity, + @ApiIgnore BindingResult bindingResult, @ApiIgnore @CurrentUser User user, HttpServletRequest request) { + if (bindingResult.hasErrors()) { + ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message(bindingResult.getFieldErrors().get(0).getDefaultMessage()); + return ResponseEntity.status(resultMap.getCode()).body(resultMap); + } + if (invalidId(dashboardId)) { ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid id"); return ResponseEntity.status(resultMap.getCode()).body(resultMap); diff --git a/server/src/main/java/edp/davinci/controller/DisplayController.java b/server/src/main/java/edp/davinci/controller/DisplayController.java index f11682505..99fc3fe90 100644 --- a/server/src/main/java/edp/davinci/controller/DisplayController.java +++ b/server/src/main/java/edp/davinci/controller/DisplayController.java @@ -611,9 +611,16 @@ public ResponseEntity uploadSlideSubWidgetBGImage(@PathVariable Long relationId, @ApiOperation(value = "share display", consumes = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/{id}/share", consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity shareDisplay(@PathVariable Long id, - @RequestBody ShareEntity shareEntity, + @Valid @RequestBody ShareEntity shareEntity, + @ApiIgnore BindingResult bindingResult, @ApiIgnore @CurrentUser User user, HttpServletRequest request) { + + if (bindingResult.hasErrors()) { + ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message(bindingResult.getFieldErrors().get(0).getDefaultMessage()); + return ResponseEntity.status(resultMap.getCode()).body(resultMap); + } + if (invalidId(id)) { ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid id"); return ResponseEntity.status(resultMap.getCode()).body(resultMap); diff --git a/server/src/main/java/edp/davinci/controller/HomeController.java b/server/src/main/java/edp/davinci/controller/HomeController.java index 63a1db915..af84da898 100644 --- a/server/src/main/java/edp/davinci/controller/HomeController.java +++ b/server/src/main/java/edp/davinci/controller/HomeController.java @@ -21,18 +21,22 @@ import edp.core.annotation.AuthIgnore; import edp.davinci.core.common.Constants; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import springfox.documentation.annotations.ApiIgnore; +import java.util.HashMap; +import java.util.Map; + @ApiIgnore @Controller public class HomeController { - @Value("${davinci.version:}") - private String version; + @Autowired + private Environment environment; @RequestMapping("swagger") public String swagger() { @@ -49,10 +53,23 @@ public String shareIndex() { return "share"; } - @RequestMapping(Constants.BASE_API_PATH + "/version") + @RequestMapping(Constants.BASE_API_PATH + "/configurations") @AuthIgnore @ResponseBody - public String version() { - return version; + public Map configurations() { + Map configs = new HashMap<>(); + configs.put("version", environment.getProperty("davinci.version")); + configs.put("jwtToken", new HashMap() {{ + put("timeout", environment.getProperty("jwtToken.timeout")); + }}); + configs.put("security", new HashMap() {{ + put("oauth2", new HashMap() {{ + put("enable", Boolean.valueOf(environment.getProperty("security.oauth2.enable"))); + }}); + }}); + + return new HashMap() {{ + put("payload", configs); + }}; } } diff --git a/server/src/main/java/edp/davinci/controller/LoginController.java b/server/src/main/java/edp/davinci/controller/LoginController.java index 5b6febe17..d65d7e7fa 100644 --- a/server/src/main/java/edp/davinci/controller/LoginController.java +++ b/server/src/main/java/edp/davinci/controller/LoginController.java @@ -48,7 +48,6 @@ import javax.validation.Valid; import java.security.Principal; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -106,7 +105,7 @@ public ResponseEntity login(@Valid @RequestBody UserLogin userLogin, @ApiIgnore return ResponseEntity.ok(new ResultMap().success(tokenUtils.generateToken(user)).payload(userLoginResult)); } - @ApiOperation(value = "get oauth2 clents") + @ApiOperation(value = "get oauth2 clients") @GetMapping(value = "getOauth2Clients", consumes = MediaType.ALL_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @AuthIgnore public ResponseEntity getOauth2Clients(HttpServletRequest request) { diff --git a/server/src/main/java/edp/davinci/controller/ShareController.java b/server/src/main/java/edp/davinci/controller/ShareController.java index 82e1f9374..5f05d6a6a 100644 --- a/server/src/main/java/edp/davinci/controller/ShareController.java +++ b/server/src/main/java/edp/davinci/controller/ShareController.java @@ -27,6 +27,7 @@ import edp.davinci.core.common.ResultMap; import edp.davinci.dto.shareDto.ShareDashboard; import edp.davinci.dto.shareDto.ShareDisplay; +import edp.davinci.dto.shareDto.ShareWidget; import edp.davinci.dto.userDto.UserLogin; import edp.davinci.dto.userDto.UserLoginResult; import edp.davinci.dto.viewDto.DistinctParam; @@ -35,7 +36,6 @@ import edp.davinci.service.ShareService; import edp.davinci.service.share.ShareOperation; import edp.davinci.service.share.ShareType; -import edp.davinci.service.share.ShareWidget; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -79,7 +79,6 @@ public ResponseEntity preFlight(@PathVariable String token) { @GetMapping(value = "/permissions/{token}") public ResponseEntity permission(@PathVariable(name = "token") String token, @RequestParam(required = false) String password, - @RequestParam String type, @ApiIgnore @CurrentUser User user, HttpServletRequest request) { @@ -215,10 +214,9 @@ public ResponseEntity getShareData(@PathVariable String token, /** - * share 获取唯一值 + * share获取控制器的值 * * @param token - * @param viewId * @param param * @param bindingResult * @param user @@ -226,17 +224,15 @@ public ResponseEntity getShareData(@PathVariable String token, * @return */ @ApiOperation(value = "get share data") - @AuthShare(type = ShareType.DATA, operation = ShareOperation.LOAD_DATA) - @PostMapping(value = "/data/{token}/distinctvalue/{viewId}", consumes = MediaType.APPLICATION_JSON_VALUE) + @AuthShare(type = ShareType.DATA, operation = ShareOperation.LOAD_DISTINCT_DATA) + @PostMapping(value = "/data/{token}/distinctvalue", consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getDistinctValue(@PathVariable("token") String token, - @RequestParam(required = false) String password, - @PathVariable("viewId") Long viewId, @Valid @RequestBody DistinctParam param, @ApiIgnore BindingResult bindingResult, @ApiIgnore @CurrentUser User user, HttpServletRequest request) { - List> resultList = shareService.getDistinctValue(viewId, param, user); + List> resultList = shareService.getDistinctValue(param, user); if (null == user || user.getId() == null) { return ResponseEntity.ok(new ResultMap().success().payloads(resultList)); } else { diff --git a/server/src/main/java/edp/davinci/controller/WidgetController.java b/server/src/main/java/edp/davinci/controller/WidgetController.java index 3d1ffdb3e..84fc9117f 100644 --- a/server/src/main/java/edp/davinci/controller/WidgetController.java +++ b/server/src/main/java/edp/davinci/controller/WidgetController.java @@ -228,9 +228,16 @@ public ResponseEntity downloadWidget(@PathVariable("id") Long id, @ApiOperation(value = "share widget", consumes = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/{id}/share", consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity shareWidget(@PathVariable Long id, - @RequestBody ShareEntity shareEntity, + @Valid @RequestBody ShareEntity shareEntity, + @ApiIgnore BindingResult bindingResult, @ApiIgnore @CurrentUser User user, HttpServletRequest request) { + + if (bindingResult.hasErrors()) { + ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message(bindingResult.getFieldErrors().get(0).getDefaultMessage()); + return ResponseEntity.status(resultMap.getCode()).body(resultMap); + } + if (invalidId(id)) { ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid id"); return ResponseEntity.status(resultMap.getCode()).body(resultMap); diff --git a/server/src/main/java/edp/davinci/core/common/ErrorMsg.java b/server/src/main/java/edp/davinci/core/common/ErrorMsg.java index ab8ca9ad7..8a2682778 100644 --- a/server/src/main/java/edp/davinci/core/common/ErrorMsg.java +++ b/server/src/main/java/edp/davinci/core/common/ErrorMsg.java @@ -21,7 +21,7 @@ public final class ErrorMsg { public static final String ERR_MSG_AUTHENTICATION = "The resource requires authentication, which was not supplied with the request"; - public static final String ERR_MSG_PERMISSION = "ERROR Permission denied"; + public static final String ERR_MSG_PERMISSION = "Error Permission denied"; public static final String ERR_INVALID_TOKEN = "Invalid share token"; diff --git a/server/src/main/java/edp/davinci/core/config/RestExceptionHandler.java b/server/src/main/java/edp/davinci/core/config/RestExceptionHandler.java index c073bf641..6586ee5d6 100644 --- a/server/src/main/java/edp/davinci/core/config/RestExceptionHandler.java +++ b/server/src/main/java/edp/davinci/core/config/RestExceptionHandler.java @@ -45,8 +45,7 @@ public class RestExceptionHandler { @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) private ResultMap commonExceptionHandler(HttpServletRequest request, Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); + log.error(e.toString(), e); return new ResultMap(tokenUtils).failAndRefreshToken(request).message(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()); } @@ -54,8 +53,7 @@ private ResultMap commonExceptionHandler(HttpServletRequest request, Exception e @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) private ResultMap serverExceptionHandler(HttpServletRequest request, Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); + log.error(e.toString(), e); return new ResultMap(tokenUtils).failAndRefreshToken(request).message(e.getMessage()); } @@ -63,7 +61,7 @@ private ResultMap serverExceptionHandler(HttpServletRequest request, Exception e @ResponseBody @ResponseStatus(HttpStatus.FORBIDDEN) private ResultMap forbiddenExceptionHandler(HttpServletRequest request, Exception e) { - log.error(e.getMessage()); + log.error(e.toString(), e); return new ResultMap(tokenUtils).failAndRefreshToken(request, HttpCodeEnum.FORBIDDEN).message(e.getMessage()); } @@ -71,7 +69,7 @@ private ResultMap forbiddenExceptionHandler(HttpServletRequest request, Exceptio @ResponseBody @ResponseStatus(HttpStatus.UNAUTHORIZED) private ResultMap unAuthorizedExceptionHandler(HttpServletRequest request, Exception e) { - log.error(e.getMessage()); + log.error(e.toString(), e); return new ResultMap(tokenUtils).failAndRefreshToken(request, HttpCodeEnum.UNAUTHORIZED).message(e.getMessage()); } @@ -79,7 +77,7 @@ private ResultMap unAuthorizedExceptionHandler(HttpServletRequest request, Excep @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) private ResultMap notFoundExceptionHandler(HttpServletRequest request, Exception e) { - log.error(e.getMessage()); + log.error(e.toString(), e); return new ResultMap(tokenUtils).failAndRefreshToken(request, HttpCodeEnum.NOT_FOUND).message(e.getMessage()); } @@ -87,7 +85,7 @@ private ResultMap notFoundExceptionHandler(HttpServletRequest request, Exception @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) private ResultMap methodArgumentNotValidExceptionHandler(HttpServletRequest request, Exception e) { - log.error(e.getMessage()); + log.error(e.toString(), e); return new ResultMap(tokenUtils).failAndRefreshToken(request, HttpCodeEnum.FAIL).message(e.getMessage()); } diff --git a/server/src/main/java/edp/davinci/core/inteceptor/AuthenticationInterceptor.java b/server/src/main/java/edp/davinci/core/inteceptor/AuthenticationInterceptor.java index b626eb677..bd5762027 100644 --- a/server/src/main/java/edp/davinci/core/inteceptor/AuthenticationInterceptor.java +++ b/server/src/main/java/edp/davinci/core/inteceptor/AuthenticationInterceptor.java @@ -70,8 +70,8 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons String token = request.getHeader(Constants.TOKEN_HEADER_STRING); - AuthShare authShareMethoed = method.getAnnotation(AuthShare.class); - if (null != authShareMethoed) { + AuthShare authShareMethod = method.getAnnotation(AuthShare.class); + if (null != authShareMethod) { if (!StringUtils.isEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) { String username = tokenUtils.getUsername(token); User user = userService.getByUsername(username); diff --git a/server/src/main/java/edp/davinci/core/inteceptor/PlatformAuthInterceptor.java b/server/src/main/java/edp/davinci/core/inteceptor/PlatformAuthInterceptor.java index 2cfbc635a..68b5f907b 100644 --- a/server/src/main/java/edp/davinci/core/inteceptor/PlatformAuthInterceptor.java +++ b/server/src/main/java/edp/davinci/core/inteceptor/PlatformAuthInterceptor.java @@ -118,8 +118,8 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons User user = null; - AuthShare authShareMethoed = method.getAnnotation(AuthShare.class); - if (null != authShareMethoed) { + AuthShare authShareMethod = method.getAnnotation(AuthShare.class); + if (null != authShareMethod) { String token = request.getHeader(Constants.TOKEN_HEADER_STRING); if (!StringUtils.isEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) { String username = tokenUtils.getUsername(token); diff --git a/server/src/main/java/edp/davinci/dao/CronJobMapper.java b/server/src/main/java/edp/davinci/dao/CronJobMapper.java index 159e7f421..70b95b489 100644 --- a/server/src/main/java/edp/davinci/dao/CronJobMapper.java +++ b/server/src/main/java/edp/davinci/dao/CronJobMapper.java @@ -42,7 +42,7 @@ public interface CronJobMapper { @Select({"select * from cron_job where job_status in ('stopped','failed') and update_time > (NOW() - INTERVAL 3 MINUTE)"}) - List getStopedJob(); + List getStoppedJob(); @Update({ "update cron_job", diff --git a/server/src/main/java/edp/davinci/dao/ViewMapper.java b/server/src/main/java/edp/davinci/dao/ViewMapper.java index 4765b183e..bd8ce44d8 100644 --- a/server/src/main/java/edp/davinci/dao/ViewMapper.java +++ b/server/src/main/java/edp/davinci/dao/ViewMapper.java @@ -19,10 +19,7 @@ package edp.davinci.dao; -import edp.davinci.dto.viewDto.ViewBaseInfo; -import edp.davinci.dto.viewDto.ViewWithProjectAndSource; -import edp.davinci.dto.viewDto.ViewWithSource; -import edp.davinci.dto.viewDto.ViewWithSourceBaseInfo; +import edp.davinci.dto.viewDto.*; import edp.davinci.model.View; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Param; @@ -51,6 +48,9 @@ public interface ViewMapper { @Select({"select * from `view` where id = #{id}"}) View getById(Long id); + @Select({"select id, name, model, variable from `view` where id = #{id}"}) + SimpleView getSimpleViewById(Long id); + @Update({ "update `view`", "set `name` = #{name,jdbcType=VARCHAR},", @@ -89,7 +89,7 @@ public interface ViewMapper { int insertBatch(@Param("list") List sourceList); @Delete({"delete from `view` where project_id = #{projectId}"}) - int deleteByPorject(@Param("projectId") Long projectId); + int deleteByProject(@Param("projectId") Long projectId); @Select({ "SELECT ", @@ -103,10 +103,11 @@ public interface ViewMapper { "FROM `view` v", " LEFT JOIN project p on p.id = v.project_id", " LEFT JOIN source s on s.id = v.source_id", - "WHERE v.id = #{id}", + "WHERE v.id = #{id}" }) ViewWithSource getViewWithSource(Long id); Set selectByWidgetIds(@Param("widgetIds") Set widgetIds); + Set selectSimpleByWidgetIds(@Param("widgetIds") Set widgetIds); } \ No newline at end of file diff --git a/server/src/main/java/edp/davinci/dao/WidgetMapper.java b/server/src/main/java/edp/davinci/dao/WidgetMapper.java index 91d35f0af..324d778b7 100644 --- a/server/src/main/java/edp/davinci/dao/WidgetMapper.java +++ b/server/src/main/java/edp/davinci/dao/WidgetMapper.java @@ -19,7 +19,7 @@ package edp.davinci.dao; -import edp.davinci.service.share.ShareWidget; +import edp.davinci.dto.shareDto.SimpleShareWidget; import edp.davinci.dto.widgetDto.WidgetWithRelationDashboardId; import edp.davinci.dto.widgetDto.WidgetWithVizId; import edp.davinci.model.Widget; @@ -42,8 +42,8 @@ public interface WidgetMapper { @Select({"select * from widget where id = #{id}"}) Widget getById(@Param("id") Long id); - @Select({"select w.*,v.model from widget w LEFT JOIN `view` v on v.id = w.view_id where w.id = #{id}"}) - ShareWidget getShareWidgetById(@Param("id") Long id); + @Select({"select id, name, description, view_id, type, config from widget where id = #{id}"}) + SimpleShareWidget getShareWidgetById(@Param("id") Long id); int insertBatch(@Param("list") List list); @@ -75,13 +75,12 @@ public interface WidgetMapper { List queryByDisplayId(@Param("displayId") Long displayId); @Select({ - "SELECT w.*, v.model, v.variable FROM widget w ", + "SELECT w.* FROM widget w ", "LEFT JOIN mem_display_slide_widget m on w.id = m.widget_id", "LEFT JOIN display_slide s on m.display_slide_id = s.id", - "LEFT JOIN `view` v on v.id = w.view_id", - "WHERE s.display_id = #{displayId}", + "WHERE s.display_id = #{displayId}" }) - Set getShareWidgetsByDisplayId(@Param("displayId") Long displayId); + Set getShareWidgetsByDisplayId(@Param("displayId") Long displayId); @Select({"select id from widget where project_id = #{projectId} and `name` = #{name}"}) Long getByNameWithProjectId(@Param("name") String name, @Param("projectId") Long projectId); @@ -92,11 +91,10 @@ public interface WidgetMapper { @Select({"SELECT w.*, m.id as 'relationId' FROM mem_dashboard_widget m LEFT JOIN widget w on w.id = m.widget_Id WHERE m.dashboard_id = #{dashboardId} order by m.create_time"}) List getByDashboard(@Param("dashboardId") Long dashboardId); - @Select({"SELECT w.*, v.model FROM mem_dashboard_widget m ", + @Select({"SELECT w.* FROM mem_dashboard_widget m ", "LEFT JOIN widget w on w.id = m.widget_Id ", - "LEFT JOIN `view` v on v.id = w.view_id", "WHERE m.dashboard_id = #{dashboardId}"}) - Set getShareWidgetsByDashboard(@Param("dashboardId") Long dashboardId); + Set getShareWidgetsByDashboard(@Param("dashboardId") Long dashboardId); @Delete({"delete from widget where project_id = #{projectId}"}) int deleteByProject(@Param("projectId") Long projectId); diff --git a/server/src/main/java/edp/davinci/dto/dashboardDto/DashboardWithMem.java b/server/src/main/java/edp/davinci/dto/dashboardDto/DashboardWithMem.java index f35847294..fefaec66c 100644 --- a/server/src/main/java/edp/davinci/dto/dashboardDto/DashboardWithMem.java +++ b/server/src/main/java/edp/davinci/dto/dashboardDto/DashboardWithMem.java @@ -19,9 +19,9 @@ package edp.davinci.dto.dashboardDto; +import edp.davinci.dto.viewDto.SimpleView; import edp.davinci.model.Dashboard; import edp.davinci.model.MemDashboardWidget; -import edp.davinci.model.View; import lombok.Data; import java.util.List; @@ -29,6 +29,6 @@ @Data public class DashboardWithMem extends Dashboard { - List widgets; - Set views; + List relations; + Set views; } diff --git a/server/src/main/java/edp/davinci/dto/projectDto/ProjectDetail.java b/server/src/main/java/edp/davinci/dto/projectDto/ProjectDetail.java index a270cacf6..c9e363d1d 100644 --- a/server/src/main/java/edp/davinci/dto/projectDto/ProjectDetail.java +++ b/server/src/main/java/edp/davinci/dto/projectDto/ProjectDetail.java @@ -26,11 +26,11 @@ @Data public class ProjectDetail extends Project { + private Organization organization; private UserBaseInfo createBy; - @Override public String toString() { return "Project{" + diff --git a/server/src/main/java/edp/davinci/dto/shareDto/ShareDashboard.java b/server/src/main/java/edp/davinci/dto/shareDto/ShareDashboard.java index f997bb060..021d1968c 100644 --- a/server/src/main/java/edp/davinci/dto/shareDto/ShareDashboard.java +++ b/server/src/main/java/edp/davinci/dto/shareDto/ShareDashboard.java @@ -20,7 +20,6 @@ package edp.davinci.dto.shareDto; import edp.davinci.model.MemDashboardWidget; -import edp.davinci.service.share.ShareWidget; import lombok.Data; import java.util.List; @@ -34,7 +33,9 @@ public class ShareDashboard { private String config; - private Set widgets; + private Set widgets; private List relations; + + private Set views; } diff --git a/server/src/main/java/edp/davinci/dto/shareDto/ShareDisplay.java b/server/src/main/java/edp/davinci/dto/shareDto/ShareDisplay.java index 400b9fac4..c824685fa 100644 --- a/server/src/main/java/edp/davinci/dto/shareDto/ShareDisplay.java +++ b/server/src/main/java/edp/davinci/dto/shareDto/ShareDisplay.java @@ -19,7 +19,6 @@ package edp.davinci.dto.shareDto; -import edp.davinci.service.share.ShareWidget; import lombok.Data; import java.util.Set; @@ -31,5 +30,6 @@ public class ShareDisplay { private String description; private String config; private Set slides; - private Set widgets; + private Set widgets; + private Set views; } diff --git a/server/src/main/java/edp/davinci/dto/shareDto/ShareEntity.java b/server/src/main/java/edp/davinci/dto/shareDto/ShareEntity.java index dbc89e49a..c1408397f 100644 --- a/server/src/main/java/edp/davinci/dto/shareDto/ShareEntity.java +++ b/server/src/main/java/edp/davinci/dto/shareDto/ShareEntity.java @@ -22,7 +22,10 @@ import edp.davinci.service.share.ShareDataPermission; import edp.davinci.service.share.ShareMode; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotNull; +import java.util.Date; import java.util.Set; @Data @@ -62,6 +65,10 @@ public class ShareEntity { */ private Set roles; + @NotNull(message = "Expired cannot be empty") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date expired; + public void valid() throws IllegalArgumentException { switch (this.getMode()) { case NORMAL: @@ -81,14 +88,14 @@ public void valid() throws IllegalArgumentException { if (!CollectionUtils.isEmpty(viewers)) { viewers.forEach(id -> { if (id < 1L) { - throw new IllegalArgumentException("Invalid viewer: " + id); + throw new IllegalArgumentException("Invalid viewer:" + id); } }); } if (!CollectionUtils.isEmpty(roles)) { roles.forEach(id -> { if (id < 1L) { - throw new IllegalArgumentException("Invalid role: " + id); + throw new IllegalArgumentException("Invalid role:" + id); } }); } diff --git a/server/src/main/java/edp/davinci/dto/shareDto/ShareView.java b/server/src/main/java/edp/davinci/dto/shareDto/ShareView.java new file mode 100644 index 000000000..318dcc0bf --- /dev/null +++ b/server/src/main/java/edp/davinci/dto/shareDto/ShareView.java @@ -0,0 +1,28 @@ +/* + * << + * Davinci + * == + * Copyright (C) 2016 - 2020 EDP + * == + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * >> + * + */ + +package edp.davinci.dto.shareDto; + +import edp.davinci.dto.viewDto.SimpleView; +import lombok.Data; + +@Data +public class ShareView extends SimpleView { + private String dataToken; +} diff --git a/server/src/main/java/edp/davinci/dto/shareDto/ShareWidget.java b/server/src/main/java/edp/davinci/dto/shareDto/ShareWidget.java new file mode 100644 index 000000000..e10cd7bf2 --- /dev/null +++ b/server/src/main/java/edp/davinci/dto/shareDto/ShareWidget.java @@ -0,0 +1,30 @@ +/* + * << + * Davinci + * == + * Copyright (C) 2016 - 2020 EDP + * == + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * >> + * + */ + +package edp.davinci.dto.shareDto; + +import lombok.Data; + +import java.util.Set; + +@Data +public class ShareWidget { + private SimpleShareWidget widget; + private Set views; +} diff --git a/server/src/main/java/edp/davinci/service/share/ShareWidget.java b/server/src/main/java/edp/davinci/dto/shareDto/SimpleShareWidget.java similarity index 85% rename from server/src/main/java/edp/davinci/service/share/ShareWidget.java rename to server/src/main/java/edp/davinci/dto/shareDto/SimpleShareWidget.java index 93e9fa3f5..de3051ef9 100644 --- a/server/src/main/java/edp/davinci/service/share/ShareWidget.java +++ b/server/src/main/java/edp/davinci/dto/shareDto/SimpleShareWidget.java @@ -16,20 +16,17 @@ * >> */ -package edp.davinci.service.share; +package edp.davinci.dto.shareDto; import lombok.Data; @Data -public class ShareWidget { +public class SimpleShareWidget { private Long id; private String name; private String description; private Long type; private String config; private String dataToken; - private String password; - private String model; private Long viewId; - private String variable; -} +} \ No newline at end of file diff --git a/server/src/main/java/edp/davinci/dto/viewDto/SimpleView.java b/server/src/main/java/edp/davinci/dto/viewDto/SimpleView.java new file mode 100644 index 000000000..c90ce717b --- /dev/null +++ b/server/src/main/java/edp/davinci/dto/viewDto/SimpleView.java @@ -0,0 +1,30 @@ +/* + * << + * Davinci + * == + * Copyright (C) 2016 - 2020 EDP + * == + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * >> + * + */ + +package edp.davinci.dto.viewDto; + +import lombok.Data; + +@Data +public class SimpleView { + private Long id; + private String name; + private String model; + private String variable; +} diff --git a/server/src/main/java/edp/davinci/dto/viewDto/ViewBaseInfo.java b/server/src/main/java/edp/davinci/dto/viewDto/ViewBaseInfo.java index 794afc450..b4f119421 100644 --- a/server/src/main/java/edp/davinci/dto/viewDto/ViewBaseInfo.java +++ b/server/src/main/java/edp/davinci/dto/viewDto/ViewBaseInfo.java @@ -26,6 +26,5 @@ public class ViewBaseInfo { private Long id; private String name; private String description; - private String sourceName; } diff --git a/server/src/main/java/edp/davinci/dto/viewDto/ViewWithProjectAndSource.java b/server/src/main/java/edp/davinci/dto/viewDto/ViewWithProjectAndSource.java index 5343948ae..49cc571ac 100644 --- a/server/src/main/java/edp/davinci/dto/viewDto/ViewWithProjectAndSource.java +++ b/server/src/main/java/edp/davinci/dto/viewDto/ViewWithProjectAndSource.java @@ -25,7 +25,6 @@ @Data public class ViewWithProjectAndSource extends ViewWithSource { - private Project project; private Source source; } diff --git a/server/src/main/java/edp/davinci/runner/LoadSupportDataSourceRunner.java b/server/src/main/java/edp/davinci/runner/LoadSupportDataSourceRunner.java index 9dc0ffcf9..22dd4d9ca 100644 --- a/server/src/main/java/edp/davinci/runner/LoadSupportDataSourceRunner.java +++ b/server/src/main/java/edp/davinci/runner/LoadSupportDataSourceRunner.java @@ -46,20 +46,20 @@ public class LoadSupportDataSourceRunner implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { - Map> dataSourceVersoins = CustomDataSourceUtils.getDataSourceVersoin(); + Map> dataSourceVersions = CustomDataSourceUtils.getDataSourceVersoin(); for (DataTypeEnum dataTypeEnum : DataTypeEnum.values()) { - if (dataSourceVersoins.containsKey(dataTypeEnum.getFeature())) { - List versions = dataSourceVersoins.get(dataTypeEnum.getFeature()); + if (dataSourceVersions.containsKey(dataTypeEnum.getFeature())) { + List versions = dataSourceVersions.get(dataTypeEnum.getFeature()); if (!versions.isEmpty() && !versions.contains(JDBC_DATASOURCE_DEFAULT_VERSION)) { versions.add(0, JDBC_DATASOURCE_DEFAULT_VERSION); } } else { - dataSourceVersoins.put(dataTypeEnum.getFeature(), null); + dataSourceVersions.put(dataTypeEnum.getFeature(), null); } } - dataSourceVersoins.forEach((name, versions) -> supportDatasourceList.add(new DatasourceType(name, versions))); + dataSourceVersions.forEach((name, versions) -> supportDatasourceList.add(new DatasourceType(name, versions))); supportDatasourceList.forEach(s -> supportDatasourceMap.put( s.getName(), diff --git a/server/src/main/java/edp/davinci/schedule/SystemSchedule.java b/server/src/main/java/edp/davinci/schedule/SystemSchedule.java index 716aa57cc..1f5bedb7d 100644 --- a/server/src/main/java/edp/davinci/schedule/SystemSchedule.java +++ b/server/src/main/java/edp/davinci/schedule/SystemSchedule.java @@ -62,8 +62,8 @@ public class SystemSchedule { public void clearTempDir() { //下载内容文件保留7天,记录保留1月 - String downloadDir = fileUtils.fileBasePath + Consts.DIR_DOWNLOAD + DateUtils.getTheDayBeforAWeekYYYYMMDD(); - String tempDir = fileUtils.fileBasePath + Consts.DIR_TEMP + DateUtils.getTheDayBeforNowDateYYYYMMDD(); + String downloadDir = fileUtils.fileBasePath + Consts.DIR_DOWNLOAD + DateUtils.getTheDayBeforeAWeekYYYYMMDD(); + String tempDir = fileUtils.fileBasePath + Consts.DIR_TEMP + DateUtils.getTheDayBeforeNowDateYYYYMMDD(); String csvDir = fileUtils.fileBasePath + File.separator + FileTypeEnum.CSV.getType(); final String download = fileUtils.formatFilePath(downloadDir); @@ -77,17 +77,13 @@ public void clearTempDir() { @Scheduled(cron = "0 0/2 * * * *") public void stopCronJob() { - -// if (redisUtils.isRedisEnable()) { -// return; -// } -// - List jobs = cronJobMapper.getStopedJob(); + List jobs = cronJobMapper.getStoppedJob(); if (!CollectionUtils.isEmpty(jobs)) { for (CronJob job : jobs) { try { quartzHandler.removeJob(job); } catch (ServerException e) { + } } } @@ -115,8 +111,8 @@ private void deleteFile(File file){ return; } - File[] childs = file.listFiles(); - if(childs.length == 0){ + File[] children = file.listFiles(); + if(children.length == 0){ file.delete(); deleteFile(file.getParentFile()); }else{ @@ -125,8 +121,8 @@ private void deleteFile(File file){ }else{ File parentDir = file.getParentFile(); - File[] childs = parentDir.listFiles(); - if(childs.length == 1){ + File[] children = parentDir.listFiles(); + if(children.length == 1){ file.delete(); deleteFile(parentDir); }else{ diff --git a/server/src/main/java/edp/davinci/service/DashboardService.java b/server/src/main/java/edp/davinci/service/DashboardService.java index 671b540d2..91f0743f9 100644 --- a/server/src/main/java/edp/davinci/service/DashboardService.java +++ b/server/src/main/java/edp/davinci/service/DashboardService.java @@ -61,6 +61,4 @@ public interface DashboardService extends CheckEntityService { boolean postDashboardVisibility(Role role, VizVisibility vizVisibility, User user) throws NotFoundException, UnAuthorizedException, ServerException; boolean updateMemDashboardWidgetAlias(Long relationId, String alias, User user) throws NotFoundException, UnAuthorizedException, ServerException; - - ; } diff --git a/server/src/main/java/edp/davinci/service/ShareService.java b/server/src/main/java/edp/davinci/service/ShareService.java index 93376d2ac..3d81043c6 100644 --- a/server/src/main/java/edp/davinci/service/ShareService.java +++ b/server/src/main/java/edp/davinci/service/ShareService.java @@ -29,7 +29,6 @@ import edp.davinci.dto.viewDto.DistinctParam; import edp.davinci.dto.viewDto.ViewExecuteParam; import edp.davinci.model.User; -import edp.davinci.service.share.ShareWidget; import java.sql.SQLException; import java.util.List; @@ -48,7 +47,7 @@ public interface ShareService { Paginate> getShareData(ViewExecuteParam executeParam, User user) throws NotFoundException, ServerException, ForbiddenException, UnAuthorizedException, SQLException; - List> getDistinctValue(Long viewId, DistinctParam param, User user); + List> getDistinctValue(DistinctParam param, User user); void formatShareParam(Long projectId, ShareEntity entity); diff --git a/server/src/main/java/edp/davinci/service/impl/BaseEntityService.java b/server/src/main/java/edp/davinci/service/impl/BaseEntityService.java index cf817aa88..bdf23069f 100644 --- a/server/src/main/java/edp/davinci/service/impl/BaseEntityService.java +++ b/server/src/main/java/edp/davinci/service/impl/BaseEntityService.java @@ -77,26 +77,26 @@ private short getEntityPermission(CheckEntityEnum entity, ProjectPermission proj short permission = (short) -1; switch (entity) { - case SOURCE: - permission = projectPermission.getSourcePermission(); - break; - case CRONJOB: - permission = projectPermission.getSchedulePermission(); - break; - case DISPLAY: - case DISPLAYSLIDE: - case DASHBOARDPORTAL: - case DASHBOARD: - permission = projectPermission.getVizPermission(); - break; - case VIEW: - permission = projectPermission.getViewPermission(); - break; - case WIDGET: - permission = projectPermission.getWidgetPermission(); - break; - default: - break; + case SOURCE: + permission = projectPermission.getSourcePermission(); + break; + case CRONJOB: + permission = projectPermission.getSchedulePermission(); + break; + case DISPLAY: + case DISPLAYSLIDE: + case DASHBOARDPORTAL: + case DASHBOARD: + permission = projectPermission.getVizPermission(); + break; + case VIEW: + permission = projectPermission.getViewPermission(); + break; + case WIDGET: + permission = projectPermission.getWidgetPermission(); + break; + default: + break; } return permission; diff --git a/server/src/main/java/edp/davinci/service/impl/BaseScheduleService.java b/server/src/main/java/edp/davinci/service/impl/BaseScheduleService.java index cd065b649..1e276a7be 100644 --- a/server/src/main/java/edp/davinci/service/impl/BaseScheduleService.java +++ b/server/src/main/java/edp/davinci/service/impl/BaseScheduleService.java @@ -1,7 +1,7 @@ package edp.davinci.service.impl; -import com.alibaba.druid.util.StringUtils; import edp.core.utils.CollectionUtils; +import edp.core.utils.DateUtils; import edp.core.utils.ServerUtils; import edp.davinci.core.enums.LogNameEnum; import edp.davinci.dao.DashboardMapper; @@ -14,6 +14,11 @@ import edp.davinci.service.ShareService; import edp.davinci.service.screenshot.ImageContent; import edp.davinci.service.screenshot.ScreenshotUtil; +import edp.davinci.service.share.ShareDataPermission; +import edp.davinci.service.share.ShareFactor; +import edp.davinci.service.share.ShareMode; +import edp.davinci.service.share.ShareType; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +30,9 @@ public class BaseScheduleService { + @Autowired + private String TOKEN_SECRET; + @Autowired protected DashboardMapper dashboardMapper; @@ -44,9 +52,11 @@ public class BaseScheduleService { protected static final String PORTAL = "PORTAL"; - protected static final String DISPLAY = "display"; + protected static final String DISPLAY = "DISPLAY"; - protected static final String DASHBOARD = "dashboard"; + protected static final String DASHBOARD = "DASHBOARD"; + + protected static final String WIDGET = "WIDGET"; /** * 根据job配置截取图片 @@ -207,7 +217,7 @@ private void buildDashboardTree(DashboardTree root, List dashboards) return; } Map> dashboardsMap = new HashMap<>(); - List rootChilds = new ArrayList<>(); + List rootChildren = new ArrayList<>(); for (Dashboard dashboard : dashboards) { if (dashboard.getParentId() > 0L && !dashboard.getParentId().equals(dashboard.getId())) { Set set; @@ -219,68 +229,69 @@ private void buildDashboardTree(DashboardTree root, List dashboards) set.add(dashboard); dashboardsMap.put(dashboard.getParentId(), set); } else { - rootChilds.add(new DashboardTree(dashboard.getId(), dashboard.getIndex())); + rootChildren.add(new DashboardTree(dashboard.getId(), dashboard.getIndex())); } } - rootChilds.sort(Comparator.comparing(DashboardTree::getIndex)); - root.setChilds(rootChilds); + rootChildren.sort(Comparator.comparing(DashboardTree::getIndex)); + root.setChilds(rootChildren); - for (DashboardTree child : rootChilds) { - child.setChilds(getChilds(dashboardsMap, child)); + for (DashboardTree child : rootChildren) { + child.setChilds(getChildren(dashboardsMap, child)); } } - private List getChilds(Map> dashboardsMap, DashboardTree node) { + private List getChildren(Map> dashboardsMap, DashboardTree node) { if (CollectionUtils.isEmpty(dashboardsMap)) { return null; } - Set childs = dashboardsMap.get(node.getId()); - if (CollectionUtils.isEmpty(childs)) { + Set children = dashboardsMap.get(node.getId()); + if (CollectionUtils.isEmpty(children)) { return null; } List list = new ArrayList<>(); - for (Dashboard dashboard : childs) { + for (Dashboard dashboard : children) { DashboardTree treeNode = new DashboardTree(dashboard.getId(), dashboard.getIndex()); - treeNode.setChilds(getChilds(dashboardsMap, treeNode)); + treeNode.setChilds(getChildren(dashboardsMap, treeNode)); list.add(treeNode); } list.sort(Comparator.comparing(DashboardTree::getIndex)); return list; } - private String getContentUrl(Long userId, String contentType, Long contengId, int index) { - String shareToken = shareService.generateShareToken(contengId, null, userId); - StringBuilder sb = new StringBuilder(); - - String type = ""; - String page = ""; - if ("widget".equalsIgnoreCase(contentType)) { - type = "widget"; - } else if (PORTAL.equalsIgnoreCase(contentType) || "dashboard".equalsIgnoreCase(contentType)) { - type = "dashboard"; - } else { - type = ""; - page = "p=" + index; + private String getContentUrl(Long userId, String contentType, Long contentId, int index) { + + ShareFactor shareFactor = ShareFactor.Builder + .shareFactor() + .withMode(ShareMode.NORMAL) + .withEntityId(contentId) + .withSharerId(userId) + .withExpired(DateUtils.add(DateUtils.currentDate(), Calendar.DATE, 1)) + .withPermission(ShareDataPermission.SHARER) + .build(); + + String page = null; + switch (contentType.toUpperCase()) { + case WIDGET: + shareFactor.setType(ShareType.WIDGET); + break; + case DISPLAY: + shareFactor.setType(ShareType.DISPLAY); + page = "&p=" + index; + break; + default: + shareFactor.setType(ShareType.DASHBOARD); + break; } + String shareToken = shareFactor.toShareResult(TOKEN_SECRET).getToken(); + StringBuilder sb = new StringBuilder(); sb.append(serverUtils.getLocalHost()) .append("/share.html") .append("?shareToken=") .append(shareToken); - - if (!StringUtils.isEmpty(type)) { - sb.append("&type=").append(type); - } - - if (!StringUtils.isEmpty(page)) { - sb.append("&").append(page); - } - - sb.append("#/share/").append(contentType.equalsIgnoreCase("widget") || contentType.equalsIgnoreCase(PORTAL) ? "dashboard" : contentType); - + sb.append(StringUtils.isEmpty(page) ? "" : page); + sb.append("#/share/").append(WIDGET.equalsIgnoreCase(contentType) || PORTAL.equalsIgnoreCase(contentType) ? DASHBOARD.toLowerCase() : contentType); return sb.toString(); } - - } diff --git a/server/src/main/java/edp/davinci/service/impl/DashboardServiceImpl.java b/server/src/main/java/edp/davinci/service/impl/DashboardServiceImpl.java index a42598742..4df6da92c 100644 --- a/server/src/main/java/edp/davinci/service/impl/DashboardServiceImpl.java +++ b/server/src/main/java/edp/davinci/service/impl/DashboardServiceImpl.java @@ -38,6 +38,7 @@ import edp.davinci.dto.projectDto.ProjectPermission; import edp.davinci.dto.roleDto.VizVisibility; import edp.davinci.dto.shareDto.ShareEntity; +import edp.davinci.dto.viewDto.SimpleView; import edp.davinci.model.*; import edp.davinci.service.DashboardService; import edp.davinci.service.ShareService; @@ -107,36 +108,10 @@ private DashboardPortal getDashboardPortal(Long portalId, boolean isThrow) { return dashboardPortal; } - public Dashboard getDashboard(Long dashboardId) { + private Dashboard getDashboard(Long dashboardId) { Dashboard dashboard = dashboardMapper.getById(dashboardId); - if (null == dashboard) { - throw new NotFoundException("dashboard is not found"); - } - return dashboard; - } - - public Dashboard getDashboard(Long dashboardId, User user) throws NotFoundException, UnAuthorizedException, ServerException { - Dashboard dashboard = getDashboard(dashboardId); if (dashboard == null) { - return null; - } - DashboardPortal dashboardPortal = getDashboardPortal(dashboard.getDashboardPortalId(), false); - if (dashboardPortal == null) { - return null; - } - - Long projectId = dashboardPortal.getProjectId(); - - ProjectPermission projectPermission = getProjectPermission(projectId, user); - - List disablePortals = getDisableVizs(user.getId(), projectId, null, VizEnum.PORTAL); - - boolean isDisable = isDisableVizs(projectPermission, disablePortals, dashboardPortal.getId()); - boolean hidden = projectPermission.getVizPermission() < UserPermissionEnum.READ.getPermission(); - boolean noPublish = projectPermission.getVizPermission() < UserPermissionEnum.WRITE.getPermission() && !dashboardPortal.getPublish(); - - if (hidden || isDisable || noPublish) { - throw new UnAuthorizedException(); + throw new NotFoundException("dashboard is not found"); } return dashboard; } @@ -213,7 +188,6 @@ public DashboardWithMem getDashboardMemWidgets(Long portalId, Long dashboardId, } List memDashboardWidgets = memDashboardWidgetMapper.getByDashboardId(dashboardId); - List disableDashboards = getDisableVizs(user.getId(), portalId, null, VizEnum.DASHBOARD); List disableMemDashboardWidget = relRoleDashboardWidgetMapper.getDisableByUser(user.getId()); @@ -223,19 +197,39 @@ public DashboardWithMem getDashboardMemWidgets(Long portalId, Long dashboardId, } Set widgetIds = memDashboardWidgets.stream().map(MemDashboardWidget::getWidgetId).collect(Collectors.toSet()); - Set views = new HashSet<>(); - if (!CollectionUtils.isEmpty(widgetIds)) { - views = viewMapper.selectByWidgetIds(widgetIds); + // widget views + Set simpleViews = CollectionUtils.isEmpty(widgetIds) ? new HashSet<>() : viewMapper.selectSimpleByWidgetIds(widgetIds); + + // global controller views + Map dashboardConfig = JSON.parseObject(dashboard.getConfig(), Map.class); + if (!CollectionUtils.isEmpty(dashboardConfig)) { + setControllerViews(simpleViews, (List>) dashboardConfig.get("filters")); } + // widget controller views + memDashboardWidgets.forEach(mw -> { + Map widgetConfigMap = JSON.parseObject(widgetMapper.getById(mw.getWidgetId()).getConfig(), Map.class); + if (!CollectionUtils.isEmpty(widgetConfigMap)) { + setControllerViews(simpleViews, (List>)widgetConfigMap.get("controls")); + } + }); + DashboardWithMem dashboardWithMem = new DashboardWithMem(); BeanUtils.copyProperties(dashboard, dashboardWithMem); - dashboardWithMem.setWidgets(memDashboardWidgets); - dashboardWithMem.setViews(views); + dashboardWithMem.setRelations(memDashboardWidgets); + dashboardWithMem.setViews(simpleViews); return dashboardWithMem; } + private void setControllerViews(Set views, List> list) { + if (!CollectionUtils.isEmpty(list)) { + list.stream().filter(m -> m.containsKey("valueViewId")).collect(Collectors.toList()).forEach(m -> { + views.add(viewMapper.getSimpleViewById(Long.parseLong(String.valueOf(m.get("valueViewId"))))); + }); + } + } + /** * 新建dashboard * @@ -711,6 +705,7 @@ public ShareResult shareDashboard(Long dashboardId, User user, ShareEntity share .withShareEntity(shareEntity) .withEntityId(dashboardId) .withSharerId(user.getId()) + .withExpired(shareEntity.getExpired()) .build(); return shareFactor.toShareResult(TOKEN_SECRET); diff --git a/server/src/main/java/edp/davinci/service/impl/DisplayServiceImpl.java b/server/src/main/java/edp/davinci/service/impl/DisplayServiceImpl.java index 9376ab594..836ab1c83 100644 --- a/server/src/main/java/edp/davinci/service/impl/DisplayServiceImpl.java +++ b/server/src/main/java/edp/davinci/service/impl/DisplayServiceImpl.java @@ -27,7 +27,6 @@ import edp.core.utils.CollectionUtils; import edp.core.utils.FileUtils; import edp.davinci.core.common.Constants; -import edp.davinci.core.common.ErrorMsg; import edp.davinci.core.enums.CheckEntityEnum; import edp.davinci.core.enums.LogNameEnum; import edp.davinci.core.enums.UserPermissionEnum; @@ -61,7 +60,6 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.UUID; @@ -292,26 +290,6 @@ public boolean updateDisplay(DisplayUpdate displayUpdate, User user) throws NotF } } - public Display getDisplay(Long displayId, User user) throws NotFoundException, UnAuthorizedException, ServerException { - Display display = displayMapper.getById(displayId); - if (display == null) { - throw new NotFoundException("Display is not found"); - } - - if (!checkReadPermission(entity, display.getProjectId(), user)) { - return null; - } - ProjectPermission projectPermission = getProjectPermission(display.getProjectId(), user); - List disableList = getDisableVizs(user.getId(), display.getProjectId(), Arrays.asList(displayId), VizEnum.DISPLAY); - boolean disable = !projectPermission.isProjectMaintainer() && disableList.contains(display.getId()); - boolean noPublish = projectPermission.getVizPermission() < UserPermissionEnum.WRITE.getPermission() - && !display.getPublish(); - if (disable || noPublish) { - throw new UnAuthorizedException(ErrorMsg.ERR_MSG_PERMISSION); - } - return display; - } - /** * 根据项目获取当前用户可见Display列表 * diff --git a/server/src/main/java/edp/davinci/service/impl/EmailScheduleServiceImpl.java b/server/src/main/java/edp/davinci/service/impl/EmailScheduleServiceImpl.java index 8f8cf0f91..eff5ac366 100644 --- a/server/src/main/java/edp/davinci/service/impl/EmailScheduleServiceImpl.java +++ b/server/src/main/java/edp/davinci/service/impl/EmailScheduleServiceImpl.java @@ -126,19 +126,19 @@ public void execute(long jobId) throws Exception { List excels = null; List images = null; - User creater = userMapper.getById(cronJob.getCreateBy()); + User creator = userMapper.getById(cronJob.getCreateBy()); if (cronJobConfig.getType().equals(CronJobMediaType.IMAGE.getType())) { - images = generateImages(jobId, cronJobConfig, creater.getId()); + images = generateImages(jobId, cronJobConfig, creator.getId()); } if (cronJobConfig.getType().equals(CronJobMediaType.EXCEL.getType())) { - excels = generateExcels(jobId, cronJobConfig, creater); + excels = generateExcels(jobId, cronJobConfig, creator); } if (cronJobConfig.getType().equals(CronJobMediaType.IMAGEANDEXCEL.getType())) { - images = generateImages(jobId, cronJobConfig, creater.getId()); - excels = generateExcels(jobId, cronJobConfig, creater); + images = generateImages(jobId, cronJobConfig, creator.getId()); + excels = generateExcels(jobId, cronJobConfig, creator); } List attachmentList = new ArrayList<>(); diff --git a/server/src/main/java/edp/davinci/service/impl/ProjectServiceImpl.java b/server/src/main/java/edp/davinci/service/impl/ProjectServiceImpl.java index 361a44224..48268bbc0 100644 --- a/server/src/main/java/edp/davinci/service/impl/ProjectServiceImpl.java +++ b/server/src/main/java/edp/davinci/service/impl/ProjectServiceImpl.java @@ -347,7 +347,7 @@ public boolean deleteProject(Long id, User user) throws ServerException, UnAutho dashboardService.deleteDashboardAndPortalByProject(project.getId()); widgetMapper.deleteByProject(project.getId()); relRoleViewMapper.deleteByProject(project.getId()); - viewMapper.deleteByPorject(project.getId()); + viewMapper.deleteByProject(project.getId()); sourceMapper.deleteByProject(project.getId()); relRoleProjectMapper.deleteByProjectId(project.getId()); relProjectAdminMapper.deleteByProjectId(project.getId()); @@ -560,18 +560,18 @@ public boolean removeAdmin(Long relationId, User user) throws ServerException, U public ProjectDetail getProjectDetail(Long id, User user, boolean modify) throws NotFoundException, UnAuthorizedException { ProjectDetail projectDetail = projectMapper.getProjectDetail(id); if (null == projectDetail) { - log.error("project (:{}) is not found", id); - throw new NotFoundException("project is not found"); + log.error("Project({}) is not found", id); + throw new NotFoundException("Project is not found"); } RelUserOrganization rel = relUserOrganizationMapper.getRel(user.getId(), projectDetail.getOrgId()); RelProjectAdmin relProjectAdmin = relProjectAdminMapper.getByProjectAndUser(id, user.getId()); - boolean isCreater = projectDetail.getUserId().equals(user.getId()) && !projectDetail.getIsTransfer(); - boolean notOwner = !isCreater && null == relProjectAdmin && (null == rel || rel.getRole() != UserOrgRoleEnum.OWNER.getRole()); + boolean isCreator = projectDetail.getUserId().equals(user.getId()) && !projectDetail.getIsTransfer(); + boolean notOwner = !isCreator && null == relProjectAdmin && (null == rel || rel.getRole() != UserOrgRoleEnum.OWNER.getRole()); if (modify) { //项目的创建人和当前项目对应组织的owner可以修改 if (notOwner) { - log.error("user(:{}) have not permission to modify project (:{})", user.getId(), id); + log.error("User({}) have not permission to modify project({})", user.getId(), id); throw new UnAuthorizedException(); } } else { @@ -579,7 +579,7 @@ public ProjectDetail getProjectDetail(Long id, User user, boolean modify) throws if (notOwner && projectDetail.getOrganization().getMemberPermission() < (short) 1 && !projectDetail.getVisibility()) { - log.error("user(:{}) have not permission to get project (:{})", user.getId(), id); + log.error("User({}) have not permission to get project ({})", user.getId(), id); throw new UnAuthorizedException(); } } @@ -771,12 +771,12 @@ public boolean isMaintainer(ProjectDetail projectDetail, User user) { return false; } - //project所在org的creater + //project所在org的creator if (projectDetail.getOrganization().getUserId().equals(user.getId())) { return true; } - //当前project的creater + //当前project的creator if (projectDetail.getUserId().equals(user.getId()) && !projectDetail.getIsTransfer()) { return true; } diff --git a/server/src/main/java/edp/davinci/service/impl/ShareServiceImpl.java b/server/src/main/java/edp/davinci/service/impl/ShareServiceImpl.java index 748856f62..592e8b982 100644 --- a/server/src/main/java/edp/davinci/service/impl/ShareServiceImpl.java +++ b/server/src/main/java/edp/davinci/service/impl/ShareServiceImpl.java @@ -20,6 +20,7 @@ package edp.davinci.service.impl; import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; import edp.core.exception.ForbiddenException; import edp.core.exception.NotFoundException; import edp.core.exception.ServerException; @@ -38,6 +39,7 @@ import edp.davinci.dto.shareDto.*; import edp.davinci.dto.userDto.UserLogin; import edp.davinci.dto.viewDto.DistinctParam; +import edp.davinci.dto.viewDto.SimpleView; import edp.davinci.dto.viewDto.ViewExecuteParam; import edp.davinci.dto.viewDto.ViewWithProjectAndSource; import edp.davinci.model.*; @@ -48,7 +50,7 @@ import edp.davinci.service.share.ShareDataPermission; import edp.davinci.service.share.ShareFactor; import edp.davinci.service.share.ShareMode; -import edp.davinci.service.share.ShareWidget; +import edp.davinci.dto.shareDto.SimpleShareWidget; import edp.davinci.service.share.aspect.ShareAuthAspect; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; @@ -58,6 +60,7 @@ import java.sql.SQLException; import java.util.*; +import java.util.stream.Collectors; import static edp.core.consts.Consts.EMPTY; @@ -140,14 +143,33 @@ public User shareLogin(UserLogin userLogin) throws NotFoundException, ServerExce public ShareWidget getShareWidget(User user) throws NotFoundException, ServerException, ForbiddenException, UnAuthorizedException { ShareFactor shareFactor = ShareAuthAspect.SHARE_FACTOR_THREAD_LOCAL.get(); + ShareFactor widgetFactor = new ShareFactor(); + BeanUtils.copyProperties(shareFactor, widgetFactor); + ShareFactor viewFactor = new ShareFactor(); + BeanUtils.copyProperties(shareFactor, viewFactor); + Widget widget = (Widget) shareFactor.getShareEntity(); - ShareWidget shareWidget = widgetMapper.getShareWidgetById(widget.getId()); + SimpleShareWidget simpleShareWidget = widgetMapper.getShareWidgetById(widget.getId()); + + if (null == simpleShareWidget) { + throw new NotFoundException("Widget is not found"); + } + + widgetFactor.freshWidgetDataToken(simpleShareWidget, TOKEN_SECRET); - if (null == shareWidget) { - throw new NotFoundException("widget not found"); + // widget controller views + Set simpleViews = new HashSet<>(); + Map widgetConfigMap = JSON.parseObject(simpleShareWidget.getConfig(), Map.class); + if (!CollectionUtils.isEmpty(widgetConfigMap)) { + setControllerViews(simpleViews, (List>)widgetConfigMap.get("controls")); } - shareFactor.freshShareDataToken(shareWidget, TOKEN_SECRET); + simpleViews.add(viewMapper.getSimpleViewById(simpleShareWidget.getViewId())); + + ShareWidget shareWidget = new ShareWidget(); + shareWidget.setWidget(simpleShareWidget); + shareWidget.setViews(generateShareViews(simpleViews, viewFactor)); + return shareWidget; } @@ -160,52 +182,50 @@ public ShareWidget getShareWidget(User user) throws NotFoundException, ServerExc */ @Override public ShareDisplay getShareDisplay(User user) throws NotFoundException, ServerException, ForbiddenException, UnAuthorizedException { + ShareFactor shareFactor = ShareAuthAspect.SHARE_FACTOR_THREAD_LOCAL.get(); + ShareFactor widgetFactor = new ShareFactor(); + BeanUtils.copyProperties(shareFactor, widgetFactor); + ShareFactor viewFactor = new ShareFactor(); + BeanUtils.copyProperties(shareFactor, viewFactor); + Display display = (Display) shareFactor.getShareEntity(); ShareDisplay shareDisplay = new ShareDisplay(); - BeanUtils.copyProperties(display, shareDisplay); List memWithSlides = memDisplaySlideWidgetMapper.getMemWithSlideByDisplayId(display.getId()); List displaySlides = displaySlideMapper.selectByDisplayId(display.getId()); - Set memDisplaySlideWidgetSet = null; - - if (!CollectionUtils.isEmpty(memWithSlides)) { - memDisplaySlideWidgetSet = new HashSet<>(); - for (MemDisplaySlideWidgetWithSlide memWithSlide : memWithSlides) { - MemDisplaySlideWidget memDisplaySlideWidget = new MemDisplaySlideWidget(); - BeanUtils.copyProperties(memWithSlide, memDisplaySlideWidget); - memDisplaySlideWidgetSet.add(memDisplaySlideWidget); - } - } + Set memDisplaySlideWidgetSet = new HashSet<>(); - if (!CollectionUtils.isEmpty(displaySlides)) { - Set shareDisplaySlideSet = new HashSet<>(); - for (DisplaySlide displaySlide : displaySlides) { - ShareDisplaySlide shareDisplaySlide = new ShareDisplaySlide(); - BeanUtils.copyProperties(displaySlide, shareDisplaySlide); - - if (!CollectionUtils.isEmpty(memDisplaySlideWidgetSet)) { - Iterator memIterator = memDisplaySlideWidgetSet.iterator(); - Set relations = new HashSet<>(); - while (memIterator.hasNext()) { - MemDisplaySlideWidget memDisplaySlideWidget = memIterator.next(); - if (memDisplaySlideWidget.getDisplaySlideId().equals(displaySlide.getId())) { - relations.add(memDisplaySlideWidget); - } - } - shareDisplaySlide.setRelations(relations); - } - shareDisplaySlideSet.add(shareDisplaySlide); - } - shareDisplay.setSlides(shareDisplaySlideSet); + for (MemDisplaySlideWidgetWithSlide memWithSlide : memWithSlides) { + MemDisplaySlideWidget memDisplaySlideWidget = new MemDisplaySlideWidget(); + BeanUtils.copyProperties(memWithSlide, memDisplaySlideWidget); + memDisplaySlideWidgetSet.add(memDisplaySlideWidget); } - Set shareWidgets = widgetMapper.getShareWidgetsByDisplayId(display.getId()); - if (!CollectionUtils.isEmpty(shareWidgets)) { - shareWidgets.forEach(shareWidget -> shareFactor.freshShareDataToken(shareWidget, TOKEN_SECRET)); - shareDisplay.setWidgets(shareWidgets); + Set shareDisplaySlideSet = new HashSet<>(); + for (DisplaySlide displaySlide : displaySlides) { + ShareDisplaySlide shareDisplaySlide = new ShareDisplaySlide(); + BeanUtils.copyProperties(displaySlide, shareDisplaySlide); + + Set relations = new HashSet<>(); + relations.addAll(memDisplaySlideWidgetSet.stream().filter(mw -> mw.getDisplaySlideId().equals(displaySlide.getId())).collect(Collectors.toSet())); + shareDisplaySlide.setRelations(relations); + shareDisplaySlideSet.add(shareDisplaySlide); } + shareDisplay.setSlides(shareDisplaySlideSet); + + Set widgets = widgetMapper.getShareWidgetsByDisplayId(display.getId()); + Set simpleViews = CollectionUtils.isEmpty(widgets) ? new HashSet<>() : viewMapper.selectSimpleByWidgetIds(widgets.stream().map(w -> w.getId()).collect(Collectors.toSet())); + widgets.forEach(w -> { + widgetFactor.freshWidgetDataToken(w, TOKEN_SECRET); + Map widgetConfigMap = JSON.parseObject(widgetMapper.getShareWidgetById(w.getId()).getConfig(), Map.class); + if (!CollectionUtils.isEmpty(widgetConfigMap)) { + setControllerViews(simpleViews, (List>) widgetConfigMap.get("controls")); + } + }); + shareDisplay.setWidgets(widgets); + shareDisplay.setViews(generateShareViews(simpleViews, viewFactor)); return shareDisplay; } @@ -219,7 +239,13 @@ public ShareDisplay getShareDisplay(User user) throws NotFoundException, ServerE @Override @Transactional public ShareDashboard getShareDashboard(User user) throws NotFoundException, ServerException, ForbiddenException, UnAuthorizedException { + ShareFactor shareFactor = ShareAuthAspect.SHARE_FACTOR_THREAD_LOCAL.get(); + ShareFactor widgetFactor = new ShareFactor(); + BeanUtils.copyProperties(shareFactor, widgetFactor); + ShareFactor viewFactor = new ShareFactor(); + BeanUtils.copyProperties(shareFactor, viewFactor); + Dashboard dashboard = (Dashboard) shareFactor.getShareEntity(); ShareDashboard shareDashboard = new ShareDashboard(); BeanUtils.copyProperties(dashboard, shareDashboard); @@ -227,79 +253,116 @@ public ShareDashboard getShareDashboard(User user) throws NotFoundException, Ser List memDashboardWidgets = memDashboardWidgetMapper.getByDashboardId(dashboard.getId()); shareDashboard.setRelations(memDashboardWidgets); - Set shareWidgets = widgetMapper.getShareWidgetsByDashboard(dashboard.getId()); - if (!CollectionUtils.isEmpty(shareWidgets)) { - shareWidgets.forEach(shareWidget -> shareFactor.freshShareDataToken(shareWidget, TOKEN_SECRET)); + Set simpleShareWidgets = widgetMapper.getShareWidgetsByDashboard(dashboard.getId()); + if (!CollectionUtils.isEmpty(simpleShareWidgets)) { + simpleShareWidgets.forEach(shareWidget -> widgetFactor.freshWidgetDataToken(shareWidget, TOKEN_SECRET)); } - shareDashboard.setWidgets(shareWidgets); + shareDashboard.setWidgets(simpleShareWidgets); + + Set widgetIds = memDashboardWidgets.stream().map(MemDashboardWidget::getWidgetId).collect(Collectors.toSet()); + Set simpleViews = CollectionUtils.isEmpty(widgetIds) ? new HashSet<>() : viewMapper.selectSimpleByWidgetIds(widgetIds); + + // global controller views + Map dashboardConfig = JSON.parseObject(dashboard.getConfig(), Map.class); + if (!CollectionUtils.isEmpty(dashboardConfig)) { + setControllerViews(simpleViews, (List>) dashboardConfig.get("filters")); + } + + // widget controller views + memDashboardWidgets.forEach(mw -> { + Map widgetConfigMap = JSON.parseObject(widgetMapper.getShareWidgetById(mw.getWidgetId()).getConfig(), Map.class); + if (!CollectionUtils.isEmpty(widgetConfigMap)) { + setControllerViews(simpleViews, (List>)widgetConfigMap.get("controls")); + } + }); + + shareDashboard.setViews(generateShareViews(simpleViews, viewFactor)); + return shareDashboard; } + private void setControllerViews(Set simpleViews, List> list) { + if (!CollectionUtils.isEmpty(list)) { + list.stream().filter(m -> m.containsKey("valueViewId")).collect(Collectors.toList()).forEach(m -> { + simpleViews.add(viewMapper.getSimpleViewById(Long.parseLong(String.valueOf(m.get("valueViewId"))))); + }); + } + } + + private Set generateShareViews(Set simpleViews, ShareFactor viewFactor) { + Set shareViews = new HashSet<>(); + simpleViews.forEach(v -> { + ShareView view = new ShareView(); + BeanUtils.copyProperties(v, view); + viewFactor.freshViewDataToken(view, TOKEN_SECRET); + shareViews.add(view); + }); + return shareViews; + } /** * 获取分享数据 * * @param executeParam - * @param user + * @param currentUser * @return */ @Override - public Paginate> getShareData(ViewExecuteParam executeParam, User user) + public Paginate> getShareData(ViewExecuteParam executeParam, User currentUser) throws NotFoundException, ServerException, ForbiddenException, UnAuthorizedException, SQLException { ShareFactor shareFactor = ShareAuthAspect.SHARE_FACTOR_THREAD_LOCAL.get(); Widget widget = (Widget) shareFactor.getShareEntity(); ViewWithProjectAndSource viewWithProjectAndSource = viewMapper.getViewWithProjectAndSourceByWidgetId(widget.getId()); - User tempUser; + User user; if (shareFactor.getPermission() == ShareDataPermission.SHARER) { - tempUser = shareFactor.getUser(); + user = shareFactor.getUser(); } else { - tempUser = user; + user = currentUser; } - ProjectDetail projectDetail = projectService.getProjectDetail(viewWithProjectAndSource.getProjectId(), tempUser, false); - boolean maintainer = projectService.isMaintainer(projectDetail, tempUser); + ProjectDetail projectDetail = projectService.getProjectDetail(viewWithProjectAndSource.getProjectId(), user, false); + boolean maintainer = projectService.isMaintainer(projectDetail, user); Paginate paginate = viewService.getResultDataList(maintainer, viewWithProjectAndSource, executeParam, user); return paginate; } /** - * 获取分享distinct value + * 获取分享控制器数据 * - * @param viewId * @param param - * @param user + * @param currentUser * @return */ @Override - public List> getDistinctValue(Long viewId, DistinctParam param, User user) { - List> list = null; + public List> getDistinctValue(DistinctParam param, User currentUser) { + List> list = new ArrayList<>(); ShareFactor shareFactor = ShareAuthAspect.SHARE_FACTOR_THREAD_LOCAL.get(); + View view = (View) shareFactor.getShareEntity(); - ViewWithProjectAndSource viewWithProjectAndSource = viewMapper.getViewWithProjectAndSourceById(viewId); + ViewWithProjectAndSource viewWithProjectAndSource = viewMapper.getViewWithProjectAndSourceById(view.getId()); if (null == viewWithProjectAndSource) { - log.info("view({}) not found", viewId); - throw new NotFoundException("view is not found"); + throw new NotFoundException("View is not found"); } - User tempUser; + User user; if (shareFactor.getPermission() == ShareDataPermission.SHARER) { - tempUser = shareFactor.getUser(); + user = shareFactor.getUser(); } else { - tempUser = user; + user = currentUser; } - ProjectDetail projectDetail = projectService.getProjectDetail(viewWithProjectAndSource.getProjectId(), tempUser, false); - boolean maintainer = projectService.isMaintainer(projectDetail, tempUser); + ProjectDetail projectDetail = projectService.getProjectDetail(viewWithProjectAndSource.getProjectId(), user, false); + boolean maintainer = projectService.isMaintainer(projectDetail, user); - if (!projectService.allowGetData(projectDetail, tempUser)) { + if (!projectService.allowGetData(projectDetail, user)) { throw new UnAuthorizedException(ErrorMsg.ERR_MSG_PERMISSION); } try { - list = viewService.getDistinctValueData(maintainer, viewWithProjectAndSource, param, tempUser); + list = viewService.getDistinctValueData(maintainer, viewWithProjectAndSource, param, user); } catch (ServerException e) { throw new UnAuthorizedException(e.getMessage()); } @@ -368,6 +431,15 @@ public Map checkShareToken() throws ServerException, ForbiddenEx ShareFactor shareFactor = ShareAuthAspect.SHARE_FACTOR_THREAD_LOCAL.get(); Map map = new HashMap<>(1); map.put("type", shareFactor.getMode().name()); + switch (shareFactor.getType()) { + case WIDGET: + case DASHBOARD: + case DISPLAY: + map.put("vizType", shareFactor.getType().name().toLowerCase()); + break; + default: + break; + } return map; } @@ -497,5 +569,4 @@ public String generateShareToken(Long shareEntityId, String username, Long userI //生成token并aes加密 return AESUtils.encrypt(tokenUtils.generateContinuousToken(shareToken), null); } -} - +} \ No newline at end of file diff --git a/server/src/main/java/edp/davinci/service/impl/ViewServiceImpl.java b/server/src/main/java/edp/davinci/service/impl/ViewServiceImpl.java index 8073405df..da17d949b 100644 --- a/server/src/main/java/edp/davinci/service/impl/ViewServiceImpl.java +++ b/server/src/main/java/edp/davinci/service/impl/ViewServiceImpl.java @@ -71,7 +71,8 @@ @Slf4j @Service("viewService") -public class ViewServiceImpl extends BaseEntityService implements ViewService { +public class +ViewServiceImpl extends BaseEntityService implements ViewService { private static final Logger optLogger = LoggerFactory.getLogger(LogNameEnum.BUSINESS_OPERATION.getName()); @@ -880,7 +881,6 @@ private List getAuthVariables(List roleViewList, List< return list; } - List authVars = variables.stream() .filter(v -> AUTHVAR == SqlVariableTypeEnum.typeOf(v.getType())).collect(Collectors.toList()); @@ -896,43 +896,47 @@ private List getAuthVariables(List roleViewList, List< List authParamValues = JSONObject.parseArray(r.getRowAuth(), AuthParamValue.class); authVarMap.forEach((k, v) -> { SqlVariable sqlVariable = v; + Optional optional = authParamValues.stream().filter(p -> k.equals(p.getName())).findFirst(); + List defaultValues = sqlVariable.getDefaultValues(); + // first time defaultValues will be null if (defaultValues == null) { + // empty list means has all data auth sqlVariable.setDefaultValues(new ArrayList<>()); - if (authParamValues.stream().filter(p -> k.equals(p.getName())).findFirst().isPresent()) { - AuthParamValue authParamValue = authParamValues.stream().filter(p -> k.equals(p.getName())).findFirst().get(); - if (authParamValue.isEnable()) { - if (CollectionUtils.isEmpty(authParamValue.getValues())) { + optional.ifPresent(p -> { + if (p.isEnable()) { + if (CollectionUtils.isEmpty(p.getValues())) { sqlVariable.setDefaultValues(Arrays.asList(new String[]{NO_AUTH_PERMISSION})); } else { - sqlVariable.setDefaultValues(authParamValue.getValues()); + sqlVariable.setDefaultValues(p.getValues()); } } - } + }); return; } - if (authParamValues.stream().filter(p -> k.equals(p.getName())).findFirst().isPresent()) { - AuthParamValue authParamValue = authParamValues.stream().filter(p -> k.equals(p.getName())).findFirst().get(); - if (authParamValue.isEnable()) { - if (!CollectionUtils.isEmpty(authParamValue.getValues())) { + if (optional.isPresent()) { + AuthParamValue p = optional.get(); + if (p.isEnable()) { + if (!CollectionUtils.isEmpty(p.getValues())) { boolean denied = defaultValues.size() == 1 && defaultValues.get(0).equals(NO_AUTH_PERMISSION); boolean disable = defaultValues.size() == 0; if (denied) { - sqlVariable.setDefaultValues(authParamValue.getValues()); - return; + sqlVariable.setDefaultValues(p.getValues()); } else if (!disable) { - defaultValues.addAll(authParamValue.getValues()); - return; + sqlVariable.getDefaultValues().addAll(p.getValues()); } } - return; + } else { + sqlVariable.setDefaultValues(new ArrayList<>()); } + return; } sqlVariable.setDefaultValues(new ArrayList<>()); }); + list.addAll(authVarMap.values()); } else { list.addAll(dacVars); @@ -942,7 +946,6 @@ private List getAuthVariables(List roleViewList, List< return list; } - private void checkAndInsertRoleParam(String sqlVariable, List roles, User user, View view) { List variables = JSONObject.parseArray(sqlVariable, SqlVariable.class); if (CollectionUtils.isEmpty(roles)) { diff --git a/server/src/main/java/edp/davinci/service/screenshot/ScreenshotUtil.java b/server/src/main/java/edp/davinci/service/screenshot/ScreenshotUtil.java index 1ec067cc2..5d465aa62 100644 --- a/server/src/main/java/edp/davinci/service/screenshot/ScreenshotUtil.java +++ b/server/src/main/java/edp/davinci/service/screenshot/ScreenshotUtil.java @@ -164,13 +164,13 @@ private File doScreenshot(long jobId, String url, Integer imageWidth) throws Exc } } catch (TimeoutException te) { - String text= driver.findElements(By.tagName("html")).get(0).getAttribute("innerText"); - scheduleLogger.info("Cronjob({}) do screenshot url={} text=\n{}",text); - LogEntries logEntries= driver.manage().logs().get(LogType.BROWSER); + String text = driver.findElements(By.tagName("html")).get(0).getAttribute("innerText"); + scheduleLogger.info("Cronjob({}) do screenshot url={} text=\n{}", text); + LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER); for (LogEntry entry : logEntries) { scheduleLogger.info(entry.getLevel() + " " + entry.getMessage()); } - scheduleLogger.error(te.getMessage(), te); + scheduleLogger.error(te.getMessage(), te); } catch (InterruptedException e) { LogEntries logEntries= driver.manage().logs().get(LogType.BROWSER); for (LogEntry entry : logEntries) { diff --git a/server/src/main/java/edp/davinci/service/share/ShareFactor.java b/server/src/main/java/edp/davinci/service/share/ShareFactor.java index 6f84839a4..ea34c0581 100644 --- a/server/src/main/java/edp/davinci/service/share/ShareFactor.java +++ b/server/src/main/java/edp/davinci/service/share/ShareFactor.java @@ -26,6 +26,8 @@ import edp.core.utils.StringZipUtil; import edp.davinci.dto.projectDto.ProjectDetail; import edp.davinci.dto.shareDto.ShareEntity; +import edp.davinci.dto.shareDto.ShareView; +import edp.davinci.dto.shareDto.SimpleShareWidget; import edp.davinci.model.User; import lombok.Data; import org.springframework.beans.BeanUtils; @@ -140,17 +142,17 @@ public Object process(Object object, String name, Object value) { */ private Set roles; - private Long expire = null; + private Date expired; /** - * permission == ShareDataPermission.SHARER ? sharer : viewer; + * permission == ShareDataPermission.SHARER ? sharer : viewer */ private User user; private Object shareEntity; private ProjectDetail projectDetail; public static ShareFactor parseShareFactor(String token, String secret) throws IllegalArgumentException { - ShareFactor factor = null; + ShareFactor factor; try { String decompress = StringZipUtil.decompress(token); String decrypt = AESUtils.decrypt(decompress, secret); @@ -160,12 +162,6 @@ public static ShareFactor parseShareFactor(String token, String secret) throws I factor = new ShareFactor(); factor.setMode(ShareMode.COMPATIBLE); } - if (factor.getMode() != ShareMode.COMPATIBLE && factor.getExpire() != null && factor.getExpire() > 0L) { - long now = System.currentTimeMillis(); - if (now > factor.getExpire()) { - throw new IllegalArgumentException("Token expired"); - } - } return factor; } @@ -178,16 +174,26 @@ public ShareResult toShareResult(String secret) { return new ShareResult(StringZipUtil.compress(AESUtils.encrypt(jsonString, secret)), this.password); } - public ShareResult freshShareDataToken(ShareWidget shareWidget, String secret) { - if (this.getMode() == ShareMode.NORMAL) { - this.setMode(ShareMode.PASSWORD); - } - this.setEntityId(shareWidget.getId()); + public void freshWidgetDataToken(SimpleShareWidget simpleShareWidget, String secret) { + this.setEntityId(simpleShareWidget.getId()); this.setType(ShareType.WIDGET); + if (ShareMode.PASSWORD == this.mode) { + this.setMode(ShareMode.NORMAL); + this.setPassword(null); + } + ShareResult shareResult = this.toShareResult(secret); + simpleShareWidget.setDataToken(shareResult.getToken()); + } + + public void freshViewDataToken(ShareView shareView, String secret) { + this.setEntityId(shareView.getId()); + this.setType(ShareType.VIEW); + if (ShareMode.PASSWORD == this.mode) { + this.setMode(ShareMode.NORMAL); + this.setPassword(null); + } ShareResult shareResult = this.toShareResult(secret); - shareWidget.setDataToken(shareResult.getToken()); - shareWidget.setPassword(shareResult.getPassword()); - return shareResult; + shareView.setDataToken(shareResult.getToken()); } private void format() { @@ -200,7 +206,7 @@ private void format() { this.setPassword(null); this.setViewers(null); this.setRoles(null); - this.setExpire(null); + this.setExpired(null); break; case NORMAL: this.setPermission(ShareDataPermission.SHARER); @@ -276,8 +282,8 @@ public Builder withRoles(Set roles) { return this; } - public Builder withExpire(Long expire) { - shareFactor.expire = expire; + public Builder withExpired(Date expired) { + shareFactor.expired = expired; return this; } @@ -294,18 +300,4 @@ public ShareFactor build() { return shareFactor; } } - - public ShareFactor expire() { - Calendar calendar = new Calendar.Builder().setInstant(new Date()).build(); - calendar.add(Calendar.DAY_OF_MONTH, DEFAULT_TOKEN_EXPIRE_DAYS); - this.setExpire(calendar.getTimeInMillis()); - return this; - } - - public ShareFactor expire(int dayOfMonth) { - Calendar calendar = new Calendar.Builder().setInstant(new Date()).build(); - calendar.add(Calendar.DAY_OF_MONTH, dayOfMonth); - this.setExpire(calendar.getTimeInMillis()); - return this; - } } diff --git a/server/src/main/java/edp/davinci/service/share/ShareResult.java b/server/src/main/java/edp/davinci/service/share/ShareResult.java index 7e461d1f0..31c8e02ab 100644 --- a/server/src/main/java/edp/davinci/service/share/ShareResult.java +++ b/server/src/main/java/edp/davinci/service/share/ShareResult.java @@ -35,5 +35,6 @@ public ShareResult(String token, String password) { } public ShareResult() { + } } diff --git a/server/src/main/java/edp/davinci/service/share/ShareType.java b/server/src/main/java/edp/davinci/service/share/ShareType.java index 959e14af5..9ce908c1c 100644 --- a/server/src/main/java/edp/davinci/service/share/ShareType.java +++ b/server/src/main/java/edp/davinci/service/share/ShareType.java @@ -21,34 +21,35 @@ import lombok.Getter; public enum ShareType { - WIDGET(0), - DASHBOARD(1), - DISPLAY(2), + VIEW(0), + WIDGET(1), + DASHBOARD(2), + DISPLAY(3), /** * 数据 */ - DATA(3), + DATA(4), /** * 记录 */ - RECORD(4), + RECORD(5), /** * 文件 */ - FILE(5), + FILE(6), /** * 登录 */ - LOGIN(6), + LOGIN(7), /** - * + * 权限 */ - PERMISSION(7); + PERMISSION(8); @Getter private int type; diff --git a/server/src/main/java/edp/davinci/service/share/aspect/ShareAuthAspect.java b/server/src/main/java/edp/davinci/service/share/aspect/ShareAuthAspect.java index 63fac0fa0..0b2f24aeb 100644 --- a/server/src/main/java/edp/davinci/service/share/aspect/ShareAuthAspect.java +++ b/server/src/main/java/edp/davinci/service/share/aspect/ShareAuthAspect.java @@ -27,18 +27,11 @@ import edp.core.utils.CollectionUtils; import edp.davinci.core.common.ErrorMsg; import edp.davinci.core.common.ResultMap; -import edp.davinci.core.enums.CheckEntityEnum; -import edp.davinci.dao.DashboardPortalMapper; -import edp.davinci.dao.RelRoleUserMapper; -import edp.davinci.dao.UserMapper; -import edp.davinci.dto.projectDto.ProjectDetail; +import edp.davinci.dao.*; import edp.davinci.dto.shareDto.ShareInfo; import edp.davinci.model.*; import edp.davinci.service.ProjectService; import edp.davinci.service.ShareService; -import edp.davinci.service.impl.DashboardServiceImpl; -import edp.davinci.service.impl.DisplayServiceImpl; -import edp.davinci.service.impl.WidgetServiceImpl; import edp.davinci.service.share.*; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; @@ -72,16 +65,19 @@ public class ShareAuthAspect { private RelRoleUserMapper relRoleUserMapper; @Autowired - private WidgetServiceImpl widgetService; + private ViewMapper viewMapper; @Autowired - private DashboardServiceImpl dashboardService; + private WidgetMapper widgetMapper; + + @Autowired + private DashboardMapper dashboardMapper; @Autowired private DashboardPortalMapper dashboardPortalMapper; @Autowired - private DisplayServiceImpl displayService; + private DisplayMapper displayMapper; @Autowired private ProjectService projectService; @@ -108,11 +104,6 @@ public ResponseEntity doAround(ProceedingJoinPoint joinPoint) throws Throwable { return ResponseEntity.status(resultMap.getCode()).body(resultMap); } - ShareFactor shareFactor = ShareFactor.parseShareFactor(token, TOKEN_SECRET); - if (shareFactor.getType() == null) { - shareFactor.setType(shareType); - } - User user = null; for (Object arg : args) { if (arg instanceof User) { @@ -123,47 +114,92 @@ public ResponseEntity doAround(ProceedingJoinPoint joinPoint) throws Throwable { } } + ShareFactor shareFactor = ShareFactor.parseShareFactor(token, TOKEN_SECRET); + if (shareFactor.getType() == null) { + shareFactor.setType(shareType); + } + + verifyShareType(shareType, shareFactor); + + verifyExpire(shareFactor); + try { + // 兼容老版本,token信息转换为新版本信息 adaptShareInfo(token, shareFactor, user); - // 下载接口数据参数语义不唯一,在业务中判断 - if (ShareOperation.DOWNLOAD != shareOperation) { - if (ShareOperation.PERMISSION == shareOperation) { - // 获取兼容模式下的分享类型 - String type = (String) args[2]; - if (CheckEntityEnum.WIDGET.getSource().equals(type.toLowerCase())) { - shareFactor.setType(ShareType.WIDGET); - } else if (CheckEntityEnum.DASHBOARD.getSource().equals(type.toLowerCase())) { - shareFactor.setType(ShareType.DASHBOARD); - } else if (CheckEntityEnum.DISPLAY.getSource().equals(type.toLowerCase())) { - shareFactor.setType(ShareType.DISPLAY); - } else { - throw new ServerException("Unknown share type"); - } - } else { - shareFactor.setType(shareType == ShareType.DATA ? ShareType.WIDGET : shareType); - } - } + convertShareType(shareType, shareOperation, shareFactor, args); if (shareType != ShareType.LOGIN) { // 校验token权限 verifyToken(shareOperation, shareFactor, user, args); // 校验数据权限 - verifyDataPermission(shareOperation, shareType, shareFactor, user); + verifyPermission(shareOperation, shareType, shareFactor, user); } // thread local share factor SHARE_FACTOR_THREAD_LOCAL.set(shareFactor); // 处理业务并返回 return (ResponseEntity) joinPoint.proceed(args); + } finally { // clean thread local SHARE_FACTOR_THREAD_LOCAL.remove(); } } + private void convertShareType(ShareType shareType, ShareOperation shareOperation, ShareFactor shareFactor, Object[] args) { + + if (ShareOperation.DOWNLOAD == shareOperation) { + return; + } + + if (ShareOperation.LOAD_DATA == shareOperation && shareType == ShareType.DATA) { + shareFactor.setType(ShareType.WIDGET); + return; + } + + if (ShareOperation.LOAD_DISTINCT_DATA == shareOperation && shareType == ShareType.DATA) { + shareFactor.setType(ShareType.VIEW); + return; + } + } + /** - * 校验Token 是否合法 + * 校验分享的viz类型 + * + * @param shareType + * @param shareFactor + */ + private void verifyShareType(ShareType shareType, ShareFactor shareFactor) { + switch (shareType) { + case WIDGET: + case DASHBOARD: + case DISPLAY: + if (!shareType.equals(shareFactor.getType())) { + throw new UnAuthorizedException("Invalid share type"); + } + break; + default: + break; + } + } + + /** + * 校验Token是否过期 + * + * @param shareFactor + */ + private void verifyExpire(ShareFactor shareFactor) { + if (shareFactor.getMode() != ShareMode.COMPATIBLE && shareFactor.getExpired() != null) { + long now = System.currentTimeMillis(); + if (now > shareFactor.getExpired().getTime()) { + throw new UnAuthorizedException("Share token expired"); + } + } + } + + /** + * 校验Token是否合法 * * @param operation * @param shareFactor @@ -209,7 +245,7 @@ private void verifyToken(ShareOperation operation, ShareFactor shareFactor, User * @param viewer */ @Transactional - protected void verifyDataPermission(ShareOperation shareOperation, ShareType shareType, ShareFactor shareFactor, User viewer) + protected void verifyPermission(ShareOperation shareOperation, ShareType shareType, ShareFactor shareFactor, User viewer) throws NotFoundException, ServerException, ForbiddenException, UnAuthorizedException { User sharer = userMapper.getById(shareFactor.getSharerId()); if (sharer == null) { @@ -217,24 +253,31 @@ protected void verifyDataPermission(ShareOperation shareOperation, ShareType sha } User user = shareFactor.getPermission() == ShareDataPermission.SHARER ? sharer : viewer; shareFactor.setUser(user); - if (shareOperation == ShareOperation.READ || shareOperation == ShareOperation.PERMISSION) { - parseEntityAndProject(shareFactor, user); - } else if (shareOperation == ShareOperation.LOAD_DATA) { - if (shareFactor.getType() != ShareType.WIDGET) { - throw new ForbiddenException(ErrorMsg.ERR_LOAD_DATA_TOKEN); - } - Widget widget = widgetService.getWidget(shareFactor.getEntityId(), user); - ProjectDetail projectDetail = projectService.getProjectDetail(widget.getProjectId(), user, false); - if (!projectService.allowGetData(projectDetail, user)) { - throw new UnAuthorizedException(ErrorMsg.ERR_MSG_PERMISSION); - } - shareFactor.setShareEntity(widget); - } else { - // 下载权限数据权限在业务中判断 - if (shareType != ShareType.DATA) { + + switch (shareOperation) { + case READ: + case PERMISSION: parseEntityAndProject(shareFactor, user); - } - return; + break; + case LOAD_DATA: + case LOAD_DISTINCT_DATA: + if (shareFactor.getType() == ShareType.VIEW) { + shareFactor.setShareEntity(viewMapper.getById(shareFactor.getEntityId())); + break; + } + + if (shareFactor.getType() == ShareType.WIDGET) { + shareFactor.setShareEntity(widgetMapper.getById(shareFactor.getEntityId())); + break; + } + + throw new ForbiddenException(ErrorMsg.ERR_LOAD_DATA_TOKEN); + + default: + if (shareType != ShareType.DATA) { + parseEntityAndProject(shareFactor, user); + } + break; } } @@ -244,18 +287,23 @@ private void parseEntityAndProject(ShareFactor shareFactor, User user) { case RECORD: case FILE: case WIDGET: - Widget widget = widgetService.getWidget(shareFactor.getEntityId(), user); + Widget widget = widgetMapper.getById(shareFactor.getEntityId()); shareFactor.setProjectDetail(projectService.getProjectDetail(widget.getProjectId(), user, false)); shareFactor.setShareEntity(widget); break; + case VIEW: + View view = viewMapper.getById(shareFactor.getEntityId()); + shareFactor.setProjectDetail(projectService.getProjectDetail(view.getProjectId(), user, false)); + shareFactor.setShareEntity(view); + break; case DASHBOARD: - Dashboard dashboard = dashboardService.getDashboard(shareFactor.getEntityId(), user); + Dashboard dashboard = dashboardMapper.getById(shareFactor.getEntityId()); DashboardPortal portal = dashboardPortalMapper.getById(dashboard.getDashboardPortalId()); shareFactor.setProjectDetail(projectService.getProjectDetail(portal.getProjectId(), user, false)); shareFactor.setShareEntity(dashboard); break; case DISPLAY: - Display display = displayService.getDisplay(shareFactor.getEntityId(), user); + Display display = displayMapper.getById(shareFactor.getEntityId()); shareFactor.setProjectDetail(projectService.getProjectDetail(display.getProjectId(), user, false)); shareFactor.setShareEntity(display); break; @@ -276,6 +324,7 @@ public void adaptShareInfo(String token, ShareFactor shareFactor, User user) { if (shareFactor.getMode() != ShareMode.COMPATIBLE) { return; } + ShareInfo shareInfo = shareService.getShareInfo(token, user); shareService.verifyShareUser(user, shareInfo); // 新老版本字段定义不同 @@ -283,6 +332,8 @@ public void adaptShareInfo(String token, ShareFactor shareFactor, User user) { shareFactor.setEntityId(shareInfo.getShareId()); shareFactor.setPermission(ShareDataPermission.SHARER); shareFactor.setMode(ShareMode.NORMAL); + // 只兼容老版本的dashboard分享 + shareFactor.setType(ShareType.DASHBOARD); // 授权模式 if (!StringUtils.isEmpty(shareInfo.getSharedUserName())) { diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 63251f6ce..824d846bc 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -17,6 +17,7 @@ davinci: version: 0.3-beta.9 + file: userfiles-path: ${DAVINCI3_HOME}/userfiles/ web_resources: ${DAVINCI3_HOME}/davinci-ui/ @@ -63,6 +64,7 @@ spring: logging: config: file:${DAVINCI3_HOME}/config/logback.xml + springfox: documentation: swagger: @@ -77,6 +79,7 @@ pagehelper: helperDialect: mysql params: count=countSql + mybatis: mapper-locations: classpath:mybatis/mapper/*Mapper.xml config-locations: classpath:mybatis/mybatis-config.xml @@ -85,11 +88,14 @@ mybatis: map-underscore-to-camel-case: true use-generated-keys: true + mapper: identity: MYSQL not-empty: false mappers: edp.davinci.dao + sql_template_delimiter: $ + custom-datasource-driver-path: ${DAVINCI3_HOME}/config/datasource_driver.yml diff --git a/server/src/main/resources/mybatis/mapper/ViewMapper.xml b/server/src/main/resources/mybatis/mapper/ViewMapper.xml index 5bebaec42..730db1e62 100644 --- a/server/src/main/resources/mybatis/mapper/ViewMapper.xml +++ b/server/src/main/resources/mybatis/mapper/ViewMapper.xml @@ -107,6 +107,21 @@ ); + SELECT v.*,