Search in sources :

Example 86 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasEntityChangeNotifier method updateFullTextMapping.

private void updateFullTextMapping(String entityId, List<AtlasClassification> classifications) {
    try {
        if (!AtlasRepositoryConfiguration.isFullTextSearchEnabled()) {
            return;
        }
    } catch (AtlasException e) {
        LOG.warn("Unable to determine if FullText is disabled. Proceeding with FullText mapping");
    }
    if (StringUtils.isEmpty(entityId) || CollectionUtils.isEmpty(classifications)) {
        return;
    }
    AtlasVertex atlasVertex = AtlasGraphUtilsV1.findByGuid(entityId);
    if (atlasVertex == null) {
        return;
    }
    if (atlasVertex == null) {
        LOG.warn("updateFullTextMapping(): no entity exists with guid {}", entityId);
        return;
    }
    try {
        String classificationFullText = fullTextMapperV2.getIndexTextForClassifications(entityId, classifications);
        String existingFullText = (String) GraphHelper.getProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY);
        String newFullText = existingFullText + " " + classificationFullText;
        GraphHelper.setProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, newFullText);
    } catch (AtlasBaseException e) {
        LOG.error("FullText mapping failed for Vertex[ guid = {} ]", entityId, e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasException(org.apache.atlas.AtlasException)

Example 87 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructInstance method setByte.

public void setByte(String attrName, byte val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.BYTE_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.BYTE_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = false;
    bytes[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Example 88 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructInstance method get.

public Object get(String attrName) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    if (nullFlags[nullPos]) {
        if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE) {
            return ((DataTypes.PrimitiveType) i.dataType()).nullValue();
        } else {
            return null;
        }
    }
    if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
        return bools[pos];
    } else if (i.dataType() == DataTypes.BYTE_TYPE) {
        return bytes[pos];
    } else if (i.dataType() == DataTypes.SHORT_TYPE) {
        return shorts[pos];
    } else if (i.dataType() == DataTypes.INT_TYPE) {
        return ints[pos];
    } else if (i.dataType() == DataTypes.LONG_TYPE) {
        return longs[pos];
    } else if (i.dataType() == DataTypes.FLOAT_TYPE) {
        return floats[pos];
    } else if (i.dataType() == DataTypes.DOUBLE_TYPE) {
        return doubles[pos];
    } else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
        return bigIntegers[pos];
    } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
        return bigDecimals[pos];
    } else if (i.dataType() == DataTypes.DATE_TYPE) {
        return dates[pos];
    } else if (i.dataType() == DataTypes.STRING_TYPE) {
        return strings[pos];
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
        return ((EnumType) i.dataType()).fromOrdinal(ints[pos]);
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
        return arrays[pos];
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
        return maps[pos];
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
        return structs[pos];
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
        if (ids[pos] != null) {
            return ids[pos];
        } else {
            return referenceables[pos];
        }
    } else {
        throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Example 89 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructInstance method getDate.

public Date getDate(String attrName) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.DATE_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic get method", attrName, getTypeName(), DataTypes.DATE_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    if (nullFlags[nullPos]) {
        return DataTypes.DATE_TYPE.nullValue();
    }
    return dates[pos];
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Example 90 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructInstance method setShort.

public void setShort(String attrName, short val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.SHORT_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.SHORT_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = false;
    shorts[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Aggregations

AtlasException (org.apache.atlas.AtlasException)101 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)26 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)19 IOException (java.io.IOException)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 RepositoryException (org.apache.atlas.repository.RepositoryException)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)9 Configuration (org.apache.commons.configuration.Configuration)9 ArrayList (java.util.ArrayList)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)6 HashMap (java.util.HashMap)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)5 CatalogRuntimeException (org.apache.atlas.catalog.exception.CatalogRuntimeException)5 Referenceable (org.apache.atlas.typesystem.Referenceable)5 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)5