Search in sources :

Example 86 with DatabaseObject

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

the class BeansDefaultValues method updateBeansDefaultValues.

private static Document updateBeansDefaultValues(Document document) throws Exception {
    try (InputStream dbInputstream = BeansDefaultValues.class.getResourceAsStream("/com/twinsoft/convertigo/beans/database_objects.xml")) {
        Document documentBeansXmlDatabase = XMLUtils.getDefaultDocumentBuilder().parse(dbInputstream);
        TwsCachedXPathAPI xpath = new TwsCachedXPathAPI();
        EnginePropertiesManager.initProperties();
        SortedSet<Node> nodes = new TreeSet<Node>((n1, n2) -> {
            return n1.getNodeValue().compareTo(n2.getNodeValue());
        });
        nodes.addAll(xpath.selectList(documentBeansXmlDatabase, "//bean/@classname"));
        Element beans = document.getDocumentElement();
        if (beans == null) {
            beans = document.createElement("beans");
            document.appendChild(beans);
        }
        String nVersion = VersionUtils.normalizeVersionString(ProductVersion.productVersion);
        for (Node node : nodes) {
            String classname = node.getNodeValue();
            DatabaseObject dbo = (DatabaseObject) Class.forName(classname).getConstructor().newInstance();
            Element def = dbo.toXml(document);
            if (def.hasAttribute("priority")) {
                def.setAttribute("priority", "0");
            }
            Element eBean = getBeanForVersion(xpath, beans, classname, nVersion);
            if (eBean != null) {
                String eVersion = eBean.getAttribute("version");
                eBean.removeAttribute("version");
                if (!checkIsSame(def, eBean)) {
                    if (eVersion.equals(nVersion)) {
                        beans.removeChild(eBean);
                    }
                    def.setAttribute("version", nVersion);
                    beans.insertBefore(def, beans.getFirstChild());
                }
                eBean.setAttribute("version", eVersion);
            } else {
                def.setAttribute("version", nVersion);
                beans.insertBefore(def, beans.getFirstChild());
            }
        }
        ;
        return document;
    }
}
Also used : InputStream(java.io.InputStream) TreeSet(java.util.TreeSet) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Document(org.w3c.dom.Document) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Example 87 with DatabaseObject

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

the class BeansDoc method createBeanElement.

