Search in sources :

Example 36 with Transaction

use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.

the class AbstractStubAction method run.

@Override
public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            if ((treeObject != null) && (treeObject instanceof SequenceTreeObject)) {
                SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject;
                Sequence sequence = sequenceTreeObject.getObject();
                File stubDir = new File(sequence.getProject().getDirPath() + "/stubs");
                stubDir.mkdirs();
                File stubFile = new File(stubDir, sequence.getName() + ".xml");
                Document dom = getXML(treeObject);
                writeStub(dom, stubFile);
            } else if ((treeObject != null) && (treeObject instanceof TransactionTreeObject)) {
                TransactionTreeObject transactionTreeObject = (TransactionTreeObject) treeObject;
                Transaction transaction = transactionTreeObject.getObject();
                File stubDir = new File(transaction.getProject().getDirPath() + "/stubs");
                stubDir.mkdirs();
                File stubFile = new File(stubDir, transaction.getParent().getName() + "." + transaction.getName() + ".xml");
                Document dom = getXML(treeObject);
                writeStub(dom, stubFile);
            }
        }
    } catch (NoSuchElementException e) {
        ConvertigoPlugin.logException(e, "No previous XML file found");
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected sequence!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) Document(org.w3c.dom.Document) Shell(org.eclipse.swt.widgets.Shell) Transaction(com.twinsoft.convertigo.beans.core.Transaction) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException) Display(org.eclipse.swt.widgets.Display)

Example 37 with Transaction

use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.

the class CreateEmptyStubAction method getXML.

public Document getXML(TreeObject treeObject) throws Exception {
    Document dom = XMLUtils.createDom("java");
    Element documentElement = (Element) dom.createElement("document");
    Object requestable = treeObject.getObject();
    if (requestable instanceof Transaction) {
        Transaction transaction = (Transaction) requestable;
        documentElement.setAttribute("connector", transaction.getParent().getName());
        documentElement.setAttribute("fromcache", "false");
        documentElement.setAttribute("generated", Calendar.getInstance(Locale.getDefault()).getTime().toString());
        documentElement.setAttribute("project", transaction.getProject().getName());
        documentElement.setAttribute("sequence", "");
        documentElement.setAttribute("transaction", transaction.getName());
    } else if (requestable instanceof Sequence) {
        Sequence sequence = (Sequence) requestable;
        documentElement.setAttribute("connector", "");
        documentElement.setAttribute("fromcache", "false");
        documentElement.setAttribute("generated", Calendar.getInstance(Locale.getDefault()).getTime().toString());
        documentElement.setAttribute("project", sequence.getProject().getName());
        documentElement.setAttribute("sequence", sequence.getName());
        documentElement.setAttribute("transaction", "");
    }
    dom.appendChild(documentElement);
    return dom;
}
Also used : Transaction(com.twinsoft.convertigo.beans.core.Transaction) Element(org.w3c.dom.Element) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Document(org.w3c.dom.Document)

Example 38 with Transaction

use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.

the class ClipboardManager method cutAndPaste.

