Commit 8d86dd2c by Madhan Neethiraj

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

parent 5e496e5e
......@@ -118,9 +118,7 @@ public final class Constants {
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_VALIDITY_PERIOD_STARTTIME_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "vp_startTime";
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";
public static final String CLASSIFICATION_VALIDITY_PERIODS_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "validityPeriods";
private Constants() {
}
......
......@@ -19,10 +19,12 @@ package org.apache.atlas.model.instance;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -53,7 +55,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
private String entityGuid = null;
private boolean propagate = true;
private TimeBoundary validityPeriod = null;
private List<TimeBoundary> validityPeriods = null;
public AtlasClassification() {
......@@ -99,12 +101,25 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
this.propagate = propagate;
}
public TimeBoundary getValidityPeriod() {
return validityPeriod;
public List<TimeBoundary> getValidityPeriods() {
return validityPeriods;
}
public void setValidityPeriod(TimeBoundary validityPeriod) {
this.validityPeriod = validityPeriod;
public void setValidityPeriods(List<TimeBoundary> validityPeriods) {
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
......@@ -115,7 +130,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
AtlasClassification that = (AtlasClassification) o;
return propagate == that.propagate &&
Objects.equals(entityGuid, that.entityGuid) &&
Objects.equals(validityPeriod, that.validityPeriod);
Objects.equals(validityPeriods, that.validityPeriods);
}
@Override
......@@ -129,7 +144,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
super.toString(sb);
sb.append("entityGuid='").append(entityGuid).append('\'');
sb.append(", propagate=").append(propagate);
sb.append(", validityPeriod=").append(validityPeriod);
sb.append(", validityPeriods=").append(validityPeriods);
sb.append('}');
return sb.toString();
}
......
......@@ -54,6 +54,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdg
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasJson;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.MapUtils;
......@@ -1591,12 +1592,13 @@ public class EntityGraphMapper {
private AtlasEdge mapClassification(EntityOperation operation, final EntityMutationContext context, AtlasClassification classification,
AtlasEntityType entityType, AtlasVertex parentInstanceVertex, AtlasVertex traitInstanceVertex)
throws AtlasBaseException {
if (classification.getValidityPeriods() != null) {
String strValidityPeriods = AtlasJson.toJson(classification.getValidityPeriods());
TimeBoundary validityPeriod = classification.getValidityPeriod();
AtlasGraphUtilsV1.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VALIDITY_PERIOD_STARTTIME_KEY, validityPeriod != null ? validityPeriod.getStartTime() : null);
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);
AtlasGraphUtilsV1.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VALIDITY_PERIODS_KEY, strValidityPeriods);
} else {
// if 'null', don't update existing value in the classification
}
// map all the attributes to this newly created AtlasVertex
mapAttributes(classification, traitInstanceVertex, operation, context);
......
......@@ -51,6 +51,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasJson;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -102,6 +103,7 @@ public final class EntityGraphRetriever {
private final String CREATE_TIME = "createTime";
private final String QUALIFIED_NAME = "qualifiedName";
private static final List<TimeBoundary> TIME_BOUNDARIES_LIST = new ArrayList<>();
private static final GraphHelper graphHelper = GraphHelper.getInstance();
private final AtlasTypeRegistry typeRegistry;
......@@ -218,12 +220,10 @@ public final class EntityGraphRetriever {
ret.setEntityGuid(AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class));
ret.setPropagate(AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_PROPAGATE_KEY, Boolean.class));
String vpStartTime = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIOD_STARTTIME_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);
String strValidityPeriods = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class);
if (vpStartTime != null || vpEndTime != null || vpTimeZone != null) {
ret.setValidityPeriod(new TimeBoundary(vpStartTime, vpEndTime, vpTimeZone));
if (strValidityPeriods != null) {
ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST.getClass()));
}
mapAttributes(classificationVertex, ret, null);
......
......@@ -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");
classification.setEntityGuid(tableGuid);
classification.setValidityPeriod(validityPeriod);
classification.addValityPeriod(validityPeriod);
atlasClientV2.addClassifications(tableGuid, Collections.singletonList(classification));
......@@ -481,7 +481,9 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
foundClassification = true;
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);
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