Search in sources :

Example 21 with Transaction

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

the class TransactionTreeObject 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;
    if (databaseObject instanceof ScreenClass) {
        String oldName = StringUtils.normalize((String) oldValue);
        String newName = StringUtils.normalize((String) newValue);
        Transaction transaction = getObject();
        // Modify Screenclass name in Transaction handlers
        if (!(transaction instanceof HtmlTransaction)) {
            // ScreenClass and Transaction must have the same connector!
            if (transaction.getConnector().equals(databaseObject.getConnector())) {
                String oldHandlerPrefix = "on" + StringUtils.normalize(oldName);
                String newHandlerPrefix = "on" + StringUtils.normalize(newName);
                if (transaction.handlers.indexOf(oldHandlerPrefix) != -1) {
                    StringEx sx = new StringEx(transaction.handlers);
                    // Updating comments
                    sx.replaceAll("handler for screen class \"" + oldName + "\"", "handler for screen class \"" + newName + "\"");
                    // Updating functions def & calls
                    sx.replaceAll(oldHandlerPrefix + "Entry", newHandlerPrefix + "Entry");
                    sx.replaceAll(oldHandlerPrefix + "Exit", newHandlerPrefix + "Exit");
                    String newHandlers = sx.toString();
                    if (!newHandlers.equals(transaction.handlers)) {
                        transaction.handlers = newHandlers;
                        hasBeenModified(true);
                    }
                    // Update the opened handlers editor if any
                    JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
                    if (jsinput != null) {
                        jsinput.reload();
                    }
                    try {
                        getProjectExplorerView().reloadTreeObject(this);
                    } catch (Exception e) {
                        ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                    }
                }
            }
        }
    }
    if (databaseObject instanceof Variable) {
        String oldVariableName = oldValue.toString();
        String newVariableName = newValue.toString();
        // A variable of this transaction has been renamed
        if (getObject().equals(databaseObject.getParent())) {
            if (getObject() instanceof AbstractHttpTransaction) {
                AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) getObject();
                try {
                    // Check for variables to be renamed in SubDir property
                    String transactionSubDir = httpTransaction.getSubDir();
                    List<String> pathVariableList = AbstractHttpTransaction.getPathVariableList(transactionSubDir);
                    if (pathVariableList.contains(oldVariableName)) {
                        transactionSubDir = transactionSubDir.replaceAll("\\{" + oldVariableName + "\\}", "{" + newVariableName + "}");
                        httpTransaction.setSubDir(transactionSubDir);
                        httpTransaction.hasChanged = true;
                    }
                    getProjectExplorerView().refreshTreeObject(this);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not reload in tree Transaction \"" + databaseObject.getName() + "\" !");
                }
            }
        }
    }
    // Case of this transaction rename : update transaction's schema
    if (treeObject.equals(this)) {
        String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME + "/" + getConnectorTreeObject().getName();
        String oldPath = path + "/" + (String) oldValue + ".xsd";
        String newPath = path + "/" + (String) newValue + ".xsd";
        IFile file = getProjectTreeObject().getFile(oldPath);
        try {
            file.getParent().refreshLocal(IResource.DEPTH_ONE, null);
            if (file.exists()) {
                // rename file (xsd/internal/connector/transaction.xsd)
                file.move(new Path((String) newValue + ".xsd"), true, null);
                // make replacements in schema files
                List<Replacement> replacements = new ArrayList<Replacement>();
                replacements.add(new Replacement("__" + (String) oldValue, "__" + (String) newValue));
                IFile newFile = file.getParent().getFile(new Path((String) newValue + ".xsd"));
                String newFilePath = newFile.getLocation().makeAbsolute().toString();
                try {
                    ProjectUtils.makeReplacementsInFile(replacements, newFilePath);
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + newPath + "\" !");
                }
                // refresh file
                file.refreshLocal(IResource.DEPTH_ZERO, null);
                Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
            }
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not rename schema file from \"" + oldPath + "\" to \"" + newPath + "\" !");
        }
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) Path(org.eclipse.core.runtime.Path) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) IFile(org.eclipse.core.resources.IFile) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ArrayList(java.util.ArrayList) Replacement(com.twinsoft.convertigo.engine.util.Replacement) PartInitException(org.eclipse.ui.PartInitException) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) StringEx(com.twinsoft.util.StringEx)

