Search in sources :

Example 1 with PathParameter

use of com.twinsoft.convertigo.beans.rest.PathParameter in project convertigo by convertigo.

the class UrlMappingTreeObject method treeObjectPropertyChanged.

@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
    super.treeObjectPropertyChanged(treeObjectEvent);
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
        // Case Mapping path has changed
        if ("path".equals(propertyName)) {
            if (treeObject.equals(this)) {
                try {
                    UrlMapping urlMapping = (UrlMapping) databaseObject;
                    String oldPath = (String) treeObjectEvent.oldValue;
                    List<String> oldPathVariableNames = urlMapping.getPathVariableNames(oldPath);
                    List<String> newPathVariableNames = urlMapping.getPathVariableNames();
                    if (!oldPathVariableNames.equals(newPathVariableNames)) {
                        int oldLen = oldPathVariableNames.size();
                        int newLen = newPathVariableNames.size();
                        /*MessageBox messageBox = new MessageBox(viewer.getControl().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); 
							messageBox.setMessage("Do you really want to update mapping path parameters?");
							messageBox.setText("Update parameters\"?");
							int ret = messageBox.open();*/
                        int ret = SWT.YES;
                        if (ret == SWT.YES) {
                            // case of deletion
                            if (newLen < oldLen) {
                                for (String variableName : oldPathVariableNames) {
                                    if (!newPathVariableNames.contains(variableName)) {
                                        for (UrlMappingOperation operation : urlMapping.getOperationList()) {
                                            for (UrlMappingParameter parameter : operation.getParameterList()) {
                                                if (parameter.getName().equals(variableName)) {
                                                    if (parameter.getType().equals(Type.Path)) {
                                                        try {
                                                            parameter.delete();
                                                            operation.remove(parameter);
                                                            operation.hasChanged = true;
                                                        } catch (EngineException e) {
                                                            ConvertigoPlugin.logException(e, "Error when deleting the parameter \"" + variableName + "\"");
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } else // case of rename
                            if (newLen == oldLen) {
                                for (int i = 0; i < oldLen; i++) {
                                    String variableName = oldPathVariableNames.get(i);
                                    for (UrlMappingOperation operation : urlMapping.getOperationList()) {
                                        for (UrlMappingParameter parameter : operation.getParameterList()) {
                                            if (parameter.getName().equals(variableName)) {
                                                if (parameter.getType().equals(Type.Path)) {
                                                    try {
                                                        parameter.setName(newPathVariableNames.get(i));
                                                        parameter.hasChanged = true;
                                                    } catch (EngineException e) {
                                                        ConvertigoPlugin.logException(e, "Error when renaming the parameter \"" + variableName + "\"");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } else // case of creation
                            {
                                for (String variableName : newPathVariableNames) {
                                    for (UrlMappingOperation operation : urlMapping.getOperationList()) {
                                        UrlMappingParameter parameter = null;
                                        try {
                                            parameter = operation.getParameterByName(variableName);
                                        } catch (EngineException e) {
                                            try {
                                                parameter = new PathParameter();
                                                parameter.setName(variableName);
                                                parameter.bNew = true;
                                                operation.add(parameter);
                                            } catch (EngineException ex) {
                                                ConvertigoPlugin.logException(ex, "Error when adding the parameter \"" + variableName + "\"");
                                            }
                                        }
                                    }
                                }
                            }
                            getProjectExplorerView().reloadTreeObject(this);
                        }
                    }
                } catch (Exception e) {
                    ConvertigoPlugin.logWarning(e, "Could not reload in tree Mapping \"" + databaseObject.getName() + "\" !");
                }
            }
        }
    }
}
Also used : UrlMapping(com.twinsoft.convertigo.beans.core.UrlMapping) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PathParameter(com.twinsoft.convertigo.beans.rest.PathParameter) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 2 with PathParameter

use of com.twinsoft.convertigo.beans.rest.PathParameter in project convertigo by convertigo.

the class UrlMappingTreeObject method treeObjectAdded.

@Override
public void treeObjectAdded(TreeObjectEvent treeObjectEvent) {
    super.treeObjectAdded(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
        try {
            boolean needReload = false;
            UrlMapping urlMapping = getObject();
            // An UrlMappingOperation has been added : add all path parameters
            if (databaseObject instanceof UrlMappingOperation) {
                if (urlMapping.equals(databaseObject.getParent())) {
                    UrlMappingOperation operation = (UrlMappingOperation) databaseObject;
                    if (operation.bNew) {
                        for (String variableName : urlMapping.getPathVariableNames()) {
                            UrlMappingParameter parameter = null;
                            try {
                                parameter = operation.getParameterByName(variableName);
                            } catch (EngineException e) {
                                try {
                                    parameter = new PathParameter();
                                    parameter.setName(variableName);
                                    parameter.bNew = true;
                                    operation.add(parameter);
                                    operation.hasChanged = true;
                                    needReload = true;
                                } catch (EngineException ex) {
                                    ConvertigoPlugin.logException(ex, "Error when adding the parameter \"" + variableName + "\"");
                                }
                            }
                        }
                    }
                    if (needReload) {
                        getProjectExplorerView().reloadTreeObject(this);
                    }
                }
            }
        } catch (Exception e) {
            ConvertigoPlugin.logWarning(e, "Could not reload in tree Mapping \"" + databaseObject.getName() + "\" !");
        }
    }
}
Also used : UrlMapping(com.twinsoft.convertigo.beans.core.UrlMapping) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PathParameter(com.twinsoft.convertigo.beans.rest.PathParameter) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 UrlMapping (com.twinsoft.convertigo.beans.core.UrlMapping)2 UrlMappingOperation (com.twinsoft.convertigo.beans.core.UrlMappingOperation)2 UrlMappingParameter (com.twinsoft.convertigo.beans.core.UrlMappingParameter)2 PathParameter (com.twinsoft.convertigo.beans.rest.PathParameter)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2