Skip to content

Commit bf242e1

Browse files
committed
add workspace favorites and resolve conflicts
1 parent eedc404 commit bf242e1

File tree

7 files changed

+272
-3
lines changed

7 files changed

+272
-3
lines changed

dss-server/src/main/java/com/webank/wedatasphere/dss/server/dao/WorkspaceMapper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import com.webank.wedatasphere.dss.server.dto.response.*;
44
import com.webank.wedatasphere.dss.server.entity.*;
5+
import com.webank.wedatasphere.dss.server.dto.response.HomepageDemoInstanceVo;
6+
import com.webank.wedatasphere.dss.server.dto.response.HomepageDemoMenuVo;
7+
import com.webank.wedatasphere.dss.server.dto.response.HomepageVideoVo;
8+
import com.webank.wedatasphere.dss.server.dto.response.WorkspaceFavoriteVo;
9+
import org.apache.ibatis.annotations.Param;
510

611
import java.util.List;
712

@@ -36,4 +41,11 @@ public interface WorkspaceMapper {
3641
List<OnestopMenuAppInstanceVo> getMenuAppInstancesCn(Long id);
3742
List<OnestopMenuAppInstanceVo> getMenuAppInstanceEn(Long id);
3843

44+
List<WorkspaceFavoriteVo> getWorkspaceFavoritesCn(@Param("username") String username, @Param("workspaceId") Long workspaceId);
45+
46+
List<WorkspaceFavoriteVo> getWorkspaceFavoritesEn(@Param("username") String username, @Param("workspaceId") Long workspaceId);
47+
48+
void addFavorite(DWSFavorite dwsFavorite);
49+
50+
void deleteFavorite(Long favouritesId);
3951
}

dss-server/src/main/java/com/webank/wedatasphere/dss/server/dao/impl/workspaceMapper.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
m.`manual_button_url`,m.`icon`,m.`order`,app.`homepage_url` AS `access_button_url`,app.project_url, app.`name`
3636
</sql>
3737

38+
<sql id="favorite_main">
39+
id,`username`,`workspace_id`,`menu_application_id`,`order`,`create_by`,`create_time`,`last_update_user`,`last_update_time`
40+
</sql>
3841