Example 22 with Transaction

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

the class VariableTreeObject2 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;
    int update = treeObjectEvent.update;
    // Updates variables references
    if (update != TreeObjectEvent.UPDATE_NONE) {
        boolean isLocalProject = false;
        boolean isSameValue = false;
        boolean shouldUpdate = false;
        try {
            if (getObject() instanceof Variable) {
                Variable variable = (Variable) getObject();
                if (databaseObject instanceof RequestableVariable) {
                    isLocalProject = variable.getProject().equals(databaseObject.getProject());
                    isSameValue = variable.getName().equals(oldValue);
                    shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                    // Verify if parent of databaseObject is a transaction
                    if (databaseObject.getParent() instanceof Transaction) {
                        Transaction transaction = (Transaction) databaseObject.getParent();
                        // Case of rename for Call Transaction
                        if (variable.getParent() instanceof TransactionStep) {
                            TransactionStep transactionStep = (TransactionStep) variable.getParent();
                            if (transactionStep.getSourceTransaction().equals(transaction.getProject() + "." + transaction.getConnector() + "." + transaction.getName())) {
                                updateNameReference(isSameValue, shouldUpdate, variable, newValue);
                            }
                        }
                        /*
							 * propagation to testCases of variable renaming in a transaction
							 */
                        if (variable.getParent() instanceof TransactionWithVariables) {
                            propagateVariableRename(true, true, treeObjectEvent, ((TransactionWithVariables) transaction).getTestCasesList(), transaction.getName());
                        }
                    }
                    // Verify if parent of databaseObject is a sequence
                    if (databaseObject.getParent() instanceof Sequence) {
                        Sequence sequence = (Sequence) databaseObject.getParent();
                        // Case of rename for Call Sequence
                        if (variable.getParent() instanceof SequenceStep) {
                            SequenceStep sequenceStep = (SequenceStep) variable.getParent();
                            if (sequenceStep.getSourceSequence().equals(sequence.getProject() + "." + sequence.getName())) {
                                updateNameReference(isSameValue, shouldUpdate, variable, newValue);
                            }
                        }
                        /*
							 * propagation to testCases of variable renaming in a sequence
							 */
                        if (variable.getParent() instanceof Sequence) {
                            propagateVariableRename(true, true, treeObjectEvent, sequence.getTestCasesList(), sequence.getName());
                        }
                    }
                }
            }
        } catch (EngineException e) {
            ConvertigoPlugin.logException(e, "Unable to rename the variable references of '" + databaseObject.getName() + "'!");
        }
    }
}
Also used : SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 23 with Transaction

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

the class XmlSchemaBuilder method midBuildSchema.

