Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
- [x]  GetTagForMetadataObject
- [x]  ListMetadataObjectsForTag
- [x]  AssociateTagsForMetadataObject
- [x]  ListTagsForMetadataObject
- [x]  ListTagsInfoForMetadataObject
  • Loading branch information
TungYuChiang committed Jan 11, 2025
1 parent bb762a4 commit 3184463
Show file tree
Hide file tree
Showing 2 changed files with 481 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,26 @@
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.exceptions.NoSuchTagException;
import org.apache.gravitino.listener.api.event.AlterTagEvent;
import org.apache.gravitino.listener.api.event.AlterTagFailureEvent;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.CreateTagEvent;
import org.apache.gravitino.listener.api.event.CreateTagFailureEvent;
import org.apache.gravitino.listener.api.event.DeleteTagEvent;
import org.apache.gravitino.listener.api.event.DeleteTagFailureEvent;
import org.apache.gravitino.listener.api.event.GetTagEvent;
import org.apache.gravitino.listener.api.event.GetTagFailureEvent;
import org.apache.gravitino.listener.api.event.GetTagForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.GetTagForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.ListMetadataObjectsForTagEvent;
import org.apache.gravitino.listener.api.event.ListMetadataObjectsForTagFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagEvent;
import org.apache.gravitino.listener.api.event.ListTagInfoEvent;
import org.apache.gravitino.listener.api.event.ListTagsForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoForMetadataObjectEvent;
import org.apache.gravitino.listener.api.info.TagInfo;
import org.apache.gravitino.listener.api.event.AlterTagFailureEvent;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.CreateTagFailureEvent;
import org.apache.gravitino.listener.api.event.DeleteTagFailureEvent;
import org.apache.gravitino.listener.api.event.GetTagFailureEvent;
import org.apache.gravitino.listener.api.event.GetTagForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.ListMetadataObjectsForTagFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.ListTagsForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.info.TagInfo;
import org.apache.gravitino.tag.Tag;
Expand Down Expand Up @@ -74,7 +73,7 @@ public String[] listTags(String metalake) {
return tagNames;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
new ListTagsFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
throw e;
}
}
Expand All @@ -85,11 +84,11 @@ public Tag[] listTagsInfo(String metalake) {
try {
Tag[] tags = dispatcher.listTagsInfo(metalake);
eventBus.dispatchEvent(
new ListTagInfoEvent(PrincipalUtils.getCurrentUserName(), metalake, tags));
new ListTagInfoEvent(PrincipalUtils.getCurrentUserName(), metalake, tags));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsInfoFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
new ListTagsInfoFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
throw e;
}
}
Expand All @@ -100,31 +99,31 @@ public Tag getTag(String metalake, String name) throws NoSuchTagException {
try {
Tag tag = dispatcher.getTag(metalake, name);
eventBus.dispatchEvent(
new GetTagEvent(PrincipalUtils.getCurrentUserName(), metalake, name, tag));
new GetTagEvent(PrincipalUtils.getCurrentUserName(), metalake, name, tag));
return tag;
} catch (Exception e) {
eventBus.dispatchEvent(
new GetTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, name, e));
new GetTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, name, e));
throw e;
}
}

