13
13
14
14
package com .netflix .metacat .main .api ;
15
15
16
+ import com .facebook .presto .spi .SchemaTableName ;
17
+ import com .facebook .presto .spi .TableNotFoundException ;
16
18
import com .netflix .metacat .common .MetacatContext ;
17
19
import com .netflix .metacat .common .QualifiedName ;
18
20
import com .netflix .metacat .common .api .TagV1 ;
19
21
import com .netflix .metacat .common .server .events .MetacatEventBus ;
20
22
import com .netflix .metacat .common .server .events .MetacatUpdateTablePostEvent ;
21
23
import com .netflix .metacat .common .usermetadata .TagService ;
22
24
import com .netflix .metacat .common .util .MetacatContextManager ;
25
+ import com .netflix .metacat .main .services .TableService ;
23
26
24
27
import javax .inject .Inject ;
25
28
import java .util .List ;
34
37
public class TagV1Resource implements TagV1 {
35
38
TagService tagService ;
36
39
MetacatEventBus eventBus ;
40
+ TableService tableService ;
37
41
@ Inject
38
- public TagV1Resource ( MetacatEventBus eventBus , TagService tagService ) {
42
+ public TagV1Resource ( MetacatEventBus eventBus , TagService tagService , TableService tableService ) {
39
43
this .tagService = tagService ;
40
44
this .eventBus = eventBus ;
45
+ this .tableService = tableService ;
41
46
}
42
47
43
48
@ Override
@@ -72,9 +77,11 @@ public Set<String> setTableTags(
72
77
Set <String > tags ) {
73
78
MetacatContext metacatContext = MetacatContextManager .getContext ();
74
79
QualifiedName name = qualifyName (() -> QualifiedName .ofTable (catalogName , databaseName , tableName ));
75
- return requestWrapper ("TagV1Resource.setTableTags" , () -> {
76
- Set <String > result = tagService .setTableTags ( name , tags , true );
77
-
80
+ return requestWrapper ( name , "TagV1Resource.setTableTags" , () -> {
81
+ if ( !tableService .exists (name )){
82
+ throw new TableNotFoundException (new SchemaTableName ( name .getDatabaseName (), name .getTableName ()));
83
+ }
84
+ Set <String > result = tagService .setTableTags (name , tags , true );
78
85
eventBus .post (new MetacatUpdateTablePostEvent (name , metacatContext ));
79
86
return result ;
80
87
});
@@ -89,7 +96,10 @@ public void removeTableTags(
89
96
Set <String > tags ) {
90
97
MetacatContext metacatContext = MetacatContextManager .getContext ();
91
98
QualifiedName name = qualifyName (() -> QualifiedName .ofTable (catalogName , databaseName , tableName ));
92
- requestWrapper ("TagV1Resource.removeTableTags" , () -> {
99
+ requestWrapper ( name , "TagV1Resource.removeTableTags" , () -> {
100
+ if ( !tableService .exists (name )){
101
+ throw new TableNotFoundException (new SchemaTableName ( name .getDatabaseName (), name .getTableName ()));
102
+ }
93
103
tagService .removeTableTags ( name , deleteAll , tags , true );
94
104
95
105
eventBus .post (new MetacatUpdateTablePostEvent (name , metacatContext ));
0 commit comments