Skip to content

Commit

Permalink
add workspace favorites and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamyuanyuan committed Jun 30, 2020
1 parent d18a6a7 commit 4dadcfe
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import com.webank.wedatasphere.dss.server.dto.response.*;
import com.webank.wedatasphere.dss.server.entity.*;
import com.webank.wedatasphere.dss.server.dto.response.HomepageDemoInstanceVo;
import com.webank.wedatasphere.dss.server.dto.response.HomepageDemoMenuVo;
import com.webank.wedatasphere.dss.server.dto.response.HomepageVideoVo;
import com.webank.wedatasphere.dss.server.dto.response.WorkspaceFavoriteVo;
import org.apache.ibatis.annotations.Param;

import java.util.List;

Expand Down Expand Up @@ -36,4 +41,11 @@ public interface WorkspaceMapper {
List<OnestopMenuAppInstanceVo> getMenuAppInstancesCn(Long id);
List<OnestopMenuAppInstanceVo> getMenuAppInstanceEn(Long id);

List<WorkspaceFavoriteVo> getWorkspaceFavoritesCn(@Param("username") String username, @Param("workspaceId") Long workspaceId);

List<WorkspaceFavoriteVo> getWorkspaceFavoritesEn(@Param("username") String username, @Param("workspaceId") Long workspaceId);

void addFavorite(DWSFavorite dwsFavorite);

void deleteFavorite(Long favouritesId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
m.`manual_button_url`,m.`icon`,m.`order`,app.`homepage_url` AS `access_button_url`,app.project_url, app.`name`
</sql>

<sql id="favorite_main">
id,`username`,`workspace_id`,`menu_application_id`,`order`,`create_by`,`create_time`,`last_update_user`,`last_update_time`
</sql>

<select id="getWorkspaces" resultType="com.webank.wedatasphere.dss.server.entity.DWSWorkspace">
SELECT *
Expand Down Expand Up @@ -84,6 +87,7 @@
`is_active` = 1 AND `menu_id` = #{id}
</where>
</select>

<select id="getHomepageInstancesByMenuIdEn" resultType="com.webank.wedatasphere.dss.server.dto.response.HomepageDemoInstanceVo">
SELECT `id`,`menu_id`,`name`,`url`,`title_en` AS `title`,`description`,`icon`,`order`
FROM dss_homepage_demo_instance
Expand All @@ -99,6 +103,7 @@
`is_active` = 1
</where>
</select>

<select id="getHomepageVideosEn" resultType="com.webank.wedatasphere.dss.server.dto.response.HomepageVideoVo">
SELECT `id`,`name`,`title_en` AS `title`,`url`,`description`,`order`
FROM dss_homepage_video
Expand All @@ -114,6 +119,7 @@
`is_active` = 0
</where>
</select>

<select id="getManagementMenuEn" resultType="com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo">
SELECT `id`,`name`,`title_en` AS `title`,`order`
FROM dss_onestop_menu
Expand All @@ -129,6 +135,7 @@
`is_active` = 1
</where>
</select>

<select id="getApplicationMenuEn" resultType="com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo">
SELECT `id`,`name`,`title_en` AS `title`,`order`
FROM dss_onestop_menu
Expand All @@ -146,6 +153,7 @@
m.`onestop_menu_id` = #{id}
</where>
</select>

<select id="getMenuAppInstancesEn" resultType="com.webank.wedatasphere.dss.server.dto.response.OnestopMenuAppInstanceVo">
SELECT <include refid = "menu_appInstances_en"/>
FROM dss_onestop_menu_application m
Expand All @@ -155,4 +163,38 @@
m.`onestop_menu_id` = #{id}
</where>
</select>

<select id="getWorkspaceFavoritesCn" resultType="com.webank.wedatasphere.dss.server.dto.response.WorkspaceFavoriteVo">
SELECT dss_onestop_user_favorites.id, dss_onestop_menu_application.id AS menuApplicationId , name, url, icon, title_cn AS title
FROM dss_onestop_user_favorites join dss_onestop_menu_application
on dss_onestop_user_favorites.menu_application_id = dss_onestop_menu_application.id
join dss_application on dss_application.id = dss_onestop_menu_application.application_id
<where>
dss_onestop_user_favorites.`username` = #{username} and `workspace_id` = #{workspaceId}
</where>
</select>

<select id="getWorkspaceFavoritesEn" resultType="com.webank.wedatasphere.dss.server.dto.response.WorkspaceFavoriteVo">
SELECT dss_onestop_user_favorites.id, dss_onestop_menu_application.id AS menuApplicationId, name, url, icon, title_en AS `title`
FROM dss_onestop_user_favorites join dss_onestop_menu_application
on dss_onestop_user_favorites.menu_application_id = dss_onestop_menu_application.id
join dss_application on dss_application.id = dss_onestop_menu_application.application_id
<where>
dss_onestop_user_favorites.`username` = #{username} and `workspace_id` = #{workspaceId}
</where>
</select>

<insert id="addFavorite" useGeneratedKeys="true" keyProperty="id" parameterType="com.webank.wedatasphere.dss.server.entity.DWSFavorite">
INSERT INTO dss_onestop_user_favorites (<include refid = "favorite_main" />)
VALUES
(#{id},#{username},#{workspaceId},#{menuApplicationId},#{order},#{createBy},#{createTime},#{lastUpdateUser},#{lastUpdateTime})
</insert>

<delete id="deleteFavorite">
DELETE
FROM
dss_onestop_user_favorites
WHERE
id = #{favouritesId}
</delete>
</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.webank.wedatasphere.dss.server.dto.response;

/**
* Created by Adamyuanyuan on 2020/6/25
*/
public class WorkspaceFavoriteVo {
private Long id;

private Long menuApplicationId;

private String name;

private String url;

private String icon;

private String title;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Long getMenuApplicationId() {
return menuApplicationId;
}

public void setMenuApplicationId(Long menuApplicationId) {
this.menuApplicationId = menuApplicationId;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.webank.wedatasphere.dss.server.entity;

/**
* Created by Adamyuanyuan on 2020/6/25
*/
public class DWSFavorite extends BaseEntity{

private Long id;

private String username;

private Long workspaceId;

private Long menuApplicationId;

private Integer order;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public Long getWorkspaceId() {
return workspaceId;
}

public void setWorkspaceId(Long workspaceId) {
this.workspaceId = workspaceId;
}

public Long getMenuApplicationId() {
return menuApplicationId;
}

public void setMenuApplicationId(Long menuApplicationId) {
this.menuApplicationId = menuApplicationId;
}

public Integer getOrder() {
return order;
}

public void setOrder(Integer order) {
this.order = order;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo;
import com.webank.wedatasphere.dss.server.entity.DWSWorkspace;
import com.webank.wedatasphere.dss.server.dto.response.WorkspaceDepartmentVo;
import com.webank.wedatasphere.dss.application.service.DSSUserService;
import com.webank.wedatasphere.dss.server.dto.response.*;
import com.webank.wedatasphere.dss.server.service.DWSWorkspaceService;
import com.webank.wedatasphere.linkis.server.Message;
import com.webank.wedatasphere.linkis.server.security.SecurityFilter;
Expand All @@ -31,6 +33,8 @@ public class WorkspaceRestfulApi {
@Autowired
private DWSWorkspaceService dwsWorkspaceService;

@Autowired
private DSSUserService dssUserService;

@GET
@Path("/workspaces")
Expand All @@ -40,6 +44,13 @@ public Response getAllWorkspaces(@Context HttpServletRequest req) {
return Message.messageToResponse(Message.ok().data("workspaces", workspaces));
}

@GET
@Path("/workspaces/{id}")
public Response getWorkspacesById(@Context HttpServletRequest req, @PathParam("id") Long id) {
DWSWorkspace workspace = dwsWorkspaceService.getWorkspacesById(id);
return Message.messageToResponse(Message.ok().data("workspace", workspace));
}

@GET
@Path("/workspaces/departments")
public Response getAllWorkspaceDepartments(@Context HttpServletRequest req) {
Expand Down Expand Up @@ -89,7 +100,7 @@ public Response getAllVideos(@Context HttpServletRequest req) {

@GET
@Path("workspaces/{workspaceId}/managements")
public Response getWorkspaceManagements(@Context HttpServletRequest req, @PathParam("workspaceId")Long workspaceId) {
public Response getWorkspaceManagements(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId) {
String header = req.getHeader("Content-language").trim();
boolean isChinese = "zh-CN".equals(header);
String username = SecurityFilter.getLoginUsername(req);
Expand All @@ -100,11 +111,45 @@ public Response getWorkspaceManagements(@Context HttpServletRequest req, @PathPa

@GET
@Path("workspaces/{workspaceId}/applications")
public Response getWorkspaceApplications(@Context HttpServletRequest req, @PathParam("workspaceId")Long workspaceId) {
public Response getWorkspaceApplications(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId) {
String header = req.getHeader("Content-language").trim();
boolean isChinese = "zh-CN".equals(header);
String username = SecurityFilter.getLoginUsername(req);
List<OnestopMenuVo> applications = dwsWorkspaceService.getWorkspaceApplications(workspaceId, username, isChinese);
return Message.messageToResponse(Message.ok().data("applications", applications));
}

@GET
@Path("/workspaces/{workspaceId}/favorites")
public Response getWorkspaceFavorites(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId) {
String header = req.getHeader("Content-language").trim();
boolean isChinese = "zh-CN".equals(header);
String username = SecurityFilter.getLoginUsername(req);
List<WorkspaceFavoriteVo> favorites = dwsWorkspaceService.getWorkspaceFavorites(workspaceId, username, isChinese);
return Message.messageToResponse(Message.ok().data("favorites", favorites));
}

/**
* 应用加入收藏,返回收藏后id
*
* @param req
* @param json
* @return
*/
@POST
@Path("/workspaces/{workspaceId}/favorites")
public Response addFavorite(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId, JsonNode json) {
String username = SecurityFilter.getLoginUsername(req);
Long menuApplicationId = json.get("menuApplicationId").getLongValue();
Long favoriteId = dwsWorkspaceService.addFavorite(username, workspaceId, menuApplicationId);
return Message.messageToResponse(Message.ok().data("favoriteId", favoriteId));
}

@DELETE
@Path("/workspaces/{workspaceId}/favorites/{favouritesId}")
public Response deleteFavorite(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId, @PathParam("favouritesId") Long favouritesId) {
String username = SecurityFilter.getLoginUsername(req);
Long favoriteId = dwsWorkspaceService.deleteFavorite(username, favouritesId);
return Message.messageToResponse(Message.ok().data("favoriteId", favoriteId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo;
import com.webank.wedatasphere.dss.server.entity.DWSWorkspace;
import com.webank.wedatasphere.dss.server.dto.response.WorkspaceDepartmentVo;
import com.webank.wedatasphere.dss.server.dto.response.*;

import java.util.List;

Expand All @@ -27,4 +28,19 @@ public interface DWSWorkspaceService {
List<OnestopMenuVo> getWorkspaceManagements(Long workspaceId, String username, boolean isChinese);

List<OnestopMenuVo> getWorkspaceApplications(Long workspaceId, String username, boolean isChinese);

DWSWorkspace getWorkspacesById(Long id);

/**
* 查询用户收藏的应用,如果是新用户,就在数据库给它插入默认两个收藏:脚本开发与工作流 workflow scriptis
* @param workspaceId
* @param username
* @param isChinese
* @return
*/
List<WorkspaceFavoriteVo> getWorkspaceFavorites(Long workspaceId, String username, boolean isChinese);

Long addFavorite(String username, Long workspaceId, Long menuApplicationId);

Long deleteFavorite(String username, Long favouritesId);
}
Loading

0 comments on commit 4dadcfe

Please sign in to comment.