Java Code Examples for org.apache.atlas.model.instance.AtlasClassification#getTypeName()

The following examples show how to use org.apache.atlas.model.instance.AtlasClassification#getTypeName() . 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: EntityAuditListenerV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
private boolean hasPropagatedEntry(Map<String, List<AtlasClassification>> propagationsMap, String guid, AtlasClassification classification) {
    boolean ret = false;

    if (MapUtils.isNotEmpty(propagationsMap) && propagationsMap.containsKey(guid) && CollectionUtils.isNotEmpty(propagationsMap.get(guid))) {
        List<AtlasClassification> classifications    = propagationsMap.get(guid);
        String                    classificationName = classification.getTypeName();
        String                    entityGuid         = classification.getEntityGuid();

        for (AtlasClassification c : classifications) {
            if (StringUtils.equals(c.getTypeName(), classificationName) && StringUtils.equals(c.getEntityGuid(), entityGuid)) {
                ret = true;
                break;
            }
        }
    }

    return ret;
}
 
Example 2
Source File: EntityGraphMapper.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void validateAndNormalizeForUpdate(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValueForUpdate(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValueForUpdate(classification);
}
 
Example 3
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValue(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValue(classification);
}
 
Example 4
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Validate if classification is not already associated with the entities
 *
 * @param guid            unique entity id
 * @param classifications list of classifications to be associated
 */
private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    List<String>    entityClassifications = getClassificationNames(guid);
    String          entityTypeName        = AtlasGraphUtilsV2.getTypeNameFromGuid(graph, guid);
    AtlasEntityType entityType            = typeRegistry.getEntityTypeByName(entityTypeName);

    for (AtlasClassification classification : classifications) {
        String newClassification = classification.getTypeName();

        if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid +
                    ", already associated with classification: " + newClassification);
        }

        // for each classification, check whether there are entities it should be restricted to
        AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(newClassification);

        if (!classificationType.canApplyToEntityType(entityType)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_ENTITY_FOR_CLASSIFICATION, guid, entityTypeName, newClassification);
        }
    }
}
 
Example 5
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValue(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValue(classification);
}
 
Example 6
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalizeForUpdate(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValueForUpdate(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValueForUpdate(classification);
}
 
Example 7
Source File: ClassificationPropagationTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void assertClassificationEquals(Set<AtlasClassification> propagatedClassifications, AtlasClassification expected) {
    String expectedTypeName = expected.getTypeName();
    for (AtlasClassification c : propagatedClassifications) {
        if(c.getTypeName().equals(expectedTypeName)) {
            assertTrue(c.isPropagate() == expected.isPropagate(), "isPropgate does not match");
            assertTrue(c.getValidityPeriods() == expected.getValidityPeriods(), "validityPeriods do not match");
            return;
        }
    }

    fail(expectedTypeName + " could not be found");
}
 
Example 8
Source File: ClassificationPropagationTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void assertClassificationExistInList(Set<AtlasClassification> classifications, AtlasClassification classification) {
    String  classificationName  = classification.getTypeName();
    String  entityGuid          = classification.getEntityGuid();
    boolean foundClassification = false;

    for (AtlasClassification c : classifications) {
        if (c.getTypeName().equals(classificationName) && c.getEntityGuid().equals(entityGuid)) {
            foundClassification = true;
        }
    }

    if (!foundClassification) {
        fail("Propagated classification is not present in classifications list!");
    }
}
 
Example 9
Source File: ClassificationPropagationTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void assertClassificationNotExistInEntity(String entityName, AtlasClassification classification) throws AtlasBaseException {
    List<AtlasClassification> classifications    = getEntity(entityName).getClassifications();
    String                    classificationName = classification.getTypeName();
    String                    entityGuid         = classification.getEntityGuid();

    if (CollectionUtils.isNotEmpty(classifications)) {
        for (AtlasClassification c : classifications) {
            if (c.getTypeName().equals(classificationName) && c.getEntityGuid().equals(entityGuid)) {
                fail("Propagated classification should not be present in entity!");
            }
        }
    }
}
 
Example 10
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Validate if classification is not already associated with the entities
 *
 * @param guid            unique entity id
 * @param classifications list of classifications to be associated
 */
private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    List<String> entityClassifications = getClassificationNames(guid);

    for (AtlasClassification classification : classifications) {
        String newClassification = classification.getTypeName();

        if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid +
                    ", already associated with classification: " + newClassification);
        }
    }
}
 
Example 11
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
@GraphTransaction
public void updateClassifications(String guid, List<AtlasClassification> newClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classifications={} for entity={}", newClassifications, guid);
    }

    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid not specified");
    }

    if (CollectionUtils.isEmpty(newClassifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }

    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    List<AtlasClassification> updatedClassifications = new ArrayList<>();

    for (AtlasClassification newClassification : newClassifications) {
        String              classificationName = newClassification.getTypeName();
        AtlasClassification oldClassification  = getClassification(guid, classificationName);

        if (oldClassification == null) {
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
        }

        validateAndNormalizeForUpdate(newClassification);

        Map<String, Object> newAttrs = newClassification.getAttributes();

        if (MapUtils.isNotEmpty(newAttrs)) {
            for (String attrName : newAttrs.keySet()) {
                oldClassification.setAttribute(attrName, newAttrs.get(attrName));
            }
        }

        entityGraphMapper.updateClassification(new EntityMutationContext(), guid, oldClassification);

        updatedClassifications.add(oldClassification);
    }

    // notify listeners on update to classifications
    entityChangeNotifier.onClassificationUpdatedToEntity(guid, updatedClassifications);
}