Skip to content

Commit 430a8e7

Browse files
committed
change all readEntity to getEntity
1 parent b80b46c commit 430a8e7

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/CatalogPolicyEventServiceDelegator.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import jakarta.ws.rs.core.Response;
2727
import jakarta.ws.rs.core.SecurityContext;
2828
import org.apache.polaris.core.context.RealmContext;
29+
import org.apache.polaris.service.catalog.CatalogPrefixParser;
2930
import org.apache.polaris.service.catalog.api.PolarisCatalogPolicyApiService;
3031
import org.apache.polaris.service.catalog.common.CatalogAdapter;
3132
import org.apache.polaris.service.events.CatalogPolicyServiceEvents;
@@ -44,6 +45,7 @@ public class CatalogPolicyEventServiceDelegator
4445

4546
@Inject @Delegate PolicyCatalogAdapter delegate;
4647
@Inject PolarisEventListener polarisEventListener;
48+
@Inject CatalogPrefixParser prefixParser;
4749

4850
@Override
4951
public Response createPolicy(
@@ -52,15 +54,16 @@ public Response createPolicy(
5254
CreatePolicyRequest createPolicyRequest,
5355
RealmContext realmContext,
5456
SecurityContext securityContext) {
57+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
5558
polarisEventListener.onBeforeCreatePolicy(
5659
new CatalogPolicyServiceEvents.BeforeCreatePolicyEvent(
57-
prefix, namespace, createPolicyRequest));
60+
catalogName, namespace, createPolicyRequest));
5861
Response resp =
5962
delegate.createPolicy(
6063
prefix, namespace, createPolicyRequest, realmContext, securityContext);
6164
polarisEventListener.onAfterCreatePolicy(
6265
new CatalogPolicyServiceEvents.AfterCreatePolicyEvent(
63-
prefix, namespace, resp.readEntity(LoadPolicyResponse.class)));
66+
catalogName, namespace, (LoadPolicyResponse) resp.getEntity()));
6467
return resp;
6568
}
6669

@@ -73,13 +76,14 @@ public Response listPolicies(
7376
String policyType,
7477
RealmContext realmContext,
7578
SecurityContext securityContext) {
79+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
7680
polarisEventListener.onBeforeListPolicies(
77-
new CatalogPolicyServiceEvents.BeforeListPoliciesEvent(prefix, namespace, policyType));
81+
new CatalogPolicyServiceEvents.BeforeListPoliciesEvent(catalogName, namespace, policyType));
7882
Response resp =
7983
delegate.listPolicies(
8084
prefix, namespace, pageToken, pageSize, policyType, realmContext, securityContext);
8185
polarisEventListener.onAfterListPolicies(
82-
new CatalogPolicyServiceEvents.AfterListPoliciesEvent(prefix, namespace, policyType));
86+
new CatalogPolicyServiceEvents.AfterListPoliciesEvent(catalogName, namespace, policyType));
8387
return resp;
8488
}
8589

@@ -90,13 +94,14 @@ public Response loadPolicy(
9094
String policyName,
9195
RealmContext realmContext,
9296
SecurityContext securityContext) {
97+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
9398
polarisEventListener.onBeforeLoadPolicy(
94-
new CatalogPolicyServiceEvents.BeforeLoadPolicyEvent(prefix, namespace, policyName));
99+
new CatalogPolicyServiceEvents.BeforeLoadPolicyEvent(catalogName, namespace, policyName));
95100
Response resp =
96101
delegate.loadPolicy(prefix, namespace, policyName, realmContext, securityContext);
97102
polarisEventListener.onAfterLoadPolicy(
98103
new CatalogPolicyServiceEvents.AfterLoadPolicyEvent(
99-
prefix, namespace, resp.readEntity(LoadPolicyResponse.class)));
104+
catalogName, namespace, (LoadPolicyResponse) resp.getEntity()));
100105
return resp;
101106
}
102107