public void cutAndPaste(final DatabaseObject object, DatabaseObject parentDatabaseObject) throws ConvertigoException {
    // Verifying if a sheet with the same browser does not already exist
    if (object instanceof Sheet) {
        String browser = ((Sheet) object).getBrowser();
        Sheet sheet = null;
        if (parentDatabaseObject instanceof ScreenClass) {
            sheet = ((ScreenClass) parentDatabaseObject).getLocalSheet(browser);
        } else if (parentDatabaseObject instanceof RequestableObject) {
            sheet = ((RequestableObject) parentDatabaseObject).getSheet(browser);
        }
        if (sheet != null) {
            throw new EngineException("You cannot cut and paste the sheet because a sheet is already defined for the browser \"" + browser + "\" in the screen class \"" + parentDatabaseObject.getName() + "\".");
        }
    }
    if (object instanceof Step) {
        if (object instanceof ThenStep) {
            throw new EngineException("You cannot cut the \"Then\" step");
        }
        if (object instanceof ElseStep) {
            throw new EngineException("You cannot cut the \"Else\" step");
        }
    }
    if (object instanceof Statement) {
        if (object instanceof ThenStatement)
            throw new EngineException("You cannot cut the \"Then\" statement");
        if (object instanceof ElseStatement)
            throw new EngineException("You cannot cut the \"Else\" statement");
    }
    // Verify object is accepted for paste
    if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
        throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
    }
    if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    }
    // Verify if a child object with same name exist
    boolean bContinue = true;
    boolean bIncName = false;
    String dboName = object.getName();
    while (bContinue) {
        try {
            if (bIncName) {
                dboName = DatabaseObject.incrementName(dboName);
                object.setName(dboName);
            }
            new WalkHelper() {

                boolean root = true;

                boolean find = false;

                @Override
                protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                    boolean isInstance = dboClass.isInstance(object);
                    find |= isInstance;
                    return isInstance;
                }

                @Override
                protected void walk(DatabaseObject databaseObject) throws Exception {
                    if (root) {
                        root = false;
                        if (databaseObject instanceof Project) {
                            if (object instanceof Connector && ((Connector) object).isDefault) {
                                throw new EngineException("You cannot cut the default connector to another project");
                            }
                        } else if (databaseObject instanceof Connector) {
                            if (object instanceof ScreenClass) {
                                throw new EngineException("You cannot cut the default screen class to another connector");
                            } else if (object instanceof Transaction && ((Transaction) object).isDefault) {
                                throw new EngineException("You cannot cut the default transaction to another connector");
                            }
                        } else if (databaseObject instanceof ScreenClass) {
                            if (object instanceof Criteria && databaseObject.getParent() instanceof Connector) {
                                throw new EngineException("You cannot cut the criterion of default screen class");
                            }
                        } else if (databaseObject instanceof MobileObject) {
                            if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
                                if (object instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                                    com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(object);
                                    if (pc.isRoot) {
                                        throw new EngineException("You cannot cut the root page to another application");
                                    }
                                }
                            } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
                                if (object instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                                    com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(object);
                                    if (pc.isRoot) {
                                        throw new EngineException("You cannot cut the root page to another application");
                                    }
                                }
                            }
                        }
                        super.walk(databaseObject);
                        if (!find) {
                            throw new EngineException("You cannot cut and paste to a " + databaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
                        }
                    } else {
                        if (object != databaseObject && object.getName().equalsIgnoreCase(databaseObject.getName())) {
                            throw new ObjectWithSameNameException("Unable to cut the object because an object with the same name already exists in target.");
                        }
                    }
                }
            }.init(parentDatabaseObject);
            bContinue = false;
        } catch (ObjectWithSameNameException e) {
            bIncName = true;
        } catch (EngineException e) {
            throw e;
        } catch (Exception e) {
            throw new EngineException("Exception in cutAndPaste", e);
        }
    }
    move(object, parentDatabaseObject);
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Project(com.twinsoft.convertigo.beans.core.Project) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Example 39 with Transaction

use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.

the class ClipboardManager method appendDndData.

private void appendDndData(Element element, DatabaseObject databaseObject) {
    Element dnd = clipboardDocument.createElement("dnd");
    Element e;
    try {
        if (databaseObject instanceof Sequence) {
            Sequence sequence = (Sequence) databaseObject;
            e = clipboardDocument.createElement("project");
            e.setAttribute("name", sequence.getProject().getName());
            dnd.appendChild(e);
        } else if (databaseObject instanceof Transaction) {
            Transaction transaction = (Transaction) databaseObject;
            e = clipboardDocument.createElement("project");
            e.setAttribute("name", transaction.getProject().getName());
            dnd.appendChild(e);
            e = clipboardDocument.createElement("connector");
            e.setAttribute("name", transaction.getConnector().getName());
            dnd.appendChild(e);
        } else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
            com.twinsoft.convertigo.beans.mobile.components.UIComponent uic = GenericUtils.cast(databaseObject);
            e = clipboardDocument.createElement("project");
            e.setAttribute("name", uic.getProject().getName());
            dnd.appendChild(e);
            e = clipboardDocument.createElement("mobileapplication");
            e.setAttribute("name", uic.getApplication().getParent().getName());
            dnd.appendChild(e);
            e = clipboardDocument.createElement("application");
            e.setAttribute("name", uic.getApplication().getName());
            dnd.appendChild(e);
        } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
            com.twinsoft.convertigo.beans.ngx.components.UIComponent uic = GenericUtils.cast(databaseObject);
            e = clipboardDocument.createElement("project");
            e.setAttribute("name", uic.getProject().getName());
            dnd.appendChild(e);
            e = clipboardDocument.createElement("mobileapplication");
            e.setAttribute("name", uic.getApplication().getParent().getName());
            dnd.appendChild(e);
            e = clipboardDocument.createElement("application");
            e.setAttribute("name", uic.getApplication().getName());
            dnd.appendChild(e);
        }
    } catch (Exception ex) {
    }
    element.appendChild(dnd);
}
Also used : Element(org.w3c.dom.Element) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction)

