Search in sources :

Example 11 with RequestableObject

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

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

the class ViewLabelProvider method getText.

@Override
public String getText(Object obj) {
    if (obj instanceof DatabaseObjectTreeObject) {
        DatabaseObject dbo = ((DatabaseObjectTreeObject) obj).getObject();
        if (dbo.isSymbolError() || (dbo instanceof Project && ((Project) dbo).undefinedGlobalSymbols)) {
            return obj.toString() + " (! undefined symbol !)";
        }
        String osname = System.getProperty("os.name");
        String version = System.getProperty("os.version");
        boolean notShownSpecialChar = osname.toLowerCase().startsWith("windows") && Double.parseDouble(version) < 6.2;
        boolean isMac = osname.toLowerCase().startsWith("mac");
        if (dbo instanceof RequestableObject && !notShownSpecialChar) {
            return (((RequestableObject) dbo).getAccessibility() == Accessibility.Private ? "🔒 " : (((RequestableObject) dbo).getAccessibility() == Accessibility.Hidden ? "👓 " : (isMac ? "🚪 " : " 🚪  "))) + (dbo instanceof Sequence ? (((Sequence) dbo).isAutoStart() ? "💡 " : "") : "") + obj.toString();
        }
    }
    return obj.toString();
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Sequence(com.twinsoft.convertigo.beans.core.Sequence)

Example 13 with RequestableObject

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

the class GenericRequester method findStyleSheet.

protected void findStyleSheet(String browser) throws EngineException {
    // The sheet url may have been already set by error handling...
    if (context.absoluteSheetUrl != null)
        return;
    // TODO: chercher la feuille de style en fonction du locale du client
    RequestableObject requestedObject = context.requestedObject;
    ISheetContainer lastDetectedObject = context.lastDetectedObject;
    InputSource inputSource = null;
    try {
        if ((context.cacheEntry != null) && (context.cacheEntry.sheetUrl != null)) {
            context.sheetUrl = context.cacheEntry.sheetUrl;
            context.absoluteSheetUrl = context.cacheEntry.absoluteSheetUrl;
            context.contentType = context.cacheEntry.contentType;
            if (context.sheetUrl == null) {
                // without sheet context...
                return;
            }
            Engine.logContext.debug("Sheet built from the cache");
        } else {
            Sheet sheet = null;
            int sheetLocation = requestedObject.getSheetLocation();
            if (sheetLocation == Transaction.SHEET_LOCATION_FROM_LAST_DETECTED_OBJECT_OF_REQUESTABLE) {
                Engine.logContext.debug("Sheet location: from last detected screen class");
            } else if (sheetLocation == Transaction.SHEET_LOCATION_FROM_REQUESTABLE) {
                Engine.logContext.debug("Sheet location: from transaction");
            } else {
                Engine.logContext.debug("Sheet location: none");
                return;
            }
            Engine.logContext.debug("Searching specific sheet for browser '" + browser + "'...");
            switch(sheetLocation) {
                default:
                case Transaction.SHEET_LOCATION_NONE:
                    break;
                case Transaction.SHEET_LOCATION_FROM_REQUESTABLE:
                    Engine.logContext.debug("Searching in the transaction");
                    sheet = requestedObject.getSheet(browser);
                    break;
                case Transaction.SHEET_LOCATION_FROM_LAST_DETECTED_OBJECT_OF_REQUESTABLE:
                    if (lastDetectedObject != null) {
                        Engine.logContext.debug("Searching in the last detected screen class (" + ((DatabaseObject) lastDetectedObject).getQName() + ")");
                        sheet = lastDetectedObject.getSheet(browser);
                    }
                    break;
            }
            if (sheet == null) {
                Engine.logContext.debug("No specific sheet has been found; searching for common sheet...");
                switch(sheetLocation) {
                    default:
                    case Transaction.SHEET_LOCATION_FROM_REQUESTABLE:
                        Engine.logContext.debug("Searching in the transaction");
                        sheet = requestedObject.getSheet(Sheet.BROWSER_ALL);
                        break;
                    case Transaction.SHEET_LOCATION_FROM_LAST_DETECTED_OBJECT_OF_REQUESTABLE:
                        if (lastDetectedObject != null) {
                            Engine.logContext.debug("Searching in the last detected screen class");
                            sheet = lastDetectedObject.getSheet(Sheet.BROWSER_ALL);
                        }
                        break;
                }
            }
            if (sheet == null) {
                // without sheet context...
                return;
            } else {
                Engine.logContext.debug("Storing found sheet into the execution context (__currentSheet)");
                context.sheetUrl = sheet.getUrl();
            }
            Engine.logContext.debug("Using XSL data from \"" + context.sheetUrl + "\"");
            // Search relatively to the Convertigo servlet application base directory
            context.absoluteSheetUrl = context.getProjectDirectory() + "/" + (context.subPath.length() > 0 ? context.subPath + "/" : "") + context.sheetUrl;
            Engine.logContext.debug("Url: " + context.absoluteSheetUrl);
            File xslFile = new File(context.absoluteSheetUrl);
            if (!xslFile.exists()) {
                Engine.logContext.debug("The local xsl file (\"" + context.absoluteSheetUrl + "\") does not exist. Trying search in Convertigo XSL directory...");
                if (context.sheetUrl.startsWith("../../xsl/"))
                    context.absoluteSheetUrl = Engine.XSL_PATH + "/" + context.sheetUrl.substring(10);
                else
                    context.absoluteSheetUrl = Engine.XSL_PATH + "/" + context.sheetUrl;
                Engine.logContext.debug("Url: " + context.absoluteSheetUrl);
                xslFile = new File(context.absoluteSheetUrl);
                if (!xslFile.exists()) {
                    Engine.logContext.debug("The common xsl file (\"" + context.absoluteSheetUrl + "\") does not exist. Trying absolute search...");
                    context.absoluteSheetUrl = context.sheetUrl;
                    Engine.logContext.debug("Url: " + context.absoluteSheetUrl);
                }
            }
            Engine.logContext.debug("Retrieving content type from the XSL...");
            // inputSource = new InputSource(new FileInputStream(context.absoluteSheetUrl));
            inputSource = new InputSource(new File(context.absoluteSheetUrl).toURI().toASCIIString());
            DocumentBuilder documentBuilder = XMLUtils.getDefaultDocumentBuilder();
            documentBuilder.setEntityResolver(XMLUtils.getEntityResolver());
            Document document = documentBuilder.parse(inputSource);
            NodeList nodeList = document.getElementsByTagName("xsl:output");
            String contentType = MimeType.Html.value();
            if (nodeList.getLength() != 0) {
                Element element = (Element) nodeList.item(0);
                contentType = element.getAttribute("media-type");
                if (contentType.length() == 0) {
                    Engine.logContext.warn("No media type is specified into the XSL style sheet \"" + context.sheetUrl + "\"; using default (\"text/html\"). You should use <xsl:output media-type=\"...\" ...> directive.");
                    contentType = MimeType.Html.value();
                }
                Engine.logContext.debug("Content-type=" + contentType);
            } else {
                Engine.logContext.warn("No media type is specified into the XSL style sheet \"" + context.sheetUrl + "\"; using default (\"text/html\"). You should use <xsl:output media-type=\"...\" ...> directive.");
            }
            context.contentType = contentType;
        }
        // Updating the cache entry properties if needed
        if (context.cacheEntry != null) {
            context.cacheEntry.contentType = context.contentType;
            context.cacheEntry.sheetUrl = context.sheetUrl;
            context.cacheEntry.absoluteSheetUrl = context.absoluteSheetUrl;
            try {
                Engine.theApp.cacheManager.updateCacheEntry(context.cacheEntry);
                Engine.logContext.debug("Sheet stored into the cache entry; updating its XSL and content type properties...");
            } catch (Exception e) {
                Engine.logContext.error("(CacheManager) Unable to update the cache entry!", e);
            }
        }
    } catch (Exception e) {
        throw new EngineException("An unexpected error has occured while finding the sheet for the transaction \"" + requestedObject.getName() + "\".", e);
    } finally {
        try {
            if (inputSource != null) {
                InputStream inputStream = inputSource.getByteStream();
                if (inputStream != null)
                    inputStream.close();
            }
        } catch (IOException e) {
            throw new EngineException("Unable to close the sheet file for the transaction \"" + requestedObject.getName() + "\".", e);
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) Document(org.w3c.dom.Document) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ISheetContainer(com.twinsoft.convertigo.beans.core.ISheetContainer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Sheet(com.twinsoft.convertigo.beans.core.Sheet) File(java.io.File)

Example 14 with RequestableObject

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

the class TreeDropAdapter method paste.

private boolean paste(Node node, TreeObject targetTreeObject) throws EngineException {
    if (targetTreeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObject parent = ((DatabaseObjectTreeObject) targetTreeObject).getObject();
        DatabaseObject databaseObject = paste(node, null, true);
        Element element = (Element) ((Element) node).getElementsByTagName("dnd").item(0);
        // SEQUENCER
        if (parent instanceof Sequence || parent instanceof StepWithExpressions) {
            if (parent instanceof XMLElementStep)
                return false;
            if (parent instanceof IThenElseContainer)
                return false;
            // Add a TransactionStep
            if (databaseObject instanceof Transaction) {
                String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
                String connectorName = ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name");
                Transaction transaction = (Transaction) databaseObject;
                TransactionStep transactionStep = new TransactionStep();
                transactionStep.setSourceTransaction(projectName + TransactionStep.SOURCE_SEPARATOR + connectorName + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
                transactionStep.bNew = true;
                parent.add(transactionStep);
                parent.hasChanged = true;
                if (transaction instanceof TransactionWithVariables) {
                    for (Variable variable : ((TransactionWithVariables) transaction).getVariablesList()) {
                        StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
                        stepVariable.setName(variable.getName());
                        stepVariable.setComment(variable.getComment());
                        stepVariable.setDescription(variable.getDescription());
                        stepVariable.setRequired(variable.isRequired());
                        stepVariable.setValueOrNull(variable.getValueOrNull());
                        stepVariable.setVisibility(variable.getVisibility());
                        transactionStep.addVariable(stepVariable);
                    }
                }
                return true;
            } else // Add a SequenceStep
            if (databaseObject instanceof Sequence) {
                String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
                Sequence seq = (Sequence) databaseObject;
                SequenceStep sequenceStep = new SequenceStep();
                sequenceStep.setSourceSequence(projectName + SequenceStep.SOURCE_SEPARATOR + seq.getName());
                sequenceStep.bNew = true;
                parent.add(sequenceStep);
                parent.hasChanged = true;
                for (Variable variable : seq.getVariablesList()) {
                    StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
                    stepVariable.setName(variable.getName());
                    stepVariable.setComment(variable.getComment());
                    stepVariable.setDescription(variable.getDescription());
                    stepVariable.setRequired(variable.isRequired());
                    stepVariable.setValueOrNull(variable.getValueOrNull());
                    stepVariable.setVisibility(variable.getVisibility());
                    sequenceStep.addVariable(stepVariable);
                }
                return true;
            }
        } else // URLMAPPER
        if (parent instanceof UrlMappingOperation) {
            // Set associated requestable, add all parameters for operation
            if (databaseObject instanceof RequestableObject) {
                String dboQName = "";
                if (databaseObject instanceof Sequence) {
                    dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + databaseObject.getName();
                } else if (databaseObject instanceof Transaction) {
                    dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name") + "." + databaseObject.getName();
                }
                UrlMappingOperation operation = (UrlMappingOperation) parent;
                operation.setTargetRequestable(dboQName);
                if (operation.getComment().isEmpty()) {
                    operation.setComment(databaseObject.getComment());
                }
                operation.hasChanged = true;
                try {
                    StringTokenizer st = new StringTokenizer(dboQName, ".");
                    int count = st.countTokens();
                    Project p = Engine.theApp.databaseObjectsManager.getProjectByName(st.nextToken());
                    List<RequestableVariable> variables = new ArrayList<RequestableVariable>();
                    if (count == 2) {
                        variables = p.getSequenceByName(st.nextToken()).getVariablesList();
                    } else if (count == 3) {
                        variables = ((TransactionWithVariables) p.getConnectorByName(st.nextToken()).getTransactionByName(st.nextToken())).getVariablesList();
                    }
                    for (RequestableVariable variable : variables) {
                        String variableName = variable.getName();
                        Object variableValue = variable.getValueOrNull();
                        UrlMappingParameter parameter = null;
                        try {
                            parameter = operation.getParameterByName(variableName);
                        } catch (Exception e) {
                        }
                        if (parameter == null) {
                            boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
                            parameter = acceptForm ? new FormParameter() : new QueryParameter();
                            parameter.setName(variableName);
                            parameter.setComment(variable.getComment());
                            parameter.setArray(false);
                            parameter.setExposed(((RequestableVariable) variable).isWsdl());
                            parameter.setMultiValued(variable.isMultiValued());
                            parameter.setRequired(variable.isRequired());
                            parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
                            parameter.setMappedVariableName(variableName);
                            parameter.bNew = true;
                            operation.add(parameter);
                            operation.hasChanged = true;
                        }
                    }
                } catch (Exception e) {
                }
                return true;
            } else // Add a parameter to mapping operation
            if (databaseObject instanceof RequestableVariable) {
                RequestableVariable variable = (RequestableVariable) databaseObject;
                UrlMappingOperation operation = (UrlMappingOperation) parent;
                UrlMappingParameter parameter = null;
                String variableName = variable.getName();
                Object variableValue = variable.getValueOrNull();
                try {
                    parameter = operation.getParameterByName(variableName);
                } catch (Exception e) {
                }
                if (parameter == null) {
                    boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
                    parameter = acceptForm ? new FormParameter() : new QueryParameter();
                    parameter.setName(variableName);
                    parameter.setComment(variable.getComment());
                    parameter.setArray(false);
                    parameter.setExposed(((RequestableVariable) variable).isWsdl());
                    parameter.setMultiValued(variable.isMultiValued());
                    parameter.setRequired(variable.isRequired());
                    parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
                    parameter.setMappedVariableName(variableName);
                    parameter.bNew = true;
                    operation.add(parameter);
                    operation.hasChanged = true;
                }
                return true;
            }
        } else // MOBILE COMPONENTS
        if (parent instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
            return pasteMobileComponent(parent, databaseObject, element);
        } else // NGX COMPONENTS
        if (parent instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
            return pasteNgxComponent(parent, databaseObject, element);
        }
    }
    return false;
}
Also used : QueryParameter(com.twinsoft.convertigo.beans.rest.QueryParameter) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IThenElseContainer(com.twinsoft.convertigo.beans.steps.IThenElseContainer) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) Element(org.w3c.dom.Element) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) FormParameter(com.twinsoft.convertigo.beans.rest.FormParameter) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) 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) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Project(com.twinsoft.convertigo.beans.core.Project) StringTokenizer(java.util.StringTokenizer) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) 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 15 with RequestableObject

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

