use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class AbstractStubAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
if ((treeObject != null) && (treeObject instanceof SequenceTreeObject)) {
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject;
Sequence sequence = sequenceTreeObject.getObject();
File stubDir = new File(sequence.getProject().getDirPath() + "/stubs");
stubDir.mkdirs();
File stubFile = new File(stubDir, sequence.getName() + ".xml");
Document dom = getXML(treeObject);
writeStub(dom, stubFile);
} else if ((treeObject != null) && (treeObject instanceof TransactionTreeObject)) {
TransactionTreeObject transactionTreeObject = (TransactionTreeObject) treeObject;
Transaction transaction = transactionTreeObject.getObject();
File stubDir = new File(transaction.getProject().getDirPath() + "/stubs");
stubDir.mkdirs();
File stubFile = new File(stubDir, transaction.getParent().getName() + "." + transaction.getName() + ".xml");
Document dom = getXML(treeObject);
writeStub(dom, stubFile);
}
}
} catch (NoSuchElementException e) {
ConvertigoPlugin.logException(e, "No previous XML file found");
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to execute the selected sequence!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class CreateEmptyStubAction method getXML.
public Document getXML(TreeObject treeObject) throws Exception {
Document dom = XMLUtils.createDom("java");
Element documentElement = (Element) dom.createElement("document");
Object requestable = treeObject.getObject();
if (requestable instanceof Transaction) {
Transaction transaction = (Transaction) requestable;
documentElement.setAttribute("connector", transaction.getParent().getName());
documentElement.setAttribute("fromcache", "false");
documentElement.setAttribute("generated", Calendar.getInstance(Locale.getDefault()).getTime().toString());
documentElement.setAttribute("project", transaction.getProject().getName());
documentElement.setAttribute("sequence", "");
documentElement.setAttribute("transaction", transaction.getName());
} else if (requestable instanceof Sequence) {
Sequence sequence = (Sequence) requestable;
documentElement.setAttribute("connector", "");
documentElement.setAttribute("fromcache", "false");
documentElement.setAttribute("generated", Calendar.getInstance(Locale.getDefault()).getTime().toString());
documentElement.setAttribute("project", sequence.getProject().getName());
documentElement.setAttribute("sequence", sequence.getName());
documentElement.setAttribute("transaction", "");
}
dom.appendChild(documentElement);
return dom;
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class ClipboardManager method cutAndPaste.
public void cutAndPaste(final DatabaseObject object, DatabaseObject parentDatabaseObject) throws ConvertigoException {
// Verifying if a sheet with the same browser does not already exist
if (object instanceof Sheet) {
String browser = ((Sheet) object).getBrowser();
Sheet sheet = null;
if (parentDatabaseObject instanceof ScreenClass) {
sheet = ((ScreenClass) parentDatabaseObject).getLocalSheet(browser);
} else if (parentDatabaseObject instanceof RequestableObject) {
sheet = ((RequestableObject) parentDatabaseObject).getSheet(browser);
}
if (sheet != null) {
throw new EngineException("You cannot cut and paste the sheet because a sheet is already defined for the browser \"" + browser + "\" in the screen class \"" + parentDatabaseObject.getName() + "\".");
}
}
if (object instanceof Step) {
if (object instanceof ThenStep) {
throw new EngineException("You cannot cut the \"Then\" step");
}
if (object instanceof ElseStep) {
throw new EngineException("You cannot cut the \"Else\" step");
}
}
if (object instanceof Statement) {
if (object instanceof ThenStatement)
throw new EngineException("You cannot cut the \"Then\" statement");
if (object instanceof ElseStatement)
throw new EngineException("You cannot cut the \"Else\" statement");
}
// Verify object is accepted for paste
if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(object);
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, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(object);
throw new EngineException("Template project " + tplVersion + " compatibility required");
}
}
// Verify if a child object with same name exist
boolean bContinue = true;
boolean bIncName = false;
String dboName = object.getName();
while (bContinue) {
try {
if (bIncName) {
dboName = DatabaseObject.incrementName(dboName);
object.setName(dboName);
}
new WalkHelper() {
boolean root = true;
boolean find = false;
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
boolean isInstance = dboClass.isInstance(object);
find |= isInstance;
return isInstance;
}
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (root) {
root = false;
if (databaseObject instanceof Project) {
if (object instanceof Connector && ((Connector) object).isDefault) {
throw new EngineException("You cannot cut the default connector to another project");
}
} else if (databaseObject instanceof Connector) {
if (object instanceof ScreenClass) {
throw new EngineException("You cannot cut the default screen class to another connector");
} else if (object instanceof Transaction && ((Transaction) object).isDefault) {
throw new EngineException("You cannot cut the default transaction to another connector");
}
} else if (databaseObject instanceof ScreenClass) {
if (object instanceof Criteria && databaseObject.getParent() instanceof Connector) {
throw new EngineException("You cannot cut the criterion of default screen class");
}
} else if (databaseObject instanceof MobileObject) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
if (object instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(object);
if (pc.isRoot) {
throw new EngineException("You cannot cut the root page to another application");
}
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
if (object instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(object);
if (pc.isRoot) {
throw new EngineException("You cannot cut the root page to another application");
}
}
}
}
super.walk(databaseObject);
if (!find) {
throw new EngineException("You cannot cut and paste to a " + databaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
} else {
if (object != databaseObject && object.getName().equalsIgnoreCase(databaseObject.getName())) {
throw new ObjectWithSameNameException("Unable to cut the object because an object with the same name already exists in target.");
}
}
}
}.init(parentDatabaseObject);
bContinue = false;
} catch (ObjectWithSameNameException e) {
bIncName = true;
} catch (EngineException e) {
throw e;
} catch (Exception e) {
throw new EngineException("Exception in cutAndPaste", e);
}
}
move(object, parentDatabaseObject);
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class ClipboardManager method appendDndData.
private void appendDndData(Element element, DatabaseObject databaseObject) {
Element dnd = clipboardDocument.createElement("dnd");
Element e;
try {
if (databaseObject instanceof Sequence) {
Sequence sequence = (Sequence) databaseObject;
e = clipboardDocument.createElement("project");
e.setAttribute("name", sequence.getProject().getName());
dnd.appendChild(e);
} else if (databaseObject instanceof Transaction) {
Transaction transaction = (Transaction) databaseObject;
e = clipboardDocument.createElement("project");
e.setAttribute("name", transaction.getProject().getName());
dnd.appendChild(e);
e = clipboardDocument.createElement("connector");
e.setAttribute("name", transaction.getConnector().getName());
dnd.appendChild(e);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
com.twinsoft.convertigo.beans.mobile.components.UIComponent uic = GenericUtils.cast(databaseObject);
e = clipboardDocument.createElement("project");
e.setAttribute("name", uic.getProject().getName());
dnd.appendChild(e);
e = clipboardDocument.createElement("mobileapplication");
e.setAttribute("name", uic.getApplication().getParent().getName());
dnd.appendChild(e);
e = clipboardDocument.createElement("application");
e.setAttribute("name", uic.getApplication().getName());
dnd.appendChild(e);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
com.twinsoft.convertigo.beans.ngx.components.UIComponent uic = GenericUtils.cast(databaseObject);
e = clipboardDocument.createElement("project");
e.setAttribute("name", uic.getProject().getName());
dnd.appendChild(e);
e = clipboardDocument.createElement("mobileapplication");
e.setAttribute("name", uic.getApplication().getParent().getName());
dnd.appendChild(e);
e = clipboardDocument.createElement("application");
e.setAttribute("name", uic.getApplication().getName());
dnd.appendChild(e);
}
} catch (Exception ex) {
}
element.appendChild(dnd);
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class ConnectorTreeObject method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
Connector connector = this.getObject();
if (databaseObject instanceof Transaction) {
Transaction transaction = (Transaction) databaseObject;
if (transaction.getConnector().equals(connector)) {
if (connector.getEndTransactionName().equals(oldValue)) {
connector.setEndTransactionName((String) newValue);
try {
getProjectExplorerView().refreshTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not refresh in tree Connector \"" + databaseObject.getName() + "\" !");
}
}
}
} else if (databaseObject instanceof JsonIndex && connector.equals(databaseObject.getParent())) {
CouchDbManager.syncDocument(connector);
}
// Case of this connector rename : update all transaction schemas
if (treeObject.equals(this)) {
String path = Project.XSD_FOLDER_NAME + "/" + Project.XSD_INTERNAL_FOLDER_NAME;
String oldPath = path + "/" + (String) oldValue;
String newPath = path + "/" + (String) newValue;
IFolder folder = getProjectTreeObject().getFolder(oldPath);
try {
folder.getParent().refreshLocal(IResource.DEPTH_ONE, null);
if (folder.exists()) {
// rename folder (xsd/internal/connector)
folder.move(new Path((String) newValue), true, null);
// make replacements in schema file
List<Replacement> replacements = new ArrayList<Replacement>();
replacements.add(new Replacement((String) oldValue + "__", (String) newValue + "__"));
IFolder newFolder = folder.getParent().getFolder(new Path((String) newValue));
for (Transaction transaction : getObject().getTransactionsList()) {
IFile file = newFolder.getFile(new Path(transaction.getName() + ".xsd"));
if (file.exists()) {
String filePath = file.getLocation().makeAbsolute().toString();
try {
ProjectUtils.makeReplacementsInFile(replacements, filePath);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could rename \"" + oldValue + "\" to \"" + newValue + "\" in schema file \"" + filePath + "\" !");
}
}
}
// refresh folder
folder.refreshLocal(IResource.DEPTH_ONE, null);
Engine.theApp.schemaManager.clearCache(getProjectTreeObject().getName());
}
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not rename folder from \"" + oldPath + "\" to \"" + newPath + "\" !");
}
if (connector instanceof CouchDbConnector) {
CouchDbManager.syncDocument(connector);
try {
getProjectExplorerView().reloadTreeObject(this);
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Could not reload connector \"" + connector.getName() + "\" in tree !");
}
}
}
}
Aggregations