Search in sources :

Example 11 with FullSyncConnector

use of com.twinsoft.convertigo.beans.connectors.FullSyncConnector in project convertigo by convertigo.

the class ObjectInfoWizardPage method createControl.

public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    layout.verticalSpacing = 9;
    Label label = new Label(container, SWT.NULL);
    label.setText("&Name:");
    beanName = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    beanName.setLayoutData(gd);
    beanName.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            dialogChanged(false);
        }
    });
    if (parentObject instanceof CouchDbConnector || parentObject instanceof FullSyncConnector) {
        couchVariablesComposite = new CouchVariablesComposite(container, SWT.V_SCROLL);
        GridData couchVarData = new GridData(GridData.FILL_BOTH);
        couchVarData.horizontalSpan = 2;
        couchVariablesComposite.setLayoutData(couchVarData);
    } else {
        tree = new Tree(container, SWT.SINGLE | SWT.BORDER);
        tree.setHeaderVisible(false);
        GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        gridData.verticalSpan = 20;
        gridData.horizontalSpan = 2;
        tree.setLayoutData(gridData);
        tree.addListener(SWT.Selection, new Listener() {

            public void handleEvent(final Event event) {
                TreeItem item = (TreeItem) event.item;
                treeItemName = item.getText();
                String suffix = getBeanName().endsWith(ScHandlerStatement.EVENT_ENTRY_HANDLER) ? ScHandlerStatement.EVENT_ENTRY_HANDLER : getBeanName().endsWith(ScHandlerStatement.EVENT_EXIT_HANDLER) ? ScHandlerStatement.EVENT_EXIT_HANDLER : "";
                setBeanName("on" + treeItemName + suffix);
                dialogChanged(true);
            }
        });
        tree.setVisible(false);
    }
    initialize();
    dialogChanged(true);
    setControl(container);
}
Also used : CouchVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) CouchVariablesComposite(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent)

Example 12 with FullSyncConnector

use of com.twinsoft.convertigo.beans.connectors.FullSyncConnector in project convertigo by convertigo.

the class ObjectExplorerWizardPage method createBean.

private void createBean() {
    BeanInfo bi = getCurrentSelectedBeanInfo();
    if (bi != null) {
        try {
            newBean = (DatabaseObject) bi.getBeanDescriptor().getBeanClass().getConstructor().newInstance();
            if (parentObject instanceof DatabaseObject) {
                newBean.setParent((DatabaseObject) parentObject);
            }
            if (xpath != null) {
                if (newBean instanceof IXPathable) {
                    ((IXPathable) newBean).setXpath(xpath);
                }
                // case we create an "javascriptable" statement
                if (newBean instanceof XpathableStatement) {
                    ((XpathableStatement) newBean).setPureXpath(xpath);
                }
            }
            // case we create a javelinConnector
            if (newBean instanceof JavelinConnector) {
                ((JavelinConnector) newBean).setEmulatorTechnology(com.twinsoft.api.Session.AS400);
                ((JavelinConnector) newBean).emulatorID = ((JavelinConnector) newBean).findEmulatorId();
                ((JavelinConnector) newBean).setServiceCode(",DIR|localhost:23");
            }
            if (newBean instanceof FullSyncConnector && parentObject instanceof Project) {
                newBean.setName(((Project) parentObject).getName().toLowerCase() + "_fullsync");
            }
        } catch (Exception e) {
            newBean = null;
        }
    }
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Project(com.twinsoft.convertigo.beans.core.Project) IXPathable(com.twinsoft.convertigo.beans.core.IXPathable) BeanInfo(java.beans.BeanInfo) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) EngineException(com.twinsoft.convertigo.engine.EngineException) XpathableStatement(com.twinsoft.convertigo.beans.statements.XpathableStatement)

Example 13 with FullSyncConnector

use of com.twinsoft.convertigo.beans.connectors.FullSyncConnector in project convertigo by convertigo.

the class CreateDbo method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String qname = request.getParameter("qname");
    String folderType = request.getParameter("folderType");
    String beanClassNameToCreate = request.getParameter("beanClass");
    DatabaseObject parentDbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
    Class<? extends DatabaseObject> beanClassToCreate = GenericUtils.cast(Class.forName(beanClassNameToCreate));
    Class<? extends DatabaseObject> databaseObjectClass = Get.folderNameToBeanClass.get(folderType);
    Element root = document.getDocumentElement();
    // Before add, we musht check if we can add it
    boolean canCreate = DatabaseObjectsManager.acceptDatabaseObjects(parentDbo, beanClassToCreate, databaseObjectClass);
    if (canCreate) {
        DatabaseObject newBean = (DatabaseObject) Class.forName(beanClassNameToCreate).getConstructor().newInstance();
        try {
            String beanName = newBean.getName();
            // The name of the FullSyncConnector needs to in be lower case
            if (newBean instanceof FullSyncConnector) {
                beanName = beanName.toLowerCase();
            }
            // Compute new name
            newBean.setName(newBean.getChildBeanName(parentDbo.getDatabaseObjectChildren(), beanName, true));
            // If the new bean has to be inserted at a specific position
            if (parentDbo instanceof IContainerOrdered) {
                String afterPriority = request.getParameter("afterPriority");
                Long after = null;
                try {
                    after = Long.valueOf(afterPriority);
                } catch (NumberFormatException e) {
                    after = null;
                }
                IContainerOrdered containerOrdered = (IContainerOrdered) parentDbo;
                containerOrdered.add(newBean, after);
            } else {
                // Need to create more things in case of Connectors
                if (newBean instanceof Connector) {
                    Connector.setupConnector(newBean);
                }
                parentDbo.add(newBean);
            }
            // Get new bean info
            Element response = document.createElement("response");
            GetChildren.getChildren(newBean.getQName(), response, 0);
            response.setAttribute("state", "success");
            root.appendChild(response);
        } catch (EngineException e) {
            throw e;
        }
    } else {
        throw new EngineException("You cannot create a " + beanClassNameToCreate + " object here.");
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) Element(org.w3c.dom.Element) IContainerOrdered(com.twinsoft.convertigo.beans.core.IContainerOrdered) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector)

Example 14 with FullSyncConnector

use of com.twinsoft.convertigo.beans.connectors.FullSyncConnector 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 15 with FullSyncConnector

use of com.twinsoft.convertigo.beans.connectors.FullSyncConnector 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

FullSyncConnector (com.twinsoft.convertigo.beans.connectors.FullSyncConnector)15 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)8 Project (com.twinsoft.convertigo.beans.core.Project)8 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)8 Sequence (com.twinsoft.convertigo.beans.core.Sequence)7 EngineException (com.twinsoft.convertigo.engine.EngineException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 JSONException (org.codehaus.jettison.json.JSONException)5 Connector (com.twinsoft.convertigo.beans.core.Connector)4 CoreException (org.eclipse.core.runtime.CoreException)4 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)3 CouchVariablesComposite (com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesComposite)3 TreeObjectEvent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)3 ArrayList (java.util.ArrayList)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3