Search in sources :

Example 1 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class SwaggerUtils method createRestConnector.

@SuppressWarnings("unused")
private static HttpConnector createRestConnector(JSONObject json) throws Exception {
    try {
        HttpConnector httpConnector = new HttpConnector();
        httpConnector.bNew = true;
        JSONObject info = json.getJSONObject("info");
        httpConnector.setName(StringUtils.normalize(info.getString("title")));
        String host = json.getString("host");
        int index = host.indexOf(":");
        String server = index == -1 ? host : host.substring(0, index);
        int port = index == -1 ? 0 : Integer.parseInt(host.substring(index + 1, 10));
        httpConnector.setServer(server);
        httpConnector.setPort(port <= 0 ? 80 : port);
        String basePath = json.getString("basePath");
        httpConnector.setBaseDir(basePath);
        JSONArray _consumes = new JSONArray();
        if (json.has("consumes")) {
            _consumes = json.getJSONArray("consumes");
        }
        JSONArray _produces = new JSONArray();
        if (json.has("produces")) {
            _produces = json.getJSONArray("produces");
        }
        Map<String, JSONObject> models = new HashMap<String, JSONObject>();
        JSONObject definitions = new JSONObject();
        if (json.has("definitions")) {
            definitions = json.getJSONObject("definitions");
            for (Iterator<String> i = GenericUtils.cast(definitions.keys()); i.hasNext(); ) {
                String key = i.next();
                JSONObject model = definitions.getJSONObject(key);
                models.put(key, model);
            }
        }
        JSONObject paths = json.getJSONObject("paths");
        for (Iterator<String> i1 = GenericUtils.cast(paths.keys()); i1.hasNext(); ) {
            String subDir = i1.next();
            JSONObject path = paths.getJSONObject(subDir);
            for (Iterator<String> i2 = GenericUtils.cast(path.keys()); i2.hasNext(); ) {
                String httpVerb = i2.next();
                JSONObject verb = path.getJSONObject(httpVerb);
                XMLVector<XMLVector<String>> httpParameters = new XMLVector<XMLVector<String>>();
                AbstractHttpTransaction transaction = new HttpTransaction();
                JSONArray consumes = verb.has("consumes") ? verb.getJSONArray("consumes") : _consumes;
                List<String> consumeList = new ArrayList<String>();
                for (int i = 0; i < consumes.length(); i++) {
                    consumeList.add(consumes.getString(i));
                }
                String h_ContentType = null;
                if (consumeList.contains(MimeType.Xml.value())) {
                    h_ContentType = MimeType.Xml.value();
                } else if (consumeList.contains(MimeType.Json.value())) {
                    h_ContentType = MimeType.Json.value();
                } else {
                    h_ContentType = consumeList.size() > 0 ? consumeList.get(0) : MimeType.WwwForm.value();
                }
                JSONArray produces = verb.has("produces") ? verb.getJSONArray("produces") : _produces;
                List<String> produceList = new ArrayList<String>();
                for (int i = 0; i < produces.length(); i++) {
                    produceList.add(produces.getString(i));
                }
                String h_Accept = null;
                if (produceList.contains(h_ContentType)) {
                    h_Accept = h_ContentType;
                } else {
                    if (produceList.contains(MimeType.Xml.value())) {
                        h_Accept = MimeType.Xml.value();
                    } else if (produceList.contains(MimeType.Json.value())) {
                        h_Accept = MimeType.Json.value();
                    }
                }
                if (h_Accept != null) {
                    XMLVector<String> xmlv = new XMLVector<String>();
                    xmlv.add("Accept");
                    xmlv.add(h_Accept);
                    httpParameters.add(xmlv);
                    if (h_Accept.equals(MimeType.Xml.value())) {
                        transaction = new XmlHttpTransaction();
                        ((XmlHttpTransaction) transaction).setXmlEncoding("UTF-8");
                    } else if (h_Accept.equals(MimeType.Json.value())) {
                        transaction = new JsonHttpTransaction();
                        ((JsonHttpTransaction) transaction).setIncludeDataType(false);
                    }
                }
                if (h_ContentType != null) {
                    XMLVector<String> xmlv = new XMLVector<String>();
                    xmlv.add(HeaderName.ContentType.value());
                    xmlv.add(h_ContentType);
                    httpParameters.add(xmlv);
                }
                String operationId = "";
                if (verb.has("operationId")) {
                    operationId = verb.getString("operationId");
                }
                String summary = "";
                if (verb.has("summary")) {
                    summary = verb.getString("summary");
                }
                String description = "";
                if (verb.has("description")) {
                    description = verb.getString("description");
                }
                String name = StringUtils.normalize(operationId);
                if (name.isEmpty()) {
                    name = StringUtils.normalize(summary);
                    if (name.isEmpty()) {
                        name = "operation";
                    }
                }
                String comment = summary;
                if (comment.isEmpty()) {
                    comment = description;
                }
                JSONArray parameters = new JSONArray();
                if (verb.has("parameters")) {
                    parameters = verb.getJSONArray("parameters");
                    for (int i = 0; i < parameters.length(); i++) {
                        JSONObject parameter = (JSONObject) parameters.get(i);
                        String type = "string";
                        if (parameter.has("collectionFormat")) {
                            type = parameter.getString("type");
                        }
                        String collectionFormat = "csv";
                        if (parameter.has("collectionFormat")) {
                            collectionFormat = parameter.getString("collectionFormat");
                        }
                        boolean isMultiValued = type.equalsIgnoreCase("array") && collectionFormat.equals("multi");
                        RequestableHttpVariable httpVariable = isMultiValued ? new RequestableHttpMultiValuedVariable() : new RequestableHttpVariable();
                        httpVariable.bNew = true;
                        httpVariable.setName(parameter.getString("name"));
                        httpVariable.setHttpName(parameter.getString("name"));
                        String in = parameter.getString("in");
                        if (in.equals("query") || in.equals("path") || in.equals("header")) {
                            httpVariable.setHttpMethod(HttpMethodType.GET.name());
                            if (in.equals("header")) {
                                // overrides variable's name : will be treated as dynamic header
                                httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpHeader.getName() + parameter.getString("name"));
                                // do not post on target server
                                httpVariable.setHttpName("");
                            }
                        } else if (in.equals("formData") || in.equals("body")) {
                            httpVariable.setHttpMethod(HttpMethodType.POST.name());
                            if (in.equals("body")) {
                                // overrides variable's name for internal use
                                httpVariable.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpBody.getName());
                                // add internal __contentType variable
                                RequestableHttpVariable ct = new RequestableHttpVariable();
                                ct.setName(com.twinsoft.convertigo.engine.enums.Parameter.HttpContentType.getName());
                                // do not post on target server
                                ct.setHttpName("");
                                ct.setHttpMethod(HttpMethodType.POST.name());
                                ct.setValueOrNull(null);
                                ct.bNew = true;
                                transaction.addVariable(ct);
                                // 
                                if (parameter.has("schema")) {
                                // String schema = parameter.getString("schema");
                                }
                            }
                        } else {
                            httpVariable.setHttpMethod("");
                        }
                        Object defaultValue = null;
                        if (parameter.has("default")) {
                            defaultValue = parameter.get("default");
                        }
                        if (defaultValue == null && type.equalsIgnoreCase("array")) {
                            JSONObject items = parameter.getJSONObject("items");
                            if (items.has("default")) {
                                defaultValue = items.get("default");
                            }
                        }
                        httpVariable.setValueOrNull(defaultValue);
                        if (parameter.has("description")) {
                            httpVariable.setDescription(parameter.getString("description"));
                        }
                        transaction.addVariable(httpVariable);
                    }
                }
                transaction.bNew = true;
                transaction.setName(name);
                transaction.setComment(comment);
                transaction.setSubDir(subDir);
                transaction.setHttpVerb(HttpMethodType.valueOf(httpVerb.toUpperCase()));
                transaction.setHttpParameters(httpParameters);
                transaction.setHttpInfo(true);
                httpConnector.add(transaction);
            }
        }
        return httpConnector;
    } catch (Throwable t) {
        System.out.println(t);
        throw new Exception("Invalid Swagger format", t);
    }
}
Also used : XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HttpTransaction(com.twinsoft.convertigo.beans.transactions.HttpTransaction) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) HashMap(java.util.HashMap) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) JSONArray(org.codehaus.jettison.json.JSONArray) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractHttpTransaction(com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction) JSONObject(org.codehaus.jettison.json.JSONObject) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) JsonHttpTransaction(com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 2 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class WsReference method importSoapWebService.

private static HttpConnector importSoapWebService(Project project, WebServiceReference soapServiceReference) throws Exception {
    List<HttpConnector> connectors = new ArrayList<HttpConnector>();
    HttpConnector firstConnector = null;
    String wsdlUrl = soapServiceReference.getUrlpath();
    WsdlProject wsdlProject = new WsdlProject();
    WsdlInterface[] wsdls = WsdlImporter.importWsdl(wsdlProject, wsdlUrl);
    int len = wsdls.length;
    if (len > 0) {
        WsdlInterface iface = wsdls[len - 1];
        if (iface != null) {
            // Retrieve definition name or first service name
            String definitionName = null;
            try {
                Definition definition = iface.getWsdlContext().getDefinition();
                QName qname = definition.getQName();
                qname = (qname == null ? (QName) definition.getAllServices().keySet().iterator().next() : qname);
                definitionName = qname.getLocalPart();
            } catch (Exception e1) {
                throw new Exception("No service found !");
            }
            // Modify reference's name
            if (soapServiceReference.bNew) {
                // Note : new reference may have already been added to the project (new object wizard)
                // its name must be replaced with a non existing one !
                String newDatabaseObjectName = project.getChildBeanName(project.getReferenceList(), StringUtils.normalize("Import_WS_" + definitionName), true);
                soapServiceReference.setName(newDatabaseObjectName);
            }
            // Retrieve directory for WSDLs to download
            File exportDir = null;
            /* For further use...
				if (!webServiceReference.getFilepath().isEmpty()) {	// for update case
					try {
						exportDir = webServiceReference.getFile().getParentFile();
						if (exportDir.exists()) {
							File destDir = exportDir;
					   		for (int index = 0; destDir.exists(); index++) {
					   			destDir = new File(exportDir.getPath()+ "/v" + index);
					   		}
							Collection<File> files = GenericUtils.cast(FileUtils.listFiles(exportDir, null, false));
							for (File file: files) {
								FileUtils.copyFileToDirectory(file, destDir);
							}
						}
					} catch (Exception ex) {}
				}*/
            if (soapServiceReference.bNew || exportDir == null) {
                // for other cases
                String projectDir = project.getDirPath();
                exportDir = new File(projectDir + "/wsdl/" + definitionName);
                for (int index = 1; exportDir.exists(); index++) {
                    exportDir = new File(projectDir + "/wsdl/" + definitionName + index);
                }
            }
            // Download all needed WSDLs (main one and imported/included ones)
            String wsdlPath = iface.getWsdlContext().export(exportDir.getPath());
            // Modify reference's filePath : path to local main WSDL
            String wsdlUriPath = new File(wsdlPath).toURI().getPath();
            String wsdlLocalPath = ".//" + wsdlUriPath.substring(wsdlUriPath.indexOf("/wsdl") + 1);
            soapServiceReference.setFilepath(wsdlLocalPath);
            soapServiceReference.hasChanged = true;
            // Add reference to project
            if (soapServiceReference.getParent() == null) {
                project.add(soapServiceReference);
            }
            // create an HTTP connector for each binding
            if (soapServiceReference.bNew) {
                for (int i = 0; i < wsdls.length; i++) {
                    iface = wsdls[i];
                    if (iface != null) {
                        Definition definition = iface.getWsdlContext().getDefinition();
                        XmlSchemaCollection xmlSchemaCollection = WSDLUtils.readSchemas(definition);
                        XmlSchema xmlSchema = xmlSchemaCollection.schemaForNamespace(definition.getTargetNamespace());
                        HttpConnector httpConnector = createSoapConnector(iface);
                        if (httpConnector != null) {
                            String bindingName = iface.getBindingName().getLocalPart();
                            String newDatabaseObjectName = project.getChildBeanName(project.getConnectorsList(), StringUtils.normalize(bindingName), true);
                            httpConnector.setName(newDatabaseObjectName);
                            boolean hasDefaultTransaction = false;
                            for (int j = 0; j < iface.getOperationCount(); j++) {
                                WsdlOperation wsdlOperation = (WsdlOperation) iface.getOperationAt(j);
                                XmlHttpTransaction xmlHttpTransaction = createSoapTransaction(xmlSchema, iface, wsdlOperation, project, httpConnector);
                                // Adds transaction
                                if (xmlHttpTransaction != null) {
                                    httpConnector.add(xmlHttpTransaction);
                                    if (!hasDefaultTransaction) {
                                        xmlHttpTransaction.setByDefault();
                                        hasDefaultTransaction = true;
                                    }
                                }
                            }
                            connectors.add(httpConnector);
                        }
                    }
                }
                // add connector(s) to project
                for (HttpConnector httpConnector : connectors) {
                    project.add(httpConnector);
                    if (firstConnector == null) {
                        firstConnector = httpConnector;
                    }
                }
            }
        }
    } else {
        throw new Exception("No interface found !");
    }
    return firstConnector;
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) ArrayList(java.util.ArrayList) Definition(javax.wsdl.Definition) WsdlProject(com.eviware.soapui.impl.wsdl.WsdlProject) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WsdlOperation(com.eviware.soapui.impl.wsdl.WsdlOperation) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) File(java.io.File)

