use of com.twinsoft.convertigo.beans.core.UrlMappingOperation 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;
}
use of com.twinsoft.convertigo.beans.core.UrlMappingOperation in project convertigo by convertigo.
the class ReferencesView method handleOperationSelection.
private void handleOperationSelection(Object firstElement) {
UrlMappingOperationTreeObject operationTreeObject = (UrlMappingOperationTreeObject) firstElement;
UrlMappingOperation operationSelected = operationTreeObject.getObject();
String operationSelectedName = operationSelected.getName();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
treeViewer.setInput(null);
RootNode root = new RootNode();
MappingOperationNode operationFolder = new MappingOperationNode(root, operationSelectedName, operationSelected);
root.addChild(operationFolder);
// Operation requires a sequence or a transaction
RequiresNode requiresNode = new RequiresNode(root, "Requires");
try {
String targetRequestableName = operationSelected.getTargetRequestable();
if (!targetRequestableName.isEmpty()) {
handleTargetRequestable(targetRequestableName, projectExplorerView, requiresNode);
}
if (requiresNode.hasChildren()) {
operationFolder.addChild(requiresNode);
}
if (!operationFolder.hasChildren()) {
operationFolder.addChild(new InformationNode(operationFolder, "This operation does not require any sequence or transaction"));
}
treeViewer.setInput(root);
treeViewer.expandAll();
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
}
}
use of com.twinsoft.convertigo.beans.core.UrlMappingOperation in project convertigo by convertigo.
the class ReferencesView method handleProjectSelection.
private void handleProjectSelection(Object firstElement) {
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
Project projectSelected = null;
ProjectTreeObject projectTreeObjectSelected = null;
UnloadedProjectTreeObject unloadedProjectTreeObjectSelected = null;
if (firstElement instanceof ProjectTreeObject) {
projectTreeObjectSelected = (ProjectTreeObject) firstElement;
projectSelected = projectTreeObjectSelected.getObject();
} else if (firstElement instanceof UnloadedProjectTreeObject) {
unloadedProjectTreeObjectSelected = (UnloadedProjectTreeObject) firstElement;
String projectNameSelected = unloadedProjectTreeObjectSelected.getName();
projectSelected = getProject(projectNameSelected, projectExplorerView);
}
if (projectSelected == null) {
return;
}
String projectNameSelected = projectSelected.getName();
treeViewer.setInput(null);
// Get the referencing sequences and transactions
List<Sequence> sequences = projectSelected.getSequencesList();
RootNode root = new RootNode();
ProjectNode projectNode = new ProjectNode(root, projectNameSelected, projectSelected);
root.addChild(projectNode);
// Get all the projects needed to successfully execute the selected project
// i.e. get all CallTransaction and CallSequence steps from the selected project
// that refer to other projects
RequiresNode requiresNode = new RequiresNode(root, "Requires");
// Search for external sequence or transaction referenced by CallSequence or CallTransaction
// from the selected project
List<String> transactionList = new ArrayList<String>();
List<String> sequenceList = new ArrayList<String>();
for (Sequence sequence : sequences) {
List<Step> steps = sequence.getSteps();
for (Step step : steps) {
getRequiredRequestables(step, projectSelected, projectExplorerView, requiresNode, transactionList, sequenceList);
}
}
UrlMapper urlMapper = projectSelected.getUrlMapper();
if (urlMapper != null) {
List<UrlMapping> mappings = urlMapper.getMappingList();
for (UrlMapping mapping : mappings) {
List<UrlMappingOperation> operations = mapping.getOperationList();
for (UrlMappingOperation operation : operations) {
try {
String targetRequestableName = operation.getTargetRequestable();
if (!targetRequestableName.isEmpty() && !targetRequestableName.startsWith(projectNameSelected)) {
handleTargetRequestable(targetRequestableName, projectExplorerView, requiresNode);
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
}
}
}
}
if (requiresNode.hasChildren()) {
projectNode.addChild(requiresNode);
} else {
projectNode.addChild(new InformationNode(projectNode, "This project does not require any other project"));
}
// Get all the projects using the selected project
// i.e. get all CallTransaction and CallSequence steps that refer to transactions
// or sequences from the selected project
IsUsedByNode isUsedByNode = new IsUsedByNode(root, "Is used by");
for (String projectName : projectNames) {
if (!(projectName.equals(projectNameSelected))) {
Project project = getProject(projectName, projectExplorerView);
if (project == null) {
// Unable to load the project, just ignore it
ConvertigoPlugin.logWarning("[References View] Unable to load the project \"" + projectName + "\"", false);
continue;
}
ProjectNode projectFolderExports = new ProjectNode(root, projectName, project);
urlMapper = project.getUrlMapper();
if (urlMapper != null) {
MapperNode mapperNode = new MapperNode(projectFolderExports, urlMapper.getName(), urlMapper);
List<UrlMapping> mappings = urlMapper.getMappingList();
for (UrlMapping mapping : mappings) {
MappingPathNode pathNode = new MappingPathNode(mapperNode, mapping.getPath(), mapping);
List<UrlMappingOperation> operations = mapping.getOperationList();
for (UrlMappingOperation operation : operations) {
String targetRequestable = operation.getTargetRequestable();
if (targetRequestable.startsWith(projectNameSelected + ".")) {
MappingOperationNode operationNode = new MappingOperationNode(pathNode, operation.getName(), operation);
pathNode.addChild(operationNode);
}
}
if (pathNode.hasChildren()) {
mapperNode.addChild(pathNode);
}
}
if (mapperNode.hasChildren()) {
projectFolderExports.addChild(mapperNode);
}
}
List<Sequence> sequencesList = project.getSequencesList();
for (Sequence sequence : sequencesList) {
// Search for CallTransaction and CallSequence
// referencing a transaction or sequence
// from the selected project
List<Step> stepList = sequence.getSteps();
SequenceNode sequenceNode = new SequenceNode(root, sequence.getName(), sequence);
for (Step step : stepList) {
getUsedRequestables(step, projectSelected, sequenceNode);
}
if (sequenceNode.hasChildren()) {
projectFolderExports.addChild(sequenceNode);
}
}
if (projectFolderExports.hasChildren()) {
isUsedByNode.addChild(projectFolderExports);
}
}
}
if (isUsedByNode.hasChildren()) {
projectNode.addChild(isUsedByNode);
} else {
projectNode.addChild(new InformationNode(projectNode, "This project is not used by any other project"));
}
treeViewer.setInput(null);
treeViewer.setInput(root);
treeViewer.expandAll();
}
use of com.twinsoft.convertigo.beans.core.UrlMappingOperation in project convertigo by convertigo.
the class ReferencesView method handleTransactionSelection.
private void handleTransactionSelection(Object firstElement) {
TransactionTreeObject transactionTreeObject = (TransactionTreeObject) firstElement;
Transaction transaction = transactionTreeObject.getObject();
String transactionName = transactionTreeObject.getName();
// Get the referencing sequence steps
String transactionProjectName = transaction.getProject().getName();
String transactionConnectorName = transaction.getParent().getName();
try {
Project project = null;
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
treeViewer.setInput(null);
RootNode root = new RootNode();
TransactionNode transactionFolder = new TransactionNode(root, transactionName, transaction);
root.addChild(transactionFolder);
IsUsedByNode isUsedByNode = new IsUsedByNode(transactionFolder, "Is used by");
RequiresNode requiresNode = new RequiresNode(transactionFolder, "Requires");
ProjectNode projectFolder = null;
// Searching all objects are required transaction selected
Connector connector = transaction.getConnector();
if (connector instanceof HtmlConnector) {
Project proj = ((HtmlConnector) connector).getProject();
ProjectNode projectNode = new ProjectNode(requiresNode, transactionProjectName, proj);
HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
List<Statement> statements = htmlTransaction.getStatements();
List<ScreenClass> screenClassList = new ArrayList<ScreenClass>();
List<String> siteClipperConnectorNames = new ArrayList<String>();
for (Statement statement : statements) {
if (statement instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) statement;
String screenClassName = scHandlerStatement.getNormalizedScreenClassName();
ScreenClass screenClass = ((HtmlConnector) connector).getScreenClassByName(screenClassName);
if (screenClass != null) {
if (!screenClassList.contains(screenClass)) {
screenClassList.add(screenClass);
requiresNode.addChild(new ScreenClassNode(requiresNode, screenClassName, screenClass));
}
}
}
List<Statement> statementList = ((FunctionStatement) statement).getStatements();
for (Statement st : statementList) {
if (st instanceof ContinueWithSiteClipperStatement) {
ContinueWithSiteClipperStatement continueWithSiteClipperStatement = (ContinueWithSiteClipperStatement) st;
String siteClipperconnectorName = continueWithSiteClipperStatement.getSiteClipperConnectorName();
if (!siteClipperConnectorNames.contains(siteClipperconnectorName)) {
siteClipperConnectorNames.add(siteClipperconnectorName);
Connector siteClipperConnector = proj.getConnectorByName(siteClipperconnectorName);
ConnectorNode connectorSiteClipperNode = new SiteClipperConnectorNode(projectNode, siteClipperconnectorName, siteClipperConnector);
projectNode.addChild(connectorSiteClipperNode);
}
}
}
}
if (projectNode.hasChildren()) {
requiresNode.addChild(projectNode);
}
} else if (connector instanceof JavelinConnector) {
JavelinTransaction javelinTransaction = (JavelinTransaction) transaction;
String handlers = javelinTransaction.handlers;
List<JavelinScreenClass> screenClasses = ((JavelinConnector) connector).getAllScreenClasses();
List<JavelinScreenClass> screenClassList = new ArrayList<JavelinScreenClass>();
for (JavelinScreenClass screenClass : screenClasses) {
if (handlers.indexOf("function on" + screenClass.getName()) != -1) {
if (!screenClassList.contains(screenClass)) {
screenClassList.add(screenClass);
requiresNode.addChild(new ScreenClassNode(requiresNode, screenClass.getName(), screenClass));
}
}
}
}
// Searching all objects are used transaction selected
for (String projectName : projectNames) {
project = getProject(projectName, projectExplorerView);
if (project != null) {
projectFolder = new ProjectNode(isUsedByNode, project.getName(), project);
UrlMapper urlMapper = project.getUrlMapper();
if (urlMapper != null) {
MapperNode mapperNode = new MapperNode(projectFolder, urlMapper.getName(), urlMapper);
List<UrlMapping> mappings = urlMapper.getMappingList();
for (UrlMapping mapping : mappings) {
MappingPathNode pathNode = new MappingPathNode(mapperNode, mapping.getPath(), mapping);
List<UrlMappingOperation> operations = mapping.getOperationList();
for (UrlMappingOperation operation : operations) {
String targetRequestable = operation.getTargetRequestable();
if (targetRequestable.equals(transactionProjectName + "." + transactionConnectorName + "." + transactionName)) {
MappingOperationNode operationNode = new MappingOperationNode(pathNode, operation.getName(), operation);
pathNode.addChild(operationNode);
}
}
if (pathNode.hasChildren()) {
mapperNode.addChild(pathNode);
}
}
if (mapperNode.hasChildren()) {
projectFolder.addChild(mapperNode);
}
}
List<Sequence> sequences = project.getSequencesList();
for (Sequence sequence : sequences) {
List<Step> stepList = sequence.getAllSteps();
SequenceNode sequenceNode = new SequenceNode(projectFolder, sequence.getName(), sequence);
for (Step step : stepList) {
getTransactionReferencing(step, projectExplorerView, sequenceNode, transactionProjectName, transactionConnectorName, transactionName);
}
if (sequenceNode.hasChildren()) {
projectFolder.addChild(sequenceNode);
}
}
if (projectFolder.hasChildren()) {
isUsedByNode.addChild(projectFolder);
}
}
}
if (requiresNode.hasChildren()) {
transactionFolder.addChild(requiresNode);
}
if (isUsedByNode.hasChildren()) {
transactionFolder.addChild(isUsedByNode);
}
if (!transactionFolder.hasChildren()) {
transactionFolder.addChild(new InformationNode(projectFolder, "This transaction is not used in any sequence"));
}
treeViewer.setInput(root);
treeViewer.expandAll();
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
}
}
use of com.twinsoft.convertigo.beans.core.UrlMappingOperation in project convertigo by convertigo.
the class TreeDropAdapter method move.
private boolean move(Node node, TreeObject targetTreeObject) throws EngineException {
if (targetTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject parent = ((DatabaseObjectTreeObject) targetTreeObject).getObject();
DatabaseObject databaseObject = paste(node, null, true);
Element element = (Element) ((Element) node).getElementsByTagName("dnd").item(0);
// SEQUENCER
if (parent instanceof Sequence || parent instanceof StepWithExpressions) {
;
} else // URLMAPPER
if (parent instanceof UrlMappingOperation) {
// Set associated requestable
if (databaseObject instanceof RequestableObject) {
String dboQName = "";
if (databaseObject instanceof Sequence) {
dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + databaseObject.getName();
} else if (databaseObject instanceof Transaction) {
dboQName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name") + "." + ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name") + "." + databaseObject.getName();
}
UrlMappingOperation operation = (UrlMappingOperation) parent;
operation.setTargetRequestable(dboQName);
if (operation.getComment().isEmpty()) {
operation.setComment(databaseObject.getComment());
}
operation.hasChanged = true;
return true;
}
} else if (parent instanceof UrlMappingParameter) {
// Set associated mapped variable for parameter
if (databaseObject instanceof RequestableVariable) {
RequestableVariable variable = (RequestableVariable) databaseObject;
UrlMappingParameter parameter = (UrlMappingParameter) parent;
parameter.setMappedVariableName(variable.getName());
parameter.hasChanged = true;
return true;
}
}
}
return false;
}
Aggregations