Search in sources :

Example 6 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class HtmlTransaction method addStatement.

public void addStatement(Statement statement) throws EngineException {
    checkSubLoaded();
    // Do not use getChildBeanName here because of ScHandlerStatement!!
    String newDatabaseObjectName = statement.getName();
    for (Statement st : vStatements) {
        if (newDatabaseObjectName.equals(st.getName())) {
            throw new ObjectWithSameNameException("Unable to add the statement \"" + newDatabaseObjectName + "\" to the html transaction class because a statement with the same name already exists.");
        }
    }
    vStatements.add(statement);
    // do not call super.add otherwise it will generate an exception
    statement.setParent(this);
    if (statement.priority != 0) {
        statement.priority = 0;
        statement.hasChanged = true;
    }
}
Also used : ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ContextAddTextNodeStatement(com.twinsoft.convertigo.beans.statements.ContextAddTextNodeStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement)

Example 7 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class TreeDropAdapter method paste.

public DatabaseObject paste(Node node, DatabaseObject parentDatabaseObject, boolean bChangeName) throws EngineException {
    Object object = ConvertigoPlugin.clipboardManagerDND.read(node);
    if (object instanceof DatabaseObject) {
        DatabaseObject databaseObject = (DatabaseObject) object;
        String dboName = databaseObject.getName();
        String name = null;
        boolean bContinue = true;
        int index = 0;
        while (bContinue) {
            if (bChangeName) {
                if (index == 0)
                    name = dboName;
                else
                    name = dboName + index;
                databaseObject.setName(name);
            }
            databaseObject.hasChanged = true;
            databaseObject.bNew = true;
            try {
                if (parentDatabaseObject != null)
                    parentDatabaseObject.add(databaseObject);
                bContinue = false;
            } catch (ObjectWithSameNameException owsne) {
                if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement))
                    throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
                if ((parentDatabaseObject instanceof Sequence) && (databaseObject instanceof Step))
                    throw new EngineException("Sequence already contains a step named \"" + name + "\".", owsne);
                // Silently ignore
                index++;
            }
        }
        NodeList childNodes = node.getChildNodes();
        int len = childNodes.getLength();
        Node childNode;
        String childNodeName;
        for (int i = 0; i < len; i++) {
            childNode = childNodes.item(i);
            if (childNode.getNodeType() != Node.ELEMENT_NODE)
                continue;
            childNodeName = childNode.getNodeName();
            if (!(childNodeName.equalsIgnoreCase("property")) && !(childNodeName.equalsIgnoreCase("handlers")) && !(childNodeName.equalsIgnoreCase("wsdltype")) && !(childNodeName.equalsIgnoreCase("docdata")) && !(childNodeName.equalsIgnoreCase("beandata")) && !(childNodeName.equalsIgnoreCase("dnd"))) {
                paste(childNode, databaseObject, bChangeName);
            }
        }
        // needed !
        databaseObject.isImporting = false;
        databaseObject.isSubLoaded = true;
        return databaseObject;
    }
    return null;
}
Also used : XpathableStatement(com.twinsoft.convertigo.beans.statements.XpathableStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) Step(com.twinsoft.convertigo.beans.core.Step) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject)

Example 8 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class TreeDropAdapter method performDrop.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
	 */
