use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ProjectManager method setCurrentProject.
public void setCurrentProject(ProjectTreeObject projectTreeObject) {
DatabaseObject databaseObject = (DatabaseObject) projectTreeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof Project)) {
if (currentProject != null)
previousProjectName = currentProjectName;
currentProject = (Project) databaseObject;
currentProjectName = currentProject.getName();
currentProjectTreeObject = projectTreeObject;
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class MobileSmartSource method getDatabaseObject.
public DatabaseObject getDatabaseObject(String rootDboName) {
List<String> sourceData = getSources();
String sourceInput = sourceData.size() > 0 ? sourceData.get(0) : null;
if (sourceInput != null) {
if (Filter.Action.equals(getFilter())) {
Matcher m = actionPattern.matcher(sourceInput);
if (m.find()) {
String stack = m.group(1);
try {
String p = stack.replaceFirst("stack\\[", "").replaceFirst("\\]", "");
// ignore quotes
p = p.substring(1, p.length() - 1);
long priority = Long.valueOf(p, 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Shared.equals(getFilter())) {
Matcher m = sharedPattern.matcher(sourceInput);
if (m.find()) {
String shared = m.group(1);
try {
long priority = Long.valueOf(shared.replaceFirst("comp", ""), 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Iteration.equals(getFilter())) {
Matcher m = directivePattern.matcher(sourceInput);
if (m.find()) {
String item = m.group(1);
try {
long priority = Long.valueOf(item.replaceFirst("item", ""), 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Form.equals(getFilter())) {
Matcher m = formPattern.matcher(sourceInput);
if (m.find()) {
String form = m.group(1);
try {
long priority = Long.valueOf(form.replaceFirst("form", ""), 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Global.equals(getFilter())) {
Matcher m = globalPattern.matcher(sourceInput);
if (m.find()) {
try {
String projectName = getProjectName();
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
DatabaseObject dbo = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
return dbo;
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Database.equals(getFilter())) {
Matcher m = cafPattern.matcher(sourceInput);
if (m.find()) {
try {
String name = m.group(1);
name = name.replaceFirst("fs://", "");
name = name.replaceFirst("\\.view", "");
name = name.replaceFirst("\\.get", "");
int i = name.indexOf('#');
if (i != -1) {
name = name.substring(0, i);
}
int index = name.indexOf('.');
String projectName = index != -1 ? name.substring(0, index) : getProjectName();
String dbName = index != -1 ? name.substring(index + 1) : name;
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
FullSyncConnector connector = (FullSyncConnector) project.getConnectorByName(dbName);
String documentName = getParameters().get("ddoc");
DesignDocument ddoc = (DesignDocument) connector.getDocumentByName(documentName);
return ddoc;
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Sequence.equals(getFilter())) {
Matcher m = cafPattern.matcher(sourceInput);
if (m.find()) {
try {
String name = m.group(1);
int i = name.indexOf('#');
if (i != -1) {
name = name.substring(0, i);
}
int index = name.indexOf('.');
String projectName = index != -1 ? name.substring(0, index) : getProjectName();
projectName = projectName.isEmpty() ? getProjectName() : projectName;
String sequenceName = index != -1 ? name.substring(index + 1) : name;
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
Sequence sequence = project.getSequenceByName(sequenceName);
return sequence;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return null;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class MobileSmartSource method findDatabaseObject.
private DatabaseObject findDatabaseObject(final String dboName, final long priority) throws Exception {
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(getProjectName());
DatabaseObject root = null;
if (dboName != null) {
ApplicationComponent app = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
try {
root = app.getPageComponentByName(dboName);
} catch (Exception e1) {
try {
root = app.getMenuComponentByName(dboName);
} catch (Exception e2) {
try {
root = app;
} catch (Exception e3) {
;
}
}
}
}
if (root == null) {
root = project;
}
final List<DatabaseObject> list = new ArrayList<DatabaseObject>();
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject.priority == priority) {
list.add(databaseObject);
}
if (list.isEmpty()) {
super.walk(databaseObject);
}
}
}.init(root);
return list.isEmpty() ? null : list.get(0);
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class CLI method loadProject.
public Project loadProject(File projectDir, String version, String mobileApplicationEndpoint, String gitContainer) throws EngineException {
File projectFile = new File(projectDir, "c8oProject.yaml");
if (!projectFile.exists()) {
throw new EngineException("No Convertigo project here: " + projectDir);
}
checkInit();
Project project;
Engine.PROJECTS_PATH = projectFile.getParentFile().getParent();
File testFile;
boolean ok = false;
if (gitContainer != null) {
testFile = new File(gitContainer, "convertigoWriteTest");
if (ok = testFile.mkdirs()) {
ok = testFile.delete();
if (ok) {
EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
}
}
if (!ok) {
Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
}
}
if (!ok) {
testFile = new File(EnginePropertiesManager.getProperty(PropertyName.GIT_CONTAINER), "convertigoWriteTest");
if (ok = testFile.mkdirs()) {
ok = testFile.delete();
if (ok) {
Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
}
}
if (!ok) {
Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
}
}
if (!ok) {
testFile = new File(Engine.PROJECTS_PATH, "convertigoWriteTest");
if (ok = testFile.mkdirs()) {
ok = testFile.delete();
}
if (ok) {
EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
}
if (!ok) {
Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
}
}
if (!ok) {
File tmpFile;
try {
tmpFile = File.createTempFile("convertigoWriteTest", "Tmp");
tmpFile.delete();
testFile = new File(tmpFile, "convertigoWriteTest");
if (ok = testFile.mkdirs()) {
ok = testFile.delete();
}
if (ok) {
EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
} else {
Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
}
} catch (IOException e) {
}
}
if (!ok) {
File _private = new File(projectDir, "_private/gitContainer");
testFile = new File(_private, "convertigoWriteTest");
if (ok = testFile.mkdirs()) {
ok = testFile.delete();
}
if (ok) {
EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
} else {
Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
}
}
try {
project = Engine.theApp.databaseObjectsManager.importProject(projectFile, false);
} catch (VersionException e) {
throw e;
} catch (Exception e) {
Engine.logConvertigo.warn("Failed to import the project from '" + projectFile + "' (" + e.getMessage() + ") trying again...");
project = Engine.theApp.databaseObjectsManager.importProject(projectFile, false);
}
if (version != null) {
project.setVersion(version);
}
if (mobileApplicationEndpoint != null) {
MobileApplication ma = project.getMobileApplication();
if (ma != null) {
ma.setEndpoint(mobileApplicationEndpoint);
}
}
return project;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class MobileResourceHelper method getMobilePlatform.
private static MobilePlatform getMobilePlatform(String projectName, String platform) throws ServiceException, EngineException {
if (!Engine.theApp.databaseObjectsManager.existsProject(projectName)) {
throw new ServiceException("Unable to get resources of the application '" + projectName + "'; reason: the project does not exist");
}
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
MobileApplication mobileApplication = project.getMobileApplication();
if (mobileApplication == null) {
throw new ServiceException("The application " + project.getName() + " doesn't contain a mobileApplication object.");
}
return mobileApplication.getMobilePlatformByName(platform);
}
Aggregations