Search in sources :

Example 16 with DesignDocument

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

the class MobileSmartSource method getDatabaseObject.

public DatabaseObject getDatabaseObject(String rootDboName) {
    List<String> sourceData = getSources();
    String sourceInput = sourceData.size() > 0 ? sourceData.get(0) : null;
    if (sourceInput != null) {
        if (Filter.Action.equals(getFilter())) {
            Matcher m = actionPattern.matcher(sourceInput);
            if (m.find()) {
                String stack = m.group(1);
                try {
                    String p = stack.replaceFirst("stack\\[", "").replaceFirst("\\]", "");
                    // ignore quotes
                    p = p.substring(1, p.length() - 1);
                    long priority = Long.valueOf(p, 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Shared.equals(getFilter())) {
            Matcher m = sharedPattern.matcher(sourceInput);
            if (m.find()) {
                String shared = m.group(1);
                try {
                    long priority = Long.valueOf(shared.replaceFirst("params", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Iteration.equals(getFilter())) {
            Matcher m = directivePattern.matcher(sourceInput);
            if (m.find()) {
                String item = m.group(1);
                try {
                    long priority = Long.valueOf(item.replaceFirst("item", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Form.equals(getFilter())) {
            Matcher m = formPattern.matcher(sourceInput);
            if (m.find()) {
                String form = m.group(1);
                try {
                    long priority = Long.valueOf(form.replaceFirst("form", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Global.equals(getFilter())) {
            Matcher m = globalPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String projectName = getProjectName();
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    DatabaseObject dbo = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
                    return dbo;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Database.equals(getFilter())) {
            Matcher m = cafPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String name = m.group(1);
                    name = name.replaceFirst("fs://", "");
                    name = name.replaceFirst("\\.view", "");
                    name = name.replaceFirst("\\.get", "");
                    int i = name.indexOf('#');
                    if (i != -1) {
                        name = name.substring(0, i);
                    }
                    int index = name.indexOf('.');
                    String projectName = index != -1 ? name.substring(0, index) : getProjectName();
                    String dbName = index != -1 ? name.substring(index + 1) : name;
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    FullSyncConnector connector = (FullSyncConnector) project.getConnectorByName(dbName);
                    String documentName = getParameters().get("ddoc");
                    DesignDocument ddoc = (DesignDocument) connector.getDocumentByName(documentName);
                    return ddoc;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Sequence.equals(getFilter())) {
            Matcher m = cafPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String name = m.group(1);
                    int i = name.indexOf('#');
                    if (i != -1) {
                        name = name.substring(0, i);
                    }
                    int index = name.indexOf('.');
                    String projectName = index != -1 ? name.substring(0, index) : getProjectName();
                    projectName = projectName.isEmpty() ? getProjectName() : projectName;
                    String sequenceName = index != -1 ? name.substring(index + 1) : name;
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    Sequence sequence = project.getSequenceByName(sequenceName);
                    return sequence;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return null;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Matcher(java.util.regex.Matcher) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) Sequence(com.twinsoft.convertigo.beans.core.Sequence) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) JSONException(org.codehaus.jettison.json.JSONException)

Example 17 with DesignDocument

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

the class MobileSmartSource method getDatabaseObject.

public DatabaseObject getDatabaseObject(String rootDboName) {
    List<String> sourceData = getSources();
    String sourceInput = sourceData.size() > 0 ? sourceData.get(0) : null;
    if (sourceInput != null) {
        if (Filter.Action.equals(getFilter())) {
            Matcher m = actionPattern.matcher(sourceInput);
            if (m.find()) {
                String stack = m.group(1);
                try {
                    String p = stack.replaceFirst("stack\\[", "").replaceFirst("\\]", "");
                    // ignore quotes
                    p = p.substring(1, p.length() - 1);
                    long priority = Long.valueOf(p, 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Shared.equals(getFilter())) {
            Matcher m = sharedPattern.matcher(sourceInput);
            if (m.find()) {
                String shared = m.group(1);
                try {
                    long priority = Long.valueOf(shared.replaceFirst("params", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Iteration.equals(getFilter())) {
            Matcher m = directivePattern.matcher(sourceInput);
            if (m.find()) {
                String item = m.group(1);
                try {
                    long priority = Long.valueOf(item.replaceFirst("item", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Form.equals(getFilter())) {
            Matcher m = formPattern.matcher(sourceInput);
            if (m.find()) {
                String form = m.group(1);
                try {
                    long priority = Long.valueOf(form.replaceFirst("form", ""), 10);
                    return findDatabaseObject(rootDboName, priority);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Global.equals(getFilter())) {
            Matcher m = globalPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String projectName = getProjectName();
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    DatabaseObject dbo = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
                    return dbo;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Database.equals(getFilter())) {
            Matcher m = cafPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String name = m.group(1);
                    name = name.replaceFirst("fs://", "");
                    name = name.replaceFirst("\\.view", "");
                    name = name.replaceFirst("\\.get", "");
                    int i = name.indexOf('#');
                    if (i != -1) {
                        name = name.substring(0, i);
                    }
                    int index = name.indexOf('.');
                    String projectName = index != -1 ? name.substring(0, index) : getProjectName();
                    String dbName = index != -1 ? name.substring(index + 1) : name;
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    FullSyncConnector connector = (FullSyncConnector) project.getConnectorByName(dbName);
                    String documentName = getParameters().get("ddoc");
                    DesignDocument ddoc = (DesignDocument) connector.getDocumentByName(documentName);
                    return ddoc;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (Filter.Sequence.equals(getFilter())) {
            Matcher m = cafPattern.matcher(sourceInput);
            if (m.find()) {
                try {
                    String name = m.group(1);
                    int i = name.indexOf('#');
                    if (i != -1) {
                        name = name.substring(0, i);
                    }
                    int index = name.indexOf('.');
                    String projectName = index != -1 ? name.substring(0, index) : getProjectName();
                    projectName = projectName.isEmpty() ? getProjectName() : projectName;
                    String sequenceName = index != -1 ? name.substring(index + 1) : name;
                    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                    Sequence sequence = project.getSequenceByName(sequenceName);
                    return sequence;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return null;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Matcher(java.util.regex.Matcher) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) Sequence(com.twinsoft.convertigo.beans.core.Sequence) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) JSONException(org.codehaus.jettison.json.JSONException)

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