use of com.twinsoft.convertigo.beans.steps.IThenElseContainer 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.steps.IThenElseContainer 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.steps.IThenElseContainer 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;
}
Aggregations