use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ProjectTreeObject method getMissingTargetProjectList.
public List<String> getMissingTargetProjectList() {
List<String> missingList = new ArrayList<String>();
Project p = getObject();
for (Sequence s : p.getSequencesList()) {
checkForImports(missingList, s.getSteps());
}
return missingList;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class MobileApplicationComponentTreeObject method treeObjectPropertyChanged.
@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
super.treeObjectPropertyChanged(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
Set<Object> done = checkDone(treeObjectEvent);
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
ApplicationComponent ac = getObject();
// for Page or Menu or Route
if (ac.equals(dbo.getParent())) {
markApplicationAsDirty(done);
} else // for any component inside a route
if (ac.equals(dbo.getParent().getParent())) {
markApplicationAsDirty(done);
} else // for any UI component inside a menu or a stack
if (dbo instanceof UIComponent) {
UIComponent uic = (UIComponent) dbo;
UIDynamicMenu menu = uic.getMenu();
if (menu != null) {
if (ac.equals(menu.getParent())) {
if (propertyName.equals("FormControlName") || uic.isFormControlAttribute()) {
if (!newValue.equals(oldValue)) {
try {
String oldSmart = ((MobileSmartSourceType) oldValue).getSmartValue();
String newSmart = ((MobileSmartSourceType) newValue).getSmartValue();
if (uic.getUIForm() != null) {
String form = uic.getUIForm().getFormGroupName();
if (menu.updateSmartSource(form + "\\?\\.controls\\['" + oldSmart + "'\\]", form + "?.controls['" + newSmart + "']")) {
this.viewer.refresh();
}
}
} catch (Exception e) {
}
}
}
markApplicationAsDirty(done);
}
}
} else // for this application
if (this.equals(doto)) {
if (propertyName.equals("isPWA")) {
if (!newValue.equals(oldValue)) {
markPwaAsDirty();
}
} else if (propertyName.equals("componentScriptContent")) {
if (!newValue.equals(oldValue)) {
markComponentTsAsDirty();
markApplicationAsDirty(done);
}
} else if (propertyName.equals("useClickForTap")) {
for (TreeObject to : this.getChildren()) {
if (to instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
for (TreeObject cto : ofto.getChildren()) {
if (cto instanceof MobilePageComponentTreeObject) {
((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
}
}
}
}
}
markApplicationAsDirty(done);
} else if (propertyName.equals("tplProjectName")) {
// close app editor and reinitialize builder
Project project = ac.getProject();
closeAllEditors(false);
MobileBuilder.releaseBuilder(project);
MobileBuilder.initBuilder(project);
IProject iproject = ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName());
iproject.refreshLocal(IResource.DEPTH_INFINITE, null);
// force app sources regeneration
for (TreeObject to : this.getChildren()) {
if (to instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
for (TreeObject cto : ofto.getChildren()) {
if (cto instanceof MobilePageComponentTreeObject) {
((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
}
}
}
}
}
markApplicationAsDirty(done);
// delete node modules and alert user
final File nodeModules = new File(project.getDirPath(), "/_private/ionic/node_modules");
if (nodeModules.exists()) {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(ConvertigoPlugin.getMainShell());
dialog.open();
dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("deleting node modules", IProgressMonitor.UNKNOWN);
String alert = "template changed!";
if (com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules)) {
alert = "You have just changed the template.\nPackages have been deleted and will be reinstalled next time you run your application again.";
} else {
alert = "You have just changed the template: packages could not be deleted!\nDo not forget to reinstall the packages before running your application again, otherwise it may be corrupted!";
}
monitor.done();
ConvertigoPlugin.infoMessageBox(alert);
}
});
}
} else {
markApplicationAsDirty(done);
}
}
} catch (Exception e) {
}
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class XmlSchemaBuilder method midBuildSchema.
private void midBuildSchema(final int nb) throws EngineException {
// System.out.println("buildSchema for "+ getTargetNamespace());
boolean fullSchema = isFull;
try {
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) {
ProjectSchemaReference ref = (ProjectSchemaReference) databaseObject;
String targetProjectName = ref.getParser().getProjectName();
String tns = Project.getProjectTargetNamespace(targetProjectName);
if (collection.schemaForNamespace(tns) == null) {
if (SchemaMeta.getXmlSchemaObject(schema, databaseObject) == null) {
XmlSchemaImport schemaImport = new XmlSchemaImport();
schemaImport.setNamespace(tns);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
XmlSchemaUtils.add(schema, schemaImport);
} else {
XmlSchemaBuilder builder = builderExecutor.getBuilderByTargetNamespace(tns);
if (builder != null) {
XmlSchemaUtils.remove(schema, SchemaMeta.getXmlSchemaObject(schema, databaseObject));
XmlSchema xmlSchema = collection.read(builder.schema.getSchemaDocument(), null);
XmlSchemaImport schemaImport = new XmlSchemaImport();
schemaImport.setNamespace(tns);
schemaImport.setSchema(xmlSchema);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
XmlSchemaUtils.add(schema, schemaImport);
}
}
}
}
}
} else {
// doesn't generate schema, just deep walk
super.walk(databaseObject);
}
}
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
// just walk references
return Reference.class.isAssignableFrom(dboClass);
}
}.init(project);
// add missing references import
if (nb == 1) {
if (this.equals(builderExecutor.getMainBuilder())) {
List<String> refs = new ArrayList<String>();
SchemaManager.getProjectReferences(refs, projectName);
List<String> missing = new ArrayList<String>();
missing.addAll(refs);
missing.remove(projectName);
for (String pname : refs) {
XmlSchemaObjectCollection col = schema.getIncludes();
for (int i = 0; i < col.getCount(); i++) {
XmlSchemaObject ob = col.getItem(i);
if (ob instanceof XmlSchemaImport) {
XmlSchemaImport xmlSchemaImport = (XmlSchemaImport) ob;
String tns = Project.getProjectTargetNamespace(pname);
if (xmlSchemaImport.getNamespace().equals(tns)) {
missing.remove(pname);
}
}
}
}
for (String pname : missing) {
String tns = Project.getProjectTargetNamespace(pname);
XmlSchemaBuilder builder = builderExecutor.getBuilderByTargetNamespace(tns);
if (builder != null) {
XmlSchema xmlSchema = collection.read(builder.schema.getSchemaDocument(), null);
XmlSchemaImport schemaImport = new XmlSchemaImport();
schemaImport.setNamespace(tns);
schemaImport.setSchema(xmlSchema);
XmlSchemaUtils.add(schema, schemaImport);
}
}
}
}
new WalkHelper() {
List<XmlSchemaParticle> particleChildren;
List<XmlSchemaAttribute> attributeChildren;
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
// Transaction case
if (databaseObject instanceof Transaction) {
Transaction transaction = (Transaction) databaseObject;
String ns = schema.getTargetNamespace();
List<QName> partElementQNames = new ArrayList<QName>();
partElementQNames.add(new QName(ns, transaction.getXsdRequestElementName()));
partElementQNames.add(new QName(ns, transaction.getXsdResponseElementName()));
LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, true);
for (QName qname : partElementQNames) {
dw.walkByElementRef(schema, qname);
}
for (QName qname : map.keySet()) {
String nsURI = qname.getNamespaceURI();
if (nsURI.equals(ns))
continue;
if (nsURI.equals(Constants.URI_2001_SCHEMA_XSD))
continue;
SchemaManager.addXmlSchemaImport(collection, schema, nsURI);
}
map.clear();
// add the 'statistics' element
if (transaction.getAddStatistics()) {
XmlSchemaComplexType xmlSchemaComplexType = (XmlSchemaComplexType) schema.getTypeByName(transaction.getXsdResponseTypeName());
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaComplexType.getParticle();
XmlSchemaType statisticsType = schema.getTypeByName("ConvertigoStatsType");
XmlSchemaElement eStatistics = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
eStatistics.setName("statistics");
eStatistics.setMinOccurs(0);
eStatistics.setMaxOccurs(1);
eStatistics.setSchemaTypeName(statisticsType.getQName());
xmlSchemaGroupBase.getItems().add(eStatistics);
SchemaMeta.getReferencedDatabaseObjects(statisticsType).add(transaction);
}
} else // Sequence case
if (databaseObject instanceof Sequence) {
Sequence sequence = (Sequence) databaseObject;
// System.out.println("--sequence:"+ sequence.toString());
particleChildren = new LinkedList<XmlSchemaParticle>();
attributeChildren = new LinkedList<XmlSchemaAttribute>();
super.walk(databaseObject);
// check for an 'error' element if needed
boolean errorFound = false;
XmlSchemaType errorType = schema.getTypeByName("ConvertigoError");
if (errorType != null) {
Set<DatabaseObject> dbos = SchemaMeta.getReferencedDatabaseObjects(errorType);
for (DatabaseObject dbo : dbos) {
if (dbo instanceof Step) {
Step errorStep = (Step) dbo;
if (errorStep.getSequence().equals(sequence) && (errorStep instanceof XMLCopyStep || errorStep.getStepNodeName().equals("error"))) {
errorFound = true;
break;
}
}
}
}
// set particle : choice or sequence
XmlSchemaComplexType cType = (XmlSchemaComplexType) schema.getTypeByName(sequence.getComplexTypeAffectation().getLocalPart());
XmlSchemaSequence xmlSeq = new XmlSchemaSequence();
XmlSchemaChoice xmlChoice = new XmlSchemaChoice();
cType.setParticle(errorFound ? xmlSeq : xmlChoice);
if (!errorFound) {
XmlSchemaElement eError = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
eError.setName("error");
eError.setMinOccurs(0);
eError.setMaxOccurs(1);
eError.setSchemaTypeName(errorType.getQName());
SchemaMeta.getReferencedDatabaseObjects(errorType).add(sequence);
xmlChoice.getItems().add(xmlSeq);
xmlChoice.getItems().add(eError);
}
// add child particles
if (!particleChildren.isEmpty()) {
for (XmlSchemaParticle child : particleChildren) {
xmlSeq.getItems().add(child);
}
}
particleChildren.clear();
// add child attributes
for (XmlSchemaAttribute attribute : attributeChildren) {
cType.getAttributes().add(attribute);
}
attributeChildren.clear();
// add the 'statistics' element
if (sequence.getAddStatistics()) {
XmlSchemaType statisticsType = schema.getTypeByName("ConvertigoStatsType");
XmlSchemaElement eStatistics = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
eStatistics.setName("statistics");
eStatistics.setMinOccurs(0);
eStatistics.setMaxOccurs(1);
eStatistics.setSchemaTypeName(statisticsType.getQName());
xmlSeq.getItems().add(eStatistics);
SchemaMeta.getReferencedDatabaseObjects(statisticsType).add(sequence);
}
// --------------------------- For Further Use -------------------------------------------------//
// Modify schema to avoid 'cosamb' (same tagname&type in different groupBase at same level)
// TODO : IfThenElse steps must be modified for xsd:sequence instead of xsd:choice
// TODO : Then/Else steps must be modified to add minOccurs=0 on xsd:sequence
// TODO : review/improve cosnoamb(XmlSchema, XmlSchemaGroupBase, XmlSchemaGroupBase) method
// ---------------------------------------------------------------------------------------------//
} else // Step case
if (databaseObject instanceof Step) {
Step step = (Step) databaseObject;
if (!step.isEnabled()) {
// stop walking for disabled steps
return;
}
List<XmlSchemaParticle> parentParticleChildren = particleChildren;
List<XmlSchemaAttribute> parentAttributeChildren = attributeChildren;
// System.out.println("step:"+ step.toString());
if (step instanceof TransactionStep) {
// System.out.println("SCHEMA TARGET STEP "+ step.toString() + "(" + step.hashCode() + ")");
}
if (step.isGenerateSchema() || (fullSchema && step.isXmlOrOutput())) {
// System.out.println("-> generate schema...");
List<XmlSchemaParticle> myParticleChildren = null;
List<XmlSchemaAttribute> myAttributeChildren = null;
// is base affected ?
@SuppressWarnings("unused") XmlSchemaType base = null;
QName baseQName = step instanceof ISimpleTypeAffectation ? ((ISimpleTypeAffectation) step).getSimpleTypeAffectation() : null;
if (baseQName != null && baseQName.getLocalPart().length() > 0) {
// base = baseQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(baseQName.getLocalPart()) : collection.getTypeByQName(baseQName);
base = XmlSchemaBuilder.this.resolveTypeByQName(baseQName);
}
// is type affected ?
XmlSchemaType type = null;
QName typeQName = step instanceof IComplexTypeAffectation ? ((IComplexTypeAffectation) step).getComplexTypeAffectation() : null;
if (typeQName != null && typeQName.getLocalPart().length() > 0) {
// type = typeQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(typeQName.getLocalPart()) : collection.getTypeByQName(typeQName);
type = XmlSchemaBuilder.this.resolveTypeByQName(typeQName);
}
// is element affected ?
XmlSchemaElement ref = null;
QName refQName = step instanceof IElementRefAffectation ? ((IElementRefAffectation) step).getElementRefAffectation() : null;
if (refQName != null && refQName.getLocalPart().length() > 0) {
// ref = refQName.getNamespaceURI().length() == 0 ? schema.getElementByName(refQName.getLocalPart()) : collection.getElementByQName(refQName);
ref = XmlSchemaBuilder.this.resolveElementByQName(refQName);
typeQName = new QName(schema.getTargetNamespace(), refQName.getLocalPart() + "Type");
if (ref == null && refQName.getNamespaceURI().equals(schema.getTargetNamespace())) {
ref = XmlSchemaUtils.makeDynamic(step, new XmlSchemaElement());
ref.setQName(refQName);
ref.setName(refQName.getLocalPart());
ref.setSchemaTypeName(baseQName);
XmlSchemaUtils.add(schema, ref);
} else if (ref != null) {
ref.setSchemaTypeName(baseQName);
// type = typeQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(typeQName.getLocalPart()) : collection.getTypeByQName(typeQName);
type = XmlSchemaBuilder.this.resolveTypeByQName(typeQName);
}
}
if (type == null || !SchemaMeta.isReadOnly(type)) {
// prepare to receive children
if (step instanceof ISchemaParticleGenerator) {
myParticleChildren = particleChildren = new LinkedList<XmlSchemaParticle>();
if (fullSchema || ((ISchemaParticleGenerator) step).isGenerateElement()) {
myAttributeChildren = attributeChildren = new LinkedList<XmlSchemaAttribute>();
}
}
// deep walk
super.walk(step);
// generate itself and add to the caller list
if (step instanceof ISchemaAttributeGenerator) {
// Attribute case
XmlSchemaAttribute attribute = ((ISchemaAttributeGenerator) step).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, attribute);
parentAttributeChildren.add(attribute);
} else if (step instanceof ISchemaParticleGenerator) {
if (step instanceof RequestableStep) {
RequestableStep requestableStep = (RequestableStep) step;
String targetProjectName = requestableStep.getProjectName();
Project targetProject = requestableStep.getSequence().getLoadedProject(targetProjectName);
if (targetProject == null) {
Engine.logEngine.warn("(XmlSchemaBuilder) Not complete schema because: Missing required or not loaded project \"" + targetProjectName + "\"");
} else if (step instanceof SequenceStep) {
// SequenceStep case : walk target sequence first
try {
Sequence targetSequence = ((SequenceStep) step).getTargetSequence();
targetProjectName = targetSequence.getProject().getName();
String targetSequenceName = targetSequence.getName();
String stepSequenceName = step.getSequence().getName();
if (projectName.equals(targetProjectName)) {
boolean isAfter = targetSequenceName.compareToIgnoreCase(stepSequenceName) > 0;
if (isAfter) {
walk(targetSequence);
}
}
} catch (EngineException e) {
if (!e.getMessage().startsWith("There is no ")) {
throw e;
} else {
Engine.logEngine.warn("(XmlSchemaBuilder) Not complete schema because: " + e.getMessage());
}
}
}
}
// Particle case
XmlSchemaParticle particle = ((ISchemaParticleGenerator) step).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, particle);
parentParticleChildren.add(particle);
// retrieve the xsd:element to add children
XmlSchemaElement element = SchemaMeta.getContainerXmlSchemaElement(ref == null ? particle : ref);
// retrieve the group to add children if any
XmlSchemaGroupBase group = SchemaMeta.getContainerXmlSchemaGroupBase(element != null ? element : particle);
// new complexType to enhance the element
XmlSchemaComplexType cType = element != null ? (XmlSchemaComplexType) element.getSchemaType() : null;
// do something only on case of child
if (!myParticleChildren.isEmpty() || (myAttributeChildren != null && !myAttributeChildren.isEmpty())) {
if (cType == null) {
cType = XmlSchemaUtils.makeDynamic(step, new XmlSchemaComplexType(schema));
}
// prepare element children in the group
if (!myParticleChildren.isEmpty()) {
if (group == null) {
group = XmlSchemaUtils.makeDynamic(step, new XmlSchemaSequence());
}
for (XmlSchemaParticle child : myParticleChildren) {
group.getItems().add(child);
}
}
if (element != null) {
XmlSchemaSimpleContentExtension sContentExt = SchemaManager.makeSimpleContentExtension(step, element, cType);
if (sContentExt != null) {
// add attributes
for (XmlSchemaAttribute attribute : myAttributeChildren) {
sContentExt.getAttributes().add(attribute);
}
} else {
// add attributes
for (XmlSchemaAttribute attribute : myAttributeChildren) {
cType.getAttributes().add(attribute);
}
// add elements
if (SchemaMeta.isDynamic(cType) && group != null) {
cType.setParticle(group);
}
}
}
}
if (element != null) {
// check if the type is named
if (typeQName != null && typeQName.getLocalPart().length() > 0) {
if (cType == null) {
cType = XmlSchemaUtils.makeDynamic(step, new XmlSchemaComplexType(schema));
SchemaManager.makeSimpleContentExtension(step, element, cType);
}
if (type == null) {
// the type doesn't exist, declare it
cType.setName(typeQName.getLocalPart());
schema.addType(cType);
schema.getItems().add(cType);
} else {
// the type already exists, merge it
XmlSchemaComplexType currentCType = (XmlSchemaComplexType) type;
SchemaManager.merge(schema, currentCType, cType);
cType = currentCType;
}
// reference the type in the current element
element.setSchemaTypeName(cType.getQName());
element.setSchemaType(null);
} else if (cType != null && SchemaMeta.isDynamic(cType) && element.getSchemaTypeName() == null) {
// the element contains an anonymous type
element.setSchemaType(cType);
}
}
} else {
XmlSchemaObject object;
XmlSchema xmlSchema = null;
if (step instanceof XMLCopyStep && !fullSchema) {
final XmlSchemaBuilder fullBuilder = builderExecutor.getBuilder(projectName, true);
if (fullBuilder != null) {
xmlSchema = fullBuilder.getXmlSchema();
XmlSchemaCollection xmlCollection = SchemaMeta.getCollection(xmlSchema);
object = step.getXmlSchemaObject(xmlCollection, xmlSchema);
} else {
xmlSchema = schema;
object = step.getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, object);
}
} else {
xmlSchema = schema;
object = step.getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, object);
}
if (step instanceof XMLCopyStep) {
if (object instanceof XmlSchemaElement) {
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) object;
QName qname = xmlSchemaElement.getSchemaTypeName();
if (qname != null) {
XmlSchemaType xmlSchemaType = xmlSchema.getTypeByName(qname);
if (xmlSchemaType != null) {
SchemaMeta.getReferencedDatabaseObjects(xmlSchemaType).add(step);
}
}
}
}
if (object instanceof XmlSchemaParticle) {
particleChildren.add((XmlSchemaParticle) object);
} else if (object instanceof XmlSchemaAttribute) {
attributeChildren.add((XmlSchemaAttribute) object);
}
}
} else {
// re-use read only type
XmlSchemaElement elt = XmlSchemaUtils.makeDynamic(step, new XmlSchemaElement());
SchemaMeta.getReferencedDatabaseObjects(type).add(step);
SchemaMeta.setXmlSchemaObject(schema, step, elt);
elt.setName(step.getStepNodeName());
elt.setSchemaTypeName(typeQName);
particleChildren.add(elt);
}
} else // Other case
{
// doesn't generate schema, just deep walk
// System.out.println("-> do not generate schema (deep walk)");
super.walk(step);
}
// restore lists for siblings
particleChildren = parentParticleChildren;
attributeChildren = parentAttributeChildren;
} else {
// just deep walk
super.walk(databaseObject);
}
}
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
// just walk ISchemaGenerator DBO
return Step.class.isAssignableFrom(dboClass) || Sequence.class.isAssignableFrom(dboClass) || Transaction.class.isAssignableFrom(dboClass) || Connector.class.isAssignableFrom(dboClass);
}
}.init(project);
} catch (Exception e) {
throw new EngineException("midBuildSchema failed", e);
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class Deploy method doUpload.
@Override
protected void doUpload(HttpServletRequest request, Document document, FileItem item) throws Exception {
if (!item.getName().endsWith(".car")) {
ServiceUtils.addMessage(document, document.getDocumentElement(), "The deployment of the project " + item.getName() + " has failed. The archive file is not valid (.car required).", "error", false);
}
super.doUpload(request, document, item);
// Depending on client browsers, according to the documentation,
// item.getName() can either return a full path file name, or
// simply a file name.
String projectArchive = item.getName();
// Bugfix #1425
int i = projectArchive.lastIndexOf('/');
if (i == -1) {
i = projectArchive.lastIndexOf('\\');
if (i != -1) {
projectArchive = projectArchive.substring(i + 1);
}
} else {
projectArchive = projectArchive.substring(i + 1);
}
Project project = Engine.theApp.databaseObjectsManager.deployProject(getRepository() + projectArchive, true, bAssembleXsl);
String projectName = project.getName();
Project.executeAutoStartSequences(projectName);
if (Boolean.parseBoolean(EnginePropertiesManager.getProperty(PropertyName.NOTIFICATIONS_NOTIFY_PROJECT_DEPLOYMENT))) {
final String fUser = (String) request.getSession().getAttribute(SessionKey.ADMIN_USER.toString());
final String fProjectName = projectName;
Engine.execute(new Runnable() {
public void run() {
try {
Properties props = new Properties();
props.put("mail.smtp.host", EnginePropertiesManager.getProperty(PropertyName.NOTIFICATIONS_SMTP_HOST));
props.put("mail.smtp.socketFactory.port", EnginePropertiesManager.getProperty(PropertyName.NOTIFICATIONS_SMTP_PORT));
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
// Initializing
Session mailSession = Session.getInstance(props, new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(EnginePropertiesManager.getProperty(PropertyName.NOTIFICATIONS_SMTP_USER), EnginePropertiesManager.getProperty(PropertyName.NOTIFICATIONS_SMTP_PASSWORD));
}
});
MimeMessage message = new MimeMessage(mailSession);
message.addRecipient(Message.RecipientType.TO, new InternetAddress(EnginePropertiesManager.getProperty(PropertyName.NOTIFICATIONS_TARGET_EMAIL)));
message.setSubject("[trial] deployment of " + fProjectName + " by " + fUser);
message.setText(message.getSubject() + "\n" + "http://trial.convertigo.net/cems/projects/" + fProjectName + "\n" + "https://trial.convertigo.net/cems/projects/" + fProjectName);
Transport.send(message);
} catch (MessagingException e1) {
}
}
});
}
String message = "The project '" + projectName + "' has been successfully deployed.";
Engine.logAdmin.info(message);
ServiceUtils.addMessage(document, document.getDocumentElement(), message, "message", false);
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class Set method getServiceResult.
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
Element root = document.getDocumentElement();
Document post = null;
Element response = document.createElement("response");
try {
Map<String, DatabaseObject> map = com.twinsoft.convertigo.engine.admin.services.projects.Get.getDatabaseObjectByQName(request);
xpath = new TwsCachedXPathAPI();
post = XMLUtils.parseDOM(request.getInputStream());
postElt = document.importNode(post.getFirstChild(), true);
String objectQName = xpath.selectSingleNode(postElt, "./@qname").getNodeValue();
DatabaseObject object = map.get(objectQName);
if (object instanceof Project) {
Project project = (Project) object;
String objectNewName = getPropertyValue(object, "name").toString();
Engine.theApp.databaseObjectsManager.renameProject(project, objectNewName);
map.remove(objectQName);
map.put(project.getQName(), project);
}
BeanInfo bi = CachedIntrospector.getBeanInfo(object.getClass());
PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String propertyName = propertyDescriptor.getName();
Method setter = propertyDescriptor.getWriteMethod();
Class<?> propertyTypeClass = propertyDescriptor.getReadMethod().getReturnType();
if (propertyTypeClass.isPrimitive()) {
propertyTypeClass = ClassUtils.primitiveToWrapper(propertyTypeClass);
}
try {
String propertyValue = getPropertyValue(object, propertyName).toString();
Object oPropertyValue = createObject(propertyTypeClass, propertyValue);
if (object.isCipheredProperty(propertyName)) {
Method getter = propertyDescriptor.getReadMethod();
String initialValue = (String) getter.invoke(object, (Object[]) null);
if (oPropertyValue.equals(initialValue) || DatabaseObject.encryptPropertyValue(initialValue).equals(oPropertyValue)) {
oPropertyValue = initialValue;
} else {
object.hasChanged = true;
}
}
if (oPropertyValue != null) {
Object[] args = { oPropertyValue };
setter.invoke(object, args);
}
} catch (IllegalArgumentException e) {
}
}
Engine.theApp.databaseObjectsManager.exportProject(object.getProject());
response.setAttribute("state", "success");
response.setAttribute("message", "Project have been successfully updated!");
} catch (Exception e) {
Engine.logAdmin.error("Error during saving the properties!\n" + e.getMessage());
response.setAttribute("state", "error");
response.setAttribute("message", "Error during saving the properties!");
Element stackTrace = document.createElement("stackTrace");
stackTrace.setTextContent(e.getMessage());
root.appendChild(stackTrace);
} finally {
xpath.resetCache();
}
root.appendChild(response);
}
Aggregations