Search in sources :

Example 41 with DatabaseObject

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

the class GetChildren method getChildren.

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

Example 42 with DatabaseObject

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

the class Set method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element root = document.getDocumentElement();
    String[] qnames = request.getParameterValues("qnames[]");
    // Remove duplicates if someone sends the qname more than once
    java.util.Set<String> uniqueQnames = new HashSet<>(Arrays.asList(qnames));
    for (String objectQName : uniqueQnames) {
        // Create the response : success or fail
        Element response = document.createElement("response");
        response.setAttribute("qname", objectQName);
        try {
            String value = request.getParameter("value");
            String property = request.getParameter("property");
            DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(objectQName);
            // Check if we try to update project name
            if (dbo instanceof Project && "name".equals(property)) {
                Project project = (Project) dbo;
                String objectNewName = getPropertyValue(dbo, property, value).toString();
                Engine.theApp.databaseObjectsManager.renameProject(project, objectNewName);
            }
            BeanInfo bi = CachedIntrospector.getBeanInfo(dbo.getClass());
            PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors();
            boolean propertyFound = false;
            for (int i = 0; !propertyFound && i < propertyDescriptors.length; ++i) {
                String propertyName = propertyDescriptors[i].getName();
                initialPropertyElt = dbo.toXml(document, propertyName);
                // Find the property we want to change
                if (propertyFound = propertyName.equals(property)) {
                    Method setter = propertyDescriptors[i].getWriteMethod();
                    Class<?> propertyTypeClass = propertyDescriptors[i].getReadMethod().getReturnType();
                    if (propertyTypeClass.isPrimitive()) {
                        propertyTypeClass = ClassUtils.primitiveToWrapper(propertyTypeClass);
                    }
                    try {
                        String propertyValue = getPropertyValue(dbo, propertyName, value).toString();
                        Object oPropertyValue = com.twinsoft.convertigo.engine.admin.services.database_objects.Set.createObject(propertyTypeClass, propertyValue);
                        if (dbo.isCipheredProperty(propertyName)) {
                            Method getter = propertyDescriptors[i].getReadMethod();
                            String initialPropertyValue = (String) getter.invoke(dbo, (Object[]) null);
                            if (oPropertyValue.equals(initialPropertyValue) || DatabaseObject.encryptPropertyValue(initialPropertyValue).equals(oPropertyValue)) {
                                oPropertyValue = initialPropertyValue;
                            } else {
                                dbo.hasChanged = true;
                            }
                        }
                        // Update property value
                        if (oPropertyValue != null) {
                            Object[] args = { oPropertyValue };
                            setter.invoke(dbo, args);
                        }
                    } catch (IllegalArgumentException e) {
                        throw e;
                    }
                }
            }
            // Invalid given property parameter
            if (!propertyFound) {
                throw new IllegalArgumentException("Property '" + property + "' not found for object '" + dbo.getQName() + "'");
            }
            response.setAttribute("state", "success");
            response.setAttribute("message", "Property " + property + " has been successfully updated.");
            Element elt = dbo.toXml(document, property);
            elt.setAttribute("name", dbo.toString());
            elt.setAttribute("hasChanged", Boolean.toString(dbo.hasChanged));
            response.appendChild(elt);
        } catch (Exception e) {
            Engine.logAdmin.error("Error during saving the properties!\n" + e.getMessage());
            response.setAttribute("state", "error");
            response.setAttribute("message", "Error during saving the properties!");
            // To restore the original value
            response.appendChild(initialPropertyElt);
        } finally {
            root.appendChild(response);
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Element(org.w3c.dom.Element) BeanInfo(java.beans.BeanInfo) Method(java.lang.reflect.Method) TransformerException(javax.xml.transform.TransformerException) Project(com.twinsoft.convertigo.beans.core.Project) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) HashSet(java.util.HashSet)

Example 43 with DatabaseObject

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

the class DboUtils method getTechnology.

public static String getTechnology(DatabaseObject parentObject, Class<? extends DatabaseObject> objectClass) {
    String technology = null;
    DatabaseObject parent = parentObject;
    if (parent != null) {
        // case of Variable
        if (Variable.class.isAssignableFrom(objectClass)) {
            return technology = parent.getClass().getName();
        }
        // parent is a connector
        if (parent instanceof Connector) {
            return technology = ((Connector) parent).getClass().getName();
        }
        // parent is a sequence
        if (parent instanceof Sequence) {
            return technology = ((Sequence) parent).getClass().getName();
        }
        // parent is a statement
        if (parent instanceof Statement) {
            return technology = "com.twinsoft.convertigo.beans.statements.BlockStatement";
        }
        // parent is a step
        if (parent instanceof Step) {
            technology = "com.twinsoft.convertigo.beans.steps.BlockStep";
            if (getClassName(parent.getClass()).startsWith("XML")) {
                technology = parent.getClass().getName();
            }
            return technology;
        }
        // parent is a transaction
        if (parent instanceof Transaction) {
            if (parent instanceof HtmlTransaction) {
                return technology = "com.twinsoft.convertigo.beans.transactions.HtmlTransaction";
            } else if (parent instanceof SiteClipperTransaction) {
                return technology = "com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction";
            }
        }
        // parent is a screenclass
        if (parent instanceof ScreenClass) {
            while ((parent = parent.getParent()) instanceof ScreenClass) {
                ;
            }
            if (parent instanceof JavelinConnector)
                technology = ((JavelinConnector) parent).getEmulatorTechnology();
            if (parent instanceof HtmlConnector)
                technology = "com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass";
            if (parent instanceof SiteClipperConnector)
                technology = "com.twinsoft.convertigo.beans.screenclasses.SiteClipperScreenClass";
        }
    }
    return technology;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Statement(com.twinsoft.convertigo.beans.core.Statement) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) SiteClipperTransaction(com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Step(com.twinsoft.convertigo.beans.core.Step) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) SiteClipperTransaction(com.twinsoft.convertigo.beans.transactions.SiteClipperTransaction) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 44 with DatabaseObject

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

the class MobileSmartSourcePropertyDescriptor method getTags.

public static String[] getTags(DatabaseObjectTreeObject databaseObjectTreeObject, String propertyName) {
    DatabaseObject bean = (DatabaseObject) databaseObjectTreeObject.getObject();
    ITagsProperty tagsProperty = null;
    if (bean instanceof ITagsProperty) {
        tagsProperty = (ITagsProperty) bean;
    } else {
        return new String[] { "" };
    }
    String[] sResults = tagsProperty.getTagsForProperty(propertyName);
    return sResults;
}
Also used : ITagsProperty(com.twinsoft.convertigo.beans.core.ITagsProperty) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 45 with DatabaseObject

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

the class MobileSmartSourceTypeCellEditor method getTags.

private String[] getTags() {
    if (databaseObjectTreeObject != null && propertyDescriptor != null) {
        String propertyName = (String) propertyDescriptor.getId();
        DatabaseObject bean = (DatabaseObject) databaseObjectTreeObject.getObject();
        if (bean instanceof ITagsProperty) {
            return ((ITagsProperty) bean).getTagsForProperty(propertyName);
        }
    }
    return new String[] { "" };
}
Also used : ITagsProperty(com.twinsoft.convertigo.beans.core.ITagsProperty) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

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