Commit 8d86dd2c by Madhan Neethiraj

ATLAS-2457: updated classification to support multiple validity-periods

parent 5e496e5e
...@@ -116,11 +116,9 @@ public final class Constants { ...@@ -116,11 +116,9 @@ public final class Constants {
public static final String ATTRIBUTE_NAME_VERSION = "version"; public static final String ATTRIBUTE_NAME_VERSION = "version";
public static final String TEMP_STRUCT_NAME_PREFIX = "__tempQueryResultStruct"; public static final String TEMP_STRUCT_NAME_PREFIX = "__tempQueryResultStruct";
public static final String CLASSIFICATION_ENTITY_GUID = INTERNAL_PROPERTY_KEY_PREFIX + "entityGuid"; public static final String CLASSIFICATION_ENTITY_GUID = INTERNAL_PROPERTY_KEY_PREFIX + "entityGuid";
public static final String CLASSIFICATION_PROPAGATE_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "propagate"; public static final String CLASSIFICATION_PROPAGATE_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "propagate";
public static final String CLASSIFICATION_VALIDITY_PERIOD_STARTTIME_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "vp_startTime"; public static final String CLASSIFICATION_VALIDITY_PERIODS_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "validityPeriods";
public static final String CLASSIFICATION_VALIDITY_PERIOD_ENDTIME_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "vp_endTime";
public static final String CLASSIFICATION_VALIDITY_PERIOD_TIMEZONE_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "vp_timeZone";
private Constants() { private Constants() {
} }
......
...@@ -19,10 +19,12 @@ package org.apache.atlas.model.instance; ...@@ -19,10 +19,12 @@ package org.apache.atlas.model.instance;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
...@@ -51,9 +53,9 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ ...@@ -51,9 +53,9 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_
public class AtlasClassification extends AtlasStruct implements Serializable { public class AtlasClassification extends AtlasStruct implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String entityGuid = null; private String entityGuid = null;
private boolean propagate = true; private boolean propagate = true;
private TimeBoundary validityPeriod = null; private List<TimeBoundary> validityPeriods = null;
public AtlasClassification() { public AtlasClassification() {
...@@ -99,12 +101,25 @@ public class AtlasClassification extends AtlasStruct implements Serializable { ...@@ -99,12 +101,25 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
this.propagate = propagate; this.propagate = propagate;
} }
public TimeBoundary getValidityPeriod() { public List<TimeBoundary> getValidityPeriods() {
return validityPeriod; return validityPeriods;
} }
public void setValidityPeriod(TimeBoundary validityPeriod) { public void setValidityPeriods(List<TimeBoundary> validityPeriods) {
this.validityPeriod = validityPeriod; this.validityPeriods = validityPeriods;
}
@JsonIgnore
public void addValityPeriod(TimeBoundary validityPeriod) {
List<TimeBoundary> vpList = this.validityPeriods;
if (vpList == null) {
vpList = new ArrayList<>();
this.validityPeriods = vpList;
}
vpList.add(validityPeriod);
} }
@Override @Override
...@@ -115,7 +130,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable { ...@@ -115,7 +130,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
AtlasClassification that = (AtlasClassification) o; AtlasClassification that = (AtlasClassification) o;
return propagate == that.propagate && return propagate == that.propagate &&
Objects.equals(entityGuid, that.entityGuid) && Objects.equals(entityGuid, that.entityGuid) &&
Objects.equals(validityPeriod, that.validityPeriod); Objects.equals(validityPeriods, that.validityPeriods);
} }
@Override @Override
...@@ -129,7 +144,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable { ...@@ -129,7 +144,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
super.toString(sb); super.toString(sb);
sb.append("entityGuid='").append(entityGuid).append('\''); sb.append("entityGuid='").append(entityGuid).append('\'');
sb.append(", propagate=").append(propagate); sb.append(", propagate=").append(propagate);
sb.append(", validityPeriod=").append(validityPeriod); sb.append(", validityPeriods=").append(validityPeriods);
sb.append('}'); sb.append('}');
return sb.toString(); return sb.toString();
} }
......
...@@ -54,6 +54,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdg ...@@ -54,6 +54,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdg
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasJson;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.IteratorUtils; import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
...@@ -1591,12 +1592,13 @@ public class EntityGraphMapper { ...@@ -1591,12 +1592,13 @@ public class EntityGraphMapper {
private AtlasEdge mapClassification(EntityOperation operation, final EntityMutationContext context, AtlasClassification classification, private AtlasEdge mapClassification(EntityOperation operation, final EntityMutationContext context, AtlasClassification classification,
AtlasEntityType entityType, AtlasVertex parentInstanceVertex, AtlasVertex traitInstanceVertex) AtlasEntityType entityType, AtlasVertex parentInstanceVertex, AtlasVertex traitInstanceVertex)
throws AtlasBaseException { throws AtlasBaseException {
if (classification.getValidityPeriods() != null) {
String strValidityPeriods = AtlasJson.toJson(classification.getValidityPeriods());
TimeBoundary validityPeriod = classification.getValidityPeriod(); AtlasGraphUtilsV1.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VALIDITY_PERIODS_KEY, strValidityPeriods);
} else {
AtlasGraphUtilsV1.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VALIDITY_PERIOD_STARTTIME_KEY, validityPeriod != null ? validityPeriod.getStartTime() : null); // if 'null', don't update existing value in the classification
AtlasGraphUtilsV1.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VALIDITY_PERIOD_ENDTIME_KEY, validityPeriod != null ? validityPeriod.getEndTime() : null); }
AtlasGraphUtilsV1.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VALIDITY_PERIOD_TIMEZONE_KEY, validityPeriod != null ? validityPeriod.getTimeZone() : null);
// map all the attributes to this newly created AtlasVertex // map all the attributes to this newly created AtlasVertex
mapAttributes(classification, traitInstanceVertex, operation, context); mapAttributes(classification, traitInstanceVertex, operation, context);
......
...@@ -51,6 +51,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute; ...@@ -51,6 +51,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasJson;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -102,7 +103,8 @@ public final class EntityGraphRetriever { ...@@ -102,7 +103,8 @@ public final class EntityGraphRetriever {
private final String CREATE_TIME = "createTime"; private final String CREATE_TIME = "createTime";
private final String QUALIFIED_NAME = "qualifiedName"; private final String QUALIFIED_NAME = "qualifiedName";
private static final GraphHelper graphHelper = GraphHelper.getInstance(); private static final List<TimeBoundary> TIME_BOUNDARIES_LIST = new ArrayList<>();
private static final GraphHelper graphHelper = GraphHelper.getInstance();
private final AtlasTypeRegistry typeRegistry; private final AtlasTypeRegistry typeRegistry;
...@@ -218,12 +220,10 @@ public final class EntityGraphRetriever { ...@@ -218,12 +220,10 @@ public final class EntityGraphRetriever {
ret.setEntityGuid(AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class)); ret.setEntityGuid(AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class));
ret.setPropagate(AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_PROPAGATE_KEY, Boolean.class)); ret.setPropagate(AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_PROPAGATE_KEY, Boolean.class));
String vpStartTime = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIOD_STARTTIME_KEY, String.class); String strValidityPeriods = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class);
String vpEndTime = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIOD_ENDTIME_KEY, String.class);
String vpTimeZone = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIOD_TIMEZONE_KEY, String.class);
if (vpStartTime != null || vpEndTime != null || vpTimeZone != null) { if (strValidityPeriods != null) {
ret.setValidityPeriod(new TimeBoundary(vpStartTime, vpEndTime, vpTimeZone)); ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST.getClass()));
} }
mapAttributes(classificationVertex, ret, null); mapAttributes(classificationVertex, ret, null);
......
...@@ -463,7 +463,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT { ...@@ -463,7 +463,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
TimeBoundary validityPeriod = new TimeBoundary("2018/03/01 00:00:00", "2018/04/01 00:00:00", "GMT"); TimeBoundary validityPeriod = new TimeBoundary("2018/03/01 00:00:00", "2018/04/01 00:00:00", "GMT");
classification.setEntityGuid(tableGuid); classification.setEntityGuid(tableGuid);
classification.setValidityPeriod(validityPeriod); classification.addValityPeriod(validityPeriod);
atlasClientV2.addClassifications(tableGuid, Collections.singletonList(classification)); atlasClientV2.addClassifications(tableGuid, Collections.singletonList(classification));
...@@ -481,7 +481,9 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT { ...@@ -481,7 +481,9 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
foundClassification = true; foundClassification = true;
assertEquals(entityClassification.getTypeName(), piiTrait.getName()); assertEquals(entityClassification.getTypeName(), piiTrait.getName());
assertEquals(entityClassification.getValidityPeriod(), validityPeriod); assertNotNull(entityClassification.getValidityPeriods());
assertEquals(entityClassification.getValidityPeriods().size(), 1);
assertEquals(entityClassification.getValidityPeriods().get(0), validityPeriod);
assertEquals(entityClassification, classification); assertEquals(entityClassification, classification);
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment