Search in sources :

Example 81 with Project

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;
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 82 with Project

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;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Matcher(java.util.regex.Matcher) DesignDocument(com.twinsoft.convertigo.beans.couchdb.DesignDocument) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FullSyncConnector(com.twinsoft.convertigo.beans.connectors.FullSyncConnector) Sequence(com.twinsoft.convertigo.beans.core.Sequence) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) JSONException(org.codehaus.jettison.json.JSONException)

Example 83 with Project

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);
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ArrayList(java.util.ArrayList) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) InvalidSourceException(com.twinsoft.convertigo.engine.InvalidSourceException) JSONException(org.codehaus.jettison.json.JSONException)

Example 84 with Project

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;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 85 with 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);
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication)

Aggregations

Project (com.twinsoft.convertigo.beans.core.Project)148 EngineException (com.twinsoft.convertigo.engine.EngineException)56 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)47 IOException (java.io.IOException)39 File (java.io.File)37 Sequence (com.twinsoft.convertigo.beans.core.Sequence)35 Connector (com.twinsoft.convertigo.beans.core.Connector)33 ArrayList (java.util.ArrayList)29 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)26 JSONException (org.codehaus.jettison.json.JSONException)26 Transaction (com.twinsoft.convertigo.beans.core.Transaction)24 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)22 SAXException (org.xml.sax.SAXException)21 CoreException (org.eclipse.core.runtime.CoreException)20 Step (com.twinsoft.convertigo.beans.core.Step)19 Element (org.w3c.dom.Element)19 Shell (org.eclipse.swt.widgets.Shell)18 JSONObject (org.codehaus.jettison.json.JSONObject)17 IProject (org.eclipse.core.resources.IProject)17 Cursor (org.eclipse.swt.graphics.Cursor)17