20
20
import com .mendix .systemwideinterfaces .core .IMendixObject ;
21
21
import com .mendix .systemwideinterfaces .core .IMendixObject .ObjectState ;
22
22
import com .mendix .systemwideinterfaces .core .IMendixObjectMember ;
23
- import com .mendix .systemwideinterfaces .core .IMendixObjectMember .MemberState ;
24
23
import com .mendix .systemwideinterfaces .core .meta .IMetaAssociation ;
25
24
import com .mendix .systemwideinterfaces .core .meta .IMetaAssociation .AssociationType ;
26
25
import com .mendix .systemwideinterfaces .core .meta .IMetaEnumValue ;
@@ -40,7 +39,7 @@ public static Long getGUID(IMendixObject item)
40
39
public static String getOriginalValueAsString (IContext context , IMendixObject item ,
41
40
String member )
42
41
{
43
- return String .valueOf (item .getMember (context , member ).getOriginalValue (context ));
42
+ return String .valueOf (item .getMember (member ).getOriginalValue (context ));
44
43
}
45
44
46
45
public static boolean objectHasChanged (IMendixObject anyobject ) {
@@ -62,7 +61,7 @@ public static boolean memberHasChanged(IContext context, IMendixObject item, Str
62
61
throw new IllegalArgumentException ("The provided object is empty" );
63
62
if (!item .hasMember (member ))
64
63
throw new IllegalArgumentException ("Unknown member: " + member );
65
- return item .getMember (context , member ).getState () == MemberState . CHANGED || item .getState () != ObjectState .NORMAL ;
64
+ return item .getMember (member ).isChanged () || item .getState () != ObjectState .NORMAL ;
66
65
}
67
66
68
67
public static void deepClone (IContext c , IMendixObject source , IMendixObject target , String membersToSkip , String membersToKeep , String reverseAssociations , String excludeEntities , String excludeModules ) throws CoreException
@@ -97,16 +96,16 @@ private static void duplicate(IContext ctx, IMendixObject src, IMendixObject tar
97
96
if (m instanceof MendixObjectReference && !keep && m .getValue (ctx ) != null ) {
98
97
IMendixObject o = Core .retrieveId (ctx , ((MendixObjectReference ) m ).getValue (ctx ));
99
98
IMendixIdentifier refObj = getCloneOfObject (ctx , o , toskip , tokeep , revAssoc , skipEntities , skipModules , mappedObjects );
100
- tar .setValue (ctx , key , refObj );
99
+ tar .setValue (ctx , key , refObj );
101
100
}
102
101
103
102
else if (m instanceof MendixObjectReferenceSet && !keep && m .getValue (ctx ) != null ) {
104
103
MendixObjectReferenceSet rs = (MendixObjectReferenceSet ) m ;
105
104
List <IMendixIdentifier > res = new ArrayList <IMendixIdentifier >();
106
105
for (IMendixIdentifier item : rs .getValue (ctx )) {
107
106
IMendixObject o = Core .retrieveId (ctx , item );
108
- IMendixIdentifier refObj = getCloneOfObject (ctx , o , toskip , tokeep , revAssoc , skipEntities , skipModules , mappedObjects );
109
- res .add (refObj );
107
+ IMendixIdentifier refObj = getCloneOfObject (ctx , o , toskip , tokeep , revAssoc , skipEntities , skipModules , mappedObjects );
108
+ res .add (refObj );
110
109
}
111
110
tar .setValue (ctx , key , res );
112
111
}
@@ -123,31 +122,31 @@ else if (m instanceof MendixAutoNumber) //skip autonumbers! Ticket 14893
123
122
}
124
123
125
124
private static IMendixIdentifier getCloneOfObject (IContext ctx , IMendixObject src ,
126
- List <String > toskip , List <String > tokeep , List <String > revAssoc ,
127
- List <String > skipEntities , List <String > skipModules ,
128
- Map <IMendixIdentifier , IMendixIdentifier > mappedObjects ) throws CoreException
125
+ List <String > toskip , List <String > tokeep , List <String > revAssoc ,
126
+ List <String > skipEntities , List <String > skipModules ,
127
+ Map <IMendixIdentifier , IMendixIdentifier > mappedObjects ) throws CoreException
129
128
{
130
- String objType = src .getMetaObject ().getName ();
131
- String modName = src .getMetaObject ().getModuleName ();
132
-
133
- // if object is already being cloned, return ref to clone
134
- if (mappedObjects .containsKey (src .getId ())) {
135
- return mappedObjects .get (src .getId ());
136
- // if object should be skipped based on module or entity, return source object
137
- } else if (skipEntities .contains (objType ) || skipModules .contains (modName )) {
138
- return src .getId ();
139
- // if not already being cloned, create clone
140
- } else {
141
- IMendixObject clone = Core .instantiate (ctx , src .getType ());
142
- duplicate (ctx , src , clone , toskip , tokeep , revAssoc , skipEntities , skipModules , mappedObjects );
143
- return clone .getId ();
144
- }
129
+ String objType = src .getMetaObject ().getName ();
130
+ String modName = src .getMetaObject ().getModuleName ();
131
+
132
+ // if object is already being cloned, return ref to clone
133
+ if (mappedObjects .containsKey (src .getId ())) {
134
+ return mappedObjects .get (src .getId ());
135
+ // if object should be skipped based on module or entity, return source object
136
+ } else if (skipEntities .contains (objType ) || skipModules .contains (modName )) {
137
+ return src .getId ();
138
+ // if not already being cloned, create clone
139
+ } else {
140
+ IMendixObject clone = Core .instantiate (ctx , src .getType ());
141
+ duplicate (ctx , src , clone , toskip , tokeep , revAssoc , skipEntities , skipModules , mappedObjects );
142
+ return clone .getId ();
143
+ }
145
144
}
146
145
147
146
private static void duplicateReverseAssociations (IContext ctx , IMendixObject src , IMendixObject tar ,
148
- List <String > toskip , List <String > tokeep , List <String > revAssocs ,
149
- List <String > skipEntities , List <String > skipModules ,
150
- Map <IMendixIdentifier , IMendixIdentifier > mappedObjects ) throws CoreException
147
+ List <String > toskip , List <String > tokeep , List <String > revAssocs ,
148
+ List <String > skipEntities , List <String > skipModules ,
149
+ Map <IMendixIdentifier , IMendixIdentifier > mappedObjects ) throws CoreException
151
150
{
152
151
for (String fullAssocName : revAssocs ) {
153
152
String [] parts = fullAssocName .split ("/" );
@@ -158,29 +157,28 @@ private static void duplicateReverseAssociations(IContext ctx, IMendixObject src
158
157
String assocname = parts .length == 3 ? parts [1 ] : parts [0 ]; //support length 3 for backward compatibility
159
158
160
159
IMetaAssociation massoc = src .getMetaObject ().getDeclaredMetaAssociationChild (assocname );
161
-
160
+
162
161
if (massoc != null ) {
163
162
IMetaObject relationParent = massoc .getParent ();
164
163
// if the parent is in the exclude list, we can't clone the parent, and setting the
165
164
// references to the newly cloned target object will screw up the source data.
166
165
if (skipEntities .contains (relationParent .getName ()) || skipModules .contains (relationParent .getModuleName ())){
167
- throw new IllegalArgumentException ("A reverse reference has been specified that starts at an entity in the exclude list, this is not possible to clone: '" + fullAssocName + "'" );
168
- }
169
-
170
- //MWE: what to do with reverse reference sets? -> to avoid spam creating objects on
171
- //reverse references, do not support referenceset (todo: we could keep a map of converted guids and reuse that!)
166
+ throw new IllegalArgumentException ("A reverse reference has been specified that starts at an entity in the exclude list, this is not possible to clone: '" + fullAssocName + "'" );
167
+ }
168
+
169
+ //MWE: what to do with reverse reference sets? -> to avoid spam creating objects on
170
+ //reverse references, do not support referenceset (todo: we could keep a map of converted guids and reuse that!)
172
171
if (massoc .getType () == AssociationType .REFERENCESET ) {
173
172
throw new IllegalArgumentException ("It is not possible to clone reverse referencesets: '" + fullAssocName + "'" );
174
173
}
175
174
176
- List <IMendixObject > objs = Core .retrieveXPathQuery ( ctx , String .format ("//%s[%s='%s']" ,
177
- relationParent .getName (), assocname , String .valueOf (src .getId ().toLong ())));
175
+ List <IMendixObject > objs = Core .createXPathQuery ( String .format ("//%s[%s='%s']" ,
176
+ relationParent .getName (), assocname , String .valueOf (src .getId ().toLong ()))). execute ( ctx );
178
177
179
178
for (IMendixObject obj : objs ) {
180
- @ SuppressWarnings ("unused" ) // object is unused on purpose
181
- IMendixIdentifier refObj = getCloneOfObject (ctx , obj , toskip , tokeep , revAssocs , skipEntities , skipModules , mappedObjects );
182
- // setting reference explicitly is not necessary, this has been done in the
183
- // duplicate() call.
179
+ @ SuppressWarnings ("unused" ) // object is unused on purpose
180
+ IMendixIdentifier refObj = getCloneOfObject (ctx , obj , toskip , tokeep , revAssocs , skipEntities , skipModules , mappedObjects );
181
+ // setting reference explicitly is not necessary, this has been done in the duplicate() call.
184
182
}
185
183
}
186
184
}
@@ -196,7 +194,7 @@ public static String getValueOfPath(IContext context, IMendixObject substitute,
196
194
{
197
195
String [] path = fullpath .split ("/" );
198
196
if (path .length == 1 ) {
199
- IMendixObjectMember <?> member = substitute .getMember (context , path [0 ]);
197
+ IMendixObjectMember <?> member = substitute .getMember (path [0 ]);
200
198
201
199
//special case, see ticket 9135, format datetime.
202
200
if (member instanceof MendixDateTime ) {
@@ -224,7 +222,7 @@ else if (path.length == 0)
224
222
throw new Exception ("communitycommons.ORM.getValueOfPath: Unexpected end of path." );
225
223
226
224
else {
227
- IMendixObjectMember <?> member = substitute .getMember (context , path [0 ]);
225
+ IMendixObjectMember <?> member = substitute .getMember (path [0 ]);
228
226
if (member instanceof MendixObjectReference ) {
229
227
MendixObjectReference ref = (MendixObjectReference ) member ;
230
228
IMendixIdentifier id = ref .getValue (context );
0 commit comments