Skip to content

Commit 1873923

Browse files
authored
Merge pull request #158 from mendix/run/4337-newvaluechanged-actions
[RUN-4337] Add objectHasChangedMemberValue and memberHasChangedValue Java actions
2 parents 609544f + cc3b67b commit 1873923

5 files changed

Lines changed: 124 additions & 2 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- The StringFromFile Java action now removes BOM from strings. (Ticket #242904)
22
- We have upgraded the Guava dependency to 33.4.7. This also removes the dependency on the jsr305 version 3.0.2 dependency, which causes some code quality scanning tools to report issues.
3-
- We have added a warning about possible deadlocks to the commitInSeparateDatabaseTransaction Java action.
3+
- We have added a warning about possible deadlocks to the commitInSeparateDatabaseTransaction Java action.
4+
- We added the objectHasChangedMemberValue and memberHasChangedValue Java actions. These actions can be used to check if an object or member has a changed value that is different from the original value.
4 KB
Binary file not shown.

src/CommunityCommons/javasource/communitycommons/ORM.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.HashMap;
2727
import java.util.List;
2828
import java.util.Map;
29-
import system.proxies.FileDocument;
3029

3130
public class ORM {
3231

@@ -46,6 +45,12 @@ public static boolean objectHasChanged(IMendixObject anyobject) {
4645
return anyobject.isChanged();
4746
}
4847

48+
/** Returns true if any member has a value other than its original value. */
49+
public static boolean objectHasChangedMemberValue(IContext context, IMendixObject object) {
50+
if (object == null) throw new IllegalArgumentException("The provided object is empty");
51+
return object.hasChangedMemberValue(context);
52+
}
53+
4954
/**
5055
* checks whether a certain member of an object has changed. If the objects itself is still new,
5156
* we consider to be changes as well.
@@ -65,6 +70,13 @@ public static boolean memberHasChanged(IContext context, IMendixObject item, Str
6570
return item.getMember(member).isChanged() || item.getState() != ObjectState.NORMAL;
6671
}
6772

73+
/** Check if the value of the member was changed to something other than its original value. */
74+
public static boolean memberHasChangedValue(IContext context, IMendixObject item, String member) {
75+
if (item == null) throw new IllegalArgumentException("The provided object is empty");
76+
if (!item.hasMember(member)) throw new IllegalArgumentException("Unknown member: " + member);
77+
return item.getMember(member).isValueChanged(context);
78+
}
79+
6880
public static void deepClone(IContext c, IMendixObject source, IMendixObject target, String membersToSkip, String membersToKeep, String reverseAssociations, String excludeEntities, String excludeModules) throws CoreException {
6981
List<String> toskip = Arrays.asList((membersToSkip + ",createdDate,changedDate").split(","));
7082
List<String> tokeep = Arrays.asList((membersToKeep + ",System.owner,System.changedBy").split(","));
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package communitycommons.actions;
11+
12+
import com.mendix.systemwideinterfaces.core.IMendixObject;
13+
import communitycommons.ORM;
14+
import com.mendix.systemwideinterfaces.core.IContext;
15+
import com.mendix.systemwideinterfaces.core.UserAction;
16+
17+
/**
18+
* Check if the value of the member was changed to something other than its original value.
19+
*/
20+
public class memberHasChangedValue extends UserAction<java.lang.Boolean>
21+
{
22+
private final IMendixObject item;
23+
private final java.lang.String member;
24+
25+
public memberHasChangedValue(
26+
IContext context,
27+
IMendixObject _item,
28+
java.lang.String _member
29+
)
30+
{
31+
super(context);
32+
this.item = _item;
33+
this.member = _member;
34+
}
35+
36+
@java.lang.Override
37+
public java.lang.Boolean executeAction() throws Exception
38+
{
39+
// BEGIN USER CODE
40+
return ORM.memberHasChangedValue(getContext(), item, member);
41+
// END USER CODE
42+
}
43+
44+
/**
45+
* Returns a string representation of this action
46+
* @return a string representation of this action
47+
*/
48+
@java.lang.Override
49+
public java.lang.String toString()
50+
{
51+
return "memberHasChangedValue";
52+
}
53+
54+
// BEGIN EXTRA CODE
55+
// END EXTRA CODE
56+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package communitycommons.actions;
11+
12+
import com.mendix.systemwideinterfaces.core.IMendixObject;
13+
import communitycommons.ORM;
14+
import com.mendix.systemwideinterfaces.core.IContext;
15+
import com.mendix.systemwideinterfaces.core.UserAction;
16+
17+
/**
18+
* Returns true if any member has a value other than its original value.
19+
*/
20+
public class objectHasChangedMemberValue extends UserAction<java.lang.Boolean>
21+
{
22+
private final IMendixObject item;
23+
24+
public objectHasChangedMemberValue(
25+
IContext context,
26+
IMendixObject _item
27+
)
28+
{
29+
super(context);
30+
this.item = _item;
31+
}
32+
33+
@java.lang.Override
34+
public java.lang.Boolean executeAction() throws Exception
35+
{
36+
// BEGIN USER CODE
37+
return ORM.objectHasChangedMemberValue(getContext(), item);
38+
// END USER CODE
39+
}
40+
41+
/**
42+
* Returns a string representation of this action
43+
* @return a string representation of this action
44+
*/
45+
@java.lang.Override
46+
public java.lang.String toString()
47+
{
48+
return "objectHasChangedMemberValue";
49+
}
50+
51+
// BEGIN EXTRA CODE
52+
// END EXTRA CODE
53+
}

0 commit comments

Comments
 (0)