@@ -108,15 +113,16 @@ public Response updatePolicy(
108113
UpdatePolicyRequest updatePolicyRequest,
109114
RealmContext realmContext,
110115
SecurityContext securityContext) {
116+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
111117
polarisEventListener.onBeforeUpdatePolicy(
112118
new CatalogPolicyServiceEvents.BeforeUpdatePolicyEvent(
113-
prefix, namespace, policyName, updatePolicyRequest));
119+
catalogName, namespace, policyName, updatePolicyRequest));
114120
Response resp =
115121
delegate.updatePolicy(
116122
prefix, namespace, policyName, updatePolicyRequest, realmContext, securityContext);
117123
polarisEventListener.onAfterUpdatePolicy(
118124
new CatalogPolicyServiceEvents.AfterUpdatePolicyEvent(
119-
prefix, namespace, resp.readEntity(LoadPolicyResponse.class)));
125+
catalogName, namespace, (LoadPolicyResponse) resp.getEntity()));
120126
return resp;
121127
}
122128

@@ -128,15 +134,16 @@ public Response dropPolicy(
128134
Boolean detachAll,
129135
RealmContext realmContext,
130136
SecurityContext securityContext) {
137+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
131138
polarisEventListener.onBeforeDropPolicy(
132139
new CatalogPolicyServiceEvents.BeforeDropPolicyEvent(
133-
prefix, namespace, policyName, detachAll));
140+
catalogName, namespace, policyName, detachAll));
134141
Response resp =
135142
delegate.dropPolicy(
136143
prefix, namespace, policyName, detachAll, realmContext, securityContext);
137144
polarisEventListener.onAfterDropPolicy(
138145
new CatalogPolicyServiceEvents.AfterDropPolicyEvent(
139-
prefix, namespace, policyName, detachAll));
146+
catalogName, namespace, policyName, detachAll));
140147
return resp;
141148
}
142149

@@ -148,15 +155,16 @@ public Response attachPolicy(
148155
AttachPolicyRequest attachPolicyRequest,
149156
RealmContext realmContext,
150157
SecurityContext securityContext) {
158+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
151159
polarisEventListener.onBeforeAttachPolicy(
152160
new CatalogPolicyServiceEvents.BeforeAttachPolicyEvent(
153-
prefix, namespace, policyName, attachPolicyRequest));
161+
catalogName, namespace, policyName, attachPolicyRequest));
154162
Response resp =
155163
delegate.attachPolicy(
156164
prefix, namespace, policyName, attachPolicyRequest, realmContext, securityContext);
157165
polarisEventListener.onAfterAttachPolicy(
158166
new CatalogPolicyServiceEvents.AfterAttachPolicyEvent(
159-
prefix, namespace, policyName, attachPolicyRequest));
167+
catalogName, namespace, policyName, attachPolicyRequest));
160168
return resp;
161169
}
162170

@@ -168,15 +176,16 @@ public Response detachPolicy(
168176
DetachPolicyRequest detachPolicyRequest,
169177
RealmContext realmContext,
170178
SecurityContext securityContext) {
179+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
171180
polarisEventListener.onBeforeDetachPolicy(
172181
new CatalogPolicyServiceEvents.BeforeDetachPolicyEvent(
173-
prefix, namespace, policyName, detachPolicyRequest));
182+
catalogName, namespace, policyName, detachPolicyRequest));
174183
Response resp =
175184
delegate.detachPolicy(
176185
prefix, namespace, policyName, detachPolicyRequest, realmContext, securityContext);
177186
polarisEventListener.onAfterDetachPolicy(
178187
new CatalogPolicyServiceEvents.AfterDetachPolicyEvent(
179-
prefix, namespace, policyName, detachPolicyRequest));
188+
catalogName, namespace, policyName, detachPolicyRequest));
180189
return resp;
181190
}
182191

@@ -190,9 +199,10 @@ public Response getApplicablePolicies(
190199
String policyType,
191200
RealmContext realmContext,
192201
SecurityContext securityContext) {
202+
String catalogName = getCatalogFromPrefix(prefix, realmContext);
193203
polarisEventListener.onBeforeGetApplicablePolicies(
194204
new CatalogPolicyServiceEvents.BeforeGetApplicablePoliciesEvent(
195-
prefix, namespace, targetName, policyType));
205+
catalogName, namespace, targetName, policyType));
196206
Response resp =
197207
delegate.getApplicablePolicies(
198208
prefix,
@@ -205,11 +215,15 @@ public Response getApplicablePolicies(
205215
securityContext);
206216
polarisEventListener.onAfterGetApplicablePolicies(
207217
new CatalogPolicyServiceEvents.AfterGetApplicablePoliciesEvent(
208-
prefix,
218+
catalogName,
209219
namespace,
210220
targetName,
211221
policyType,
212-
resp.readEntity(GetApplicablePoliciesResponse.class)));
222+
(GetApplicablePoliciesResponse) resp.getEntity()));
213223
return resp;
214224
}
225+
226+
private String getCatalogFromPrefix(String prefix, RealmContext realmContext) {
227+
return prefixParser.prefixToCatalogName(realmContext, prefix);
228+
}
215229
}

