Commit a0e4cd1a by Madhan Neethiraj

ATLAS-3051: on container entity-delete, contained entities in composition…

ATLAS-3051: on container entity-delete, contained entities in composition relationship should be deleted Change-Id: I6a5c2d19cd2bc96a32050150e88108fa63623d97
parent ef752a18
......@@ -289,8 +289,11 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
public AtlasAttributeDef() { this(null, null); }
public AtlasAttributeDef(String name, String typeName) {
this(name, typeName, false, Cardinality.SINGLE, COUNT_NOT_SET, COUNT_NOT_SET, false, false, false, null);
this(name, typeName, false, Cardinality.SINGLE);
}
public AtlasAttributeDef(String name, String typeName, boolean isOptional, Cardinality cardinality) {
this(name, typeName, isOptional, cardinality, COUNT_NOT_SET, COUNT_NOT_SET, false, false, false, null);
}
public AtlasAttributeDef(String name, String typeName, boolean isOptional, Cardinality cardinality,
......
......@@ -68,6 +68,7 @@ public class AtlasEntityType extends AtlasStructType {
private Set<String> typeAndAllSuperTypes = Collections.emptySet();
private Map<String, AtlasAttribute> relationshipAttributes = Collections.emptyMap();
private Map<String, List<AtlasRelationshipType>> relationshipAttributesType = Collections.emptyMap();
private List<AtlasAttribute> ownedRefAttributes = Collections.emptyList();
private String typeAndAllSubTypesQryStr = "";
private boolean isInternalType = false;
private Map<String, AtlasAttribute> headerAttributes = Collections.emptyMap();
......@@ -207,12 +208,27 @@ public class AtlasEntityType extends AtlasStructType {
}
}
subTypes = Collections.unmodifiableSet(subTypes);
allSubTypes = Collections.unmodifiableSet(allSubTypes);
typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes);
typeAndAllSubTypesQryStr = ""; // will be computed on next access
relationshipAttributes = Collections.unmodifiableMap(relationshipAttributes);
ownedRefAttributes = new ArrayList<>();
for (AtlasAttribute attribute : allAttributes.values()) {
if (attribute.isOwnedRef()) {
ownedRefAttributes.add(attribute);
}
}
for (AtlasAttribute attribute : relationshipAttributes.values()) {
if (attribute.isOwnedRef()) {
ownedRefAttributes.add(attribute);
}
}
subTypes = Collections.unmodifiableSet(subTypes);
allSubTypes = Collections.unmodifiableSet(allSubTypes);
typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes);
typeAndAllSubTypesQryStr = ""; // will be computed on next access
relationshipAttributes = Collections.unmodifiableMap(relationshipAttributes);
relationshipAttributesType = Collections.unmodifiableMap(relationshipAttributesType);
ownedRefAttributes = Collections.unmodifiableList(ownedRefAttributes);
entityDef.setSubTypes(subTypes);
}
......@@ -273,6 +289,10 @@ public class AtlasEntityType extends AtlasStructType {
return relationshipAttributes;
}
public List<AtlasAttribute> getOwnedRefAttributes() {
return ownedRefAttributes;
}
public AtlasAttribute getRelationshipAttribute(String attributeName) {
return relationshipAttributes.get(attributeName);
}
......@@ -753,6 +773,18 @@ public class AtlasEntityType extends AtlasStructType {
Object value = entityObj.getAttribute(attributeName);
String fieldName = objName + "." + attributeName;
if (!attribute.getAttributeDef().getIsOptional()) {
// if required attribute is null, check if attribute value specified in relationship
if (value == null) {
value = entityObj.getRelationshipAttribute(attributeName);
}
if (value == null) {
ret = false;
messages.add(fieldName + ": mandatory attribute value missing in type " + getTypeName());
}
}
if (isValidRelationshipType(dataType) && value != null) {
ret = dataType.validateValue(value, fieldName, messages) && ret;
}
......
......@@ -25,8 +25,10 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory;
import org.apache.atlas.model.typedef.AtlasRelationshipEndDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -34,6 +36,7 @@ import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.Objects;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN;
......@@ -120,9 +123,9 @@ public class AtlasRelationshipType extends AtlasStructType {
relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName());
}
addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel);
addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel, relationshipDef.getRelationshipCategory());
addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel);
addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel, relationshipDef.getRelationshipCategory());
// add relationship edge direction information
addRelationshipEdgeDirection();
......@@ -293,7 +296,7 @@ public class AtlasRelationshipType extends AtlasStructType {
}
private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName,
AtlasTypeRegistry typeRegistry, String relationshipLabel) throws AtlasBaseException {
AtlasTypeRegistry typeRegistry, String relationshipLabel, RelationshipCategory relationshipCategory) throws AtlasBaseException {
String attrName = (endDef != null) ? endDef.getName() : null;
......@@ -310,12 +313,29 @@ public class AtlasRelationshipType extends AtlasStructType {
}
if (attribute == null) { //attr doesn't exist in type - is a new relationship attribute
Cardinality cardinality = endDef.getCardinality();
boolean isOptional = true;
AtlasConstraintDef constraint = null;
if (endDef.getCardinality() == Cardinality.SET) {
if (cardinality == Cardinality.SET) {
attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName);
}
attribute = new AtlasAttribute(entityType, new AtlasAttributeDef(attrName, attrTypeName),
if (relationshipCategory == RelationshipCategory.COMPOSITION) {
if (endDef.getIsContainer()) {
constraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF);
} else {
isOptional = false;
}
}
AtlasAttributeDef attributeDef = new AtlasAttributeDef(attrName, attrTypeName, isOptional, cardinality);
if (constraint != null) {
attributeDef.addConstraint(constraint);
}
attribute = new AtlasAttribute(entityType, attributeDef,
typeRegistry.getType(attrTypeName), relationshipLabel);
} else {
......
......@@ -20,6 +20,7 @@ package org.apache.atlas.repository.ogm.glossary;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.type.AtlasTypeRegistry;
......@@ -123,6 +124,7 @@ public class AtlasGlossaryCategoryDTO extends AbstractGlossaryDTO<AtlasGlossaryC
ret.setAttribute("name", obj.getName());
ret.setAttribute("shortDescription", obj.getShortDescription());
ret.setAttribute("longDescription", obj.getLongDescription());
ret.setAttribute("anchor", new AtlasObjectId(obj.getAnchor().getGlossaryGuid()));
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasGlossaryCategoryDTO.toEntity() : {}", ret);
......
......@@ -20,6 +20,7 @@ package org.apache.atlas.repository.ogm.glossary;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.AtlasGlossaryTerm;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.type.AtlasTypeRegistry;
......@@ -218,6 +219,7 @@ public class AtlasGlossaryTermDTO extends AbstractGlossaryDTO<AtlasGlossaryTerm>
ret.setAttribute("examples", obj.getExamples());
ret.setAttribute("abbreviation", obj.getAbbreviation());
ret.setAttribute("usage", obj.getUsage());
ret.setAttribute("anchor", new AtlasObjectId(obj.getAnchor().getGlossaryGuid()));
if (CollectionUtils.isNotEmpty(obj.getClassifications())) {
if (LOG.isDebugEnabled()) {
......
......@@ -21,6 +21,7 @@ import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.discovery.SearchParameters;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.profile.AtlasUserSavedSearch;
import org.apache.atlas.repository.ogm.AbstractDataTransferObject;
import org.apache.atlas.type.AtlasType;
......@@ -29,22 +30,25 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Component
public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSavedSearch> {
private static final String ENTITY_TYPE_NAME = "__AtlasUserSavedSearch";
private static final String PROPERTY_NAME = "name";
private static final String PROPERTY_OWNER_NAME = "ownerName";
private static final String PROPERTY_SEARCH_PARAMETERS = "searchParameters";
private static final String PROPERTY_UNIQUE_NAME = "uniqueName";
private static final String PROPERTY_SEARCH_TYPE = "searchType";
private static final String PROPERTY_UI_PARAMETERS = "uiParameters";
private static final String PROPERTY_UI_PARAMETERS = "uiParameters";
private static final String PROPERTY_USER_PROFILE = "userProfile";
@Inject
public AtlasSavedSearchDTO(AtlasTypeRegistry typeRegistry) {
super(typeRegistry, AtlasUserSavedSearch.class, "__AtlasUserSavedSearch");
super(typeRegistry, AtlasUserSavedSearch.class, ENTITY_TYPE_NAME);
}
@Override
......@@ -76,10 +80,14 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
public AtlasEntity toEntity(AtlasUserSavedSearch obj) throws AtlasBaseException {
AtlasEntity entity = getDefaultAtlasEntity(obj);
AtlasObjectId userProfileId = new AtlasObjectId(AtlasUserProfileDTO.ENTITY_TYPE_NAME,
Collections.singletonMap(AtlasUserProfileDTO.PROPERTY_USER_NAME, obj.getOwnerName()));
entity.setAttribute(PROPERTY_NAME, obj.getName());
entity.setAttribute(PROPERTY_OWNER_NAME, obj.getOwnerName());
entity.setAttribute(PROPERTY_SEARCH_TYPE, obj.getSearchType());
entity.setAttribute(PROPERTY_UNIQUE_NAME, getUniqueValue(obj));
entity.setAttribute(PROPERTY_USER_PROFILE, userProfileId);
if (obj.getSearchParameters() != null) {
entity.setAttribute(PROPERTY_SEARCH_PARAMETERS, AtlasType.toJson(obj.getSearchParameters()));
......
......@@ -32,15 +32,16 @@ import java.util.*;
@Component
public class AtlasUserProfileDTO extends AbstractDataTransferObject<AtlasUserProfile> {
private final String PROPERTY_USER_NAME = "name";
private final String PROPERTY_FULL_NAME = "fullName";
private final String PROPERTY_SAVED_SEARCHES = "savedSearches";
public static final String ENTITY_TYPE_NAME = "__AtlasUserProfile";
public static final String PROPERTY_USER_NAME = "name";
private static final String PROPERTY_FULL_NAME = "fullName";
private static final String PROPERTY_SAVED_SEARCHES = "savedSearches";
private final AtlasSavedSearchDTO savedSearchDTO;
@Inject
public AtlasUserProfileDTO(AtlasTypeRegistry typeRegistry, AtlasSavedSearchDTO savedSearchDTO) {
super(typeRegistry, AtlasUserProfile.class, "__AtlasUserProfile");
super(typeRegistry, AtlasUserProfile.class, ENTITY_TYPE_NAME);
this.savedSearchDTO = savedSearchDTO;
}
......
......@@ -202,11 +202,7 @@ public abstract class DeleteHandlerV1 {
vertexInfoMap.put(guid, new GraphHelper.VertexInfo(entity, vertex));
for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getAllAttributes().values()) {
if (!attributeInfo.isOwnedRef()) {
continue;
}
for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getOwnedRefAttributes()) {
String edgeLabel = attributeInfo.getRelationshipEdgeLabel();
AtlasType attrType = attributeInfo.getAttributeType();
TypeCategory typeCategory = attrType.getTypeCategory();
......
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