Search in sources :

Example 51 with EngineException

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

the class FileCacheManager method getStoredResponseFromRepository.

protected Document getStoredResponseFromRepository(Requester requester, CacheEntry cacheEntry) throws EngineException {
    FileCacheEntry fileCacheEntry = (FileCacheEntry) cacheEntry;
    Engine.logCacheManager.debug("cacheEntry=[" + cacheEntry.toString() + "]");
    try {
        File file = new File(fileCacheEntry.fileName);
        Document document = XMLUtils.parseDOM(file);
        Engine.logCacheManager.debug("Response built from the cache");
        return document;
    } catch (FileNotFoundException e) {
        Engine.logCacheManager.warn("Unable to find the response [" + cacheEntry.toString() + "] into the cache; the stored response is invalidated.");
        return null;
    } catch (Exception e) {
        throw new EngineException("Unable to get the response [" + cacheEntry.toString() + "] from the cache!", e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) EngineException(com.twinsoft.convertigo.engine.EngineException) Document(org.w3c.dom.Document) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 52 with EngineException

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

the class FileCacheManager method init.

@Override
public void init() throws EngineException {
    File cacheDir = new File(EnginePropertiesManager.getProperty(PropertyName.CACHE_MANAGER_FILECACHE_DIRECTORY));
    try {
        if (cacheDir.exists() && !cacheDir.isDirectory()) {
            Engine.logEngine.error("(FileCacheManager) The 'file cache directory' must be a directory : " + cacheDir);
        } else {
            cacheDir.mkdirs();
            File testWrite = new File(cacheDir, ".testWrite");
            if (testWrite.createNewFile()) {
                testWrite.delete();
                Engine.CACHE_PATH = cacheDir.getCanonicalPath();
            } else {
                Engine.logEngine.error("(FileCacheManager) Failed to write to : " + testWrite);
            }
        }
    } catch (Exception e) {
        Engine.logEngine.error("(FileCacheManager) Failed to write to : " + cacheDir, e);
    }
    super.init();
}
Also used : File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 53 with EngineException

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

the class FileCacheManager method storeResponseToRepository.

protected synchronized CacheEntry storeResponseToRepository(Document response, String requestString, long expiryDate) throws EngineException {
    long index = getNextIndex();
    String fileName = Engine.CACHE_PATH + "/" + Long.toHexString(index) + ".xml";
    try {
        makeDirectory();
        XMLUtils.saveXml(response, fileName, true);
        FileCacheEntry cacheEntry = new FileCacheEntry();
        cacheEntry.requestString = requestString;
        cacheEntry.fileName = fileName;
        cacheEntry.expiryDate = expiryDate;
        Engine.logCacheManager.debug("The response has been stored: [" + cacheEntry + "]");
        return cacheEntry;
    } catch (IOException e) {
        throw new EngineException("Unable to store the response! (requestString: " + requestString + ", file: " + fileName + ")", e);
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException)

Example 54 with EngineException

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

the class FileCacheManager method saveCacheIndex.

protected void saveCacheIndex() throws EngineException {
    String indexFileName = Engine.CACHE_PATH + "/index.dat";
    File file = new File(indexFileName);
    File backupFile = null;
    if (file.exists()) {
        backupFile = new File(Engine.CACHE_PATH + "/index.sav");
        if (backupFile.exists()) {
            if (!backupFile.delete()) {
                Engine.logCacheManager.warn("Unable to delete the backup cache index file: " + backupFile);
            }
        }
        if (!file.renameTo(backupFile)) {
            Engine.logCacheManager.warn("Unable to backup the cache index: " + file + " to " + backupFile);
        }
    }
    try {
        makeDirectory();
        try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(indexFileName))) {
            objectOutputStream.writeObject(cacheIndex);
            objectOutputStream.flush();
        }
    } catch (Exception e) {
        throw new EngineException("Unable to save the cache index.", e);
    }
    if (backupFile != null) {
        if (!backupFile.delete()) {
            Engine.logCacheManager.warn("Unable to delete the backup cache index file.");
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) EngineException(com.twinsoft.convertigo.engine.EngineException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 55 with EngineException

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

the class NgxUIComponentTreeObject method handlesBeanNameChanged.

protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
    DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
    DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    int update = treeObjectEvent.update;
    if (update != TreeObjectEvent.UPDATE_NONE) {
        // Case a UIStackVariable has been renamed
        if (databaseObject instanceof UIStackVariable) {
            UIStackVariable variable = (UIStackVariable) databaseObject;
            UIActionStack stack = variable.getSharedAction();
            if (stack != null) {
                // rename variable for InvokeAction
                if (getObject() instanceof UIDynamicInvoke) {
                    UIDynamicInvoke udi = (UIDynamicInvoke) getObject();
                    if (udi.getSharedActionQName().equals(stack.getQName())) {
                        boolean isLocalProject = variable.getProject().equals(udi.getProject());
                        boolean isSameValue = variable.getName().equals(oldValue);
                        boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                        if (!isSameValue && shouldUpdate) {
                            Iterator<UIComponent> it = udi.getUIComponentList().iterator();
                            while (it.hasNext()) {
                                UIComponent component = (UIComponent) it.next();
                                if (component instanceof UIControlVariable) {
                                    UIControlVariable uicv = (UIControlVariable) component;
                                    if (uicv.getName().equals(oldValue)) {
                                        try {
                                            uicv.setName((String) newValue);
                                            uicv.hasChanged = true;
                                            hasBeenModified(true);
                                            viewer.refresh();
                                            markMainAsDirty(udi);
                                            notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for InvokeAction !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else // Case a UICompVariable has been renamed
        if (databaseObject instanceof UICompVariable) {
            UICompVariable variable = (UICompVariable) databaseObject;
            UISharedComponent comp = variable.getSharedComponent();
            if (comp != null) {
                // rename variable for UseShared
                if (getObject() instanceof UIUseShared) {
                    UIUseShared uus = (UIUseShared) getObject();
                    if (uus.getSharedComponentQName().equals(comp.getQName())) {
                        boolean isLocalProject = variable.getProject().equals(uus.getProject());
                        boolean isSameValue = variable.getName().equals(oldValue);
                        boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                        if (!isSameValue && shouldUpdate) {
                            Iterator<UIComponent> it = uus.getUIComponentList().iterator();
                            while (it.hasNext()) {
                                UIComponent component = (UIComponent) it.next();
                                if (component instanceof UIUseVariable) {
                                    UIUseVariable uicv = (UIUseVariable) component;
                                    if (uicv.getName().equals(oldValue)) {
                                        try {
                                            uicv.setName((String) newValue);
                                            uicv.hasChanged = true;
                                            hasBeenModified(true);
                                            viewer.refresh();
                                            markMainAsDirty(uus);
                                            notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for UseShared !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else // Case a UICompEvent has been renamed
        if (databaseObject instanceof UICompEvent) {
            UICompEvent event = (UICompEvent) databaseObject;
            UISharedComponent comp = event.getSharedComponent();
            if (comp != null) {
                // rename control event for UseShared
                if (getObject() instanceof UIUseShared) {
                    UIUseShared uus = (UIUseShared) getObject();
                    if (uus.getSharedComponentQName().equals(comp.getQName())) {
                        boolean isLocalProject = event.getProject().equals(uus.getProject());
                        boolean isSameValue = event.getName().equals(oldValue);
                        boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                        if (!isSameValue && shouldUpdate) {
                            Iterator<UIComponent> it = uus.getUIComponentList().iterator();
                            while (it.hasNext()) {
                                UIComponent component = (UIComponent) it.next();
                                if (component instanceof UIControlEvent) {
                                    UIControlEvent uice = (UIControlEvent) component;
                                    if (uice.getEventName().equals(oldValue)) {
                                        try {
                                            uice.setEventName((String) newValue);
                                            uice.hasChanged = true;
                                            hasBeenModified(true);
                                            viewer.refresh();
                                            markMainAsDirty(uus);
                                            notifyDataseObjectPropertyChanged(uice, "eventName", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' event for UseShared !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else // Case a RequestableVariable has been renamed
        if (databaseObject instanceof RequestableVariable) {
            RequestableVariable variable = (RequestableVariable) databaseObject;
            DatabaseObject parent = variable.getParent();
            if (getObject() instanceof UIDynamicAction) {
                UIDynamicAction uia = (UIDynamicAction) getObject();
                IonBean ionBean = uia.getIonBean();
                if (ionBean != null) {
                    // rename variable for CallSequenceAction
                    if (ionBean.getName().equals("CallSequenceAction")) {
                        Object p_val = ionBean.getProperty("requestable").getValue();
                        if (!p_val.equals(false)) {
                            if (parent.getQName().equals(p_val.toString())) {
                                boolean isLocalProject = variable.getProject().equals(uia.getProject());
                                boolean isSameValue = variable.getName().equals(oldValue);
                                boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
                                if (!isSameValue && shouldUpdate) {
                                    Iterator<UIComponent> it = uia.getUIComponentList().iterator();
                                    while (it.hasNext()) {
                                        UIComponent component = (UIComponent) it.next();
                                        if (component instanceof UIControlVariable) {
                                            UIControlVariable uicv = (UIControlVariable) component;
                                            if (uicv.getName().equals(oldValue)) {
                                                try {
                                                    uicv.setName((String) newValue);
                                                    uicv.hasChanged = true;
                                                    hasBeenModified(true);
                                                    viewer.refresh();
                                                    markMainAsDirty(uia);
                                                    notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
                                                    break;
                                                } catch (EngineException e) {
                                                    ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for CallSequenceAction !");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : UICompEvent(com.twinsoft.convertigo.beans.ngx.components.UICompEvent) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) EngineException(com.twinsoft.convertigo.engine.EngineException) UIControlVariable(com.twinsoft.convertigo.beans.ngx.components.UIControlVariable) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) UIControlEvent(com.twinsoft.convertigo.beans.ngx.components.UIControlEvent) Iterator(java.util.Iterator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIUseVariable(com.twinsoft.convertigo.beans.ngx.components.UIUseVariable) HashSet(java.util.HashSet) UICompVariable(com.twinsoft.convertigo.beans.ngx.components.UICompVariable) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) UIStackVariable(com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Aggregations

EngineException (com.twinsoft.convertigo.engine.EngineException)426 IOException (java.io.IOException)155 File (java.io.File)117 Element (org.w3c.dom.Element)84 NodeList (org.w3c.dom.NodeList)64 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)62 Document (org.w3c.dom.Document)43 JSONObject (org.codehaus.jettison.json.JSONObject)41 Node (org.w3c.dom.Node)40 Project (com.twinsoft.convertigo.beans.core.Project)35 ArrayList (java.util.ArrayList)35 JSONException (org.codehaus.jettison.json.JSONException)33 Sequence (com.twinsoft.convertigo.beans.core.Sequence)31 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)29 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)27 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)25 Connector (com.twinsoft.convertigo.beans.core.Connector)24 HashMap (java.util.HashMap)23 Transaction (com.twinsoft.convertigo.beans.core.Transaction)21 ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)20