private void midBuildSchema(final int nb) throws EngineException {
    // System.out.println("buildSchema for "+ getTargetNamespace());
    boolean fullSchema = isFull;
    try {
        new WalkHelper() {

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (databaseObject instanceof ISchemaGenerator) {
                    // generate itself and add to the caller list
                    if (databaseObject instanceof ISchemaImportGenerator) {
                        // Import case
                        if (databaseObject instanceof ProjectSchemaReference) {
                            ProjectSchemaReference ref = (ProjectSchemaReference) databaseObject;
                            String targetProjectName = ref.getParser().getProjectName();
                            String tns = Project.getProjectTargetNamespace(targetProjectName);
                            if (collection.schemaForNamespace(tns) == null) {
                                if (SchemaMeta.getXmlSchemaObject(schema, databaseObject) == null) {
                                    XmlSchemaImport schemaImport = new XmlSchemaImport();
                                    schemaImport.setNamespace(tns);
                                    SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
                                    XmlSchemaUtils.add(schema, schemaImport);
                                } else {
                                    XmlSchemaBuilder builder = builderExecutor.getBuilderByTargetNamespace(tns);
                                    if (builder != null) {
                                        XmlSchemaUtils.remove(schema, SchemaMeta.getXmlSchemaObject(schema, databaseObject));
                                        XmlSchema xmlSchema = collection.read(builder.schema.getSchemaDocument(), null);
                                        XmlSchemaImport schemaImport = new XmlSchemaImport();
                                        schemaImport.setNamespace(tns);
                                        schemaImport.setSchema(xmlSchema);
                                        SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
                                        XmlSchemaUtils.add(schema, schemaImport);
                                    }
                                }
                            }
                        }
                    }
                } else {
                    // doesn't generate schema, just deep walk
                    super.walk(databaseObject);
                }
            }

            @Override
            protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                // just walk references
                return Reference.class.isAssignableFrom(dboClass);
            }
        }.init(project);
        // add missing references import
        if (nb == 1) {
            if (this.equals(builderExecutor.getMainBuilder())) {
                List<String> refs = new ArrayList<String>();
                SchemaManager.getProjectReferences(refs, projectName);
                List<String> missing = new ArrayList<String>();
                missing.addAll(refs);
                missing.remove(projectName);
                for (String pname : refs) {
                    XmlSchemaObjectCollection col = schema.getIncludes();
                    for (int i = 0; i < col.getCount(); i++) {
                        XmlSchemaObject ob = col.getItem(i);
                        if (ob instanceof XmlSchemaImport) {
                            XmlSchemaImport xmlSchemaImport = (XmlSchemaImport) ob;
                            String tns = Project.getProjectTargetNamespace(pname);
                            if (xmlSchemaImport.getNamespace().equals(tns)) {
                                missing.remove(pname);
                            }
                        }
                    }
                }
                for (String pname : missing) {
                    String tns = Project.getProjectTargetNamespace(pname);
                    XmlSchemaBuilder builder = builderExecutor.getBuilderByTargetNamespace(tns);
                    if (builder != null) {
                        XmlSchema xmlSchema = collection.read(builder.schema.getSchemaDocument(), null);
                        XmlSchemaImport schemaImport = new XmlSchemaImport();
                        schemaImport.setNamespace(tns);
                        schemaImport.setSchema(xmlSchema);
                        XmlSchemaUtils.add(schema, schemaImport);
                    }
                }
            }
        }
        new WalkHelper() {

            List<XmlSchemaParticle> particleChildren;

            List<XmlSchemaAttribute> attributeChildren;

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                // Transaction case
                if (databaseObject instanceof Transaction) {
                    Transaction transaction = (Transaction) databaseObject;
                    String ns = schema.getTargetNamespace();
                    List<QName> partElementQNames = new ArrayList<QName>();
                    partElementQNames.add(new QName(ns, transaction.getXsdRequestElementName()));
                    partElementQNames.add(new QName(ns, transaction.getXsdResponseElementName()));
                    LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
                    XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, true);
                    for (QName qname : partElementQNames) {
                        dw.walkByElementRef(schema, qname);
                    }
                    for (QName qname : map.keySet()) {
                        String nsURI = qname.getNamespaceURI();
                        if (nsURI.equals(ns))
                            continue;
                        if (nsURI.equals(Constants.URI_2001_SCHEMA_XSD))
                            continue;
                        SchemaManager.addXmlSchemaImport(collection, schema, nsURI);
                    }
                    map.clear();
                    // add the 'statistics' element
                    if (transaction.getAddStatistics()) {
                        XmlSchemaComplexType xmlSchemaComplexType = (XmlSchemaComplexType) schema.getTypeByName(transaction.getXsdResponseTypeName());
                        XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaComplexType.getParticle();
                        XmlSchemaType statisticsType = schema.getTypeByName("ConvertigoStatsType");
                        XmlSchemaElement eStatistics = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
                        eStatistics.setName("statistics");
                        eStatistics.setMinOccurs(0);
                        eStatistics.setMaxOccurs(1);
                        eStatistics.setSchemaTypeName(statisticsType.getQName());
                        xmlSchemaGroupBase.getItems().add(eStatistics);
                        SchemaMeta.getReferencedDatabaseObjects(statisticsType).add(transaction);
                    }
                } else // Sequence case
                if (databaseObject instanceof Sequence) {
                    Sequence sequence = (Sequence) databaseObject;
                    // System.out.println("--sequence:"+ sequence.toString());
                    particleChildren = new LinkedList<XmlSchemaParticle>();
                    attributeChildren = new LinkedList<XmlSchemaAttribute>();
                    super.walk(databaseObject);
                    // check for an 'error' element if needed
                    boolean errorFound = false;
                    XmlSchemaType errorType = schema.getTypeByName("ConvertigoError");
                    if (errorType != null) {
                        Set<DatabaseObject> dbos = SchemaMeta.getReferencedDatabaseObjects(errorType);
                        for (DatabaseObject dbo : dbos) {
                            if (dbo instanceof Step) {
                                Step errorStep = (Step) dbo;
                                if (errorStep.getSequence().equals(sequence) && (errorStep instanceof XMLCopyStep || errorStep.getStepNodeName().equals("error"))) {
                                    errorFound = true;
                                    break;
                                }
                            }
                        }
                    }
                    // set particle : choice or sequence
                    XmlSchemaComplexType cType = (XmlSchemaComplexType) schema.getTypeByName(sequence.getComplexTypeAffectation().getLocalPart());
                    XmlSchemaSequence xmlSeq = new XmlSchemaSequence();
                    XmlSchemaChoice xmlChoice = new XmlSchemaChoice();
                    cType.setParticle(errorFound ? xmlSeq : xmlChoice);
                    if (!errorFound) {
                        XmlSchemaElement eError = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
                        eError.setName("error");
                        eError.setMinOccurs(0);
                        eError.setMaxOccurs(1);
                        eError.setSchemaTypeName(errorType.getQName());
                        SchemaMeta.getReferencedDatabaseObjects(errorType).add(sequence);
                        xmlChoice.getItems().add(xmlSeq);
                        xmlChoice.getItems().add(eError);
                    }
                    // add child particles
                    if (!particleChildren.isEmpty()) {
                        for (XmlSchemaParticle child : particleChildren) {
                            xmlSeq.getItems().add(child);
                        }
                    }
                    particleChildren.clear();
                    // add child attributes
                    for (XmlSchemaAttribute attribute : attributeChildren) {
                        cType.getAttributes().add(attribute);
                    }
                    attributeChildren.clear();
                    // add the 'statistics' element
                    if (sequence.getAddStatistics()) {
                        XmlSchemaType statisticsType = schema.getTypeByName("ConvertigoStatsType");
                        XmlSchemaElement eStatistics = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
                        eStatistics.setName("statistics");
                        eStatistics.setMinOccurs(0);
                        eStatistics.setMaxOccurs(1);
                        eStatistics.setSchemaTypeName(statisticsType.getQName());
                        xmlSeq.getItems().add(eStatistics);
                        SchemaMeta.getReferencedDatabaseObjects(statisticsType).add(sequence);
                    }
                // --------------------------- For Further Use -------------------------------------------------//
                // Modify schema to avoid 'cosamb' (same tagname&type in different groupBase at same level)
                // TODO : IfThenElse steps must be modified for xsd:sequence instead of xsd:choice
                // TODO : Then/Else steps must be modified to add minOccurs=0 on xsd:sequence
                // TODO : review/improve cosnoamb(XmlSchema, XmlSchemaGroupBase, XmlSchemaGroupBase) method
                // ---------------------------------------------------------------------------------------------//
                } else // Step case
                if (databaseObject instanceof Step) {
                    Step step = (Step) databaseObject;
                    if (!step.isEnabled()) {
                        // stop walking for disabled steps
                        return;
                    }
                    List<XmlSchemaParticle> parentParticleChildren = particleChildren;
                    List<XmlSchemaAttribute> parentAttributeChildren = attributeChildren;
                    // System.out.println("step:"+ step.toString());
                    if (step instanceof TransactionStep) {
                    // System.out.println("SCHEMA TARGET STEP "+ step.toString() + "(" + step.hashCode() + ")");
                    }
                    if (step.isGenerateSchema() || (fullSchema && step.isXmlOrOutput())) {
                        // System.out.println("-> generate schema...");
                        List<XmlSchemaParticle> myParticleChildren = null;
                        List<XmlSchemaAttribute> myAttributeChildren = null;
                        // is base affected ?
                        @SuppressWarnings("unused") XmlSchemaType base = null;
                        QName baseQName = step instanceof ISimpleTypeAffectation ? ((ISimpleTypeAffectation) step).getSimpleTypeAffectation() : null;
                        if (baseQName != null && baseQName.getLocalPart().length() > 0) {
                            // base = baseQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(baseQName.getLocalPart()) : collection.getTypeByQName(baseQName);
                            base = XmlSchemaBuilder.this.resolveTypeByQName(baseQName);
                        }
                        // is type affected ?
                        XmlSchemaType type = null;
                        QName typeQName = step instanceof IComplexTypeAffectation ? ((IComplexTypeAffectation) step).getComplexTypeAffectation() : null;
                        if (typeQName != null && typeQName.getLocalPart().length() > 0) {
                            // type = typeQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(typeQName.getLocalPart()) : collection.getTypeByQName(typeQName);
                            type = XmlSchemaBuilder.this.resolveTypeByQName(typeQName);
                        }
                        // is element affected ?
                        XmlSchemaElement ref = null;
                        QName refQName = step instanceof IElementRefAffectation ? ((IElementRefAffectation) step).getElementRefAffectation() : null;
                        if (refQName != null && refQName.getLocalPart().length() > 0) {
                            // ref = refQName.getNamespaceURI().length() == 0 ? schema.getElementByName(refQName.getLocalPart()) : collection.getElementByQName(refQName);
                            ref = XmlSchemaBuilder.this.resolveElementByQName(refQName);
                            typeQName = new QName(schema.getTargetNamespace(), refQName.getLocalPart() + "Type");
                            if (ref == null && refQName.getNamespaceURI().equals(schema.getTargetNamespace())) {
                                ref = XmlSchemaUtils.makeDynamic(step, new XmlSchemaElement());
                                ref.setQName(refQName);
                                ref.setName(refQName.getLocalPart());
                                ref.setSchemaTypeName(baseQName);
                                XmlSchemaUtils.add(schema, ref);
                            } else if (ref != null) {
                                ref.setSchemaTypeName(baseQName);
                                // type = typeQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(typeQName.getLocalPart()) : collection.getTypeByQName(typeQName);
                                type = XmlSchemaBuilder.this.resolveTypeByQName(typeQName);
                            }
                        }
                        if (type == null || !SchemaMeta.isReadOnly(type)) {
                            // prepare to receive children
                            if (step instanceof ISchemaParticleGenerator) {
                                myParticleChildren = particleChildren = new LinkedList<XmlSchemaParticle>();
                                if (fullSchema || ((ISchemaParticleGenerator) step).isGenerateElement()) {
                                    myAttributeChildren = attributeChildren = new LinkedList<XmlSchemaAttribute>();
                                }
                            }
                            // deep walk
                            super.walk(step);
                            // generate itself and add to the caller list
                            if (step instanceof ISchemaAttributeGenerator) {
                                // Attribute case
                                XmlSchemaAttribute attribute = ((ISchemaAttributeGenerator) step).getXmlSchemaObject(collection, schema);
                                SchemaMeta.setXmlSchemaObject(schema, step, attribute);
                                parentAttributeChildren.add(attribute);
                            } else if (step instanceof ISchemaParticleGenerator) {
                                if (step instanceof RequestableStep) {
                                    RequestableStep requestableStep = (RequestableStep) step;
                                    String targetProjectName = requestableStep.getProjectName();
                                    Project targetProject = requestableStep.getSequence().getLoadedProject(targetProjectName);
                                    if (targetProject == null) {
                                        Engine.logEngine.warn("(XmlSchemaBuilder) Not complete schema because: Missing required or not loaded project \"" + targetProjectName + "\"");
                                    } else if (step instanceof SequenceStep) {
                                        // SequenceStep case : walk target sequence first
                                        try {
                                            Sequence targetSequence = ((SequenceStep) step).getTargetSequence();
                                            targetProjectName = targetSequence.getProject().getName();
                                            String targetSequenceName = targetSequence.getName();
                                            String stepSequenceName = step.getSequence().getName();
                                            if (projectName.equals(targetProjectName)) {
                                                boolean isAfter = targetSequenceName.compareToIgnoreCase(stepSequenceName) > 0;
                                                if (isAfter) {
                                                    walk(targetSequence);
                                                }
                                            }
                                        } catch (EngineException e) {
                                            if (!e.getMessage().startsWith("There is no ")) {
                                                throw e;
                                            } else {
                                                Engine.logEngine.warn("(XmlSchemaBuilder) Not complete schema because: " + e.getMessage());
                                            }
                                        }
                                    }
                                }
                                // Particle case
                                XmlSchemaParticle particle = ((ISchemaParticleGenerator) step).getXmlSchemaObject(collection, schema);
                                SchemaMeta.setXmlSchemaObject(schema, step, particle);
                                parentParticleChildren.add(particle);
                                // retrieve the xsd:element to add children
                                XmlSchemaElement element = SchemaMeta.getContainerXmlSchemaElement(ref == null ? particle : ref);
                                // retrieve the group to add children if any
                                XmlSchemaGroupBase group = SchemaMeta.getContainerXmlSchemaGroupBase(element != null ? element : particle);
                                // new complexType to enhance the element
                                XmlSchemaComplexType cType = element != null ? (XmlSchemaComplexType) element.getSchemaType() : null;
                                // do something only on case of child
                                if (!myParticleChildren.isEmpty() || (myAttributeChildren != null && !myAttributeChildren.isEmpty())) {
                                    if (cType == null) {
                                        cType = XmlSchemaUtils.makeDynamic(step, new XmlSchemaComplexType(schema));
                                    }
                                    // prepare element children in the group
                                    if (!myParticleChildren.isEmpty()) {
                                        if (group == null) {
                                            group = XmlSchemaUtils.makeDynamic(step, new XmlSchemaSequence());
                                        }
                                        for (XmlSchemaParticle child : myParticleChildren) {
                                            group.getItems().add(child);
                                        }
                                    }
                                    if (element != null) {
                                        XmlSchemaSimpleContentExtension sContentExt = SchemaManager.makeSimpleContentExtension(step, element, cType);
                                        if (sContentExt != null) {
                                            // add attributes
                                            for (XmlSchemaAttribute attribute : myAttributeChildren) {
                                                sContentExt.getAttributes().add(attribute);
                                            }
                                        } else {
                                            // add attributes
                                            for (XmlSchemaAttribute attribute : myAttributeChildren) {
                                                cType.getAttributes().add(attribute);
                                            }
                                            // add elements
                                            if (SchemaMeta.isDynamic(cType) && group != null) {
                                                cType.setParticle(group);
                                            }
                                        }
                                    }
                                }
                                if (element != null) {
                                    // check if the type is named
                                    if (typeQName != null && typeQName.getLocalPart().length() > 0) {
                                        if (cType == null) {
                                            cType = XmlSchemaUtils.makeDynamic(step, new XmlSchemaComplexType(schema));
                                            SchemaManager.makeSimpleContentExtension(step, element, cType);
                                        }
                                        if (type == null) {
                                            // the type doesn't exist, declare it
                                            cType.setName(typeQName.getLocalPart());
                                            schema.addType(cType);
                                            schema.getItems().add(cType);
                                        } else {
                                            // the type already exists, merge it
                                            XmlSchemaComplexType currentCType = (XmlSchemaComplexType) type;
                                            SchemaManager.merge(schema, currentCType, cType);
                                            cType = currentCType;
                                        }
                                        // reference the type in the current element
                                        element.setSchemaTypeName(cType.getQName());
                                        element.setSchemaType(null);
                                    } else if (cType != null && SchemaMeta.isDynamic(cType) && element.getSchemaTypeName() == null) {
                                        // the element contains an anonymous type
                                        element.setSchemaType(cType);
                                    }
                                }
                            } else {
                                XmlSchemaObject object;
                                XmlSchema xmlSchema = null;
                                if (step instanceof XMLCopyStep && !fullSchema) {
                                    final XmlSchemaBuilder fullBuilder = builderExecutor.getBuilder(projectName, true);
                                    if (fullBuilder != null) {
                                        xmlSchema = fullBuilder.getXmlSchema();
                                        XmlSchemaCollection xmlCollection = SchemaMeta.getCollection(xmlSchema);
                                        object = step.getXmlSchemaObject(xmlCollection, xmlSchema);
                                    } else {
                                        xmlSchema = schema;
                                        object = step.getXmlSchemaObject(collection, schema);
                                        SchemaMeta.setXmlSchemaObject(schema, step, object);
                                    }
                                } else {
                                    xmlSchema = schema;
                                    object = step.getXmlSchemaObject(collection, schema);
                                    SchemaMeta.setXmlSchemaObject(schema, step, object);
                                }
                                if (step instanceof XMLCopyStep) {
                                    if (object instanceof XmlSchemaElement) {
                                        XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) object;
                                        QName qname = xmlSchemaElement.getSchemaTypeName();
                                        if (qname != null) {
                                            XmlSchemaType xmlSchemaType = xmlSchema.getTypeByName(qname);
                                            if (xmlSchemaType != null) {
                                                SchemaMeta.getReferencedDatabaseObjects(xmlSchemaType).add(step);
                                            }
                                        }
                                    }
                                }
                                if (object instanceof XmlSchemaParticle) {
                                    particleChildren.add((XmlSchemaParticle) object);
                                } else if (object instanceof XmlSchemaAttribute) {
                                    attributeChildren.add((XmlSchemaAttribute) object);
                                }
                            }
                        } else {
                            // re-use read only type
                            XmlSchemaElement elt = XmlSchemaUtils.makeDynamic(step, new XmlSchemaElement());
                            SchemaMeta.getReferencedDatabaseObjects(type).add(step);
                            SchemaMeta.setXmlSchemaObject(schema, step, elt);
                            elt.setName(step.getStepNodeName());
                            elt.setSchemaTypeName(typeQName);
                            particleChildren.add(elt);
                        }
                    } else // Other case
                    {
                        // doesn't generate schema, just deep walk
                        // System.out.println("-> do not generate schema (deep walk)");
                        super.walk(step);
                    }
                    // restore lists for siblings
                    particleChildren = parentParticleChildren;
                    attributeChildren = parentAttributeChildren;
                } else {
                    // just deep walk
                    super.walk(databaseObject);
                }
            }

            @Override
            protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                // just walk ISchemaGenerator DBO
                return Step.class.isAssignableFrom(dboClass) || Sequence.class.isAssignableFrom(dboClass) || Transaction.class.isAssignableFrom(dboClass) || Connector.class.isAssignableFrom(dboClass);
            }
        }.init(project);
    } catch (Exception e) {
        throw new EngineException("midBuildSchema failed", e);
    }
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaGroupBase(org.apache.ws.commons.schema.XmlSchemaGroupBase) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) Project(com.twinsoft.convertigo.beans.core.Project) IComplexTypeAffectation(com.twinsoft.convertigo.beans.core.IComplexTypeAffectation) Transaction(com.twinsoft.convertigo.beans.core.Transaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ISchemaImportGenerator(com.twinsoft.convertigo.beans.core.ISchemaImportGenerator) ISchemaGenerator(com.twinsoft.convertigo.beans.core.ISchemaGenerator) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Step(com.twinsoft.convertigo.beans.core.Step) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ISchemaParticleGenerator(com.twinsoft.convertigo.beans.core.ISchemaParticleGenerator) XMLCopyStep(com.twinsoft.convertigo.beans.steps.XMLCopyStep) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) IElementRefAffectation(com.twinsoft.convertigo.beans.core.IElementRefAffectation) XmlSchemaWalker(com.twinsoft.convertigo.engine.util.XmlSchemaWalker) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaChoice(org.apache.ws.commons.schema.XmlSchemaChoice) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) ISchemaAttributeGenerator(com.twinsoft.convertigo.beans.core.ISchemaAttributeGenerator) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) QName(javax.xml.namespace.QName) ISimpleTypeAffectation(com.twinsoft.convertigo.beans.core.ISimpleTypeAffectation) XmlSchemaParticle(org.apache.ws.commons.schema.XmlSchemaParticle) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Example 24 with Transaction

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

