use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class TreeDropAdapter method paste.
private boolean paste(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) {
if (parent instanceof XMLElementStep)
return false;
if (parent instanceof IThenElseContainer)
return false;
// Add a TransactionStep
if (databaseObject instanceof Transaction) {
String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
String connectorName = ((Element) element.getElementsByTagName("connector").item(0)).getAttribute("name");
Transaction transaction = (Transaction) databaseObject;
TransactionStep transactionStep = new TransactionStep();
transactionStep.setSourceTransaction(projectName + TransactionStep.SOURCE_SEPARATOR + connectorName + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
transactionStep.bNew = true;
parent.add(transactionStep);
parent.hasChanged = true;
if (transaction instanceof TransactionWithVariables) {
for (Variable variable : ((TransactionWithVariables) transaction).getVariablesList()) {
StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
stepVariable.setName(variable.getName());
stepVariable.setComment(variable.getComment());
stepVariable.setDescription(variable.getDescription());
stepVariable.setRequired(variable.isRequired());
stepVariable.setValueOrNull(variable.getValueOrNull());
stepVariable.setVisibility(variable.getVisibility());
transactionStep.addVariable(stepVariable);
}
}
return true;
} else // Add a SequenceStep
if (databaseObject instanceof Sequence) {
String projectName = ((Element) element.getElementsByTagName("project").item(0)).getAttribute("name");
Sequence seq = (Sequence) databaseObject;
SequenceStep sequenceStep = new SequenceStep();
sequenceStep.setSourceSequence(projectName + SequenceStep.SOURCE_SEPARATOR + seq.getName());
sequenceStep.bNew = true;
parent.add(sequenceStep);
parent.hasChanged = true;
for (Variable variable : seq.getVariablesList()) {
StepVariable stepVariable = variable.isMultiValued() ? new StepMultiValuedVariable() : new StepVariable();
stepVariable.setName(variable.getName());
stepVariable.setComment(variable.getComment());
stepVariable.setDescription(variable.getDescription());
stepVariable.setRequired(variable.isRequired());
stepVariable.setValueOrNull(variable.getValueOrNull());
stepVariable.setVisibility(variable.getVisibility());
sequenceStep.addVariable(stepVariable);
}
return true;
}
} else // URLMAPPER
if (parent instanceof UrlMappingOperation) {
// Set associated requestable, add all parameters for operation
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;
try {
StringTokenizer st = new StringTokenizer(dboQName, ".");
int count = st.countTokens();
Project p = Engine.theApp.databaseObjectsManager.getProjectByName(st.nextToken());
List<RequestableVariable> variables = new ArrayList<RequestableVariable>();
if (count == 2) {
variables = p.getSequenceByName(st.nextToken()).getVariablesList();
} else if (count == 3) {
variables = ((TransactionWithVariables) p.getConnectorByName(st.nextToken()).getTransactionByName(st.nextToken())).getVariablesList();
}
for (RequestableVariable variable : variables) {
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
UrlMappingParameter parameter = null;
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
parameter = acceptForm ? new FormParameter() : new QueryParameter();
parameter.setName(variableName);
parameter.setComment(variable.getComment());
parameter.setArray(false);
parameter.setExposed(((RequestableVariable) variable).isWsdl());
parameter.setMultiValued(variable.isMultiValued());
parameter.setRequired(variable.isRequired());
parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
parameter.setMappedVariableName(variableName);
parameter.bNew = true;
operation.add(parameter);
operation.hasChanged = true;
}
}
} catch (Exception e) {
}
return true;
} else // Add a parameter to mapping operation
if (databaseObject instanceof RequestableVariable) {
RequestableVariable variable = (RequestableVariable) databaseObject;
UrlMappingOperation operation = (UrlMappingOperation) parent;
UrlMappingParameter parameter = null;
String variableName = variable.getName();
Object variableValue = variable.getValueOrNull();
try {
parameter = operation.getParameterByName(variableName);
} catch (Exception e) {
}
if (parameter == null) {
boolean acceptForm = operation.getMethod().equalsIgnoreCase(HttpMethodType.POST.name()) || operation.getMethod().equalsIgnoreCase(HttpMethodType.PUT.name());
parameter = acceptForm ? new FormParameter() : new QueryParameter();
parameter.setName(variableName);
parameter.setComment(variable.getComment());
parameter.setArray(false);
parameter.setExposed(((RequestableVariable) variable).isWsdl());
parameter.setMultiValued(variable.isMultiValued());
parameter.setRequired(variable.isRequired());
parameter.setValueOrNull(!variable.isMultiValued() ? variableValue : null);
parameter.setMappedVariableName(variableName);
parameter.bNew = true;
operation.add(parameter);
operation.hasChanged = true;
}
return true;
}
} else // MOBILE COMPONENTS
if (parent instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
return pasteMobileComponent(parent, databaseObject, element);
} else // NGX COMPONENTS
if (parent instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
return pasteNgxComponent(parent, databaseObject, element);
}
}
return false;
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class UpdateXSDTypesAction method run.
public void run() {
final 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();
ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
String message = "Do you really want to extract the schema?\nWarning: the previous one will be replaced.";
messageBox.setMessage(message);
if (messageBox.open() == SWT.YES) {
RequestableObject requestable = (RequestableObject) treeObject.getObject();
String requestableName = StringUtils.normalize(requestable.getName(), true);
Document document = null;
String result = null;
if (!(requestableName.equals(requestable.getName()))) {
throw new Exception("Requestable name should be normalized");
}
if (requestable instanceof Transaction) {
Connector connector = (Connector) requestable.getParent();
String connectorName = StringUtils.normalize(connector.getName(), true);
if (!(connectorName.equals(connector.getName()))) {
throw new Exception("Connector name should be normalized");
}
if (connector.getDefaultTransaction() == null) {
throw new Exception("Connector must have a default transaction");
}
if (requestable instanceof HtmlTransaction) {
if (extract) {
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
if (connectorEditor == null) {
ConvertigoPlugin.infoMessageBox("Please open connector first.");
return;
}
document = connectorEditor.getLastGeneratedDocument();
if (document == null) {
ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
return;
}
result = requestable.generateXsdTypes(document, extract);
} else {
HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
String defaultTransactionName = StringUtils.normalize(defaultTransaction.getName(), true);
if (!(defaultTransactionName.equals(defaultTransaction.getName()))) {
throw new Exception("Default transaction name should be normalized");
}
String defaultXsdTypes = defaultTransaction.generateXsdTypes(null, false);
if (requestable.equals(defaultTransaction))
result = defaultXsdTypes;
else {
TransactionXSDTypesDialog dlg = new TransactionXSDTypesDialog(shell, requestable);
if (dlg.open() == Window.OK) {
result = dlg.result;
result += defaultXsdTypes;
}
}
}
} else {
if (extract) {
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
if (connectorEditor == null) {
ConvertigoPlugin.infoMessageBox("Please open connector first.");
return;
}
document = connectorEditor.getLastGeneratedDocument();
if (document == null) {
ConvertigoPlugin.infoMessageBox("You should first generate the document data before trying to extract the XSD types.");
return;
}
String prefix = requestable.getXsdTypePrefix();
document.getDocumentElement().setAttribute("transaction", prefix + requestableName);
}
if (requestable instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
String reqn = xmlHttpTransaction.getResponseElementQName();
if (extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
if (!xmlQName.isEmpty()) {
ConvertigoPlugin.infoMessageBox("You should first unset 'Assigned element QName' property.");
return;
}
if (!reqn.equals("")) {
ConvertigoPlugin.infoMessageBox("You should first unset 'Schema of XML response root element' property.");
return;
}
}
}
result = requestable.generateXsdTypes(document, extract);
}
}
if ((result != null) && (!result.equals(""))) {
String xsdTypes = result;
if (requestable instanceof Transaction) {
if (requestable instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
String reqn = xmlHttpTransaction.getResponseElementQName();
if (!extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
// ignore
;
} else
((Transaction) requestable).writeSchemaToFile(xsdTypes);
} else
((Transaction) requestable).writeSchemaToFile(xsdTypes);
}
requestable.hasChanged = true;
Engine.theApp.schemaManager.clearCache(requestable.getProject().getName());
explorerView.refreshFirstSelectedTreeObject();
explorerView.objectSelected(new CompositeEvent(requestable));
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to update schema!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class ViewExecuteSelectedAction 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();
if ((treeObject != null) && (treeObject instanceof DesignDocumentViewTreeObject)) {
DesignDocumentViewTreeObject viewTreeObject = (DesignDocumentViewTreeObject) treeObject;
DesignDocumentTreeObject ddto = (DesignDocumentTreeObject) viewTreeObject.getTreeObjectOwner();
ConnectorTreeObject cto = (ConnectorTreeObject) ddto.getOwnerDatabaseObjectTreeObject();
ProjectTreeObject projectTreeObject = cto.getProjectTreeObject();
CouchDbConnector connector = (CouchDbConnector) cto.getObject();
cto.openConnectorEditor();
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
if (connectorEditor != null) {
// activate connector's editor
getActivePage().activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
((GetViewTransaction) transaction).setViewname(viewTreeObject.getDocViewName());
Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
view_reduce.setValueOrNull(viewTreeObject.hasReduce() ? isReduceRequested() : false);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalView, isStubRequested());
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to execute the selected view!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class ProjectTreeObject method treeObjectRemoved.
@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
super.treeObjectRemoved(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
if (!(treeObject.equals(this)) && (treeObject.getParents().contains(this))) {
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
String dboName = databaseObject.getName();
// Case of a connector deletion
if (databaseObject instanceof Connector) {
// connector in this project
if (treeObject.getProjectTreeObject().equals(this)) {
String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
IFolder parentFolder = getProjectTreeObject().getFolder(path);
IFolder folder = parentFolder.getFolder(dboName);
if (folder.exists()) {
IPath folderPath = folder.getLocation().makeAbsolute();
try {
// delete folder
folder.delete(true, null);
// refresh folder
parentFolder.refreshLocal(IResource.DEPTH_ONE, null);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not delete folder \"" + folderPath + "\"!");
}
}
}
} else // Case of a transaction deletion
if (databaseObject instanceof Transaction) {
// transaction in this project
if (treeObject.getProjectTreeObject().equals(this)) {
String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
ConnectorTreeObject cto = ((TransactionTreeObject) treeObject).getConnectorTreeObject();
IFolder parentFolder = getProjectTreeObject().getFolder(path).getFolder(cto.getName());
IFile file = parentFolder.getFile(dboName + ".xsd");
if (file.exists()) {
IPath filePath = file.getLocation().makeAbsolute();
try {
// delete file
file.delete(true, null);
// refresh folder
parentFolder.refreshLocal(IResource.DEPTH_ONE, null);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not delete file \"" + filePath + "\"!");
}
}
}
} else if (databaseObject instanceof ProjectSchemaReference) {
checkMissingProjects(false);
}
// Clear schema cache
if (this.equals(treeObject.getProjectTreeObject())) {
Engine.theApp.schemaManager.clearCache(getName());
}
}
}
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class ReferencesView method handleConnectorSelection.
private void handleConnectorSelection(Object firstElement) {
ConnectorTreeObject connectorTreeObject = (ConnectorTreeObject) firstElement;
Connector connectorSelected = connectorTreeObject.getObject();
String connectorSelectedName = connectorSelected.getName();
Project projectConnectorSelected = connectorSelected.getProject();
String connectorProjectName = connectorSelected.getProject().getName();
List<Transaction> transactions = connectorSelected.getTransactionsList();
try {
Project project = null;
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
treeViewer.setInput(null);
RootNode root = new RootNode();
ConnectorNode connectorNode = null;
connectorNode = getConnectorNode(root, connectorSelected);
root.addChild(connectorNode);
IsUsedByNode isUsedByNode = new IsUsedByNode(connectorNode, "Is used by");
RequiresNode requiresNode = new RequiresNode(connectorNode, "Requires");
ProjectNode projectFolder = null;
// Search handlers are that referenced by the selected connector for continue with site Clipper
if (connectorSelected instanceof HtmlConnector) {
ProjectNode projectNode = new ProjectNode(requiresNode, connectorProjectName, projectConnectorSelected);
for (Transaction transaction : transactions) {
List<Statement> statements = ((HtmlTransaction) transaction).getStatements();
List<String> siteClipperConnectorNames = new ArrayList<String>();
for (Statement statement : statements) {
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 = projectConnectorSelected.getConnectorByName(siteClipperconnectorName);
ConnectorNode connectorSiteClipperNode = new SiteClipperConnectorNode(projectNode, siteClipperconnectorName, siteClipperConnector);
projectNode.addChild(connectorSiteClipperNode);
}
}
}
}
}
if (projectNode.hasChildren()) {
requiresNode.addChild(projectNode);
}
} else if (connectorSelected instanceof SiteClipperConnector) {
List<Connector> connectors = projectConnectorSelected.getConnectorsList();
ProjectNode projectNode = new ProjectNode(isUsedByNode, connectorProjectName, projectConnectorSelected);
for (Connector connector : connectors) {
if (connector instanceof HtmlConnector) {
List<Transaction> transactionList = ((HtmlConnector) connector).getTransactionsList();
for (Transaction transaction : transactionList) {
List<Statement> statements = ((HtmlTransaction) transaction).getStatements();
for (Statement statement : statements) {
List<Statement> statementList = ((FunctionStatement) statement).getStatements();
for (Statement st : statementList) {
if (st instanceof ContinueWithSiteClipperStatement) {
String sourceSiteClipperConnectorName = ((ContinueWithSiteClipperStatement) st).getSiteClipperConnectorName();
if (sourceSiteClipperConnectorName.equals(connectorSelectedName)) {
ContinueWithSiteClipperStatement continueWithSiteClipperStatement = (ContinueWithSiteClipperStatement) st;
HtmlConnectorNode htmlConnectorNode = new HtmlConnectorNode(projectNode, connector.getName(), connector);
projectNode.addChild(htmlConnectorNode);
TransactionNode transactionNode = new TransactionNode(htmlConnectorNode, transaction.getName(), continueWithSiteClipperStatement);
htmlConnectorNode.addChild(transactionNode);
}
}
}
}
}
}
}
if (projectNode.hasChildren()) {
isUsedByNode.addChild(projectNode);
}
}
// Searching all objects that are referenced by the selected connector
for (String projectName : projectNames) {
project = getProject(projectName, projectExplorerView);
if (project != null) {
projectFolder = new ProjectNode(isUsedByNode, projectName, 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.startsWith(projectConnectorSelected + "." + connectorSelectedName + ".")) {
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> steps = sequence.getSteps();
SequenceNode sequenceNode = new SequenceNode(projectFolder, sequence.getName(), sequence);
for (Step step : steps) {
getConnectorReferencingIsUsedBy(step, projectExplorerView, sequenceNode, transactions, connectorProjectName, connectorSelectedName);
}
if (sequenceNode.hasChildren()) {
projectFolder.addChild(sequenceNode);
}
}
if (projectFolder.hasChildren()) {
isUsedByNode.addChild(projectFolder);
}
}
}
if (requiresNode.hasChildren()) {
connectorNode.addChild(requiresNode);
}
if (isUsedByNode.hasChildren()) {
connectorNode.addChild(isUsedByNode);
}
if (!connectorNode.hasChildren()) {
connectorNode.addChild(new InformationNode(connectorNode, "This connector is not used by any other objects"));
}
treeViewer.setInput(root);
treeViewer.expandAll();
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
}
}
Aggregations