Java Code Examples for org.apache.atlas.AtlasErrorCode#RELATIONSHIPDEF_INVALID_END2_UPDATE

The following examples show how to use org.apache.atlas.AtlasErrorCode#RELATIONSHIPDEF_INVALID_END2_UPDATE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasRelationshipDefStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 2
Source File: AtlasRelationshipDefStoreV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
/**
 * 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)){
        if (!RequestContext.get().isInTypePatching()) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_CATEGORY_UPDATE,
                    newRelationshipDef.getName(), newRelationshipCategory.name(),
                    existingRelationshipCategory.name());
        } else {
            LOG.warn("RELATIONSHIP UPDATE: relationship category from {} to {} for {}", existingRelationshipCategory.name(), newRelationshipCategory.name(), newRelationshipDef.getName());
        }
    }

    AtlasRelationshipEndDef existingEnd1 = existingRelationshipDef.getEndDef1();
    AtlasRelationshipEndDef existingEnd2 = existingRelationshipDef.getEndDef2();
    AtlasRelationshipEndDef newEnd1      = newRelationshipDef.getEndDef1();
    AtlasRelationshipEndDef newEnd2      = newRelationshipDef.getEndDef2();
    boolean                 endsSwaped   = false;

    if ( !isValidUpdate(existingEnd1, newEnd1) ) {
        if (RequestContext.get().isInTypePatching() && isValidUpdate(existingEnd1, newEnd2)) { // allow swap of ends during type-patch
            endsSwaped = true;
        } else {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END1_UPDATE,
                                         newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString());
        }
    }

    AtlasRelationshipEndDef newEndToCompareWith = endsSwaped ? newEnd1 : newEnd2;

    if ( !isValidUpdate(existingEnd2, newEndToCompareWith) ) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END2_UPDATE,
                                         newRelationshipDef.getName(), newEndToCompareWith.toString(), existingEnd2.toString());
    }
}