use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class SetDefaultTransactionAction method run.
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) {
TransactionTreeObject transactionTreeObject = (TransactionTreeObject) explorerView.getFirstSelectedTreeObject();
Transaction transaction = (Transaction) explorerView.getFirstSelectedDatabaseObject();
Connector connector = (Connector) transaction.getParent();
// Report from 4.5: fix #401
TransactionTreeObject defaultTransactionTreeObject = null;
Transaction defaultTransaction = connector.getDefaultTransaction();
if (defaultTransaction != null) {
defaultTransactionTreeObject = (TransactionTreeObject) explorerView.findTreeObjectByUserObject(defaultTransaction);
}
connector.setDefaultTransaction(transaction);
if (defaultTransactionTreeObject != null) {
defaultTransactionTreeObject.isDefault = false;
defaultTransactionTreeObject.hasBeenModified(true);
}
transactionTreeObject.isDefault = true;
transactionTreeObject.hasBeenModified(true);
// Updating the tree
explorerView.refreshTreeObject(transactionTreeObject.getParentDatabaseObjectTreeObject());
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to set transaction to default one!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class DatabaseObjectsManager method performWsMigration.
private boolean performWsMigration(String version, String projectName) {
if (VersionUtils.compare(version, "4.6.0") < 0) {
try {
// Retrieve a !clone! of project to perform update
Project project = getProjectByName(projectName);
for (Connector connector : project.getConnectorsList()) {
// Retrieve backup wsdlTypes and store Transaction's schema
for (Transaction transaction : connector.getTransactionsList()) {
try {
String xsdTypes = transaction.migrateToXsdTypes();
transaction.writeSchemaToFile(xsdTypes);
Engine.logDatabaseObjectManager.info("Internal schema stored for \"" + transaction.getName() + "\" transaction");
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("An error occured while writing schema to file for \"" + transaction.getName() + "\" transaction");
}
}
}
// Fix sequence's steps sources
for (Sequence sequence : project.getSequencesList()) {
try {
List<Step> steps = sequence.getSteps();
// Replace source's xpath
// replace ./xxx by
// ./transaction/document/xxx or by
// ./sequence/document/xxx
replaceSourceXpath(version, sequence, steps);
Engine.logDatabaseObjectManager.info("Step sources updated for sequence \"" + sequence.getName() + "\"");
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("An error occured while updating step sources for sequence \"" + sequence.getName() + "\"");
}
}
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("An error occured while updating project '" + projectName + "' for XSD", e);
return false;
}
}
return true;
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class Migration7_0_0 method migrate.
public static void migrate(final String projectName) {
try {
Map<String, Reference> referenceMap = new HashMap<String, Reference>();
XmlSchema projectSchema = null;
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
// Copy all xsd files to project's xsd directory
File destDir = new File(project.getXsdDirPath());
copyXsdOfProject(projectName, destDir);
String projectWsdlFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".wsdl";
File wsdlFile = new File(projectWsdlFilePath);
String projectXsdFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".xsd";
File xsdFile = new File(projectXsdFilePath);
if (xsdFile.exists()) {
// Load project schema from old XSD file
XmlSchemaCollection collection = new XmlSchemaCollection();
collection.setSchemaResolver(new DefaultURIResolver() {
public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
// Case of a c8o project location
if (schemaLocation.startsWith("../") && schemaLocation.endsWith(".xsd")) {
try {
String targetProjectName = schemaLocation.substring(3, schemaLocation.indexOf("/", 3));
File pDir = new File(Engine.projectDir(targetProjectName));
if (pDir.exists()) {
File pFile = new File(Engine.PROJECTS_PATH + schemaLocation.substring(2));
// Case c8o project is already migrated
if (!pFile.exists()) {
Document doc = Engine.theApp.schemaManager.getSchemaForProject(targetProjectName).getSchemaDocument();
DOMSource source = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory.newInstance().newTransformer().transform(source, result);
StringReader reader = new StringReader(writer.toString());
return new InputSource(reader);
}
}
return null;
} catch (Exception e) {
Engine.logDatabaseObjectManager.warn("[Migration 7.0.0] Unable to find schema location \"" + schemaLocation + "\"", e);
return null;
}
} else if (schemaLocation.indexOf("://") == -1 && schemaLocation.endsWith(".xsd")) {
return super.resolveEntity(targetNamespace, schemaLocation, Engine.PROJECTS_PATH + "/" + projectName);
}
return super.resolveEntity(targetNamespace, schemaLocation, baseUri);
}
});
projectSchema = SchemaUtils.loadSchema(new File(projectXsdFilePath), collection);
ConvertigoError.updateXmlSchemaObjects(projectSchema);
SchemaMeta.setCollection(projectSchema, collection);
for (Connector connector : project.getConnectorsList()) {
for (Transaction transaction : connector.getTransactionsList()) {
try {
// Migrate transaction in case of a Web Service consumption project
if (transaction instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) transaction;
String reqn = xmlHttpTransaction.getResponseElementQName();
if (!reqn.equals("")) {
boolean useRef = reqn.indexOf(";") == -1;
// Doc/Literal case
if (useRef) {
try {
String[] qn = reqn.split(":");
QName refName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName));
} catch (Exception e) {
}
} else // RPC case
{
int index, index2;
try {
index = reqn.indexOf(";");
String opName = reqn.substring(0, index);
if ((index2 = reqn.indexOf(";", index + 1)) != -1) {
String eltName = reqn.substring(index + 1, index2);
String eltType = reqn.substring(index2 + 1);
String[] qn = eltType.split(":");
QName typeName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
String responseElementQName = opName + ";" + eltName + ";" + "{" + typeName.getNamespaceURI() + "}" + typeName.getLocalPart();
xmlHttpTransaction.setResponseElementQName(responseElementQName);
}
} catch (Exception e) {
}
}
}
}
// Retrieve required XmlSchemaObjects for transaction
QName requestQName = new QName(project.getTargetNamespace(), transaction.getXsdRequestElementName());
QName responseQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseElementName());
LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, false);
dw.walkByElementRef(projectSchema, requestQName);
dw.walkByElementRef(projectSchema, responseQName);
// Create transaction schema
String targetNamespace = projectSchema.getTargetNamespace();
String prefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
XmlSchema transactionSchema = SchemaUtils.createSchema(prefix, targetNamespace, XsdForm.unqualified.name(), XsdForm.unqualified.name());
// Add required prefix declarations
List<String> nsList = new LinkedList<String>();
for (QName qname : map.keySet()) {
String nsURI = qname.getNamespaceURI();
if (!nsURI.equals(Constants.URI_2001_SCHEMA_XSD)) {
if (!nsList.contains(nsURI)) {
nsList.add(nsURI);
}
}
String nsPrefix = qname.getPrefix();
if (!nsURI.equals(targetNamespace)) {
NamespaceMap nsMap = SchemaUtils.getNamespaceMap(transactionSchema);
if (nsMap.getNamespaceURI(nsPrefix) == null) {
nsMap.add(nsPrefix, nsURI);
transactionSchema.setNamespaceContext(nsMap);
}
}
}
// Add required imports
for (String namespaceURI : nsList) {
XmlSchemaObjectCollection includes = projectSchema.getIncludes();
for (int i = 0; i < includes.getCount(); i++) {
XmlSchemaObject xmlSchemaObject = includes.getItem(i);
if (xmlSchemaObject instanceof XmlSchemaImport) {
if (((XmlSchemaImport) xmlSchemaObject).getNamespace().equals(namespaceURI)) {
// do not allow import with same ns !
if (namespaceURI.equals(project.getTargetNamespace()))
continue;
String location = ((XmlSchemaImport) xmlSchemaObject).getSchemaLocation();
// This is a convertigo project reference
if (location.startsWith("../")) {
// Copy all xsd files to xsd directory
String targetProjectName = location.substring(3, location.indexOf("/", 3));
copyXsdOfProject(targetProjectName, destDir);
}
// Add reference
addReferenceToMap(referenceMap, namespaceURI, location);
// Add import
addImport(transactionSchema, namespaceURI, location);
}
}
}
}
QName responseTypeQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseTypeName());
// Add required schema objects
for (QName qname : map.keySet()) {
if (qname.getNamespaceURI().equals(targetNamespace)) {
XmlSchemaObject ob = map.get(qname);
if (qname.getLocalPart().startsWith("ConvertigoError"))
continue;
transactionSchema.getItems().add(ob);
// Add missing response error element and attributes
if (qname.equals(responseTypeQName)) {
Transaction.addSchemaResponseObjects(transactionSchema, (XmlSchemaComplexType) ob);
}
}
}
// Add missing ResponseType (with document)
if (map.containsKey(responseTypeQName)) {
Transaction.addSchemaResponseType(transactionSchema, transaction);
}
// Add everything
if (map.isEmpty()) {
Transaction.addSchemaObjects(transactionSchema, transaction);
}
// Add c8o error objects (for internal xsd edition only)
ConvertigoError.updateXmlSchemaObjects(transactionSchema);
// Save schema to file
String transactionXsdFilePath = transaction.getSchemaFilePath();
new File(transaction.getSchemaFileDirPath()).mkdirs();
SchemaUtils.saveSchema(transactionXsdFilePath, transactionSchema);
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating transaction \"" + transaction.getName() + "\"", e);
}
if (transaction instanceof TransactionWithVariables) {
TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
handleRequestableVariable(transactionVars.getVariablesList());
// Change SQLQuery variables : i.e. {id} --> {{id}}
if (transaction instanceof SqlTransaction) {
String sqlQuery = ((SqlTransaction) transaction).getSqlQuery();
sqlQuery = sqlQuery.replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{{$1}}");
((SqlTransaction) transaction).setSqlQuery(sqlQuery);
}
}
}
}
} else {
// Should only happen for projects which version <= 4.6.0
XmlSchemaCollection collection = new XmlSchemaCollection();
String prefix = project.getName() + "_ns";
projectSchema = SchemaUtils.createSchema(prefix, project.getNamespaceUri(), XsdForm.unqualified.name(), XsdForm.unqualified.name());
ConvertigoError.addXmlSchemaObjects(projectSchema);
SchemaMeta.setCollection(projectSchema, collection);
for (Connector connector : project.getConnectorsList()) {
for (Transaction transaction : connector.getTransactionsList()) {
if (transaction instanceof TransactionWithVariables) {
TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
handleRequestableVariable(transactionVars.getVariablesList());
}
}
}
}
// Handle sequence objects
for (Sequence sequence : project.getSequencesList()) {
handleSteps(projectSchema, referenceMap, sequence.getSteps());
handleRequestableVariable(sequence.getVariablesList());
}
// Add all references to project
if (!referenceMap.isEmpty()) {
for (Reference reference : referenceMap.values()) project.add(reference);
}
// Delete XSD file
if (xsdFile.exists())
xsdFile.delete();
// Delete WSDL file
if (wsdlFile.exists())
wsdlFile.delete();
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating project \"" + projectName + "\"", e);
}
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class TreeDropAdapter method move.
private boolean move(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) {
;
} else // URLMAPPER
if (parent instanceof UrlMappingOperation) {
// Set associated requestable
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;
return true;
}
} else if (parent instanceof UrlMappingParameter) {
// Set associated mapped variable for parameter
if (databaseObject instanceof RequestableVariable) {
RequestableVariable variable = (RequestableVariable) databaseObject;
UrlMappingParameter parameter = (UrlMappingParameter) parent;
parameter.setMappedVariableName(variable.getName());
parameter.hasChanged = true;
return true;
}
}
}
return false;
}
use of com.twinsoft.convertigo.beans.core.Transaction in project convertigo by convertigo.
the class SapJcoConnectorDesignComposite method createBapiTransactions.
private void createBapiTransactions(final TableItem[] items) {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = display.getActiveShell();
if (shell != null) {
try {
shell.setCursor(waitCursor);
for (int i = 0; i < items.length; i++) {
TableItem item = items[i];
String bapiName = item.getText(0);
String bapiDesc = item.getText(1);
ConvertigoPlugin.logDebug("Creating transaction for BAPI '" + bapiName + "' ...");
sapConnector.removeSerializedData(bapiName);
SapJcoTransaction sapJcoTransaction = SapJcoConnector.createSapJcoTransaction(sapConnector, bapiName);
if (sapJcoTransaction != null) {
Transaction transaction = sapConnector.getTransactionByName(bapiName);
if (transaction != null) {
try {
File xsdFile = new File(transaction.getSchemaFilePath());
if (xsdFile.exists()) {
xsdFile.delete();
}
} catch (Exception e) {
}
sapConnector.remove(transaction);
}
sapJcoTransaction.setComment(bapiDesc);
sapConnector.add(sapJcoTransaction);
fireObjectChanged(new CompositeEvent(sapConnector));
ConvertigoPlugin.logDebug("Transaction added.");
}
}
} catch (Exception ee) {
ConvertigoPlugin.logException(ee, "Error while creating transaction(s)");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
}
Aggregations