mappum 0.2.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 +48 -0
- data/VERSION +1 -0
- data/bin/mapserver.rb +4 -0
- data/java-api/pom.xml +63 -0
- data/java-api/src/main/java/pl/ivmx/mappum/JavaTransform.java +12 -0
- data/java-api/src/main/java/pl/ivmx/mappum/MappumApi.java +83 -0
- data/java-api/src/main/java/pl/ivmx/mappum/TreeElement.java +23 -0
- data/java-api/src/main/java/pl/ivmx/mappum/WorkdirLoader.java +12 -0
- data/java-api/src/test/java/iv/Client.java +237 -0
- data/java-api/src/test/java/iv/Person.java +261 -0
- data/java-api/src/test/java/pl/ivmx/mappum/MappumTest.java +122 -0
- data/java-api/src/test/resources/map/example_map.rb +88 -0
- data/lib/mappum.rb +46 -0
- data/lib/mappum/autoconv_catalogue.rb +43 -0
- data/lib/mappum/dsl.rb +255 -0
- data/lib/mappum/java_transform.rb +107 -0
- data/lib/mappum/map.rb +194 -0
- data/lib/mappum/mapserver/mapgraph.rb +192 -0
- data/lib/mappum/mapserver/mapserver.rb +213 -0
- data/lib/mappum/mapserver/maptable.rb +80 -0
- data/lib/mappum/mapserver/views/doc.erb +15 -0
- data/lib/mappum/mapserver/views/main.erb +39 -0
- data/lib/mappum/mapserver/views/maptable.erb +16 -0
- data/lib/mappum/mapserver/views/rubysource.erb +25 -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 +68 -0
- data/lib/mappum/ruby_transform.rb +199 -0
- data/lib/mappum/xml_transform.rb +382 -0
- data/mappum.gemspec +117 -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 +44 -0
- data/sample/example_conversions.rb +12 -0
- data/sample/example_map.rb +92 -0
- data/sample/example_notypes.rb +77 -0
- data/sample/example_when.rb +13 -0
- data/sample/person_fixture.xml +23 -0
- data/sample/person_fixture_any.xml +26 -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_conversions.rb +24 -0
- data/test/test_example.rb +175 -0
- data/test/test_openstruct.rb +129 -0
- data/test/test_soap4r.rb +108 -0
- data/test/test_when.rb +35 -0
- data/test/test_xml_any.rb +62 -0
- metadata +164 -0
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,44 @@
|
|
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:element name="spouse" minOccurs="0" maxOccurs="5">
|
26
|
+
<xsd:complexType>
|
27
|
+
<xsd:sequence>
|
28
|
+
<xsd:element name="name" type="xsd:string"/>
|
29
|
+
<xsd:element name="type" type="xsd:string" minOccurs="0"/>
|
30
|
+
</xsd:sequence>
|
31
|
+
</xsd:complexType>
|
32
|
+
<xsd:element>
|
33
|
+
</xsd:sequence>
|
34
|
+
</xsd:complexType>
|
35
|
+
</xsd:element>
|
36
|
+
<xsd:complexType name="phone">
|
37
|
+
<xsd:sequence>
|
38
|
+
<xsd:element name="number" type="xsd:string"/>
|
39
|
+
<xsd:element name="extension" type="xsd:string" minOccurs="0"/>
|
40
|
+
<xsd:element name="type" type="xsd:string" minOccurs="0"/>
|
41
|
+
</xsd:sequence>
|
42
|
+
</xsd:complexType>
|
43
|
+
</xsd:schema>
|
44
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
Mappum.catalogue_add do
|
4
|
+
|
5
|
+
map :typed,:stringed do |t,s|
|
6
|
+
map t.date(Date) <=> s.date(String)
|
7
|
+
map t.time(Time) <=> s.time(String)
|
8
|
+
map t.fixnum(Fixnum) <=> s.fixnum(String)
|
9
|
+
map t.float(Float) >> s.float(String)
|
10
|
+
map t.float(Float) << s.float(String)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,92 @@
|
|
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.find{|cp|cp.type == "Wife"} do |ps,cp|
|
44
|
+
map ps.name <=> cp.name
|
45
|
+
map "Wife" >> cp.type
|
46
|
+
end
|
47
|
+
map p.spouse(ERP::Person) <=> c.partners.find{|cp|cp.type == "Friend"} do |ps,cp|
|
48
|
+
map ps.name <=> cp.name
|
49
|
+
map "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
|
+
`Example of submaps autodiscovery`
|
88
|
+
map :Group, :ClientList do |g,cl|
|
89
|
+
map g.main(ERP::Person) <=> cl.leader(CRM::Client)
|
90
|
+
map g.list(ERP::Person)[] <=> cl.clients(CRM::Client)[]
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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
|
+
name_map_prefix :notype
|
9
|
+
name_map :<=>, :notype_person_client
|
10
|
+
name_map :<, :notype_client_to_person
|
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 <=> c.address do |a, b|
|
23
|
+
map a.street <=> b.street
|
24
|
+
#etc.
|
25
|
+
end
|
26
|
+
|
27
|
+
#xml attributes
|
28
|
+
map p.xmlattr_id <=> c.xmlattr_ident
|
29
|
+
|
30
|
+
#compicated finc call
|
31
|
+
map p.name >> c.surname do |name|
|
32
|
+
name + "ski"
|
33
|
+
end
|
34
|
+
map p.name << c.surname do |name|
|
35
|
+
if name =~ /ski/
|
36
|
+
name[0..-4]
|
37
|
+
else
|
38
|
+
name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
#field to array and array to field
|
42
|
+
map p.email1 <=> c.emails[0]
|
43
|
+
map p.email2 <=> c.emails[1]
|
44
|
+
map p.email3 <=> c.emails[2]
|
45
|
+
|
46
|
+
map p.phones[] <=> c.phones[] do |a, b|
|
47
|
+
map a.number <=> b.self
|
48
|
+
end
|
49
|
+
|
50
|
+
map p.spouse <=> c.partners do |ps,cp|
|
51
|
+
|
52
|
+
map ps.self <=> cp.partner[1] do |ps1,cp1|
|
53
|
+
map ps1.name <=> cp1.xmlattr_name
|
54
|
+
map "Wife" >> cp1.xmlattr_type
|
55
|
+
end
|
56
|
+
map ps.self <=> cp.partner[1] do |ps2,cp2|
|
57
|
+
map ps2.name <=> cp2.xmlattr_name
|
58
|
+
map "Friend" >> cp2.xmlattr_type
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
#subobject to fields
|
65
|
+
map p.main_phone <=> c.self do |a, b|
|
66
|
+
map a.number <=> b.main_phone
|
67
|
+
map a.type <=> b.main_phone_type
|
68
|
+
end
|
69
|
+
|
70
|
+
#TODO one to many
|
71
|
+
#map p.name << [c.first_name, c.surname] do |fname, surname|
|
72
|
+
# fname + " " + surname
|
73
|
+
#end
|
74
|
+
#map p.name.split >> [c.first_name, c.surname]
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Mappum.catalogue_add do
|
2
|
+
map :foo, :bar do |f, b|
|
3
|
+
map_when(:>){|foo| foo.age < 10}
|
4
|
+
|
5
|
+
#map f.mem <=> b.tem, :when_l2r => lambda {|mem| mem > 10}
|
6
|
+
#or the same
|
7
|
+
map f.mem <=> b.tem do
|
8
|
+
map_when(:>) {|mem| mem > 10}
|
9
|
+
end
|
10
|
+
map f.mem <=> b.gem, :when_l2r => lambda {|mem| mem <= 10}
|
11
|
+
map f.pol >> b.gol, :when => lambda {|pol| pol != 0}
|
12
|
+
end
|
13
|
+
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,26 @@
|
|
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
|
+
<spouse>
|
24
|
+
<name>Mary</name>
|
25
|
+
</spouse>
|
26
|
+
</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 Time.now >> 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
|