org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef Java Examples

The following examples show how to use org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef. 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: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void rectifyAttributesIfNeeded(final Set<String> entityNames, AtlasStructDef structDef) {
    List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();

    if (CollectionUtils.isNotEmpty(attributeDefs)) {
        for (AtlasAttributeDef attributeDef : attributeDefs) {
            if (!hasOwnedReferenceConstraint(attributeDef.getConstraints())) {
                continue;
            }

            Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());

            boolean valid = false;

            for (String referencedTypeName : referencedTypeNames) {
                if (entityNames.contains(referencedTypeName)) {
                    valid = true;
                    break;
                }
            }

            if (!valid) {
                rectifyOwnedReferenceError(structDef, attributeDef);
            }
        }
    }
}
 
Example #2
Source File: GraphBackedSearchIndexer.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void cleanupIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) {
    final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
    String attribTypeName = attributeDef.getTypeName();
    boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
    boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
    boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);

    try {
        AtlasType atlasType = typeRegistry.getType(attribTypeName);

        if (isMapType || isArrayType || isClassificationType(atlasType) || isEntityType(atlasType)) {
            LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
        } else if (isBuiltInType || isEnumType(atlasType)) {
            cleanupIndex(management, propertyName);
        } else if (isStructType(atlasType)) {
            AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName);
            cleanupIndices(management, structDef);
        }
    } catch (AtlasBaseException e) {
        LOG.error("No type exists for {}", attribTypeName, e);
    }
}
 
Example #3
Source File: UniqueAttributePatch.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void processIndexStringAttribute(Long vertexId, AtlasVertex vertex, String typeName, AtlasEntityType entityType) {
    for (AtlasAttribute attribute : entityType.getAllAttributes().values()) {
        if (attribute.getAttributeDef().getIndexType() != null &&
                attribute.getAttributeDef().getIndexType() == AtlasAttributeDef.IndexType.STRING) {

            String vertexPropertyName = attribute.getVertexPropertyName();
            if (vertex.getProperty(vertexPropertyName, String.class) != null) {
                continue;
            }

            Object attrVal = AtlasGraphUtilsV2.getEncodedProperty(vertex, attribute.getQualifiedName(), String.class);
            if (attrVal != null) {
                AtlasGraphUtilsV2.setEncodedProperty(vertex, vertexPropertyName, attrVal);
            }
        }
    }

    LOG.debug("processIndexStringAttribute(typeName={}, vertexId={}): Done!", typeName, vertexId);
}
 
Example #4
Source File: GraphBackedSearchIndexer.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void addIndexForType(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
    if (typeDef instanceof AtlasEnumDef) {
        // Only handle complex types like Struct, Classification and Entity
        return;
    }
    if (typeDef instanceof AtlasStructDef) {
        AtlasStructDef structDef = (AtlasStructDef) typeDef;
        List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
        if (CollectionUtils.isNotEmpty(attributeDefs)) {
            for (AtlasAttributeDef attributeDef : attributeDefs) {
                createIndexForAttribute(management, structDef, attributeDef);
            }
        }
    } else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())){
        throw new IllegalArgumentException("bad data type" + typeDef.getName());
    }
}
 
Example #5
Source File: GraphBackedSearchIndexer.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void addIndexForType(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
    if (typeDef instanceof AtlasEnumDef) {
        // Only handle complex types like Struct, Classification and Entity
        return;
    }
    if (typeDef instanceof AtlasStructDef) {
        AtlasStructDef structDef = (AtlasStructDef) typeDef;
        List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
        if (CollectionUtils.isNotEmpty(attributeDefs)) {
            for (AtlasAttributeDef attributeDef : attributeDefs) {
                createIndexForAttribute(management, typeDef.getName(), attributeDef);
            }
        }
    } else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())){
        throw new IllegalArgumentException("bad data type" + typeDef.getName());
    }
}
 