Example 3 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class TransactionWithVariables method getRequestString.

public String getRequestString(Context context) {
    checkSubLoaded();
    List<String> vVariables = new ArrayList<String>(variables.size());
    // Use authenticated user as cache key
    if (isAuthenticatedUserAsCacheKey())
        vVariables.add("userID=" + context.getAuthenticatedUser());
    for (String variableName : variables.keySet()) {
        if (includeVariableIntoRequestString(variableName)) {
            String variableValueAsString = ParameterUtils.toString(variables.get(variableName));
            vVariables.add(variableName + "=" + variableValueAsString);
        }
    }
    if (bIncludeCertificateGroup) {
        try {
            CertificateManager certificateManager = ((HttpConnector) getParent()).certificateManager;
            certificateManager.collectStoreInformation(context);
            if ((certificateManager.keyStoreGroup == null) || (certificateManager.keyStoreGroup.length() == 0)) {
                vVariables.add("certificateGroup=" + certificateManager.keyStoreName);
            } else {
                vVariables.add("certificateGroup=" + certificateManager.keyStoreGroup);
            }
        } catch (EngineException e) {
            vVariables.add("certificateGroup=exception");
        }
    }
    Collections.sort(vVariables);
    String requestString = context.projectName + " " + context.transactionName + " " + vVariables.toString();
    return requestString;
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException) CertificateManager(com.twinsoft.convertigo.engine.CertificateManager)

