Search in sources :

Example 1 with InvalidSourceException

use of com.twinsoft.convertigo.engine.InvalidSourceException in project convertigo by convertigo.

the class UIComponent method preconfigure.

@Override
public void preconfigure(Element element) throws Exception {
    super.preconfigure(element);
    String version = element.getAttribute("version");
    long priority = Long.valueOf(element.getAttribute("priority")).longValue();
    // TODO: REMOVE BEFORE RELEASE !!!
    boolean doMigration = false;
    if (!doMigration) {
        return;
    }
    if (VersionUtils.compare(version, "7.9.0") < 0) {
        try {
            NodeList properties = element.getElementsByTagName("property");
            int len = properties.getLength();
            Element propElement;
            for (int i = 0; i < len; i++) {
                propElement = (Element) properties.item(i);
                if (propElement != null && propElement.getParentNode().equals(element)) {
                    String propertyName = propElement.getAttribute("name");
                    Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
                    if (valueElement != null) {
                        Document document = valueElement.getOwnerDocument();
                        Object content = XMLUtils.readObjectFromXml(valueElement);
                        // This is data of the peusdo-bean
                        if ("beanData".equals(propertyName) && content instanceof String) {
                            try {
                                boolean needChange = false;
                                List<String> logList = new ArrayList<String>();
                                IonBean ionBean = new IonBean((String) content);
                                List<IonProperty> propertyList = new ArrayList<IonProperty>();
                                propertyList.addAll(ionBean.getProperties().values());
                                // Walk through properties
                                for (IonProperty ionProperty : propertyList) {
                                    String ionPropertyName = ionProperty.getName();
                                    String modeUpperCase = ionProperty.getMode().toUpperCase();
                                    if (Mode.SOURCE.equals(Mode.valueOf(modeUpperCase))) {
                                        MobileSmartSourceType msst = ionProperty.getSmartType();
                                        String smartValue = msst.getSmartValue();
                                        if (smartValue != null && !smartValue.isEmpty()) {
                                            try {
                                                MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
                                                if (mss != null) {
                                                    boolean migrated = !smartValue.equals(mss.toJsonString());
                                                    if (migrated) {
                                                        msst.setSmartValue(mss.toJsonString());
                                                        ionBean.setPropertyValue(ionPropertyName, msst);
                                                        needChange = true;
                                                        logList.add("Done migration of \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
                                                    }
                                                }
                                            } catch (Exception e) {
                                                if (e instanceof InvalidSourceException) {
                                                    Engine.logBeans.warn("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
                                                } else {
                                                    Engine.logBeans.error("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                                                }
                                            }
                                        }
                                    }
                                }
                                // Store new beandata property value
                                if (needChange) {
                                    String beanData = ionBean.toBeanData();
                                    Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, beanData);
                                    propElement.replaceChild(newValueElement, valueElement);
                                    hasChanged = true;
                                    logList.forEach(s -> Engine.logBeans.warn(s));
                                }
                            } catch (Exception e) {
                                Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                            }
                        } else // This is a MobileSmartSourceType property
                        if (content instanceof MobileSmartSourceType) {
                            MobileSmartSourceType msst = (MobileSmartSourceType) content;
                            // Property is in 'SRC' mode
                            if (Mode.SOURCE.equals(msst.getMode())) {
                                try {
                                    String smartValue = msst.getSmartValue();
                                    if (smartValue != null && !smartValue.isEmpty()) {
                                        MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
                                        if (mss != null) {
                                            boolean migrated = !smartValue.equals(mss.toJsonString());
                                            if (migrated) {
                                                msst.setSmartValue(mss.toJsonString());
                                                // Store new property value
                                                Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, msst);
                                                propElement.replaceChild(newValueElement, valueElement);
                                                hasChanged = true;
                                                Engine.logBeans.warn("Done migration of \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    if (e instanceof InvalidSourceException) {
                                        Engine.logBeans.warn("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
                                    } else {
                                        Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new EngineException("Unable to preconfigure the mobile uicomponent \"" + getName() + "\".", e);
        }
    }
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException) Document(org.w3c.dom.Document) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 2 with InvalidSourceException

use of com.twinsoft.convertigo.engine.InvalidSourceException in project convertigo by convertigo.

the class UIComponent method preconfigure.

@Override
public void preconfigure(Element element) throws Exception {
    super.preconfigure(element);
    String version = element.getAttribute("version");
    long priority = Long.valueOf(element.getAttribute("priority")).longValue();
    // TODO: REMOVE BEFORE RELEASE !!!
    boolean doMigration = false;
    if (!doMigration) {
        return;
    }
    if (VersionUtils.compare(version, "7.9.0") < 0) {
        try {
            NodeList properties = element.getElementsByTagName("property");
            int len = properties.getLength();
            Element propElement;
            for (int i = 0; i < len; i++) {
                propElement = (Element) properties.item(i);
                if (propElement != null && propElement.getParentNode().equals(element)) {
                    String propertyName = propElement.getAttribute("name");
                    Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
                    if (valueElement != null) {
                        Document document = valueElement.getOwnerDocument();
                        Object content = XMLUtils.readObjectFromXml(valueElement);
                        // This is data of the peusdo-bean
                        if ("beanData".equals(propertyName) && content instanceof String) {
                            try {
                                boolean needChange = false;
                                List<String> logList = new ArrayList<String>();
                                IonBean ionBean = new IonBean((String) content);
                                List<IonProperty> propertyList = new ArrayList<IonProperty>();
                                propertyList.addAll(ionBean.getProperties().values());
                                // Walk through properties
                                for (IonProperty ionProperty : propertyList) {
                                    String ionPropertyName = ionProperty.getName();
                                    String modeUpperCase = ionProperty.getMode().toUpperCase();
                                    if (Mode.SOURCE.equals(Mode.valueOf(modeUpperCase))) {
                                        MobileSmartSourceType msst = ionProperty.getSmartType();
                                        String smartValue = msst.getSmartValue();
                                        if (smartValue != null && !smartValue.isEmpty()) {
                                            try {
                                                MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
                                                if (mss != null) {
                                                    boolean migrated = !smartValue.equals(mss.toJsonString());
                                                    if (migrated) {
                                                        msst.setSmartValue(mss.toJsonString());
                                                        ionBean.setPropertyValue(ionPropertyName, msst);
                                                        needChange = true;
                                                        logList.add("Done migration of \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
                                                    }
                                                }
                                            } catch (Exception e) {
                                                if (e instanceof InvalidSourceException) {
                                                    Engine.logBeans.warn("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
                                                } else {
                                                    Engine.logBeans.error("Failed to migrate \"" + ionPropertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                                                }
                                            }
                                        }
                                    }
                                }
                                // Store new beandata property value
                                if (needChange) {
                                    String beanData = ionBean.toBeanData();
                                    Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, beanData);
                                    propElement.replaceChild(newValueElement, valueElement);
                                    hasChanged = true;
                                    logList.forEach(s -> Engine.logBeans.warn(s));
                                }
                            } catch (Exception e) {
                                Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                            }
                        } else // This is a MobileSmartSourceType property
                        if (content instanceof MobileSmartSourceType) {
                            MobileSmartSourceType msst = (MobileSmartSourceType) content;
                            // Property is in 'SRC' mode
                            if (Mode.SOURCE.equals(msst.getMode())) {
                                try {
                                    String smartValue = msst.getSmartValue();
                                    if (smartValue != null && !smartValue.isEmpty()) {
                                        MobileSmartSource mss = MobileSmartSource.migrate(smartValue);
                                        if (mss != null) {
                                            boolean migrated = !smartValue.equals(mss.toJsonString());
                                            if (migrated) {
                                                msst.setSmartValue(mss.toJsonString());
                                                // Store new property value
                                                Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, msst);
                                                propElement.replaceChild(newValueElement, valueElement);
                                                hasChanged = true;
                                                Engine.logBeans.warn("Done migration of \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")");
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    if (e instanceof InvalidSourceException) {
                                        Engine.logBeans.warn("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + "): " + e.getMessage());
                                    } else {
                                        Engine.logBeans.error("Failed to migrate \"" + propertyName + "\" property for the object \"" + getName() + "\" (priority: " + priority + ")", e);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new EngineException("Unable to preconfigure the mobile uicomponent \"" + getName() + "\".", e);
        }
    }
}
Also used : IonProperty(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonProperty) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException) Document(org.w3c.dom.Document) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 InvalidSourceException (com.twinsoft.convertigo.engine.InvalidSourceException)2 ArrayList (java.util.ArrayList)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 IonBean (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean)1 IonProperty (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonProperty)1 IonBean (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)1 IonProperty (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty)1