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

Version Path
mondrian-rest-0.7.9-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.8-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.7-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.6-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.5-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.4-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.3-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.2-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.1-java lib/mondrian_rest/formatters/jsonstat.rb
mondrian-rest-0.7.0-java lib/mondrian_rest/formatters/jsonstat.rb