mappum 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/java-api/pom.xml +1 -1
- data/java-api/src/main/java/pl/ivmx/mappum/JavaMappumException.java +151 -0
- data/java-api/src/main/java/pl/ivmx/mappum/JavaTransform.java +36 -4
- data/java-api/src/main/java/pl/ivmx/mappum/TreeElement.java +1 -1
- data/java-api/src/test/java/iv/Client.java +8 -6
- data/java-api/src/test/java/pl/ivmx/mappum/MappumTest.java +84 -6
- data/java-api/src/test/resources/map/error_map.rb +17 -0
- data/java-api/src/test/resources/map/example_map.rb +5 -3
- data/lib/mappum/dsl.rb +37 -17
- data/lib/mappum/java_transform.rb +62 -9
- data/lib/mappum/map.rb +18 -8
- data/lib/mappum/map_space.rb +11 -0
- data/lib/mappum/mappum_exception.rb +14 -6
- data/lib/mappum/mapserver/mapgraph.rb +1 -1
- data/lib/mappum/mapserver/mapserver.rb +32 -25
- data/lib/mappum/mapserver/views/main.erb +1 -0
- data/lib/mappum/ruby_transform.rb +132 -80
- data/lib/mappum/xml_transform.rb +36 -10
- data/mappum.gemspec +9 -3
- data/sample/crm.rb +1 -1
- data/sample/crm_client.xsd +1 -0
- data/sample/erp.rb +1 -1
- data/sample/example_context.rb +89 -0
- data/sample/example_map.rb +4 -1
- data/sample/server/schema/crm_client.xsd +1 -0
- data/test/test_context.rb +58 -0
- data/test/test_example.rb +7 -3
- data/test/test_openstruct.rb +2 -2
- data/test/test_soap4r.rb +6 -3
- data/test/test_xml_any.rb +6 -2
- metadata +8 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/java-api/pom.xml
CHANGED
@@ -0,0 +1,151 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
*/
|
4
|
+
package pl.ivmx.mappum;
|
5
|
+
|
6
|
+
import java.util.List;
|
7
|
+
|
8
|
+
import org.jruby.RubyException;
|
9
|
+
import org.jruby.exceptions.RaiseException;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @author Jan Topinski (jtopinski@ivmx.pl)
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
public class JavaMappumException extends RuntimeException {
|
16
|
+
|
17
|
+
/**
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
public JavaMappumException() {
|
21
|
+
super();
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* @param arg0
|
25
|
+
* @param arg1
|
26
|
+
*/
|
27
|
+
public JavaMappumException(String arg0, RubyException arg1) {
|
28
|
+
super(arg0, new RaiseException(arg1));
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* @param arg0
|
32
|
+
* @param arg1
|
33
|
+
*/
|
34
|
+
public JavaMappumException(String arg0, Throwable arg1) {
|
35
|
+
super(arg0, arg1);
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* @param arg0
|
39
|
+
*/
|
40
|
+
public JavaMappumException(String arg0) {
|
41
|
+
super(arg0);
|
42
|
+
}
|
43
|
+
/**
|
44
|
+
* @param arg0
|
45
|
+
*/
|
46
|
+
public JavaMappumException(Throwable arg0) {
|
47
|
+
super(arg0);
|
48
|
+
}
|
49
|
+
/**
|
50
|
+
* @param arg0
|
51
|
+
*/
|
52
|
+
public JavaMappumException(RubyException arg0) {
|
53
|
+
super(new RaiseException(arg0));
|
54
|
+
}
|
55
|
+
private static final long serialVersionUID = 1L;
|
56
|
+
|
57
|
+
private String fromName;
|
58
|
+
private String toName;
|
59
|
+
private Object from;
|
60
|
+
private Object to;
|
61
|
+
private Object fromRoot;
|
62
|
+
private Object toRoot;
|
63
|
+
private List<String> mappumBacktrace;
|
64
|
+
/**
|
65
|
+
*
|
66
|
+
*
|
67
|
+
* @return the fromName
|
68
|
+
*/
|
69
|
+
public String getFromName() {
|
70
|
+
return fromName;
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* @param fromName the fromName to set
|
74
|
+
*/
|
75
|
+
public void setFromName(String fromName) {
|
76
|
+
this.fromName = fromName;
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* @return the toName
|
80
|
+
*/
|
81
|
+
public String getToName() {
|
82
|
+
return toName;
|
83
|
+
}
|
84
|
+
/**
|
85
|
+
* @param toName the toName to set
|
86
|
+
*/
|
87
|
+
public void setToName(String toName) {
|
88
|
+
this.toName = toName;
|
89
|
+
}
|
90
|
+
/**
|
91
|
+
* @return the from
|
92
|
+
*/
|
93
|
+
public Object getFrom() {
|
94
|
+
return from;
|
95
|
+
}
|
96
|
+
/**
|
97
|
+
* @param from the from to set
|
98
|
+
*/
|
99
|
+
public void setFrom(Object from) {
|
100
|
+
this.from = from;
|
101
|
+
}
|
102
|
+
/**
|
103
|
+
* @return the to
|
104
|
+
*/
|
105
|
+
public Object getTo() {
|
106
|
+
return to;
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* @param to the to to set
|
110
|
+
*/
|
111
|
+
public void setTo(Object to) {
|
112
|
+
this.to = to;
|
113
|
+
}
|
114
|
+
/**
|
115
|
+
* @return the fromRoot
|
116
|
+
*/
|
117
|
+
public Object getFromRoot() {
|
118
|
+
return fromRoot;
|
119
|
+
}
|
120
|
+
/**
|
121
|
+
* @param fromRoot the fromRoot to set
|
122
|
+
*/
|
123
|
+
public void setFromRoot(Object fromRoot) {
|
124
|
+
this.fromRoot = fromRoot;
|
125
|
+
}
|
126
|
+
/**
|
127
|
+
* @return the toRoot
|
128
|
+
*/
|
129
|
+
public Object getToRoot() {
|
130
|
+
return toRoot;
|
131
|
+
}
|
132
|
+
/**
|
133
|
+
* @param toRoot the toRoot to set
|
134
|
+
*/
|
135
|
+
public void setToRoot(Object toRoot) {
|
136
|
+
this.toRoot = toRoot;
|
137
|
+
}
|
138
|
+
/**
|
139
|
+
* @return the mappumBacktrace
|
140
|
+
*/
|
141
|
+
public List<String> getMappumBacktrace() {
|
142
|
+
return mappumBacktrace;
|
143
|
+
}
|
144
|
+
/**
|
145
|
+
* @param mappumBacktrace the mappumBacktrace to set
|
146
|
+
*/
|
147
|
+
public void setMappumBacktrace(List<String> mappumBacktrace) {
|
148
|
+
this.mappumBacktrace = mappumBacktrace;
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
@@ -1,12 +1,44 @@
|
|
1
1
|
package pl.ivmx.mappum;
|
2
2
|
|
3
|
+
import java.util.Map;
|
4
|
+
|
3
5
|
public interface JavaTransform {
|
4
6
|
/**
|
5
7
|
* Transforms Pojo (plain old java bean)
|
6
8
|
* @param from
|
7
|
-
* @return
|
9
|
+
* @return transformed object
|
8
10
|
*/
|
9
|
-
public Object transform(Object from, String map, Object to);
|
10
|
-
public Object transform(Object from, String map);
|
11
11
|
public Object transform(Object from);
|
12
|
-
|
12
|
+
/**
|
13
|
+
* Transforms Pojo (plain old java bean)
|
14
|
+
* @param from
|
15
|
+
* @param map name of map to use
|
16
|
+
* @return transformed object
|
17
|
+
*/
|
18
|
+
public Object transform(Object from, String map);
|
19
|
+
/**
|
20
|
+
* Transforms Pojo (plain old java bean)
|
21
|
+
* @param from
|
22
|
+
* @param map name of map to use
|
23
|
+
* @param to object to change
|
24
|
+
* @return transformed object
|
25
|
+
*/
|
26
|
+
public Object transform(Object from, String map, Object to);
|
27
|
+
/**
|
28
|
+
* Transforms Pojo (plain old java bean)
|
29
|
+
* @param from
|
30
|
+
* @param map name of map to use
|
31
|
+
* @param to object to change
|
32
|
+
* @param map of options for now use "context" to store context
|
33
|
+
* @return transformed object
|
34
|
+
*/
|
35
|
+
public Object transform(Object from, String map, Object to, Map options);
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Transforms Pojo (plain old java bean)
|
39
|
+
* @param from
|
40
|
+
* @param map of options for now use "context" to store context
|
41
|
+
* @return transformed object
|
42
|
+
*/
|
43
|
+
public Object transform(Object from, Map options);
|
44
|
+
}
|
@@ -9,7 +9,7 @@ import java.util.List;
|
|
9
9
|
* @author Jan Topinski (jtopinski@ivmx.pl)
|
10
10
|
*
|
11
11
|
*/
|
12
|
-
public interface TreeElement {
|
12
|
+
public interface TreeElement extends Comparable<TreeElement>{
|
13
13
|
public String getName();
|
14
14
|
public void setName(String name);
|
15
15
|
public List<TreeElement> getElements();
|
@@ -1,6 +1,8 @@
|
|
1
1
|
package iv;
|
2
2
|
|
3
3
|
import java.util.Date;
|
4
|
+
import java.util.Set;
|
5
|
+
import java.util.HashMap;
|
4
6
|
|
5
7
|
public class Client {
|
6
8
|
|
@@ -71,12 +73,12 @@ public class Client {
|
|
71
73
|
private String surname;
|
72
74
|
private String sexId;
|
73
75
|
private String[] phones;
|
74
|
-
private
|
76
|
+
private HashMap emails;
|
75
77
|
private String mainPhone;
|
76
78
|
private String mainPhoneType;
|
77
79
|
private Address address;
|
78
80
|
private String orderBy;
|
79
|
-
private NameType
|
81
|
+
private Set<NameType> partners;
|
80
82
|
private Date updated;
|
81
83
|
|
82
84
|
public Date getUpdated() {
|
@@ -92,11 +94,11 @@ public class Client {
|
|
92
94
|
public void setOrderBy(String orderBy) {
|
93
95
|
this.orderBy = orderBy;
|
94
96
|
}
|
95
|
-
public NameType
|
97
|
+
public Set<NameType> getPartners() {
|
96
98
|
return partners;
|
97
99
|
}
|
98
100
|
|
99
|
-
public void setPartners(NameType
|
101
|
+
public void setPartners(Set<NameType> partners) {
|
100
102
|
this.partners = partners;
|
101
103
|
}
|
102
104
|
/**
|
@@ -186,13 +188,13 @@ public class Client {
|
|
186
188
|
/**
|
187
189
|
* @return the emails
|
188
190
|
*/
|
189
|
-
public
|
191
|
+
public HashMap getEmails() {
|
190
192
|
return emails;
|
191
193
|
}
|
192
194
|
/**
|
193
195
|
* @param emails the emails to set
|
194
196
|
*/
|
195
|
-
public void setEmails(
|
197
|
+
public void setEmails(HashMap emails) {
|
196
198
|
this.emails = emails;
|
197
199
|
}
|
198
200
|
/**
|
@@ -6,6 +6,8 @@ package pl.ivmx.mappum;
|
|
6
6
|
import java.util.ArrayList;
|
7
7
|
import java.util.Calendar;
|
8
8
|
import java.util.List;
|
9
|
+
import java.util.HashMap;
|
10
|
+
import java.util.Map;
|
9
11
|
|
10
12
|
import iv.Client;
|
11
13
|
import iv.Person;
|
@@ -16,7 +18,15 @@ import junit.framework.TestCase;
|
|
16
18
|
*
|
17
19
|
*/
|
18
20
|
public class MappumTest extends TestCase {
|
19
|
-
|
21
|
+
class Context {
|
22
|
+
Map properties;
|
23
|
+
public Map getProperties() {
|
24
|
+
return properties;
|
25
|
+
}
|
26
|
+
public void setProperties(Map properties) {
|
27
|
+
this.properties = properties;
|
28
|
+
}
|
29
|
+
}
|
20
30
|
/* (non-Javadoc)
|
21
31
|
* @see junit.framework.TestCase#setUp()
|
22
32
|
*/
|
@@ -33,10 +43,62 @@ public class MappumTest extends TestCase {
|
|
33
43
|
assertEquals(null,treeElement.getClazz());
|
34
44
|
assertEquals("Client",treeElement.getName());
|
35
45
|
assertEquals(false,treeElement.getIsArray());
|
36
|
-
assertEquals(
|
46
|
+
assertEquals(11,treeElement.getElements().size());
|
37
47
|
wl.cleanup();
|
38
48
|
}
|
49
|
+
|
50
|
+
public void testError(){
|
51
|
+
MappumApi mp = new MappumApi();
|
52
|
+
mp.loadMaps();
|
53
|
+
JavaTransform jt = mp.getJavaTransform("Error");
|
54
|
+
|
55
|
+
Person per = newPerson();
|
56
|
+
try {
|
57
|
+
jt.transform(per);
|
58
|
+
fail("Exception shall be thrown");
|
59
|
+
} catch (JavaMappumException e) {
|
60
|
+
assertTrue(e.getMappumBacktrace().get(0).indexOf("error_map.rb:") > -1);
|
61
|
+
assertEquals("/address/wrong", e.getFromName());
|
62
|
+
assertEquals("/address/name", e.getToName());
|
63
|
+
|
64
|
+
assertEquals(per.getAddress(), e.getFrom());
|
65
|
+
assertEquals(null, e.getTo());
|
66
|
+
//FIXME
|
67
|
+
//assertEquals(per, e.getFromRoot());
|
68
|
+
assertEquals(null, e.getToRoot());
|
69
|
+
|
70
|
+
}
|
71
|
+
|
72
|
+
}
|
73
|
+
|
74
|
+
public void testContext(){
|
75
|
+
MappumApi mp = new MappumApi();
|
76
|
+
mp.loadMaps();
|
77
|
+
JavaTransform jt = mp.getJavaTransform();
|
39
78
|
|
79
|
+
Person per = newPerson();
|
80
|
+
Client cli = null;
|
81
|
+
Person person = null;
|
82
|
+
|
83
|
+
HashMap<String, String> props = new HashMap<String, String>();
|
84
|
+
props.put("Title", "Sir");
|
85
|
+
Context context = new Context();
|
86
|
+
context.setProperties(props);
|
87
|
+
HashMap<String, Object> options = new HashMap<String, Object>();
|
88
|
+
options.put("context", context);
|
89
|
+
|
90
|
+
cli = (Client) jt.transform(per, options);
|
91
|
+
person = (Person) jt.transform(cli, options);
|
92
|
+
|
93
|
+
assertEquals("2",cli.getSexId());
|
94
|
+
assertEquals("Skoryski",cli.getSurname());
|
95
|
+
assertEquals("M",person.getSex());
|
96
|
+
assertEquals("Skory",person.getName());
|
97
|
+
assertEquals("sir",person.getTitle());
|
98
|
+
assertEquals("Skoryski",context.getProperties().get("Name"));
|
99
|
+
|
100
|
+
}
|
101
|
+
|
40
102
|
public void testTransform(){
|
41
103
|
MappumApi mp = new MappumApi();
|
42
104
|
mp.loadMaps();
|
@@ -46,10 +108,18 @@ public class MappumTest extends TestCase {
|
|
46
108
|
Client cli = null;
|
47
109
|
Person person = null;
|
48
110
|
|
111
|
+
HashMap<String, String> props = new HashMap<String, String>();
|
112
|
+
props.put("Title", "Sir");
|
113
|
+
Context context = new Context();
|
114
|
+
context.setProperties(props);
|
115
|
+
HashMap<String, Object> options = new HashMap<String, Object>();
|
116
|
+
options.put("context", context);
|
117
|
+
|
49
118
|
long time = System.currentTimeMillis();
|
50
119
|
for (int i = 0; i < 200; i++) {
|
51
|
-
|
52
|
-
|
120
|
+
|
121
|
+
cli = (Client) jt.transform(per, options);
|
122
|
+
person = (Person) jt.transform(cli, options);
|
53
123
|
}
|
54
124
|
time = System.currentTimeMillis()-time;
|
55
125
|
System.out.println(time);
|
@@ -58,6 +128,8 @@ public class MappumTest extends TestCase {
|
|
58
128
|
assertEquals("M",person.getSex());
|
59
129
|
assertEquals("Skory",person.getName());
|
60
130
|
}
|
131
|
+
|
132
|
+
|
61
133
|
/**
|
62
134
|
* @return
|
63
135
|
*/
|
@@ -94,11 +166,17 @@ public class MappumTest extends TestCase {
|
|
94
166
|
Runnable task = new Runnable(){
|
95
167
|
|
96
168
|
public void run() {
|
169
|
+
HashMap<String, String> props = new HashMap<String, String>();
|
170
|
+
props.put("Title", "Sir");
|
171
|
+
Context context = new Context();
|
172
|
+
context.setProperties(props);
|
173
|
+
HashMap<String, Object> options = new HashMap<String, Object>();
|
174
|
+
options.put("context", context);
|
97
175
|
|
98
176
|
Person per = newPerson();
|
99
177
|
for (int j = 0; j < loops; j++) {
|
100
|
-
Client cli = (Client) jt.transform(per);
|
101
|
-
Person person = (Person) jt.transform(cli);
|
178
|
+
Client cli = (Client) jt.transform(per, options);
|
179
|
+
Person person = (Person) jt.transform(cli, options);
|
102
180
|
}
|
103
181
|
}
|
104
182
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Example of map for given object domains CRM and ERP
|
2
|
+
require 'mappum'
|
3
|
+
require 'java'
|
4
|
+
import 'iv.Client'
|
5
|
+
import 'iv.Person'
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
Mappum.catalogue_add "Error" do
|
9
|
+
|
10
|
+
map Person,Client do |p, c|
|
11
|
+
#submaps
|
12
|
+
map p.address(Person::Address) <=> c.address(Client::Address) do |a, b|
|
13
|
+
map a.wrong <=> b.name
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -10,8 +10,10 @@ Mappum.catalogue_add do
|
|
10
10
|
map Person,Client do |p, c|
|
11
11
|
|
12
12
|
#simple mapping
|
13
|
-
map p.title <=>
|
13
|
+
map p.title <=> context.properties["Title"]
|
14
14
|
|
15
|
+
map context.properties["Name"] << c.surname
|
16
|
+
|
15
17
|
#map with simple function call
|
16
18
|
map p.person_id << c.cid.downcase
|
17
19
|
map p.person_id.upcase >> c.cid
|
@@ -41,11 +43,11 @@ Mappum.catalogue_add do
|
|
41
43
|
map p.email2 <=> c.emails[1]
|
42
44
|
map p.email3 <=> c.emails[2]
|
43
45
|
|
44
|
-
map p.spouse(Person) <=> c.partners(Client::NameType)
|
46
|
+
map p.spouse(Person) <=> c.partners(Client::NameType).find{|cp|cp.type == "Wife"} do |ps,cp|
|
45
47
|
map ps.name <=> cp.name
|
46
48
|
"Wife" >> cp.type
|
47
49
|
end
|
48
|
-
map p.spouse(Person) <=> c.partners(Client::NameType)
|
50
|
+
map p.spouse(Person) <=> c.partners(Client::NameType).find{|cp|cp.type == "Friend"} do |ps,cp|
|
49
51
|
map ps.name <=> cp.name
|
50
52
|
"Friend" >> cp.type
|
51
53
|
end
|