Example #6
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static List<AtlasStructDef> toAtlasStructDefs(List<StructTypeDefinition> structTypeDefinitions) {
    List<AtlasStructDef> ret = new ArrayList<>();

    for (StructTypeDefinition structType : structTypeDefinitions) {
        List<AtlasAttributeDef> attrDefs  = new ArrayList<AtlasAttributeDef>();

        if (CollectionUtils.isNotEmpty(structType.getAttributeDefinitions())) {
            for (AttributeDefinition attrDefinition : structType.getAttributeDefinitions()) {
                attrDefs.add(toAtlasAttributeDef(attrDefinition));
            }
        }

        AtlasStructDef structDef = new AtlasStructDef(structType.getTypeName(), structType.getTypeDescription(), structType.getTypeVersion(), attrDefs);

        ret.add(structDef);
    }

    return ret;
}
 
Example #7
Source File: GraphBackedSearchIndexer.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void createEdgeLabelsForStruct(AtlasGraphManagement management, AtlasEntityDef entityDef) {
    try {
        AtlasType type = typeRegistry.getType(entityDef.getName());
        if (!(type instanceof AtlasEntityType)) {
            return;
        }

        AtlasEntityType entityType = (AtlasEntityType) type;
        for (AtlasAttributeDef attributeDef : entityDef.getAttributeDefs()) {
            AtlasAttribute attribute = entityType.getAttribute(attributeDef.getName());
            if (attribute.getAttributeType().getTypeCategory() == TypeCategory.STRUCT) {
                String relationshipLabel = attribute.getRelationshipEdgeLabel();
                createEdgeLabelUsingLabelName(management, relationshipLabel);
            }
        }
    } catch (AtlasBaseException e) {
        LOG.error("Error fetching type: {}", entityDef.getName(), e);
    }
}
 
Example #8
Source File: AtlasTypeDefStoreInitializer.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static boolean updateTypeAttributes(AtlasStructDef oldStructDef, AtlasStructDef newStructDef, boolean checkTypeVersion) {
    boolean ret = isTypeUpdateApplicable(oldStructDef, newStructDef, checkTypeVersion);

    if (ret) {
        // make sure that all attributes in oldDef are in newDef as well
        if (CollectionUtils.isNotEmpty(oldStructDef.getAttributeDefs())){
            for (AtlasAttributeDef oldAttrDef : oldStructDef.getAttributeDefs()) {
                if (!newStructDef.hasAttribute(oldAttrDef.getName())) {
                    newStructDef.addAttribute(oldAttrDef);
                }
            }
        }
    }

    return ret;
}
 
Example #9
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static Multiplicity getMultiplicity(AtlasAttributeDef attributeDef) {
    int lower;
    int upper;
    if (attributeDef.getCardinality() == Cardinality.SINGLE) {
        lower = attributeDef.getIsOptional() ? 0 : 1;
        upper = 1;
    } else {
        if(attributeDef.getIsOptional()) {
            lower = 0;
        } else {
            lower = attributeDef.getValuesMinCount() < 1 ? 1 : attributeDef.getValuesMinCount();
        }

        upper = attributeDef.getValuesMaxCount() < 2 ? Integer.MAX_VALUE : attributeDef.getValuesMaxCount();
    }

    return new Multiplicity(lower, upper, Cardinality.SET.equals(attributeDef.getCardinality()));
}
 
Example #10
Source File: EntityGraphMapper.java    From atlas with Apache License 2.0 6 votes vote down vote up
private AtlasEdge updateEdge(AtlasAttributeDef attributeDef, Object value, AtlasEdge currentEdge, final AtlasVertex entityVertex) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating entity reference {} for reference attribute {}",  attributeDef.getName());
    }

    AtlasVertex currentVertex   = currentEdge.getInVertex();
    String      currentEntityId = getIdFromVertex(currentVertex);
    String      newEntityId     = getIdFromVertex(entityVertex);
    AtlasEdge   newEdge         = currentEdge;

    if (!currentEntityId.equals(newEntityId) && entityVertex != null) {
        try {
            newEdge = graphHelper.getOrCreateEdge(currentEdge.getOutVertex(), entityVertex, currentEdge.getLabel());
        } catch (RepositoryException e) {
            throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
        }
    }

    return newEdge;
}
 
