use of org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method preUpdateCheck.
/**
* Check ends are the same and relationshipCategory is the same.
*
* We do this by comparing 2 relationshipDefs to avoid exposing the AtlasVertex to unit testing.
*
* @param newRelationshipDef
* @param existingRelationshipDef
* @throws AtlasBaseException
*/
public static void preUpdateCheck(AtlasRelationshipDef newRelationshipDef, AtlasRelationshipDef existingRelationshipDef) throws AtlasBaseException {
// do not allow renames of the Def.
String existingName = existingRelationshipDef.getName();
String newName = newRelationshipDef.getName();
if (!existingName.equals(newName)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_NAME_UPDATE, newRelationshipDef.getGuid(), existingName, newName);
}
RelationshipCategory existingRelationshipCategory = existingRelationshipDef.getRelationshipCategory();
RelationshipCategory newRelationshipCategory = newRelationshipDef.getRelationshipCategory();
if (!existingRelationshipCategory.equals(newRelationshipCategory)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_CATEGORY_UPDATE, newRelationshipDef.getName(), newRelationshipCategory.name(), existingRelationshipCategory.name());
}
AtlasRelationshipEndDef existingEnd1 = existingRelationshipDef.getEndDef1();
AtlasRelationshipEndDef newEnd1 = newRelationshipDef.getEndDef1();
if (!newEnd1.equals(existingEnd1)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END1_UPDATE, newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString());
}
AtlasRelationshipEndDef existingEnd2 = existingRelationshipDef.getEndDef2();
AtlasRelationshipEndDef newEnd2 = newRelationshipDef.getEndDef2();
if (!newEnd2.equals(existingEnd2)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END2_UPDATE, newRelationshipDef.getName(), newEnd2.toString(), existingEnd2.toString());
}
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method toRelationshipDef.
private AtlasRelationshipDef toRelationshipDef(AtlasVertex vertex) throws AtlasBaseException {
AtlasRelationshipDef ret = null;
if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.RELATIONSHIP)) {
String name = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
String description = vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
String version = vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class);
String end1Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END1_KEY, String.class);
String end2Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END2_KEY, String.class);
String relationStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, String.class);
String propagateStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, String.class);
// set the ends
AtlasRelationshipEndDef endDef1 = AtlasType.fromJson(end1Str, AtlasRelationshipEndDef.class);
AtlasRelationshipEndDef endDef2 = AtlasType.fromJson(end2Str, AtlasRelationshipEndDef.class);
// set the relationship Category
RelationshipCategory relationshipCategory = null;
for (RelationshipCategory value : RelationshipCategory.values()) {
if (value.name().equals(relationStr)) {
relationshipCategory = value;
}
}
// set the propagateTags
PropagateTags propagateTags = null;
for (PropagateTags value : PropagateTags.values()) {
if (value.name().equals(propagateStr)) {
propagateTags = value;
}
}
ret = new AtlasRelationshipDef(name, description, version, relationshipCategory, propagateTags, endDef1, endDef2);
// add in the attributes
AtlasStructDefStoreV1.toStructDef(vertex, ret, typeDefStore);
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory in project incubator-atlas by apache.
the class AtlasRelationshipDefStoreV1 method toRelationshipDef.
private AtlasRelationshipDef toRelationshipDef(AtlasVertex vertex) throws AtlasBaseException {
AtlasRelationshipDef ret = null;
if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.RELATIONSHIP)) {
String name = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
String description = vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
String version = vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class);
String end1Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END1_KEY, String.class);
String end2Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END2_KEY, String.class);
String relationStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, String.class);
String propagateStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, String.class);
// set the ends
AtlasRelationshipEndDef endDef1 = AtlasType.fromJson(end1Str, AtlasRelationshipEndDef.class);
AtlasRelationshipEndDef endDef2 = AtlasType.fromJson(end2Str, AtlasRelationshipEndDef.class);
// set the relationship Category
RelationshipCategory relationshipCategory = null;
for (RelationshipCategory value : RelationshipCategory.values()) {
if (value.name().equals(relationStr)) {
relationshipCategory = value;
}
}
// set the propagateTags
PropagateTags propagateTags = null;
for (PropagateTags value : PropagateTags.values()) {
if (value.name().equals(propagateStr)) {
propagateTags = value;
}
}
ret = new AtlasRelationshipDef(name, description, version, relationshipCategory, propagateTags, endDef1, endDef2);
// add in the attributes
AtlasStructDefStoreV1.toStructDef(vertex, ret, typeDefStore);
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory in project atlas by apache.
the class AtlasRelationshipType method validateAtlasRelationshipDef.
/**
* Throw an exception so we can junit easily.
*
* This method assumes that the 2 ends are not null.
*
* @param relationshipDef
* @throws AtlasBaseException
*/
public static void validateAtlasRelationshipDef(AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
RelationshipCategory relationshipCategory = relationshipDef.getRelationshipCategory();
String name = relationshipDef.getName();
boolean isContainer1 = endDef1.getIsContainer();
boolean isContainer2 = endDef2.getIsContainer();
if ((endDef1.getCardinality() == AtlasAttributeDef.Cardinality.LIST) || (endDef2.getCardinality() == AtlasAttributeDef.Cardinality.LIST)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_LIST_ON_END, name);
}
if (isContainer1 && isContainer2) {
// we support 0 or 1 of these flags.
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_DOUBLE_CONTAINERS, name);
}
if ((isContainer1 || isContainer2)) {
// we have an isContainer defined in an end
if (relationshipCategory == RelationshipCategory.ASSOCIATION) {
// associations are not containment relationships - so do not allow an endpoint with isContainer
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_ASSOCIATION_AND_CONTAINER, name);
}
} else {
// we do not have an isContainer defined on an end
if (relationshipCategory == RelationshipCategory.COMPOSITION) {
// COMPOSITION needs one end to be the container.
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_NO_CONTAINER, name);
} else if (relationshipCategory == RelationshipCategory.AGGREGATION) {
// AGGREGATION needs one end to be the container.
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_AGGREGATION_NO_CONTAINER, name);
}
}
if (relationshipCategory == RelationshipCategory.COMPOSITION) {
// composition children should not be multiple cardinality
if (endDef1.getCardinality() == AtlasAttributeDef.Cardinality.SET && !endDef1.getIsContainer()) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS, name);
}
if ((endDef2.getCardinality() == AtlasAttributeDef.Cardinality.SET) && !endDef2.getIsContainer()) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_COMPOSITION_MULTIPLE_PARENTS, name);
}
}
}
use of org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory in project incubator-atlas by apache.
the class AtlasRelationshipDefStoreV1 method preUpdateCheck.
/**
* Check ends are the same and relationshipCategory is the same.
*
* We do this by comparing 2 relationshipDefs to avoid exposing the AtlasVertex to unit testing.
*
* @param newRelationshipDef
* @param existingRelationshipDef
* @throws AtlasBaseException
*/
public static void preUpdateCheck(AtlasRelationshipDef newRelationshipDef, AtlasRelationshipDef existingRelationshipDef) throws AtlasBaseException {
// do not allow renames of the Def.
String existingName = existingRelationshipDef.getName();
String newName = newRelationshipDef.getName();
if (!existingName.equals(newName)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_NAME_UPDATE, newRelationshipDef.getGuid(), existingName, newName);
}
RelationshipCategory existingRelationshipCategory = existingRelationshipDef.getRelationshipCategory();
RelationshipCategory newRelationshipCategory = newRelationshipDef.getRelationshipCategory();
if (!existingRelationshipCategory.equals(newRelationshipCategory)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_CATEGORY_UPDATE, newRelationshipDef.getName(), newRelationshipCategory.name(), existingRelationshipCategory.name());
}
AtlasRelationshipEndDef existingEnd1 = existingRelationshipDef.getEndDef1();
AtlasRelationshipEndDef newEnd1 = newRelationshipDef.getEndDef1();
if (!newEnd1.equals(existingEnd1)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END1_UPDATE, newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString());
}
AtlasRelationshipEndDef existingEnd2 = existingRelationshipDef.getEndDef2();
AtlasRelationshipEndDef newEnd2 = newRelationshipDef.getEndDef2();
if (!newEnd2.equals(existingEnd2)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END2_UPDATE, newRelationshipDef.getName(), newEnd2.toString(), existingEnd2.toString());
}
}
Aggregations