diff --git a/common/src/main/java/org/apache/atlas/repository/Constants.java b/common/src/main/java/org/apache/atlas/repository/Constants.java index 6ca15e7abd..4a2cd5905c 100644 --- a/common/src/main/java/org/apache/atlas/repository/Constants.java +++ b/common/src/main/java/org/apache/atlas/repository/Constants.java @@ -129,7 +129,6 @@ public final class Constants { public static final String ATLAS_GLOSSARY_ENTITY_TYPE = "AtlasGlossary"; public static final String ATLAS_GLOSSARY_TERM_ENTITY_TYPE = "AtlasGlossaryTerm"; public static final String ATLAS_GLOSSARY_CATEGORY_ENTITY_TYPE = "AtlasGlossaryCategory"; - public static final String DOCUMENT_ENTITY_TYPE = "Document"; public static final String CATEGORY_PARENT_EDGE_LABEL = "r:AtlasGlossaryCategoryHierarchyLink"; public static final String CATEGORY_TERMS_EDGE_LABEL = "r:AtlasGlossaryTermCategorization"; public static final String GLOSSARY_TERMS_EDGE_LABEL = "r:AtlasGlossaryTermAnchor"; diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java index f2263b0036..04d72bdfb2 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java +++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java @@ -225,7 +225,7 @@ public enum AtlasErrorCode { TYPE_HAS_RELATIONSHIPS(409, "ATLAS-409-00-005", "Given type {0} has associated relationshipDefs"), SAVED_SEARCH_ALREADY_EXISTS(409, "ATLAS-409-00-006", "search named {0} already exists for user {1}"), GLOSSARY_ALREADY_EXISTS(409, "ATLAS-409-00-007", "Glossary with name {0} already exists"), - GLOSSARY_TERM_ALREADY_EXISTS(409, "ATLAS-409-00-009", "Glossary {0} with name {1} already exists"), + GLOSSARY_TERM_ALREADY_EXISTS(409, "ATLAS-409-00-009", "Glossary term with name {0} already exists"), GLOSSARY_CATEGORY_ALREADY_EXISTS(409, "ATLAS-409-00-00A", "Glossary category with name {0} already exists on this level"), ACHOR_UPDATION_NOT_SUPPORTED(409, "ATLAS-400-00-0010", "Anchor(glossary) change not supported"), GLOSSARY_IMPORT_FAILED(409, "ATLAS-409-00-011", "Glossary import failed"), diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index d21d89de33..124ad92218 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -58,7 +58,6 @@ import org.apache.atlas.repository.store.graph.v1.RestoreHandlerV1; import org.apache.atlas.repository.store.graph.v2.preprocessor.AuthPolicyPreProcessor; import org.apache.atlas.repository.store.graph.v2.preprocessor.ConnectionPreProcessor; -import org.apache.atlas.repository.store.graph.v2.preprocessor.glossary.DocumentPreProcessor; import org.apache.atlas.repository.store.graph.v2.preprocessor.resource.LinkPreProcessor; import org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessor; import org.apache.atlas.repository.store.graph.v2.preprocessor.accesscontrol.PersonaPreProcessor; @@ -1797,10 +1796,6 @@ public PreProcessor getPreProcessor(String typeName) { preProcessor = new TermPreProcessor(typeRegistry, entityRetriever, graph, taskManagement); break; - case DOCUMENT_ENTITY_TYPE: - preProcessor = new DocumentPreProcessor(typeRegistry, entityRetriever, graph, taskManagement); - break; - case ATLAS_GLOSSARY_CATEGORY_ENTITY_TYPE: preProcessor = new CategoryPreProcessor(typeRegistry, entityRetriever, graph, taskManagement, entityGraphMapper); break; diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java index 6d14890e60..b446f4c299 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java @@ -1980,7 +1980,7 @@ private void addGlossaryAttr(AttributeMutationContext ctx, AtlasEdge edge) { AtlasVertex toVertex = ctx.getReferringVertex(); String toVertexType = getTypeName(toVertex); - if (TYPE_TERM.equals(toVertexType) || DOCUMENT_ENTITY_TYPE.equals(toVertexType) || TYPE_CATEGORY.equals(toVertexType)) { + if (TYPE_TERM.equals(toVertexType) || TYPE_CATEGORY.equals(toVertexType)) { // handle __glossary attribute of term or category entity String gloQname = edge.getOutVertex().getProperty(QUALIFIED_NAME, String.class); AtlasGraphUtilsV2.setEncodedProperty(toVertex, GLOSSARY_PROPERTY_KEY, gloQname); @@ -2064,7 +2064,7 @@ private void addCategoriesToTermEntity(AttributeMutationContext ctx, List categoryVertices = newElementsCreated.stream().map(x -> ((AtlasEdge)x).getOutVertex()).collect(Collectors.toList()); Set catQnames = categoryVertices.stream().map(x -> x.getProperty(QUALIFIED_NAME, String.class)).collect(Collectors.toSet()); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/AbstractGlossaryPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/AbstractGlossaryPreProcessor.java index d6422a9bbb..91950f783c 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/AbstractGlossaryPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/AbstractGlossaryPreProcessor.java @@ -90,14 +90,14 @@ public abstract class AbstractGlossaryPreProcessor implements PreProcessor { } } - public void termExists(String termName, String glossaryQName, String entityType) throws AtlasBaseException { + public void termExists(String termName, String glossaryQName) throws AtlasBaseException { AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("termExists"); boolean ret = false; try { List mustClauseList = new ArrayList(); mustClauseList.add(mapOf("term", mapOf("__glossary", glossaryQName))); - mustClauseList.add(mapOf("term", mapOf("__typeName.keyword", entityType))); + mustClauseList.add(mapOf("term", mapOf("__typeName.keyword", ATLAS_GLOSSARY_TERM_ENTITY_TYPE))); mustClauseList.add(mapOf("term", mapOf("__state", "ACTIVE"))); mustClauseList.add(mapOf("term", mapOf("name.keyword", termName))); @@ -110,8 +110,7 @@ public void termExists(String termName, String glossaryQName, String entityType) } if (ret) { - String type = entityType.equals(ATLAS_GLOSSARY_TERM_ENTITY_TYPE) ? "term" : "document"; - throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_ALREADY_EXISTS, type, termName); + throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_ALREADY_EXISTS, termName); } } finally { RequestContext.get().endMetricRecord(metricRecorder); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/CategoryPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/CategoryPreProcessor.java index fd5b99833f..eb39ff3b1d 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/CategoryPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/CategoryPreProcessor.java @@ -59,7 +59,6 @@ import static org.apache.atlas.AtlasErrorCode.BAD_REQUEST; import static org.apache.atlas.repository.Constants.ATLAS_GLOSSARY_CATEGORY_ENTITY_TYPE; import static org.apache.atlas.repository.Constants.ATLAS_GLOSSARY_ENTITY_TYPE; -import static org.apache.atlas.repository.Constants.ATLAS_GLOSSARY_TERM_ENTITY_TYPE; import static org.apache.atlas.repository.Constants.CATEGORY_PARENT_EDGE_LABEL; import static org.apache.atlas.repository.Constants.CATEGORY_TERMS_EDGE_LABEL; import static org.apache.atlas.repository.Constants.GUID_PROPERTY_KEY; @@ -273,7 +272,7 @@ public void moveChildTermToAnotherGlossary(AtlasVertex termVertex, LOG.info("Moving child term {} to Glossary {}", termName, targetGlossaryQualifiedName); //check duplicate term name - termExists(termName, targetGlossaryQualifiedName, ATLAS_GLOSSARY_TERM_ENTITY_TYPE); + termExists(termName, targetGlossaryQualifiedName); String currentTermQualifiedName = termVertex.getProperty(QUALIFIED_NAME, String.class); String updatedTermQualifiedName = currentTermQualifiedName.replace(sourceGlossaryQualifiedName, targetGlossaryQualifiedName); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/DocumentPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/DocumentPreProcessor.java deleted file mode 100644 index eab053e7a1..0000000000 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/DocumentPreProcessor.java +++ /dev/null @@ -1,252 +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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.store.graph.v2.preprocessor.glossary; - - -import org.apache.atlas.AtlasErrorCode; -import org.apache.atlas.RequestContext; -import org.apache.atlas.authorize.AtlasAuthorizationUtils; -import org.apache.atlas.authorize.AtlasEntityAccessRequest; -import org.apache.atlas.authorize.AtlasPrivilege; -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.instance.AtlasEntity; -import org.apache.atlas.model.instance.AtlasEntityHeader; -import org.apache.atlas.model.instance.AtlasObjectId; -import org.apache.atlas.model.instance.AtlasRelatedObjectId; -import org.apache.atlas.model.instance.AtlasStruct; -import org.apache.atlas.model.instance.EntityMutations; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever; -import org.apache.atlas.repository.store.graph.v2.EntityMutationContext; -import org.apache.atlas.tasks.TaskManagement; -import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.utils.AtlasPerfMetrics; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.util.Iterator; -import java.util.List; - -import static org.apache.atlas.repository.Constants.CATEGORY_TERMS_EDGE_LABEL; -import static org.apache.atlas.repository.Constants.DOCUMENT_ENTITY_TYPE; -import static org.apache.atlas.repository.Constants.NAME; -import static org.apache.atlas.repository.Constants.QUALIFIED_NAME; -import static org.apache.atlas.repository.graph.GraphHelper.getActiveParentVertices; -import static org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessorUtils.ANCHOR; -import static org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessorUtils.getUUID; -import static org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessorUtils.isNameInvalid; -import static org.apache.atlas.repository.store.graph.v2.tasks.MeaningsTaskFactory.UPDATE_ENTITY_MEANINGS_ON_TERM_UPDATE; - -@Component -public class DocumentPreProcessor extends AbstractGlossaryPreProcessor { - private static final Logger LOG = LoggerFactory.getLogger(DocumentPreProcessor.class); - - private AtlasEntityHeader anchor; - public DocumentPreProcessor(AtlasTypeRegistry typeRegistry, EntityGraphRetriever entityRetriever, AtlasGraph graph, TaskManagement taskManagement) { - super(typeRegistry, entityRetriever, graph, taskManagement); - } - - @Override - public void processAttributes(AtlasStruct entityStruct, EntityMutationContext context, EntityMutations.EntityOperation operation) throws AtlasBaseException { - if (LOG.isDebugEnabled()) { - LOG.debug("DocumentPreProcessor.processAttributes: pre processing {}, {}", - entityStruct.getAttribute(QUALIFIED_NAME), operation); - } - - AtlasEntity entity = (AtlasEntity) entityStruct; - AtlasVertex vertex = context.getVertex(entity.getGuid()); - - setAnchor(entity, context); - - switch (operation) { - case CREATE: - processCreateDocument(entity, vertex); - break; - case UPDATE: - processUpdateDocument(entity, vertex); - break; - } - } - - private void processCreateDocument(AtlasEntity entity, AtlasVertex vertex) throws AtlasBaseException { - AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("processCreateDocument"); - String docName = (String) entity.getAttribute(NAME); - - if (StringUtils.isEmpty(docName) || isNameInvalid(docName)) { - throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME); - } - - String glossaryQName = (String) anchor.getAttribute(QUALIFIED_NAME); - - termExists(docName, glossaryQName, DOCUMENT_ENTITY_TYPE); - - validateCategory(entity); - - entity.setAttribute(QUALIFIED_NAME, createQualifiedName()); - AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)), - "create entity: type=", entity.getTypeName()); - - RequestContext.get().endMetricRecord(metricRecorder); - } - - private void processUpdateDocument(AtlasEntity entity, AtlasVertex vertex) throws AtlasBaseException { - AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("processUpdateDocument"); - String docName = (String) entity.getAttribute(NAME); - String vertexName = vertex.getProperty(NAME, String.class); - String docGuid = entity.getGuid(); - - if (StringUtils.isEmpty(docName) || isNameInvalid(docName)) { - throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME); - } - - validateCategory(entity); - - AtlasEntity storedDoc = entityRetriever.toAtlasEntity(vertex); - AtlasRelatedObjectId currentGlossary = (AtlasRelatedObjectId) storedDoc.getRelationshipAttribute(ANCHOR); - AtlasEntityHeader currentGlossaryHeader = entityRetriever.toAtlasEntityHeader(currentGlossary.getGuid()); - String currentGlossaryQualifiedName = (String) currentGlossaryHeader.getAttribute(QUALIFIED_NAME); - - String docQualifiedName = vertex.getProperty(QUALIFIED_NAME, String.class); - - String newGlossaryQualifiedName = (String) anchor.getAttribute(QUALIFIED_NAME); - - if (!currentGlossaryQualifiedName.equals(newGlossaryQualifiedName)){ - //Auth check - isAuthorized(currentGlossaryHeader, anchor); - - String updatedDocQualifiedName = moveDocToAnotherGlossary(entity, vertex, currentGlossaryQualifiedName, newGlossaryQualifiedName, docQualifiedName); - - if (checkEntityTermAssociation(docQualifiedName)) { - if (taskManagement != null && DEFERRED_ACTION_ENABLED) { - createAndQueueTask(UPDATE_ENTITY_MEANINGS_ON_TERM_UPDATE, vertexName, docName, docQualifiedName, updatedDocQualifiedName, vertex); - } else { - updateMeaningsAttributesInEntitiesOnTermUpdate(vertexName, docName, docQualifiedName, updatedDocQualifiedName, docGuid); - } - } - - } else { - - if (!vertexName.equals(docName)) { - termExists(docName, newGlossaryQualifiedName, DOCUMENT_ENTITY_TYPE); - } - - entity.setAttribute(QUALIFIED_NAME, docQualifiedName); - - if (!docName.equals(vertexName) && checkEntityTermAssociation(docQualifiedName)) { - if (taskManagement != null && DEFERRED_ACTION_ENABLED) { - createAndQueueTask(UPDATE_ENTITY_MEANINGS_ON_TERM_UPDATE, vertexName, docName, docQualifiedName, null, vertex); - } else { - updateMeaningsAttributesInEntitiesOnTermUpdate(vertexName, docName, docQualifiedName, null, docGuid); - } - } - } - - RequestContext.get().endMetricRecord(metricRecorder); - } - - private void validateCategory(AtlasEntity entity) throws AtlasBaseException { - String glossaryQualifiedName = (String) anchor.getAttribute(QUALIFIED_NAME); - - if (entity.hasRelationshipAttribute(ATTR_CATEGORIES) && entity.getRelationshipAttribute(ATTR_CATEGORIES) != null) { - List categories = (List) entity.getRelationshipAttribute(ATTR_CATEGORIES); - - if (CollectionUtils.isNotEmpty(categories)) { - AtlasObjectId category = categories.get(0); - String categoryQualifiedName; - - if (category.getUniqueAttributes() != null && category.getUniqueAttributes().containsKey(QUALIFIED_NAME)) { - categoryQualifiedName = (String) category.getUniqueAttributes().get(QUALIFIED_NAME); - } else { - AtlasVertex categoryVertex = entityRetriever.getEntityVertex(category.getGuid()); - categoryQualifiedName = categoryVertex.getProperty(QUALIFIED_NAME, String.class); - } - - if (!categoryQualifiedName.endsWith(glossaryQualifiedName)) { - throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Passed category doesn't belongs to Passed Glossary"); - } - } - } - } - - public String moveDocToAnotherGlossary(AtlasEntity entity, AtlasVertex vertex, - String sourceGlossaryQualifiedName, - String targetGlossaryQualifiedName, - String currentDocQualifiedName) throws AtlasBaseException { - - //check duplicate doc name - termExists((String) entity.getAttribute(NAME), targetGlossaryQualifiedName, DOCUMENT_ENTITY_TYPE); - - - String updatedQualifiedName = currentDocQualifiedName.replace(sourceGlossaryQualifiedName, targetGlossaryQualifiedName); - - //qualifiedName - entity.setAttribute(QUALIFIED_NAME, updatedQualifiedName); - - // __categories - /* if category is not passed in relationshipAttributes, check - whether category belongs to target glossary, if not throw an exception - */ - if (!entity.hasRelationshipAttribute(ATTR_CATEGORIES)) { - Iterator categoriesItr = getActiveParentVertices(vertex, CATEGORY_TERMS_EDGE_LABEL); - - if (categoriesItr.hasNext()) { - AtlasVertex categoryVertex = categoriesItr.next(); - - String categoryQualifiedName = categoryVertex.getProperty(QUALIFIED_NAME, String.class); - - if (!categoryQualifiedName.endsWith(targetGlossaryQualifiedName)) { - throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Passed category doesn't belongs to Passed Glossary"); - } - } - } - - return updatedQualifiedName; - } - - private String createQualifiedName() { - return getUUID() + "@" + anchor.getAttribute(QUALIFIED_NAME); - } - - private void setAnchor(AtlasEntity entity, EntityMutationContext context) throws AtlasBaseException { - AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("TermPreProcessor.setAnchor"); - if (anchor == null) { - AtlasObjectId objectId = (AtlasObjectId) entity.getRelationshipAttribute(ANCHOR); - - if (StringUtils.isNotEmpty(objectId.getGuid())) { - AtlasVertex vertex = context.getVertex(objectId.getGuid()); - - if (vertex == null) { - anchor = entityRetriever.toAtlasEntityHeader(objectId.getGuid()); - } else { - anchor = entityRetriever.toAtlasEntityHeader(vertex); - } - - } else if (MapUtils.isNotEmpty(objectId.getUniqueAttributes()) && - StringUtils.isNotEmpty( (String) objectId.getUniqueAttributes().get(QUALIFIED_NAME))) { - anchor = new AtlasEntityHeader(objectId.getTypeName(), objectId.getUniqueAttributes()); - - } - } - RequestContext.get().endMetricRecord(metricRecorder); - } -} diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java index fd0330435b..53e12ea93e 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java @@ -93,7 +93,7 @@ private void processCreateTerm(AtlasEntity entity, AtlasVertex vertex) throws At String glossaryQName = (String) anchor.getAttribute(QUALIFIED_NAME); - termExists(termName, glossaryQName, ATLAS_GLOSSARY_TERM_ENTITY_TYPE); + termExists(termName, glossaryQName); validateCategory(entity); @@ -142,7 +142,7 @@ private void processUpdateTerm(AtlasEntity entity, AtlasVertex vertex) throws At } else { if (!vertexName.equals(termName)) { - termExists(termName, newGlossaryQualifiedName, ATLAS_GLOSSARY_TERM_ENTITY_TYPE); + termExists(termName, newGlossaryQualifiedName); } entity.setAttribute(QUALIFIED_NAME, termQualifiedName); @@ -189,7 +189,7 @@ public String moveTermToAnotherGlossary(AtlasEntity entity, AtlasVertex vertex, String currentTermQualifiedName) throws AtlasBaseException { //check duplicate term name - termExists((String) entity.getAttribute(NAME), targetGlossaryQualifiedName, ATLAS_GLOSSARY_TERM_ENTITY_TYPE); + termExists((String) entity.getAttribute(NAME), targetGlossaryQualifiedName); String updatedQualifiedName = currentTermQualifiedName.replace(sourceGlossaryQualifiedName, targetGlossaryQualifiedName);