birt-core 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.project +12 -0
- data/Gemfile +1 -1
- data/birt-core.gemspec +3 -1
- data/lib/birt/core/data_set.rb +27 -0
- data/lib/birt/core/data_source.rb +27 -0
- data/lib/birt/core/mysql.rb +19 -0
- data/lib/birt/core/report/table_report.rb +2 -0
- data/lib/birt/core/rpt_design.rb +36 -0
- data/lib/birt/core/version.rb +1 -1
- data/lib/birt/core.rb +6 -0
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dd88b8f71e985e806347414c5548bcd9ce5013f
|
4
|
+
data.tar.gz: ce5bfa174ba56eba559f037b5245d7379754149c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 403653f667629407dcdbd2ec7a3c5e517c6d40639cd5e64b920b94f50e3a425bd1885a124d02e63c009a2f556a7b219a4a18da51832842448b2d04b9b131e04b
|
7
|
+
data.tar.gz: f13c91555c88b2c98ecc02ee3ee0bc0e7310b2a9c4e3d164f250df1e279fa994a3859188d42571c9a2f8c6413aa20e5221d981432ad72c544bde91625b0c7861
|
data/.gitignore
CHANGED
data/.project
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>birt-core</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
</buildSpec>
|
9
|
+
<natures>
|
10
|
+
<nature>org.eclipse.birt.report.designer.ui.reportprojectnature</nature>
|
11
|
+
</natures>
|
12
|
+
</projectDescription>
|
data/Gemfile
CHANGED
data/birt-core.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/mumaoxi/birt-core"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|birt)/}) }
|
18
18
|
spec.bindir = "exe"
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
@@ -25,4 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.9"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "core_extend", "~> 0.1.5"
|
29
|
+
spec.add_development_dependency "mysql2","~> 0.3.19"
|
28
30
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Birt::Core::DataSet
|
2
|
+
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :columns
|
5
|
+
attr_accessor :query_text
|
6
|
+
attr_accessor :query_result
|
7
|
+
attr_accessor :data_source
|
8
|
+
|
9
|
+
def initialize(xml_element)
|
10
|
+
self.columns = Array.new
|
11
|
+
if xml_element
|
12
|
+
self.name = xml_element.attribute(:name).value
|
13
|
+
xml_element.get_elements("list-property[@name='resultSet']/structure/property[@name='name']").each do |column|
|
14
|
+
self.columns.push column.text
|
15
|
+
end
|
16
|
+
self.query_text = xml_element.get_elements("xml-property[@name='queryText']")[0].text.gsub("\n", ' ')
|
17
|
+
end
|
18
|
+
yield(self) if block_given?
|
19
|
+
end
|
20
|
+
|
21
|
+
#开始查询
|
22
|
+
def query
|
23
|
+
Birt::Core::Mysql.query(self.data_source, query_text).each do |row|
|
24
|
+
p row
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Birt::Core::DataSource
|
2
|
+
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :host
|
5
|
+
attr_accessor :port
|
6
|
+
attr_accessor :username
|
7
|
+
attr_accessor :password
|
8
|
+
attr_accessor :database
|
9
|
+
|
10
|
+
def initialize(xml_element)
|
11
|
+
if xml_element
|
12
|
+
self.name = xml_element.attribute(:name).value
|
13
|
+
self.host = xml_element.get_elements("property[@name='odaURL']")[0].text
|
14
|
+
self.username = xml_element.get_elements("property[@name='odaUser']")[0].text
|
15
|
+
self.password = Base64.decode64 xml_element.get_elements("encrypted-property[@name='odaPassword']")[0].text
|
16
|
+
end
|
17
|
+
yield(self) if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
def host=(host)
|
21
|
+
host_port = host.gsub('jdbc:mysql://', '').split(':')
|
22
|
+
port_database = host_port[1].split('/')
|
23
|
+
@host = host_port[0]
|
24
|
+
@port = port_database[0]
|
25
|
+
@database = port_database[1]
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Birt::Core::Mysql
|
2
|
+
|
3
|
+
def self.client(data_source)
|
4
|
+
@client ||=Mysql2::Core::Client.new(
|
5
|
+
host: data_source.host,
|
6
|
+
port: data_source.port,
|
7
|
+
username: data_source.username,
|
8
|
+
password: data_source.password,
|
9
|
+
database: data_source.database
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.query(data_source, query_text)
|
14
|
+
client = client(data_source)
|
15
|
+
results = client.query(query_text)
|
16
|
+
yield(results) if block_given?
|
17
|
+
results
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Birt::Core::RptDesign
|
2
|
+
|
3
|
+
#design文件路径
|
4
|
+
attr_accessor :rpt_design_path
|
5
|
+
attr_accessor :data_sources
|
6
|
+
attr_accessor :data_sets
|
7
|
+
|
8
|
+
def initialize(rpt_design_path)
|
9
|
+
self.rpt_design_path = rpt_design_path
|
10
|
+
self.data_sources = Hash.new
|
11
|
+
self.data_sets = Hash.new
|
12
|
+
end
|
13
|
+
|
14
|
+
#解析文件
|
15
|
+
def parse_rpt
|
16
|
+
_root = REXML::Document.new(File.read(self.rpt_design_path)).root
|
17
|
+
|
18
|
+
#数据源
|
19
|
+
_root.each_element(xpath = '/report/data-sources/oda-data-source') do |item|
|
20
|
+
self.data_sources[item.attribute(:name).value] = Birt::Core::DataSource.new(item)
|
21
|
+
end
|
22
|
+
|
23
|
+
#数据集
|
24
|
+
_root.each_element(xpath='/report/data-sets/oda-data-set') do |item|
|
25
|
+
self.data_sets[item.attribute(:name).value] = Birt::Core::DataSet.new(item) do |data_set|
|
26
|
+
data_set.data_source = self.data_sources[item.get_elements("property[@name='dataSource']")[0].text]
|
27
|
+
data_set.query
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
p self.data_sources
|
32
|
+
p self.data_sets
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/lib/birt/core/version.rb
CHANGED
data/lib/birt/core.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
require "birt/core/version"
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'base64'
|
4
|
+
require 'mysql2'
|
5
|
+
|
6
|
+
Dir.glob("#{File.dirname(__FILE__)}/core/*.rb") { |f| require f }
|
7
|
+
Dir.glob("#{File.dirname(__FILE__)}/core/report/*.rb") { |f| require f }
|
2
8
|
|
3
9
|
module Birt
|
4
10
|
module Core
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: birt-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stream
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: core_extend
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.5
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.3.19
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.3.19
|
41
69
|
description: birt report design parser
|
42
70
|
email:
|
43
71
|
- 15201280641@qq.com
|
@@ -46,6 +74,7 @@ extensions: []
|
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
76
|
- ".gitignore"
|
77
|
+
- ".project"
|
49
78
|
- CODE_OF_CONDUCT.md
|
50
79
|
- Gemfile
|
51
80
|
- LICENSE
|
@@ -56,6 +85,11 @@ files:
|
|
56
85
|
- bin/setup
|
57
86
|
- birt-core.gemspec
|
58
87
|
- lib/birt/core.rb
|
88
|
+
- lib/birt/core/data_set.rb
|
89
|
+
- lib/birt/core/data_source.rb
|
90
|
+
- lib/birt/core/mysql.rb
|
91
|
+
- lib/birt/core/report/table_report.rb
|
92
|
+
- lib/birt/core/rpt_design.rb
|
59
93
|
- lib/birt/core/version.rb
|
60
94
|
homepage: https://github.com/mumaoxi/birt-core
|
61
95
|
licenses:
|