use of com.servoy.j2db.persistence.AbstractBase in project servoy-client by Servoy.
the class FormComponentPropertyType method getFCPropertyDescription.
/**
* @param property
* @param currentValue
* @param fs
* @param forms
* @return
*/
private PropertyDescription getFCPropertyDescription(String property, JSONObject currentValue, FlattenedSolution fs, HashSet<String> forms, Map<String, PropertyDescription> cached) {
PropertyDescription pd;
if (currentValue != null) {
String formName = currentValue.optString(SVY_FORM);
PropertyDescription propertyDescription = cached.get(formName);
if (propertyDescription != null) {
return propertyDescription;
}
PropertyDescriptionBuilder pdBuilder = new PropertyDescriptionBuilder().withName(property).withType(FormComponentPropertyType.INSTANCE);
PropertyDescription formDesc = new PropertyDescriptionBuilder().withName(SVY_FORM).withType(StringPropertyType.INSTANCE).build();
pdBuilder.withProperty(SVY_FORM, formDesc);
Form form = getForm(formName, fs);
String testFormName = form.getName();
boolean nested = false;
if (form != null && !forms.add(testFormName)) {
// $NON-NLS-1$
Debug.error("recursive reference found between (List)FormComponents: " + forms);
nested = true;
}
while (form != null) {
List<IFormElement> formelements = form.getFlattenedObjects(null);
for (IFormElement element : formelements) {
if (element.getName() != null) {
WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(FormTemplateGenerator.getComponentTypeName(element));
Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (properties.size() > 0 && !nested) {
PropertyDescriptionBuilder nestedFormComponentBuilder = new PropertyDescriptionBuilder().withName(element.getName());
for (PropertyDescription nestedFormComponentPD : properties) {
Object object = ((AbstractBase) element).getProperty(nestedFormComponentPD.getName());
if (object instanceof JSONObject) {
nestedFormComponentBuilder.withProperty(nestedFormComponentPD.getName(), getFCPropertyDescription(nestedFormComponentPD.getName(), (JSONObject) object, fs, forms, cached));
}
}
pdBuilder.withProperty(element.getName(), nestedFormComponentBuilder.build());
} else {
pdBuilder.withProperty(element.getName(), spec);
}
}
}
form = form.getExtendsForm();
}
forms.remove(testFormName);
pd = pdBuilder.build();
cached.put(formName, pd);
} else {
PropertyDescriptionBuilder pdBuilder = new PropertyDescriptionBuilder().withName(property).withType(FormComponentPropertyType.INSTANCE);
PropertyDescription formDesc = new PropertyDescriptionBuilder().withName(SVY_FORM).withType(StringPropertyType.INSTANCE).build();
pdBuilder.withProperty(SVY_FORM, formDesc);
pd = pdBuilder.build();
}
return pd;
}
use of com.servoy.j2db.persistence.AbstractBase in project servoy-client by Servoy.
the class EventExecutor method executeEvent.
public Object executeEvent(WebComponent component, String eventType, int eventId, Object[] eventArgs) {
Scriptable scope = null;
Function f = null;
Object[] newargs = eventArgs != null ? Arrays.copyOf(eventArgs, eventArgs.length) : null;
if (eventId > 0) {
ScriptMethod scriptMethod = formController.getApplication().getFlattenedSolution().getScriptMethod(eventId);
if (scriptMethod != null) {
if (scriptMethod.getParent() instanceof Form) {
FormScope formScope = formController.getFormScope();
f = formScope.getFunctionByName(scriptMethod.getName());
if (f != null && f != Scriptable.NOT_FOUND) {
scope = formScope;
}
} else // is it a global method
if (scriptMethod.getParent() instanceof Solution) {
scope = formController.getApplication().getScriptEngine().getScopesScope().getGlobalScope(scriptMethod.getScopeName());
if (scope != null) {
f = ((GlobalScope) scope).getFunctionByName(scriptMethod.getName());
}
} else // very like a foundset/entity method
{
Scriptable foundsetScope = null;
if (component instanceof WebFormComponent) {
IRecord rec = ((WebFormComponent) component).getDataAdapterList().getRecord();
if (rec != null) {
foundsetScope = (Scriptable) rec.getParentFoundSet();
}
}
if (foundsetScope == null)
foundsetScope = (Scriptable) formController.getFormModel();
if (foundsetScope != null) {
// TODO ViewFoundSets should be come a scriptable if they have foundset methods..
scope = foundsetScope;
Object scopeMethod = scope.getPrototype().get(scriptMethod.getName(), scope);
if (scopeMethod instanceof Function)
f = (Function) scopeMethod;
}
}
if (f == null) {
Debug.error(// $NON-NLS-1$ //$NON-NLS-2$
"No function found for " + scriptMethod + " when trying to execute the event " + eventType + '(' + eventId + ") of component: " + component, // $NON-NLS-1$
new RuntimeException());
return null;
}
} else {
Debug.warn("Couldn't find the ScriptMethod for event: " + eventType + " with event id: " + eventId + " to execute for component " + component);
}
}
// $NON-NLS-1$
if (formController.isInFindMode() && !Utils.getAsBoolean(f.get("_AllowToRunInFind_", f)))
return null;
if (newargs != null) {
for (int i = 0; i < newargs.length; i++) {
if (newargs[i] instanceof JSONObject && "event".equals(((JSONObject) newargs[i]).optString("type"))) {
JSONObject json = (JSONObject) newargs[i];
JSEvent event = new JSEvent();
JSEventType.fillJSEvent(event, json, component, formController);
event.setType(getEventType(eventType));
event.setName(RepositoryHelper.getDisplayName(eventType, BaseComponent.class));
newargs[i] = event;
} else {
// try to convert the received arguments
WebObjectFunctionDefinition propertyDesc = component.getSpecification().getHandler(eventType);
List<PropertyDescription> parameters = propertyDesc.getParameters();
if (i < parameters.size()) {
PropertyDescription parameterPropertyDescription = parameters.get(i);
ValueReference<Boolean> returnValueAdjustedIncommingValueForIndex = new ValueReference<Boolean>(Boolean.FALSE);
newargs[i] = NGConversions.INSTANCE.convertSabloComponentToRhinoValue(JSONUtils.fromJSON(null, newargs[i], parameterPropertyDescription, new BrowserConverterContext(component, PushToServerEnum.allow), returnValueAdjustedIncommingValueForIndex), parameterPropertyDescription, component, scope);
}
// TODO? if in propertyDesc.getAsPropertyDescription().getConfig() we have "type":"${dataproviderType}" and parameterPropertyDescription.getType() is Object
// then get the type from the dataprovider and try to convert the json to that type instead of simply object
}
}
}
if (component instanceof WebFormComponent) {
IPersist persist = ((WebFormComponent) component).getFormElement().getPersistIfAvailable();
if (persist instanceof AbstractBase) {
List<Object> instanceMethodArguments = ((AbstractBase) persist).getFlattenedMethodArguments(eventType);
if (instanceMethodArguments != null && instanceMethodArguments.size() > 0) {
// create entries for the instanceMethodArguments if they are more then callback arguments
if (instanceMethodArguments.size() > newargs.length) {
newargs = Utils.arrayJoin(newargs, new Object[instanceMethodArguments.size() - newargs.length]);
}
// use instanceMethodArguments if not null, else just use the callback argument
for (int i = 0; i < instanceMethodArguments.size(); i++) {
Object value = instanceMethodArguments.get(i);
if (value != null && value != JSONObject.NULL) {
newargs[i] = Utils.parseJSExpression(value);
}
}
}
}
}
try {
formController.getApplication().updateLastAccessed();
return formController.getApplication().getScriptEngine().executeFunction(f, scope, scope, newargs, false, false);
} catch (Exception ex) {
formController.getApplication().reportJSError(ex.getMessage(), ex);
return null;
}
}
use of com.servoy.j2db.persistence.AbstractBase in project servoy-client by Servoy.
the class PersistBasedFormElementImpl method getFormElementPropertyValues.
public Map<String, Object> getFormElementPropertyValues(FlattenedSolution fs, Map<String, PropertyDescription> specProperties, PropertyPath propertyPath) {
Map<String, String> parsedAttributes = new HashMap<String, String>();
if (persist instanceof BaseComponent) {
Map<String, String> attributes = new HashMap<String, String>(((BaseComponent) persist).getMergedAttributes());
if (attributes != null && attributes.size() > 0) {
attributes.forEach((key, value) -> {
if (value != null && key != null)
parsedAttributes.put(StringEscapeUtils.escapeEcmaScript(key), value);
});
}
}
if (persist instanceof IBasicWebComponent) {
if (FormTemplateGenerator.isWebcomponentBean(persist)) {
JSONObject jsonProperties = ((IBasicWebComponent) persist).getFlattenedJson();
if (jsonProperties == null)
jsonProperties = new ServoyJSONObject();
// convert from persist design-time value (which might be non-json) to the expected value
Map<String, Object> jsonMap = processPersistProperties(fs, specProperties, propertyPath);
// this is handled separately as NG component definition
jsonMap.remove(IContentSpecConstantsBase.PROPERTY_BEANXML);
// this is handled separately as NG component definition
jsonMap.remove(IContentSpecConstants.PROPERTY_JSON);
try {
// add beanXML (which is actually a JSON string here) defined properties to the map
formElement.convertFromJSONToFormElementValues(fs, specProperties, jsonMap, formElement.getWebComponentSpec().getHandlers(), jsonProperties, propertyPath);
} catch (Exception ex) {
Debug.error("Error while parsing bean design json", ex);
jsonMap.put("error", "Error while parsing bean design json(bean not supported in NGClient?): " + persist);
}
if (parsedAttributes.size() > 0) {
jsonMap.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
}
return jsonMap;
} else {
Map<String, Object> defaultProperties = new HashMap<String, Object>();
defaultProperties.put(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), ((IBasicWebComponent) persist).getSize());
defaultProperties.put(StaticContentSpecLoader.PROPERTY_NAME.getPropertyName(), ((IBasicWebComponent) persist).getName());
defaultProperties.put("error", "Bean not supported in NGClient: " + persist);
return defaultProperties;
}
} else if (persist instanceof AbstractBase) {
Map<String, Object> map = processPersistProperties(fs, specProperties, propertyPath);
if (persist instanceof Field && ((Field) persist).getDisplayType() == Field.MULTISELECT_LISTBOX) {
map.put("multiselectListbox", Boolean.TRUE);
} else if (persist instanceof TabPanel) {
convertFromTabPanelToNGProperties((IFormElement) persist, fs, map, specProperties, propertyPath);
} else if (persist instanceof Portal) {
convertFromPortalToNGProperties((Portal) persist, fs, map, specProperties, propertyPath);
}
if (parsedAttributes.size() > 0) {
map.put(IContentSpecConstants.PROPERTY_ATTRIBUTES, parsedAttributes);
}
return map;
} else {
return Collections.emptyMap();
}
}
use of com.servoy.j2db.persistence.AbstractBase in project servoy-client by Servoy.
the class FormElementHelper method getFormElement.
public FormElement getFormElement(IFormElement formElement, FlattenedSolution fs, PropertyPath propertyPath, final boolean designer) {
// dont cache if solution model is used (media,valuelist,relations can be changed for a none changed element)
if (designer || (fs.getSolutionCopy(false) != null) || ((AbstractBase) formElement).getRuntimeProperty(FORM_COMPONENT_FORM_NAME) != null) {
if (formElement instanceof BodyPortal)
return createBodyPortalFormElement((BodyPortal) formElement, fs, designer);
else
return new FormElement(formElement, fs, propertyPath == null ? new PropertyPath().setShouldAddElementName() : propertyPath, designer);
}
FormElement persistWrapper = persistWrappers.get(formElement);
if (persistWrapper == null) {
if (propertyPath == null) {
propertyPath = new PropertyPath();
propertyPath.setShouldAddElementName();
}
if (formElement instanceof BodyPortal)
persistWrapper = createBodyPortalFormElement((BodyPortal) formElement, getSharedFlattenedSolution(fs), designer);
else
persistWrapper = new FormElement(formElement, getSharedFlattenedSolution(fs), propertyPath, designer);
FormElement existing = persistWrappers.putIfAbsent(formElement, persistWrapper);
if (existing != null) {
persistWrapper = existing;
}
}
return persistWrapper;
}
use of com.servoy.j2db.persistence.AbstractBase in project servoy-client by Servoy.
the class FormElement method convertDesignToFormElementValueAndPut.
/**
* Applies 'Conversion 1' (see {@link NGConversions}) to one property value - from design to FormElement value and then puts the value in the given formElementValues map.
*/
protected void convertDesignToFormElementValueAndPut(FlattenedSolution fs, PropertyDescription pd, Map<String, Object> formElementValues, String key, Object value, PropertyPath propertyPath) {
// is it a property
if (pd != null) {
propertyPath.add(key);
// value has the 'merged' value in hierarchy, except for the 'formcomponent' property; do the merge here
if ((pd.getType() instanceof FormComponentPropertyType) && value instanceof JSONObject && getPersistIfAvailable() instanceof ISupportExtendsID) {
// this is a json object, look for super persist for this property to get those values.
List<AbstractBase> hierarchy = PersistHelper.getOverrideHierarchy((ISupportExtendsID) getPersistIfAvailable());
if (hierarchy.size() > 1) {
// there is a super element (or more) so make a copy and copy everything in that.
JSONObject mergedValue = null;
for (int i = hierarchy.size(); --i >= 0; ) {
Object property = hierarchy.get(i).getProperty(key);
if (property instanceof JSONObject) {
if (mergedValue == null) {
mergedValue = new JSONObject();
}
ServoyJSONObject.mergeAndDeepCloneJSON((JSONObject) property, mergedValue);
} else if (property != null) {
mergedValue = null;
break;
}
}
if (mergedValue != null) {
value = mergedValue;
}
}
}
Object convertedValue = NGConversions.INSTANCE.convertDesignToFormElementValue(value, pd, fs, this, propertyPath);
formElementValues.put(key, convertedValue);
propertyPath.backOneLevel();
} else if (StaticContentSpecLoader.PROPERTY_NAME.getPropertyName().equals(key)) {
formElementValues.put(key, value);
}
}
Aggregations