the class UpdateXSDTypesAction method run.

public void run() {
    final Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
            String message = "Do you really want to extract the schema?\nWarning: the previous one will be replaced.";
            messageBox.setMessage(message);
            if (messageBox.open() == SWT.YES) {
                RequestableObject requestable = (RequestableObject) treeObject.getObject();
                String requestableName = StringUtils.normalize(requestable.getName(), true);
                Document document = null;
                String result = null;
                if (!(requestableName.equals(requestable.getName()))) {
                    throw new Exception("Requestable name should be normalized");
                }
                if (requestable instanceof Transaction) {
                    Connector connector = (Connector) requestable.getParent();
                    String connectorName = StringUtils.normalize(connector.getName(), true);
                    if (!(connectorName.equals(connector.getName()))) {
                        throw new Exception("Connector name should be normalized");
                    }
                    if (connector.getDefaultTransaction() == null) {
                        throw new Exception("Connector must have a default transaction");
                    }
                    if (requestable instanceof HtmlTransaction) {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
                                return;
                            }
                            result = requestable.generateXsdTypes(document, extract);
                        } else {
                            HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
                            String defaultTransactionName = StringUtils.normalize(defaultTransaction.getName(), true);
                            if (!(defaultTransactionName.equals(defaultTransaction.getName()))) {
                                throw new Exception("Default transaction name should be normalized");
                            }
                            String defaultXsdTypes = defaultTransaction.generateXsdTypes(null, false);
                            if (requestable.equals(defaultTransaction))
                                result = defaultXsdTypes;
                            else {
                                TransactionXSDTypesDialog dlg = new TransactionXSDTypesDialog(shell, requestable);
                                if (dlg.open() == Window.OK) {
                                    result = dlg.result;
                                    result += defaultXsdTypes;
                                }
                            }
                        }
                    } else {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
                                return;
                            }
                            String prefix = requestable.getXsdTypePrefix();
                            document.getDocumentElement().setAttribute("transaction", prefix + requestableName);
                        }
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                if (!xmlQName.isEmpty()) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Assigned element QName' property.");
                                    return;
                                }
                                if (!reqn.equals("")) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Schema of XML response root element' property.");
                                    return;
                                }
                            }
                        }
                        result = requestable.generateXsdTypes(document, extract);
                    }
                }
                if ((result != null) && (!result.equals(""))) {
                    String xsdTypes = result;
                    if (requestable instanceof Transaction) {
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (!extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                // ignore
                                ;
                            } else
                                ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                        } else
                            ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                    }
                    requestable.hasChanged = true;
                    Engine.theApp.schemaManager.clearCache(requestable.getProject().getName());
                    explorerView.refreshFirstSelectedTreeObject();
                    explorerView.objectSelected(new CompositeEvent(requestable));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to update schema!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Cursor(org.eclipse.swt.graphics.Cursor) Document(org.w3c.dom.Document) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) MessageBox(org.eclipse.swt.widgets.MessageBox) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) Shell(org.eclipse.swt.widgets.Shell) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) TransactionXSDTypesDialog(com.twinsoft.convertigo.eclipse.dialogs.TransactionXSDTypesDialog) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)18 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)10 Sequence (com.twinsoft.convertigo.beans.core.Sequence)8 Transaction (com.twinsoft.convertigo.beans.core.Transaction)8 Project (com.twinsoft.convertigo.beans.core.Project)7 Connector (com.twinsoft.convertigo.beans.core.Connector)6 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)6 JSONException (org.codehaus.jettison.json.JSONException)6 Document (org.w3c.dom.Document)6 Element (org.w3c.dom.Element)6 Variable (com.twinsoft.convertigo.beans.core.Variable)4 DesignDocument (com.twinsoft.convertigo.beans.couchdb.DesignDocument)4 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)4 ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)4 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)4 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)4 IOException (java.io.IOException)4 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 Cursor (org.eclipse.swt.graphics.Cursor)4