use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class NgxPickerComposite method getJsonModel.
private JSONObject getJsonModel(Map<String, Object> data, DatabaseObject databaseObject) throws Exception {
JSONObject jsonModel = new JSONObject();
Map<String, String> params;
DatabaseObject dbo;
String dataPath;
if (databaseObject == null) {
dbo = (DatabaseObject) data.get("databaseObject");
params = GenericUtils.cast(data.get("params"));
dataPath = (String) data.get("searchPath");
} else {
dbo = databaseObject;
params = new HashMap<String, String>();
dataPath = "";
}
if (dbo != null) {
// case of requestable
if (dbo instanceof RequestableObject) {
RequestableObject ro = (RequestableObject) dbo;
Project project = ro.getProject();
String responseEltName = ro.getXsdTypePrefix() + ro.getName() + "Response";
boolean isDocumentNode = JsonRoot.docNode.equals(project.getJsonRoot()) && dataPath.isEmpty();
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(project.getName());
XmlSchemaObject xso = SchemaMeta.getXmlSchemaObject(schema, ro);
if (xso != null) {
Document document = XmlSchemaUtils.getDomInstance(xso);
// System.out.println(XMLUtils.prettyPrintDOM(document));
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonObject = new JSONObject(jsonString);
String searchPath = "document." + responseEltName + ".response";
searchPath += isDocumentNode || !dataPath.startsWith(".document") ? dataPath : dataPath.replaceFirst("\\.document", "");
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = isDocumentNode ? new JSONObject().put("document", jsonOutput) : jsonOutput;
}
} else if (dbo instanceof DesignDocument) {
DesignDocument dd = (DesignDocument) dbo;
Connector connector = dd.getConnector();
String ddoc = params.get("ddoc");
String view = params.get("view");
String viewName = ddoc + "/" + view;
String includeDocs = params.get("include_docs");
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
((GetViewTransaction) transaction).setViewname(viewName);
((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
view_reduce.setValueOrNull(false);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalView, false);
}
}
});
} else // case of UIForm
if (dbo instanceof UIForm) {
// JSONObject jsonObject = new JSONObject("{\"controls\":{\"['area']\":{\"value\":\"\"}}}");
JSONObject jsonObject = new JSONObject(((UIForm) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UIACtionStack
if (dbo instanceof UIActionStack) {
JSONObject jsonObject = new JSONObject(((UIActionStack) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UIDynamicAction or UICustomAction
if (dbo instanceof IAction) {
JSONObject jsonObject = new JSONObject();
if (dbo instanceof UIDynamicAction) {
UIDynamicAction uida = (UIDynamicAction) dbo;
jsonObject = new JSONObject(uida.computeJsonModel());
IonBean ionBean = uida.getIonBean();
if (ionBean != null) {
String name = ionBean.getName();
if ("CallSequenceAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
DatabaseObject sequence = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (sequence != null) {
JSONObject targetJsonModel = getJsonModel(data, sequence);
if (jsonObject.has("out")) {
jsonObject.put("out", targetJsonModel);
}
}
} else if ("CallFullSyncAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
String verb = ionBean.getProperty("verb").getValue().toString();
Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
AbstractCouchDbTransaction act = null;
if ("all".equals(verb))
act = new AllDocsTransaction();
else if ("create".equals(verb))
act = new PutDatabaseTransaction();
else if ("destroy".equals(verb))
act = new DeleteDatabaseTransaction();
else if ("get".equals(verb))
act = new GetDocumentTransaction();
else if ("delete".equals(verb))
act = new DeleteDocumentTransaction();
else if ("delete_attachment".equals(verb))
act = new DeleteDocumentAttachmentTransaction();
else if ("post".equals(verb))
act = new PostDocumentTransaction();
else if ("put_attachment".equals(verb))
act = new PutDocumentAttachmentTransaction();
else if ("replicate_push".equals(verb))
act = new PostReplicateTransaction();
else if ("reset".equals(verb))
act = new ResetDatabaseTransaction();
else if ("view".equals(verb))
act = new GetViewTransaction();
if (act != null) {
QName typeQName = act.getComplexTypeAffectation();
XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
cleanJsonModel(jsonOutput);
jsonOutput.remove("_c8oMeta");
jsonOutput.remove("error");
jsonOutput.remove("reason");
if (jsonObject.has("out")) {
jsonObject.put("out", jsonOutput);
}
}
}
} else if ("FullSyncGetAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
String docid = ionBean.getProperty("_id").getValue().toString();
Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalDocument);
Variable var_docid = ((GetDocumentTransaction) transaction).getVariable(CouchParam.docid.param());
var_docid.setValueOrNull(docid);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalDocument, false);
}
}
});
}
} else if ("FullSyncViewAction".equals(name)) {
String fsview = ionBean.getProperty("fsview").getValue().toString();
String includeDocs = ionBean.getProperty("include_docs").getValue().toString();
String reduce = ionBean.getProperty("reduce").getValue().toString();
String qname = fsview.substring(0, fsview.lastIndexOf('.'));
DesignDocument dd = (DesignDocument) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
Connector connector = dd.getConnector();
String viewName = dd.getName() + "/" + fsview.substring(fsview.lastIndexOf('.') + 1);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
((GetViewTransaction) transaction).setViewname(viewName);
((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
view_reduce.setValueOrNull(reduce);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalView, false);
}
}
});
} else if (name.startsWith("FullSync")) {
if (ionBean.getProperty("requestable") != null) {
String qname = ionBean.getProperty("requestable").getValue().toString();
DatabaseObject connector = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
AbstractCouchDbTransaction act = null;
if ("FullSyncDeleteAction".equals(name))
act = new DeleteDocumentTransaction();
else if ("FullSyncDeleteAttachmentAction".equals(name))
act = new DeleteDocumentAttachmentTransaction();
else if ("FullSyncPostAction".equals(name))
act = new PostDocumentTransaction();
else if ("FullSyncPutAttachmentAction".equals(name))
act = new PutDocumentAttachmentTransaction();
if (act != null) {
QName typeQName = act.getComplexTypeAffectation();
XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
cleanJsonModel(jsonOutput);
jsonOutput.remove("_c8oMeta");
jsonOutput.remove("error");
jsonOutput.remove("reason");
if (jsonObject.has("out")) {
jsonObject.put("out", jsonOutput);
}
}
}
}
}
}
} else if (dbo instanceof UICustomAction) {
jsonObject = new JSONObject(((UICustomAction) dbo).computeJsonModel());
}
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UISharedComponent
if (dbo instanceof UISharedComponent) {
JSONObject jsonObject = new JSONObject(((UISharedComponent) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of ApplicationComponent
if (dbo instanceof ApplicationComponent) {
String json = params.get("json");
jsonModel = new JSONObject(json);
} else // should not happened
{
throw new Exception("DatabaseObject " + dbo.getClass().getName() + " not supported!");
}
}
return jsonModel;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class MobilePickerComposite method lookupModelData.
private Map<String, Object> lookupModelData(TVObject tvObject) {
Map<String, Object> data = new HashMap<String, Object>();
Map<String, String> params = new HashMap<String, String>();
DatabaseObject dbo = null;
String searchPath = "";
Object object = tvObject.getObject();
JSONObject infos = tvObject.getInfos();
if (object != null) {
try {
if (object instanceof RequestableObject) {
dbo = (RequestableObject) object;
searchPath = "";
} else if (object instanceof DesignDocument) {
dbo = (DesignDocument) object;
DesignDocument dd = (DesignDocument) dbo;
params.put("ddoc", dd.getName());
params.put("view", tvObject.getParent().getName());
params.put("include_docs", infos.has("include_docs") ? infos.getString("include_docs") : "false");
searchPath = tvObject.getName().startsWith("get") ? ".rows.value" : "";
} else if (object instanceof UIControlDirective) {
dbo = (UIControlDirective) object;
do {
UIControlDirective directive = (UIControlDirective) dbo;
String rootDboName = "";
if (directive.getPage() != null) {
rootDboName = directive.getPage().getName();
} else if (directive.getMenu() != null) {
rootDboName = directive.getMenu().getName();
}
MobileSmartSourceType msst = directive.getSourceSmartType();
MobileSmartSource mss = msst.getSmartSource();
if (mss != null) {
dbo = mss.getDatabaseObject(rootDboName);
params.putAll(mss.getParameters());
searchPath = mss.getModelPath().replaceAll("\\?\\.", ".") + searchPath;
} else {
dbo = null;
}
} while (dbo != null && dbo instanceof UIControlDirective);
} else if (object instanceof UIForm) {
dbo = (UIForm) object;
searchPath = "";
} else if (object instanceof ApplicationComponent) {
dbo = (ApplicationComponent) object;
params.put("json", infos.toString());
searchPath = "";
} else if (object instanceof UIActionStack) {
dbo = (UIActionStack) object;
searchPath = "";
} else if (object instanceof IAction) {
if (object instanceof UIDynamicAction) {
dbo = (UIDynamicAction) object;
searchPath = "";
} else if (object instanceof UICustomAction) {
dbo = (UICustomAction) object;
searchPath = "";
}
} else if (object instanceof UISharedComponent) {
dbo = (UISharedComponent) object;
searchPath = "";
}
} catch (Exception e) {
e.printStackTrace();
}
}
data.put("databaseObject", dbo);
data.put("params", params);
data.put("searchPath", searchPath);
return data;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject 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;
boolean bIncName = false;
long oldPriority = databaseObject.priority;
// Verify if a child object with same name exist and change name
while (bContinue) {
if (bIncName) {
dboName = DatabaseObject.incrementName(dboName);
databaseObject.setName(dboName);
}
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);
}
if (bChangeName) {
bIncName = true;
}
} 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.UISharedComponentEvent || 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.core.DatabaseObject in project convertigo by convertigo.
the class ClipboardManager method copy.
public String copy(TreePath[] treePaths) throws EngineException {
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
clipboardDocument = XMLUtils.getDefaultDocumentBuilder().newDocument();
ProcessingInstruction pi = clipboardDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"ISO-8859-1\"");
clipboardDocument.appendChild(pi);
clipboardRootElement = clipboardDocument.createElement("convertigo-clipboard");
clipboardDocument.appendChild(clipboardRootElement);
TreePath[] selectedPaths = ((treePaths == null) ? projectExplorerView.getSelectionPaths() : treePaths);
treeObjectsList = new ArrayList<TreeObject>();
treeParentsList = new ArrayList<TreeObject>();
for (int i = 0; i < selectedPaths.length; i++) {
TreeObject treeObject = (TreeObject) selectedPaths[i].getLastPathComponent();
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) treeObject;
DatabaseObjectTreeObject parentDatabaseObjectTreeObject = databaseObjectTreeObject.getParentDatabaseObjectTreeObject();
treeObjectsList.add(databaseObjectTreeObject);
treeParentsList.add(parentDatabaseObjectTreeObject);
copyDatabaseObject((DatabaseObject) databaseObjectTreeObject.getObject());
} else if (treeObject instanceof IPropertyTreeObject) {
IPropertyTreeObject propertyTreeObject = (IPropertyTreeObject) treeObject;
treeObjectsList.add(treeObject);
treeParentsList.add(((IPropertyTreeObject) treeObject).getTreeObjectOwner());
copyPropertyObject(propertyTreeObject);
} else if (treeObject instanceof IDesignTreeObject) {
IDesignTreeObject designTreeObject = (IDesignTreeObject) treeObject;
treeObjectsList.add(treeObject);
treeParentsList.add(((IDesignTreeObject) treeObject).getTreeObjectOwner());
copyDesignObject(designTreeObject);
} else {
throw new EngineException("Tree item not supported :" + treeObject.getClass().getName());
}
}
objects = treeObjectsList.toArray(new Object[selectedPaths.length]);
parentTreeNodeOfCutObjects = treeParentsList.toArray(new TreeObject[selectedPaths.length]);
String strObject = XMLUtils.prettyPrintDOM(clipboardDocument);
return strObject;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class ConnectorTreeObject 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();
Connector connector = this.getObject();
// A transaction has been removed
if (databaseObject instanceof Transaction) {
if (connector.getEndTransactionName().equals(databaseObject.getName())) {
connector.setEndTransactionName("");
try {
getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not refresh in tree Connector \"" + databaseObject.getName() + "\" !");
}
}
} else if (databaseObject instanceof JsonIndex) {
CouchDbManager.syncDocument(connector);
}
}
}
}
Aggregations