Search in sources :

Example 1 with Project

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

the class SwaggerUtils method parse.

public static Swagger parse(String requestUrl, UrlMapper urlMapper) {
    Project project = urlMapper.getProject();
    String projectName = project.getName();
    String oasDirUrl = requestUrl.substring(0, requestUrl.indexOf("/" + servletMappingPath)) + "/projects/" + projectName + "/" + jsonSchemaDirectory + "/";
    Swagger swagger = parseCommon(requestUrl, project);
    List<Tag> tags = new ArrayList<Tag>();
    Tag tag = new Tag();
    tag.setName(urlMapper.getProject().getName());
    tag.setDescription(urlMapper.getProject().getComment());
    tags.add(tag);
    swagger.setTags(tags);
    // Security
    Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
    for (UrlAuthentication authentication : urlMapper.getAuthenticationList()) {
        if (AuthenticationType.Basic.equals(authentication.getType())) {
            if (securityDefinitions == null || !securityDefinitions.containsKey("basicAuth")) {
                BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition();
                swagger.addSecurityDefinition("basicAuth", basicAuthDefinition);
                SecurityRequirement securityRequirement = new SecurityRequirement();
                securityRequirement.requirement("basicAuth", new ArrayList<String>());
                swagger.addSecurity(securityRequirement);
            }
        }
    }
    // Models and Schemas
    Map<String, Model> swagger_models = new HashMap<String, Model>();
    try {
        String models = getModels(oasDirUrl, urlMapper);
        if (!models.isEmpty()) {
            ObjectMapper mapper = Json.mapper();
            JsonNode definitionNode = mapper.readTree(models);
            for (Iterator<Entry<String, JsonNode>> it = GenericUtils.cast(definitionNode.fields()); it.hasNext(); ) {
                Entry<String, JsonNode> entry = it.next();
                swagger_models.put(entry.getKey().toString(), mapper.convertValue(entry.getValue(), Model.class));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Engine.logEngine.warn("Unexpected exception while reading UrlMapper defined models", e);
    }
    swagger.setDefinitions(swagger_models);
    // Mappings
    Map<String, Path> swagger_paths = new HashMap<String, Path>();
    try {
        for (UrlMapping urlMapping : urlMapper.getMappingList()) {
            Path swagger_path = new Path();
            for (UrlMappingOperation umo : urlMapping.getOperationList()) {
                Operation s_operation = new Operation();
                s_operation.setOperationId(umo.getQName());
                s_operation.setDescription(umo.getComment());
                s_operation.setSummary(umo.getComment());
                // Operation produces
                if (umo instanceof AbstractRestOperation) {
                    DataContent dataOutput = ((AbstractRestOperation) umo).getOutputContent();
                    if (dataOutput.equals(DataContent.toJson)) {
                        s_operation.setProduces(Arrays.asList(MimeType.Json.value()));
                    } else if (dataOutput.equals(DataContent.toXml)) {
                        s_operation.setProduces(Arrays.asList(MimeType.Xml.value()));
                    } else {
                        s_operation.setProduces(Arrays.asList(MimeType.Json.value(), MimeType.Xml.value()));
                    }
                }
                // Operation tags
                List<String> list = Arrays.asList("" + project.getName());
                s_operation.setTags(list);
                // Operation consumes
                List<String> consumes = new ArrayList<String>();
                // Operation parameters
                List<Parameter> s_parameters = new ArrayList<Parameter>();
                // 1 - add path parameters
                for (String pathVarName : urlMapping.getPathVariableNames()) {
                    PathParameter s_parameter = new PathParameter();
                    s_parameter.setName(pathVarName);
                    s_parameter.setRequired(true);
                    s_parameter.setType("string");
                    // retrieve parameter description from bean
                    UrlMappingParameter ump = null;
                    try {
                        ump = umo.getParameterByName(pathVarName);
                    } catch (Exception e) {
                    }
                    if (ump != null && ump.getType() == Type.Path) {
                        s_parameter.setDescription(ump.getComment());
                        s_parameter.setType(ump.getInputType().toLowerCase());
                        Object value = ump.getValueOrNull();
                        if (value != null) {
                            s_parameter.setDefaultValue(String.valueOf(value));
                        }
                    }
                    s_parameters.add(s_parameter);
                }
                // 2 - add other parameters
                for (UrlMappingParameter ump : umo.getParameterList()) {
                    Parameter s_parameter = null;
                    if (ump.getType() == Type.Query) {
                        s_parameter = new QueryParameter();
                    } else if (ump.getType() == Type.Form) {
                        s_parameter = new FormParameter();
                    } else if (ump.getType() == Type.Body) {
                        s_parameter = new BodyParameter();
                        if (ump instanceof IMappingRefModel) {
                            String modelReference = ((IMappingRefModel) ump).getModelReference();
                            if (!modelReference.isEmpty()) {
                                if (modelReference.indexOf(".jsonschema") != -1) {
                                    modelReference = oasDirUrl + modelReference;
                                }
                                RefModel refModel = new RefModel(modelReference);
                                ((BodyParameter) s_parameter).setSchema(refModel);
                            }
                        }
                    } else if (ump.getType() == Type.Header) {
                        s_parameter = new HeaderParameter();
                    } else if (ump.getType() == Type.Path) {
                    // ignore : should have been treated before
                    }
                    if (s_parameter != null) {
                        s_parameter.setName(ump.getName());
                        s_parameter.setDescription(ump.getComment());
                        s_parameter.setRequired(ump.isRequired());
                        if (s_parameter instanceof SerializableParameter) {
                            boolean isArray = ump.isMultiValued() || ump.isArray();
                            String _type = isArray ? "array" : ump.getDataType().name().toLowerCase();
                            String _collectionFormat = ump.isMultiValued() ? "multi" : (isArray ? "csv" : null);
                            Property _items = isArray ? getItems(ump.getDataType()) : null;
                            ((SerializableParameter) s_parameter).setType(_type);
                            ((SerializableParameter) s_parameter).setCollectionFormat(_collectionFormat);
                            ((SerializableParameter) s_parameter).setItems(_items);
                            Object value = ump.getValueOrNull();
                            if (value != null) {
                                String collection = ((SerializableParameter) s_parameter).getCollectionFormat();
                                if (collection != null && collection.equals("multi")) {
                                    Property items = new StringProperty();
                                    // items.setDefault(String.valueOf(value));
                                    ((SerializableParameter) s_parameter).setItems(items);
                                // ((SerializableParameter) s_parameter).setEnumValue(Arrays.asList("val1","val2","val3"));
                                } else {
                                    ((AbstractSerializableParameter<?>) s_parameter).setDefaultValue(String.valueOf(value));
                                }
                            }
                        }
                        DataContent dataInput = ump.getInputContent();
                        if (dataInput.equals(DataContent.toJson)) {
                            if (!consumes.contains(MimeType.Json.value())) {
                                consumes.add(MimeType.Json.value());
                            }
                        } else if (dataInput.equals(DataContent.toXml)) {
                            if (!consumes.contains(MimeType.Xml.value())) {
                                consumes.add(MimeType.Xml.value());
                            }
                        }
                        // swagger-ui workaround for invalid request content-type for POST
                        if (ump.getType() == Type.Form) {
                            if (!DataType.File.equals(ump.getDataType())) {
                                if (!consumes.contains(MimeType.WwwForm.value())) {
                                    consumes.add(MimeType.WwwForm.value());
                                }
                            } else {
                                if (!consumes.contains("multipart/form-data")) {
                                    consumes.add("multipart/form-data");
                                }
                            }
                        }
                        // add parameter
                        if (ump.isExposed()) {
                            s_parameters.add(s_parameter);
                        }
                    }
                }
                s_operation.setParameters(s_parameters);
                if (!consumes.isEmpty()) {
                    s_operation.setConsumes(consumes);
                }
                // Set operation responses
                Map<String, Response> responses = new HashMap<String, Response>();
                for (UrlMappingResponse umr : umo.getResponseList()) {
                    String statusCode = umr.getStatusCode();
                    if (!statusCode.isEmpty()) {
                        if (!responses.containsKey(statusCode)) {
                            Response response = new Response();
                            // response.setDescription(umr.getComment());
                            response.setDescription(umr.getStatusText());
                            if (umr instanceof IMappingRefModel) {
                                String modelReference = ((IMappingRefModel) umr).getModelReference();
                                if (!modelReference.isEmpty()) {
                                    if (modelReference.indexOf(".jsonschema") != -1) {
                                        modelReference = oasDirUrl + modelReference;
                                    }
                                    RefProperty refProperty = new RefProperty(modelReference);
                                    response.setResponseSchema(new PropertyModelConverter().propertyToModel(refProperty));
                                }
                            }
                            responses.put(statusCode, response);
                        }
                    }
                }
                if (responses.isEmpty()) {
                    Response resp200 = new Response();
                    resp200.description("successful operation");
                    responses.put("200", resp200);
                }
                s_operation.setResponses(responses);
                // Add operation to path
                String s_method = umo.getMethod().toLowerCase();
                swagger_path.set(s_method, s_operation);
            }
            swagger_paths.put(urlMapping.getPathWithPrefix(), swagger_path);
        }
    } catch (Exception e) {
        e.printStackTrace();
        Engine.logEngine.error("Unexpected exception while parsing UrlMapper to generate definition", e);
    }
    swagger.setPaths(swagger_paths);
    return swagger;
}
Also used : UrlMapping(com.twinsoft.convertigo.beans.core.UrlMapping) SerializableParameter(io.swagger.models.parameters.SerializableParameter) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) AbstractRestOperation(com.twinsoft.convertigo.beans.rest.AbstractRestOperation) RefModel(io.swagger.models.RefModel) IMappingRefModel(com.twinsoft.convertigo.beans.core.IMappingRefModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) PropertyModelConverter(io.swagger.models.utils.PropertyModelConverter) DataContent(com.twinsoft.convertigo.beans.core.UrlMappingParameter.DataContent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Project(com.twinsoft.convertigo.beans.core.Project) JSONObject(org.codehaus.jettison.json.JSONObject) IMappingRefModel(com.twinsoft.convertigo.beans.core.IMappingRefModel) QueryParameter(io.swagger.models.parameters.QueryParameter) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) UrlMappingResponse(com.twinsoft.convertigo.beans.core.UrlMappingResponse) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) AbstractRestOperation(com.twinsoft.convertigo.beans.rest.AbstractRestOperation) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) RefProperty(io.swagger.models.properties.RefProperty) Entry(java.util.Map.Entry) Swagger(io.swagger.models.Swagger) HeaderParameter(io.swagger.models.parameters.HeaderParameter) StringProperty(io.swagger.models.properties.StringProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) Path(io.swagger.models.Path) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) SecuritySchemeDefinition(io.swagger.models.auth.SecuritySchemeDefinition) BasicAuthDefinition(io.swagger.models.auth.BasicAuthDefinition) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Response(io.swagger.models.Response) UrlMappingResponse(com.twinsoft.convertigo.beans.core.UrlMappingResponse) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) IMappingRefModel(com.twinsoft.convertigo.beans.core.IMappingRefModel) SerializableParameter(io.swagger.models.parameters.SerializableParameter) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) Tag(io.swagger.models.Tag) UrlAuthentication(com.twinsoft.convertigo.beans.core.UrlAuthentication) SecurityRequirement(io.swagger.models.SecurityRequirement)

