use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class ClipboardAction method pasteStep.
private Object pasteStep(Shell shell, String source, DatabaseObject targetObject) throws ParserConfigurationException, SAXException, IOException {
// Can only paste on Sequence or Step
if (targetObject instanceof Sequence)
return targetObject;
else if (!(targetObject instanceof Step))
return null;
// cannot paste to IThenElseContainer
if (targetObject instanceof IThenElseContainer)
return null;
else {
List<Object> objects = clipboardManager.read(source);
int size = objects.size();
for (Object ob : objects) {
// Can only paste step objects
if (!(ob instanceof Step))
return null;
// Can paste only on step which may contain children
if ((ob instanceof StepWithExpressions) && (!(targetObject instanceof StepWithExpressions)))
return null;
// cannot paste a ThenStep
if (ob instanceof ThenStep)
return null;
// cannot paste a ElseStep
if (ob instanceof ElseStep)
return null;
// cannot paste a ThenStatement
if (ob instanceof ThenStatement)
return null;
// cannot paste a ElseStatement
if (ob instanceof ElseStatement)
return null;
// Special case of XMLElementStep, ElementStep
if ((targetObject instanceof XMLElementStep) || (targetObject instanceof ElementStep)) {
// Case paste on itself -> target is changed to parent
if ((size == 1) && ((ob instanceof XMLElementStep) || (ob instanceof ElementStep))) {
if (((Step) ob).getName().equals(targetObject.getName())) {
return targetObject.getParent();
}
return null;
} else // Else, only accept paste of XMLAttributeStep
if (!(ob instanceof XMLAttributeStep || ob instanceof AttributeStep)) {
return null;
}
} else // Case of step which may contain children
if (targetObject instanceof StepWithExpressions) {
// Case paste on itself -> ask user what to do
if ((size == 1) && (ob.getClass().equals(targetObject.getClass()))) {
if (((Step) ob).getName().equals(targetObject.getName())) {
CustomDialog customDialog = new CustomDialog(shell, "Paste a step", "Do you want to paste the step as a sibling or a child step?", 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) {
return targetObject.getParent();
} else if (response == 2) {
return null;
} else
break;
}
}
// Else, paste
break;
} else // Other case
{
// Case paste on itself -> target is changed to parent
if ((size == 1) && (ob.getClass().equals(targetObject.getClass()))) {
if (((Step) ob).getName().equals(targetObject.getName())) {
return targetObject.getParent();
}
return null;
}
// Else, not permitted
return null;
}
}
}
return targetObject;
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class ChangeToSingleValuedVariableAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
Object databaseObject = treeObject.getObject();
if (databaseObject != null) {
Variable multi = (Variable) databaseObject;
Variable simple = null;
if (databaseObject instanceof TestCaseMultiValuedVariable)
simple = new TestCaseVariable();
if (databaseObject instanceof StepMultiValuedVariable)
simple = new StepVariable();
if (databaseObject instanceof RequestableMultiValuedVariable)
simple = new RequestableVariable();
if (databaseObject instanceof RequestableHttpMultiValuedVariable)
simple = new RequestableHttpVariable();
if (databaseObject instanceof HttpStatementMultiValuedVariable)
simple = new HttpStatementVariable();
if (simple != null) {
if (multi instanceof StepMultiValuedVariable) {
((StepVariable) simple).setSourceDefinition(((StepVariable) multi).getSourceDefinition());
}
if (multi instanceof RequestableVariable) {
((RequestableVariable) simple).setXmlTypeAffectation(((RequestableVariable) multi).getXmlTypeAffectation());
}
if (multi instanceof RequestableHttpVariable) {
// HttpName
((RequestableHttpVariable) simple).setHttpName(((RequestableHttpVariable) multi).getHttpName());
// HttpMethod
((RequestableHttpVariable) simple).setHttpMethod(((RequestableHttpVariable) multi).getHttpMethod());
}
XMLVector<Object> xmlv = GenericUtils.cast(multi.getValueOrNull());
Object value = (xmlv == null) ? null : (xmlv.isEmpty() ? "" : xmlv.get(0).toString());
simple.setValueOrNull(value);
simple.setVisibility(multi.getVisibility());
// Comment
simple.setComment(multi.getComment());
// Description
simple.setDescription(multi.getDescription());
// Required
simple.setRequired(multi.isRequired());
simple.bNew = true;
simple.hasChanged = true;
// Add new variable to parent
DatabaseObject parentDbo = multi.getParent();
parentDbo.add(simple);
// Set correct order
if (parentDbo instanceof TestCase)
((TestCase) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof RequestableStep)
((RequestableStep) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof TransactionWithVariables)
((TransactionWithVariables) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof HTTPStatement)
((HTTPStatement) parentDbo).insertAtOrder(simple, multi.priority);
// Add new variable in Tree
VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, simple);
treeParent.addChild(varTreeObject);
// Delete simple variable
multi.delete();
// Set correct name
simple.setName(multi.getName());
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(simple));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class CreateStubFromXMLAction method getXML.
public Document getXML(TreeObject treeObject) throws Exception {
Document dom = XMLUtils.createDom("java");
ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
Object requestable = treeObject.getObject();
if (requestable instanceof Transaction) {
Transaction transaction = (Transaction) requestable;
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor((Connector) transaction.getParent());
dom = connectorEditor.getLastGeneratedDocument();
} else if (requestable instanceof Sequence) {
SequenceEditor sequenceEditor = projectTreeObject.getSequenceEditor((Sequence) requestable);
dom = sequenceEditor.getLastGeneratedDocument();
}
if (dom == null) {
throw new NoSuchElementException();
}
return dom;
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class ReferencesView method getRequiredRequestables.
private void getRequiredRequestables(Step step, Project projectSelected, ProjectExplorerView projectExplorerView, AbstractParentNode parentNode, List<String> transactionList, List<String> sequenceList) {
try {
if (step instanceof SequenceStep) {
SequenceStep sequenceStep = (SequenceStep) step;
String sourceProjectName = sequenceStep.getProjectName();
if (!sourceProjectName.equals(projectSelected.getName())) {
Project project;
project = getProject(sourceProjectName, projectExplorerView);
ProjectNode projectNode = new ProjectNode(parentNode, sourceProjectName, project);
Sequence sourceSequence = null;
String sourceSequenceName = sequenceStep.getSequenceName();
try {
if (project != null)
sourceSequence = project.getSequenceByName(sourceSequenceName);
} catch (EngineException e) {
sourceSequence = null;
}
projectNode.addChild(new SequenceNode(projectNode, sourceSequenceName, sourceSequence));
if (!sequenceList.contains(sourceProjectName + sourceSequenceName)) {
sequenceList.add(sourceProjectName + sourceSequenceName);
parentNode.addChild(projectNode);
}
}
} else if (step instanceof TransactionStep) {
TransactionStep transactionStep = (TransactionStep) step;
String sourceProjectName = transactionStep.getProjectName();
if (!sourceProjectName.equals(projectSelected.getName())) {
Project project;
project = getProject(sourceProjectName, projectExplorerView);
ProjectNode projectNode = new ProjectNode(parentNode, sourceProjectName, project);
if (project != null) {
Connector connector = project.getConnectorByName(transactionStep.getConnectorName());
ConnectorNode connectorNode = null;
connectorNode = getConnectorNode(projectNode, connector);
projectNode.addChild(connectorNode);
Transaction sourceTransaction = null;
String sourceTransactionName = transactionStep.getTransactionName();
try {
if (connector != null)
sourceTransaction = connector.getTransactionByName(sourceTransactionName);
} catch (Exception e) {
sourceTransaction = null;
}
connectorNode.addChild(new TransactionNode(connectorNode, sourceTransactionName, sourceTransaction));
if (!transactionList.contains(project.getName() + connector.getName() + sourceTransactionName)) {
transactionList.add(project.getName() + connector.getName() + sourceTransactionName);
parentNode.addChild(projectNode);
}
}
}
} else if (isStepContainer(step)) {
List<Step> steps = getStepList(step);
if (steps != null) {
for (Step s : steps) {
getRequiredRequestables(s, projectSelected, projectExplorerView, parentNode, transactionList, sequenceList);
}
}
}
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Unable to load the project", true);
}
}
use of com.twinsoft.convertigo.beans.core.Sequence 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();
}
Aggregations