the class DatabaseObjectDeleteAction method delete.

private void delete(DatabaseObject databaseObject, boolean deleteProjectOnDisk) throws EngineException, CoreException {
    if (databaseObject instanceof Connector) {
        if (((Connector) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default connector!");
        }
        String dirPath, projectName;
        File dir;
        projectName = databaseObject.getParent().getName();
        MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        messageBox.setText("Also delete linked resources?");
        // Delete soap templates for this connector
        dirPath = Engine.projectDir(projectName) + "/soap-templates/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
        // Delete directory corresponding to connector under Traces directory
        dirPath = Engine.projectDir(projectName) + "/Traces/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
    } else if (databaseObject instanceof Transaction) {
        if (((Transaction) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default transaction!");
        }
    } else if (databaseObject instanceof ScreenClass) {
        if ((databaseObject.getParent()) instanceof Project) {
            throw new EngineException("Cannot delete the root screen class!");
        }
    } else if (databaseObject instanceof Statement) {
        if ((databaseObject instanceof ThenStatement) || (databaseObject instanceof ElseStatement)) {
            throw new EngineException("Cannot delete this statement!");
        }
    } else if (databaseObject instanceof Step) {
        if ((databaseObject instanceof ThenStep) || (databaseObject instanceof ElseStep)) {
            throw new EngineException("Cannot delete this step!");
        }
    } else if (databaseObject instanceof MobilePlatform) {
        MobilePlatform mobilePlatform = (MobilePlatform) databaseObject;
        File resourceFolder = mobilePlatform.getResourceFolder();
        if (resourceFolder.exists()) {
            MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("Do you want to delete the whole resource folder \"" + mobilePlatform.getRelativeResourcePath() + "\"?");
            messageBox.setText("Delete the \"" + resourceFolder.getName() + "\" folder?");
            if (messageBox.open() == SWT.YES) {
                FileUtils.deleteQuietly(resourceFolder);
            }
        }
    } else if (databaseObject instanceof PageComponent) {
        if (((PageComponent) databaseObject).isRoot) {
            throw new EngineException("Cannot delete the root page!");
        }
    }
    String dboQName = databaseObject.getQName();
    if (databaseObject instanceof Project) {
        // Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName());
        if (deleteProjectOnDisk) {
            Engine.theApp.databaseObjectsManager.deleteProjectAndCar(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        } else {
            Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        }
        ConvertigoPlugin.getDefault().deleteProjectPluginResource(deleteProjectOnDisk, databaseObject.getName());
    } else {
        databaseObject.delete();
    }
    if (databaseObject instanceof CouchDbConnector) {
        CouchDbConnector couchDbConnector = (CouchDbConnector) databaseObject;
        String db = couchDbConnector.getDatabaseName();
        if (!db.isEmpty()) {
            MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("Do you want to delete the \"" + db + "\" database from the CouchDb server?");
            messageBox.setText("Delete the database?");
            if (messageBox.open() == SWT.YES) {
                couchDbConnector.getCouchClient().deleteDatabase(db);
            }
        }
    }
    ConvertigoPlugin.logDebug("The object \"" + dboQName + "\" has been deleted from the database repository!");
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) EngineException(com.twinsoft.convertigo.engine.EngineException) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) IOException(java.io.IOException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) MessageBox(org.eclipse.swt.widgets.MessageBox) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Project(com.twinsoft.convertigo.beans.core.Project) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) File(java.io.File)

Example 25 with Transaction

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

the class CreateStubFromXMLAction method getXML.

public Document getXML(TreeObject treeObject) throws Exception {
    Document dom = XMLUtils.createDom("java");
    ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
    Object requestable = treeObject.getObject();
    if (requestable instanceof Transaction) {
        Transaction transaction = (Transaction) requestable;
        ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor((Connector) transaction.getParent());
        dom = connectorEditor.getLastGeneratedDocument();
    } else if (requestable instanceof Sequence) {
        SequenceEditor sequenceEditor = projectTreeObject.getSequenceEditor((Sequence) requestable);
        dom = sequenceEditor.getLastGeneratedDocument();
    }
    if (dom == null) {
        throw new NoSuchElementException();
    }
    return dom;
}
Also used : Transaction(com.twinsoft.convertigo.beans.core.Transaction) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SequenceEditor(com.twinsoft.convertigo.eclipse.editors.sequence.SequenceEditor) Document(org.w3c.dom.Document) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) NoSuchElementException(java.util.NoSuchElementException)

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