@Override
public Tag createTag(
String metalake, String name, String comment, Map<String, String> properties) {
String metalake, String name, String comment, Map<String, String> properties) {
TagInfo tagInfo = new TagInfo(name, comment, properties);
// TODO: createTagPreEvent
try {
Tag tag = dispatcher.createTag(metalake, name, comment, properties);
eventBus.dispatchEvent(
new CreateTagEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
new TagInfo(tag.name(), tag.comment(), tag.properties())));
new CreateTagEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
new TagInfo(tag.name(), tag.comment(), tag.properties())));
return tag;
} catch (Exception e) {
eventBus.dispatchEvent(
new CreateTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, tagInfo, e));
new CreateTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, tagInfo, e));
throw e;
}
}
Expand All @@ -135,16 +134,16 @@ public Tag alterTag(String metalake, String name, TagChange... changes) {
try {
Tag tag = dispatcher.alterTag(metalake, name, changes);
eventBus.dispatchEvent(
new AlterTagEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
changes,
new TagInfo(tag.name(), tag.comment(), tag.properties())));
new AlterTagEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
changes,
new TagInfo(tag.name(), tag.comment(), tag.properties())));
return tag;
} catch (Exception e) {
eventBus.dispatchEvent(
new AlterTagFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, name, changes, e));
new AlterTagFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, name, changes, e));
throw e;
}
}
Expand All @@ -155,11 +154,11 @@ public boolean deleteTag(String metalake, String name) {
try {
boolean isExists = dispatcher.deleteTag(metalake, name);
eventBus.dispatchEvent(
new DeleteTagEvent(PrincipalUtils.getCurrentUserName(), metalake, isExists));
new DeleteTagEvent(PrincipalUtils.getCurrentUserName(), metalake, isExists));
return isExists;
} catch (Exception e) {
eventBus.dispatchEvent(
new DeleteTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, name, e));
new DeleteTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, name, e));
throw e;
}
}
Expand All @@ -170,13 +169,13 @@ public MetadataObject[] listMetadataObjectsForTag(String metalake, String name)
try {
MetadataObject[] metadataObjects = dispatcher.listMetadataObjectsForTag(metalake, name);
eventBus.dispatchEvent(
new ListMetadataObjectsForTagEvent(
PrincipalUtils.getCurrentUserName(), metalake, name, metadataObjects));
new ListMetadataObjectsForTagEvent(
PrincipalUtils.getCurrentUserName(), metalake, name, metadataObjects));
return metadataObjects;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListMetadataObjectsForTagFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, name, e));
new ListMetadataObjectsForTagFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, name, e));
throw e;
}
}
Expand All @@ -187,13 +186,13 @@ public String[] listTagsForMetadataObject(String metalake, MetadataObject metada
try {
String[] tags = dispatcher.listTagsForMetadataObject(metalake, metadataObject);
eventBus.dispatchEvent(
new ListTagsForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, tags));
new ListTagsForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, tags));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, e));
new ListTagsForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, e));
throw e;
}
}
Expand All @@ -204,43 +203,43 @@ public Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metad
try {
Tag[] tags = dispatcher.listTagsInfoForMetadataObject(metalake, metadataObject);
eventBus.dispatchEvent(
new ListTagsInfoForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, tags));
new ListTagsInfoForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, tags));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsInfoForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, e));
new ListTagsInfoForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, e));
throw e;
}
}

@Override
public String[] associateTagsForMetadataObject(
String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove) {
String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove) {
// TODO: associateTagsForMetadataObjectPreEvent
try {
String[] associatedTags =
dispatcher.associateTagsForMetadataObject(
metalake, metadataObject, tagsToAdd, tagsToRemove);
dispatcher.associateTagsForMetadataObject(
metalake, metadataObject, tagsToAdd, tagsToRemove);
eventBus.dispatchEvent(
new AssociateTagsForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
metadataObject,
tagsToAdd,
tagsToRemove,
associatedTags));
new AssociateTagsForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
metadataObject,
tagsToAdd,
tagsToRemove,
associatedTags));
return associatedTags;
} catch (Exception e) {
eventBus.dispatchEvent(
new AssociateTagsForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
metadataObject,
tagsToAdd,
tagsToRemove,
e));
new AssociateTagsForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
metadataObject,
tagsToAdd,
tagsToRemove,
e));
throw e;
}
}
Expand All @@ -251,14 +250,14 @@ public Tag getTagForMetadataObject(String metalake, MetadataObject metadataObjec
try {
Tag tag = dispatcher.getTagForMetadataObject(metalake, metadataObject, name);
eventBus.dispatchEvent(
new GetTagForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, name, tag));
new GetTagForMetadataObjectEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, name, tag));
return tag;
} catch (Exception e) {
eventBus.dispatchEvent(
new GetTagForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, name, e));
new GetTagForMetadataObjectFailureEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, name, e));
throw e;
}
}
}
}
Loading

0 comments on commit 3184463

Please sign in to comment.