private void createBeanElement(DboBean bean, boolean bEnable) throws Exception {
    String databaseObjectClassName = bean.getClassName();
    Class<?> databaseObjectClass = Class.forName(databaseObjectClassName);
    DatabaseObject databaseObject = (DatabaseObject) databaseObjectClass.getConstructor().newInstance();
    BeanInfo beanInfo = Introspector.getBeanInfo(databaseObjectClass);
    BeanDescriptor databaseObjectBeanDescriptor = beanInfo.getBeanDescriptor();
    String displayName = databaseObjectBeanDescriptor.getDisplayName();
    String normalizedGroupName = normalize(groupName);
    String normalizedCategoryName = normalize(categoryName);
    String normalizedBeansCategoryName = normalize(beansCategoryName);
    String normalizedName = normalize(displayName);
    String path = (normalizedGroupName + "/" + normalizedCategoryName + "/" + normalizedBeansCategoryName + "/" + normalizedName).replaceAll("/+", "/");
    String iconName = MySimpleBeanInfo.getIconName(beanInfo, BeanInfo.ICON_COLOR_32x32);
    String iconPath = iconName.replaceFirst(".*/beans/", "");
    try {
        try (InputStream is = getClass().getResourceAsStream(iconName)) {
            FileUtils.copyInputStreamToFile(is, new File(imageDirectory, iconPath));
        }
    } catch (Exception e) {
        iconName = "/com/twinsoft/convertigo/beans/core/images/default_color_16x16.png";
        iconPath = iconName.replaceFirst(".*/beans/", "");
        try (InputStream is = getClass().getResourceAsStream(iconName)) {
            FileUtils.copyInputStreamToFile(is, new File(imageDirectory, iconPath));
        }
    }
    StringBuilder sb = new StringBuilder();
    String permalink = "reference-manual/convertigo-objects/" + path + "/";
    String metadesc = databaseObjectBeanDescriptor.getShortDescription();
    metadesc = metadesc.replaceAll("<[a-zA-Z]*>|<\\/[a-zA-Z]*>|<br\\/>", " ");
    metadesc = metadesc.replaceAll(":", " ");
    metadesc = metadesc.replaceAll("\\|", " ");
    if (metadesc.length() >= 150)
        metadesc = metadesc.substring(0, 150);
    sb.append("---\n" + "layout: page\n" + "title: " + displayName + "\n" + "sidebar: c8o_sidebar\n" + "permalink: " + permalink + "\n" + "metadesc: " + metadesc + "\n" + "ObjGroup: " + groupName + "\n" + "ObjCatName: " + normalizedBeansCategoryName + "\n" + "ObjName: " + displayName + "\n" + "ObjClass: " + databaseObjectClassName + "\n" + "ObjIcon: /images/beans/" + iconPath + "\n" + "topnav: topnavobj" + "\n" + "---\n");
    if (bEnable) {
        String description = databaseObjectBeanDescriptor.getShortDescription();
        String shortDescription = description;
        String longDescription = "";
        Matcher mDescription = pDescription.matcher(description);
        if (mDescription.matches()) {
            shortDescription = mDescription.group(1);
            if (mDescription.group(2) != null) {
                longDescription = mDescription.group(2);
                longDescription.replaceAll("\\n", "\n\n");
            }
        }
        sb.append("##### " + shortDescription + "\n\n" + longDescription + "\n");
        SortedMap<String, String> properties = new TreeMap<>();
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor databaseObjectPropertyDescriptor : propertyDescriptors) {
            boolean skip = false;
            longDescription = "";
            // Don't display hidden property descriptors
            if (databaseObjectPropertyDescriptor.isHidden()) {
                skip = true;
            }
            Method getter = databaseObjectPropertyDescriptor.getReadMethod();
            Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
            // Only display read/write property descriptors
            if (getter == null || setter == null) {
                skip = true;
            }
            String blackListedForParentClass = (String) databaseObjectPropertyDescriptor.getValue("blackListedForParentClass");
            if (blackListedForParentClass != null) {
                // check
                for (DboParent parent : bean.getParents()) {
                    String parentName = parent.getClassName();
                    if (blackListedForParentClass.equals(parentName)) {
                        skip = true;
                        break;
                    }
                }
            }
            if (skip) {
                continue;
            }
            String category = "standard";
            if (databaseObject instanceof ExtractionRule) {
                category = "configuration";
                if (databaseObjectPropertyDescriptor.isExpert()) {
                    category = "selection";
                }
            } else if (databaseObjectPropertyDescriptor.isExpert()) {
                category = "expert";
            }
            description = databaseObjectPropertyDescriptor.getShortDescription();
            mDescription = pDescription.matcher(description);
            if (mDescription.matches()) {
                description = mDescription.group(1).trim();
                if (mDescription.group(2) != null) {
                    description += "<br/>" + mDescription.group(2).trim();
                }
            }
            String type = databaseObjectPropertyDescriptor.getPropertyType().getSimpleName();
            if ("true".equals("" + databaseObjectPropertyDescriptor.getValue("scriptable"))) {
                type = "JS expression";
            }
            String propDisplayName = databaseObjectPropertyDescriptor.getDisplayName();
            description = description.replace("|", "&#124;");
            String line = propDisplayName + " | " + type + " | " + category + " | " + description + "\n";
            if (category.equals("standard")) {
                category = "0";
            }
            properties.put(category + "_" + propDisplayName, line);
        }
        if (!properties.isEmpty()) {
            sb.append("\nProperty | Type | Category | Description\n--- | --- | --- | ---\n");
            for (String line : properties.values()) {
                sb.append(line);
            }
        }
    } else {
        sb.append("##### Not yet documented.\nFor more information, do not hesitate to contact us in the forum in our Developer Network website: http://www.convertigo.com/itcenter.html\n");
    }
    String toWrite = sb.toString();
    if (!"\n".equals(System.lineSeparator())) {
        toWrite = toWrite.replace("\n", System.lineSeparator());
    }
    FileUtils.write(new File(outputDirectory, path + ".md"), toWrite, "UTF-8");
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) BeanInfo(java.beans.BeanInfo) MySimpleBeanInfo(com.twinsoft.convertigo.beans.core.MySimpleBeanInfo) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) IOException(java.io.IOException) BeanDescriptor(java.beans.BeanDescriptor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) File(java.io.File) DboParent(com.twinsoft.convertigo.engine.dbo_explorer.DboParent)

