Search in sources :

Example 1 with MetricProjectionMaker

use of com.yahoo.elide.datastores.aggregation.query.MetricProjectionMaker in project elide by yahoo.

the class TableType method buildAnnotations.

private static Map<Class<? extends Annotation>, Annotation> buildAnnotations(Measure measure) {
    Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
    annotations.put(ColumnMeta.class, new ColumnMeta() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return ColumnMeta.class;
        }

        @Override
        public String friendlyName() {
            return measure.getFriendlyName();
        }

        @Override
        public String description() {
            return measure.getDescription();
        }

        @Override
        public String category() {
            return measure.getCategory();
        }

        @Override
        public TableSource tableSource() {
            return buildTableSource(null);
        }

        @Override
        public String[] tags() {
            return measure.getTags().toArray(new String[0]);
        }

        @Override
        public String[] values() {
            return new String[0];
        }

        @Override
        public boolean isHidden() {
            return measure.getHidden() != null && measure.getHidden();
        }

        @Override
        public String filterTemplate() {
            return measure.getFilterTemplate();
        }

        @Override
        public CardinalitySize size() {
            return CardinalitySize.UNKNOWN;
        }
    });
    annotations.put(MetricFormula.class, new MetricFormula() {

        @Override
        public ArgumentDefinition[] arguments() {
            return getArgumentDefinitions(measure.getArguments());
        }

        @Override
        public Class<? extends Annotation> annotationType() {
            return MetricFormula.class;
        }

        @Override
        public String value() {
            if (measure.getDefinition() != null) {
                return trimColumnReferences(measure.getDefinition());
            } else {
                return "";
            }
        }

        @Override
        public Class<? extends MetricProjectionMaker> maker() {
            if (measure.getMaker() == null || measure.getMaker().isEmpty()) {
                return DefaultMetricProjectionMaker.class;
            }
            try {
                return (Class<? extends MetricProjectionMaker>) Class.forName(measure.getMaker());
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException(e);
            }
        }
    });
    String readPermission = measure.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;
}
Also used : CardinalitySize(com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize) MetricFormula(com.yahoo.elide.datastores.aggregation.annotation.MetricFormula) MetricProjectionMaker(com.yahoo.elide.datastores.aggregation.query.MetricProjectionMaker) DefaultMetricProjectionMaker(com.yahoo.elide.datastores.aggregation.query.DefaultMetricProjectionMaker) HashMap(java.util.HashMap) Annotation(java.lang.annotation.Annotation) TableSource(com.yahoo.elide.datastores.aggregation.annotation.TableSource) ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) ReadPermission(com.yahoo.elide.annotation.ReadPermission)

Aggregations

ReadPermission (com.yahoo.elide.annotation.ReadPermission)1 CardinalitySize (com.yahoo.elide.datastores.aggregation.annotation.CardinalitySize)1 ColumnMeta (com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta)1 MetricFormula (com.yahoo.elide.datastores.aggregation.annotation.MetricFormula)1 TableSource (com.yahoo.elide.datastores.aggregation.annotation.TableSource)1 DefaultMetricProjectionMaker (com.yahoo.elide.datastores.aggregation.query.DefaultMetricProjectionMaker)1 MetricProjectionMaker (com.yahoo.elide.datastores.aggregation.query.MetricProjectionMaker)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1