mpxj 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +292 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +792 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/mpxj.rb +11 -0
- data/lib/mpxj/assignment.rb +11 -0
- data/lib/mpxj/container.rb +91 -0
- data/lib/mpxj/project.rb +83 -0
- data/lib/mpxj/reader.rb +22 -0
- data/lib/mpxj/relation.rb +4 -0
- data/lib/mpxj/resource.rb +9 -0
- data/lib/mpxj/task.rb +47 -0
- data/lib/mpxj/version.rb +3 -0
- data/mpxj.gemspec +26 -0
- metadata +134 -0
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "mpxj"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/mpxj.rb
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require 'duration'
|
|
2
|
+
require 'time'
|
|
3
|
+
|
|
4
|
+
module MPXJ
|
|
5
|
+
class Container
|
|
6
|
+
attr_reader :parent_project
|
|
7
|
+
def initialize(parent_project, attribute_types, attribute_values)
|
|
8
|
+
@parent_project = parent_project
|
|
9
|
+
@attribute_types = attribute_types
|
|
10
|
+
@attribute_values = attribute_values
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def method_missing(name, *args, &block)
|
|
14
|
+
attribute_name = name.to_s
|
|
15
|
+
attribute_type = @attribute_types[attribute_name]
|
|
16
|
+
attribute_value = @attribute_values[attribute_name]
|
|
17
|
+
|
|
18
|
+
if attribute_type.nil? && attribute_value.nil?
|
|
19
|
+
super
|
|
20
|
+
else
|
|
21
|
+
if attribute_type.nil?
|
|
22
|
+
attribute_type = 1
|
|
23
|
+
end
|
|
24
|
+
get_attribute_value(attribute_type, attribute_value)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
attr_reader :attribute_values
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def get_attribute_value(attribute_type, attribute_value)
|
|
35
|
+
case attribute_type.to_i
|
|
36
|
+
when 12, 17
|
|
37
|
+
get_integer_value(attribute_value)
|
|
38
|
+
when 8, 3, 5, 7
|
|
39
|
+
get_float_value(attribute_value)
|
|
40
|
+
when 2
|
|
41
|
+
get_date_value(attribute_value)
|
|
42
|
+
when 6, 16
|
|
43
|
+
get_duration_value(attribute_value)
|
|
44
|
+
when 4
|
|
45
|
+
get_boolean_value(attribute_value)
|
|
46
|
+
else
|
|
47
|
+
attribute_value
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def get_duration_value(attribute_value)
|
|
52
|
+
if attribute_value.nil?
|
|
53
|
+
Duration.new(0)
|
|
54
|
+
else
|
|
55
|
+
Duration.new(attribute_value.to_i)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def get_date_value(attribute_value)
|
|
60
|
+
if attribute_value.nil?
|
|
61
|
+
nil
|
|
62
|
+
else
|
|
63
|
+
Time.parse(attribute_value)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_float_value(attribute_value)
|
|
68
|
+
if attribute_value.nil?
|
|
69
|
+
0.0
|
|
70
|
+
else
|
|
71
|
+
attribute_value.to_f
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def get_integer_value(attribute_value)
|
|
76
|
+
if attribute_value.nil?
|
|
77
|
+
0
|
|
78
|
+
else
|
|
79
|
+
attribute_value.to_i
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def get_boolean_value(attribute_value)
|
|
84
|
+
if attribute_value.nil?
|
|
85
|
+
false
|
|
86
|
+
else
|
|
87
|
+
attribute_value == "true"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/mpxj/project.rb
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module MPXJ
|
|
4
|
+
class Project
|
|
5
|
+
attr_reader :all_resources
|
|
6
|
+
attr_reader :all_tasks
|
|
7
|
+
attr_reader :child_tasks
|
|
8
|
+
attr_reader :all_assignments
|
|
9
|
+
def initialize(file_name)
|
|
10
|
+
@resources_by_unique_id = {}
|
|
11
|
+
@tasks_by_unique_id = {}
|
|
12
|
+
|
|
13
|
+
@resources_by_id = {}
|
|
14
|
+
@tasks_by_id = {}
|
|
15
|
+
|
|
16
|
+
@all_resources = []
|
|
17
|
+
@all_tasks = []
|
|
18
|
+
@all_assignments = []
|
|
19
|
+
@child_tasks = []
|
|
20
|
+
|
|
21
|
+
file = File.read(file_name)
|
|
22
|
+
json_data = JSON.parse(file)
|
|
23
|
+
process_resources(json_data)
|
|
24
|
+
process_tasks(json_data)
|
|
25
|
+
process_assignments(json_data)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get_resource_by_unique_id(unique_id)
|
|
29
|
+
@resources_by_unique_id[unique_id]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_task_by_unique_id(unique_id)
|
|
33
|
+
@tasks_by_unique_id[unique_id]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get_resource_by_id(id)
|
|
37
|
+
@resources_by_id[id]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def get_task_by_id(id)
|
|
41
|
+
@tasks_by_unique_id[id]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def process_resources(json_data)
|
|
47
|
+
attribute_types = json_data["resource_types"]
|
|
48
|
+
resources = json_data["resources"]
|
|
49
|
+
resources.each do |attribute_values|
|
|
50
|
+
resource = Resource.new(self, attribute_types, attribute_values)
|
|
51
|
+
@all_resources << resource
|
|
52
|
+
@resources_by_unique_id[resource.unique_id] = resource
|
|
53
|
+
@resources_by_id[resource.id] = resource
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def process_tasks(json_data)
|
|
58
|
+
attribute_types = json_data["task_types"]
|
|
59
|
+
tasks = json_data["tasks"]
|
|
60
|
+
tasks.each do |attribute_values|
|
|
61
|
+
task = Task.new(self, attribute_types, attribute_values)
|
|
62
|
+
@all_tasks << task
|
|
63
|
+
@tasks_by_unique_id[task.unique_id] = task
|
|
64
|
+
@tasks_by_id[task.id] = task
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def process_assignments(json_data)
|
|
69
|
+
attribute_types = json_data["assignment_types"]
|
|
70
|
+
assignments = json_data["assignments"]
|
|
71
|
+
assignments.each do |attribute_values|
|
|
72
|
+
assignment = Assignment.new(self, attribute_types, attribute_values)
|
|
73
|
+
@all_assignments << assignment
|
|
74
|
+
if assignment.task
|
|
75
|
+
assignment.task.assignments << assignment
|
|
76
|
+
end
|
|
77
|
+
if assignment.resource
|
|
78
|
+
assignment.resource.assignments << assignment
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/lib/mpxj/reader.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'tempfile'
|
|
2
|
+
|
|
3
|
+
module MPXJ
|
|
4
|
+
class Reader
|
|
5
|
+
def self.read(file_name)
|
|
6
|
+
project = nil
|
|
7
|
+
json_file = Tempfile.new([File.basename(file_name, ".*"), '.json'])
|
|
8
|
+
begin
|
|
9
|
+
classpath = Dir["#{File.dirname(__FILE__)}/*.jar"].join(";")
|
|
10
|
+
java_output = `java -cp \"#{classpath}\" net.sf.mpxj.sample.MpxjConvert #{file_name} #{json_file.path}`
|
|
11
|
+
if $?.exitstatus != 0
|
|
12
|
+
raise "Failed to read file: #{java_output}"
|
|
13
|
+
end
|
|
14
|
+
project = Project.new(json_file)
|
|
15
|
+
ensure
|
|
16
|
+
json_file.close
|
|
17
|
+
json_file.unlink
|
|
18
|
+
end
|
|
19
|
+
project
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/mpxj/task.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module MPXJ
|
|
2
|
+
class Task < Container
|
|
3
|
+
RELATION_ATTRIBUTE_TYPES = {"task_unique_id" => 17, "lag" => 6, "type" => 10}
|
|
4
|
+
|
|
5
|
+
attr_reader :assignments
|
|
6
|
+
attr_reader :predecessors
|
|
7
|
+
attr_reader :successors
|
|
8
|
+
attr_reader :child_tasks
|
|
9
|
+
|
|
10
|
+
def initialize(parent_project, attribute_types, attribute_values)
|
|
11
|
+
super(parent_project, attribute_types, attribute_values)
|
|
12
|
+
@assignments = []
|
|
13
|
+
@child_tasks = []
|
|
14
|
+
process_relations
|
|
15
|
+
process_hierarchy
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def parent_task
|
|
19
|
+
parent_project.get_task_by_unique_id(parent_task_unique_id)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def process_relations
|
|
25
|
+
@predecessors = process_relation_list(attribute_values["predecessors"])
|
|
26
|
+
@successors = process_relation_list(attribute_values["successors"])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def process_relation_list(list)
|
|
30
|
+
result = []
|
|
31
|
+
if list
|
|
32
|
+
list.each do |attribute_values|
|
|
33
|
+
result << Relation.new(self, RELATION_ATTRIBUTE_TYPES, attribute_values)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
result
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def process_hierarchy
|
|
40
|
+
if parent_task
|
|
41
|
+
parent_task.child_tasks << self
|
|
42
|
+
else
|
|
43
|
+
parent_project.child_tasks << self
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/mpxj/version.rb
ADDED
data/mpxj.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'mpxj/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "mpxj"
|
|
8
|
+
spec.version = MPXJ::VERSION
|
|
9
|
+
spec.authors = ["Jon Iles"]
|
|
10
|
+
spec.email = ["jon.iles@bcs.org.uk"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "The MPXJ gem allows Ruby applications to work with schedule data from project management applications including Microsoft Project, Primavera, Asta Powerproject and Gnome Planner amongst others. The gem provides a Ruby wrapper around the MPXJ Java JAR."
|
|
13
|
+
spec.homepage = "http://mpxj.sf.net"
|
|
14
|
+
|
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
16
|
+
spec.bindir = "exe"
|
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
18
|
+
spec.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
22
|
+
spec.add_development_dependency "rspec"
|
|
23
|
+
|
|
24
|
+
spec.add_dependency "json"
|
|
25
|
+
spec.add_dependency "duration"
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mpxj
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jon Iles
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.8'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.8'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: json
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: duration
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description:
|
|
84
|
+
email:
|
|
85
|
+
- jon.iles@bcs.org.uk
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".rspec"
|
|
91
|
+
- ".rubocop.yml"
|
|
92
|
+
- ".travis.yml"
|
|
93
|
+
- Gemfile
|
|
94
|
+
- README.md
|
|
95
|
+
- Rakefile
|
|
96
|
+
- bin/console
|
|
97
|
+
- bin/setup
|
|
98
|
+
- lib/mpxj.rb
|
|
99
|
+
- lib/mpxj/assignment.rb
|
|
100
|
+
- lib/mpxj/container.rb
|
|
101
|
+
- lib/mpxj/project.rb
|
|
102
|
+
- lib/mpxj/reader.rb
|
|
103
|
+
- lib/mpxj/relation.rb
|
|
104
|
+
- lib/mpxj/resource.rb
|
|
105
|
+
- lib/mpxj/task.rb
|
|
106
|
+
- lib/mpxj/version.rb
|
|
107
|
+
- mpxj.gemspec
|
|
108
|
+
homepage: http://mpxj.sf.net
|
|
109
|
+
licenses: []
|
|
110
|
+
metadata: {}
|
|
111
|
+
post_install_message:
|
|
112
|
+
rdoc_options: []
|
|
113
|
+
require_paths:
|
|
114
|
+
- lib
|
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - ">="
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0'
|
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
requirements: []
|
|
126
|
+
rubyforge_project:
|
|
127
|
+
rubygems_version: 2.2.2
|
|
128
|
+
signing_key:
|
|
129
|
+
specification_version: 4
|
|
130
|
+
summary: The MPXJ gem allows Ruby applications to work with schedule data from project
|
|
131
|
+
management applications including Microsoft Project, Primavera, Asta Powerproject
|
|
132
|
+
and Gnome Planner amongst others. The gem provides a Ruby wrapper around the MPXJ
|
|
133
|
+
Java JAR.
|
|
134
|
+
test_files: []
|