Example 88 with DatabaseObject

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

the class ProjectSchemaWizardPage method dialogChanged.

private void dialogChanged() {
    if (projectName == null) {
        updateStatus("Please select a project");
        return;
    }
    try {
        DatabaseObject dbo = ((ObjectExplorerWizardPage) getWizard().getPage("ObjectExplorerWizardPage")).getCreatedBean();
        if (dbo != null) {
            if (dbo instanceof ProjectSchemaReference) {
                projectName = ProjectUrlParser.getUrl(projectName);
                ((ProjectSchemaReference) dbo).setProjectName(projectName);
            }
        }
    } catch (NullPointerException e) {
        updateStatus("New Bean has not been instantiated");
        return;
    }
    updateStatus(null);
}
Also used : ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectExplorerWizardPage(com.twinsoft.convertigo.eclipse.wizards.new_object.ObjectExplorerWizardPage)

Example 89 with DatabaseObject

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

the class AbstractConnectorCompositeWrap method checkEventSource.

protected boolean checkEventSource(EventObject event) {
    boolean isSourceFromConnector = false;
    Object source = event.getSource();
    if (event instanceof ConnectorEvent) {
        if (source instanceof DatabaseObject) {
            Connector connector = ((DatabaseObject) source).getConnector();
            if ((connector != null) && (connector.equals(this.connector)))
                isSourceFromConnector = true;
        }
    }
    return isSourceFromConnector;
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ConnectorEvent(com.twinsoft.convertigo.beans.core.ConnectorEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) EventObject(java.util.EventObject)

Example 90 with DatabaseObject

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

the class NgxComponentCreateAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        int folderType = -1;
        TreeObject parentTreeObject = null;
        DatabaseObject databaseObject = null;
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            parentTreeObject = explorerView.getFirstSelectedTreeObject();
            if (parentTreeObject instanceof ObjectsFolderTreeObject) {
                ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) parentTreeObject;
                folderType = folderTreeObject.folderType;
                parentTreeObject = folderTreeObject.getParent();
                databaseObject = (DatabaseObject) parentTreeObject.getObject();
            } else {
                databaseObject = (DatabaseObject) parentTreeObject.getObject();
            }
            ComponentObjectWizard newObjectWizard = new ComponentObjectWizard(databaseObject, databaseObjectClassName, folderType);
            WizardDialog wzdlg = new WizardDialog(shell, newObjectWizard);
            wzdlg.setPageSize(850, 650);
            wzdlg.open();
            int result = wzdlg.getReturnCode();
            if ((result != Window.CANCEL) && (newObjectWizard.newBean != null)) {
                postCreate(parentTreeObject, newObjectWizard.newBean);
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create a new database object '" + databaseObjectClassName + "'!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Cursor(org.eclipse.swt.graphics.Cursor) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Display(org.eclipse.swt.widgets.Display) ComponentObjectWizard(com.twinsoft.convertigo.eclipse.wizards.new_ngx.ComponentObjectWizard)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)296 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)98 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)97 EngineException (com.twinsoft.convertigo.engine.EngineException)88 Shell (org.eclipse.swt.widgets.Shell)46 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)45 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)43 Cursor (org.eclipse.swt.graphics.Cursor)42 Display (org.eclipse.swt.widgets.Display)42 Sequence (com.twinsoft.convertigo.beans.core.Sequence)41 Project (com.twinsoft.convertigo.beans.core.Project)38 CoreException (org.eclipse.core.runtime.CoreException)36 IOException (java.io.IOException)35 Step (com.twinsoft.convertigo.beans.core.Step)33 ActionModel (com.twinsoft.convertigo.engine.studio.ActionModel)33 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)31 Element (org.w3c.dom.Element)30 ObjectsFolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject)27 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)27 PartInitException (org.eclipse.ui.PartInitException)26