This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch RANGER-3923
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/RANGER-3923 by this push:
new ba960b237 RANGER-4530: fixed update APIs to not require guid in the
payload
ba960b237 is described below
commit ba960b237b46827f25ba85a6770154ff8dc4ea69
Author: Madhan Neethiraj <[email protected]>
AuthorDate: Thu Nov 16 09:25:24 2023 -0800
RANGER-4530: fixed update APIs to not require guid in the payload
---
.../java/org/apache/ranger/biz/GdsDBStore.java | 38 ++++++++++++++++++++++
.../main/java/org/apache/ranger/rest/GdsREST.java | 6 ----
2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/GdsDBStore.java
b/security-admin/src/main/java/org/apache/ranger/biz/GdsDBStore.java
index 6390f0547..589fcdd68 100755
--- a/security-admin/src/main/java/org/apache/ranger/biz/GdsDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/GdsDBStore.java
@@ -163,6 +163,8 @@ public class GdsDBStore extends AbstractGdsStore {
validator.validateUpdate(dataset, existing);
+ copyExistingBaseFields(dataset, existing);
+
RangerDataset ret = datasetService.update(dataset);
datasetService.onObjectChange(ret, existing,
RangerServiceService.OPERATION_UPDATE_CONTEXT);
@@ -455,6 +457,8 @@ public class GdsDBStore extends AbstractGdsStore {
validator.validateUpdate(project, existing);
+ copyExistingBaseFields(project, existing);
+
RangerProject ret = projectService.update(project);
projectService.onObjectChange(ret, existing,
RangerServiceService.OPERATION_UPDATE_CONTEXT);
@@ -754,6 +758,8 @@ public class GdsDBStore extends AbstractGdsStore {
validator.validateUpdate(dataShare, existing);
+ copyExistingBaseFields(dataShare, existing);
+
RangerDataShare ret = dataShareService.update(dataShare);
dataShareService.onObjectChange(ret, existing,
RangerServiceService.OPERATION_UPDATE_CONTEXT);
@@ -866,6 +872,8 @@ public class GdsDBStore extends AbstractGdsStore {
validator.validateUpdate(resource, existing);
+ copyExistingBaseFields(resource, existing);
+
RangerSharedResource ret = sharedResourceService.update(resource);
sharedResourceService.onObjectChange(ret, existing,
RangerServiceService.OPERATION_UPDATE_CONTEXT);
@@ -1005,6 +1013,8 @@ public class GdsDBStore extends AbstractGdsStore {
validator.validateUpdate(dataShareInDataset, existing);
+ copyExistingBaseFields(dataShareInDataset, existing);
+
dataShareInDataset.setApprover(validator.needApproverUpdate(existing.getStatus(),
dataShareInDataset.getStatus()) ? bizUtil.getCurrentUserLoginId() :
existing.getApprover());
RangerDataShareInDataset ret =
dataShareInDatasetService.update(dataShareInDataset);
@@ -1105,6 +1115,8 @@ public class GdsDBStore extends AbstractGdsStore {
validator.validateUpdate(datasetInProject, existing);
+ copyExistingBaseFields(datasetInProject, existing);
+
datasetInProject.setApprover(validator.needApproverUpdate(existing.getStatus(),
datasetInProject.getStatus()) ? bizUtil.getCurrentUserLoginId() :
existing.getApprover());
RangerDatasetInProject ret =
datasetInProjectService.update(datasetInProject);
@@ -1878,6 +1890,32 @@ public class GdsDBStore extends AbstractGdsStore {
}
}
+ private void copyExistingBaseFields(RangerGdsBaseModelObject objToUpdate,
RangerGdsBaseModelObject existingObj) {
+ if (objToUpdate != null && existingObj != null) {
+ // retain existing values for: guid, createdBy, createTime
+ objToUpdate.setGuid(existingObj.getGuid());
+ objToUpdate.setCreatedBy(existingObj.getCreatedBy());
+ objToUpdate.setCreateTime(existingObj.getCreateTime());
+
+ // retain existing values if objToUpdate has null for: isEnabled,
description, options, additionalInfo
+ if (objToUpdate.getIsEnabled() == null) {
+ objToUpdate.setIsEnabled(existingObj.getIsEnabled());
+ }
+
+ if (objToUpdate.getDescription() == null) {
+ objToUpdate.setDescription(existingObj.getDescription());
+ }
+
+ if (objToUpdate.getOptions() == null) {
+ objToUpdate.setOptions(existingObj.getOptions());
+ }
+
+ if (objToUpdate.getAdditionalInfo() == null) {
+ objToUpdate.setAdditionalInfo(existingObj.getAdditionalInfo());
+ }
+ }
+ }
+
private ServiceGdsInfo retrieveServiceGdsInfo(Long serviceId, String
serviceName) throws Exception {
ServiceGdsInfo ret = new ServiceGdsInfo();
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/GdsREST.java
b/security-admin/src/main/java/org/apache/ranger/rest/GdsREST.java
index b1dc9d37d..1c312e5e9 100755
--- a/security-admin/src/main/java/org/apache/ranger/rest/GdsREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/GdsREST.java
@@ -454,7 +454,6 @@ public class GdsREST {
@GET
@Path(("/dataset/{id}/policy/{policyId}"))
- @Consumes({ "application/json" })
@Produces({ "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" +
RangerAPIList.DATASET_POLICY + "\")")
public RangerPolicy getDatasetPolicy(@PathParam("id") Long datasetId,
@PathParam("policyId") Long policyId) {
@@ -482,7 +481,6 @@ public class GdsREST {
@GET
@Path(("/dataset/{id}/policy"))
- @Consumes({ "application/json" })
@Produces({ "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" +
RangerAPIList.DATASET_POLICY + "\")")
public List<RangerPolicy> getDatasetPolicies(@PathParam("id") Long
datasetId, @Context HttpServletRequest request) {
@@ -780,7 +778,6 @@ public class GdsREST {
@GET
@Path(("/project/{id}/policy/{policyId}"))
- @Consumes({ "application/json" })
@Produces({ "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" +
RangerAPIList.PROJECT_POLICY + "\")")
public RangerPolicy getProjectPolicy(@PathParam("id") Long projectId,
@PathParam("policyId") Long policyId) {
@@ -808,7 +805,6 @@ public class GdsREST {
@GET
@Path(("/project/{id}/policy"))
- @Consumes({ "application/json" })
@Produces({ "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" +
RangerAPIList.PROJECT_POLICY + "\")")
public List<RangerPolicy> getProjectPolicies(@PathParam("id") Long
projectId, @Context HttpServletRequest request) {
@@ -1277,7 +1273,6 @@ public class GdsREST {
@GET
@Path("/datashare/dataset/{id}")
- @Consumes({ "application/json" })
@Produces({ "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" +
RangerAPIList.GET_DATASHARE_IN_DATASET + "\")")
public RangerDataShareInDataset getDataShareInDataset(@PathParam("id")
Long id) {
@@ -1433,7 +1428,6 @@ public class GdsREST {
@GET
@Path("/dataset/project/{id}")
- @Consumes({ "application/json" })
@Produces({ "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" +
RangerAPIList.GET_DATASET_IN_PROJECT + "\")")
public RangerDatasetInProject getDatasetInProject(@PathParam("id") Long
id) {