Skip to content

Commit

Permalink
Fixes #2942 - Fix bugs reported by Sonar issue on release 0.9 (#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshms committed Feb 24, 2022
1 parent a1257bd commit 7ea9e44
Show file tree
Hide file tree
Showing 28 changed files with 69 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void logAfterExecution(StatementContext context) {
environment.jersey().register(new JsonProcessingExceptionMapper(true));
environment.jersey().register(new EarlyEofExceptionMapper());
environment.jersey().register(JsonMappingExceptionMapper.class);
environment.healthChecks().register("UserDatabaseCheck", new CatalogHealthCheck(catalogConfig, jdbi));
environment.healthChecks().register("UserDatabaseCheck", new CatalogHealthCheck(jdbi));
registerResources(catalogConfig, environment, jdbi);

// Register Event Handler
Expand Down Expand Up @@ -242,7 +242,7 @@ public static void main(String[] args) throws Exception {
catalogApplication.run(args);
}

public class ManagedShutdown implements Managed {
public static class ManagedShutdown implements Managed {

@Override
public void start() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CatalogHealthCheck extends HealthCheck {
private final UserRepository userRepository;
private final EntityUtil.Fields fields = new EntityUtil.Fields(FIELD_LIST, "profile");

public CatalogHealthCheck(CatalogApplicationConfig config, Jdbi jdbi) {
public CatalogHealthCheck(Jdbi jdbi) {
super();
CollectionDAO repo = jdbi.onDemand(CollectionDAO.class);
this.userRepository = new UserRepository(repo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public final class Entity {
public static final String LOCATION = "location";
public static final String GLOSSARY = "glossary";
public static final String GLOSSARY_TERM = "glossaryTerm";
public static final String THREAD = "thread";

//
// Policies
Expand Down Expand Up @@ -115,10 +116,10 @@ public static <T> void registerEntity(
}

public static EntityReference getEntityReference(EntityReference ref) throws IOException {
return getEntityReference(ref.getType(), ref.getId());
return getEntityReferenceById(ref.getType(), ref.getId());
}

public static EntityReference getEntityReference(String entity, UUID id) throws IOException {
public static EntityReference getEntityReferenceById(@NonNull String entity, @NonNull UUID id) throws IOException {
EntityDAO<?> dao = DAO_MAP.get(entity);
if (dao == null) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityTypeNotFound(entity));
Expand All @@ -135,14 +136,6 @@ public static EntityReference getEntityReferenceByName(@NonNull String entity, @
return dao.findEntityReferenceByName(fqn);
}

public static EntityReference getEntityReferenceById(@NonNull String entity, @NonNull UUID id) throws IOException {
EntityDAO<?> dao = DAO_MAP.get(entity);
if (dao == null) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityTypeNotFound(entity));
}
return dao.findEntityReferenceById(id);
}

public static <T> EntityReference getEntityReference(T entity) {
String entityType = getEntityTypeFromObject(entity);

Expand Down Expand Up @@ -277,6 +270,8 @@ public static String getEntityTypeFromObject(Object object) {

/** Class for getting validated entity list from a queryParam with list of entities. */
public static class EntityList {
private EntityList() {}

public static List<String> getEntityList(String name, String entitiesParam) {
if (entitiesParam == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static OpenMetadataIngestionComponent makeOpenMetadataDatasourceComponent
return OpenMetadataIngestionComponent.builder().type(ingestionType).config(dbConfig).build();
}

public static OpenMetadataIngestionComponent makeElasticSearchSinkComponent(AirflowPipeline airflowPipeline) {
public static OpenMetadataIngestionComponent makeElasticSearchSinkComponent() {
Map<String, Object> sinkConfig = new HashMap<>();
return OpenMetadataIngestionComponent.builder().type("elasticsearch").config(sinkConfig).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private UpdateRequest updateUser(ChangeEvent event) throws IOException {
UserESIndex userESIndex = null;
if (event.getEntity() != null && event.getEventType() != EventType.ENTITY_SOFT_DELETED) {
User user = (User) event.getEntity();
userESIndex = UserESIndex.builder(user, event.getEventType()).build();
userESIndex = UserESIndex.builder(user).build();
}
switch (event.getEventType()) {
case ENTITY_CREATED:
Expand All @@ -334,7 +334,7 @@ private UpdateRequest updateTeam(ChangeEvent event) throws IOException {
TeamESIndex teamESIndex = null;
if (event.getEntity() != null && event.getEventType() != EventType.ENTITY_SOFT_DELETED) {
Team team = (Team) event.getEntity();
teamESIndex = TeamESIndex.builder(team, event.getEventType()).build();
teamESIndex = TeamESIndex.builder(team).build();
}
switch (event.getEventType()) {
case ENTITY_CREATED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class ParseTags {
ParseTags(List<String> tags) {
if (!tags.isEmpty()) {
List<String> tagsList = new ArrayList<>(tags);
String tierTag = null;
for (String tag : tagsList) {
if (tag.toLowerCase().matches("(.*)tier(.*)")) {
tierTag = tag;
Expand All @@ -280,7 +279,6 @@ class ParseTags {
}
if (tierTag != null) {
tagsList.remove(tierTag);
this.tierTag = tierTag;
}
this.tags = tagsList;
} else {
Expand Down Expand Up @@ -751,7 +749,7 @@ class UserESIndex {

Boolean deleted;

public static UserESIndexBuilder builder(User user, EventType eventType) {
public static UserESIndexBuilder builder(User user) {
List<String> teams = new ArrayList<>();
List<String> roles = new ArrayList<>();
List<ElasticSearchSuggest> suggest = new ArrayList<>();
Expand Down Expand Up @@ -817,7 +815,7 @@ class TeamESIndex {

Boolean deleted;

public static TeamESIndexBuilder builder(Team team, EventType eventType) {
public static TeamESIndexBuilder builder(Team team) {
List<String> users = new ArrayList<>();
List<String> owns = new ArrayList<>();
List<ElasticSearchSuggest> suggest = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
public class ElasticSearchRetriableException extends RetriableException {
private static final long serialVersionUID = 1L;

public ElasticSearchRetriableException() {
super();
}

public ElasticSearchRetriableException(String message, Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public static ChangeEvent getChangeEvent(String method, ContainerResponseContext
return null;
}

private static ChangeEvent getChangeEvent(EventType eventType, String entityType, EntityInterface entityInterface) {
private static ChangeEvent getChangeEvent(
EventType eventType, String entityType, EntityInterface<?> entityInterface) {
return new ChangeEvent()
.withEventType(eventType)
.withEntityId(entityInterface.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ public EventPublisherException(String message) {
public EventPublisherException(Throwable cause) {
super(cause);
}

public EventPublisherException() {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ public abstract class RetriableException extends EventPublisherException {

private static final long serialVersionUID = 1L;

public RetriableException(String message, Throwable cause) {
protected RetriableException(String message, Throwable cause) {
super(message, cause);
}

public RetriableException(String message) {
protected RetriableException(String message) {
super(message);
}

public RetriableException(Throwable cause) {
protected RetriableException(Throwable cause) {
super(cause);
}

public RetriableException() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,7 @@ public EntityReference validateFieldOrNull(String fieldName) throws IOException,
}
// this could be changed to Include.NON_DELETED because we validate only when creating entities linked to
// non-deleted entities.
Object entity = Entity.getEntity(entityReference, Fields.EMPTY_FIELDS, isDeleted);
return helper(entity).toEntityReference();
return helper(Entity.getEntity(entityReference, Fields.EMPTY_FIELDS, isDeleted)).toEntityReference();
}

/**
Expand Down Expand Up @@ -1081,17 +1080,17 @@ public final <K> boolean recordListChange(
updatedList = Optional.ofNullable(updatedList).orElse(Collections.emptyList());
for (K stored : origList) {
// If an entry in the original list is not in updated list, then it is deleted during update
K updated = updatedList.stream().filter(c -> typeMatch.test(c, stored)).findAny().orElse(null);
if (updated == null) {
K u = updatedList.stream().filter(c -> typeMatch.test(c, stored)).findAny().orElse(null);
if (u == null) {
deletedItems.add(stored);
}
}

for (K updated : updatedList) {
for (K U : updatedList) {
// If an entry in the updated list is not in original list, then it is added during update
K stored = origList.stream().filter(c -> typeMatch.test(c, updated)).findAny().orElse(null);
K stored = origList.stream().filter(c -> typeMatch.test(c, U)).findAny().orElse(null);
if (stored == null) { // New column added
addedItems.add(updated);
addedItems.add(U);
}
}
if (!addedItems.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public Thread create(Thread thread) throws IOException, ParseException {

// Add relationship User -- created --> Thread relationship
dao.relationshipDAO()
.insert(createdBy, thread.getId().toString(), "user", "thread", Relationship.CREATED.ordinal());
.insert(createdBy, thread.getId().toString(), Entity.USER, Entity.THREAD, Relationship.CREATED.ordinal());

// Add field relationship data asset Thread -- isAbout ---> entity/entityField
// relationship
dao.fieldRelationshipDAO()
.insert(
thread.getId().toString(), // from FQN
about.getFullyQualifiedFieldValue(), // to FQN
"thread", // From type
Entity.THREAD, // From type
about.getFullyQualifiedFieldType(), // to Type
Relationship.IS_ABOUT.ordinal());

Expand All @@ -84,7 +84,7 @@ public Thread create(Thread thread) throws IOException, ParseException {
.insert(
thread.getId().toString(),
owner.getId().toString(),
"thread",
Entity.THREAD,
owner.getType(),
Relationship.ADDRESSED_TO.ordinal());
}
Expand All @@ -102,7 +102,7 @@ public Thread create(Thread thread) throws IOException, ParseException {
mention.getFullyQualifiedFieldValue(),
thread.getId().toString(),
mention.getFullyQualifiedFieldType(),
"thread",
Entity.THREAD,
Relationship.MENTIONED_IN.ordinal()));

return thread;
Expand Down Expand Up @@ -137,7 +137,8 @@ public Thread addPostToThread(String id, Post post) throws IOException {
}
if (!relationAlreadyExists) {
dao.relationshipDAO()
.insert(post.getFrom(), thread.getId().toString(), "user", "thread", Relationship.REPLIED_TO.ordinal());
.insert(
post.getFrom(), thread.getId().toString(), Entity.USER, Entity.THREAD, Relationship.REPLIED_TO.ordinal());
}
return thread;
}
Expand All @@ -153,7 +154,7 @@ public ThreadCount getThreadsCount(String link, boolean isResolved) throws IOExc
result =
dao.feedDAO()
.listCountByEntityLink(
StringUtils.EMPTY, "thread", StringUtils.EMPTY, Relationship.IS_ABOUT.ordinal(), isResolved);
StringUtils.EMPTY, Entity.THREAD, StringUtils.EMPTY, Relationship.IS_ABOUT.ordinal(), isResolved);
} else {
EntityLink entityLink = EntityLink.parse(link);
EntityReference reference = EntityUtil.validateEntityLink(entityLink);
Expand All @@ -165,7 +166,7 @@ public ThreadCount getThreadsCount(String link, boolean isResolved) throws IOExc
dao.feedDAO()
.listCountByEntityLink(
entityLink.getFullyQualifiedFieldValue(),
"thread",
Entity.THREAD,
entityLink.getFullyQualifiedFieldType(),
Relationship.IS_ABOUT.ordinal(),
isResolved);
Expand Down Expand Up @@ -200,7 +201,7 @@ public List<Thread> listThreads(String link, int limitPosts) throws IOException
List<List<String>> result;

// TODO remove hardcoding of thread
// For a user entitylink get created or replied relationships to the thread
// For a user entityLink get created or replied relationships to the thread
if (reference.getType().equals(Entity.USER)) {
threadIds.addAll(getUserThreadIds(reference));
} else {
Expand All @@ -209,7 +210,7 @@ public List<Thread> listThreads(String link, int limitPosts) throws IOException
dao.fieldRelationshipDAO()
.listFromByAllPrefix(
entityLink.getFullyQualifiedFieldValue(),
"thread",
Entity.THREAD,
entityLink.getFullyQualifiedFieldType(),
Relationship.IS_ABOUT.ordinal());
result.forEach(l -> threadIds.add(l.get(1)));
Expand Down Expand Up @@ -251,15 +252,15 @@ private List<String> getUserThreadIds(EntityReference user) {
user.getName(),
user.getType(),
Relationship.CREATED.ordinal(),
"thread",
Entity.THREAD,
toBoolean(Include.NON_DELETED)));
threadIds.addAll(
dao.relationshipDAO()
.findTo(
user.getName(),
user.getType(),
Relationship.REPLIED_TO.ordinal(),
"thread",
Entity.THREAD,
toBoolean(Include.NON_DELETED)));
return threadIds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
public class GlossaryRepository extends EntityRepository<Glossary> {
private static final Fields GLOSSARY_UPDATE_FIELDS = new Fields(GlossaryResource.FIELD_LIST, "owner,tags");
private static final Fields GLOSSARY_PATCH_FIELDS = new Fields(GlossaryResource.FIELD_LIST, "owner,tags");
private final CollectionDAO dao;

public GlossaryRepository(CollectionDAO dao) {
super(
Expand All @@ -52,12 +51,11 @@ public GlossaryRepository(CollectionDAO dao) {
true,
true,
false);
this.dao = dao;
}

@Transaction
public EntityReference getOwnerReference(Glossary glossary) throws IOException {
return EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), glossary.getOwner());
return EntityUtil.populateOwner(daoCollection.userDAO(), daoCollection.teamDAO(), glossary.getOwner());
}

@Override
Expand All @@ -71,7 +69,7 @@ public Glossary setFields(Glossary glossary, Fields fields) throws IOException,
public void prepare(Glossary glossary) throws IOException, ParseException {
glossary.setOwner(helper(glossary).validateOwnerOrNull());
// TODO validate reviewers
glossary.setTags(EntityUtil.addDerivedTags(dao.tagDAO(), glossary.getTags()));
glossary.setTags(EntityUtil.addDerivedTags(daoCollection.tagDAO(), glossary.getTags()));
}

@Override
Expand All @@ -85,9 +83,9 @@ public void storeEntity(Glossary glossary, boolean update) throws IOException {
glossary.withOwner(null).withHref(null).withTags(null);

if (update) {
dao.glossaryDAO().update(glossary.getId(), JsonUtils.pojoToJson(glossary));
daoCollection.glossaryDAO().update(glossary.getId(), JsonUtils.pojoToJson(glossary));
} else {
dao.glossaryDAO().insert(glossary);
daoCollection.glossaryDAO().insert(glossary);
}

// Restore the relationships
Expand Down

0 comments on commit 7ea9e44

Please sign in to comment.