Example 4 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class Biller method insertCariocaBilling.

public void insertCariocaBilling(Context context, Object data) throws EngineException {
    String sSqlRequest = null;
    try {
        Engine.logBillers.debug("[Biller] Trying to insert the billing into a Carioca database ");
        sqlRequester.checkConnection();
        int cache = 0;
        double cost = getCost(context, data);
        if (cost == -1) {
            Engine.logBillers.debug("[Biller] Billing aborted because the returned cost is -1, i.e. do not need to bill.");
            return;
        } else if (cost == -2) {
            Engine.logBillers.debug("[Biller] Billing zero cost because the response was in cache.");
            cost = 0;
            cache = 1;
        }
        Connector connector = context.getConnector();
        CertificateManager certificateManager = null;
        if (connector instanceof HttpConnector) {
            certificateManager = ((HttpConnector) connector).certificateManager;
        } else if (connector instanceof SiteClipperConnector) {
            certificateManager = ((SiteClipperConnector) connector).certificateManager;
        }
        if (!certificateManager.storeInformationCollected) {
            certificateManager.collectStoreInformation(context);
        }
        String certificate = new File(certificateManager.keyStore).getName();
        int idx = certificate.indexOf('.');
        if (idx != -1) {
            certificate = certificate.substring(0, idx);
        }
        Statement statement = null;
        long startBilling = System.currentTimeMillis();
        try {
            Engine.logBillers.debug("[Biller] Replacements from the context done");
            StringEx sqlRequest = new StringEx(sqlRequester.getProperty(Biller.PROPERTIES_SQL_REQUEST_INSERT_BILLING));
            try {
                Engine.logBillers.debug("[Biller] Replacing TAS IDs");
                sqlRequest.replace("{IDSVR}", context.get("IDSVR").toString());
                sqlRequest.replace("{IDSERV}", context.get("IDSERV").toString());
                sqlRequest.replace("{IDUSER}", context.get("IDUSER").toString());
                sqlRequest.replace("{IDPROF}", context.get("IDPROF").toString());
                sqlRequest.replace("{IDEMUL}", context.get("IDEMUL").toString());
                Engine.logBillers.debug("[Biller] Replacing TAS variables");
                sqlRequest.replaceSQL("{NomSv}", context.tasVirtualServerName, '\'');
                sqlRequest.replaceSQL("{UserName}", context.tasUserName, '\'');
                sqlRequest.replaceSQL("{UserGroup}", context.tasUserGroup, '\'');
                sqlRequest.replaceSQL("{Service}", getService(context, data), '\'');
                Engine.logBillers.debug("[Biller] Replacing POBI variables");
                sqlRequest.replace("{cdbanque}", context.get("cdbanque").toString());
                sqlRequest.replace("{cdguichet}", context.get("cdguichet").toString());
                sqlRequest.replaceSQL("{certificat}", certificate, '\'');
                sqlRequest.replace("{cache}", Integer.toString(cache));
                sqlRequest.replaceSQL("{module}", getModule(context, data), '\'');
                sqlRequest.replaceSQL("{userdata}", context.get("userdata").toString(), '\'');
                sqlRequest.replaceSQL("{BDFKey}", getDataKey(context, data), '\'');
                sqlRequest.replaceSQL("{UserGroupAuto}", context.get("UserGroupAuto").toString(), '\'');
            } catch (NullPointerException e) {
                throw new EngineException("One parameter for SQL replacement is missing.", e);
            }
            Calendar rightNow = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat(sqlRequester.getProperty(Biller.PROPERTIES_SQL_DATE_FORMAT));
            String date = df.format(rightNow.getTime());
            sqlRequest.replace("{StartHour}", date);
            sqlRequest.replace("{EndHour}", date);
            Engine.logBillers.debug("[Biller] Start and End hour computed");
            sqlRequest.replace("{Cost}", Double.toString(cost));
            Engine.logBillers.debug("[Biller] Cost computed");
            sSqlRequest = sqlRequest.toString();
            Engine.logBillers.debug("[Biller] SQL: " + sSqlRequest);
            statement = sqlRequester.connection.createStatement();
            int nResult = statement.executeUpdate(sSqlRequest);
            Engine.logBillers.debug("[Biller] " + nResult + " row(s) inserted.");
        } finally {
            if (statement != null) {
                statement.close();
            }
            Engine.logBillers.info("[Biller] insertCariocaBilling, 1 request in " + (System.currentTimeMillis() - startBilling) + " ms");
        }
    } catch (SQLException e) {
        Engine.logBillers.warn("[Biller] Unable to insert the billing.\n" + e.getMessage() + " (error code: " + e.getErrorCode() + ")\nSQL: " + sSqlRequest);
    } catch (Exception e) {
        Engine.logBillers.error("[Biller] Unable to insert the billing", e);
    }
}
Also used : SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Calendar(java.util.Calendar) IOException(java.io.IOException) SQLException(java.sql.SQLException) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) StringEx(com.twinsoft.util.StringEx) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with HttpConnector

