use of com.yahoo.elide.datastores.aggregation.annotation.TableMeta in project elide by yahoo.
the class TableType method buildAnnotations.
private static Map<Class<? extends Annotation>, Annotation> buildAnnotations(Table table) {
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
annotations.put(Include.class, getIncludeAnnotation(table));
if (table.getSql() != null && !table.getSql().isEmpty()) {
annotations.put(FromSubquery.class, new FromSubquery() {
@Override
public Class<? extends Annotation> annotationType() {
return FromSubquery.class;
}
@Override
public String sql() {
return table.getSql();
}
@Override
public String dbConnectionName() {
return table.getDbConnectionName();
}
});
} else {
annotations.put(FromTable.class, new FromTable() {
@Override
public Class<? extends Annotation> annotationType() {
return FromTable.class;
}
@Override
public String name() {
String tableName = table.getTable();
if (table.getSchema() != null && !table.getSchema().isEmpty()) {
return table.getSchema() + "." + tableName;
}
return tableName;
}
@Override
public String dbConnectionName() {
return table.getDbConnectionName();
}
});
}
annotations.put(TableMeta.class, new TableMeta() {
@Override
public Class<? extends Annotation> annotationType() {
return TableMeta.class;
}
@Override
public String friendlyName() {
return table.getFriendlyName();
}
@Override
public String description() {
return table.getDescription();
}
@Override
public String category() {
return table.getCategory();
}
@Override
public String[] hints() {
return table.getHints().toArray(new String[0]);
}
@Override
public String[] tags() {
return table.getTags().toArray(new String[0]);
}
@Override
public String filterTemplate() {
return table.getFilterTemplate();
}
@Override
public boolean isFact() {
return table.getIsFact();
}
@Override
public boolean isHidden() {
return table.getHidden() != null && table.getHidden();
}
@Override
public CardinalitySize size() {
if (table.getCardinality() == null || table.getCardinality().isEmpty()) {
return CardinalitySize.UNKNOWN;
}
return CardinalitySize.valueOf(table.getCardinality().toUpperCase(Locale.ENGLISH));
}
@Override
public ArgumentDefinition[] arguments() {
return getArgumentDefinitions(table.getArguments());
}
});
String readPermission = table.getReadAccess();
if (StringUtils.isNotEmpty(readPermission)) {
annotations.put(ReadPermission.class, new ReadPermission() {
@Override
public Class<? extends Annotation> annotationType() {
return ReadPermission.class;
}
@Override
public String expression() {
return readPermission;
}
});
}
return annotations;
}
use of com.yahoo.elide.datastores.aggregation.annotation.TableMeta in project elide by yahoo.
the class TableTypeTest method testHiddenTableAnnotations.
@Test
void testHiddenTableAnnotations() throws Exception {
Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").hidden(true).schema("db1").category("category1").build();
TableType testType = new TableType(testTable);
Include include = (Include) testType.getAnnotation(Include.class);
assertNotNull(include);
TableMeta tableMeta = (TableMeta) testType.getAnnotation(TableMeta.class);
assertNotNull(tableMeta);
assertTrue(tableMeta.isHidden());
}
use of com.yahoo.elide.datastores.aggregation.annotation.TableMeta in project elide by yahoo.
the class TableTypeTest method testTableAnnotations.
@Test
void testTableAnnotations() throws Exception {
Set<String> tags = new HashSet<>(Arrays.asList("tag1", "tag2"));
Set<String> hints = new HashSet<>(Arrays.asList("hint1", "hint2"));
Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").tags(tags).hints(hints).build();
TableType testType = new TableType(testTable);
Include include = (Include) testType.getAnnotation(Include.class);
assertEquals("Table", include.name());
FromTable fromTable = (FromTable) testType.getAnnotation(FromTable.class);
assertEquals("db1.table1", fromTable.name());
assertEquals("dbConn", fromTable.dbConnectionName());
TableMeta tableMeta = (TableMeta) testType.getAnnotation(TableMeta.class);
assertEquals("foo", tableMeta.friendlyName());
assertEquals(CardinalitySize.MEDIUM, tableMeta.size());
assertEquals("A test table", tableMeta.description());
assertEquals("category1", tableMeta.category());
assertTrue(tableMeta.isFact());
assertEquals(tags, new HashSet<>(Arrays.asList(tableMeta.tags())));
assertEquals(hints, new HashSet<>(Arrays.asList(tableMeta.hints())));
assertEquals("a==b", tableMeta.filterTemplate());
ReadPermission readPermission = (ReadPermission) testType.getAnnotation(ReadPermission.class);
assertEquals("Admin", readPermission.expression());
}
Aggregations