Example 40 with Transaction

use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.

the class ConnectorTreeObject method handlesBeanNameChanged.

protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
    DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
    DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    Connector connector = this.getObject();
    if (databaseObject instanceof Transaction) {
        Transaction transaction = (Transaction) databaseObject;
        if (transaction.getConnector().equals(connector)) {
            if (connector.getEndTransactionName().equals(oldValue)) {
                connector.setEndTransactionName((String) newValue);
                try {
                    getProjectExplorerView().refreshTreeObject(this);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not refresh in tree Connector \"" + databaseObject.getName() + "\" !");
                }
            }
        }
    } else if (databaseObject instanceof JsonIndex && connector.equals(databaseObject.getParent())) {
        CouchDbManager.syncDocument(connector);
    }
    // Case of this connector rename : update all transaction schemas
    if (treeObject.equals(this)) {
        String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
        String oldPath = path + "/" + (String) oldValue;
        String newPath = path + "/" + (String) newValue;
        IFolder folder = getProjectTreeObject().getFolder(oldPath);
        try {
            folder.getParent().refreshLocal(IResource.DEPTH_ONE, null);
            if (folder.exists()) {
                // rename folder (xsd/internal/connector)
                folder.move(new Path((String) newValue), true, null);
                // make replacements in schema file
                List<Replacement> replacements = new ArrayList<Replacement>();
                replacements.add(new Replacement((String) oldValue + "__", (String) newValue + "__"));
                IFolder newFolder = folder.getParent().getFolder(new Path((String) newValue));
                for (Transaction transaction : getObject().getTransactionsList()) {
                    IFile file = newFolder.getFile(new Path(transaction.getName() + ".xsd"));
                    if (file.exists()) {
                        String filePath = file.getLocation().makeAbsolute().toString();
                        try {
                            ProjectUtils.makeReplacementsInFile(replacements, filePath);
                        } catch (Exception e) {
                            ConvertigoPlugin.logWarning(e, "Could rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + filePath + "\" !");
                        }
                    }
                }
                // refresh folder
                folder.refreshLocal(IResource.DEPTH_ONE, null);
                Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
            }
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not rename folder from \"" + oldPath + "\" to \"" + newPath + "\" !");
        }
        if (connector instanceof CouchDbConnector) {
            CouchDbManager.syncDocument(connector);
            try {
                getProjectExplorerView().reloadTreeObject(this);
            } catch (Exception e) {
                ConvertigoPlugin.logWarning(e, "Could not reload connector \"" + connector.getName() + "\" in tree !");
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Connector(com.twinsoft.convertigo.beans.core.Connector) SapJcoConnector(com.twinsoft.convertigo.beans.connectors.SapJcoConnector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) Replacement(com.twinsoft.convertigo.engine.util.Replacement) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JsonIndex(com.twinsoft.convertigo.beans.couchdb.JsonIndex) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

Transaction (com.twinsoft.convertigo.beans.core.Transaction)67 Connector (com.twinsoft.convertigo.beans.core.Connector)43 Sequence (com.twinsoft.convertigo.beans.core.Sequence)29 EngineException (com.twinsoft.convertigo.engine.EngineException)27 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)24 Project (com.twinsoft.convertigo.beans.core.Project)23 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)21 Step (com.twinsoft.convertigo.beans.core.Step)17 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)16 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)16 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)15 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)15 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)13 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)13 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)12 Statement (com.twinsoft.convertigo.beans.core.Statement)12 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)12 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)12 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)12 JavelinTransaction (com.twinsoft.convertigo.beans.transactions.JavelinTransaction)12