Repository: incubator-atlas Updated Branches: refs/heads/0.8-incubating 163beb0c2 -> 943e480c0
ATLAS-1657 Taxonomy term disassociation with assets fail Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/943e480c Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/943e480c Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/943e480c Branch: refs/heads/0.8-incubating Commit: 943e480c05549a8e4885af1e02bea28009796244 Parents: 163beb0 Author: Suma Shivaprasad <[email protected]> Authored: Tue Mar 7 19:03:24 2017 -0800 Committer: Suma Shivaprasad <[email protected]> Committed: Tue Mar 7 21:18:01 2017 -0800 ---------------------------------------------------------------------- .../apache/atlas/catalog/DefaultTypeSystem.java | 90 ++-- .../org/apache/atlas/type/AtlasTypeUtil.java | 7 +- .../converters/TypeConverterUtil.java | 412 ++++++++++++++++++ .../java/org/apache/atlas/util/RestUtils.java | 421 ------------------- .../atlas/web/resources/EntityService.java | 6 +- .../atlas/web/resources/TaxonomyService.java | 6 +- .../atlas/web/resources/TypesResource.java | 14 +- .../org/apache/atlas/util/RestUtilsTest.java | 6 +- .../web/resources/TaxonomyServiceTest.java | 67 +-- 9 files changed, 531 insertions(+), 498 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/catalog/src/main/java/org/apache/atlas/catalog/DefaultTypeSystem.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/DefaultTypeSystem.java b/catalog/src/main/java/org/apache/atlas/catalog/DefaultTypeSystem.java index ea967f9..eabd272 100644 --- a/catalog/src/main/java/org/apache/atlas/catalog/DefaultTypeSystem.java +++ b/catalog/src/main/java/org/apache/atlas/catalog/DefaultTypeSystem.java @@ -20,33 +20,35 @@ package org.apache.atlas.catalog; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasException; import org.apache.atlas.catalog.definition.ResourceDefinition; import org.apache.atlas.catalog.exception.CatalogRuntimeException; import org.apache.atlas.catalog.exception.ResourceAlreadyExistsException; import org.apache.atlas.catalog.exception.ResourceNotFoundException; import org.apache.atlas.classification.InterfaceAudience; +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.typedef.AtlasClassificationDef; +import org.apache.atlas.model.typedef.AtlasEntityDef; +import org.apache.atlas.model.typedef.AtlasEnumDef; +import org.apache.atlas.model.typedef.AtlasStructDef; +import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.repository.converters.TypeConverterUtil; import org.apache.atlas.services.MetadataService; +import org.apache.atlas.store.AtlasTypeDefStore; +import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Struct; -import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.exception.EntityExistsException; import org.apache.atlas.typesystem.exception.EntityNotFoundException; import org.apache.atlas.typesystem.exception.TraitNotFoundException; -import org.apache.atlas.typesystem.exception.TypeExistsException; -import org.apache.atlas.typesystem.exception.TypeNotFoundException; -import org.apache.atlas.typesystem.json.TypesSerialization; import org.apache.atlas.typesystem.types.AttributeDefinition; import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.EnumTypeDefinition; import org.apache.atlas.typesystem.types.HierarchicalType; -import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; -import org.apache.atlas.typesystem.types.StructTypeDefinition; import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.utils.TypesUtil; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -58,36 +60,43 @@ import java.util.Map; public class DefaultTypeSystem implements AtlasTypeSystem { private final MetadataService metadataService; + private final AtlasTypeDefStore typeDefStore; + /** * Constructor. * * @param metadataService atlas metadata service */ - public DefaultTypeSystem(MetadataService metadataService) throws AtlasException { + public DefaultTypeSystem(MetadataService metadataService, AtlasTypeDefStore typeDefStore) throws AtlasBaseException { this.metadataService = metadataService; + this.typeDefStore = typeDefStore; //Create namespace createSuperTypes(); } @InterfaceAudience.Private - private void createSuperTypes() throws AtlasException { - HierarchicalTypeDefinition<TraitType> termType = TypesUtil - .createTraitTypeDef(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE, ImmutableSet.<String>of(), - TypesUtil.createOptionalAttrDef(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, - DataTypes.STRING_TYPE)); + private void createSuperTypes() throws AtlasBaseException { + + AtlasClassificationDef termClassification = AtlasTypeUtil.createTraitTypeDef(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE, TaxonomyResourceProvider.TAXONOMY_TERM_TYPE, + ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, "string")); - createTraitType(termType); + createTraitType(termClassification); } - private void createTraitType(HierarchicalTypeDefinition<TraitType> type) throws AtlasException { + private void createTraitType(AtlasClassificationDef classificationDef) throws AtlasBaseException { try { - metadataService.getTypeDefinition(type.typeName); - } catch(TypeNotFoundException tne) { + typeDefStore.getClassificationDefByName(classificationDef.getName()); + } catch (AtlasBaseException tne) { //Type not found . Create - TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), - ImmutableList.of(type), - ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); - metadataService.createType(TypesSerialization.toJson(typesDef)); + if (tne.getAtlasErrorCode() == AtlasErrorCode.TYPE_NAME_NOT_FOUND) { + AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), + ImmutableList.of(classificationDef), + ImmutableList.<AtlasEntityDef>of()); + + typeDefStore.createTypesDef(typesDef); + } else { + throw tne; + } } } @@ -194,24 +203,37 @@ public class DefaultTypeSystem implements AtlasTypeSystem { String name, String description, boolean isTrait) - throws ResourceAlreadyExistsException { + throws ResourceAlreadyExistsException { try { - HierarchicalTypeDefinition<T> definition = null; + List<AtlasStructDef.AtlasAttributeDef> attrDefs = new ArrayList<>(); + for (AttributeDefinition attrDefinition : attributes) { + attrDefs.add(TypeConverterUtil.toAtlasAttributeDef(attrDefinition)); + } if ( isTrait) { - definition = new HierarchicalTypeDefinition<>(type, name, description, - ImmutableSet.of(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE), attributes.toArray(new AttributeDefinition[attributes.size()])); + AtlasClassificationDef classificationDef = new AtlasClassificationDef(name, description, "1.0", attrDefs, ImmutableSet.of(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)); + AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), + ImmutableList.of(classificationDef), + ImmutableList.<AtlasEntityDef>of()); + + typeDefStore.createTypesDef(typesDef); + } else { - definition = new HierarchicalTypeDefinition<>(type, name, description, - ImmutableSet.<String>of(), attributes.toArray(new AttributeDefinition[attributes.size()])); + AtlasEntityDef entityDef = new AtlasEntityDef(name, description, "1.0", attrDefs); + AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), + ImmutableList.<AtlasClassificationDef>of(), + ImmutableList.of(entityDef)); + + typeDefStore.createTypesDef(typesDef); } - metadataService.createType(TypesSerialization.toJson(definition, isTrait)); - } catch (TypeExistsException e) { - throw new ResourceAlreadyExistsException(String.format("Type '%s' already exists", name)); - } catch (AtlasException e) { - throw new CatalogRuntimeException(String.format( + } catch (AtlasBaseException e) { + if ( e.getAtlasErrorCode() == AtlasErrorCode.TYPE_ALREADY_EXISTS) { + throw new ResourceAlreadyExistsException(String.format("Type '%s' already exists", name)); + } else { + throw new CatalogRuntimeException(String.format( "Unable to create type '%s' in type system: %s", name, e), e); + } } } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java index 6d3a9f5..eca1abf 100644 --- a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java +++ b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java @@ -121,10 +121,11 @@ public class AtlasTypeUtil { } public static void validateType(AtlasBaseTypeDef typeDef) throws AtlasBaseException { - String typeName = typeDef.getName(); + boolean isValidName = (typeDef instanceof AtlasClassificationDef) ? isValidTraitTypeName(typeDef.getName()) + : isValidTypeName(typeDef.getName()); - if (!isValidTypeName(typeName)) { - throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID_FORMAT, typeName, typeDef.getCategory().name()); + if (!isValidName) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID_FORMAT, typeDef.getName(), typeDef.getCategory().name()); } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/repository/src/main/java/org/apache/atlas/repository/converters/TypeConverterUtil.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/TypeConverterUtil.java b/repository/src/main/java/org/apache/atlas/repository/converters/TypeConverterUtil.java new file mode 100644 index 0000000..7902100 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/converters/TypeConverterUtil.java @@ -0,0 +1,412 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.converters; + +import static org.apache.atlas.AtlasErrorCode.INVALID_TYPE_DEFINITION; +import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF; +import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF; +import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE; +import static org.apache.atlas.type.AtlasTypeUtil.isArrayType; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.typedef.AtlasClassificationDef; +import org.apache.atlas.model.typedef.AtlasEntityDef; +import org.apache.atlas.model.typedef.AtlasEnumDef; +import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef; +import org.apache.atlas.model.typedef.AtlasStructDef; +import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; +import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality; +import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef; +import org.apache.atlas.model.typedef.AtlasTypeDefHeader; +import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.repository.store.graph.v1.AtlasStructDefStoreV1; +import org.apache.atlas.type.AtlasClassificationType; +import org.apache.atlas.type.AtlasEntityType; +import org.apache.atlas.type.AtlasEnumType; +import org.apache.atlas.type.AtlasStructType; +import org.apache.atlas.type.AtlasStructType.AtlasAttribute; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.atlas.type.AtlasTypeUtil; +import org.apache.atlas.typesystem.TypesDef; +import org.apache.atlas.typesystem.json.TypesSerialization; +import org.apache.atlas.typesystem.types.AttributeDefinition; +import org.apache.atlas.typesystem.types.ClassType; +import org.apache.atlas.typesystem.types.EnumTypeDefinition; +import org.apache.atlas.typesystem.types.EnumValue; +import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; +import org.apache.atlas.typesystem.types.Multiplicity; +import org.apache.atlas.typesystem.types.StructTypeDefinition; +import org.apache.atlas.typesystem.types.TraitType; +import org.apache.atlas.typesystem.types.utils.TypesUtil; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; + + +public final class TypeConverterUtil { + private TypeConverterUtil() {} + private static final Logger LOG = LoggerFactory.getLogger(TypeConverterUtil.class); + + public static TypesDef toTypesDef(AtlasType type, AtlasTypeRegistry typeRegistry) throws AtlasBaseException { + final TypesDef ret; + + if (type instanceof AtlasEnumType) { + ret = TypeConverterUtil.enumToTypesDef((AtlasEnumType) type); + } else if (type instanceof AtlasEntityType) { + ret = TypeConverterUtil.entityToTypesDef((AtlasEntityType) type, typeRegistry); + } else if (type instanceof AtlasClassificationType) { + ret = TypeConverterUtil.classificationToTypesDef((AtlasClassificationType) type, typeRegistry); + } else if (type instanceof AtlasStructType) { + ret = TypeConverterUtil.structToTypesDef((AtlasStructType) type, typeRegistry); + } else { + ret = new TypesDef(); + } + + return ret; + } + + private static TypesDef enumToTypesDef(AtlasEnumType enumType) { + TypesDef ret = null; + + AtlasEnumDef enumDef = enumType.getEnumDef(); + + String enumName = enumDef.getName(); + String enumDesc = enumDef.getDescription(); + String enumVersion = enumDef.getTypeVersion(); + EnumValue[] enumValues = getEnumValues(enumDef.getElementDefs()); + + if (enumName != null && enumValues != null && enumValues.length > 0) { + EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues); + + ret = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDef), + ImmutableList.<StructTypeDefinition>of(), + ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), + ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); + } + + return ret; + } + + private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) + throws AtlasBaseException { + String typeName = structType.getStructDef().getName(); + String typeDesc = structType.getStructDef().getDescription(); + String typeVersion = structType.getStructDef().getTypeVersion(); + AttributeDefinition[] attributes = getAttributes(structType, registry); + StructTypeDefinition structTypeDef = TypesUtil.createStructTypeDef(typeName, typeDesc, typeVersion, attributes); + + TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), + ImmutableList.of(structTypeDef), + ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), + ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); + + return ret; + } + + private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) + throws AtlasBaseException { + String typeName = entityType.getEntityDef().getName(); + String typeDesc = entityType.getEntityDef().getDescription(); + String typeVersion = entityType.getEntityDef().getTypeVersion(); + ImmutableSet superTypes = ImmutableSet.copyOf(entityType.getEntityDef().getSuperTypes()); + AttributeDefinition[] attributes = getAttributes(entityType, registry); + + HierarchicalTypeDefinition<ClassType> classType = TypesUtil.createClassTypeDef(typeName, typeDesc, typeVersion, + superTypes, attributes); + TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), + ImmutableList.<StructTypeDefinition>of(), + ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), + ImmutableList.of(classType)); + + return ret; + } + + private static TypesDef classificationToTypesDef(AtlasClassificationType classificationType, + AtlasTypeRegistry registry) throws AtlasBaseException { + String typeName = classificationType.getClassificationDef().getName(); + String typeDesc = classificationType.getClassificationDef().getDescription(); + String typeVersion = classificationType.getClassificationDef().getTypeVersion(); + ImmutableSet superTypes = ImmutableSet.copyOf(classificationType.getClassificationDef().getSuperTypes()); + AttributeDefinition[] attributes = getAttributes(classificationType, registry); + + HierarchicalTypeDefinition traitType = TypesUtil.createTraitTypeDef(typeName, typeDesc, typeVersion, superTypes, + attributes); + TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), + ImmutableList.<StructTypeDefinition>of(), + ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(traitType), + ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); + return ret; + } + + + + public static AtlasTypesDef toAtlasTypesDef(String typeDefinition, AtlasTypeRegistry registry) throws AtlasBaseException { + AtlasTypesDef ret = new AtlasTypesDef(); + + try { + if (StringUtils.isEmpty(typeDefinition)) { + throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition); + } + + TypesDef typesDef = TypesSerialization.fromJson(typeDefinition); + if (CollectionUtils.isNotEmpty(typesDef.enumTypesAsJavaList())) { + List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.enumTypesAsJavaList()); + ret.setEnumDefs(enumDefs); + } + + if (CollectionUtils.isNotEmpty(typesDef.structTypesAsJavaList())) { + List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.structTypesAsJavaList()); + ret.setStructDefs(structDefs); + } + + if (CollectionUtils.isNotEmpty(typesDef.classTypesAsJavaList())) { + List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.classTypesAsJavaList(), registry); + ret.setEntityDefs(entityDefs); + } + + if (CollectionUtils.isNotEmpty(typesDef.traitTypesAsJavaList())) { + List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.traitTypesAsJavaList()); + ret.setClassificationDefs(classificationDefs); + } + + } catch (Exception e) { + LOG.error("Invalid type definition = {}", typeDefinition, e); + throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition); + } + + return ret; + } + + public static ImmutableList<String> getTypeNames(List<AtlasTypeDefHeader> atlasTypesDefs) { + List<String> ret = new ArrayList<String>(); + if (CollectionUtils.isNotEmpty(atlasTypesDefs)) { + for (AtlasTypeDefHeader atlasTypesDef : atlasTypesDefs) { + ret.add(atlasTypesDef.getName()); + } + } + + return ImmutableList.copyOf(ret); + } + + public static List<String> getTypeNames(AtlasTypesDef typesDef) { + List<AtlasTypeDefHeader> atlasTypesDefs = AtlasTypeUtil.toTypeDefHeader(typesDef); + return getTypeNames(atlasTypesDefs); + } + + private static List<AtlasEnumDef> toAtlasEnumDefs(List<EnumTypeDefinition> enumTypeDefinitions) { + List<AtlasEnumDef> ret = new ArrayList<AtlasEnumDef>(); + + for (EnumTypeDefinition enumType : enumTypeDefinitions) { + AtlasEnumDef enumDef = new AtlasEnumDef(); + enumDef.setName(enumType.name); + enumDef.setDescription(enumType.description); + enumDef.setTypeVersion(enumType.version); + enumDef.setElementDefs(getAtlasEnumElementDefs(enumType.enumValues)); + + ret.add(enumDef); + } + + return ret; + } + + private static List<AtlasStructDef> toAtlasStructDefs(List<StructTypeDefinition> structTypeDefinitions) + throws AtlasBaseException { + List<AtlasStructDef> ret = new ArrayList<AtlasStructDef>(); + + for (StructTypeDefinition structType : structTypeDefinitions) { + AtlasStructDef structDef = new AtlasStructDef(); + List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>(); + + structDef.setName(structType.typeName); + structDef.setDescription(structType.typeDescription); + structDef.setTypeVersion(structType.typeVersion); + + AttributeDefinition[] attrDefinitions = structType.attributeDefinitions; + for (AttributeDefinition attrDefinition : attrDefinitions) { + attrDefs.add(toAtlasAttributeDef(attrDefinition)); + } + + structDef.setAttributeDefs(attrDefs); + ret.add(structDef); + } + + return ret; + } + + private static List<AtlasClassificationDef> toAtlasClassificationDefs(List<HierarchicalTypeDefinition<TraitType>> traitTypeDefinitions) + throws AtlasBaseException { + List<AtlasClassificationDef> ret = new ArrayList<AtlasClassificationDef>(); + + for (HierarchicalTypeDefinition<TraitType> traitType : traitTypeDefinitions) { + AtlasClassificationDef classifDef = new AtlasClassificationDef(); + List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>(); + + classifDef.setName(traitType.typeName); + classifDef.setDescription(traitType.typeDescription); + classifDef.setTypeVersion(traitType.typeVersion); + classifDef.setSuperTypes(traitType.superTypes); + + AttributeDefinition[] attrDefinitions = traitType.attributeDefinitions; + for (AttributeDefinition attrDefinition : attrDefinitions) { + attrDefs.add(toAtlasAttributeDef(attrDefinition)); + } + + classifDef.setAttributeDefs(attrDefs); + ret.add(classifDef); + } + + return ret; + } + + 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; + } + + private static String getArrayTypeName(String attrType) { + String ret = null; + if (isArrayType(attrType)) { + Set<String> typeNames = AtlasTypeUtil.getReferencedTypeNames(attrType); + if (typeNames.size() > 0) { + ret = typeNames.iterator().next(); + } + } + + return ret; + } + + private static List<AtlasEnumElementDef> getAtlasEnumElementDefs(EnumValue[] enums) { + List<AtlasEnumElementDef> ret = new ArrayList<AtlasEnumElementDef>(); + + for (EnumValue enumElem : enums) { + ret.add(new AtlasEnumElementDef(enumElem.value, null, enumElem.ordinal)); + } + + return ret; + } + + private static EnumValue[] getEnumValues(List<AtlasEnumElementDef> enumDefs) { + List<EnumValue> ret = new ArrayList<EnumValue>(); + + if (CollectionUtils.isNotEmpty(enumDefs)) { + for (AtlasEnumElementDef enumDef : enumDefs) { + if (enumDef != null) { + ret.add(new EnumValue(enumDef.getValue(), enumDef.getOrdinal())); + } + } + } + + return ret.toArray(new EnumValue[ret.size()]); + } + + public static AtlasAttributeDef toAtlasAttributeDef(final AttributeDefinition attrDefinition) { + AtlasAttributeDef ret = new AtlasAttributeDef(); + + ret.setName(attrDefinition.name); + ret.setTypeName(attrDefinition.dataTypeName); + ret.setIsIndexable(attrDefinition.isIndexable); + ret.setIsUnique(attrDefinition.isUnique); + if (attrDefinition.isComposite) { + ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF)); + } + + if (StringUtils.isNotBlank(attrDefinition.reverseAttributeName)) { + ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, + new HashMap<String, Object>() {{ + put(CONSTRAINT_PARAM_ATTRIBUTE, attrDefinition.reverseAttributeName); + }})); + } + + // Multiplicity attribute mapping + Multiplicity multiplicity = attrDefinition.multiplicity; + int minCount = multiplicity.lower; + int maxCount = multiplicity.upper; + boolean isUnique = multiplicity.isUnique; + + if (minCount == 0) { + ret.setIsOptional(true); + ret.setValuesMinCount(0); + } else { + ret.setIsOptional(false); + ret.setValuesMinCount(minCount); + } + + if (maxCount < 2) { + ret.setCardinality(Cardinality.SINGLE); + ret.setValuesMaxCount(1); + } else { + if (!isUnique) { + ret.setCardinality(Cardinality.LIST); + } else { + ret.setCardinality(Cardinality.SET); + } + + ret.setValuesMaxCount(maxCount); + } + + return ret; + } + + private static AttributeDefinition[] getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException { + List<AttributeDefinition> ret = new ArrayList<>(); + List<AtlasAttributeDef> attrDefs = structType.getStructDef().getAttributeDefs(); + + if (CollectionUtils.isNotEmpty(attrDefs)) { + for (AtlasAttributeDef attrDef : attrDefs) { + AtlasAttribute attribute = structType.getAttribute(attrDef.getName()); + + ret.add(AtlasStructDefStoreV1.toAttributeDefintion(attribute)); + } + } + + return ret.toArray(new AttributeDefinition[ret.size()]); + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/webapp/src/main/java/org/apache/atlas/util/RestUtils.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/util/RestUtils.java b/webapp/src/main/java/org/apache/atlas/util/RestUtils.java deleted file mode 100644 index 6ce1bba..0000000 --- a/webapp/src/main/java/org/apache/atlas/util/RestUtils.java +++ /dev/null @@ -1,421 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.atlas.util; - -import static org.apache.atlas.AtlasErrorCode.INVALID_TYPE_DEFINITION; -import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF; -import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF; -import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE; -import static org.apache.atlas.type.AtlasTypeUtil.isArrayType; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.TypeCategory; -import org.apache.atlas.model.typedef.AtlasClassificationDef; -import org.apache.atlas.model.typedef.AtlasEntityDef; -import org.apache.atlas.model.typedef.AtlasEnumDef; -import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef; -import org.apache.atlas.model.typedef.AtlasStructDef; -import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; -import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality; -import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef; -import org.apache.atlas.model.typedef.AtlasTypeDefHeader; -import org.apache.atlas.model.typedef.AtlasTypesDef; -import org.apache.atlas.repository.store.graph.v1.AtlasStructDefStoreV1; -import org.apache.atlas.type.AtlasClassificationType; -import org.apache.atlas.type.AtlasEntityType; -import org.apache.atlas.type.AtlasEnumType; -import org.apache.atlas.type.AtlasStructType; -import org.apache.atlas.type.AtlasStructType.AtlasAttribute; -import org.apache.atlas.type.AtlasType; -import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.type.AtlasTypeUtil; -import org.apache.atlas.typesystem.TypesDef; -import org.apache.atlas.typesystem.json.TypesSerialization; -import org.apache.atlas.typesystem.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.EnumTypeDefinition; -import org.apache.atlas.typesystem.types.EnumValue; -import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; -import org.apache.atlas.typesystem.types.Multiplicity; -import org.apache.atlas.typesystem.types.StructTypeDefinition; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.utils.TypesUtil; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; -import org.codehaus.jackson.map.ObjectMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import static org.apache.atlas.AtlasErrorCode.INVALID_TYPE_DEFINITION; -import static org.apache.atlas.type.AtlasTypeUtil.isArrayType; - - -public final class RestUtils { - private RestUtils() {} - private static final Logger LOG = LoggerFactory.getLogger(RestUtils.class); - - public static TypesDef toTypesDef(AtlasType type, AtlasTypeRegistry typeRegistry) throws AtlasBaseException { - final TypesDef ret; - - if (type instanceof AtlasEnumType) { - ret = RestUtils.enumToTypesDef((AtlasEnumType)type); - } else if (type instanceof AtlasEntityType) { - ret = RestUtils.entityToTypesDef((AtlasEntityType)type, typeRegistry); - } else if (type instanceof AtlasClassificationType) { - ret = RestUtils.classificationToTypesDef((AtlasClassificationType)type, typeRegistry); - } else if (type instanceof AtlasStructType) { - ret = RestUtils.structToTypesDef((AtlasStructType)type, typeRegistry); - } else { - ret = new TypesDef(); - } - - return ret; - } - - private static TypesDef enumToTypesDef(AtlasEnumType enumType) { - TypesDef ret = null; - - AtlasEnumDef enumDef = enumType.getEnumDef(); - - String enumName = enumDef.getName(); - String enumDesc = enumDef.getDescription(); - String enumVersion = enumDef.getTypeVersion(); - EnumValue[] enumValues = getEnumValues(enumDef.getElementDefs()); - - if (enumName != null && enumValues != null && enumValues.length > 0) { - EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues); - - ret = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDef), - ImmutableList.<StructTypeDefinition>of(), - ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), - ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); - } - - return ret; - } - - private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) - throws AtlasBaseException { - String typeName = structType.getStructDef().getName(); - String typeDesc = structType.getStructDef().getDescription(); - String typeVersion = structType.getStructDef().getTypeVersion(); - AttributeDefinition[] attributes = getAttributes(structType, registry); - StructTypeDefinition structTypeDef = TypesUtil.createStructTypeDef(typeName, typeDesc, typeVersion, attributes); - - TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), - ImmutableList.of(structTypeDef), - ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), - ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); - - return ret; - } - - private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) - throws AtlasBaseException { - String typeName = entityType.getEntityDef().getName(); - String typeDesc = entityType.getEntityDef().getDescription(); - String typeVersion = entityType.getEntityDef().getTypeVersion(); - ImmutableSet superTypes = ImmutableSet.copyOf(entityType.getEntityDef().getSuperTypes()); - AttributeDefinition[] attributes = getAttributes(entityType, registry); - - HierarchicalTypeDefinition<ClassType> classType = TypesUtil.createClassTypeDef(typeName, typeDesc, typeVersion, - superTypes, attributes); - TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), - ImmutableList.<StructTypeDefinition>of(), - ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), - ImmutableList.of(classType)); - - return ret; - } - - private static TypesDef classificationToTypesDef(AtlasClassificationType classificationType, - AtlasTypeRegistry registry) throws AtlasBaseException { - String typeName = classificationType.getClassificationDef().getName(); - String typeDesc = classificationType.getClassificationDef().getDescription(); - String typeVersion = classificationType.getClassificationDef().getTypeVersion(); - ImmutableSet superTypes = ImmutableSet.copyOf(classificationType.getClassificationDef().getSuperTypes()); - AttributeDefinition[] attributes = getAttributes(classificationType, registry); - - HierarchicalTypeDefinition traitType = TypesUtil.createTraitTypeDef(typeName, typeDesc, typeVersion, superTypes, - attributes); - TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), - ImmutableList.<StructTypeDefinition>of(), - ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(traitType), - ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); - return ret; - } - - - - public static AtlasTypesDef toAtlasTypesDef(String typeDefinition, AtlasTypeRegistry registry) throws AtlasBaseException { - AtlasTypesDef ret = new AtlasTypesDef(); - - try { - if (StringUtils.isEmpty(typeDefinition)) { - throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition); - } - - TypesDef typesDef = TypesSerialization.fromJson(typeDefinition); - if (CollectionUtils.isNotEmpty(typesDef.enumTypesAsJavaList())) { - List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.enumTypesAsJavaList()); - ret.setEnumDefs(enumDefs); - } - - if (CollectionUtils.isNotEmpty(typesDef.structTypesAsJavaList())) { - List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.structTypesAsJavaList()); - ret.setStructDefs(structDefs); - } - - if (CollectionUtils.isNotEmpty(typesDef.classTypesAsJavaList())) { - List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.classTypesAsJavaList(), registry); - ret.setEntityDefs(entityDefs); - } - - if (CollectionUtils.isNotEmpty(typesDef.traitTypesAsJavaList())) { - List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.traitTypesAsJavaList()); - ret.setClassificationDefs(classificationDefs); - } - - } catch (Exception e) { - LOG.error("Invalid type definition = {}", typeDefinition, e); - throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition); - } - - return ret; - } - - public static ImmutableList<String> getTypeNames(List<AtlasTypeDefHeader> atlasTypesDefs) { - List<String> ret = new ArrayList<String>(); - if (CollectionUtils.isNotEmpty(atlasTypesDefs)) { - for (AtlasTypeDefHeader atlasTypesDef : atlasTypesDefs) { - ret.add(atlasTypesDef.getName()); - } - } - - return ImmutableList.copyOf(ret); - } - - public static List<String> getTypeNames(AtlasTypesDef typesDef) { - List<AtlasTypeDefHeader> atlasTypesDefs = AtlasTypeUtil.toTypeDefHeader(typesDef); - return getTypeNames(atlasTypesDefs); - } - - private static List<AtlasEnumDef> toAtlasEnumDefs(List<EnumTypeDefinition> enumTypeDefinitions) { - List<AtlasEnumDef> ret = new ArrayList<AtlasEnumDef>(); - - for (EnumTypeDefinition enumType : enumTypeDefinitions) { - AtlasEnumDef enumDef = new AtlasEnumDef(); - enumDef.setName(enumType.name); - enumDef.setDescription(enumType.description); - enumDef.setTypeVersion(enumType.version); - enumDef.setElementDefs(getAtlasEnumElementDefs(enumType.enumValues)); - - ret.add(enumDef); - } - - return ret; - } - - private static List<AtlasStructDef> toAtlasStructDefs(List<StructTypeDefinition> structTypeDefinitions) - throws AtlasBaseException { - List<AtlasStructDef> ret = new ArrayList<AtlasStructDef>(); - - for (StructTypeDefinition structType : structTypeDefinitions) { - AtlasStructDef structDef = new AtlasStructDef(); - List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>(); - - structDef.setName(structType.typeName); - structDef.setDescription(structType.typeDescription); - structDef.setTypeVersion(structType.typeVersion); - - AttributeDefinition[] attrDefinitions = structType.attributeDefinitions; - for (AttributeDefinition attrDefinition : attrDefinitions) { - attrDefs.add(toAtlasAttributeDef(attrDefinition)); - } - - structDef.setAttributeDefs(attrDefs); - ret.add(structDef); - } - - return ret; - } - - private static List<AtlasClassificationDef> toAtlasClassificationDefs(List<HierarchicalTypeDefinition<TraitType>> traitTypeDefinitions) - throws AtlasBaseException { - List<AtlasClassificationDef> ret = new ArrayList<AtlasClassificationDef>(); - - for (HierarchicalTypeDefinition<TraitType> traitType : traitTypeDefinitions) { - AtlasClassificationDef classifDef = new AtlasClassificationDef(); - List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>(); - - classifDef.setName(traitType.typeName); - classifDef.setDescription(traitType.typeDescription); - classifDef.setTypeVersion(traitType.typeVersion); - classifDef.setSuperTypes(traitType.superTypes); - - AttributeDefinition[] attrDefinitions = traitType.attributeDefinitions; - for (AttributeDefinition attrDefinition : attrDefinitions) { - attrDefs.add(toAtlasAttributeDef(attrDefinition)); - } - - classifDef.setAttributeDefs(attrDefs); - ret.add(classifDef); - } - - return ret; - } - - 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; - } - - private static String getArrayTypeName(String attrType) { - String ret = null; - if (isArrayType(attrType)) { - Set<String> typeNames = AtlasTypeUtil.getReferencedTypeNames(attrType); - if (typeNames.size() > 0) { - ret = typeNames.iterator().next(); - } - } - - return ret; - } - - private static List<AtlasEnumElementDef> getAtlasEnumElementDefs(EnumValue[] enums) { - List<AtlasEnumElementDef> ret = new ArrayList<AtlasEnumElementDef>(); - - for (EnumValue enumElem : enums) { - ret.add(new AtlasEnumElementDef(enumElem.value, null, enumElem.ordinal)); - } - - return ret; - } - - private static EnumValue[] getEnumValues(List<AtlasEnumElementDef> enumDefs) { - List<EnumValue> ret = new ArrayList<EnumValue>(); - - if (CollectionUtils.isNotEmpty(enumDefs)) { - for (AtlasEnumElementDef enumDef : enumDefs) { - if (enumDef != null) { - ret.add(new EnumValue(enumDef.getValue(), enumDef.getOrdinal())); - } - } - } - - return ret.toArray(new EnumValue[ret.size()]); - } - - private static AtlasAttributeDef toAtlasAttributeDef(final AttributeDefinition attrDefinition) { - AtlasAttributeDef ret = new AtlasAttributeDef(); - - ret.setName(attrDefinition.name); - ret.setTypeName(attrDefinition.dataTypeName); - ret.setIsIndexable(attrDefinition.isIndexable); - ret.setIsUnique(attrDefinition.isUnique); - if (attrDefinition.isComposite) { - ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF)); - } - - if (StringUtils.isNotBlank(attrDefinition.reverseAttributeName)) { - ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, - new HashMap<String, Object>() {{ - put(CONSTRAINT_PARAM_ATTRIBUTE, attrDefinition.reverseAttributeName); - }})); - } - - // Multiplicity attribute mapping - Multiplicity multiplicity = attrDefinition.multiplicity; - int minCount = multiplicity.lower; - int maxCount = multiplicity.upper; - boolean isUnique = multiplicity.isUnique; - - if (minCount == 0) { - ret.setIsOptional(true); - ret.setValuesMinCount(0); - } else { - ret.setIsOptional(false); - ret.setValuesMinCount(minCount); - } - - if (maxCount < 2) { - ret.setCardinality(Cardinality.SINGLE); - ret.setValuesMaxCount(1); - } else { - if (!isUnique) { - ret.setCardinality(Cardinality.LIST); - } else { - ret.setCardinality(Cardinality.SET); - } - - ret.setValuesMaxCount(maxCount); - } - - return ret; - } - - private static AttributeDefinition[] getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException { - List<AttributeDefinition> ret = new ArrayList<>(); - List<AtlasAttributeDef> attrDefs = structType.getStructDef().getAttributeDefs(); - - if (CollectionUtils.isNotEmpty(attrDefs)) { - for (AtlasAttributeDef attrDef : attrDefs) { - AtlasAttribute attribute = structType.getAttribute(attrDef.getName()); - - ret.add(AtlasStructDefStoreV1.toAttributeDefintion(attribute)); - } - } - - return ret.toArray(new AttributeDefinition[ret.size()]); - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java index e3c9e1b..32c2cb8 100644 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java @@ -27,7 +27,9 @@ import org.apache.atlas.catalog.EntityTagResourceProvider; import org.apache.atlas.catalog.InstanceRequest; import org.apache.atlas.catalog.Result; import org.apache.atlas.catalog.exception.CatalogException; +import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.services.MetadataService; +import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.web.util.Servlets; import org.slf4j.Logger; @@ -63,8 +65,8 @@ public class EntityService extends BaseService { private final EntityTagResourceProvider entityTagResourceProvider; @Inject - public EntityService(MetadataService metadataService) throws AtlasException { - DefaultTypeSystem typeSystem = new DefaultTypeSystem(metadataService); + public EntityService(MetadataService metadataService, AtlasTypeDefStore typeDefStore) throws AtlasBaseException { + DefaultTypeSystem typeSystem = new DefaultTypeSystem(metadataService, typeDefStore); entityResourceProvider = new EntityResourceProvider(typeSystem); entityTagResourceProvider = new EntityTagResourceProvider(typeSystem); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java b/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java index 13b0250..b13810f 100644 --- a/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java @@ -22,7 +22,9 @@ import org.apache.atlas.AtlasException; import org.apache.atlas.catalog.*; import org.apache.atlas.catalog.exception.CatalogException; import org.apache.atlas.catalog.exception.InvalidPayloadException; +import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.services.MetadataService; +import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.web.util.Servlets; import org.slf4j.Logger; @@ -58,8 +60,8 @@ public class TaxonomyService extends BaseService { private ResourceProvider termResourceProvider; @Inject - public void setMetadataService(MetadataService metadataService) throws AtlasException { - DefaultTypeSystem typeSystem = new DefaultTypeSystem(metadataService); + public void setMetadataService(MetadataService metadataService, AtlasTypeDefStore typeDefStore) throws AtlasBaseException { + DefaultTypeSystem typeSystem = new DefaultTypeSystem(metadataService, typeDefStore); taxonomyResourceProvider = createTaxonomyResourceProvider(typeSystem); termResourceProvider = createTermResourceProvider(typeSystem); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java index 2c385c9..424ca58 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java @@ -26,7 +26,7 @@ import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.json.TypesSerialization; -import org.apache.atlas.util.RestUtils; +import org.apache.atlas.repository.converters.TypeConverterUtil; import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.web.rest.TypesREST; import org.apache.atlas.web.util.Servlets; @@ -105,9 +105,9 @@ public class TypesResource { LOG.debug("Creating type with definition {} ", typeDefinition); } - AtlasTypesDef createTypesDef = RestUtils.toAtlasTypesDef(typeDefinition, typeRegistry); + AtlasTypesDef createTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry); AtlasTypesDef createdTypesDef = typesRest.createAtlasTypeDefs(createTypesDef); - List<String> typeNames = RestUtils.getTypeNames(createdTypesDef); + List<String> typeNames = TypeConverterUtil.getTypeNames(createdTypesDef); for (int i = 0; i < typeNames.size(); i++) { final String name = typeNames.get(i); @@ -173,9 +173,9 @@ public class TypesResource { LOG.debug("Updating type with definition {} ", typeDefinition); } - AtlasTypesDef updateTypesDef = RestUtils.toAtlasTypesDef(typeDefinition, typeRegistry); + AtlasTypesDef updateTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry); AtlasTypesDef updatedTypesDef = typesRest.updateAtlasTypeDefs(updateTypesDef); - List<String> typeNames = RestUtils.getTypeNames(updatedTypesDef); + List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef); for (int i = 0; i < typeNames.size(); i++) { final String name = typeNames.get(i); @@ -231,7 +231,7 @@ public class TypesResource { JSONObject response = new JSONObject(); try { - TypesDef typesDef = RestUtils.toTypesDef(typeRegistry.getType(typeName), typeRegistry);; + TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);; String typeDefinition = TypesSerialization.toJson(typesDef); response.put(AtlasClient.TYPENAME, typeName); @@ -290,7 +290,7 @@ public class TypesResource { TypesREST typesRest = resourceContext.getResource(TypesREST.class); JSONObject response = new JSONObject(); try { - List<String> result = RestUtils.getTypeNames(typesRest.getTypeDefHeaders(request)); + List<String> result = TypeConverterUtil.getTypeNames(typesRest.getTypeDefHeaders(request)); response.put(AtlasClient.RESULTS, new JSONArray(result)); response.put(AtlasClient.COUNT, result.size()); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/webapp/src/test/java/org/apache/atlas/util/RestUtilsTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/util/RestUtilsTest.java b/webapp/src/test/java/org/apache/atlas/util/RestUtilsTest.java index 0cb112a..87259df 100644 --- a/webapp/src/test/java/org/apache/atlas/util/RestUtilsTest.java +++ b/webapp/src/test/java/org/apache/atlas/util/RestUtilsTest.java @@ -28,12 +28,12 @@ import java.util.List; import java.util.Map; import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.repository.Constants; +import org.apache.atlas.repository.converters.TypeConverterUtil; import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.repository.store.graph.v1.AtlasStructDefStoreV1; @@ -178,7 +178,7 @@ public class RestUtilsTest { for (int i = 0; i < toConvert.size(); i++) { AtlasEntityDef entityDef = toConvert.get(i); AtlasEntityType entity = reg.getEntityTypeByName(entityDef.getName()); - HierarchicalTypeDefinition<ClassType> converted = RestUtils.toTypesDef(entity, reg) + HierarchicalTypeDefinition<ClassType> converted = TypeConverterUtil.toTypesDef(entity, reg) .classTypesAsJavaList().get(0); result.add(converted); } @@ -205,7 +205,7 @@ public class RestUtilsTest { String json = TypesSerialization.toJson(toConvert); AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry(); - AtlasTypesDef converted = RestUtils.toAtlasTypesDef(json, emptyRegistry); + AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry); List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs(); return convertedEntityDefs; } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/943e480c/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java b/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java index cba78f3..54a9b9a 100644 --- a/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/TaxonomyServiceTest.java @@ -48,7 +48,9 @@ import org.apache.atlas.catalog.ResourceProvider; import org.apache.atlas.catalog.Result; import org.apache.atlas.catalog.TaxonomyResourceProvider; import org.apache.atlas.catalog.TermPath; +import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.services.MetadataService; +import org.apache.atlas.store.AtlasTypeDefStore; import org.easymock.Capture; import org.testng.annotations.Test; @@ -60,6 +62,7 @@ public class TaxonomyServiceTest { public void testGetTaxonomy() throws Exception { String taxonomyName = "testTaxonomy"; MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -78,7 +81,7 @@ public class TaxonomyServiceTest { replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer); TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getTaxonomy(null, uriInfo, taxonomyName); Request request = requestCapture.getValue(); @@ -89,12 +92,13 @@ public class TaxonomyServiceTest { assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Get Response"); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer); } @Test public void testGetTaxonomies() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -117,7 +121,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getTaxonomies(null, uriInfo); Request request = requestCapture.getValue(); @@ -127,12 +131,13 @@ public class TaxonomyServiceTest { assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Get Response"); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer); } @Test public void testCreateTaxonomy() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -148,7 +153,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, null); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null); Response response = service.createTaxonomy(body, null, uriInfo, "testTaxonomy"); Request request = requestCapture.getValue(); @@ -162,12 +167,13 @@ public class TaxonomyServiceTest { assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy"); assertEquals(createResults.status, 201); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider); } @Test public void testDeleteTaxonomy() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -182,7 +188,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, null); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null); Response response = service.deleteTaxonomy(null, uriInfo, "testTaxonomy"); Request request = requestCapture.getValue(); @@ -195,7 +201,7 @@ public class TaxonomyServiceTest { assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy"); assertEquals(createResults.status, 200); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider); } @Test @@ -203,6 +209,7 @@ public class TaxonomyServiceTest { String taxonomyName = "testTaxonomy"; String termName = "testTaxonomy.termName"; MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -221,7 +228,7 @@ public class TaxonomyServiceTest { replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer); TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getTaxonomyTerm(null, uriInfo, taxonomyName, termName); Request request = requestCapture.getValue(); @@ -233,12 +240,13 @@ public class TaxonomyServiceTest { assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Term Get Response"); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer); } @Test public void testGetTaxonomyTerms() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -261,7 +269,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getTaxonomyTerms(null, uriInfo, "testTaxonomy"); Request request = requestCapture.getValue(); @@ -273,12 +281,13 @@ public class TaxonomyServiceTest { assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Term Get Response"); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer); } @Test public void testGetSubTerms_instance() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -308,7 +317,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2"); Request request = requestCapture.getValue(); @@ -320,13 +329,14 @@ public class TaxonomyServiceTest { assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Term Get Response"); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer, + verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3); } @Test public void testGetSubTerms_collection() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -358,7 +368,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, serializer); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2/terms"); Request request = requestCapture.getValue(); @@ -370,7 +380,7 @@ public class TaxonomyServiceTest { assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Term Get Response"); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer, + verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3); } @@ -379,6 +389,7 @@ public class TaxonomyServiceTest { String taxonomyName = "testTaxonomy"; String termName = "testTerm"; MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -394,7 +405,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, null); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null); Response response = service.createTerm(body, null, uriInfo, taxonomyName, termName); Request request = requestCapture.getValue(); @@ -409,7 +420,7 @@ public class TaxonomyServiceTest { assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm"); assertEquals(createResults.status, 201); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider); } @Test @@ -417,6 +428,7 @@ public class TaxonomyServiceTest { String taxonomyName = "testTaxonomy"; String termName = "testTerm"; MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -432,7 +444,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, null); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null); Response response = service.createSubTerm(body, null, uriInfo, taxonomyName, termName, "/terms/testTerm2"); Request request = requestCapture.getValue(); @@ -447,12 +459,13 @@ public class TaxonomyServiceTest { assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2"); assertEquals(createResults.status, 201); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider); } @Test public void testDeleteTerm() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -467,7 +480,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, null); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null); Response response = service.deleteTerm(null, uriInfo, "testTaxonomy", "testTerm"); Request request = requestCapture.getValue(); @@ -481,12 +494,13 @@ public class TaxonomyServiceTest { assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm"); assertEquals(createResults.status, 200); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider); } @Test public void testDeleteSubTerm() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); + AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); @@ -501,7 +515,7 @@ public class TaxonomyServiceTest { // instantiate service and invoke method being tested TestTaxonomyService service = new TestTaxonomyService( - metadataService, taxonomyResourceProvider, termResourceProvider, null); + metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null); Response response = service.deleteSubTerm(null, uriInfo, "testTaxonomy", "testTerm", "terms/testTerm2"); Request request = requestCapture.getValue(); @@ -515,7 +529,7 @@ public class TaxonomyServiceTest { assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2"); assertEquals(createResults.status, 200); - verify(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider); + verify(uriInfo, taxonomyResourceProvider, termResourceProvider); } private static class TestTaxonomyService extends TaxonomyService { @@ -525,14 +539,15 @@ public class TaxonomyServiceTest { private boolean transactionInitialized = false; public TestTaxonomyService(MetadataService metadataService, + AtlasTypeDefStore typeDefStore, ResourceProvider taxonomyProvider, ResourceProvider termResourceProvider, - JsonSerializer serializer) throws AtlasException { + JsonSerializer serializer) throws AtlasBaseException { testTaxonomyResourceProvider = taxonomyProvider; testTermResourceProvider = termResourceProvider; testSerializer = serializer; - setMetadataService(metadataService); + setMetadataService(metadataService, typeDefStore); } @Override
