simcha-mappum 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.
- data/.gitignore +4 -0
- data/LICENSE +15 -0
- data/README +53 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/bin/mapserver.rb +4 -0
- data/lib/mappum.rb +19 -0
- data/lib/mappum/dsl.rb +186 -0
- data/lib/mappum/map.rb +133 -0
- data/lib/mappum/mapserver/mapgraph.rb +193 -0
- data/lib/mappum/mapserver/mapserver.rb +197 -0
- data/lib/mappum/mapserver/views/transform-ws.wsdl.erb +50 -0
- data/lib/mappum/mapserver/views/ws-error.erb +10 -0
- data/lib/mappum/open_xml_object.rb +61 -0
- data/lib/mappum/ruby_transform.rb +129 -0
- data/lib/mappum/xml_transform.rb +298 -0
- data/mappum.gemspec +89 -0
- data/sample/address_fixture.xml +11 -0
- data/sample/crm.rb +9 -0
- data/sample/crm_client.xsd +28 -0
- data/sample/erp.rb +7 -0
- data/sample/erp_person.xsd +36 -0
- data/sample/example_map.rb +87 -0
- data/sample/example_notypes.rb +61 -0
- data/sample/person_fixture.xml +23 -0
- data/sample/person_fixture_any.xml +23 -0
- data/sample/server/map/example_any.rb +28 -0
- data/sample/server/map/example_soap4r.rb +59 -0
- data/sample/server/mapserver.sh +1 -0
- data/sample/server/schema/crm_client.xsd +29 -0
- data/sample/server/schema/erp/erp_person.xsd +38 -0
- data/test/test_example.rb +137 -0
- data/test/test_openstruct.rb +129 -0
- data/test/test_soap4r.rb +108 -0
- data/test/test_xml_any.rb +62 -0
- metadata +130 -0
data/mappum.gemspec
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{mappum}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Jan Topi\305\204ski"]
|
9
|
+
s.date = %q{2009-06-29}
|
10
|
+
s.default_executable = %q{mapserver.rb}
|
11
|
+
s.description = %q{}
|
12
|
+
s.email = %q{jtopinski@chatka.org}
|
13
|
+
s.executables = ["mapserver.rb"]
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"LICENSE",
|
21
|
+
"README",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bin/mapserver.rb",
|
25
|
+
"lib/mappum.rb",
|
26
|
+
"lib/mappum/dsl.rb",
|
27
|
+
"lib/mappum/map.rb",
|
28
|
+
"lib/mappum/mapserver/mapgraph.rb",
|
29
|
+
"lib/mappum/mapserver/mapserver.rb",
|
30
|
+
"lib/mappum/mapserver/views/transform-ws.wsdl.erb",
|
31
|
+
"lib/mappum/mapserver/views/ws-error.erb",
|
32
|
+
"lib/mappum/open_xml_object.rb",
|
33
|
+
"lib/mappum/ruby_transform.rb",
|
34
|
+
"lib/mappum/xml_transform.rb",
|
35
|
+
"mappum.gemspec",
|
36
|
+
"sample/address_fixture.xml",
|
37
|
+
"sample/crm.rb",
|
38
|
+
"sample/crm_client.xsd",
|
39
|
+
"sample/erp.rb",
|
40
|
+
"sample/erp_person.xsd",
|
41
|
+
"sample/example_map.rb",
|
42
|
+
"sample/example_notypes.rb",
|
43
|
+
"sample/person_fixture.xml",
|
44
|
+
"sample/person_fixture_any.xml",
|
45
|
+
"sample/server/map/example_any.rb",
|
46
|
+
"sample/server/map/example_soap4r.rb",
|
47
|
+
"sample/server/mapserver.sh",
|
48
|
+
"sample/server/schema/crm_client.xsd",
|
49
|
+
"sample/server/schema/erp/erp_person.xsd",
|
50
|
+
"test/test_example.rb",
|
51
|
+
"test/test_openstruct.rb",
|
52
|
+
"test/test_soap4r.rb",
|
53
|
+
"test/test_xml_any.rb"
|
54
|
+
]
|
55
|
+
s.has_rdoc = true
|
56
|
+
s.homepage = %q{http://wiki.github.com/simcha/mappum}
|
57
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
58
|
+
s.require_paths = ["lib"]
|
59
|
+
s.rubygems_version = %q{1.3.1}
|
60
|
+
s.summary = %q{Mappum is the tree to tree (object, bean etc.) mapping DSL.}
|
61
|
+
s.test_files = [
|
62
|
+
"test/test_example.rb",
|
63
|
+
"test/test_openstruct.rb",
|
64
|
+
"test/test_xml_any.rb",
|
65
|
+
"test/test_soap4r.rb"
|
66
|
+
]
|
67
|
+
|
68
|
+
if s.respond_to? :specification_version then
|
69
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
70
|
+
s.specification_version = 2
|
71
|
+
|
72
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
73
|
+
s.add_runtime_dependency(%q<facets>, [">= 2.5.2"])
|
74
|
+
s.add_runtime_dependency(%q<soap4r>, [">= 1.5.8"])
|
75
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
|
76
|
+
s.add_runtime_dependency(%q<thin>, [">= 1.2.2"])
|
77
|
+
else
|
78
|
+
s.add_dependency(%q<facets>, [">= 2.5.2"])
|
79
|
+
s.add_dependency(%q<soap4r>, [">= 1.5.8"])
|
80
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
81
|
+
s.add_dependency(%q<thin>, [">= 1.2.2"])
|
82
|
+
end
|
83
|
+
else
|
84
|
+
s.add_dependency(%q<facets>, [">= 2.5.2"])
|
85
|
+
s.add_dependency(%q<soap4r>, [">= 1.5.8"])
|
86
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
87
|
+
s.add_dependency(%q<thin>, [">= 1.2.2"])
|
88
|
+
end
|
89
|
+
end
|
data/sample/crm.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module CRM
|
2
|
+
class Client
|
3
|
+
attr_accessor :title, :id, :key, :first_name, :surname, :address,
|
4
|
+
:sex_id, :phones, :emails, :main_phone, :main_phone_type, :company, :company_suffix, :order_by, :updated, :partners
|
5
|
+
end
|
6
|
+
class Address
|
7
|
+
attr_accessor :street
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xsd:schema version="1.0"
|
3
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
4
|
+
<xsd:element name="client">
|
5
|
+
<xsd:complexType>
|
6
|
+
<xsd:sequence>
|
7
|
+
<xsd:element name="title" type="xsd:string" maxOccurs="1"/>
|
8
|
+
<xsd:element name="id" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
9
|
+
<xsd:element name="first_name" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
10
|
+
<xsd:element name="surname" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
11
|
+
<xsd:element name="sex_id" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
12
|
+
<xsd:element name="phones" type="xsd:string" minOccurs="0" maxOccurs="20"/>
|
13
|
+
<xsd:element name="emails" type="xsd:string" minOccurs="0" maxOccurs="3"/>
|
14
|
+
<xsd:element name="main_phone" type="xsd:string" minOccurs="0" maxOccurs="3"/>
|
15
|
+
<xsd:element name="main_phone_type" type="xsd:string" minOccurs="0" maxOccurs="3"/>
|
16
|
+
<xsd:element name="address" minOccurs="0" maxOccurs="1">
|
17
|
+
<xsd:complexType>
|
18
|
+
<xsd:sequence>
|
19
|
+
<xsd:element name="street" type="xsd:string"/>
|
20
|
+
<xsd:element name="city" type="xsd:string" minOccurs="0"/>
|
21
|
+
</xsd:sequence>
|
22
|
+
</xsd:complexType>
|
23
|
+
</xsd:element>
|
24
|
+
</xsd:sequence>
|
25
|
+
</xsd:complexType>
|
26
|
+
</xsd:element>
|
27
|
+
</xsd:schema>
|
28
|
+
|
data/sample/erp.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xsd:schema version="1.0"
|
3
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
4
|
+
<xsd:element name="person">
|
5
|
+
<xsd:complexType>
|
6
|
+
<xsd:sequence>
|
7
|
+
<xsd:element name="title" type="xsd:string" maxOccurs="1"/>
|
8
|
+
<xsd:element name="person_id" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
9
|
+
<xsd:element name="name" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
10
|
+
<xsd:element name="surname" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
11
|
+
<xsd:element name="sex" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
12
|
+
<xsd:element name="email1" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
13
|
+
<xsd:element name="email2" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
14
|
+
<xsd:element name="email3" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
15
|
+
<xsd:element name="main_phone" type="phone" minOccurs="0" maxOccurs="1"/>
|
16
|
+
<xsd:element name="address" minOccurs="0" maxOccurs="1">
|
17
|
+
<xsd:complexType>
|
18
|
+
<xsd:sequence>
|
19
|
+
<xsd:element name="street" type="xsd:string"/>
|
20
|
+
<xsd:element name="city" type="xsd:string" minOccurs="0"/>
|
21
|
+
</xsd:sequence>
|
22
|
+
</xsd:complexType>
|
23
|
+
</xsd:element>
|
24
|
+
<xsd:element name="phones" type="phone" minOccurs="0" maxOccurs="5"/>
|
25
|
+
</xsd:sequence>
|
26
|
+
</xsd:complexType>
|
27
|
+
</xsd:element>
|
28
|
+
<xsd:complexType name="phone">
|
29
|
+
<xsd:sequence>
|
30
|
+
<xsd:element name="number" type="xsd:string"/>
|
31
|
+
<xsd:element name="extension" type="xsd:string" minOccurs="0"/>
|
32
|
+
<xsd:element name="type" type="xsd:string" minOccurs="0"/>
|
33
|
+
</xsd:sequence>
|
34
|
+
</xsd:complexType>
|
35
|
+
</xsd:schema>
|
36
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Example of map for given object domains CRM and ERP
|
2
|
+
require 'mappum'
|
3
|
+
require 'sample/erp'
|
4
|
+
require 'sample/crm'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
Mappum.catalogue_add "CRM-ERP" do
|
8
|
+
|
9
|
+
map ERP::Person, CRM::Client do |p, c|
|
10
|
+
|
11
|
+
#simple mapping
|
12
|
+
map p.title <=> c.title
|
13
|
+
|
14
|
+
#map with simple function call
|
15
|
+
map p.person_id << c.id.downcase
|
16
|
+
map p.person_id.upcase >> c.id
|
17
|
+
|
18
|
+
#dictionary use
|
19
|
+
map p.sex <=> c.sex_id, :dict => {"F" => "1", "M" => "2"}
|
20
|
+
|
21
|
+
#submaps
|
22
|
+
map p.address(ERP::Address) <=> c.address(CRM::Address) do |a, b|
|
23
|
+
map a.street <=> b.street
|
24
|
+
#etc.
|
25
|
+
end
|
26
|
+
|
27
|
+
#compicated finc call
|
28
|
+
map p.name >> c.surname do |name|
|
29
|
+
name + "ski"
|
30
|
+
end
|
31
|
+
map p.name << c.surname do |name|
|
32
|
+
if name =~ /ski/
|
33
|
+
name[0..-4]
|
34
|
+
else
|
35
|
+
name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
#field to array and array to field
|
39
|
+
map p.email1 <=> c.emails[0]
|
40
|
+
map p.email2 <=> c.emails[1]
|
41
|
+
map p.email3 <=> c.emails[2]
|
42
|
+
|
43
|
+
map p.spouse(ERP::Person) <=> c.partners[0] do |ps,cp|
|
44
|
+
map ps.name <=> cp.name
|
45
|
+
"Wife" >> cp.type
|
46
|
+
end
|
47
|
+
map p.spouse(ERP::Person) <=> c.partners[1] do |ps,cp|
|
48
|
+
map ps.name <=> cp.name
|
49
|
+
"Friend" >> cp.type
|
50
|
+
end
|
51
|
+
map p.phones(ERP::Phone)[] <=> c.phones[] do |a, b|
|
52
|
+
map a.number <=> b.self
|
53
|
+
end
|
54
|
+
|
55
|
+
#subobject to fields
|
56
|
+
map p.main_phone(ERP::Phone) <=> c.self do |a, b|
|
57
|
+
map a.number <=> b.main_phone
|
58
|
+
map a.type <=> b.main_phone_type
|
59
|
+
end
|
60
|
+
|
61
|
+
#TODO one to many
|
62
|
+
#map p.name << [c.first_name, c.surname] do |fname, surname|
|
63
|
+
# fname + " " + surname
|
64
|
+
#end
|
65
|
+
#map p.name.split >> [c.first_name, c.surname]
|
66
|
+
map p.corporation << c.self do |client|
|
67
|
+
"#{client.company} #{client.company_suffix}" unless client.company.nil?
|
68
|
+
end
|
69
|
+
map p.corporation >> c.company do |corpo|
|
70
|
+
corpo.split(" ")[0]
|
71
|
+
end
|
72
|
+
map p.corporation >> c.company_suffix do |corpo|
|
73
|
+
corpo.split(" ")[1]
|
74
|
+
end
|
75
|
+
#constants
|
76
|
+
map p.type << "NaN"
|
77
|
+
map "Last" >> c.order_by
|
78
|
+
|
79
|
+
#func
|
80
|
+
map p.date_updated << func do
|
81
|
+
Date.today
|
82
|
+
end
|
83
|
+
map func >> c.updated do
|
84
|
+
Time.now
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Example of map for given object domains CRM and ERP
|
2
|
+
require 'mappum'
|
3
|
+
|
4
|
+
|
5
|
+
Mappum.catalogue_add "NOTYPE-CRM-ERP" do
|
6
|
+
|
7
|
+
map :person, :client do |p, c|
|
8
|
+
|
9
|
+
#simple mapping
|
10
|
+
map p.title <=> c.title
|
11
|
+
|
12
|
+
#map with simple function call
|
13
|
+
map p.person_id << c.id.downcase
|
14
|
+
map p.person_id.upcase >> c.id
|
15
|
+
|
16
|
+
#dictionary use
|
17
|
+
map p.sex <=> c.sex_id, :dict => {"F" => "1", "M" => "2"}
|
18
|
+
|
19
|
+
#submaps
|
20
|
+
map p.address <=> c.address do |a, b|
|
21
|
+
map a.street <=> b.street
|
22
|
+
#etc.
|
23
|
+
end
|
24
|
+
|
25
|
+
#xml attributes
|
26
|
+
map p.xmlattr_id <=> c.xmlattr_ident
|
27
|
+
|
28
|
+
#compicated finc call
|
29
|
+
map p.name >> c.surname do |name|
|
30
|
+
name + "ski"
|
31
|
+
end
|
32
|
+
map p.name << c.surname do |name|
|
33
|
+
if name =~ /ski/
|
34
|
+
name[0..-4]
|
35
|
+
else
|
36
|
+
name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
#field to array and array to field
|
40
|
+
map p.email1 <=> c.emails[0]
|
41
|
+
map p.email2 <=> c.emails[1]
|
42
|
+
map p.email3 <=> c.emails[2]
|
43
|
+
|
44
|
+
map p.phones[] <=> c.phones[] do |a, b|
|
45
|
+
map a.number <=> b.self
|
46
|
+
end
|
47
|
+
|
48
|
+
#subobject to fields
|
49
|
+
map p.main_phone <=> c.self do |a, b|
|
50
|
+
map a.number <=> b.main_phone
|
51
|
+
map a.type <=> b.main_phone_type
|
52
|
+
end
|
53
|
+
|
54
|
+
#TODO one to many
|
55
|
+
#map p.name << [c.first_name, c.surname] do |fname, surname|
|
56
|
+
# fname + " " + surname
|
57
|
+
#end
|
58
|
+
#map p.name.split >> [c.first_name, c.surname]
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
2
|
+
<n1:person xmlns:n1="http://mappum.ivmx.pl/person">
|
3
|
+
<title>sir</title>
|
4
|
+
<person_id>asddsa</person_id>
|
5
|
+
<name>Skory</name>
|
6
|
+
<sex>M</sex>
|
7
|
+
<email1>j@j.com</email1>
|
8
|
+
<email2>k@k.com</email2>
|
9
|
+
<email3>l@l.com</email3>
|
10
|
+
<main_phone>
|
11
|
+
<number>09876567</number>
|
12
|
+
<type>mobile</type>
|
13
|
+
</main_phone>
|
14
|
+
<address>
|
15
|
+
<street>Victoria</street>
|
16
|
+
</address>
|
17
|
+
<phones>
|
18
|
+
<number>21311231</number>
|
19
|
+
</phones>
|
20
|
+
<phones>
|
21
|
+
<number>21311232</number>
|
22
|
+
</phones>
|
23
|
+
</n1:person>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
2
|
+
<person id="123212">
|
3
|
+
<title>sir</title>
|
4
|
+
<person_id>asddsa</person_id>
|
5
|
+
<name>Skory</name>
|
6
|
+
<sex>M</sex>
|
7
|
+
<email1>j@j.com</email1>
|
8
|
+
<email2>k@k.com</email2>
|
9
|
+
<email3>l@l.com</email3>
|
10
|
+
<main_phone>
|
11
|
+
<number>09876567</number>
|
12
|
+
<type>mobile</type>
|
13
|
+
</main_phone>
|
14
|
+
<address>
|
15
|
+
<street>Victoria</street>
|
16
|
+
</address>
|
17
|
+
<phones>
|
18
|
+
<number>21311231</number>
|
19
|
+
</phones>
|
20
|
+
<phones>
|
21
|
+
<number>21311232</number>
|
22
|
+
</phones>
|
23
|
+
</person>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Example of map for any type
|
2
|
+
|
3
|
+
Mappum.catalogue_add do
|
4
|
+
|
5
|
+
map :address, :adresse do |e, f|
|
6
|
+
|
7
|
+
#simple mapping
|
8
|
+
map e.city <=> f.ville
|
9
|
+
map e.street <=> f.rue
|
10
|
+
map e.zip_code <=> f.code_postale
|
11
|
+
|
12
|
+
#map with simple function call
|
13
|
+
map e.country << f.pays.downcase
|
14
|
+
map e.country.upcase >> f.pays
|
15
|
+
|
16
|
+
#submaps
|
17
|
+
map e.house <=> f.maison do |h, m|
|
18
|
+
map h.number <=> m.numero
|
19
|
+
map h.flat <=> m.appartement
|
20
|
+
end
|
21
|
+
`Current time`
|
22
|
+
map e.updated << func do
|
23
|
+
Time.now
|
24
|
+
end
|
25
|
+
map "oui" >> f.correct
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Example of map for given object domains CRM and ERP
|
2
|
+
|
3
|
+
Mappum.catalogue_add do
|
4
|
+
`
|
5
|
+
Mapping Erp system Person to Crm Client
|
6
|
+
`
|
7
|
+
map Erp::Person, Client do |p, c|
|
8
|
+
|
9
|
+
#simple mapping
|
10
|
+
map p.title <=> c.title
|
11
|
+
|
12
|
+
#map with simple function call
|
13
|
+
map p.person_id << c.id.downcase
|
14
|
+
map p.person_id.upcase >> c.id
|
15
|
+
|
16
|
+
`Map F to 1 and M to 2`
|
17
|
+
map p.sex <=> c.sex_id, :dict => {"F" => "1", "M" => "2"}
|
18
|
+
|
19
|
+
#submaps
|
20
|
+
map p.address(Erp::Person::Address) <=> c.address(Client::Address) do |a, b|
|
21
|
+
map a.street <=> b.street
|
22
|
+
#etc.
|
23
|
+
end
|
24
|
+
|
25
|
+
`Add 'ski' to name`
|
26
|
+
map p.name >> c.surname do |name|
|
27
|
+
name + "ski"
|
28
|
+
end
|
29
|
+
`Remove "ski" from surname`
|
30
|
+
map p.name << c.surname do |name|
|
31
|
+
if name =~ /ski/
|
32
|
+
name[0..-4]
|
33
|
+
else
|
34
|
+
name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
#field to array and array to field
|
38
|
+
map p.email1 <=> c.emails[0]
|
39
|
+
map p.email2 <=> c.emails[1]
|
40
|
+
map p.email3 <=> c.emails[2]
|
41
|
+
|
42
|
+
map p.phones(Erp::Phone)[] <=> c.phones[] do |a, b|
|
43
|
+
map a.number <=> b.self
|
44
|
+
end
|
45
|
+
|
46
|
+
#subobject to fields
|
47
|
+
map p.main_phone(Erp::Phone) <=> c.self do |a, b|
|
48
|
+
map a.number <=> b.main_phone
|
49
|
+
map a.type <=> b.main_phone_type
|
50
|
+
end
|
51
|
+
|
52
|
+
#TODO one to many
|
53
|
+
#map p.name << [c.first_name, c.surname] do |fname, surname|
|
54
|
+
# fname + " " + surname
|
55
|
+
#end
|
56
|
+
#map p.name.split >> [c.first_name, c.surname]
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|