Search in sources :

Example 11 with IonBean

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean in project convertigo by convertigo.

the class MobileComponentImportVariablesAction 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) {
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 12 with IonBean

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean in project convertigo by convertigo.

the class MobilePickerComposite 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;
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) Variable(com.twinsoft.convertigo.beans.core.Variable) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) UIForm(com.twinsoft.convertigo.beans.mobile.components.UIForm) GetDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetDocumentTransaction) PostDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostDocumentTransaction) Document(org.w3c.dom.Document) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ConnectorEditorInput(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorInput) DeleteDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDatabaseTransaction) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) AllDocsTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AllDocsTransaction) DeleteDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentTransaction) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PartInitException(org.eclipse.ui.PartInitException) PutDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDocumentAttachmentTransaction) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) IAction(com.twinsoft.convertigo.beans.mobile.components.IAction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) PutDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDatabaseTransaction) QName(javax.xml.namespace.QName) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) DeleteDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentAttachmentTransaction) ResetDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.ResetDatabaseTransaction) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) Project(com.twinsoft.convertigo.beans.core.Project) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) JSONObject(org.codehaus.jettison.json.JSONObject) DeleteDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentAttachmentTransaction) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) PutDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDatabaseTransaction) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) GetDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetDocumentTransaction) PostReplicateTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostReplicateTransaction) DeleteDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDocumentTransaction) PutDocumentAttachmentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PutDocumentAttachmentTransaction) DeleteDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.DeleteDatabaseTransaction) ResetDatabaseTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.ResetDatabaseTransaction) PostDocumentTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostDocumentTransaction) AllDocsTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AllDocsTransaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) PostReplicateTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.PostReplicateTransaction) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction)

Example 13 with IonBean

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean in project convertigo by convertigo.

the class BeansDoc method generateMobileComponentsMd.

private void generateMobileComponentsMd(File outputDirectory) {
    List<Component> grpBeans = ComponentManager.getComponentsByGroup();
    Map<String, IonBean> map = ComponentManager.getIonBeans();
    for (Component beanMB : grpBeans) {
        String grpName = beanMB.getGroup();
        String objName = beanMB.getName();
        String objLabel = beanMB.getLabel();
        String imgPath = beanMB.getImagePath();
        String imgPathNormalized = imgPath.replaceFirst("/com/twinsoft/convertigo/beans/", "");
        // We are changing it if the bean is not an IonBean just below
        String classPathNormalized = "ion_objects.json";
        String grpNameNormalized = grpName;
        Boolean isIonBean = false;
        // If it is we set isIonBean to true;
        for (Map.Entry<String, IonBean> ionbean : map.entrySet()) {
            if (objName == ionbean.getKey()) {
                isIonBean = true;
            }
        }
        // If this bean is not an IonBean we simply add this class
        if (isIonBean == false) {
            classPathNormalized = "com.twinsoft.convertigo.beans.mobile.components.res." + objName;
        }
        if (!grpName.contains("Components")) {
            grpNameNormalized = grpName.concat(" Components");
        }
        grpNameNormalized = mbNormalize(grpNameNormalized);
        String objLabelNormalized = mbNormalize(objLabel);
        String path = "/mobile-application/components/" + grpNameNormalized + "/";
        String permalink = "reference-manual/convertigo-objects" + path + objLabelNormalized + "/";
        String metadesc = beanMB.getDescription();
        metadesc = metadesc.replaceAll("<[a-zA-Z]*>|<\\/[a-zA-Z]*>|<br\\/>", " ");
        metadesc = metadesc.replaceAll(":", " ");
        metadesc = metadesc.replaceAll("\\|", " ");
        if (metadesc.length() >= 150)
            metadesc = metadesc.substring(0, 150);
        StringBuilder sb = new StringBuilder();
        sb.append("---\n" + "layout: page\n" + "title: " + objLabel + "\n" + "sidebar: c8o_sidebar\n" + "permalink: " + permalink + "\n" + "metadesc: " + metadesc + "\n" + "ObjGroup: " + grpName + "\n" + "ObjCatName: " + grpNameNormalized + "\n" + "ObjName: " + objName + "\n" + "ObjClass: " + classPathNormalized + "\n" + "ObjIcon: /images/beans/" + imgPathNormalized + "\n" + "topnav: topnavobj" + "\n" + "---\n");
        String description = beanMB.getDescription();
        description = description.replaceAll("\\|", "<br/>\n");
        description = description.replaceAll("<br\\/>", "<br/>\n");
        description = description.replaceAll("Defines| Defines", "##### Defines");
        sb.append(description + "\n\n");
        // Prepare properties to create a markdown table
        String properties = beanMB.getPropertiesDescription();
        properties = properties.replaceAll("</i></br>", " | ");
        properties = properties.replaceAll("<ul>|</ul>", "");
        properties = properties.replaceAll("<li><i>", "");
        properties = properties.replaceAll("</li>", "\n");
        if (!properties.isEmpty()) {
            sb.append("Name | Description \n");
            sb.append("--- | ---\n");
            sb.append(properties + "\n");
        }
        String toWrite = sb.toString();
        if (!"\n".equals(System.lineSeparator())) {
            toWrite = toWrite.replace("\n", System.lineSeparator());
        }
        try (InputStream is = getClass().getResourceAsStream(imgPath)) {
            System.out.println("imgPath : " + imgPath);
            String imgPathModified = imgPath.replaceFirst(".*\\w\\/beans", "");
            FileUtils.copyInputStreamToFile(is, new File(imageDirectory, imgPathModified));
            System.out.println("Image generated at : " + imageDirectory + imgPathModified);
        } catch (Exception e) {
            System.out.println("Unable to copy the image file");
        }
        try {
            FileUtils.write(new File(outputDirectory, path + objLabelNormalized + ".md"), toWrite, "UTF-8");
            System.out.println("Generated md for : " + objLabel);
        } catch (IOException e) {
            System.out.println("Unable to write the file");
        }
    }
}
Also used : IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Component(com.twinsoft.convertigo.beans.mobile.components.dynamic.Component) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) File(java.io.File)

