1
1
/*
2
2
* This file is part of Hopsworks
3
- * Copyright (C) 2020, Logical Clocks AB. All rights reserved
3
+ * Copyright (C) 2024, Hopsworks AB. All rights reserved
4
4
*
5
5
* Hopsworks is free software: you can redistribute it and/or modify it under the terms of
6
6
* the GNU Affero General Public License as published by the Free Software Foundation,
13
13
* You should have received a copy of the GNU Affero General Public License along with this program.
14
14
* If not, see <https://www.gnu.org/licenses/>.
15
15
*/
16
+ package io .hops .hopsworks .api .featurestore .keyword ;
16
17
17
- package io .hops .hopsworks .api .featurestore ;
18
-
19
- import io .hops .hopsworks .common .featurestore .featureview .FeatureViewController ;
18
+ import io .hops .hopsworks .api .auth .key .ApiKeyRequired ;
19
+ import io .hops .hopsworks .api .featurestore .FeaturestoreKeywordBuilder ;
20
20
import io .hops .hopsworks .api .filter .AllowedProjectRoles ;
21
21
import io .hops .hopsworks .api .filter .Audience ;
22
- import io .hops .hopsworks .api .auth .key .ApiKeyRequired ;
23
22
import io .hops .hopsworks .common .api .ResourceRequest ;
24
23
import io .hops .hopsworks .common .featurestore .featuregroup .FeaturegroupController ;
25
24
import io .hops .hopsworks .common .featurestore .keyword .KeywordDTO ;
28
27
import io .hops .hopsworks .jwt .annotation .JWTRequired ;
29
28
import io .hops .hopsworks .persistence .entity .featurestore .Featurestore ;
30
29
import io .hops .hopsworks .persistence .entity .featurestore .featuregroup .Featuregroup ;
31
- import io .hops .hopsworks .persistence .entity .featurestore .featureview .FeatureView ;
32
- import io .hops .hopsworks .persistence .entity .featurestore .trainingdataset .TrainingDataset ;
33
30
import io .hops .hopsworks .persistence .entity .project .Project ;
34
31
import io .hops .hopsworks .persistence .entity .user .security .apiKey .ApiScope ;
35
- import io .hops .hopsworks .restutils .RESTCodes ;
36
32
import io .swagger .annotations .Api ;
37
33
import io .swagger .annotations .ApiOperation ;
38
34
55
51
import javax .ws .rs .core .UriInfo ;
56
52
import java .util .HashSet ;
57
53
import java .util .List ;
58
- import java .util .logging .Level ;
59
54
60
55
@ RequestScoped
61
56
@ TransactionAttribute (TransactionAttributeType .NEVER )
62
- @ Api (value = "Feature store labels resource" )
63
- public class FeaturestoreKeywordResource {
64
-
57
+ @ Api (value = "Feature Group Keywords Resource" )
58
+ public class FeatureGroupKeywordResource {
65
59
@ EJB
66
60
private FeaturegroupController featuregroupController ;
67
61
@ EJB
68
- private FeatureViewController featureViewController ;
69
- @ EJB
70
62
private FeaturestoreKeywordBuilder featurestoreKeywordBuilder ;
71
63
@ Inject
72
64
private FeatureStoreKeywordControllerIface keywordCtrl ;
73
65
74
66
private Project project ;
75
67
private Featurestore featurestore ;
76
68
private Featuregroup featuregroup ;
77
- private TrainingDataset trainingDataset ;
78
- private FeatureView featureView ;
79
69
80
70
public void setProject (Project project ) {
81
71
this .project = project ;
@@ -89,42 +79,20 @@ public void setFeatureGroupId(Integer featureGroupId) throws FeaturestoreExcepti
89
79
this .featuregroup = featuregroupController .getFeaturegroupById (featurestore , featureGroupId );
90
80
}
91
81
92
- public void setTrainingDataset (TrainingDataset trainingDataset ) {
93
- this .trainingDataset = trainingDataset ;
94
- }
95
-
96
- public void setFeatureView (String name , Integer version ) throws FeaturestoreException {
97
- this .featureView = featureViewController .getByNameVersionAndFeatureStore (name , version , featurestore );
98
- }
99
-
100
82
@ GET
101
83
@ Produces (MediaType .APPLICATION_JSON )
102
84
@ ApiOperation (value = "Get keywords" )
103
85
@ AllowedProjectRoles ({AllowedProjectRoles .DATA_OWNER , AllowedProjectRoles .DATA_SCIENTIST })
104
86
@ JWTRequired (acceptedTokens = {Audience .API , Audience .JOB },
105
- allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
87
+ allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
106
88
@ ApiKeyRequired (acceptedScopes = {ApiScope .FEATURESTORE },
107
- allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
89
+ allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
108
90
public Response getKeywords (@ Context SecurityContext sc ,
109
91
@ Context HttpServletRequest req ,
110
- @ Context UriInfo uriInfo )
111
- throws FeaturestoreException {
112
-
92
+ @ Context UriInfo uriInfo ) {
113
93
ResourceRequest resourceRequest = new ResourceRequest (ResourceRequest .Name .KEYWORDS );
114
- KeywordDTO dto ;
115
- if (featuregroup != null ) {
116
- List <String > keywords = keywordCtrl .getKeywords (featuregroup );
117
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featuregroup , keywords );
118
- } else if (trainingDataset != null ) {
119
- List <String > keywords = keywordCtrl .getKeywords (trainingDataset );
120
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , trainingDataset , keywords );
121
- } else if (featureView != null ) {
122
- List <String > keywords = keywordCtrl .getKeywords (featureView );
123
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featureView , keywords );
124
- } else {
125
- throw new FeaturestoreException (RESTCodes .FeaturestoreErrorCode .KEYWORD_ERROR , Level .FINE ,
126
- "Error building keyword object" );
127
- }
94
+ List <String > keywords = keywordCtrl .getKeywords (featuregroup );
95
+ KeywordDTO dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featuregroup , keywords );
128
96
return Response .ok ().entity (dto ).build ();
129
97
}
130
98
@@ -134,64 +102,36 @@ public Response getKeywords(@Context SecurityContext sc,
134
102
@ ApiOperation (value = "Create keywords or replace existing ones" )
135
103
@ AllowedProjectRoles ({AllowedProjectRoles .DATA_OWNER })
136
104
@ JWTRequired (acceptedTokens = {Audience .API , Audience .JOB },
137
- allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
105
+ allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
138
106
@ ApiKeyRequired (acceptedScopes = {ApiScope .FEATURESTORE },
139
- allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
107
+ allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
140
108
public Response replaceKeywords (@ Context SecurityContext sc ,
141
109
@ Context HttpServletRequest req ,
142
110
@ Context UriInfo uriInfo , KeywordDTO keywordDTO )
143
111
throws FeaturestoreException {
144
112
ResourceRequest resourceRequest = new ResourceRequest (ResourceRequest .Name .KEYWORDS );
145
113
KeywordDTO dto ;
146
- if (featuregroup != null ) {
147
- List <String > updatedKeywords = keywordCtrl .replaceKeywords (featuregroup ,
148
- new HashSet <>(keywordDTO .getKeywords ()));
149
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featuregroup , updatedKeywords );
150
- } else if (trainingDataset != null ) {
151
- List <String > updatedKeywords = keywordCtrl .replaceKeywords (trainingDataset ,
152
- new HashSet <>(keywordDTO .getKeywords ()));
153
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , trainingDataset , updatedKeywords );
154
- } else if (featureView != null ) {
155
- List <String > updatedKeywords = keywordCtrl .replaceKeywords (featureView ,
156
- new HashSet <>(keywordDTO .getKeywords ()));
157
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featureView , updatedKeywords );
158
- } else {
159
- throw new FeaturestoreException (RESTCodes .FeaturestoreErrorCode .KEYWORD_ERROR , Level .FINE ,
160
- "Error building keyword object" );
161
- }
114
+ List <String > updatedKeywords = keywordCtrl .replaceKeywords (featuregroup , new HashSet <>(keywordDTO .getKeywords ()));
115
+ dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featuregroup , updatedKeywords );
162
116
return Response .ok ().entity (dto ).build ();
163
117
}
164
118
165
119
@ DELETE
166
120
@ ApiOperation (value = "Delete a keyword" )
167
121
@ AllowedProjectRoles ({AllowedProjectRoles .DATA_OWNER })
168
122
@ JWTRequired (acceptedTokens = {Audience .API , Audience .JOB },
169
- allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
123
+ allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
170
124
@ ApiKeyRequired (acceptedScopes = {ApiScope .FEATURESTORE },
171
- allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
125
+ allowedUserRoles = {"HOPS_ADMIN" , "HOPS_USER" , "HOPS_SERVICE_USER" })
172
126
public Response deleteKeywords (@ Context SecurityContext sc ,
173
127
@ Context UriInfo uriInfo ,
174
128
@ Context HttpServletRequest req ,
175
129
@ QueryParam ("keyword" ) String keyword )
176
130
throws FeaturestoreException {
177
131
ResourceRequest resourceRequest = new ResourceRequest (ResourceRequest .Name .KEYWORDS );
178
- KeywordDTO dto ;
179
- if (featuregroup != null ) {
180
- keywordCtrl .deleteKeyword (featuregroup , keyword );
181
- List <String > updatedKeywords = keywordCtrl .getKeywords (featuregroup );
182
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featuregroup , updatedKeywords );
183
- } else if (trainingDataset != null ) {
184
- keywordCtrl .deleteKeyword (trainingDataset , keyword );
185
- List <String > updatedKeywords = keywordCtrl .getKeywords (trainingDataset );
186
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , trainingDataset , updatedKeywords );
187
- } else if (featureView != null ) {
188
- keywordCtrl .deleteKeyword (featureView , keyword );
189
- List <String > updatedKeywords = keywordCtrl .getKeywords (featureView );
190
- dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featureView , updatedKeywords );
191
- } else {
192
- throw new FeaturestoreException (RESTCodes .FeaturestoreErrorCode .KEYWORD_ERROR , Level .FINE ,
193
- "Error building keyword object" );
194
- }
132
+ keywordCtrl .deleteKeyword (featuregroup , keyword );
133
+ List <String > updatedKeywords = keywordCtrl .getKeywords (featuregroup );
134
+ KeywordDTO dto = featurestoreKeywordBuilder .build (uriInfo , resourceRequest , project , featuregroup , updatedKeywords );
195
135
return Response .ok ().entity (dto ).build ();
196
136
}
197
137
}
0 commit comments