Skip to content

Commit

Permalink
RANGER-4035: DB schema update to persist XXAccessTypeDef.category - #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mneethiraj committed Oct 26, 2023
1 parent 9422101 commit 932f96a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ private boolean updateTagAccessTypeDefs(List<RangerServiceDef.RangerAccessTypeDe
tagAccessType.setName(prefix + svcAccessType.getName());
tagAccessType.setLabel(svcAccessType.getLabel());
tagAccessType.setRbKeyLabel(svcAccessType.getRbKeyLabel());
tagAccessType.setCategory(svcAccessType.getCategory());

tagAccessType.setImpliedGrants(new HashSet<String>());
if (CollectionUtils.isNotEmpty(svcAccessType.getImpliedGrants())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ CREATE TABLE `x_access_type_def` (
`name` varchar(1024) DEFAULT NULL,
`label` varchar(1024) DEFAULT NULL,
`rb_key_label` varchar(1024) DEFAULT NULL,
`category` smallint DEFAULT NULL,
`sort_order` int DEFAULT 0,
`datamask_options` varchar(1024) NULL DEFAULT NULL,
`rowfilter_options` varchar(1024) NULL DEFAULT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ item_id BIGINT NOT NULL,
name VARCHAR(1024) DEFAULT NULL NULL,
label VARCHAR(1024) DEFAULT NULL NULL,
rb_key_label VARCHAR(1024) DEFAULT NULL NULL,
category SMALLINT DEFAULT NULL NULL,
sort_order INT DEFAULT '0' NULL,
datamask_options VARCHAR(1024) DEFAULT NULL NULL,
rowfilter_options VARCHAR(1024) DEFAULT NULL NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.ranger.entity;

import javax.persistence.*;
import java.util.Objects;

@Entity
@Cacheable
Expand Down Expand Up @@ -82,6 +83,12 @@ public class XXAccessTypeDef extends XXDBBase implements java.io.Serializable {
@Column(name = "rb_key_label")
protected String rbKeyLabel;

/**
* category of the XXAccessTypeDef
*/
@Column(name = "category")
protected Short category;

/**
* order of the XXAccessTypeDef
* <ul>
Expand Down Expand Up @@ -229,6 +236,14 @@ public String getRbkeylabel() {
return this.rbKeyLabel;
}

public Short getCategory() {
return category;
}

public void setCategory(Short category) {
this.category = category;
}

/**
* This method sets the value to the member attribute <b> order</b> . You
* cannot set null to the attribute.
Expand Down Expand Up @@ -268,83 +283,26 @@ public void setDataMaskOptions(String dataMaskOptions) {
*/
@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
return false;
}
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
} else if (getClass() != obj.getClass()) {
return false;
}
if (getClass() != obj.getClass()) {
} else if (!super.equals(obj)) {
return false;
}

XXAccessTypeDef other = (XXAccessTypeDef) obj;
if (defId == null) {
if (other.defId != null) {
return false;
}
} else if (!defId.equals(other.defId)) {
return false;
}
if (itemId == null) {
if (other.itemId != null) {
return false;
}
} else if (!itemId.equals(other.itemId)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (label == null) {
if (other.label != null) {
return false;
}
} else if (!label.equals(other.label)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (order == null) {
if (other.order != null) {
return false;
}
} else if (!order.equals(other.order)) {
return false;
}
if (rbKeyLabel == null) {
if (other.rbKeyLabel != null) {
return false;
}
} else if (!rbKeyLabel.equals(other.rbKeyLabel)) {
return false;
}
if (dataMaskOptions == null) {
if (other.dataMaskOptions != null) {
return false;
}
} else if (!dataMaskOptions.equals(other.dataMaskOptions)) {
return false;
}
if (rowFilterOptions == null) {
if (other.rowFilterOptions != null) {
return false;
}
} else if (!rowFilterOptions.equals(other.rowFilterOptions)) {
return false;
}
return true;

return Objects.equals(defId, other.defId) &&
Objects.equals(itemId, other.itemId) &&
Objects.equals(id, other.id) &&
Objects.equals(name, other.name) &&
Objects.equals(label, other.label) &&
Objects.equals(rbKeyLabel, other.rbKeyLabel) &&
Objects.equals(category, other.category) &&
Objects.equals(dataMaskOptions, other.dataMaskOptions) &&
Objects.equals(rowFilterOptions, other.rowFilterOptions) &&
Objects.equals(order, other.order);
}

/*
Expand All @@ -356,7 +314,7 @@ public boolean equals(Object obj) {
public String toString() {
return "XXAccessTypeDef [" + super.toString() + " id=" + id
+ ", defId=" + defId + ", itemId=" + itemId + ", name=" + name + ", label=" + label
+ ", rbKeyLabel=" + rbKeyLabel + ", dataMaskOptions=" + dataMaskOptions
+ ", rbKeyLabel=" + rbKeyLabel + ", category=" + category + ", dataMaskOptions=" + dataMaskOptions
+ ", rowFilterOptions=" + rowFilterOptions + ", order=" + order + "]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.ranger.entity.*;
import org.apache.ranger.plugin.model.RangerServiceDef;
import org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef;
import org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef.AccessTypeCategory;
import org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef;
import org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskDef;
import org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskTypeDef;
Expand Down Expand Up @@ -410,6 +411,11 @@ public XXAccessTypeDef populateRangerAccessTypeDefToXX(RangerAccessTypeDef vObj,
xObj.setLabel(vObj.getLabel());
xObj.setRbkeylabel(vObj.getRbKeyLabel());
xObj.setOrder(AppConstants.DEFAULT_SORT_ORDER);

if (vObj.getCategory() != null) {
xObj.setCategory((short) vObj.getCategory().ordinal());
}

return xObj;
}

Expand All @@ -432,6 +438,10 @@ public RangerAccessTypeDef populateXXToRangerAccessTypeDef(XXAccessTypeDef xObj,
vObj.setRbKeyLabel(xObj.getRbkeylabel());
vObj.setImpliedGrants(impliedGrants);

if (xObj.getCategory() != null) {
vObj.setCategory(toAccessTypeCategory(xObj.getCategory()));
}

return vObj;
}

Expand Down Expand Up @@ -756,4 +766,18 @@ boolean addImplicitConditionExpressionIfNeeded(RangerServiceDef serviceDef) {

return ret;
}

private AccessTypeCategory toAccessTypeCategory(short val) {
AccessTypeCategory ret = null;

for (AccessTypeCategory category : AccessTypeCategory.values()) {
if (category.ordinal() == val) {
ret = category;

break;
}
}

return ret;
}
}

0 comments on commit 932f96a

Please sign in to comment.