Sha256: 68f8ed9c781792d0f9cc4216a8b18a9237e60ef70e62db4a6bfd317eeecf2f7c
Contents?: true
Size: 1.54 KB
Versions: 10
Compression:
Stored size: 1.54 KB
Contents
require 'java' module Mondrian::REST::Formatters module JSONStat def self.call(result, env) mapper = Java::ComFasterxmlJacksonDatabind::ObjectMapper.new mapper.registerModule(Java::NoSsbJsonstat::JsonStatModule.new) mapper.registerModule(Java::ComFasterxmlJacksonDatatypeJdk8::Jdk8Module.new.configureAbsentsAsNulls(true)) mapper.setSerializationInclusion(Java::ComFasterxmlJacksonAnnotation::JsonInclude::Include::NON_NULL) mapper.registerModule(Java::ComFasterxmlJacksonDatatypeGuava::GuavaModule.new.configureAbsentsAsNulls(false)) rs = result.to_h rdims = rs[:axis_dimensions].reverse builder = Java::NoSsbJsonstatV2::Dataset .create .withLabel('Aggregation: ') .withSource(env['REQUEST_URI'] || '') dimensions = rdims.map.with_index do |d, i| dim = Java::NoSsbJsonstatV2::Dimension .create(d[:name]) if d[:type] == :measures dim = dim.withMetricRole elsif d[:type] == :time dim = dim.withTimeRole end dim.withLabel(d[:caption]) .withIndexedLabels( Java::ComGoogleCommonCollect::ImmutableMap.copyOf( Hash[*(rs[:axes][-1 - i][:members].map { |m| [ m[:key].to_s, m[:caption] ] }.flatten)].to_java ) ) end dataset = builder .withDimensions(dimensions) .withValues(rs[:values].flatten) .build mapper.writeValueAsString(dataset) end end end
Version data entries
10 entries across 10 versions & 1 rubygems