Skip to content

Commit f7b6c93

Browse files
committed
ajax parameters modification hash based detection
1 parent 7794262 commit f7b6c93

File tree

8 files changed

+259
-83
lines changed

8 files changed

+259
-83
lines changed

common/src/main/java/com/genexus/GXBaseCollection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class GXBaseCollection<T extends GXXMLSerializable> extends GXSimpleColle
2323
private static final long serialVersionUID = 1L;
2424
public GXBaseCollection()
2525
{
26+
super();
2627
}
2728

2829
public GXBaseCollection(Class<T> elementsType, String elementsName, String containedXmlNamespace)
@@ -42,7 +43,7 @@ public GXBaseCollection(Class<T> elementsType, String elementsName, String conta
4243

4344
public GXBaseCollection(Class<T> elementsType, String elementsName, String containedXmlNamespace, Vector<T> data, int remoteHandle)
4445
{
45-
46+
super();
4647
this.elementsType = elementsType;
4748
this.elementsName = elementsName;
4849
xmlElementsName = elementsName;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.genexus;
2+
3+
import java.io.Serializable;
4+
import java.util.Vector;
5+
import com.genexus.internet.IGxJSONAble;
6+
import com.genexus.internet.IGxJSONSerializable;
7+
8+
public abstract class GXBaseList<T> extends Vector<T> implements Serializable, IGxJSONAble, IGxJSONSerializable, IGXAssigned
9+
{
10+
private boolean IsAssigned;
11+
12+
public GXBaseList()
13+
{
14+
IsAssigned = true;
15+
}
16+
17+
public void clear() {
18+
super.clear();
19+
IsAssigned = true;
20+
}
21+
22+
public boolean getIsAssigned()
23+
{
24+
return this.IsAssigned;
25+
}
26+
public void setIsAssigned(boolean bAssigned)
27+
{
28+
this.IsAssigned = bAssigned;
29+
}
30+
public void removeAllItems()
31+
{
32+
clear();
33+
}
34+
public byte removeItem(int index)
35+
{
36+
T item = null;
37+
if(index > 0 && index <= size())
38+
{
39+
item = super.remove((int)index - 1);//Vector.remove(int)
40+
IsAssigned = true;
41+
return (byte)1;
42+
}
43+
return (byte)0;
44+
}
45+
public byte removeElement(double index)
46+
{
47+
if(index > 0 && index <= size())
48+
{
49+
super.remove((int)index - 1);//Vector.remove(int)
50+
IsAssigned = true;
51+
return (byte)1;
52+
}
53+
else
54+
{
55+
return (byte)0;
56+
}
57+
}
58+
59+
@SuppressWarnings("unchecked")
60+
public void addObject(Object obj){
61+
super.add((T)obj);
62+
IsAssigned = true;
63+
}
64+
@SuppressWarnings("unchecked")
65+
public void add(Object item, int index)
66+
{
67+
if(index < 1 || index > size())
68+
{
69+
add((T)item); //this.add, GXBCLevelCollection.add for example
70+
}
71+
else
72+
{
73+
super.add(index - 1, (T)item); //Vector insert element
74+
IsAssigned = true;
75+
}
76+
}
77+
@SuppressWarnings("unchecked")
78+
public void addBase( Object item)
79+
{
80+
super.add((T)item);
81+
IsAssigned = true;
82+
}
83+
}
84+
85+
86+

common/src/main/java/com/genexus/GXSimpleCollection.java

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.simpleframework.xml.*;
3838

3939
@Root(name="Collection")
40-
public class GXSimpleCollection<T> extends Vector<T> implements Serializable, IGxJSONAble, IGxJSONSerializable {
40+
public class GXSimpleCollection<T> extends GXBaseList<T> {
4141

4242
@ElementList(entry="item",inline=true)
4343
GXSimpleCollection<T> list;
@@ -50,6 +50,7 @@ public class GXSimpleCollection<T> extends Vector<T> implements Serializable, IG
5050

5151
public GXSimpleCollection()
5252
{
53+
super();
5354
}
5455

5556
public GXSimpleCollection(Class<T> elementsType, String elementsName, String containedXmlNamespace)
@@ -69,6 +70,7 @@ public GXSimpleCollection(Class<T> elementsType, String elementsName, String con
6970

7071
public GXSimpleCollection(Class<T> elementsType, String elementsName, String containedXmlNamespace, Vector data, int remoteHandle)
7172
{
73+
super();
7274
this.elementsType = elementsType;
7375
this.elementsName = elementsName;
7476
xmlElementsName = elementsName;
@@ -432,11 +434,6 @@ public Object currentItem()
432434

433435
//-- Este add se usa cuando se quiere agregar a las lineas de un BC sin usar la logica de manteniomiento del estado
434436
// de la linea
435-
@SuppressWarnings("unchecked")
436-
public void addBase( Object item)
437-
{
438-
super.add((T)item);
439-
}
440437
protected String getMethodName(boolean isGet, String method)
441438
{
442439
String getName = elementsType.getName();
@@ -456,19 +453,6 @@ public void addInternal(Object item)
456453
super.add((T)item);
457454
}
458455

459-
@SuppressWarnings("unchecked")
460-
public void add(Object item, int index)
461-
{
462-
if(index < 1 || index > size())
463-
{
464-
add((T)item); //this.add, GXBCLevelCollection.add for example
465-
}
466-
else
467-
{
468-
super.add(index - 1, (T)item); //Vector insert element
469-
}
470-
}
471-
472456
public void add(byte item)
473457
{
474458
addInternal(new Byte(item));
@@ -520,11 +504,6 @@ public void addIntegralConstant(double item)
520504
}
521505
}
522506

523-
@SuppressWarnings("unchecked")
524-
public void addObject(Object obj){
525-
super.add((T)obj);
526-
}
527-
528507
public void add(long item)
529508
{
530509
addInternal(new Long(item));
@@ -602,11 +581,6 @@ public void add(double item, int index)
602581
addIntegralConstant(item, index);
603582
}
604583

605-
public void removeAllItems()
606-
{
607-
super.clear();
608-
}
609-
610584
public void clearCollection()
611585
{
612586
removeAllItems();
@@ -694,30 +668,6 @@ public boolean remove(char item)
694668
return remove(new Character(item));
695669
}
696670

697-
public byte removeItem(int index)
698-
{
699-
T item = null;
700-
if(index > 0 && index <= size())
701-
{
702-
item = super.remove((int)index - 1);//Vector.remove(int)
703-
return (byte)1;
704-
}
705-
return (byte)0;
706-
}
707-
708-
public byte removeElement(double index)
709-
{
710-
if(index > 0 && index <= size())
711-
{
712-
super.remove((int)index - 1);//Vector.remove(int)
713-
return (byte)1;
714-
}
715-
else
716-
{
717-
return (byte)0;
718-
}
719-
}
720-
721671
/** Ordena la Collection de acuerdo a un proc pasado por parametro
722672
* El proc tiene que recibir como parms
723673
* parm(IN: &SDT1, IN: &SDT2, OUT: INT)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.genexus;
2+
public interface IGXAssigned
3+
{
4+
boolean getIsAssigned();
5+
void setIsAssigned(boolean bAssigned);
6+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.genexus;
2+
3+
import com.genexus.xml.GXXMLSerializable;
4+
5+
public abstract class GxUserType extends GXXMLSerializable implements Cloneable, java.io.Serializable, IGXAssigned
6+
{
7+
8+
public GxUserType(ModelContext context, String type)
9+
{
10+
super(-1, context, type);
11+
}
12+
13+
public GxUserType(int remoteHandle, ModelContext context, String type)
14+
{
15+
super( remoteHandle, context, type);
16+
}
17+
18+
boolean bIsAssigned = true;
19+
20+
public abstract String getJsonMap( String value );
21+
22+
@Override
23+
public boolean getIsAssigned() {
24+
return bIsAssigned;
25+
}
26+
27+
@Override
28+
public void setIsAssigned(boolean bAssigned) {
29+
bIsAssigned = bAssigned;
30+
}
31+
}

java/src/main/java/com/genexus/internet/HttpAjaxContext.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
import java.util.Hashtable;
88
import java.util.Stack;
99

10+
import com.genexus.IGXAssigned;
1011
import com.genexus.diagnostics.core.ILogger;
1112
import com.genexus.diagnostics.core.LogManager;
13+
import com.genexus.webpanels.DynAjaxEventContext;
14+
import com.genexus.webpanels.GXWebPanel;
1215
import com.genexus.webpanels.GXWebRow;
1316

1417
import json.org.json.IJsonFormattable;
@@ -44,8 +47,13 @@ public abstract class HttpAjaxContext
4447
public void setAjaxOnSessionTimeout( String ajaxOnSessionTimeout){ this._ajaxOnSessionTimeout = ajaxOnSessionTimeout;}
4548
public String ajaxOnSessionTimeout(){ return _ajaxOnSessionTimeout;}
4649

50+
DynAjaxEventContext dynAjaxEventContext = new DynAjaxEventContext();
4751

48-
public abstract boolean isMultipartContent();
52+
public DynAjaxEventContext getDynAjaxEventContext() {
53+
return dynAjaxEventContext;
54+
}
55+
56+
public abstract boolean isMultipartContent();
4957
public abstract void ajax_rsp_assign_prop_as_hidden(String Control, String Property, String Value);
5058

5159
public abstract boolean isSpaRequest();
@@ -319,16 +327,28 @@ public void ajax_rsp_assign_attri( String CmpContext, boolean IsMasterPage, Stri
319327
}
320328
}
321329

322-
public void ajax_rsp_assign_sdt_attri( String CmpContext, boolean IsMasterPage, String AttName, Object SdtObj)
330+
private boolean isUndefinedOutParam(String key, Object SdtObj) {
331+
if (!dynAjaxEventContext.isInputParm(key))
332+
{
333+
if (SdtObj instanceof IGXAssigned)
334+
{
335+
return !((IGXAssigned)SdtObj).getIsAssigned();
336+
}
337+
}
338+
return false;
339+
}
340+
341+
342+
public void ajax_rsp_assign_sdt_attri( String CmpContext, boolean IsMasterPage, String AttName, Object SdtObj)
323343
{
324344
if (isJsOutputEnabled)
325345
{
326346
if (!isSpaRequest() || (isSpaRequest() && (CmpContext == null || CmpContext.trim().length() == 0)))
327347
{
328348
try {
329349
JSONObject obj = getGxObject(AttValues, CmpContext, IsMasterPage);
330-
if (obj != null)
331-
{
350+
if (obj != null && (dynAjaxEventContext.isParmModified(AttName, SdtObj) || !isUndefinedOutParam( AttName, SdtObj)))
351+
{
332352
if (SdtObj instanceof IGxJSONAble)
333353
obj.put(AttName, ((IGxJSONAble)SdtObj).GetJSONObject());
334354
else
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.genexus.webpanels;
2+
3+
import com.genexus.GXutil;
4+
import com.genexus.internet.IGxJSONSerializable;
5+
import json.org.json.JSONArray;
6+
7+
import java.util.HashSet;
8+
import java.util.Hashtable;
9+
10+
public class DynAjaxEventContext implements GXWebPanel.IDynAjaxEventContext {
11+
JSONArray inParmsMetadata;
12+
HashSet<String> inParmsMetadataHash = new HashSet<String>();
13+
JSONArray outParmsMetadata;
14+
HashSet<String> outParmsMetadataHash = new HashSet<String>();
15+
private Hashtable<String, String> inParmsHashValue = new Hashtable<String, String>();
16+
17+
public void ClearParmsMetadata() {
18+
inParmsMetadata = new JSONArray();
19+
inParmsMetadataHash = new HashSet<String>();
20+
outParmsMetadata = new JSONArray();
21+
outParmsMetadataHash = new HashSet<String>();
22+
}
23+
24+
public boolean isInputParm(String key) {
25+
return inParmsMetadataHash.contains(key);
26+
}
27+
28+
public void Clear() {
29+
inParmsHashValue.clear();
30+
}
31+
32+
public void SetParmHash(String fieldName, Object value) {
33+
IGxJSONSerializable jsonValue = (value instanceof IGxJSONSerializable) ? (IGxJSONSerializable) value : null;
34+
if (jsonValue != null) {
35+
inParmsHashValue.put(fieldName, GXutil.getHash(jsonValue.toJSonString()));
36+
}
37+
}
38+
39+
public boolean isParmModified(String fieldName, Object value) {
40+
IGxJSONSerializable jsonValue = (value instanceof IGxJSONSerializable) ? (IGxJSONSerializable) value : null;
41+
if (value != null) {
42+
if (!inParmsHashValue.containsKey(fieldName))
43+
return true;
44+
return !GXutil.getHash(jsonValue.toJSonString()).equals(inParmsHashValue.get(fieldName));
45+
}
46+
return true;
47+
}
48+
}

0 commit comments

Comments
 (0)