Search in sources :

Example 6 with Criteria

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

the class GetChildren method getChildren.

public static void getChildren(String qname, Element parent, int depth) throws Exception {
    DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
    List<DatabaseObject> children = dbo.getDatabaseObjectChildren();
    // Get all children of the dbo
    Element elt = createDboElement(parent.getOwnerDocument(), dbo, !children.isEmpty());
    /*
		 *  In case of ScreenClass, we have to get Criteria, ExtractionRule and Sheets manually.
		 *  If fact, if the dbo is an inherited screen class, inherited Criteria, ExtractionRule and Sheets,
		 *  won't be retrieved by the method #getDatabaseObjectChildren.
		 */
    if (dbo instanceof ScreenClass) {
        ScreenClass sc = (ScreenClass) dbo;
        boolean hasChildren = false;
        // Get all Criteria
        List<Criteria> criteria = sc.getCriterias();
        for (Criteria criterion : criteria) {
            children.remove(criterion);
            Element eltCriterion = createScreenClassChildElement(parent.getOwnerDocument(), criterion, dbo);
            elt.appendChild(eltCriterion);
            hasChildren = true;
        }
        // Get all Extraction Rules
        List<ExtractionRule> extractionRules = sc.getExtractionRules();
        for (ExtractionRule extractionRule : extractionRules) {
            children.remove(extractionRule);
            Element eltExtractionRule = createScreenClassChildElement(parent.getOwnerDocument(), extractionRule, dbo);
            elt.appendChild(eltExtractionRule);
            hasChildren = true;
        }
        // Get all Sheets
        List<Sheet> sheets = sc.getSheets();
        for (Sheet sheet : sheets) {
            children.remove(sheet);
            Element eltSheet = createScreenClassChildElement(parent.getOwnerDocument(), sheet, dbo);
            elt.appendChild(eltSheet);
            hasChildren = true;
        }
        // In case of JavelinScreenClass, we also have to get the block factory manually
        if (dbo instanceof JavelinScreenClass) {
            JavelinScreenClass jsc = (JavelinScreenClass) sc;
            BlockFactory blockFactory = jsc.getBlockFactory();
            children.remove(blockFactory);
            Element eltBlockFactory = createScreenClassChildElement(parent.getOwnerDocument(), blockFactory, dbo);
            elt.appendChild(eltBlockFactory);
            hasChildren = true;
        }
        if (hasChildren) {
            elt.setAttribute("hasChildren", "true");
        }
    }
    parent.appendChild(elt);
    if (depth > 0) {
        for (DatabaseObject child : children) {
            getChildren(child.getQName(), elt, depth - 1);
        }
    }
}
Also used : JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) BlockFactory(com.twinsoft.convertigo.beans.core.BlockFactory) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) Element(org.w3c.dom.Element) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) Criteria(com.twinsoft.convertigo.beans.core.Criteria) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Example 7 with Criteria

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

the class ScreenClassHelper method findScreenClass.

private SC findScreenClass(SC currentScreenClass) throws EngineException {
    int scDepth = currentScreenClass.getDepth() * 3;
    String tab = scDepth == 0 ? "" : String.format("%" + scDepth + "s", "");
    Engine.logBeans.trace(tab + "Analyzing screen class " + currentScreenClass.getName());
    currentScreenClass.checkSymbols();
    for (Criteria criteria : currentScreenClass.getLocalCriterias()) {
        criteria.checkSymbols();
        if (criteria.isMatching(connector)) {
            Engine.logBeans.trace(tab + ". Criteria " + criteria.getName() + " is matching");
        } else {
            Engine.logBeans.trace(tab + ". Criteria " + criteria.getName() + " not matching; aborting screen class analyze");
            return null;
        }
    }
    Engine.logBeans.trace(tab + "::: Screen class " + currentScreenClass.getName() + " is matching");
    SC bestFoundScreenClass = currentScreenClass;
    int bestFoundScreenClassNumberOfLocalCriterias = bestFoundScreenClass.getNumberOfLocalCriterias();
    SC screenClass;
    for (SC inheritedScreenClass : getInheritedScreenClasses(currentScreenClass)) if ((screenClass = findScreenClass(inheritedScreenClass)) != null) {
        int screenClassNumberOfLocalCriterias = screenClass.getNumberOfLocalCriterias();
        // Avoid the "folder" screen classes, i.e. those with no local criterias
        if (screenClassNumberOfLocalCriterias != 0) {
            if ((screenClass.getDepth() > bestFoundScreenClass.getDepth()) || (screenClassNumberOfLocalCriterias > bestFoundScreenClassNumberOfLocalCriterias)) {
                bestFoundScreenClass = screenClass;
                bestFoundScreenClassNumberOfLocalCriterias = screenClassNumberOfLocalCriterias;
                Engine.logBeans.trace(tab + "   >>> Found a better screen class " + screenClass.getName());
            }
        }
    }
    if (// Setting the returned screen class to the best found one
    bestFoundScreenClass != null)
        currentScreenClass = bestFoundScreenClass;
    Engine.logBeans.trace(tab + "<<< Returning " + currentScreenClass.getName());
    return currentScreenClass;
}
Also used : Criteria(com.twinsoft.convertigo.beans.core.Criteria)