Example 2 with Project

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

the class ClipboardAction method paste.

public void paste(String source, Shell shell, ProjectExplorerView explorerView, TreeObject selectedTreeObject, boolean isDND) throws ConvertigoException, IOException, ParserConfigurationException, SAXException, CoreException {
    if ((explorerView != null) && (selectedTreeObject != null)) {
        TreeObject targetTreeObject = null;
        Object targetObject = null;
        if (selectedTreeObject instanceof FolderTreeObject) {
            if (selectedTreeObject.getParent() instanceof IDesignTreeObject) {
                selectedTreeObject = selectedTreeObject.getParent();
            }
        }
        if (selectedTreeObject instanceof IPropertyTreeObject) {
            targetTreeObject = selectedTreeObject;
            targetObject = selectedTreeObject;
        } else if (selectedTreeObject instanceof IDesignTreeObject) {
            targetTreeObject = selectedTreeObject;
            targetObject = selectedTreeObject;
            if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_DOCUMENT) {
                targetTreeObject = ((IDesignTreeObject) selectedTreeObject).getTreeObjectOwner();
                targetObject = (DatabaseObject) targetTreeObject.getObject();
            }
        } else {
            // case of folder, retrieve owner object
            targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(selectedTreeObject);
            targetObject = (DatabaseObject) targetTreeObject.getObject();
            // i.e. without having to select the parent database object.
            if (clipboardManager.objectsType == ProjectExplorerView.getTreeObjectType(new TreePath(targetTreeObject))) {
                // it must be different from the currently selected object.
                if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_SCREEN_CLASS) {
                    CustomDialog customDialog = new CustomDialog(shell, "Paste a Screenclass", "Do you want to paste the Screenclass as a sibling or as an inherited ScreenClass?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As an iherited", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
                    int response = customDialog.open();
                    if (response == 0)
                        targetObject = ((DatabaseObject) targetObject).getParent();
                    else if (response == 2)
                        return;
                } else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STATEMENT_WITH_EXPRESSIONS) {
                    if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_FUNCTION) {
                        targetObject = ((DatabaseObject) targetObject).getParent();
                    } else {
                        CustomDialog customDialog = new CustomDialog(shell, "Paste a statement", "Do you want to paste the statement as a sibling or a child statement?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As a child", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
                        int response = customDialog.open();
                        if (response == 0) {
                            targetObject = ((DatabaseObject) targetObject).getParent();
                        } else if (response == 2) {
                            return;
                        }
                    }
                } else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_MOBILE_UICOMPONENT) {
                    if (!clipboardManager.isCut) {
                        CustomDialog customDialog = new CustomDialog(shell, "Paste a Component", "Do you want to paste the Component as a sibling or as a child component?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As a child", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
                        int response = customDialog.open();
                        if (response == 0) {
                            targetObject = ((DatabaseObject) targetObject).getParent();
                        } else if (response == 2) {
                            return;
                        }
                    }
                } else if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP_WITH_EXPRESSIONS || clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP) {
                    targetObject = pasteStep(shell, source, (DatabaseObject) targetObject);
                    if (targetObject == null)
                        return;
                } else if (isDND && clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_SEQUENCE) {
                // Do not change target to parent
                } else {
                    targetObject = ((DatabaseObject) targetObject).getParent();
                }
                targetTreeObject = explorerView.findTreeObjectByUserObject(((DatabaseObject) targetObject));
            } else {
                if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP_WITH_EXPRESSIONS || clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP) {
                    targetObject = pasteStep(shell, source, (DatabaseObject) targetObject);
                    if (targetObject == null)
                        return;
                }
            }
        }
        if (clipboardManager.isCut) {
            TreeParent targetTreeParent = null;
            String targetPath = targetTreeObject.getPath();
            if (targetTreeObject instanceof DatabaseObjectTreeObject) {
                targetTreeParent = ((DatabaseObjectTreeObject) targetTreeObject).getOwnerDatabaseObjectTreeObject();
            } else if (targetTreeObject instanceof IPropertyTreeObject) {
                targetTreeParent = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
            } else if (targetTreeObject instanceof IDesignTreeObject) {
                targetTreeParent = ((IDesignTreeObject) targetTreeObject).getTreeObjectOwner();
            }
            for (int i = 0; i < clipboardManager.objects.length; i++) {
                // Cut & paste
                clipboardManager.cutAndPaste(clipboardManager.objects[i], targetTreeObject);
                // Updating the tree
                // Report 4.5: fix #401
                // explorerView.reloadTreeObject(clipboardManager.parentTreeNodeOfCutObjects[i]);
                TreeObject parentTreeNodeOfCutObjects = clipboardManager.parentTreeNodeOfCutObjects[i];
                parentTreeNodeOfCutObjects.getProjectTreeObject().hasBeenModified(true);
                if (!(parentTreeNodeOfCutObjects instanceof IDesignTreeObject)) {
                    explorerView.reloadTreeObject(parentTreeNodeOfCutObjects);
                }
            }
            if (targetTreeObject != null) {
                if (targetTreeObject.getParent() == null)
                    targetTreeObject = explorerView.findTreeObjectByPath(targetTreeParent, targetPath);
                if (targetTreeObject != null)
                    // Report 4.5: fix #401
                    targetTreeObject.getProjectTreeObject().hasBeenModified(true);
            }
            clipboardManager.reset();
        } else if (source != null) {
            // Paste
            clipboardManager.paste(source, targetObject, true);
            // Case of project copy
            if (clipboardManager.objectsType == ProjectExplorerView.TREE_OBJECT_TYPE_DBO_PROJECT) {
                Object[] pastedObjects = clipboardManager.pastedObjects;
                for (int i = 0; i < pastedObjects.length; i++) {
                    Object object = pastedObjects[i];
                    if ((object != null) && (object instanceof Project)) {
                        Project project = (Project) object;
                        String oldName = project.getName();
                        try {
                            Project importedProject = importProjectTempArchive(oldName, explorerView);
                            if (importedProject != null) {
                                String newName = importedProject.getName();
                                explorerView.importProjectTreeObject(newName, true, oldName);
                            } else
                                throw new EngineException("Unable to import project temporary archive");
                        } catch (Exception e) {
                            throw new EngineException("Unable to paste project", e);
                        }
                    }
                }
            }
        }
        // Updating the tree
        if (targetTreeObject != null) {
            TreeObject treeObjectToReload = targetTreeObject;
            TreeObject treeObjectToSelect = targetTreeObject;
            if (targetTreeObject instanceof IPropertyTreeObject) {
                treeObjectToSelect = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
                treeObjectToReload = treeObjectToSelect;
                if (treeObjectToReload instanceof DatabaseObjectTreeObject) {
                    treeObjectToReload = treeObjectToReload.getParent();
                    if (treeObjectToReload instanceof FolderTreeObject)
                        treeObjectToReload = treeObjectToReload.getParent();
                }
            }
            if (targetTreeObject instanceof IDesignTreeObject) {
                treeObjectToSelect = ((IDesignTreeObject) targetTreeObject).getTreeObjectOwner();
                treeObjectToReload = treeObjectToSelect;
                if (treeObjectToReload instanceof DatabaseObjectTreeObject) {
                    treeObjectToReload = treeObjectToReload.getParent();
                    if (treeObjectToReload instanceof FolderTreeObject)
                        treeObjectToReload = treeObjectToReload.getParent();
                }
            }
            if (treeObjectToReload != null) {
                // explorerView.reloadTreeObject(targetTreeObject);
                // explorerView.setSelectedTreeObject(targetTreeObject);
                explorerView.objectChanged(new CompositeEvent(treeObjectToReload.getObject(), treeObjectToSelect.getPath()));
            }
        }
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) EngineException(com.twinsoft.convertigo.engine.EngineException) CoreException(org.eclipse.core.runtime.CoreException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) CustomDialog(com.twinsoft.convertigo.eclipse.dialogs.CustomDialog) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ButtonSpec(com.twinsoft.convertigo.eclipse.dialogs.ButtonSpec) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Example 3 with Project

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