Example #11
Source File: GraphBackedSearchIndexer.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void cleanupIndices(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
    Preconditions.checkNotNull(typeDef, "Cannot process null typedef");
    if (LOG.isDebugEnabled()) {
        LOG.debug("Cleaning up index for {}", typeDef);
    }

    if (typeDef instanceof AtlasEnumDef) {
        // Only handle complex types like Struct, Classification and Entity
        return;
    }

    if (typeDef instanceof AtlasStructDef) {
        AtlasStructDef structDef = (AtlasStructDef) typeDef;
        List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
        if (CollectionUtils.isNotEmpty(attributeDefs)) {
            for (AtlasAttributeDef attributeDef : attributeDefs) {
                cleanupIndexForAttribute(management, typeDef.getName(), attributeDef);
            }
        }
    } else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())){
        throw new IllegalArgumentException("bad data type" + typeDef.getName());
    }
}
 
Example #12
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static AtlasStructDef toStructDef(AtlasVertex vertex, AtlasStructDef structDef,
                                         AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
    AtlasStructDef ret = (structDef != null) ? structDef :new AtlasStructDef();

    typeDefStore.vertexToTypeDef(vertex, ret);

    List<AtlasAttributeDef> attributeDefs = new ArrayList<>();
    List<String> attrNames = vertex.getProperty(AtlasGraphUtilsV1.getTypeDefPropertyKey(ret), List.class);

    if (CollectionUtils.isNotEmpty(attrNames)) {
        for (String attrName : attrNames) {
            String propertyKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(ret, attrName);
            String attribJson  = vertex.getProperty(GraphHelper.encodePropertyKey(propertyKey), String.class);

            attributeDefs.add(toAttributeDefFromJson(structDef, AtlasType.fromJson(attribJson, Map.class),
                              typeDefStore));
        }
    }
    ret.setAttributeDefs(attributeDefs);

    return ret;
}
 
Example #13
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef,
                                              AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
    Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());

    String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);

    for (String referencedTypeName : referencedTypeNames) {
        if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) {
            AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName);

            if (referencedTypeVertex == null) {
                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName());
            }

            String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName());

            typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label);
        }
    }
}
 
Example #14
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private Object getNormalizedValue(Object value, AtlasAttributeDef attributeDef) {
    AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

    if (attribute != null) {
        AtlasType attrType = attribute.getAttributeType();

        if (value == null) {
            if (!attributeDef.getIsOptional()) {
                return attrType.createDefaultValue();
            }
        } else {
            return attrType.getNormalizedValue(value);
        }
    }

    return null;
}
 
Example #15
Source File: AtlasStructType.java    From atlas with Apache License 2.0 6 votes vote down vote up
private boolean isAssignableValueForUpdate(Object value, AtlasAttributeDef attributeDef) {
    boolean ret = true;

    if (value != null) {
        AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

        if (attribute != null) {
            AtlasType attrType = attribute.getAttributeType();

            if (!attrType.isValidValueForUpdate(value)) {
                ret = false; // invalid value
            }
        }
    }

    return ret;
}
 
Example #16
Source File: AtlasStructType.java    From atlas with Apache License 2.0 6 votes vote down vote up
private boolean isAssignableValue(Object value, AtlasAttributeDef attributeDef) {
    boolean ret = true;

    if (value != null) {
        AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

        if (attribute != null) {
            AtlasType attrType = attribute.getAttributeType();

                if (!attrType.isValidValue(value)) {
                    ret = false; // invalid value
                }
        }
    } else if (!attributeDef.getIsOptional()) {
        ret = false; // mandatory attribute not present
    }

    return ret;
}
 
Example #17
Source File: AtlasStructType.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void populateDefaultValues(AtlasStruct obj) {
    if (obj != null) {
        Map<String, Object> attributes = obj.getAttributes();

        if (attributes == null) {
            attributes = new HashMap<>();
        }

        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            if (!attributeDef.getIsOptional()) {
                attributes.put(attributeDef.getName(), createDefaultValue(attributeDef));
            }
        }

        obj.setAttributes(attributes);
    }
}
 