Example 8 with Criteria

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

the class HtmlConnectorDesignComposite method createCriteriasFromSelection.

public void createCriteriasFromSelection(Document dom) throws EngineException {
    String className = "com.twinsoft.convertigo.beans.core.Criteria";
    // Retrieve selected criterias xpath
    String criteriaXpath = xpathEvaluator.getSelectionXpath();
    // Retrieve parent ScreenClass
    HtmlScreenClass parentObject = getParentHtmlScreenClass();
    NewObjectWizard newObjectWizard = new NewObjectWizard(parentObject, className, criteriaXpath, dom);
    WizardDialog wzdlg = new WizardDialog(Display.getCurrent().getActiveShell(), newObjectWizard);
    wzdlg.setPageSize(850, 650);
    wzdlg.open();
    if (wzdlg.getReturnCode() != Window.CANCEL) {
        Criteria criteria = (Criteria) newObjectWizard.newBean;
        // Reload parent ScreenClass in Tree
        fireObjectChanged(new CompositeEvent(parentObject));
        // Set selection on last created criteria (will expand tree to new criteria)
        if (criteria != null)
            fireObjectSelected(new CompositeEvent(criteria));
        // Set back selection on parent ScreenClass
        fireObjectSelected(new CompositeEvent(parentObject));
    }
}
Also used : HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) Criteria(com.twinsoft.convertigo.beans.core.Criteria) NewObjectWizard(com.twinsoft.convertigo.eclipse.wizards.new_object.NewObjectWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent)

Example 9 with Criteria

use of com.twinsoft.convertigo.beans.core.Criteria 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 Criteria

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

the class SiteClipperScreenClass method getNumberOfLocalCriterias.

@Override
public int getNumberOfLocalCriterias() {
    // If we are in REQUEST mode, return the number of request criteria.
    Shuttle shuttle = getConnector().getShuttle();
    if (shuttle != null && shuttle.getProcessState() == ProcessState.request) {
        List<Criteria> localCriteria = getLocalCriterias();
        int nRequestLocalCriteria = 0;
        for (Criteria criteria : localCriteria) {
            if (criteria instanceof ISiteClipperRequestCriteria)
                nRequestLocalCriteria++;
        }
        return nRequestLocalCriteria;
    }
    // return the total number of local criteria.
    return super.getNumberOfLocalCriterias();
}
Also used : ISiteClipperRequestCriteria(com.twinsoft.convertigo.beans.common.ISiteClipperRequestCriteria) Criteria(com.twinsoft.convertigo.beans.core.Criteria) ISiteClipperRequestCriteria(com.twinsoft.convertigo.beans.common.ISiteClipperRequestCriteria) Shuttle(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector.Shuttle)

Aggregations

Criteria (com.twinsoft.convertigo.beans.core.Criteria)11 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)8 EngineException (com.twinsoft.convertigo.engine.EngineException)7 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 Sheet (com.twinsoft.convertigo.beans.core.Sheet)6 JavelinScreenClass (com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass)6 Connector (com.twinsoft.convertigo.beans.core.Connector)5 Statement (com.twinsoft.convertigo.beans.core.Statement)5 Transaction (com.twinsoft.convertigo.beans.core.Transaction)5 WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)5 IOException (java.io.IOException)5 ExtractionRule (com.twinsoft.convertigo.beans.core.ExtractionRule)4 Project (com.twinsoft.convertigo.beans.core.Project)4 Step (com.twinsoft.convertigo.beans.core.Step)4 TestCase (com.twinsoft.convertigo.beans.core.TestCase)4 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)4 BlockFactory (com.twinsoft.convertigo.beans.core.BlockFactory)3 Sequence (com.twinsoft.convertigo.beans.core.Sequence)3 Variable (com.twinsoft.convertigo.beans.core.Variable)3 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)3