the class ClipboardAction method makeProjectTempArchive.

private void makeProjectTempArchive(ProjectTreeObject projectTreeObject) throws EngineException {
    Project project = projectTreeObject.getObject();
    try {
        File exportDirectory = new File(Engine.USER_WORKSPACE_PATH + "/temp");
        if (!exportDirectory.exists())
            exportDirectory.mkdir();
        String exportDirectoryPath = exportDirectory.getCanonicalPath();
        CarUtils.makeArchive(exportDirectoryPath, project);
    } catch (Exception e) {
        throw new EngineException("Unable to make a project copy archive", e);
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) EngineException(com.twinsoft.convertigo.engine.EngineException) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 4 with Project

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

the class ClipboardAction method importProjectTempArchive.

private Project importProjectTempArchive(String projectName, ProjectExplorerView explorerView) throws EngineException {
    try {
        // Get an available target project name
        int index = 1;
        String targetProjectName = projectName;
        while (explorerView.getProjectRootObject(targetProjectName) != null) {
            targetProjectName = projectName + index++;
        }
        // Get the original temporary project archive
        File importDirectory = new File(Engine.USER_WORKSPACE_PATH + "/temp");
        if (!importDirectory.exists())
            importDirectory.mkdir();
        String importDirectoryPath, importArchiveFilename;
        importDirectoryPath = importDirectory.getCanonicalPath();
        importArchiveFilename = importDirectoryPath + "/" + projectName + ".car";
        // Deploy archive to target project
        Project importedProject = Engine.theApp.databaseObjectsManager.deployProject(importArchiveFilename, targetProjectName, true, true);
        // Try to delete archive
        try {
            new File(importArchiveFilename).delete();
        } catch (Exception e) {
        }
        return importedProject;
    } catch (Exception e) {
        throw new EngineException("Unable to import project archive", e);
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) EngineException(com.twinsoft.convertigo.engine.EngineException) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 5 with Project

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

the class DatabaseObjectDeleteAction method delete.

private void delete(DatabaseObject databaseObject, boolean deleteProjectOnDisk) throws EngineException, CoreException {
    if (databaseObject instanceof Connector) {
        if (((Connector) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default connector!");
        }
        String dirPath, projectName;
        File dir;
        projectName = databaseObject.getParent().getName();
        MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        messageBox.setText("Also delete linked resources?");
        // Delete soap templates for this connector
        dirPath = Engine.projectDir(projectName) + "/soap-templates/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
        // Delete directory corresponding to connector under Traces directory
        dirPath = Engine.projectDir(projectName) + "/Traces/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
    } else if (databaseObject instanceof Transaction) {
        if (((Transaction) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default transaction!");
        }
    } else if (databaseObject instanceof ScreenClass) {
        if ((databaseObject.getParent()) instanceof Project) {
            throw new EngineException("Cannot delete the root screen class!");
        }
    } else if (databaseObject instanceof Statement) {
        if ((databaseObject instanceof ThenStatement) || (databaseObject instanceof ElseStatement)) {
            throw new EngineException("Cannot delete this statement!");
        }
    } else if (databaseObject instanceof Step) {
        if ((databaseObject instanceof ThenStep) || (databaseObject instanceof ElseStep)) {
            throw new EngineException("Cannot delete this step!");
        }
    } else if (databaseObject instanceof MobilePlatform) {
        MobilePlatform mobilePlatform = (MobilePlatform) databaseObject;
        File resourceFolder = mobilePlatform.getResourceFolder();
        if (resourceFolder.exists()) {
            MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("Do you want to delete the whole resource folder \"" + mobilePlatform.getRelativeResourcePath() + "\"?");
            messageBox.setText("Delete the \"" + resourceFolder.getName() + "\" folder?");
            if (messageBox.open() == SWT.YES) {
                FileUtils.deleteQuietly(resourceFolder);
            }
        }
    } else if (databaseObject instanceof PageComponent) {
        if (((PageComponent) databaseObject).isRoot) {
            throw new EngineException("Cannot delete the root page!");
        }
    }
    String dboQName = databaseObject.getQName();
    if (databaseObject instanceof Project) {
        // Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName());
        if (deleteProjectOnDisk) {
            Engine.theApp.databaseObjectsManager.deleteProjectAndCar(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        } else {
            Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        }
        ConvertigoPlugin.getDefault().deleteProjectPluginResource(deleteProjectOnDisk, databaseObject.getName());
    } else {
        databaseObject.delete();
    }
    if (databaseObject instanceof CouchDbConnector) {
        CouchDbConnector couchDbConnector = (CouchDbConnector) databaseObject;
        String db = couchDbConnector.getDatabaseName();
        if (!db.isEmpty()) {
            MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
            messageBox.setMessage("Do you want to delete the \"" + db + "\" database from the CouchDb server?");
            messageBox.setText("Delete the database?");
            if (messageBox.open() == SWT.YES) {
                couchDbConnector.getCouchClient().deleteDatabase(db);
            }
        }
    }
    ConvertigoPlugin.logDebug("The object \"" + dboQName + "\" has been deleted from the database repository!");
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) EngineException(com.twinsoft.convertigo.engine.EngineException) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) IOException(java.io.IOException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) MessageBox(org.eclipse.swt.widgets.MessageBox) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Project(com.twinsoft.convertigo.beans.core.Project) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) File(java.io.File)

Aggregations

Project (com.twinsoft.convertigo.beans.core.Project)144 EngineException (com.twinsoft.convertigo.engine.EngineException)53 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)47 IOException (java.io.IOException)37 Sequence (com.twinsoft.convertigo.beans.core.Sequence)35 Connector (com.twinsoft.convertigo.beans.core.Connector)33 File (java.io.File)33 ArrayList (java.util.ArrayList)29 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)25 Transaction (com.twinsoft.convertigo.beans.core.Transaction)24 JSONException (org.codehaus.jettison.json.JSONException)24 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)21 SAXException (org.xml.sax.SAXException)21 Step (com.twinsoft.convertigo.beans.core.Step)19 CoreException (org.eclipse.core.runtime.CoreException)19 Element (org.w3c.dom.Element)19 JSONObject (org.codehaus.jettison.json.JSONObject)17 IProject (org.eclipse.core.resources.IProject)17 Shell (org.eclipse.swt.widgets.Shell)17 WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)16