Example #18
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private static List<AtlasEntityDef> toAtlasEntityDefs(List<HierarchicalTypeDefinition<ClassType>> classTypeDefinitions,
                                                      AtlasTypeRegistry registry) throws AtlasBaseException {
    List<AtlasEntityDef> atlasEntityDefs = new ArrayList<AtlasEntityDef>();

    for (HierarchicalTypeDefinition<ClassType> classType : classTypeDefinitions) {
        List<AtlasAttributeDef> attrDefs         = new ArrayList<AtlasAttributeDef>();
        AtlasEntityDef          atlasEntityDef   = new AtlasEntityDef();
        String                  classTypeDefName = classType.typeName;

        atlasEntityDef.setName(classTypeDefName);
        atlasEntityDef.setDescription(classType.typeDescription);
        atlasEntityDef.setTypeVersion(classType.typeVersion);
        atlasEntityDef.setSuperTypes(classType.superTypes);

        AttributeDefinition[] attrDefinitions = classType.attributeDefinitions;
        for (AttributeDefinition oldAttr : attrDefinitions) {
            AtlasAttributeDef newAttr = toAtlasAttributeDef(oldAttr);
            attrDefs.add(newAttr);
        }

        atlasEntityDef.setAttributeDefs(attrDefs);
        atlasEntityDefs.add(atlasEntityDef);
    }

    return atlasEntityDefs;
}
 
Example #19
Source File: AtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static AtlasEntityDef getRootEntityDef() {
    List<AtlasAttributeDef> attributeDefs = new ArrayList<AtlasAttributeDef>() {{
        add(new AtlasAttributeDef(TIMESTAMP_PROPERTY_KEY, ATLAS_TYPE_DATE, false, true));
        add(new AtlasAttributeDef(MODIFICATION_TIMESTAMP_PROPERTY_KEY, ATLAS_TYPE_DATE, false, true));
        add(new AtlasAttributeDef(MODIFIED_BY_KEY, ATLAS_TYPE_STRING, false, true));
        add(new AtlasAttributeDef(CREATED_BY_KEY, ATLAS_TYPE_STRING, false, true));
        add(new AtlasAttributeDef(STATE_PROPERTY_KEY, ATLAS_TYPE_STRING, false, true));

        add(new AtlasAttributeDef(GUID_PROPERTY_KEY, ATLAS_TYPE_STRING, true, true));
        add(new AtlasAttributeDef(HISTORICAL_GUID_PROPERTY_KEY, ATLAS_TYPE_STRING, true, true));
        add(new AtlasAttributeDef(TYPE_NAME_PROPERTY_KEY, ATLAS_TYPE_STRING, false, true));
        add(new AtlasAttributeDef(CLASSIFICATION_TEXT_KEY, ATLAS_TYPE_STRING, false, true));
        add(new AtlasAttributeDef(CLASSIFICATION_NAMES_KEY, ATLAS_TYPE_STRING, false, true));
        add(new AtlasAttributeDef(PROPAGATED_CLASSIFICATION_NAMES_KEY, ATLAS_TYPE_STRING, false, true));
        add(new AtlasAttributeDef(IS_INCOMPLETE_PROPERTY_KEY, ATLAS_TYPE_INT, false, true));
        add(new AtlasAttributeDef(LABELS_PROPERTY_KEY, ATLAS_TYPE_STRING, false, true));
        add(new AtlasAttributeDef(CUSTOM_ATTRIBUTES_PROPERTY_KEY, ATLAS_TYPE_STRING, false, true));
    }};

    return new AtlasEntityDef(ENTITY_ROOT_NAME, "Root entity for system attributes", "1.0", attributeDefs);
}
 
Example #20
Source File: AtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
private boolean isAssignableValue(Object value, AtlasAttributeDef attributeDef) {
    boolean ret = true;

    if (value != null) {
        String         relationshipType = AtlasEntityUtil.getRelationshipType(value);
        AtlasAttribute attribute        = getRelationshipAttribute(attributeDef.getName(), relationshipType);

        if (attribute != null) {
            AtlasType attrType = attribute.getAttributeType();

            if (!isValidRelationshipType(attrType) && !attrType.isValidValue(value)) {
                ret = false;
            }
        }
    }

    return ret;
}
 
Example #21
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private boolean isAssignableValue(Object value, AtlasAttributeDef attributeDef) {
    boolean ret = true;

    if (value != null) {
        AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

        if (attribute != null) {
            AtlasType attrType = attribute.getAttributeType();

                if (!attrType.isValidValue(value)) {
                    ret = false; // invalid value
                }
        }
    } else if (!attributeDef.getIsOptional()) {
        ret = false; // mandatory attribute not present
    }

    return ret;
}
 