3942
<select id="getWorkspaces" resultType="com.webank.wedatasphere.dss.server.entity.DWSWorkspace">
4043
SELECT *
@@ -84,6 +87,7 @@
8487
`is_active` = 1 AND `menu_id` = #{id}
8588
</where>
8689
</select>
90+
8791
<select id="getHomepageInstancesByMenuIdEn" resultType="com.webank.wedatasphere.dss.server.dto.response.HomepageDemoInstanceVo">
8892
SELECT `id`,`menu_id`,`name`,`url`,`title_en` AS `title`,`description`,`icon`,`order`
8993
FROM dss_homepage_demo_instance
@@ -99,6 +103,7 @@
99103
`is_active` = 1
100104
</where>
101105
</select>
106+
102107
<select id="getHomepageVideosEn" resultType="com.webank.wedatasphere.dss.server.dto.response.HomepageVideoVo">
103108
SELECT `id`,`name`,`title_en` AS `title`,`url`,`description`,`order`
104109
FROM dss_homepage_video
@@ -114,6 +119,7 @@
114119
`is_active` = 0
115120
</where>
116121
</select>
122+
117123
<select id="getManagementMenuEn" resultType="com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo">
118124
SELECT `id`,`name`,`title_en` AS `title`,`order`
119125
FROM dss_onestop_menu
@@ -129,6 +135,7 @@
129135
`is_active` = 1
130136
</where>
131137
</select>
138+
132139
<select id="getApplicationMenuEn" resultType="com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo">
133140
SELECT `id`,`name`,`title_en` AS `title`,`order`
134141
FROM dss_onestop_menu
@@ -146,6 +153,7 @@
146153
m.`onestop_menu_id` = #{id}
147154
</where>
148155
</select>
156+
149157
<select id="getMenuAppInstancesEn" resultType="com.webank.wedatasphere.dss.server.dto.response.OnestopMenuAppInstanceVo">
150158
SELECT <include refid = "menu_appInstances_en"/>
151159
FROM dss_onestop_menu_application m
@@ -155,4 +163,38 @@
155163
m.`onestop_menu_id` = #{id}
156164
</where>
157165
</select>
166+
167+
<select id="getWorkspaceFavoritesCn" resultType="com.webank.wedatasphere.dss.server.dto.response.WorkspaceFavoriteVo">
168+
SELECT dss_onestop_user_favorites.id, dss_onestop_menu_application.id AS menuApplicationId , name, url, icon, title_cn AS title
169+
FROM dss_onestop_user_favorites join dss_onestop_menu_application
170+
on dss_onestop_user_favorites.menu_application_id = dss_onestop_menu_application.id
171+
join dss_application on dss_application.id = dss_onestop_menu_application.application_id
172+
<where>
173+
dss_onestop_user_favorites.`username` = #{username} and `workspace_id` = #{workspaceId}
174+
</where>
175+
</select>
176+
177+
<select id="getWorkspaceFavoritesEn" resultType="com.webank.wedatasphere.dss.server.dto.response.WorkspaceFavoriteVo">
178+
SELECT dss_onestop_user_favorites.id, dss_onestop_menu_application.id AS menuApplicationId, name, url, icon, title_en AS `title`
179+
FROM dss_onestop_user_favorites join dss_onestop_menu_application
180+
on dss_onestop_user_favorites.menu_application_id = dss_onestop_menu_application.id
181+
join dss_application on dss_application.id = dss_onestop_menu_application.application_id
182+
<where>
183+
dss_onestop_user_favorites.`username` = #{username} and `workspace_id` = #{workspaceId}
184+
</where>
185+
</select>
186+
187+
<insert id="addFavorite" useGeneratedKeys="true" keyProperty="id" parameterType="com.webank.wedatasphere.dss.server.entity.DWSFavorite">
188+
INSERT INTO dss_onestop_user_favorites (<include refid = "favorite_main" />)
189+
VALUES
190+
(#{id},#{username},#{workspaceId},#{menuApplicationId},#{order},#{createBy},#{createTime},#{lastUpdateUser},#{lastUpdateTime})
191+
</insert>
192+
193+
<delete id="deleteFavorite">
194+
DELETE
195+
FROM
196+
dss_onestop_user_favorites
197+
WHERE
198+
id = #{favouritesId}
199+
</delete>
158200
</mapper>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.webank.wedatasphere.dss.server.dto.response;
2+
3+
/**
4+
* Created by Adamyuanyuan on 2020/6/25
5+
*/
6+
public class WorkspaceFavoriteVo {
7+
private Long id;
8+
9+
private Long menuApplicationId;
10+
11+
private String name;
12+
13+
private String url;
14+
15+
private String icon;
16+
17+
private String title;
18+
19+
public Long getId() {
20+
return id;
21+
}
22+
23+
public void setId(Long id) {
24+
this.id = id;
25+
}
26+
public String getName() {
27+
return name;
28+
}
29+
30+
public void setName(String name) {
31+
this.name = name;
32+
}
33+
34+
public Long getMenuApplicationId() {
35+
return menuApplicationId;
36+
}
37+
38+
public void setMenuApplicationId(Long menuApplicationId) {
39+
this.menuApplicationId = menuApplicationId;
40+
}
41+
42+
public String getUrl() {
43+
return url;
44+
}
45+
46+
public void setUrl(String url) {
47+
this.url = url;
48+
}
49+
50+
public String getIcon() {
51+
return icon;
52+
}
53+
54+
public void setIcon(String icon) {
55+
this.icon = icon;
56+
}
57+
58+
public String getTitle() {
59+
return title;
60+
}
61+
62+
public void setTitle(String title) {
63+
this.title = title;
64+
}
65+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.webank.wedatasphere.dss.server.entity;
2+
3+
/**
4+
* Created by Adamyuanyuan on 2020/6/25
5+
*/
6+
public class DWSFavorite extends BaseEntity{
7+
8+
private Long id;
9+
10+
private String username;
11+
12+
private Long workspaceId;
13+
14+
private Long menuApplicationId;
15+
16+
private Integer order;
17+
18+
public Long getId() {
19+
return id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public String getUsername() {
27+
return username;
28+
}
29+
30+
public void setUsername(String username) {
31+
this.username = username;
32+
}
33+
34+
public Long getWorkspaceId() {
35+
return workspaceId;
36+
}
37+
38+
public void setWorkspaceId(Long workspaceId) {
39+
this.workspaceId = workspaceId;
40+
}
41+
42+
public Long getMenuApplicationId() {
43+
return menuApplicationId;
44+
}
45+
46+
public void setMenuApplicationId(Long menuApplicationId) {
47+
this.menuApplicationId = menuApplicationId;
48+
}
49+
50+
public Integer getOrder() {
51+
return order;
52+
}
53+
54+
public void setOrder(Integer order) {
55+
this.order = order;
56+
}
57+
}

dss-server/src/main/java/com/webank/wedatasphere/dss/server/restful/WorkspaceRestfulApi.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo;
66
import com.webank.wedatasphere.dss.server.entity.DWSWorkspace;
77
import com.webank.wedatasphere.dss.server.dto.response.WorkspaceDepartmentVo;
8+
import com.webank.wedatasphere.dss.application.service.DSSUserService;
9+
import com.webank.wedatasphere.dss.server.dto.response.*;
810
import com.webank.wedatasphere.dss.server.service.DWSWorkspaceService;
911
import com.webank.wedatasphere.linkis.server.Message;
1012
import com.webank.wedatasphere.linkis.server.security.SecurityFilter;
@@ -31,6 +33,8 @@ public class WorkspaceRestfulApi {
3133
@Autowired
3234
private DWSWorkspaceService dwsWorkspaceService;
3335

36+
@Autowired
37+
private DSSUserService dssUserService;
3438

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

47+
@GET
48+
@Path("/workspaces/{id}")
49+
public Response getWorkspacesById(@Context HttpServletRequest req, @PathParam("id") Long id) {
50+
DWSWorkspace workspace = dwsWorkspaceService.getWorkspacesById(id);
51+
return Message.messageToResponse(Message.ok().data("workspace", workspace));
52+
}
53+
4354
@GET
4455
@Path("/workspaces/departments")
4556
public Response getAllWorkspaceDepartments(@Context HttpServletRequest req) {
@@ -89,7 +100,7 @@ public Response getAllVideos(@Context HttpServletRequest req) {
89100

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

101112
@GET
102113
@Path("workspaces/{workspaceId}/applications")
103-
public Response getWorkspaceApplications(@Context HttpServletRequest req, @PathParam("workspaceId")Long workspaceId) {
114+
public Response getWorkspaceApplications(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId) {
104115
String header = req.getHeader("Content-language").trim();
105116
boolean isChinese = "zh-CN".equals(header);
106117
String username = SecurityFilter.getLoginUsername(req);
107118
List<OnestopMenuVo> applications = dwsWorkspaceService.getWorkspaceApplications(workspaceId, username, isChinese);
108119
return Message.messageToResponse(Message.ok().data("applications", applications));
109120
}
121+
122+
@GET
123+
@Path("/workspaces/{workspaceId}/favorites")
124+
public Response getWorkspaceFavorites(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId) {
125+
String header = req.getHeader("Content-language").trim();
126+
boolean isChinese = "zh-CN".equals(header);
127+
String username = SecurityFilter.getLoginUsername(req);
128+
List<WorkspaceFavoriteVo> favorites = dwsWorkspaceService.getWorkspaceFavorites(workspaceId, username, isChinese);
129+
return Message.messageToResponse(Message.ok().data("favorites", favorites));
130+
}
131+
132+
/**
133+
* 应用加入收藏,返回收藏后id
134+
*
135+
* @param req
136+
* @param json
137+
* @return
138+
*/
139+
@POST
140+
@Path("/workspaces/{workspaceId}/favorites")
141+
public Response addFavorite(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId, JsonNode json) {
142+
String username = SecurityFilter.getLoginUsername(req);
143+
Long menuApplicationId = json.get("menuApplicationId").getLongValue();
144+
Long favoriteId = dwsWorkspaceService.addFavorite(username, workspaceId, menuApplicationId);
145+
return Message.messageToResponse(Message.ok().data("favoriteId", favoriteId));
146+
}
147+
148+
@DELETE
149+
@Path("/workspaces/{workspaceId}/favorites/{favouritesId}")
150+
public Response deleteFavorite(@Context HttpServletRequest req, @PathParam("workspaceId") Long workspaceId, @PathParam("favouritesId") Long favouritesId) {
151+
String username = SecurityFilter.getLoginUsername(req);
152+
Long favoriteId = dwsWorkspaceService.deleteFavorite(username, favouritesId);
153+
return Message.messageToResponse(Message.ok().data("favoriteId", favoriteId));
154+
}
110155
}

dss-server/src/main/java/com/webank/wedatasphere/dss/server/service/DWSWorkspaceService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.webank.wedatasphere.dss.server.dto.response.OnestopMenuVo;
66
import com.webank.wedatasphere.dss.server.entity.DWSWorkspace;
77
import com.webank.wedatasphere.dss.server.dto.response.WorkspaceDepartmentVo;
8+
import com.webank.wedatasphere.dss.server.dto.response.*;
89

910
import java.util.List;
1011

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

2930
List<OnestopMenuVo> getWorkspaceApplications(Long workspaceId, String username, boolean isChinese);
31+
32+
DWSWorkspace getWorkspacesById(Long id);
33+
34+
/**
35+
* 查询用户收藏的应用,如果是新用户,就在数据库给它插入默认两个收藏:脚本开发与工作流 workflow scriptis
36+
* @param workspaceId
37+
* @param username
38+
* @param isChinese
39+
* @return
40+
*/
41+
List<WorkspaceFavoriteVo> getWorkspaceFavorites(Long workspaceId, String username, boolean isChinese);
42+
43+
Long addFavorite(String username, Long workspaceId, Long menuApplicationId);
44+
45+
Long deleteFavorite(String username, Long favouritesId);
3046
}

0 commit comments

Comments
 (0)