use of com.twinsoft.convertigo.beans.connectors.HttpConnector in project convertigo by convertigo.

the class Get method createCategories.

private void createCategories(Document document, DatabaseObject dbo, Class<? extends DatabaseObject> databaseObjectClass, Element root) throws Exception {
    Element response = document.createElement("response");
    try {
        List<String> defaultDboList = new ArrayList<>();
        Class<? extends DatabaseObject> parentObjectClass = dbo.getClass();
        Map<String, DboCategoryData> categoryNameToDboCategory = new HashMap<>();
        DboExplorerManager manager = Engine.theApp.getDboExplorerManager();
        for (DboGroup group : manager.getGroups()) {
            for (DboCategory category : group.getCategories()) {
                for (DboBeans beansCategory : category.getBeans()) {
                    for (DboBean bean : beansCategory.getBeans()) {
                        // Skip if bean is disabled
                        if (!bean.isEnable()) {
                            continue;
                        }
                        String className = bean.getClassName();
                        try {
                            Class<DatabaseObject> beanClass = GenericUtils.cast(Class.forName(className));
                            DboCategoryInfo dboCategoryInfo = DatabaseObject.getDboGroupInfo(beanClass);
                            if (dboCategoryInfo == null) {
                                continue;
                            }
                            // If one of these cases, do not add the category
                            if (dbo instanceof ScreenClass) {
                                ScreenClass sc = (ScreenClass) dbo;
                                // Do not show Criteria category if it is the default Screen Class
                                if (sc.getDepth() == 0 && dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Criteria.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof CicsConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof JavelinConnector) {
                                // Do not show ScreenClass category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SqlConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HtmlConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HttpConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SiteClipperConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof Transaction) {
                                // Do not show Statement category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Statement.class))) {
                                    continue;
                                }
                            }
                            if (bean.isDefault()) {
                                defaultDboList.add(className);
                            }
                            // The bean should derived from
                            // DatabaseObject...
                            boolean isDatabaseObject = (DatabaseObject.class.isAssignableFrom(beanClass));
                            if (isDatabaseObject) {
                                // ... and should derived from the specified class
                                boolean isFromSpecifiedClass = (databaseObjectClass == null || (databaseObjectClass != null && databaseObjectClass.isAssignableFrom(beanClass)));
                                if (isFromSpecifiedClass) {
                                    // Check parent
                                    boolean bFound = DatabaseObjectsManager.checkParent(parentObjectClass, bean);
                                    if (bFound) {
                                        String technology = DboUtils.getTechnology(dbo, beanClass);
                                        // Check technology if needed
                                        if (technology != null) {
                                            Collection<String> acceptedTechnologies = bean.getEmulatorTechnologies();
                                            if (!acceptedTechnologies.isEmpty() && !acceptedTechnologies.contains(technology)) {
                                                continue;
                                            }
                                        }
                                        String beanInfoClassName = className + "BeanInfo";
                                        Class<BeanInfo> beanInfoClass = GenericUtils.cast(Class.forName(beanInfoClassName));
                                        if (beanInfoClass != null) {
                                            String categoryName = dboCategoryInfo.getCategoryName();
                                            // Create category
                                            DboCategoryData dboCategoryData = categoryNameToDboCategory.get(categoryName);
                                            if (dboCategoryData == null) {
                                                dboCategoryData = new DboCategoryData(dboCategoryInfo.getCategoryId(), categoryName, dboCategoryInfo.getIconClassCSS());
                                                categoryNameToDboCategory.put(categoryName, dboCategoryData);
                                            }
                                            // Beans name
                                            String beansName = beansCategory.getName();
                                            if (beansName.length() == 0) {
                                                beansName = categoryName;
                                            }
                                            // Create beans
                                            DboBeansData dboBeansData = dboCategoryData.getDboBeans(beansName);
                                            if (dboBeansData == null) {
                                                dboBeansData = new DboBeansData(beansName);
                                                dboCategoryData.addDboBeans(beansName, dboBeansData);
                                            }
                                            // Create bean
                                            DboBeanData dboBeanData = new DboBeanData(beanInfoClass.getConstructor().newInstance());
                                            dboBeansData.addDboBean(dboBeanData);
                                        } else {
                                            String message = java.text.MessageFormat.format("The \"{0}\" does not exist.", new Object[] { beanInfoClassName });
                                            throw new Exception(message);
                                        }
                                    }
                                }
                            } else {
                                String message = java.text.MessageFormat.format("The \"{0}\" class is not a Convertigo database object.", new Object[] { className });
                                throw new Exception(message);
                            }
                        } catch (ClassNotFoundException e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" class.\n\nClass not found: {1}", new Object[] { className, e.getMessage() });
                            throw new Exception(message);
                        } catch (Throwable e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" Convertigo database object.", new Object[] { className });
                            throw new Exception(message);
                        }
                    }
                }
            }
        }
        // Find the default selected bean for each categories
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            boolean defaultDboFound = false;
            List<DboBeanData> dboBeansList = dboCategory.getAllDboBean(true);
            // By default, we chose the first bean as default selected bean
            DboBeanData defaultSelectedBean = dboBeansList.get(0);
            // Find the default selected bean
            for (int i = 0; i < dboBeansList.size() && !defaultDboFound; ++i) {
                Class<DatabaseObject> beanClass = dboBeansList.get(i).getBeanClass();
                // Another bean is set as default selected bean
                if (defaultDboFound = defaultDboList.contains(beanClass.getName())) {
                    defaultSelectedBean = dboBeansList.get(i);
                }
            }
            defaultSelectedBean.setSelectedByDefault(true);
        }
        // XmlLize
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            response.appendChild(dboCategory.toXml(document));
        }
    } catch (Exception e) {
        throw new Exception("Unable to load database objects properties.");
    }
    root.appendChild(response);
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) HashMap(java.util.HashMap) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) Element(org.w3c.dom.Element) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) DboCategory(com.twinsoft.convertigo.engine.dbo_explorer.DboCategory) DboBeansData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeansData) DboBeanData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeanData) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) DboCategoryInfo(com.twinsoft.convertigo.beans.core.DatabaseObject.DboCategoryInfo) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) DboCategoryData(com.twinsoft.convertigo.beans.dbo_explorer.DboCategoryData) DboGroup(com.twinsoft.convertigo.engine.dbo_explorer.DboGroup) DboExplorerManager(com.twinsoft.convertigo.engine.dbo_explorer.DboExplorerManager) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBeans(com.twinsoft.convertigo.engine.dbo_explorer.DboBeans) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Transaction(com.twinsoft.convertigo.beans.core.Transaction) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBean(com.twinsoft.convertigo.engine.dbo_explorer.DboBean)

Aggregations

HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)21 EngineException (com.twinsoft.convertigo.engine.EngineException)9 IOException (java.io.IOException)9 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)6 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)5 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)5 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)5 HttpTransaction (com.twinsoft.convertigo.beans.transactions.HttpTransaction)5 XmlHttpTransaction (com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction)5 File (java.io.File)5 JsonHttpTransaction (com.twinsoft.convertigo.beans.transactions.JsonHttpTransaction)4 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)3 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)3 SapJcoConnector (com.twinsoft.convertigo.beans.connectors.SapJcoConnector)3 Connector (com.twinsoft.convertigo.beans.core.Connector)3 Project (com.twinsoft.convertigo.beans.core.Project)3 AbstractHttpTransaction (com.twinsoft.convertigo.beans.transactions.AbstractHttpTransaction)3