runtime/service/src/main/java/org/apache/polaris/service/events/CatalogPolicyServiceEvents.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,66 +34,66 @@ public class CatalogPolicyServiceEvents {
3434

3535
// Policy CRUD Events
3636
public record BeforeCreatePolicyEvent(
37-
String prefix, String namespace, CreatePolicyRequest createPolicyRequest) {}
37+
String catalogName, String namespace, CreatePolicyRequest createPolicyRequest) {}
3838

3939
public record AfterCreatePolicyEvent(
40-
String prefix, String namespace, LoadPolicyResponse loadPolicyResponse) {}
40+
String catalogName, String namespace, LoadPolicyResponse loadPolicyResponse) {}
4141

42-
public record BeforeListPoliciesEvent(String prefix, String namespace, String policyType) {}
42+
public record BeforeListPoliciesEvent(String catalogName, String namespace, String policyType) {}
4343

44-
public record AfterListPoliciesEvent(String prefix, String namespace, String policyType) {}
44+
public record AfterListPoliciesEvent(String catalogName, String namespace, String policyType) {}
4545

46-
public record BeforeLoadPolicyEvent(String prefix, String namespace, String policyName) {}
46+
public record BeforeLoadPolicyEvent(String catalogName, String namespace, String policyName) {}
4747

4848
public record AfterLoadPolicyEvent(
49-
String prefix, String namespace, LoadPolicyResponse loadPolicyResponse) {}
49+
String catalogName, String namespace, LoadPolicyResponse loadPolicyResponse) {}
5050

5151
public record BeforeUpdatePolicyEvent(
52-
String prefix,
52+
String catalogName,
5353
String namespace,
5454
String policyName,
5555
UpdatePolicyRequest updatePolicyRequest) {}
5656

5757
public record AfterUpdatePolicyEvent(
58-
String prefix, String namespace, LoadPolicyResponse loadPolicyResponse) {}
58+
String catalogName, String namespace, LoadPolicyResponse loadPolicyResponse) {}
5959

6060
public record BeforeDropPolicyEvent(
61-
String prefix, String namespace, String policyName, Boolean detachAll) {}
61+
String catalogName, String namespace, String policyName, Boolean detachAll) {}
6262

6363
public record AfterDropPolicyEvent(
64-
String prefix, String namespace, String policyName, Boolean detachAll) {}
64+
String catalogName, String namespace, String policyName, Boolean detachAll) {}
6565

6666
// Policy Attachment Events
6767
public record BeforeAttachPolicyEvent(
68-
String prefix,
68+
String catalogName,
6969
String namespace,
7070
String policyName,
7171
AttachPolicyRequest attachPolicyRequest) {}
7272

7373
public record AfterAttachPolicyEvent(
74-
String prefix,
74+
String catalogName,
7575
String namespace,
7676
String policyName,
7777
AttachPolicyRequest attachPolicyRequest) {}
7878

7979
public record BeforeDetachPolicyEvent(
80-
String prefix,
80+
String catalogName,
8181
String namespace,
8282
String policyName,
8383
DetachPolicyRequest detachPolicyRequest) {}
8484

8585
public record AfterDetachPolicyEvent(
86-
String prefix,
86+
String catalogName,
8787
String namespace,
8888
String policyName,
8989
DetachPolicyRequest detachPolicyRequest) {}
9090

9191
// Policy Query Events
9292
public record BeforeGetApplicablePoliciesEvent(
93-
String prefix, String namespace, String targetName, String policyType) {}
93+
String catalogName, String namespace, String targetName, String policyType) {}
9494

9595
public record AfterGetApplicablePoliciesEvent(
96-
String prefix,
96+
String catalogName,
9797
String namespace,
9898
String targetName,
9999
String policyType,

0 commit comments

Comments
 (0)