use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class UIDynamicInvoke method getTargetSharedAction.
public UIActionStack getTargetSharedAction() {
try {
String qname = getSharedActionQName();
if (qname != null && qname.indexOf('.') != -1) {
String p_name = qname.substring(0, qname.indexOf('.'));
Project project = this.getProject();
Project p = Engine.theApp.referencedProjectManager.importProjectFrom(project, p_name);
if (p != null) {
ApplicationComponent app = (ApplicationComponent) p.getMobileApplication().getApplicationComponent();
for (UIActionStack uias : app.getSharedActionList()) {
if (uias.getQName().equals(qname)) {
return uias;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class UIUseShared method getTargetSharedComponent.
public UISharedComponent getTargetSharedComponent() {
String qname = getSharedComponentQName();
if (target == null || !target.getQName().equals(qname)) {
target = null;
if (qname.indexOf('.') != -1) {
String p_name = qname.substring(0, qname.indexOf('.'));
Project project = this.getProject();
if (project != null) {
Project p = null;
try {
p = Engine.theApp.referencedProjectManager.importProjectFrom(project, p_name);
if (p == null) {
throw new Exception();
}
} catch (Exception e) {
Engine.logBeans.warn("(UIUseShared) For \"" + this.toString() + "\", targeted project \"" + p_name + "\" is missing !");
}
if (p != null) {
if (p.getMobileApplication() != null) {
try {
ApplicationComponent app = (ApplicationComponent) p.getMobileApplication().getApplicationComponent();
if (app != null) {
for (UISharedComponent uisc : app.getSharedComponentList()) {
if (uisc.getQName().equals(qname)) {
target = uisc;
break;
}
}
}
} catch (ClassCastException e) {
Engine.logBeans.warn("(UIUseShared) For \"" + this.toString() + "\", targeted component \"" + qname + "\" is not compatible !");
}
} else {
Engine.logBeans.warn("(UIUseShared) For \"" + this.toString() + "\", targeted project \"" + p_name + "\" does not contain any mobile application !");
}
if (target == null) {
Engine.logBeans.warn("(UIUseShared) For \"" + this.toString() + "\", targeted component \"" + qname + "\" is missing !");
}
}
}
} else {
Engine.logBeans.warn("(UIUseShared) Component \"" + this.toString() + "\" has no target shared component defined !");
}
}
return target;
}
use of com.twinsoft.convertigo.beans.core.Project 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.Project in project convertigo by convertigo.
the class NgxBuilder method updateConsumers.
// for created or modified files
private void updateConsumers(UISharedComponent uisc, Project to) {
String compName = uisc.getName();
String compQName = uisc.getQName();
for (String useQName : ComponentRefManager.get(Mode.use).getAllConsumers(compQName)) {
if (projectName(useQName).equals(project.getName()))
continue;
if (to != null && !to.getName().equals(projectName(useQName)))
continue;
try {
File dest = new File(Engine.projectDir(projectName(useQName)), "_private/ionic/src/app/components/" + compName.toLowerCase());
File src = new File(project.getDirPath(), "_private/ionic/src/app/components/" + compName.toLowerCase());
if (src.exists() && shouldUpdate(src, dest)) {
Engine.logEngine.debug("(MobileBuilder) Copying " + src + " to " + dest);
FileUtils.copyDirectory(src, dest, true);
Project dest_project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName(useQName), false);
if (dest_project != null && dest_project.isMobileBuilderInitialized()) {
dest_project.getMobileBuilder().updateEnvFile();
}
}
} catch (Exception e) {
Engine.logEngine.warn("Unable to update consumers for " + projectName(useQName) + ": " + e.getMessage());
}
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class UIUseShared method getTargetSharedComponent.
public UISharedComponent getTargetSharedComponent() {
String qname = getSharedComponentQName();
if (target == null || !target.getQName().equals(qname)) {
target = null;
if (qname.indexOf('.') != -1) {
String p_name = qname.substring(0, qname.indexOf('.'));
Project project = this.getProject();
if (project != null) {
Project p = null;
try {
p = Engine.theApp.referencedProjectManager.importProjectFrom(project, p_name);
if (p == null) {
throw new Exception();
}
} catch (Exception e) {
Engine.logBeans.warn("(UIUseShared) For \"" + this.toString() + "\", targeted project \"" + p_name + "\" is missing !");
}
if (p != null) {
if (p.getMobileApplication() != null) {
ApplicationComponent app = (ApplicationComponent) p.getMobileApplication().getApplicationComponent();
if (app != null) {
for (UISharedComponent uisc : app.getSharedComponentList()) {
if (uisc.getQName().equals(qname)) {
target = uisc;
}
}
}
if (target == null) {
Engine.logBeans.warn("(UIUseShared) For \"" + this.toString() + "\", targeted component \"" + qname + "\" is missing !");
}
} else {
Engine.logBeans.warn("(UIUseShared) For \"" + this.toString() + "\", targeted project \"" + p_name + "\" does not contain any mobile application !");
}
}
}
} else {
Engine.logBeans.warn("(UIUseShared) Component \"" + this.toString() + "\" has no target shared component defined !");
}
}
return target;
}
Aggregations