@Override
public boolean performDrop(Object data) {
    MobileBuilder mb = null;
    Engine.logStudio.info("---------------------- Drop started ----------------------");
    try {
        Object targetObject = getCurrentTarget();
        IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
        if (editorPart != null) {
            IEditorInput input = editorPart.getEditorInput();
            if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
                com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                mb = editorInput.getApplication().getProject().getMobileBuilder();
            }
            if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
                com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                mb = editorInput.getApplication().getProject().getMobileBuilder();
            }
        }
        // Handle objects copy or move with Drag and drop
        if (targetObject instanceof TreeObject) {
            TreeObject targetTreeObject = (TreeObject) targetObject;
            if (targetTreeObject != null) {
                ProjectExplorerView explorerView = targetTreeObject.getProjectExplorerView();
                Document document = null;
                try {
                    Shell shell = Display.getDefault().getActiveShell();
                    try {
                        // Try to parse text data into an XML document
                        String source = data.toString();
                        document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(source)));
                        if (mb != null) {
                            mb.prepareBatchBuild();
                        }
                        BatchOperationHelper.start();
                        boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
                        boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
                        TreeObject sourceObject = (TreeObject) getSelectedObject();
                        if (insertBefore || insertAfter) {
                            TreeParent targetTreeParent = ((TreeObject) targetObject).getParent();
                            if (sourceObject.getParent() != targetTreeParent) {
                                ProjectTreeObject prjTree = targetTreeParent.getProjectTreeObject();
                                String path = targetTreeParent.getPath();
                                ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeParent, true);
                                targetTreeParent = (TreeParent) explorerView.findTreeObjectByPath(prjTree, path);
                            }
                            explorerView.moveChildTo(targetTreeParent, sourceObject, targetTreeObject, insertBefore);
                        } else {
                            ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeObject, true);
                        }
                        BatchOperationHelper.stop();
                        return true;
                    } catch (SAXException sax) {
                        BatchOperationHelper.cancel();
                        if (mb != null) {
                            mb.prepareBatchBuild();
                        }
                        BatchOperationHelper.start();
                        // Parse failed probably because data was not XML but an XPATH String
                        // in this case, create DatabaseObjects of the correct Type according to the folder where the XPATH is dropped on
                        performDrop(data, explorerView, targetTreeObject);
                        BatchOperationHelper.stop();
                        return true;
                    }
                } catch (Exception e) {
                    BatchOperationHelper.cancel();
                    if (e instanceof ObjectWithSameNameException) {
                        document = null;
                    }
                    if (e instanceof InvalidOperationException) {
                        document = null;
                    }
                    // Case of unauthorized databaseObject paste
                    if (document != null) {
                        try {
                            if (!(targetTreeObject instanceof IPropertyTreeObject)) {
                                Element rootElement = document.getDocumentElement();
                                NodeList nodeList = rootElement.getChildNodes();
                                boolean unauthorized = false;
                                int len = nodeList.getLength();
                                Node node;
                                // case of folder, retrieve owner object
                                targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(targetTreeObject);
                                if (detail == DND.DROP_COPY) {
                                    for (int i = 0; i < len; i++) {
                                        node = (Node) nodeList.item(i);
                                        if (node.getNodeType() != Node.TEXT_NODE) {
                                            // Special objects paste
                                            if (!paste(node, targetTreeObject)) {
                                                // Real unauthorized databaseObject paste
                                                unauthorized = true;
                                            }
                                        }
                                    }
                                    reloadTreeObject(explorerView, targetTreeObject);
                                } else if (detail == DND.DROP_MOVE) {
                                    for (int i = 0; i < len; i++) {
                                        node = (Node) nodeList.item(i);
                                        if (node.getNodeType() != Node.TEXT_NODE) {
                                            // Special objects move
                                            if (!move(node, targetTreeObject)) {
                                                // Real unauthorized databaseObject move
                                                unauthorized = true;
                                            }
                                        }
                                    }
                                    reloadTreeObject(explorerView, targetTreeObject);
                                } else {
                                    // Real unauthorized databaseObject
                                    unauthorized = true;
                                }
                                if (unauthorized) {
                                    throw e;
                                }
                                return true;
                            }
                        } catch (Exception ex) {
                            ConvertigoPlugin.errorMessageBox(ex.getMessage());
                            return false;
                        }
                    } else {
                        ConvertigoPlugin.errorMessageBox(e.getMessage());
                        return false;
                    }
                }
            }
        }
        return false;
    } finally {
        Engine.logStudio.info("---------------------- Drop ended   ----------------------");
        BatchOperationHelper.cancel();
    }
}
Also used : InputSource(org.xml.sax.InputSource) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) Shell(org.eclipse.swt.widgets.Shell) StringReader(java.io.StringReader) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) NodeList(org.w3c.dom.NodeList) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IEditorInput(org.eclipse.ui.IEditorInput) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Example 9 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException 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 10 with ObjectWithSameNameException

use of com.twinsoft.convertigo.engine.ObjectWithSameNameException in project convertigo by convertigo.

the class HtmlConnectorDesignComposite method modelChanged.

