Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
import org.apache.atlas.model.discovery.SearchParameters;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever;
Expand All @@ -48,7 +46,9 @@
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -582,15 +582,16 @@ private AtlasVertex getGlossaryTermVertex(String termName) {
AtlasVertex ret = null;

if (StringUtils.isNotEmpty(termName)) {
AtlasEntityType termType = getTermEntityType();
AtlasAttribute attrName = termType.getAttribute(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_QNAME);
AtlasGraphQuery query = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, termType.getTypeName())
.has(attrName.getVertexPropertyName(), termName)
.has(Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name());
AtlasEntityType termType = getTermEntityType();
Map<String, Object> uniqAttributes = new HashMap<>();

Iterator<AtlasVertex> results = query.vertices().iterator();
uniqAttributes.put(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_QNAME, termName);

ret = results.hasNext() ? results.next() : null;
ret = AtlasGraphUtilsV2.findByUniqueAttributes(graph, termType, uniqAttributes);

if (ret != null && AtlasGraphUtilsV2.getState(ret) != AtlasEntity.Status.ACTIVE) {
ret = null;
}
}

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ public AtlasGlossary updateGlossary(AtlasGlossary atlasGlossary) throws AtlasBas
if (!storeObject.equals(atlasGlossary)) {
atlasGlossary.setGuid(storeObject.getGuid());
atlasGlossary.setQualifiedName(storeObject.getQualifiedName());
atlasGlossary.setTerms(null);
atlasGlossary.setCategories(null);

storeObject = dataAccess.save(atlasGlossary);
storeObject = dataAccess.savePartial(atlasGlossary);

setInfoForRelations(storeObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public <T extends AtlasBaseModelObject> T save(T obj) throws AtlasBaseException
return this.load(obj);
}

public <T extends AtlasBaseModelObject> T savePartial(T obj) throws AtlasBaseException {
savePartialNoLoad(obj);

return this.load(obj);
}

public <T extends AtlasBaseModelObject> void saveNoLoad(T obj) throws AtlasBaseException {
requireNonNull(obj, "Can't save a null object");

Expand Down Expand Up @@ -91,6 +97,34 @@ public <T extends AtlasBaseModelObject> void saveNoLoad(T obj) throws AtlasBaseE
}
}

public <T extends AtlasBaseModelObject> void savePartialNoLoad(T obj) throws AtlasBaseException {
requireNonNull(obj, "Can't save a null object");

AtlasPerfTracer perf = null;

try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.savePartial()");
}

DataTransferObject<T> dto = dtoRegistry.get((Class<T>) obj.getClass());

AtlasEntityWithExtInfo entityWithExtInfo = dto.toEntityWithExtInfo(obj);
EntityMutationResponse entityMutationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), true);

// Update GUID assignment for newly created entity
if (CollectionUtils.isNotEmpty(entityMutationResponse.getCreatedEntities())) {
String assignedGuid = entityMutationResponse.getGuidAssignments().get(obj.getGuid());

if (!obj.getGuid().equals(assignedGuid)) {
obj.setGuid(assignedGuid);
}
}
} finally {
AtlasPerfTracer.log(perf);
}
}

public <T extends AtlasBaseModelObject> Iterable<T> save(Iterable<T> obj) throws AtlasBaseException {
requireNonNull(obj, "Can't save a null object");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.BasicTestSetup;
import org.apache.atlas.SortOrder;
import org.apache.atlas.TestModules;
Expand All @@ -29,6 +30,7 @@
import org.apache.atlas.model.discovery.QuickSearchParameters;
import org.apache.atlas.model.discovery.RelationshipSearchParameters;
import org.apache.atlas.model.discovery.SearchParameters;
import org.apache.atlas.model.glossary.AtlasGlossary;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader;
Expand Down Expand Up @@ -113,6 +115,26 @@ public void term() throws AtlasBaseException {
assertSearchProcessorWithoutMarker(params, 10);
}

@Test
public void termSearchAfterGlossaryUpdate() throws AtlasBaseException {
List<AtlasGlossary> glossaries = glossaryService.getGlossaries(100, 0, SortOrder.ASCENDING);
AtlasGlossary glossary = glossaries.stream()
.filter(g -> SALES_GLOSSARY.equals(g.getName()))
.findFirst()
.orElseThrow(() -> new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Glossary not found: " + SALES_GLOSSARY));

SearchParameters params = new SearchParameters();

params.setTermName(SALES_TERM + "@" + SALES_GLOSSARY);

assertSearchProcessorWithoutMarker(params, 10);

glossary.setShortDescription("updated after glossary update");
glossaryService.updateGlossary(glossary);

assertSearchProcessorWithoutMarker(params, 10);
}

// TSP execute and CSP,ESP filter
@Test
public void termTag() throws AtlasBaseException {
Expand Down