Fixes #5068 Child Glossary Terms have null in fullyQualifiedName (#5075)

This commit is contained in:
Suresh Srinivas 2022-05-20 12:14:46 -07:00 committed by GitHub
parent ff07c5966c
commit de117ba4c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 12 deletions

View File

@ -98,6 +98,11 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
// Validate glossary
EntityReference glossary = Entity.getEntityReference(entity.getGlossary());
entity.setGlossary(glossary);
// Validate parent term
EntityReference parentTerm = Entity.getEntityReference(entity.getParent());
entity.setParent(parentTerm);
setFullyQualifiedName(entity);
// Validate related terms
@ -167,14 +172,11 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
@Override
public void setFullyQualifiedName(GlossaryTerm entity) {
// Validate parent
if (entity.getParent() == null) {
if (entity.getParent() == null) { // Glossary term at the root of the glossary
entity.setFullyQualifiedName(FullyQualifiedName.add(entity.getGlossary().getName(), entity.getName()));
} else {
// TODO fix me
// EntityReference parent = Entity.getEntityReference(entity.getParent());
} else { // Glossary term that is a child of another glossary term
EntityReference parent = entity.getParent();
entity.setFullyQualifiedName(FullyQualifiedName.add(parent.getFullyQualifiedName(), entity.getName()));
entity.setParent(parent);
}
}

View File

@ -30,6 +30,7 @@ import java.util.List;
import java.util.Objects;
import java.util.UUID;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -38,7 +39,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

View File

@ -79,7 +79,7 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
@Order(0)
@Test
void get_listGlossaryTermsWithDifferentFilters() throws HttpResponseException {
void get_listGlossaryTermsWithDifferentFilters() throws IOException {
// Create the following glossary
// glossary1
// - term1
@ -274,12 +274,12 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
assertEntityDeleted(t1.getId(), true);
}
public GlossaryTerm createTerm(Glossary glossary, GlossaryTerm parent, String termName) throws HttpResponseException {
public GlossaryTerm createTerm(Glossary glossary, GlossaryTerm parent, String termName) throws IOException {
EntityReference glossaryRef = glossary.getEntityReference();
EntityReference parentRef = parent != null ? parent.getEntityReference() : null;
CreateGlossaryTerm createGlossaryTerm =
createRequest(termName, "", "", null).withGlossary(glossaryRef).withParent(parentRef);
return createEntity(createGlossaryTerm, ADMIN_AUTH_HEADERS);
return createAndCheckEntity(createGlossaryTerm, ADMIN_AUTH_HEADERS);
}
public void assertContains(List<GlossaryTerm> expectedTerms, List<GlossaryTerm> actualTerms)
@ -313,9 +313,14 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
public void validateCreatedEntity(GlossaryTerm entity, CreateGlossaryTerm request, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(entity, request.getDescription(), TestUtils.getPrincipal(authHeaders), null);
assertReference(request.getParent(), entity.getParent());
assertReference(request.getGlossary(), entity.getGlossary());
// Validate fully qualified name
String fqn = entity.getParent() == null ? entity.getGlossary().getName() : entity.getParent().getName();
String fqn =
entity.getParent() == null
? entity.getGlossary().getFullyQualifiedName()
: entity.getParent().getFullyQualifiedName();
fqn = FullyQualifiedName.add(fqn, entity.getName());
assertEquals(fqn, entity.getFullyQualifiedName());
@ -340,8 +345,9 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
throws HttpResponseException {
validateCommonEntityFields(patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null);
validateEntityReference(patched.getGlossary());
assertEquals(expected.getGlossary().getId(), patched.getGlossary().getId());
assertReference(expected.getGlossary(), patched.getGlossary());
assertReference(expected.getParent(), patched.getParent());
assertEquals(expected.getFullyQualifiedName(), patched.getFullyQualifiedName());
// Entity specific validation
TestUtils.validateTags(expected.getTags(), patched.getTags());