Skip to content

Commit

Permalink
Merge branch 'upstream_master' into Ajax_interactivityImprovements
Browse files Browse the repository at this point in the history
  • Loading branch information
markusstoll committed Jun 16, 2019
2 parents 98d21c0 + e811aae commit d92ef2e
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 49 deletions.
1 change: 0 additions & 1 deletion .mvn/maven.config

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
* <td>bounces the application (starts a few instances per hosts, set the rest to refusing sessions and auto-recover)</td>
* </tr>
* <tr>
* <td>setAdditionalArgs</td>
* <td>'OK' or <br>
* error message</td>
* <td>updates the instances' additional command line arguments</td>
* </tr>
* <tr>
* <td>info</td>
* <td>JSON or<br>
* error message</td>
Expand Down Expand Up @@ -191,6 +197,21 @@
* </table>
* </p>
* <p>
* The direct action <code>setAdditionalArgs</code> must be invoked with the following argument:
* <table cellspacing="0" cellpadding="5" border="1">
* <tr>
* <th>Argument</th>
* <th>Value</th>
* <th>Description</th>
* </tr>
* <tr>
* <td><code>args</code></td>
* <td><i>string</i></td>
* <td>the additional arguments to be passed to the instance on startup</td>
* </tr>
* </table>
* </p>
* <p>
* Possible status codes:
* <table cellspacing="0" cellpadding="5" border="1">
* <tr>
Expand Down Expand Up @@ -478,6 +499,12 @@ public void weeklyScheduleRangeAction() {
applicationsPage().weeklyStartHours(instances, Integer.parseInt(beginScheduleWindow), Integer.parseInt(endScheduleWindow), Integer.parseInt(weekDay));
}

public void setAdditionalArgsAction() {
String arguments = (String) context().request().formValueForKey("args");
if (arguments != null)
applicationsPage().setAdditionalArgs(instances, arguments);
}

