Search in sources :

Example 11 with DesignDocument

use of com.twinsoft.convertigo.beans.couchdb.DesignDocument in project convertigo by convertigo.

the class NgxPickerContentProvider method addFsObjects.

private void addFsObjects(Map<String, Set<String>> map, TVObject tvd, Object object, boolean isReferenced) {
    if (object != null) {
        if (object instanceof Project) {
            Project project = (Project) object;
            for (Connector c : project.getConnectorsList()) {
                if (c instanceof FullSyncConnector) {
                    String label = isReferenced ? c.getQName() : c.getName();
                    TVObject tvc = tvd.add(new TVObject(label));
                    for (Document d : c.getDocumentsList()) {
                        if (d instanceof DesignDocument) {
                            TVObject tdd = tvc.add(new TVObject(d.getName()));
                            JSONObject views = CouchKey.views.JSONObject(((DesignDocument) d).getJSONObject());
                            if (views != null) {
                                for (Iterator<String> it = GenericUtils.cast(views.keys()); it.hasNext(); ) {
                                    try {
                                        Set<String> infos = null;
                                        String view = it.next();
                                        String key = c.getQName() + "." + d.getName() + "." + view;
                                        TVObject tvv = tdd.add(new TVObject(view));
                                        SourceData sd = null;
                                        try {
                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "get"));
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        tvv.add(new TVObject("get", d, sd));
                                        infos = map.get(key + ".get");
                                        if (infos == null) {
                                            infos = map.get(c.getQName() + ".get");
                                        }
                                        if (infos != null) {
                                            for (String info : infos) {
                                                try {
                                                    JSONObject jsonInfo = new JSONObject(info);
                                                    boolean includeDocs = false;
                                                    if (jsonInfo.has("include_docs")) {
                                                        includeDocs = Boolean.valueOf(jsonInfo.getString("include_docs")).booleanValue();
                                                    }
                                                    if (jsonInfo.has("marker")) {
                                                        String marker = jsonInfo.getString("marker");
                                                        if (!marker.isEmpty()) {
                                                            String name = "get" + "#" + marker;
                                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "get").put("marker", marker).put("includeDocs", includeDocs));
                                                            tvv.add(new TVObject(name, d, sd, jsonInfo));
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                        try {
                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "view"));
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        tvv.add(new TVObject("view", d, sd));
                                        infos = map.get(key + ".view");
                                        if (infos != null) {
                                            for (String info : infos) {
                                                try {
                                                    JSONObject jsonInfo = new JSONObject(info);
                                                    boolean includeDocs = false;
                                                    if (jsonInfo.has("include_docs")) {
                                                        includeDocs = Boolean.valueOf(jsonInfo.getString("include_docs")).booleanValue();
                                                    }
                                                    if (jsonInfo.has("marker")) {
                                                        String marker = jsonInfo.getString("marker");
                                                        if (!marker.isEmpty()) {
                                                            String name = "view" + "#" + marker;
                                                            sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "view").put("marker", marker).put("includeDocs", includeDocs));
                                                            tvv.add(new TVObject(name, d, sd, jsonInfo));
                                                        }
                                                    }
                                                } catch (JSONException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) JSONException(org.codehaus.jettison.json.JSONException) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) Document(com.twinsoft.convertigo.beans.core.Document) SourceData(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource.SourceData) JSONException(org.codehaus.jettison.json.JSONException) Project(com.twinsoft.convertigo.beans.core.Project) JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument)

Example 12 with DesignDocument

use of com.twinsoft.convertigo.beans.couchdb.DesignDocument in project convertigo by convertigo.

the class DesignDocumentViewTreeObject method toXml.

@Override
public Element toXml(Document document) {
    DesignDocument ddoc = getParentDesignTreeObject().getObject();
    ViewObject view = getObject();
    String qname = ddoc.getQName() + "." + view.getName();
    Element element = document.createElement("view");
    element.setAttribute("classname", getClass().getName());
    JSONObject jsondata = new JSONObject();
    try {
        jsondata.put("name", view.getName());
        jsondata.put("value", view.getJSONObject());
        jsondata.put("qname", qname);
    } catch (JSONException e) {
    }
    CDATASection cDATASection = document.createCDATASection(jsondata.toString());
    element.appendChild(cDATASection);
    return element;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) JSONException(org.codehaus.jettison.json.JSONException) ViewObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject.ViewObject)

Example 13 with DesignDocument

use of com.twinsoft.convertigo.beans.couchdb.DesignDocument in project convertigo by convertigo.

the class DesignDocumentTreeObject method hasBeenModified.

@Override
public synchronized void hasBeenModified() {
    JSONObject filters = new JSONObject();
    for (TreeObject to : fFilters.getChildren()) {
        DesignDocumentFilterTreeObject ddfto = (DesignDocumentFilterTreeObject) to;
        FilterObject filterObject = ddfto.getObject();
        try {
            filters.put(filterObject.name, filterObject.function);
        } catch (JSONException e) {
        // TODO Auto-generated catch block
        }
    }
    JSONObject updates = new JSONObject();
    for (TreeObject to : fUpdates.getChildren()) {
        DesignDocumentUpdateTreeObject dduto = (DesignDocumentUpdateTreeObject) to;
        UpdateObject updateObject = dduto.getObject();
        try {
            updates.put(updateObject.name, updateObject.function);
        } catch (JSONException e) {
        // TODO Auto-generated catch block
        }
    }
    JSONObject views = new JSONObject();
    for (TreeObject to : fViews.getChildren()) {
        DesignDocumentViewTreeObject ddvto = (DesignDocumentViewTreeObject) to;
        ViewObject viewObject = ddvto.getObject();
        try {
            views.put(viewObject.name, viewObject.getJSONObject());
        } catch (JSONException e) {
        // TODO Auto-generated catch block
        }
    }
    String validatefun = null;
    if (fValidate.hasChildren()) {
        DesignDocumentValidateTreeObject ddvto = (DesignDocumentValidateTreeObject) fValidate.getChildren().get(0);
        validatefun = ddvto.getObject().function;
    }
    try {
        DesignDocument dd = getObject();
        JSONObject jso = dd.getJSONObject();
        CouchKey.filters.put(jso, filters);
        CouchKey.updates.put(jso, updates);
        CouchKey.views.put(jso, views);
        if (validatefun != null) {
            CouchKey.validate_doc_update.put(jso, validatefun);
        } else {
            CouchKey.validate_doc_update.remove(jso);
        }
        dd.hasChanged = true;
        hasBeenModified(true);
        syncDocument();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    }
    TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
    viewer.update(this, null);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) JSONException(org.codehaus.jettison.json.JSONException) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException) JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument)

Example 14 with DesignDocument

use of com.twinsoft.convertigo.beans.couchdb.DesignDocument in project convertigo by convertigo.

the class DesignDocumentTreeObject method syncDocument.

private void syncDocument() {
    try {
        DesignDocument dd = getObject();
        JSONObject jso = dd.getJSONObject();
        if (CouchKey._id.has(jso)) {
            CouchDbConnector couchDbConnector = dd.getConnector();
            lastRev = CouchDbManager.syncDocument(couchDbConnector.getCouchClient(), couchDbConnector.getDatabaseName(), jso.toString());
        }
    } catch (Throwable t) {
        ConvertigoPlugin.logException(t, "Failed to syncDocument");
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector)

Example 15 with DesignDocument

use of com.twinsoft.convertigo.beans.couchdb.DesignDocument in project convertigo by convertigo.

the class NgxPickerComposite method lookupModelData.

private Map<String, Object> lookupModelData(TVObject tvObject) {
    Map<String, Object> data = new HashMap<String, Object>();
    Map<String, String> params = new HashMap<String, String>();
    DatabaseObject dbo = null;
    String searchPath = "";
    Object object = tvObject.getObject();
    JSONObject infos = tvObject.getInfos();
    if (object != null) {
        try {
            if (object instanceof RequestableObject) {
                dbo = (RequestableObject) object;
                searchPath = "";
            } else if (object instanceof DesignDocument) {
                dbo = (DesignDocument) object;
                DesignDocument dd = (DesignDocument) dbo;
                params.put("ddoc", dd.getName());
                params.put("view", tvObject.getParent().getName());
                params.put("include_docs", infos.has("include_docs") ? infos.getString("include_docs") : "false");
                searchPath = tvObject.getName().startsWith("get") ? ".rows.value" : "";
            } else if (object instanceof UIControlDirective) {
                dbo = (UIControlDirective) object;
                do {
                    UIControlDirective directive = (UIControlDirective) dbo;
                    String rootDboName = "";
                    if (directive.getPage() != null) {
                        rootDboName = directive.getPage().getName();
                    } else if (directive.getMenu() != null) {
                        rootDboName = directive.getMenu().getName();
                    }
                    MobileSmartSourceType msst = directive.getSourceSmartType();
                    MobileSmartSource mss = msst.getSmartSource();
                    if (mss != null) {
                        dbo = mss.getDatabaseObject(rootDboName);
                        params.putAll(mss.getParameters());
                        searchPath = mss.getModelPath().replaceAll("\\?\\.", ".") + searchPath;
                    } else {
                        dbo = null;
                    }
                } while (dbo != null && dbo instanceof UIControlDirective);
            } else if (object instanceof UIForm) {
                dbo = (UIForm) object;
                searchPath = "";
            } else if (object instanceof ApplicationComponent) {
                dbo = (ApplicationComponent) object;
                params.put("json", infos.toString());
                searchPath = "";
            } else if (object instanceof UIActionStack) {
                dbo = (UIActionStack) object;
                searchPath = "";
            } else if (object instanceof IAction) {
                if (object instanceof UIDynamicAction) {
                    dbo = (UIDynamicAction) object;
                    searchPath = "";
                } else if (object instanceof UICustomAction) {
                    dbo = (UICustomAction) object;
                    searchPath = "";
                }
            } else if (object instanceof UISharedComponent) {
                dbo = (UISharedComponent) object;
                searchPath = "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    data.put("databaseObject", dbo);
    data.put("params", params);
    data.put("searchPath", searchPath);
    return data;
}
Also used : RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) IAction(com.twinsoft.convertigo.beans.ngx.components.IAction) HashMap(java.util.HashMap) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) UIControlDirective(com.twinsoft.convertigo.beans.ngx.components.UIControlDirective) UIForm(com.twinsoft.convertigo.beans.ngx.components.UIForm) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) PartInitException(org.eclipse.ui.PartInitException) JSONException(org.codehaus.jettison.json.JSONException) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) MobileSmartSource(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) JSONObject(org.codehaus.jettison.json.JSONObject) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UICustomAction(com.twinsoft.convertigo.beans.ngx.components.UICustomAction) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) TVObject(com.twinsoft.convertigo.eclipse.views.mobile.NgxPickerContentProvider.TVObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject)

Aggregations

DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)17 JSONException (org.codehaus.jettison.json.JSONException)11 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)10 JSONObject (org.codehaus.jettison.json.JSONObject)10 FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)8 Project (com.twinsoft.convertigo.beans.core.Project)8 EngineException (com.twinsoft.convertigo.engine.EngineException)7 Sequence (com.twinsoft.convertigo.beans.core.Sequence)6 PartInitException (org.eclipse.ui.PartInitException)5 Connector (com.twinsoft.convertigo.beans.core.Connector)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)4 CoreException (org.eclipse.core.runtime.CoreException)4 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)3 MobileSmartSourceType (com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType)3 UIActionStack (com.twinsoft.convertigo.beans.mobile.components.UIActionStack)3 UIDynamicAction (com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction)3 UISharedComponent (com.twinsoft.convertigo.beans.mobile.components.UISharedComponent)3 Document (com.twinsoft.convertigo.beans.core.Document)2