Example 14 with IonBean

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean in project convertigo by convertigo.

the class UIDynamicElement method initAttributes.

@Override
protected StringBuilder initAttributes() {
    StringBuilder attributes = super.initAttributes();
    IonBean ionBean = getIonBean();
    if (ionBean != null) {
        if (is("Tabs")) {
            attributes.append(" #c8oTabs");
        }
        String formControlVarName = getFormControlName();
        Map<String, String> vm = new HashMap<String, String>();
        for (IonProperty property : ionBean.getProperties().values()) {
            String name = property.getName();
            Object value = property.getValue();
            if (!value.equals(false)) {
                MobileSmartSourceType msst = property.getSmartType();
                String smartValue = msst.getValue();
                if (Mode.PLAIN.equals(msst.getMode())) {
                    if (property.getType().equalsIgnoreCase("string")) {
                        if (!isComposedValue(smartValue)) {
                            smartValue = "\'" + MobileSmartSourceType.escapeStringForTpl(smartValue) + "\'";
                        }
                    }
                }
                vm.put(name, smartValue);
            } else {
                vm.put(name, "null");
            }
        }
        StrSubstitutor sub = new StrSubstitutor(vm, "$[", "]");
        sub.setEnableSubstitutionInVariables(true);
        for (IonProperty property : ionBean.getProperties().values()) {
            String name = property.getName();
            String attr = property.getAttr();
            Object value = property.getValue();
            boolean isComposite = property.isComposite();
            // case value is set
            if (!value.equals(false)) {
                if (name.equals("AutoDisable")) {
                    UIForm form = getUIForm();
                    if (form != null) {
                        String formGroupName = form.getFormGroupName();
                        attributes.append(" [disabled]=\"!").append(formGroupName).append(".valid\"");
                    }
                } else {
                    if (name.equals("FormControlName") && formControlVarName.isEmpty()) {
                        continue;
                    }
                    if (attr.equals("[ngModel]")) {
                        String tagName = getTagName();
                        if (tagName.equals("ion-checkbox") || tagName.equals("ion-toggle")) {
                            attr = formControlVarName.isEmpty() ? "[checked]" : "[ngModel]";
                        } else if (tagName.equals("ion-datetime")) {
                            attr = formControlVarName.isEmpty() ? "value" : "[ngModel]";
                        }
                    }
                    String smartValue = property.getSmartValue();
                    smartValue = sub.replace(smartValue);
                    if (!isComposite) {
                        attributes.append(" ");
                        if (attr.isEmpty()) {
                            attributes.append(smartValue);
                        } else if (attr.indexOf("%%") != -1) {
                            attributes.append(attr.replaceFirst("%%", smartValue));
                        } else {
                            attributes.append(attr).append("=");
                            attributes.append("\"").append(smartValue).append("\"");
                        }
                    }
                }
            } else // case value is not set
            {
                if (!isComposite) {
                    if (attr.equals("[ngModel]")) {
                        String tagName = getTagName();
                        if (formControlVarName.isEmpty() || tagName.equals("ion-checkbox") || tagName.equals("ion-toggle")) {
                            continue;
                        } else {
                            attributes.append(" [ngModel]=\"null\"");
                        }
                    }
                }
            }
        }
    }
    return attributes;
}
Also used : StrSubstitutor(org.apache.commons.text.StrSubstitutor) IonProperty(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonProperty) HashMap(java.util.HashMap) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 15 with IonBean

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean in project convertigo by convertigo.

the class UIDynamicElement method getEventNames.

protected String[] getEventNames() {
    IonBean ionBean = getIonBean();
    String[] eventNames = new String[0];
    if (ionBean != null) {
        eventNames = ionBean.getEvents().keySet().toArray(new String[0]);
        Arrays.sort(eventNames);
    }
    return eventNames;
}
Also used : IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean)

Aggregations

IonBean (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean)22 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)10 IonProperty (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonProperty)8 JSONObject (org.codehaus.jettison.json.JSONObject)7 EngineException (com.twinsoft.convertigo.engine.EngineException)6 HashMap (java.util.HashMap)6 UIDynamicAction (com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction)4 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)4 File (java.io.File)4 JSONException (org.codehaus.jettison.json.JSONException)4 MobileSmartSourceType (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType)3 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)3 UICompVariable (com.twinsoft.convertigo.beans.mobile.components.UICompVariable)3 UIDynamicElement (com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement)3 UIUseShared (com.twinsoft.convertigo.beans.mobile.components.UIUseShared)3 Project (com.twinsoft.convertigo.beans.core.Project)2 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)2 UIComponent (com.twinsoft.convertigo.beans.mobile.components.UIComponent)2 UIControlVariable (com.twinsoft.convertigo.beans.mobile.components.UIControlVariable)2 UIDynamicInvoke (com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke)2