public void modelChanged(HttpProxyEvent event) {
    if (!checkProxySource(event)) {
        return;
    }
    String requestString = event.getRequest();
    String responseString = event.getResponse();
    boolean https = event.isHttps();
    int status = Integer.parseInt(event.getStatus());
    // do not record client redirection
    if ((status == HttpStatus.SC_MOVED_TEMPORARILY) || (status == HttpStatus.SC_MOVED_PERMANENTLY) || (status == HttpStatus.SC_SEE_OTHER) || (status == HttpStatus.SC_TEMPORARY_REDIRECT)) {
        return;
    }
    /*if (requestString.indexOf(getServer()) == -1) {
			return;
		}*/
    Map<String, String> headers = parseResponseString(responseString);
    String contentType = headers.get(HeaderName.ContentType.value().toLowerCase());
    // record only text/html or null Content-Type ...
    if (contentType == null) {
        return;
    }
    if (MimeType.Html.is(contentType) && MimeType.Plain.is(contentType)) {
        return;
    }
    ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) Learning statement...");
    try {
        String url, method, handlerName, transactionName, statementName, scHandlerName;
        String normalizedScreenClassName, screenClassName;
        HtmlTransaction htmlTransaction = null;
        HTTPStatement httpStatement = null;
        HtmlScreenClass htmlScreenClass = null;
        HandlerStatement handlerStatement = null;
        ScHandlerStatement scHandlerStatement = null;
        // Document dom = null;
        // Log log = null;
        int size, index1;
        boolean bContinue;
        index1 = 0;
        bContinue = true;
        normalizedScreenClassName = "Unknown";
        htmlTransaction = (HtmlTransaction) htmlConnector.getLearningTransaction();
        synchronized (htmlConnector) {
            // dom = htmlConnector.getCurrentXmlDocument();
            htmlScreenClass = htmlConnector.getCurrentScreenClass();
        }
        screenClassName = htmlScreenClass.getName();
        normalizedScreenClassName = StringUtils.normalize(htmlScreenClass.getName());
        ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) current screen class is '" + screenClassName + "'");
        if (htmlTransaction != null) {
            transactionName = htmlTransaction.getName();
            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) creating new HTTPStatement");
            ConvertigoPlugin.logDebug2(requestString);
            httpStatement = parseRequestString(requestString);
            httpStatement.setHttps(https);
            httpStatement.setPort(https ? 443 : 80);
            method = httpStatement.getMethod().toLowerCase();
            // size = httpStatement.getVariablesDefinitionSize();
            size = httpStatement.numberOfVariables();
            url = httpStatement.getUrl(htmlConnector.isHttps(), htmlConnector.getServer(), htmlConnector.getPort());
            while (bContinue) {
                statementName = method + ((index1 == 0) ? " " : " " + index1) + " (" + url + " - " + size + ")";
                statementName = StringUtils.normalize(statementName);
                httpStatement.setName(statementName);
                httpStatement.hasChanged = true;
                httpStatement.bNew = true;
                if (htmlScreenClass == null) {
                    try {
                        httpStatement.priority = 0;
                        htmlTransaction.addStatement(httpStatement);
                        ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to default transaction '" + transactionName + "'");
                        fireObjectChanged(new CompositeEvent(htmlTransaction));
                        Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                        bContinue = false;
                    } catch (ObjectWithSameNameException owsne) {
                        index1++;
                    }
                } else {
                    if (htmlConnector.isAccumulating())
                        handlerName = "on" + normalizedScreenClassName + "Exit";
                    else
                        handlerName = "on" + normalizedScreenClassName + "Entry";
                    handlerStatement = htmlTransaction.getHandlerStatement(handlerName);
                    if (handlerStatement != null) {
                        try {
                            handlerStatement.addStatement(httpStatement);
                            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to handler '" + handlerName + "' of transaction '" + transactionName + "'");
                            fireObjectChanged(new CompositeEvent(handlerStatement));
                            Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                            bContinue = false;
                        } catch (ObjectWithSameNameException owsne) {
                            index1++;
                        }
                    } else {
                        try {
                            if (htmlConnector.isAccumulating())
                                scHandlerStatement = new ScExitHandlerStatement(normalizedScreenClassName);
                            else
                                scHandlerStatement = new ScEntryHandlerStatement(normalizedScreenClassName);
                            scHandlerName = scHandlerStatement.getName();
                            scHandlerStatement.setName(scHandlerName);
                            scHandlerStatement.hasChanged = true;
                            scHandlerStatement.bNew = true;
                            scHandlerStatement.priority = 0;
                            htmlTransaction.addStatement(scHandlerStatement);
                            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new ScExitHandlerStatement '" + handlerName + "' of transaction '" + transactionName + "'");
                            try {
                                scHandlerStatement.addStatement(httpStatement);
                                ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement '" + statementName + "' to ScExitHandlerStatement '" + handlerName + "'");
                                fireObjectChanged(new CompositeEvent(htmlTransaction));
                                Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                                bContinue = false;
                            } catch (ObjectWithSameNameException owsne) {
                                index1++;
                            }
                        }// Should not append
                         catch (ObjectWithSameNameException owsne) {
                            throw new EngineException(owsne.getMessage());
                        }
                    }
                }
            }
        } else {
            throw new EngineException("Found none learning transaction");
        }
    } catch (EngineException e) {
        ConvertigoPlugin.logException(e, "An exception occured while learning");
    }
}
Also used : HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Aggregations

ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)14 EngineException (com.twinsoft.convertigo.engine.EngineException)13 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)11 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)6 Statement (com.twinsoft.convertigo.beans.core.Statement)5 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)5 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)5 Project (com.twinsoft.convertigo.beans.core.Project)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)4 IOException (java.io.IOException)4 Connector (com.twinsoft.convertigo.beans.core.Connector)3 Criteria (com.twinsoft.convertigo.beans.core.Criteria)3 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)3 Sheet (com.twinsoft.convertigo.beans.core.Sheet)3 Step (com.twinsoft.convertigo.beans.core.Step)3 Transaction (com.twinsoft.convertigo.beans.core.Transaction)3 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)3 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)3 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)3 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)3