use of com.twinsoft.convertigo.beans.statements.HTTPStatement 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.statements.HTTPStatement in project convertigo by convertigo.
the class HtmlTransaction method applyUserRequest.
public void applyUserRequest(Object object) throws EngineException {
final HtmlConnector connector = (HtmlConnector) parent;
if (!runningThread.bContinue) {
return;
}
Cookie[] cookies = new Cookie[] {};
final byte[][] httpData = { null };
try {
Document dom = null;
TriggerXMLizer triggerXML = null;
String t = context.statistics.start(EngineStatistics.HTTP_CONNECT);
try {
// Retrieving Data
if (object instanceof HtmlConnector) {
Engine.logBeans.trace("(HtmlTransaction) Retrieving data from connector ...");
httpData[0] = connector.getData(context);
triggerXML = trigger;
}
if (object instanceof HTTPStatement) {
Engine.logBeans.trace("(HtmlTransaction) Retrieving data from http statement ...");
connector.prepareForHTTPStatement(context);
httpData[0] = connector.getData(context);
triggerXML = ((HTTPStatement) object).getTrigger();
}
if (!alreadyConnected)
alreadyConnected = true;
Engine.logBeans.trace("(HtmlTransaction) Data retrieved!");
// Engine.logBeans.trace("(HtmlTransaction) Data html:\n"+ new String(httpData));
} finally {
context.statistics.stop(t);
}
// Retrieve cookies from HttpClient response
if (connector.handleCookie) {
cookies = connector.getCookies();
if (Engine.logBeans.isTraceEnabled()) {
Engine.logBeans.trace("(HtmlTransaction) cookies from HttpClient response :" + Arrays.asList(cookies).toString());
}
}
if (!runningThread.bContinue) {
return;
}
// Parse response : push data into HTML parser
if (!isContentTypeHTML()) {
final String[] filename = { connector.getReferer() };
int id;
if ((id = filename[0].indexOf('?')) != -1) {
filename[0] = filename[0].substring(0, id);
}
if ((id = filename[0].lastIndexOf('/')) != -1) {
filename[0] = filename[0].substring(id + 1);
}
connector.getHtmlParser().downloadRequest(context, new IDownloader() {
public String getUri() {
return connector.getReferer();
}
public String getReferrer() {
return connector.getReferer();
}
public String getFilename() {
return filename[0];
}
public byte[] getData(long timeout, long threshold) {
return httpData[0];
}
public String getContentType() {
return HtmlTransaction.this.getContentType();
}
public void cancel() {
}
public Status getStatus() {
return Status.direct;
}
});
return;
}
dom = connector.parseData(httpData[0], connector.getReferer(), connector.getCharset(), triggerXML.getTrigger());
if (!runningThread.bContinue)
return;
setCurrentXmlDocument(dom);
if (Engine.logBeans.isTraceEnabled())
Engine.logBeans.trace("(HtmlTransaction) Parser result dom:\n" + XMLUtils.prettyPrintDOM(dom));
if (!runningThread.bContinue)
return;
// Modify input document if needed
modifyInputDocument();
} catch (IOException e) {
throw new EngineException("An IO exception occured while trying to connect to the URL.\nURL: " + connector.sUrl + "\nPost query: " + connector.postQuery, e);
} catch (Exception e) {
throw new EngineException("An unexpected exception occured while trying to get the document via HTTP.", e);
}
if (!runningThread.bContinue)
return;
// Applying handler
executeHandler(EVENT_DATA_RETRIEVED, ((RequestableThread) Thread.currentThread()).javascriptContext);
}
use of com.twinsoft.convertigo.beans.statements.HTTPStatement in project convertigo by convertigo.
the class NewObjectWizard method doFinish.
private void doFinish(IProgressMonitor monitor) throws CoreException {
String dboName, name;
boolean bContinue = true;
int index = 0;
try {
int total = 0;
Class<?> c = getCreatedBeanClass();
if (c != null) {
total = 4;
if (c.equals(WebServiceReference.class)) {
total += ImportWsReference.getTotalTaskNumber();
}
}
monitor.beginTask("Creating new object", total);
newBean = getCreatedBean();
if (newBean != null) {
monitor.setTaskName("Object created");
monitor.worked(1);
dboName = newBean.getName();
if (!StringUtils.isNormalized(dboName))
throw new EngineException("Bean name is not normalized : \"" + dboName + "\".");
// Verify if a child object with same name exist and change name
while (bContinue) {
if (index == 0)
name = dboName;
else
name = dboName + index;
newBean.setName(name);
newBean.hasChanged = true;
newBean.bNew = true;
try {
new WalkHelper() {
boolean root = true;
boolean find = false;
@Override
protected boolean before(DatabaseObject dbo, Class<? extends DatabaseObject> dboClass) {
boolean isInstance = dboClass.isInstance(newBean);
find |= isInstance;
return isInstance;
}
@Override
protected void walk(DatabaseObject dbo) throws Exception {
if (root) {
root = false;
super.walk(dbo);
if (!find) {
throw new EngineException("You cannot add to a " + newBean.getClass().getSimpleName() + " a database object of type " + parentObject.getClass().getSimpleName());
}
} else {
if (newBean.getName().equalsIgnoreCase(dbo.getName())) {
throw new ObjectWithSameNameException("Unable to add the object because an object with the same name already exists in target.");
}
}
}
}.init(parentObject);
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
if ((parentObject instanceof HtmlTransaction) && (newBean instanceof Statement)) {
throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
}
// Silently ignore
index++;
} catch (EngineException ee) {
throw ee;
} catch (Exception e) {
throw new EngineException("Exception in create", e);
}
}
// Now add bean to target
try {
boolean hasChanged = parentObject.hasChanged;
if ((newBean instanceof Statement) && (parentObject instanceof Transaction)) {
newBean.priority = 0;
}
if (newBean instanceof ScreenClass)
newBean.priority = parentObject.priority + 1;
if (newBean instanceof Criteria) {
Connector connector = parentObject.getConnector();
if (parentObject.equals(((IScreenClassContainer<?>) connector).getDefaultScreenClass()))
throw new EngineException("You cannot add a new criterion on default screenclass.");
}
parentObject.add(newBean);
monitor.setTaskName("Object added");
monitor.worked(1);
if (newBean instanceof HTTPStatement) {
HTTPStatement httpStatement = (HTTPStatement) newBean;
HtmlConnector connector = (HtmlConnector) httpStatement.getParentTransaction().getParent();
httpStatement.setMethod("GET");
httpStatement.setHost(connector.getServer());
httpStatement.setPort(connector.getPort());
httpStatement.setHttps(connector.isHttps());
}
if (newBean instanceof ContinueWithSiteClipperStatement) {
Project project = newBean.getProject();
if (project != null) {
String[] connectorWithSiteClipperConnector = ContinueWithSiteClipperStatement.getSiteClippersConnectorNames(project);
if (connectorWithSiteClipperConnector.length > 0) {
((ContinueWithSiteClipperStatement) newBean).setSiteClipperConnectorName(connectorWithSiteClipperConnector[0]);
}
}
}
if (newBean instanceof Connector) {
Project project = (Project) parentObject;
if (project.getDefaultConnector() == null)
project.setDefaultConnector((Connector) newBean);
Connector.setupConnector(newBean);
}
if (newBean instanceof PageComponent) {
ApplicationComponent application = (ApplicationComponent) parentObject;
if (application.getRootPage() == null)
application.setRootPage((PageComponent) newBean);
}
if (newBean instanceof SequenceStep) {
Project project = newBean.getProject();
((SequenceStep) newBean).setSourceSequence(project.getName() + TransactionStep.SOURCE_SEPARATOR + project.getSequencesList().get(0));
}
if (newBean instanceof TransactionStep) {
Project project = newBean.getProject();
Connector connector = project.getDefaultConnector();
Transaction transaction = connector.getDefaultTransaction();
((TransactionStep) newBean).setSourceTransaction(project.getName() + TransactionStep.SOURCE_SEPARATOR + connector.getName() + TransactionStep.SOURCE_SEPARATOR + transaction.getName());
}
if (newBean instanceof IThenElseContainer) {
ThenStep thenStep = new ThenStep();
((IThenElseContainer) newBean).addStep(thenStep);
ElseStep elseStep = new ElseStep();
((IThenElseContainer) newBean).addStep(elseStep);
}
if (newBean instanceof IThenElseStatementContainer) {
ThenStatement thenStatement = new ThenStatement();
((IThenElseStatementContainer) newBean).addStatement(thenStatement);
ElseStatement elseStatement = new ElseStatement();
((IThenElseStatementContainer) newBean).addStatement(elseStatement);
}
if (newBean instanceof Sheet) {
InputStream is = null;
try {
String sheetName = newBean.getName() + ".xsl";
is = new FileInputStream(new File(Engine.XSL_PATH + "/customsheet.xsl"));
String projectName = ((DatabaseObject) parentObject).getProject().getName();
IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
final IFile file = project.getFile(sheetName);
if (!file.exists())
file.create(is, true, null);
((Sheet) newBean).setUrl(sheetName);
} catch (Exception e) {
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
}
if (newBean instanceof TestCase) {
TestCase testCase = (TestCase) newBean;
testCase.importRequestableVariables((RequestableObject) testCase.getParent());
}
if (newBean instanceof RequestableHttpVariable) {
RequestableHttpVariable variable = (RequestableHttpVariable) newBean;
AbstractHttpTransaction httpTransaction = (AbstractHttpTransaction) variable.getParent();
HttpMethodType httpMethodType = httpTransaction.getHttpVerb();
boolean isVarPost = httpMethodType.equals(HttpMethodType.PUT) || httpMethodType.equals(HttpMethodType.POST);
variable.setHttpMethod(isVarPost ? HttpMethodType.POST.name() : HttpMethodType.GET.name());
if (!(httpTransaction instanceof HtmlTransaction)) {
variable.setHttpName(variable.getName());
}
}
if (newBean instanceof WebServiceReference) {
try {
Project project = (Project) parentObject;
WebServiceReference webServiceReference = (WebServiceReference) newBean;
ImportWsReference wsr = new ImportWsReference(webServiceReference);
wsr.importInto(project);
} catch (Exception e) {
if (newBean != null) {
parentObject.remove(newBean);
parentObject.hasChanged = hasChanged;
}
throw new Exception(e);
}
}
if (newBean instanceof RestServiceReference) {
try {
Project project = (Project) parentObject;
RestServiceReference restServiceReference = (RestServiceReference) newBean;
ImportWsReference wsr = new ImportWsReference(restServiceReference);
wsr.importInto(project);
} catch (Exception e) {
if (newBean != null) {
parentObject.remove(newBean);
parentObject.hasChanged = hasChanged;
}
throw new Exception(e);
}
}
if (newBean instanceof SqlTransaction) {
SqlTransaction sqlTransaction = (SqlTransaction) newBean;
sqlTransaction.setSqlQuery(sqlQueriesWizardPage.getSQLQueries());
sqlTransaction.initializeQueries(true);
}
if (newBean instanceof SapJcoLogonTransaction) {
SapJcoLogonTransaction sapLogonTransaction = (SapJcoLogonTransaction) newBean;
sapLogonTransaction.addCredentialsVariables();
}
if (newBean instanceof AbstractCouchDbTransaction) {
AbstractCouchDbTransaction abstractCouchDbTransaction = (AbstractCouchDbTransaction) newBean;
List<CouchVariable> selectedVariables = objectInfoPage.getSelectedParameters();
abstractCouchDbTransaction.createVariables(selectedVariables);
}
ConvertigoPlugin.logInfo("New object class '" + this.className + "' named '" + newBean.getName() + "' has been added");
monitor.setTaskName("Object setted up");
monitor.worked(1);
bContinue = false;
} catch (com.twinsoft.convertigo.engine.ObjectWithSameNameException owsne) {
if (newBean instanceof HandlerStatement) {
throw owsne;
}
}
} else {
throw new Exception("Could not instantiate bean!");
}
} catch (Exception e) {
String message = "Unable to create a new object from class '" + this.className + "'.";
ConvertigoPlugin.logException(e, message);
if (objectExplorerPage != null) {
objectExplorerPage.doCancel();
}
}
}
use of com.twinsoft.convertigo.beans.statements.HTTPStatement in project convertigo by convertigo.
the class ClipboardManager method paste.
public Object paste(Node node, DatabaseObject parentDatabaseObject, boolean bChangeName) throws EngineException {
Object object = read(node);
if (object instanceof DatabaseObject) {
DatabaseObject databaseObject = (DatabaseObject) object;
String dboName = databaseObject.getName();
String name = null;
if (objectsType != ProjectExplorerView.TREE_OBJECT_TYPE_DBO_PROJECT) {
// Verify if object is accepted for paste
if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, databaseObject)) {
throw new EngineException("You cannot paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + databaseObject.getClass().getSimpleName());
}
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, databaseObject)) {
throw new EngineException("You cannot paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + databaseObject.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, databaseObject)) {
String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(databaseObject);
throw new EngineException("Template project " + tplVersion + " compatibility required");
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, databaseObject)) {
throw new EngineException("You cannot paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + databaseObject.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, databaseObject)) {
String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(databaseObject);
throw new EngineException("Template project " + tplVersion + " compatibility required");
}
}
// Disable the isDefault boolean flag when the connector is pasted
if (databaseObject instanceof Connector) {
Connector connector = (Connector) databaseObject;
if (connector.isDefault) {
connector.isDefault = false;
}
}
// Disable the isRoot boolean flag when the page is pasted
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
com.twinsoft.convertigo.beans.mobile.components.PageComponent page = GenericUtils.cast(databaseObject);
if (page.isRoot) {
page.isRoot = false;
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
com.twinsoft.convertigo.beans.ngx.components.PageComponent page = GenericUtils.cast(databaseObject);
if (page.isRoot) {
page.isRoot = false;
}
}
if (objectsType != ProjectExplorerView.TREE_OBJECT_TYPE_DBO_CONNECTOR) {
// Disable the isDefault boolean flag when the transaction is pasted
if (databaseObject instanceof Transaction) {
Transaction transaction = (Transaction) databaseObject;
if (transaction.isDefault) {
transaction.isDefault = false;
}
}
}
}
// Special case of project
if (databaseObject instanceof Project) {
return databaseObject;
}
boolean bContinue = true;
int index = 0;
long oldPriority = databaseObject.priority;
// Verify if a child object with same name exist and change name
while (bContinue) {
if (bChangeName) {
if (index == 0)
name = dboName;
else
name = dboName + index;
databaseObject.setName(name);
}
databaseObject.hasChanged = true;
databaseObject.bNew = true;
try {
new WalkHelper() {
boolean root = true;
boolean find = false;
@Override
protected boolean before(DatabaseObject dbo, Class<? extends DatabaseObject> dboClass) {
boolean isInstance = dboClass.isInstance(databaseObject);
find |= isInstance;
return isInstance;
}
@Override
protected void walk(DatabaseObject dbo) throws Exception {
if (root) {
root = false;
super.walk(dbo);
if (!find) {
// ignore: we must accept special paste: e.g. transaction over sequence
}
} else {
if (databaseObject.getName().equalsIgnoreCase(dbo.getName())) {
throw new ObjectWithSameNameException("Unable to paste the object because an object with the same name already exists in target.");
}
}
}
}.init(parentDatabaseObject);
bContinue = false;
} catch (ObjectWithSameNameException owsne) {
if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement)) {
throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
}
// Silently ignore
index++;
} catch (EngineException ee) {
throw ee;
} catch (Exception e) {
throw new EngineException("Exception in paste", e);
}
}
// reset ordered properties
if (databaseObject instanceof IContainerOrdered) {
// Mobile beans
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent ac = GenericUtils.cast(databaseObject);
ac.setOrderedRoutes(getNewOrdered());
ac.setOrderedMenus(getNewOrdered());
ac.setOrderedPages(getNewOrdered());
ac.setOrderedComponents(getNewOrdered());
ac.setOrderedSharedActions(getNewOrdered());
ac.setOrderedSharedComponents(getNewOrdered());
}
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteComponent) {
com.twinsoft.convertigo.beans.mobile.components.RouteComponent rc = GenericUtils.cast(databaseObject);
rc.setOrderedActions(getNewOrdered());
rc.setOrderedEvents(getNewOrdered());
}
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(databaseObject);
pc.setOrderedComponents(getNewOrdered());
}
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
com.twinsoft.convertigo.beans.mobile.components.UIComponent uic = GenericUtils.cast(databaseObject);
uic.setOrderedComponents(getNewOrdered());
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent ac = GenericUtils.cast(databaseObject);
ac.setOrderedMenus(getNewOrdered());
ac.setOrderedPages(getNewOrdered());
ac.setOrderedComponents(getNewOrdered());
ac.setOrderedSharedActions(getNewOrdered());
ac.setOrderedSharedComponents(getNewOrdered());
}
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(databaseObject);
pc.setOrderedComponents(getNewOrdered());
}
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
com.twinsoft.convertigo.beans.ngx.components.UIComponent uic = GenericUtils.cast(databaseObject);
uic.setOrderedComponents(getNewOrdered());
}
}
// Sequence beans
if (databaseObject instanceof Sequence) {
((Sequence) databaseObject).setOrderedSteps(getNewOrdered());
((Sequence) databaseObject).setOrderedVariables(getNewOrdered());
}
if (databaseObject instanceof StepWithExpressions) {
((StepWithExpressions) databaseObject).setOrderedSteps(getNewOrdered());
}
if (databaseObject instanceof RequestableStep) {
((RequestableStep) databaseObject).setOrderedVariables(getNewOrdered());
}
// Transaction beans
if (databaseObject instanceof TransactionWithVariables) {
((TransactionWithVariables) databaseObject).setOrderedVariables(getNewOrdered());
}
if (databaseObject instanceof StatementWithExpressions) {
((StatementWithExpressions) databaseObject).setOrderedStatements(getNewOrdered());
}
if (databaseObject instanceof HTTPStatement) {
((HTTPStatement) databaseObject).setOrderedVariables(getNewOrdered());
}
if (databaseObject instanceof ScreenClass) {
((ScreenClass) databaseObject).setOrderedCriterias(getNewOrdered());
((ScreenClass) databaseObject).setOrderedExtractionRules(getNewOrdered());
}
// TestCase bean
if (databaseObject instanceof TestCase) {
((TestCase) databaseObject).setOrderedVariables(getNewOrdered());
}
}
// Now add dbo to target
try {
if (parentDatabaseObject instanceof ScreenClass) {
if (parentDatabaseObject instanceof JavelinScreenClass) {
JavelinScreenClass screenClass = (JavelinScreenClass) parentDatabaseObject;
if (databaseObject instanceof BlockFactory) {
screenClass.add(databaseObject);
screenClass.setBlockFactory((BlockFactory) databaseObject);
}
}
ScreenClass screenClass = (ScreenClass) parentDatabaseObject;
if (databaseObject instanceof Criteria) {
if ((!screenClass.bNew) && (screenClass.equals(((IScreenClassContainer<?>) screenClass.getConnector()).getDefaultScreenClass()))) {
throw new EngineException("You cannot paste a new criterion to the default screen class");
}
databaseObject.priority = databaseObject.getNewOrderValue();
screenClass.add(databaseObject);
} else if (databaseObject instanceof ExtractionRule) {
databaseObject.priority = databaseObject.getNewOrderValue();
screenClass.add(databaseObject);
} else if (databaseObject instanceof Sheet) {
screenClass.add(databaseObject);
} else if (databaseObject instanceof ScreenClass) {
databaseObject.priority = screenClass.priority + 1;
screenClass.add(databaseObject);
}
} else if (parentDatabaseObject instanceof HtmlTransaction) {
HtmlTransaction transaction = (HtmlTransaction) parentDatabaseObject;
if (databaseObject instanceof Sheet) {
transaction.add(databaseObject);
} else if (databaseObject instanceof TestCase) {
transaction.add(databaseObject);
} else if (databaseObject instanceof Variable) {
databaseObject.priority = databaseObject.getNewOrderValue();
transaction.add(databaseObject);
} else if (databaseObject instanceof FunctionStatement) {
if (databaseObject instanceof StatementWithExpressions) {
databaseObject.priority = 0;
}
transaction.add(databaseObject);
} else {
throw new EngineException("You cannot paste to an HtmlTransaction a database object of type " + databaseObject.getClass().getName());
}
} else if (parentDatabaseObject instanceof TransactionWithVariables) {
TransactionWithVariables transaction = (TransactionWithVariables) parentDatabaseObject;
if (databaseObject instanceof Sheet) {
transaction.add(databaseObject);
} else if (databaseObject instanceof TestCase) {
transaction.add(databaseObject);
} else if (databaseObject instanceof Variable) {
databaseObject.priority = databaseObject.getNewOrderValue();
transaction.add(databaseObject);
}
} else if (parentDatabaseObject instanceof Sequence) {
Sequence sequence = (Sequence) parentDatabaseObject;
if (databaseObject instanceof Sheet) {
sequence.add(databaseObject);
} else if (databaseObject instanceof TestCase) {
sequence.add(databaseObject);
} else if (databaseObject instanceof Step) {
databaseObject.priority = databaseObject.getNewOrderValue();
sequence.add(databaseObject);
} else if (databaseObject instanceof Variable) {
databaseObject.priority = databaseObject.getNewOrderValue();
sequence.add(databaseObject);
} else {
throw new EngineException("You cannot paste to a Sequence a database object of type " + databaseObject.getClass().getName());
}
} else if (parentDatabaseObject instanceof StatementWithExpressions) {
StatementWithExpressions statement = (StatementWithExpressions) parentDatabaseObject;
databaseObject.priority = databaseObject.getNewOrderValue();
statement.add(databaseObject);
} else if (parentDatabaseObject instanceof HTTPStatement) {
HTTPStatement statement = (HTTPStatement) parentDatabaseObject;
if (databaseObject instanceof Variable) {
databaseObject.priority = databaseObject.getNewOrderValue();
statement.add(databaseObject);
}
} else if (parentDatabaseObject instanceof StepWithExpressions) {
StepWithExpressions step = (StepWithExpressions) parentDatabaseObject;
databaseObject.priority = databaseObject.getNewOrderValue();
step.add(databaseObject);
} else if (parentDatabaseObject instanceof RequestableStep) {
RequestableStep step = (RequestableStep) parentDatabaseObject;
if (databaseObject instanceof Variable) {
databaseObject.priority = databaseObject.getNewOrderValue();
step.add(databaseObject);
}
} else if (parentDatabaseObject instanceof TestCase) {
TestCase testCase = (TestCase) parentDatabaseObject;
if (databaseObject instanceof Variable) {
databaseObject.priority = databaseObject.getNewOrderValue();
testCase.add(databaseObject);
}
} else // MOBILE COMPONENTS
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent app = GenericUtils.cast(parentDatabaseObject);
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
app.add(databaseObject);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
app.add(databaseObject);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
databaseObject.priority = databaseObject.getNewOrderValue();
app.add(databaseObject);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
app.add(databaseObject);
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteComponent) {
com.twinsoft.convertigo.beans.mobile.components.RouteComponent route = GenericUtils.cast(parentDatabaseObject);
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteActionComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
com.twinsoft.convertigo.beans.mobile.components.RouteActionComponent rac = GenericUtils.cast(databaseObject);
int i = rac.getPage().lastIndexOf(".");
if (i != -1) {
String pageName = rac.getPage().substring(i);
String pageQName = route.getParent().getQName() + pageName;
rac.setPage(pageQName);
}
route.add(rac);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteEventComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
route.add(databaseObject);
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
com.twinsoft.convertigo.beans.mobile.components.PageComponent page = GenericUtils.cast(parentDatabaseObject);
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
page.add(databaseObject);
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu menu = GenericUtils.cast(parentDatabaseObject);
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
menu.add(databaseObject);
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
com.twinsoft.convertigo.beans.mobile.components.UIComponent component = GenericUtils.cast(parentDatabaseObject);
databaseObject.priority = databaseObject.getNewOrderValue();
component.add(databaseObject);
}
} else // NGX COMPONENTS
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent app = GenericUtils.cast(parentDatabaseObject);
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
app.add(databaseObject);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
databaseObject.priority = databaseObject.getNewOrderValue();
app.add(databaseObject);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
app.add(databaseObject);
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
com.twinsoft.convertigo.beans.ngx.components.PageComponent page = GenericUtils.cast(parentDatabaseObject);
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
page.add(databaseObject);
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu menu = GenericUtils.cast(parentDatabaseObject);
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
databaseObject.priority = databaseObject.getNewOrderValue();
menu.add(databaseObject);
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
com.twinsoft.convertigo.beans.ngx.components.UIComponent component = GenericUtils.cast(parentDatabaseObject);
databaseObject.priority = databaseObject.getNewOrderValue();
component.add(databaseObject);
}
} else if (parentDatabaseObject == null) {
if (databaseObject instanceof Project) {
if (Engine.theApp.databaseObjectsManager.existsProject(databaseObject.getName())) {
throw new ObjectWithSameNameException("Project already exist!");
}
}
} else {
parentDatabaseObject.add(databaseObject);
}
} catch (ObjectWithSameNameException owsne) {
if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement)) {
throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
}
if ((parentDatabaseObject instanceof Sequence) && (databaseObject instanceof Step)) {
throw new EngineException("Sequence already contains a step named \"" + name + "\".", owsne);
}
}
NodeList childNodes = node.getChildNodes();
int len = childNodes.getLength();
Node childNode;
String childNodeName;
for (int i = 0; i < len; i++) {
childNode = childNodes.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
childNodeName = childNode.getNodeName();
if (!(childNodeName.equalsIgnoreCase("property")) && !(childNodeName.equalsIgnoreCase("handlers")) && !(childNodeName.equalsIgnoreCase("wsdltype")) && !(childNodeName.equalsIgnoreCase("docdata")) && !(childNodeName.equalsIgnoreCase("dnd"))) {
paste(childNode, databaseObject, bChangeName);
}
}
// For update of sources which reference this step
if (databaseObject instanceof Step) {
pastedSteps.put(String.valueOf(oldPriority), (Step) databaseObject);
}
// For update of sources which reference this mobile component
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.IAction || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIControlDirective || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIForm || databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) {
pastedComponents.put(String.valueOf(oldPriority), GenericUtils.cast(databaseObject));
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.IAction || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIControlDirective || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIForm || databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) {
pastedComponents.put(String.valueOf(oldPriority), GenericUtils.cast(databaseObject));
}
}
// needed
databaseObject.isImporting = false;
databaseObject.isSubLoaded = true;
return databaseObject;
} else if (object instanceof JsonData) {
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIPageEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIAppEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack) {
JsonData jsonData = (JsonData) object;
JSONObject json = jsonData.getData();
if (json.has("qname")) {
try {
com.twinsoft.convertigo.beans.mobile.components.UIComponent uiComponent = GenericUtils.cast(parentDatabaseObject);
DatabaseObject call = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.createBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getComponentByName("FullSyncViewAction"));
if (call != null && call instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) {
com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction dynAction = GenericUtils.cast(call);
com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean ionBean = dynAction.getIonBean();
if (ionBean != null && ionBean.hasProperty("fsview")) {
call.bNew = true;
call.hasChanged = true;
ionBean.setPropertyValue("fsview", new com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType(json.getString("qname")));
uiComponent.add(call);
uiComponent.hasChanged = true;
}
return call;
}
} catch (JSONException e) {
Engine.logStudio.warn("Failed to create a FullSyncViewAction", e);
}
}
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIPageEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIAppEvent || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction || parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack) {
JsonData jsonData = (JsonData) object;
JSONObject json = jsonData.getData();
if (json.has("qname")) {
try {
com.twinsoft.convertigo.beans.ngx.components.UIComponent uiComponent = GenericUtils.cast(parentDatabaseObject);
DatabaseObject call = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.createBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getComponentByName("FullSyncViewAction"));
if (call != null && call instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) {
com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction dynAction = GenericUtils.cast(call);
com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean ionBean = dynAction.getIonBean();
if (ionBean != null && ionBean.hasProperty("fsview")) {
call.bNew = true;
call.hasChanged = true;
ionBean.setPropertyValue("fsview", new com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType(json.getString("qname")));
uiComponent.add(call);
uiComponent.hasChanged = true;
}
return call;
}
} catch (JSONException e) {
Engine.logStudio.warn("Failed to create a FullSyncViewAction", e);
}
}
}
}
}
return null;
}
use of com.twinsoft.convertigo.beans.statements.HTTPStatement in project convertigo by convertigo.
the class ChangeToMultiValuedVariableAction 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 simple = (Variable) databaseObject;
Variable multi = null;
if (databaseObject instanceof TestCaseVariable)
multi = new TestCaseMultiValuedVariable();
if (databaseObject instanceof StepVariable)
multi = new StepMultiValuedVariable();
if (databaseObject instanceof RequestableVariable)
multi = new RequestableMultiValuedVariable();
if (databaseObject instanceof RequestableHttpVariable)
multi = new RequestableHttpMultiValuedVariable();
if (databaseObject instanceof HttpStatementVariable)
multi = new HttpStatementMultiValuedVariable();
if (multi != null) {
if (multi instanceof StepVariable) {
((StepVariable) multi).setSourceDefinition(((StepVariable) simple).getSourceDefinition());
}
if (multi instanceof RequestableVariable) {
((RequestableVariable) multi).setXmlTypeAffectation(((RequestableVariable) simple).getXmlTypeAffectation());
}
if (multi instanceof RequestableHttpVariable) {
// HttpName
((RequestableHttpVariable) multi).setHttpName(((RequestableHttpVariable) simple).getHttpName());
// HttpMethod
((RequestableHttpVariable) multi).setHttpMethod(((RequestableHttpVariable) simple).getHttpMethod());
}
Object value = simple.getValueOrNull();
multi.setValueOrNull(value);
multi.setVisibility(simple.getVisibility());
// Comment
multi.setComment(simple.getComment());
// Description
multi.setDescription(simple.getDescription());
// Required
multi.setRequired(simple.isRequired());
multi.bNew = true;
multi.hasChanged = true;
// Add new variable to parent
DatabaseObject parentDbo = simple.getParent();
parentDbo.add(multi);
// Set correct order
if (parentDbo instanceof TestCase)
((TestCase) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof RequestableStep)
((RequestableStep) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof TransactionWithVariables)
((TransactionWithVariables) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof HTTPStatement)
((HTTPStatement) parentDbo).insertAtOrder(multi, simple.priority);
// Add new variable in Tree
VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, multi);
treeParent.addChild(varTreeObject);
// Delete simple variable
simple.delete();
// Set correct name
multi.setName(simple.getName());
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(multi));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations