use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class ReferencesView method handleTargetRequestable.
private void handleTargetRequestable(String targetRequestableName, ProjectExplorerView projectExplorerView, RequiresNode requiresNode) throws EngineException {
StringTokenizer st = new StringTokenizer(targetRequestableName, ".");
int count = st.countTokens();
String projectName = st.nextToken();
Project project = getProject(projectName, projectExplorerView);
if (project != null) {
ProjectNode requiresProjectNode = new ProjectNode(requiresNode, projectName, project);
if (count == 2) {
String sequenceName = count == 2 ? st.nextToken() : "";
Sequence sequence = project.getSequenceByName(sequenceName);
SequenceNode sequenceNode = new SequenceNode(requiresProjectNode, sequenceName, sequence);
requiresProjectNode.addChild(sequenceNode);
} else if (count == 3) {
String connectorName = count == 3 ? st.nextToken() : "";
Connector connector = project.getConnectorByName(connectorName);
ConnectorNode connectorNode = new ConnectorNode(requiresProjectNode, connectorName, connector);
requiresProjectNode.addChild(connectorNode);
String transactionName = count == 3 ? st.nextToken() : "";
Transaction transaction = connector.getTransactionByName(transactionName);
TransactionNode transactionNode = new TransactionNode(connectorNode, transactionName, transaction);
connectorNode.addChild(transactionNode);
}
if (requiresProjectNode.hasChildren()) {
requiresNode.addChild(requiresProjectNode);
}
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class ReferencesView method handleSequenceSelection.
private void handleSequenceSelection(Object firstElement) {
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) firstElement;
Sequence sequenceSelected = sequenceTreeObject.getObject();
String sequenceSelectedName = sequenceSelected.getName();
// String sequenceProjectName = sequenceSelected.getProject().getName();
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
treeViewer.setInput(null);
// Get the referencing sequence steps
List<String> referencingSequence = new ArrayList<String>();
RootNode root = new RootNode();
SequenceNode sequenceFolder = new SequenceNode(root, sequenceSelectedName, sequenceSelected);
root.addChild(sequenceFolder);
IsUsedByNode isUsedByNode = new IsUsedByNode(sequenceFolder, "Is used by");
// Searching all objects that reference the selected sequence
for (String projectName : projectNames) {
Project project = getProject(projectName, projectExplorerView);
if (project != null) {
ProjectNode projectFolder = null;
projectFolder = new ProjectNode(isUsedByNode, project.getName(), project);
List<Sequence> sequences = project.getSequencesList();
referencingSequence.clear();
UrlMapper urlMapper = project.getUrlMapper();
if (urlMapper != null) {
MapperNode mapperNode = new MapperNode(projectFolder, urlMapper.getName(), urlMapper);
List<UrlMapping> mappings = urlMapper.getMappingList();
for (UrlMapping mapping : mappings) {
MappingPathNode pathNode = new MappingPathNode(mapperNode, mapping.getPath(), mapping);
List<UrlMappingOperation> operations = mapping.getOperationList();
for (UrlMappingOperation operation : operations) {
String targetRequestable = operation.getTargetRequestable();
if (targetRequestable.equals(projectName + "." + sequenceSelectedName)) {
MappingOperationNode operationNode = new MappingOperationNode(pathNode, operation.getName(), operation);
pathNode.addChild(operationNode);
}
}
if (pathNode.hasChildren()) {
mapperNode.addChild(pathNode);
}
}
if (mapperNode.hasChildren()) {
projectFolder.addChild(mapperNode);
}
}
for (Sequence sequence : sequences) {
List<Step> steps = sequence.getSteps();
for (Step step : steps) {
SequenceNode sequenceNode = new SequenceNode(projectFolder, sequence.getName(), sequence);
getSequenceReferencingIsUsedBy(step, sequenceSelected, sequenceNode);
if (sequenceNode.hasChildren()) {
projectFolder.addChild(sequenceNode);
}
}
}
if (projectFolder.hasChildren()) {
isUsedByNode.addChild(projectFolder);
}
}
}
List<Step> steps = sequenceSelected.getSteps();
RequiresNode requiresNode = new RequiresNode(root, "Requires");
// Searching all objects that are referenced by the selected sequence
List<String> transactionList = new ArrayList<String>();
List<String> sequenceList = new ArrayList<String>();
for (Step step : steps) {
getSequenceReferencingRequires(step, sequenceSelected, projectExplorerView, requiresNode, transactionList, sequenceList);
}
if (requiresNode.hasChildren()) {
sequenceFolder.addChild(requiresNode);
}
if (isUsedByNode.hasChildren()) {
sequenceFolder.addChild(isUsedByNode);
}
if (!sequenceFolder.hasChildren()) {
sequenceFolder.addChild(new InformationNode(sequenceFolder, "This sequence is not used in any sequence"));
}
treeViewer.setInput(root);
treeViewer.expandAll();
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class ProcessExecStep method createStepNodeValue.
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
ProcessStreamReaderThread stderrThread = null, stdoutThread = null;
// Create step child nodes
final Node errorNode = stepNode.appendChild(doc.createElement("error"));
final Node outputNode = stepNode.appendChild(doc.createElement("output"));
final Node exitNode = stepNode.appendChild(doc.createElement("exit"));
// Status exit code
int status = -1;
try {
// Environment parameters (name/value pairs)
String[] envp = null;
if (envParameters.size() > 0) {
// Retrieve current environment parameters and overrides
Map<String, String> envmap = new HashMap<String, String>();
envmap.putAll(System.getenv());
for (List<String> parameter : envParameters) envmap.put(parameter.get(0), parameter.get(1));
// Fill parameters array
int i = 0;
envp = new String[envmap.size()];
for (Map.Entry<String, String> entry : envmap.entrySet()) envp[i++] = entry.getKey() + "=" + entry.getValue();
}
// Execution directory
File dir = null;
if (!executionDirectory.equals(""))
dir = Engine.theApp.filePropertyManager.getFileFromProperty(executionDirectory, getProject().getName());
// Command line string
if (evaluated instanceof org.mozilla.javascript.Undefined)
throw new EngineException("Process command line argument is empty.");
String cmd = null;
String[] command = null;
if (evaluated instanceof org.mozilla.javascript.NativeArray) {
long ln = ((org.mozilla.javascript.NativeArray) evaluated).getLength();
command = new String[(int) ln];
for (int i = 0; i < ln; i++) {
command[i] = "" + ((org.mozilla.javascript.NativeArray) evaluated).get(i, null);
}
} else {
cmd = evaluated.toString();
}
// Check if encoding is supported
try {
if (!Charset.isSupported(commandCharset)) {
throw new EngineException("Wrong encoding for \"Process execute\" step, please enter a valid one.");
}
} catch (IllegalCharsetNameException e) {
throw new EngineException("Wrong encoding for \"Process execute\" step, please enter a valid one.");
}
// Launch the process :
// if envp is null, current environment parameters are used
// if dir is null, current execution directory is used
// final Process process = Runtime.getRuntime().exec(command, envp, dir);
final Process process;
if (command != null) {
Engine.logBeans.debug("Launching ProcessExec command : " + Arrays.toString(command) + " In directory: " + dir);
process = Runtime.getRuntime().exec(command, envp, dir);
} else {
Engine.logBeans.debug("Launching ProcessExec command : " + cmd + " In directory: " + dir);
process = Runtime.getRuntime().exec(cmd, envp, dir);
}
// Create and launch process stream reader threads
stderrThread = new ProcessStreamReaderThread(process.getErrorStream(), errorNode);
stdoutThread = new ProcessStreamReaderThread(process.getInputStream(), outputNode);
stderrThread.start();
stdoutThread.start();
if (isWaitForProcessEnd()) {
// Launch a thread to handle sequence abortion
final Sequence s = sequence;
Engine.execute(new Runnable() {
public void run() {
try {
while (s.isRunning()) {
Thread.sleep(500);
}
process.destroy();
} catch (Exception e) {
Engine.logBeans.warn("An error occured while executing process.", e);
}
}
});
// Wait for process end
process.waitFor();
stdoutThread.join();
stderrThread.join();
}
// Append process exit status to the 'exit' child node
try {
status = process.exitValue();
} catch (IllegalThreadStateException e) {
}
} catch (Throwable t) {
setErrorStatus(true);
if (t instanceof EngineException) {
Engine.logBeans.error("An error occured while executing process.", t);
errorNode.appendChild(errorNode.getOwnerDocument().createCDATASection("An error occured. See engine logs for more details..."));
} else
errorNode.appendChild(errorNode.getOwnerDocument().createCDATASection(t.getMessage()));
} finally {
exitNode.appendChild(doc.createTextNode("" + status));
try {
stderrThread.bContinue = false;
stdoutThread.bContinue = false;
} catch (Exception e) {
}
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class SchemaManager method makeXmlRestCompliant.
public synchronized Document makeXmlRestCompliant(Document document, boolean debug) {
try {
Element documentElement = document.getDocumentElement();
if (documentElement != null) {
String project = documentElement.getAttribute("project");
String sequence = documentElement.getAttribute("sequence");
String connector = documentElement.getAttribute("connector");
String transaction = documentElement.getAttribute("transaction");
XmlSchema schema = getSchemaForProject(project);
XmlSchemaCollection collection = SchemaMeta.getCollection(schema);
String targetNamespace = schema.getTargetNamespace();
String prefix = collection.getNamespaceContext().getPrefix(targetNamespace);
String requestableName = sequence != null && sequence.length() > 0 ? sequence : connector + "__" + transaction;
String tagname = prefix + ":" + requestableName + "Response";
QName qname = new QName(targetNamespace, requestableName + "Response");
Project p = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(project);
boolean isIncludeResponseElement = true;
if (!"".equals(sequence)) {
try {
Sequence seqObj = p.getSequenceByName(sequence);
isIncludeResponseElement = seqObj.isIncludeResponseElement();
} catch (Exception e) {
}
}
Document responseDoc = XMLUtils.getDefaultDocumentBuilder().newDocument();
Element requestableResponse = responseDoc.createElementNS(targetNamespace, tagname);
if (isIncludeResponseElement) {
Node renamed = responseDoc.renameNode(responseDoc.importNode(documentElement, true), "", "response");
requestableResponse.appendChild(renamed);
} else {
NodeList children = documentElement.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
requestableResponse.appendChild(responseDoc.importNode(children.item(i), true));
}
}
new XmlResponseWalker(true, true, debug) {
private boolean keepText(String text) {
try {
if (!text.isEmpty()) {
String strResult = "";
StringTokenizer strtok = new StringTokenizer(text, "\r\n\t");
while (strtok.hasMoreTokens()) {
strResult += strtok.nextToken();
}
return text.equals(strResult);
}
} catch (Exception e) {
}
return true;
}
@Override
public boolean makeCompliant(XmlSchemaObject xso, Node node) {
return makeCompliant(xso, node, false);
}
protected boolean makeCompliant(XmlSchemaObject xso, Node node, boolean forceArray) {
String tns = node.getNamespaceURI();
String nodeName = node.getNodeName();
String localName = nodeName.substring(nodeName.indexOf(":") + 1);
String xsoName = xso instanceof XmlSchemaElement ? ((XmlSchemaElement) xso).getName() : ((XmlSchemaAttribute) xso).getName();
if (xsoName.equals(localName)) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String elName = element.getNodeName();
long maxOccurs = ((XmlSchemaElement) xso).getMaxOccurs();
if (debug && maxOccurs > 1L) {
System.out.println(elName + ": maxOccurs=" + maxOccurs);
}
boolean isMixed = false;
XmlSchemaType xmlSchemaType = ((XmlSchemaElement) xso).getSchemaType();
if (xmlSchemaType != null) {
isMixed = xmlSchemaType.isMixed();
}
if (debug && isMixed) {
System.out.println(elName + ": is mixed !");
}
if (element.hasAttributes()) {
List<Node> removeList = new ArrayList<Node>();
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Node attr = attributes.item(i);
String prefix = attr.getPrefix();
String attrname = attr.getNodeName();
if ((prefix != null && (prefix.toLowerCase().equals("xsi") || prefix.toLowerCase().equals("xmlns") || prefix.toLowerCase().startsWith("soap-"))) || (attrname != null && (attrname.toLowerCase().startsWith("xsi") || attrname.toLowerCase().startsWith("xmlns") || attrname.toLowerCase().startsWith("soap-")))) {
removeList.add(attr);
}
}
for (Node attr : removeList) {
element.removeAttributeNode((Attr) attr);
}
try {
// replace boolean string "0" or "1" with "false" or "true"
for (XmlSchemaObject xsa : map.get(xso).get(1)) {
if (xsa instanceof XmlSchemaAttribute) {
XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute) xsa;
String xsa_name = xmlSchemaAttribute.getName();
QName xsa_qname = xmlSchemaAttribute.getSchemaTypeName();
if (xsa_qname != null) {
String xsa_type = xsa_qname.getLocalPart();
Node attr = element.getAttributeNode(xsa_name);
if (attr != null && !xsa_type.equals("string")) {
String attr_value = attr.getNodeValue();
if (xsa_type.equals("boolean")) {
if (attr_value.equals("0")) {
attr.setNodeValue("false");
}
if (attr_value.equals("1")) {
attr.setNodeValue("true");
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
boolean hasAttributes = element.hasAttributes();
int numOfAttr = map.get(xso).get(1).size();
if (debug && !hasAttributes && numOfAttr > 0) {
System.out.println(elName + ": has NO attributes and should have " + numOfAttr);
}
boolean hasChildNode = element.hasChildNodes();
int numOfChildren = map.get(xso).get(0).size();
if (hasChildNode) {
NodeList children = element.getChildNodes();
int len = children.getLength();
for (int i = 0; i < len; i++) {
Node n = children.item(i);
if (n.getNodeType() == Node.TEXT_NODE) {
String nv = n.getNodeValue();
if (keepText(nv)) {
// System.out.println("<text>"+nv+"</text>");
}
continue;
}
boolean needArray = false;
for (XmlSchemaObject e : map.get(xso).get(0)) {
if (e instanceof XmlSchemaElement) {
XmlSchemaElement xse = (XmlSchemaElement) e;
if ("StartC8oFakeOccurs".equals(xse.getName())) {
needArray = true;
}
if ("EndC8oFakeOccurs".equals(xse.getName())) {
needArray = false;
}
}
if (makeCompliant(e, n, needArray)) {
break;
}
}
}
}
if (debug && !hasChildNode && numOfChildren > 0) {
System.out.println(elName + ": has NO children and should have " + numOfChildren);
}
boolean selfClosedTag = !hasChildNode;
boolean needOfAttr = numOfAttr > 0;
boolean needOfChildren = numOfChildren > 0;
if (selfClosedTag) {
// <tag c8o_emptyObject="" c8o_needAttr=""/> => {"tag": {"attr":[]}}
if (needOfChildren) {
element.setAttribute("c8o_emptyObject", "");
} else {
element.setAttribute("c8o_nullObject", "");
}
if (needOfAttr) {
element.setAttribute("c8o_needAttr", "");
}
} else {
// <tag c8o_needAttr=""><user>user</user></tag> => {"tag": {"user":"user", "attr":[]}}
if (isMixed || (needOfAttr && !hasAttributes)) {
element.setAttribute("c8o_needAttr", "");
}
}
// case need array
if (maxOccurs > 1L || forceArray) {
// <user c8o_arrayOfSingle=""><name>name</name></user> => {"user":[{"name":"name"}]}
if (nodeName.equals(localName)) {
if (immediateElementsByTagName(element, localName) == 1) {
element.setAttribute("c8o_arrayOfSingle", "");
}
} else {
if (immediateElementsByTagNameNS(element, tns, localName) == 1) {
element.setAttribute("c8o_arrayOfSingle", "");
}
}
}
}
return true;
} else {
// System.out.println(""+nodeName); // not matching child
}
return false;
}
}.init(schema, qname, requestableResponse);
if (isIncludeResponseElement) {
responseDoc.appendChild(requestableResponse.getFirstChild());
} else {
responseDoc.appendChild(requestableResponse);
}
return responseDoc;
}
} catch (Throwable t) {
Engine.logContext.warn("An error occured while generating compliant XML for REST", t);
}
return document;
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class XmlSchemaBuilder method preBuildSchema.
private void preBuildSchema() throws EngineException {
try {
schema.setElementFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
schema.setAttributeFormDefault(new XmlSchemaForm(project.getSchemaElementForm().name()));
ConvertigoError.addXmlSchemaObjects(schema);
EngineStatistics.addXmlSchemaObjects(schema);
// static and read-only generation : references, transactions, sequences declaration
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject instanceof ISchemaGenerator) {
// generate itself and add to the caller list
if (databaseObject instanceof ISchemaImportGenerator) {
// Import case
if (databaseObject instanceof ProjectSchemaReference) {
// done further in buildSchema
} else {
XmlSchemaImport schemaImport = ((ISchemaImportGenerator) databaseObject).getXmlSchemaObject(collection, schema);
if (schemaImport != null) {
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
XmlSchemaUtils.add(schema, schemaImport);
}
}
} else if (databaseObject instanceof ISchemaIncludeGenerator) {
// Include case
if (databaseObject instanceof Transaction) {
XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
} else {
XmlSchemaInclude schemaInclude = ((ISchemaIncludeGenerator) databaseObject).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaInclude);
XmlSchemaUtils.add(schema, schemaInclude);
}
} else if (databaseObject instanceof Sequence) {
// Sequence case
XmlSchemaElement element = ((Sequence) databaseObject).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, element);
XmlSchemaUtils.add(schema, element);
}
} else {
// doesn't generate schema, just deep walk
super.walk(databaseObject);
}
}
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
// just walk references, transactions, sequences declaration
return Step.class.isAssignableFrom(dboClass) || Transaction.class.isAssignableFrom(dboClass) || Sequence.class.isAssignableFrom(dboClass) || Reference.class.isAssignableFrom(dboClass) || Connector.class.isAssignableFrom(dboClass);
}
protected void addSchemaIncludeObjects(DatabaseObject databaseObject, XmlSchema xmlSchema) {
if (xmlSchema != null) {
XmlSchemaObjectCollection c = xmlSchema.getItems();
Iterator<XmlSchemaObject> it = GenericUtils.cast(c.getIterator());
while (it.hasNext()) {
XmlSchemaObject xmlSchemaObject = it.next();
SchemaMeta.getReferencedDatabaseObjects(xmlSchemaObject).add(databaseObject);
if (xmlSchemaObject instanceof XmlSchemaImport) {
// ignore
} else if (xmlSchemaObject instanceof XmlSchemaInclude) {
XmlSchemaInclude schemaInclude = (XmlSchemaInclude) xmlSchemaObject;
addSchemaIncludeObjects(databaseObject, schemaInclude.getSchema());
} else if (xmlSchemaObject instanceof XmlSchemaAttribute) {
XmlSchemaAttribute attribute = (XmlSchemaAttribute) xmlSchemaObject;
if (schema.getAttributes().getItem(attribute.getQName()) == null) {
schema.getAttributes().add(attribute.getQName(), attribute);
schema.getItems().add(attribute);
}
} else if (xmlSchemaObject instanceof XmlSchemaAttributeGroup) {
XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) xmlSchemaObject;
if (schema.getAttributeGroups().getItem(attributeGroup.getName()) == null) {
schema.getAttributeGroups().add(attributeGroup.getName(), attributeGroup);
schema.getItems().add(attributeGroup);
}
} else if (xmlSchemaObject instanceof XmlSchemaGroup) {
XmlSchemaGroup group = (XmlSchemaGroup) xmlSchemaObject;
if (schema.getGroups().getItem(group.getName()) == null) {
schema.getGroups().add(group.getName(), group);
schema.getItems().add(group);
}
} else if (xmlSchemaObject instanceof XmlSchemaElement) {
XmlSchemaElement element = (XmlSchemaElement) xmlSchemaObject;
if (collection.getElementByQName(element.getQName()) == null && schema.getElementByName(element.getQName()) == null) {
schema.getElements().add(element.getQName(), element);
schema.getItems().add(element);
}
} else if (xmlSchemaObject instanceof XmlSchemaType) {
XmlSchemaType schemaType = (XmlSchemaType) xmlSchemaObject;
if (collection.getTypeByQName(schemaType.getQName()) == null && schema.getTypeByName(schemaType.getQName()) == null) {
schema.addType(schemaType);
schema.getItems().add(schemaType);
}
} else {
schema.getItems().add(xmlSchemaObject);
}
}
}
}
}.init(project);
} catch (Exception e) {
throw new EngineException("preBuildSchema failed", e);
}
}
Aggregations