public void turnScheduledOnAction() {
applicationsPage().turnScheduledOn(instances);
}
Expand Down Expand Up @@ -635,4 +662,4 @@ public WOActionResults performActionNamed(String s) {
public Session mySession() {
return (Session) session();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ public void turnScheduledOff(NSArray nsarray) {
sendUpdateInstancesToWotaskds();
}

public void setAdditionalArgs(NSArray instances, String arguments) {
for(Enumeration enumeration = instances.objectEnumerator(); enumeration.hasMoreElements();) {
MInstance instance = (MInstance) enumeration.nextElement();
String instArgs = instance.additionalArgs();
if (instArgs == null || !arguments.equals(instArgs)) {
instance.setAdditionalArgs(arguments);
processedInstance(instance);
}
}
sendUpdateInstancesToWotaskds();
}

public void turnRefuseNewSessionsOn(NSArray nsarray) {
for(Enumeration enumeration = nsarray.objectEnumerator(); enumeration.hasMoreElements();) {
MInstance minstance = (MInstance) enumeration.nextElement();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
<webobject name = "Disabled"><webobject name = "TextField" /></webobject><webobject name = "NotDisabled"> <webobject name = "ShowItem"> <webobject name = "TextField" /> <webobject name="HasIndicator"><webobject name="Indicator"/></webobject> <webobject name = "ZIndexContainer"> <webobject name = "AutoCompleteContainer"/> </webobject> <script> Event.observe(window, 'load', function() { var div = $('<webobject name = "ZIndexContainerName"/>'); <webobject name="hasContainerId"> document.getElementById('<webobject name="containerId"/>').appendChild(div); </webobject> <webobject name="else"> document.getElementsByTagName('body')[0].appendChild(div); </webobject> }); </script> </webobject> <webobject name = "ShowList"><webobject name = "Content" /></webobject></webobject>
<webobject name = "Disabled"><webobject name = "TextField" /></webobject>
<webobject name = "NotDisabled">
<webobject name = "ShowItem">
<webobject name = "TextField" />
<webobject name = "HasIndicator"><webobject name = "Indicator" /></webobject>
<webobject name = "AutoCompleteContainer"><webobject name = "ZIndexContainer" /></webobject>
<script>
Event.observe(window, 'load', function() {
var div = $('<webobject name = "ZIndexContainerName" />');
<webobject name = "hasContainerId">document.getElementById('<webobject name = "containerId" />').appendChild(div);</webobject>
<webobject name = "else">document.getElementsByTagName('body')[0].appendChild(div);</webobject>
});
</script>
</webobject>
<webobject name = "ShowList"><webobject name = "Content" /></webobject>
</webobject>
20 changes: 15 additions & 5 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxAutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
* @binding minChars Look at the scriptaculous documentation.
* @binding indicator Look at the scriptaculous documentation.
* @binding updateElement Look at the scriptaculous documentation.
* @binding afterUpdateElement Look at the scriptaculous documentation.
* @binding afterUpdateElement Look at the scriptaculous documentation. Also, a value of <code>"observe"</code> will generate javascript to submit change to server when item selected from list. Provided because {@link AjaxObserveField} doesn't work on {@link AjaxAutoComplete} fields.
* @binding select Look at the scriptaculous documentation.
* @binding onShow Look at the scriptaculous documentation.
* @binding fullSearch Look at the scriptaculous documentation.
Expand Down Expand Up @@ -159,7 +159,7 @@ protected NSDictionary<String, String> createAjaxOptions() {
ajaxOptionsArray.addObject(new AjaxOption("tokens", AjaxOption.STRING_ARRAY));
ajaxOptionsArray.addObject(new AjaxOption("frequency", AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("minChars", AjaxOption.NUMBER));
ajaxOptionsArray.addObject(new AjaxOption("indicator", indicator(), AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("indicator", indicator(), AjaxOption.STRING));
ajaxOptionsArray.addObject(new AjaxOption("updateElement", AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("afterUpdateElement", AjaxOption.SCRIPT));
ajaxOptionsArray.addObject(new AjaxOption("onShow", AjaxOption.SCRIPT));
Expand All @@ -183,6 +183,17 @@ public void appendToResponse(WOResponse res, WOContext ctx) {
super.appendToResponse(res, ctx);
boolean isDisabled = booleanValueForBinding("disabled", false);
if ( !isDisabled ) {
String actionUrl = AjaxUtils.ajaxComponentActionUrl(ctx);
NSMutableDictionary<String, String> options = createAjaxOptions().mutableClone();
if ("observe".equalsIgnoreCase(options.get("afterUpdateElement"))) {
// Javascript to simulate AjaxObserveField on this AjaxAutocomplete when an item has been selected from the list
String afterUpdateElement = "function (text, li) { " +
"var options = new Array();" +
"options.parameters = encodeURIComponent('"+fieldName+"') + '=' + encodeURIComponent(text.value);" +
"new Ajax.Request('"+actionUrl+"', options);" +
"}";
options.put("afterUpdateElement", afterUpdateElement);
}
boolean isLocal = booleanValueForBinding("isLocal", false);
if (isLocal) {
StringBuilder str = new StringBuilder();
Expand All @@ -208,14 +219,13 @@ public void appendToResponse(WOResponse res, WOContext ctx) {
str.append("',");
str.append(listJS);
str.append(',');
AjaxOptions.appendToBuffer(createAjaxOptions(), str, ctx);
AjaxOptions.appendToBuffer(options, str, ctx);
str.append(");\n// ]]>\n</script>\n");
res.appendContentString(String.valueOf(str));
} else {
String actionUrl = AjaxUtils.ajaxComponentActionUrl(ctx);
AjaxUtils.appendScriptHeader(res);
res.appendContentString("new Ajax.Autocompleter('" + fieldName + "', '" + divName + "', '" + actionUrl + "', ");
AjaxOptions.appendToResponse(createAjaxOptions(), res, ctx);
AjaxOptions.appendToResponse(options, res, ctx);
res.appendContentString(");");
AjaxUtils.appendScriptFooter(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1871,34 +1871,38 @@ public static EOQualifier localInstancesInQualifier(EOEditingContext ec, EOQuali
* @param eos the NSArray of EOEnterpriseObjects
* @return a NSArray of EOGlobalIDs
*/
public static NSArray globalIDsForObjects(NSArray eos) {
int c = eos != null ? eos.count() : 0;
NSMutableArray ids = new NSMutableArray(c);
for (int i = 0; i < c; i++) {
EOEnterpriseObject eo = (EOEnterpriseObject)eos.objectAtIndex(i);
public static NSArray<EOGlobalID> globalIDsForObjects(NSArray<? extends EOEnterpriseObject> eos) {
if (eos == null) {
return new NSArray<>();
}
NSMutableArray<EOGlobalID> ids = new NSMutableArray(eos.count());
for (EOEnterpriseObject eo : eos) {
EOEditingContext ec = eo.editingContext();
EOGlobalID gid = ec.globalIDForObject(eo);
ids.addObject(gid);
}
}
return ids;
}

/**
* Aggregate method for <code>EOEditingContext.objectForGlobalID()</code>.
* <b>NOTE:</b> this only returns objects that are already registered, if you
* need all objects from the GIDs, use {@link #faultsForGlobalIDs(EOEditingContext, NSArray)}.
* @param ec the EOEditingContext in which the EOEnterpriseObjects should be faulted
* @param globalIDs the EOGlobalIDs
* @return a NSArray of EOEnterpriseObjects
* @see com.webobjects.eocontrol.EOEditingContext#objectForGlobalID(EOGlobalID)
*/
public static NSArray objectsForGlobalIDs(final EOEditingContext ec, final NSArray globalIDs) {
NSArray result = null;
public static <T extends EOEnterpriseObject> NSArray<T> objectsForGlobalIDs(final EOEditingContext ec, final NSArray<EOGlobalID> globalIDs) {
NSArray<T> result = null;

if ( globalIDs != null && globalIDs.count() > 0 ) {
final NSMutableArray a = new NSMutableArray();
final Enumeration e = globalIDs.objectEnumerator();
final NSMutableArray<T> a = new NSMutableArray<>();
final Enumeration<EOGlobalID> e = globalIDs.objectEnumerator();

while ( e.hasMoreElements() ) {
final EOGlobalID theGID = (EOGlobalID)e.nextElement();
final EOEnterpriseObject theObject = ec.faultForGlobalID(theGID, ec);
final EOGlobalID theGID = e.nextElement();
final T theObject = (T) ec.faultForGlobalID(theGID, ec);

if ( theObject != null )
a.addObject(theObject);
Expand All @@ -1915,23 +1919,23 @@ public static NSArray objectsForGlobalIDs(final EOEditingContext ec, final NSArr
* @param gids the EOGlobalIDs
* @return a NSArray of EOEnterpriseObjects
*/
public static NSArray faultsForGlobalIDs(EOEditingContext ec, NSArray gids) {
public static <T extends EOEnterpriseObject> NSArray<T> faultsForGlobalIDs(EOEditingContext ec, NSArray<EOGlobalID> gids) {
int c = gids.count();
NSMutableArray a = new NSMutableArray(c);
NSMutableArray<T> a = new NSMutableArray<>(c);
for (int i = 0; i < c; i++) {
EOGlobalID gid = (EOGlobalID)gids.objectAtIndex(i);
EOEnterpriseObject eo = ec.faultForGlobalID(gid, ec);
EOGlobalID gid = gids.objectAtIndex(i);
T eo = (T) ec.faultForGlobalID(gid, ec);
a.addObject(eo);
}
return a;
}

public static NSArray faultsForRawRowsFromEntity(EOEditingContext ec, NSArray primKeys, String entityName) {
public static <T extends EOEnterpriseObject> NSArray<T> faultsForRawRowsFromEntity(EOEditingContext ec, NSArray primKeys, String entityName) {
int c = primKeys.count();
NSMutableArray a = new NSMutableArray(c);
NSMutableArray<T> a = new NSMutableArray<>(c);
for (int i = 0; i < c; i++) {
NSDictionary pkDict = (NSDictionary)primKeys.objectAtIndex(i);
EOEnterpriseObject eo = ec.faultForRawRow(pkDict, entityName);
T eo = (T) ec.faultForRawRow(pkDict, entityName);
a.addObject(eo);
}
return a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected long cacheTime(NSArray eos, EOFetchSpecification fs) {
* @param eos
* @param fs
*/
public void setObjectsForFetchSpecification(EODatabaseContext dbc, EOEditingContext ec, NSArray<?> eos, EOFetchSpecification fs) {
public void setObjectsForFetchSpecification(EODatabaseContext dbc, EOEditingContext ec, NSArray<? extends EOEnterpriseObject> eos, EOFetchSpecification fs) {
String identifier = ERXFetchSpecification.identifierForFetchSpec(fs);
synchronized (cache) {
currentDatabase = dbc.database();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
Expand All @@ -28,6 +29,7 @@
import com.webobjects.eocontrol.EOQualifier;
import com.webobjects.eocontrol.EOSortOrdering;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSData;
import com.webobjects.foundation.NSDictionary;
import com.webobjects.foundation.NSForwardException;
import com.webobjects.foundation.NSKeyValueCoding;
Expand All @@ -43,6 +45,7 @@

import er.extensions.eof.ERXEOAccessUtilities.ChannelAction;
import er.extensions.foundation.ERXProperties;
import er.extensions.foundation.ERXStringUtilities;
import er.extensions.jdbc.ERXSQLHelper;

/**
Expand Down Expand Up @@ -851,6 +854,18 @@ protected static void setupAdaptorChannelEOAttributes(EOAdaptorChannel adaptorCh
if (externalType != null) adaptorSelectAttribute.setExternalType(externalType);
if (className != null) adaptorSelectAttribute.setClassName(className);
if (valueType != null) adaptorSelectAttribute.setValueType(valueType);

adaptorSelectAttribute.setAdaptorValueConversionClassName(selectAttribute.adaptorValueConversionClassName());
adaptorSelectAttribute.setAdaptorValueConversionMethodName(selectAttribute.adaptorValueConversionMethodName());
adaptorSelectAttribute.setFactoryMethodArgumentType(selectAttribute.factoryMethodArgumentType());
adaptorSelectAttribute.setValueFactoryMethodName(selectAttribute.valueFactoryMethodName());
// Defined in the ERXAttributeExtension EOAttribute but not visible by the compiler we use a runtime trick...
// adaptorSelectAttribute.setValueFactoryClassName(selectAttribute.valueFactoryClassName());
try {
String valueFactoryClassName = (String) NSKeyValueCoding.DefaultImplementation.valueForKey(selectAttribute, "valueFactoryClassName");
NSKeyValueCoding.DefaultImplementation.takeValueForKey(adaptorSelectAttribute, valueFactoryClassName, "valueFactoryClassName");
}
catch (Exception e) {} // Fail if ERXAttributeExtension is not loaded but you cannot use factory class anyway
}
adaptorChannel.setAttributesToFetch(adaptorSelectAttributes);
}
Expand Down Expand Up @@ -1812,24 +1827,19 @@ protected String formatValueForAttributeForInlineUse(EOSQLExpression sqlExpressi
// If the formattedValue is "NULL" then the formatValueForAttribute() did not
// do its job and we'll do the best we can here
if (formattedValue == null || formattedValue.equals("NULL")) {
if (value instanceof String) {
formattedValue = sqlExpression.formatStringValue((String)value);
} else if (value instanceof NSTimestamp) {
NSTimestamp timestamp = (NSTimestamp) value;
formattedValue = formattedTimestampForInlineUse(sqlExpression, timestamp, attribute);
} else if (value instanceof Boolean) {
boolean boolValue = (Boolean) value;
// If stored in the database as a string then format as string
// otherwise format as a number 1 or 0.
if (attribute.externalType().toLowerCase().contains("char")) {
formattedValue = "'" + boolValue +"'";
} else if (boolValue) {
formattedValue = EOSQLExpression.sqlStringForNumber(1);
} else {
formattedValue = EOSQLExpression.sqlStringForNumber(0);
}
// Ask the attribute to convert the value to adaptor type, this reduce the number of cases.
// Possible value type are now String, Date, Number or NSData
Object attributeValue = attribute.adaptorValueByConvertingAttributeValue(value);
if (attributeValue instanceof String) {
formattedValue = sqlExpression.formatStringValue((String)attributeValue);
} else if (attributeValue instanceof Date) {
Date date = (Date) attributeValue;
formattedValue = formattedTimestampForInlineUse(sqlExpression, date, attribute);
} else if (value instanceof NSData) {
NSData data = (NSData) value;
formattedValue = "X'" + ERXStringUtilities.byteArrayToHexString(data._bytesNoCopy()) + "'";
} else {
formattedValue = value.toString();
formattedValue = attributeValue.toString();
}
}
}
Expand All @@ -1845,7 +1855,7 @@ protected String databaseProductName(EOEntity entity) {
return plugin.databaseProductName().toLowerCase();
}

protected String formattedTimestampForInlineUse(EOSQLExpression sqlExpression, NSTimestamp timestamp, EOAttribute attribute) {
protected String formattedTimestampForInlineUse(EOSQLExpression sqlExpression, Date timestamp, EOAttribute attribute) {
EOEntity entity = attribute.entity();
String databaseProductName = databaseProductName(entity);
//NSTimestampFormatter formatter = new NSTimestampFormatter("%Y-%m-%d %H:%M:%S");
Expand Down
6 changes: 5 additions & 1 deletion Frameworks/EOF/ERRest/Sources/er/rest/ERXRestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;

Expand Down Expand Up @@ -172,6 +173,9 @@ else if (value instanceof OffsetDateTime) {
else if (value instanceof NSData && ((NSData)value).length() == 24) {
formattedValue = NSPropertyListSerialization.stringFromPropertyList(value);
}
else if (value instanceof NSData) {
formattedValue = Base64.getEncoder().encodeToString(((NSData) value).bytes());
}
else {
formattedValue = value.toString();
}
Expand Down Expand Up @@ -445,7 +449,7 @@ else if (valueType != null && TemporalAccessor.class.isAssignableFrom(valueType)
}
else {
TemporalQuery<?> query = null;
Class<? extends Class> valueTypeClass = valueType.getClass();
Class<?> valueTypeClass = valueType;
if (valueTypeClass.equals(LocalDate.class)) {
query = LocalDate::from;
}
Expand Down
1 change: 1 addition & 0 deletions Frameworks/Mail/ERCMail/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
Loading

0 comments on commit d92ef2e

Please sign in to comment.