2020import com .mendix .systemwideinterfaces .core .IMendixObject ;
2121import com .mendix .systemwideinterfaces .core .IMendixObject .ObjectState ;
2222import com .mendix .systemwideinterfaces .core .IMendixObjectMember ;
23- import com .mendix .systemwideinterfaces .core .IMendixObjectMember .MemberState ;
2423import com .mendix .systemwideinterfaces .core .meta .IMetaAssociation ;
2524import com .mendix .systemwideinterfaces .core .meta .IMetaAssociation .AssociationType ;
2625import com .mendix .systemwideinterfaces .core .meta .IMetaEnumValue ;
@@ -40,7 +39,7 @@ public static Long getGUID(IMendixObject item)
4039 public static String getOriginalValueAsString (IContext context , IMendixObject item ,
4140 String member )
4241 {
43- return String .valueOf (item .getMember (context , member ).getOriginalValue (context ));
42+ return String .valueOf (item .getMember (member ).getOriginalValue (context ));
4443 }
4544
4645 public static boolean objectHasChanged (IMendixObject anyobject ) {
@@ -62,7 +61,7 @@ public static boolean memberHasChanged(IContext context, IMendixObject item, Str
6261 throw new IllegalArgumentException ("The provided object is empty" );
6362 if (!item .hasMember (member ))
6463 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 ;
6665 }
6766
6867 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
9796 if (m instanceof MendixObjectReference && !keep && m .getValue (ctx ) != null ) {
9897 IMendixObject o = Core .retrieveId (ctx , ((MendixObjectReference ) m ).getValue (ctx ));
9998 IMendixIdentifier refObj = getCloneOfObject (ctx , o , toskip , tokeep , revAssoc , skipEntities , skipModules , mappedObjects );
100- tar .setValue (ctx , key , refObj );
99+ tar .setValue (ctx , key , refObj );
101100 }
102101
103102 else if (m instanceof MendixObjectReferenceSet && !keep && m .getValue (ctx ) != null ) {
104103 MendixObjectReferenceSet rs = (MendixObjectReferenceSet ) m ;
105104 List <IMendixIdentifier > res = new ArrayList <IMendixIdentifier >();
106105 for (IMendixIdentifier item : rs .getValue (ctx )) {
107106 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 );
110109 }
111110 tar .setValue (ctx , key , res );
112111 }
@@ -123,31 +122,31 @@ else if (m instanceof MendixAutoNumber) //skip autonumbers! Ticket 14893
123122 }
124123
125124 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
129128 {
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+ }
145144 }
146145
147146 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
151150 {
152151 for (String fullAssocName : revAssocs ) {
153152 String [] parts = fullAssocName .split ("/" );
@@ -158,29 +157,28 @@ private static void duplicateReverseAssociations(IContext ctx, IMendixObject src
158157 String assocname = parts .length == 3 ? parts [1 ] : parts [0 ]; //support length 3 for backward compatibility
159158
160159 IMetaAssociation massoc = src .getMetaObject ().getDeclaredMetaAssociationChild (assocname );
161-
160+
162161 if (massoc != null ) {
163162 IMetaObject relationParent = massoc .getParent ();
164163 // if the parent is in the exclude list, we can't clone the parent, and setting the
165164 // references to the newly cloned target object will screw up the source data.
166165 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!)
172171 if (massoc .getType () == AssociationType .REFERENCESET ) {
173172 throw new IllegalArgumentException ("It is not possible to clone reverse referencesets: '" + fullAssocName + "'" );
174173 }
175174
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 );
178177
179178 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.
184182 }
185183 }
186184 }
@@ -196,7 +194,7 @@ public static String getValueOfPath(IContext context, IMendixObject substitute,
196194 {
197195 String [] path = fullpath .split ("/" );
198196 if (path .length == 1 ) {
199- IMendixObjectMember <?> member = substitute .getMember (context , path [0 ]);
197+ IMendixObjectMember <?> member = substitute .getMember (path [0 ]);
200198
201199 //special case, see ticket 9135, format datetime.
202200 if (member instanceof MendixDateTime ) {
@@ -224,7 +222,7 @@ else if (path.length == 0)
224222 throw new Exception ("communitycommons.ORM.getValueOfPath: Unexpected end of path." );
225223
226224 else {
227- IMendixObjectMember <?> member = substitute .getMember (context , path [0 ]);
225+ IMendixObjectMember <?> member = substitute .getMember (path [0 ]);
228226 if (member instanceof MendixObjectReference ) {
229227 MendixObjectReference ref = (MendixObjectReference ) member ;
230228 IMendixIdentifier id = ref .getValue (context );
0 commit comments