Example #22
Source File: AtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void collectTypeHierarchyInfo(AtlasTypeRegistry typeRegistry,
                                      Set<String> allSuperTypeNames,
                                      Map<String, AtlasAttribute> allAttributes,
                                      List<String> visitedTypes) throws AtlasBaseException {
    if (visitedTypes.contains(entityDef.getName())) {
        throw new AtlasBaseException(AtlasErrorCode.CIRCULAR_REFERENCE, entityDef.getName(),
                                     visitedTypes.toString());
    }

    if (CollectionUtils.isNotEmpty(entityDef.getSuperTypes())) {
        visitedTypes.add(entityDef.getName());
        for (String superTypeName : entityDef.getSuperTypes()) {
            AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName);

            if (superType != null) {
                superType.collectTypeHierarchyInfo(typeRegistry, allSuperTypeNames, allAttributes, visitedTypes);
            }
        }
        visitedTypes.remove(entityDef.getName());
        allSuperTypeNames.addAll(entityDef.getSuperTypes());
    }

    if (CollectionUtils.isNotEmpty(entityDef.getAttributeDefs())) {
        for (AtlasAttributeDef attributeDef : entityDef.getAttributeDefs()) {

            AtlasType type = typeRegistry.getType(attributeDef.getTypeName());
            allAttributes.put(attributeDef.getName(), new AtlasAttribute(this, attributeDef, type));
        }
    }
}
 
Example #23
Source File: AtlasTypeDefStoreInitializer.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void addOrUpdateAttributes(AtlasStructDef structDef, List<AtlasAttributeDef> attributesToUpdate) {
    for (AtlasAttributeDef attributeToUpdate : attributesToUpdate) {
        String attrName = attributeToUpdate.getName();

        if (structDef.hasAttribute(attrName)) {
            structDef.removeAttribute(attrName);
        }

        structDef.addAttribute(attributeToUpdate);
    }
}
 
Example #24
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValuesForUpdate(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attrDef : structDef.getAttributeDefs()) {
            String attrName  = attrDef.getName();
            Object attrValue = obj.get(attrName);

            if (obj.containsKey(attrName)) {
                attrValue = getNormalizedValueForUpdate(attrValue, attrDef);
                obj.put(attrName, attrValue);
            }
        }
    }
}
 
Example #25
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(AtlasStruct obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.hasAttribute(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.getAttribute(attributeName), attributeDef);

                obj.setAttribute(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.setAttribute(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
 
Example #26
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValuesForUpdate(AtlasStruct obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.hasAttribute(attributeName)) {
                Object attributeValue = getNormalizedValueForUpdate(obj.getAttribute(attributeName), attributeDef);
                obj.setAttribute(attributeName, attributeValue);
            }
        }
    }
}
 
Example #27
Source File: AtlasTypeUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasRelationshipDef createRelationshipTypeDef(String                  name,
                                                             String                  description,
                                                             String                  version,
                                                             RelationshipCategory    relationshipCategory,
                                                             PropagateTags           propagateTags,
                                                             AtlasRelationshipEndDef endDef1,
                                                             AtlasRelationshipEndDef endDef2,
                                                             AtlasAttributeDef...    attrDefs) {
    return new AtlasRelationshipDef(name, description, version, relationshipCategory, propagateTags,
                                    endDef1, endDef2, Arrays.asList(attrDefs));
}
 
Example #28
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValuesForUpdate(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attrDef : structDef.getAttributeDefs()) {
            String attrName  = attrDef.getName();
            Object attrValue = obj.get(attrName);

            if (obj.containsKey(attrName)) {
                attrValue = getNormalizedValueForUpdate(attrValue, attrDef);
                obj.put(attrName, attrValue);
            }
        }
    }
}
 
Example #29
Source File: GraphBackedSearchIndexer.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasCardinality toAtlasCardinality(AtlasAttributeDef.Cardinality cardinality) {
    switch (cardinality) {
        case SINGLE:
            return AtlasCardinality.SINGLE;
        case LIST:
            return AtlasCardinality.LIST;
        case SET:
            return AtlasCardinality.SET;
    }
    // Should never reach this point
    throw new IllegalArgumentException(String.format("Bad cardinality %s", cardinality));
}
 
Example #30
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.containsKey(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.get(attributeName), attributeDef);

                obj.put(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.put(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}