Skip to content

Commit

Permalink
Merge pull request edp963#1992 from xxxllluuu/dev-0.3
Browse files Browse the repository at this point in the history
Fix: Refactor share module code compatible issue bug
  • Loading branch information
scottsut authored Oct 28, 2020
2 parents 2105e6a + 4272405 commit d0a080b
Show file tree
Hide file tree
Showing 46 changed files with 672 additions and 422 deletions.
4 changes: 2 additions & 2 deletions config/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -145,7 +145,7 @@ spring:
username:
password:
base:
domainName: # domainName 指 企业邮箱后缀,如企业邮箱为:xxx@example.com, 这里值为 '@example.com'
domainName: # domainName 指 企业邮箱后缀,如企业邮箱为:xxx@example.com这里值为 '@example.com'

security:
oauth2:
Expand Down
2 changes: 1 addition & 1 deletion config/datasource_driver.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
33 changes: 23 additions & 10 deletions server/src/main/java/edp/core/utils/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);

Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 23 additions & 6 deletions server/src/main/java/edp/davinci/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<String, Object> configurations() {
Map<String, Object> configs = new HashMap<>();
configs.put("version", environment.getProperty("davinci.version"));
configs.put("jwtToken", new HashMap<String, Object>() {{
put("timeout", environment.getProperty("jwtToken.timeout"));
}});
configs.put("security", new HashMap<String, Object>() {{
put("oauth2", new HashMap<String, Object>() {{
put("enable", Boolean.valueOf(environment.getProperty("security.oauth2.enable")));
}});
}});

return new HashMap<String, Object>() {{
put("payload", configs);
}};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 5 additions & 9 deletions server/src/main/java/edp/davinci/controller/ShareController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -215,28 +214,25 @@ public ResponseEntity getShareData(@PathVariable String token,


/**
* share 获取唯一值
* share获取控制器的值
*
* @param token
* @param viewId
* @param param
* @param bindingResult
* @param user
* @param request
* @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<Map<String, Object>> resultList = shareService.getDistinctValue(viewId, param, user);
List<Map<String, Object>> resultList = shareService.getDistinctValue(param, user);
if (null == user || user.getId() == null) {
return ResponseEntity.ok(new ResultMap().success().payloads(resultList));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/edp/davinci/core/common/ErrorMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,47 @@ 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());
}

@ExceptionHandler(value = ServerException.class)
@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());
}

@ExceptionHandler(value = ForbiddenException.class)
@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());
}

@ExceptionHandler(value = UnAuthorizedException.class)
@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());
}

@ExceptionHandler(value = NotFoundException.class)
@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());
}

@ExceptionHandler(value = MethodArgumentNotValidException.class)
@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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/edp/davinci/dao/CronJobMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<CronJob> getStopedJob();
List<CronJob> getStoppedJob();

@Update({
"update cron_job",
Expand Down
Loading

0 comments on commit d0a080b

Please sign in to comment.