use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicAction method addInfos.
@Override
protected void addInfos(Set<UIComponent> done, Map<String, Set<String>> infoMap) {
super.addInfos(done, infoMap);
IonBean ionBean = getIonBean();
if (ionBean != null) {
String beanName = ionBean.getName();
if (ionBean.hasProperty("marker")) {
JSONObject json = new JSONObject();
String key = null;
for (IonProperty property : ionBean.getProperties().values()) {
MobileSmartSourceType msst = property.getSmartType();
String p_name = property.getName();
Object p_value = property.getValue();
if (!p_value.equals(false)) {
if (beanName.equals("FullSyncViewAction")) {
if (p_name.equals("fsview")) {
key = p_value.toString() + ".view";
}
} else if (beanName.equals("FullSyncGetAction")) {
if (p_name.equals("requestable")) {
key = p_value.toString() + ".get";
}
} else if (beanName.equals("CallSequenceAction")) {
if (p_name.equals("requestable")) {
key = p_value.toString();
}
} else if (beanName.equals("CallFullSyncAction")) {
if (p_name.equals("requestable")) {
key = p_value.toString();
Object p_verb = ionBean.getProperty("verb").getValue();
if (!p_verb.equals(false)) {
key += "." + p_verb.toString();
}
}
}
}
try {
if (p_name.equals("marker")) {
json.put(p_name, !p_value.equals(false) ? msst.getValue() : "");
}
if (p_name.equals("include_docs")) {
json.put(p_name, !p_value.equals(false) ? msst.getValue() : "false");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
if (key != null && !key.isEmpty()) {
Set<String> infos = infoMap.get(key);
if (infos == null) {
infos = new HashSet<String>();
}
String info = json.toString();
if (!info.isEmpty()) {
infos.add(info);
}
infoMap.put(key, infos);
}
}
}
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIComponent method preconfigure.
@Override
public void preconfigure(Element element) throws Exception {
super.preconfigure(element);
String version = element.getAttribute("version");
long priority = Long.valueOf(element.getAttribute("priority")).longValue();
// TODO: REMOVE BEFORE RELEASE !!!
boolean doMigration = false;
if (!doMigration) {
return;
}
if (VersionUtils.compare(version, "7.9.0") < 0) {
try {
NodeList properties = element.getElementsByTagName("property");
int len = properties.getLength();
Element propElement;
for (int i = 0; i < len; i++) {
propElement = (Element) properties.item(i);
if (propElement != null && propElement.getParentNode().equals(element)) {
String propertyName = propElement.getAttribute("name");
Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
if (valueElement != null) {
Document document = valueElement.getOwnerDocument();
Object content = XMLUtils.readObjectFromXml(valueElement);
// This is data of the peusdo-bean
if ("beanData".equals(propertyName) && content instanceof String) {
try {
boolean needChange = false;
List<String> logList = new ArrayList<String>();
IonBean ionBean = new IonBean((String) content);
List<IonProperty> propertyList = new ArrayList<IonProperty>();
propertyList.addAll(ionBean.getProperties().values());
// Walk through properties
for (IonProperty ionProperty : propertyList) {
String ionPropertyName = ionProperty.getName();
String modeUpperCase = ionProperty.getMode().toUpperCase();
if (Mode.SOURCE.equals(Mode.valueOf(modeUpperCase))) {
MobileSmartSourceType msst = ionProperty.getSmartType();
String smartValue = msst.getSmartValue();
if (smartValue != null && !smartValue.isEmpty()) {
try {
MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
if (mss != null) {
boolean migrated = !smartValue.equals(mss.toJsonString());
if (migrated) {
msst.setSmartValue(mss.toJsonString());
ionBean.setPropertyValue(ionPropertyName, msst);
needChange = true;
logList.add("Done migration of \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
}
}
} catch (Exception e) {
if (e instanceof InvalidSourceException) {
Engine.logBeans.warn("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
} else {
Engine.logBeans.error("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
}
}
}
}
}
// Store new beandata property value
if (needChange) {
String beanData = ionBean.toBeanData();
Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, beanData);
propElement.replaceChild(newValueElement, valueElement);
hasChanged = true;
logList.forEach(s -> Engine.logBeans.warn(s));
}
} catch (Exception e) {
Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
}
} else // This is a MobileSmartSourceType property
if (content instanceof MobileSmartSourceType) {
MobileSmartSourceType msst = (MobileSmartSourceType) content;
// Property is in 'SRC' mode
if (Mode.SOURCE.equals(msst.getMode())) {
try {
String smartValue = msst.getSmartValue();
if (smartValue != null && !smartValue.isEmpty()) {
MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
if (mss != null) {
boolean migrated = !smartValue.equals(mss.toJsonString());
if (migrated) {
msst.setSmartValue(mss.toJsonString());
// Store new property value
Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, msst);
propElement.replaceChild(newValueElement, valueElement);
hasChanged = true;
Engine.logBeans.warn("Done migration of \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
}
}
}
} catch (Exception e) {
if (e instanceof InvalidSourceException) {
Engine.logBeans.warn("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
} else {
Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
}
}
}
}
}
}
}
} catch (Exception e) {
throw new EngineException("Unable to preconfigure the mobile uicomponent \"" + getName() + "\".", e);
}
}
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicComponent method getContributor.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement#getContributor()
*/
@Override
protected Contributor getContributor() {
Contributor contributor = super.getContributor();
return new Contributor() {
@Override
public Map<String, String> getActionTsFunctions() {
return contributor.getActionTsFunctions();
}
@Override
public Map<String, String> getActionTsImports() {
return contributor.getActionTsImports();
}
@Override
public Map<String, File> getCompBeanDir() {
Map<String, File> map = new HashMap<String, File>();
IonBean ionBean = getIonBean();
if (ionBean != null) {
String compName = ionBean.getName();
File dir = ComponentManager.getCompBeanDir(compName);
if (dir != null) {
map.put(compName, dir);
}
}
return map;
}
@Override
public Map<String, String> getModuleTsImports() {
return contributor.getModuleTsImports();
}
@Override
public Set<String> getModuleNgImports() {
return contributor.getModuleNgImports();
}
@Override
public Set<String> getModuleNgProviders() {
return contributor.getModuleNgProviders();
}
@Override
public Set<String> getModuleNgDeclarations() {
return contributor.getModuleNgDeclarations();
}
@Override
public Set<String> getModuleNgComponents() {
return contributor.getModuleNgComponents();
}
@Override
public Map<String, String> getPackageDependencies() {
return contributor.getPackageDependencies();
}
@Override
public Map<String, String> getConfigPlugins() {
return contributor.getConfigPlugins();
}
@Override
public Set<String> getModuleNgRoutes(String pageSegment) {
return contributor.getModuleNgRoutes(pageSegment);
}
};
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class NgxPickerComposite method getJsonModel.
private JSONObject getJsonModel(Map<String, Object> data, DatabaseObject databaseObject) throws Exception {
JSONObject jsonModel = new JSONObject();
Map<String, String> params;
DatabaseObject dbo;
String dataPath;
if (databaseObject == null) {
dbo = (DatabaseObject) data.get("databaseObject");
params = GenericUtils.cast(data.get("params"));
dataPath = (String) data.get("searchPath");
} else {
dbo = databaseObject;
params = new HashMap<String, String>();
dataPath = "";
}
if (dbo != null) {
// case of requestable
if (dbo instanceof RequestableObject) {
RequestableObject ro = (RequestableObject) dbo;
Project project = ro.getProject();
String responseEltName = ro.getXsdTypePrefix() + ro.getName() + "Response";
boolean isDocumentNode = JsonRoot.docNode.equals(project.getJsonRoot()) && dataPath.isEmpty();
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(project.getName());
XmlSchemaObject xso = SchemaMeta.getXmlSchemaObject(schema, ro);
if (xso != null) {
Document document = XmlSchemaUtils.getDomInstance(xso);
// System.out.println(XMLUtils.prettyPrintDOM(document));
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonObject = new JSONObject(jsonString);
String searchPath = "document." + responseEltName + ".response";
searchPath += isDocumentNode || !dataPath.startsWith(".document") ? dataPath : dataPath.replaceFirst("\\.document", "");
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = isDocumentNode ? new JSONObject().put("document", jsonOutput) : jsonOutput;
}
} else if (dbo instanceof DesignDocument) {
DesignDocument dd = (DesignDocument) dbo;
Connector connector = dd.getConnector();
String ddoc = params.get("ddoc");
String view = params.get("view");
String viewName = ddoc + "/" + view;
String includeDocs = params.get("include_docs");
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
((GetViewTransaction) transaction).setViewname(viewName);
((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
view_reduce.setValueOrNull(false);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalView, false);
}
}
});
} else // case of UIForm
if (dbo instanceof UIForm) {
// JSONObject jsonObject = new JSONObject("{\"controls\":{\"['area']\":{\"value\":\"\"}}}");
JSONObject jsonObject = new JSONObject(((UIForm) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UIACtionStack
if (dbo instanceof UIActionStack) {
JSONObject jsonObject = new JSONObject(((UIActionStack) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UIDynamicAction or UICustomAction
if (dbo instanceof IAction) {
JSONObject jsonObject = new JSONObject();
if (dbo instanceof UIDynamicAction) {
UIDynamicAction uida = (UIDynamicAction) dbo;
jsonObject = new JSONObject(uida.computeJsonModel());
IonBean ionBean = uida.getIonBean();
if (ionBean != null) {
String name = ionBean.getName();
if ("CallSequenceAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
DatabaseObject sequence = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (sequence != null) {
JSONObject targetJsonModel = getJsonModel(data, sequence);
if (jsonObject.has("out")) {
jsonObject.put("out", targetJsonModel);
}
}
} else if ("CallFullSyncAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
String verb = ionBean.getProperty("verb").getValue().toString();
Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
AbstractCouchDbTransaction act = null;
if ("all".equals(verb))
act = new AllDocsTransaction();
else if ("create".equals(verb))
act = new PutDatabaseTransaction();
else if ("destroy".equals(verb))
act = new DeleteDatabaseTransaction();
else if ("get".equals(verb))
act = new GetDocumentTransaction();
else if ("delete".equals(verb))
act = new DeleteDocumentTransaction();
else if ("delete_attachment".equals(verb))
act = new DeleteDocumentAttachmentTransaction();
else if ("post".equals(verb))
act = new PostDocumentTransaction();
else if ("put_attachment".equals(verb))
act = new PutDocumentAttachmentTransaction();
else if ("replicate_push".equals(verb))
act = new PostReplicateTransaction();
else if ("reset".equals(verb))
act = new ResetDatabaseTransaction();
else if ("view".equals(verb))
act = new GetViewTransaction();
if (act != null) {
QName typeQName = act.getComplexTypeAffectation();
XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
cleanJsonModel(jsonOutput);
jsonOutput.remove("_c8oMeta");
jsonOutput.remove("error");
jsonOutput.remove("reason");
if (jsonObject.has("out")) {
jsonObject.put("out", jsonOutput);
}
}
}
} else if ("FullSyncGetAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
String docid = ionBean.getProperty("_id").getValue().toString();
Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalDocument);
Variable var_docid = ((GetDocumentTransaction) transaction).getVariable(CouchParam.docid.param());
var_docid.setValueOrNull(docid);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalDocument, false);
}
}
});
}
} else if ("FullSyncViewAction".equals(name)) {
String fsview = ionBean.getProperty("fsview").getValue().toString();
String includeDocs = ionBean.getProperty("include_docs").getValue().toString();
String reduce = ionBean.getProperty("reduce").getValue().toString();
String qname = fsview.substring(0, fsview.lastIndexOf('.'));
DesignDocument dd = (DesignDocument) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
Connector connector = dd.getConnector();
String viewName = dd.getName() + "/" + fsview.substring(fsview.lastIndexOf('.') + 1);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
((GetViewTransaction) transaction).setViewname(viewName);
((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
view_reduce.setValueOrNull(reduce);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalView, false);
}
}
});
} else if (name.startsWith("FullSync")) {
if (ionBean.getProperty("requestable") != null) {
String qname = ionBean.getProperty("requestable").getValue().toString();
DatabaseObject connector = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
AbstractCouchDbTransaction act = null;
if ("FullSyncDeleteAction".equals(name))
act = new DeleteDocumentTransaction();
else if ("FullSyncDeleteAttachmentAction".equals(name))
act = new DeleteDocumentAttachmentTransaction();
else if ("FullSyncPostAction".equals(name))
act = new PostDocumentTransaction();
else if ("FullSyncPutAttachmentAction".equals(name))
act = new PutDocumentAttachmentTransaction();
if (act != null) {
QName typeQName = act.getComplexTypeAffectation();
XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
cleanJsonModel(jsonOutput);
jsonOutput.remove("_c8oMeta");
jsonOutput.remove("error");
jsonOutput.remove("reason");
if (jsonObject.has("out")) {
jsonObject.put("out", jsonOutput);
}
}
}
}
}
}
} else if (dbo instanceof UICustomAction) {
jsonObject = new JSONObject(((UICustomAction) dbo).computeJsonModel());
}
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UISharedComponent
if (dbo instanceof UISharedComponent) {
JSONObject jsonObject = new JSONObject(((UISharedComponent) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of ApplicationComponent
if (dbo instanceof ApplicationComponent) {
String json = params.get("json");
jsonModel = new JSONObject(json);
} else // should not happened
{
throw new Exception("DatabaseObject " + dbo.getClass().getName() + " not supported!");
}
}
return jsonModel;
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class NgxComponentImportVariablesAction method selectionChanged.
public void selectionChanged(IAction action, ISelection selection) {
try {
boolean enable = false;
super.selectionChanged(action, selection);
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
TreeObject treeObject = (TreeObject) structuredSelection.getFirstElement();
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject dbo = (DatabaseObject) treeObject.getObject();
if (dbo instanceof UIDynamicAction) {
IonBean ionBean = ((UIDynamicAction) dbo).getIonBean();
if (ionBean != null) {
String beanName = ionBean.getName();
enable = beanName.equals("CallSequenceAction") || beanName.equals("InvokeAction");
if (enable) {
String text = beanName.equals("CallSequenceAction") ? "Import variables from the targeted sequence" : "Import variables from the targeted shared action";
action.setText(text);
}
}
} else if (dbo instanceof UIUseShared) {
enable = true;
action.setText("Import variables from the targeted shared component");
}
}
action.setEnabled(enable);
} catch (Exception e) {
}
}
Aggregations