Package org.eclipse.orion.server.core.metastore

Examples of org.eclipse.orion.server.core.metastore.ProjectInfo


    //make sure required fields are set
    if (name == null)
      name = request.getHeader(ProtocolConstants.HEADER_SLUG);
    if (!validateProjectName(workspace, name, request, response))
      return null;
    ProjectInfo project = new ProjectInfo();
    if (id != null)
      project.setUniqueId(id);
    project.setFullName(name);
    project.setWorkspaceId(workspace.getUniqueId());
    String content = toAdd.optString(ProtocolConstants.KEY_CONTENT_LOCATION, null);
    if (!isAllowedLinkDestination(content, request.getRemoteUser())) {
      String msg = NLS.bind("Cannot link to server path {0}. Use the orion.file.allowedPaths property to specify server locations where content can be linked.", content);
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, msg, null));
      return null;
    }

    try {
      computeProjectLocation(request, project, content, getInit(toAdd));
      //project creation will assign unique project id
      getMetaStore().createProject(project);
    } catch (CoreException e) {
      String msg = "Error persisting project state";
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
      return null;
    }
    try {
      getMetaStore().updateProject(project);
    } catch (CoreException e) {
      boolean authFail = handleAuthFailure(request, response, e);

      //delete the project so we don't end up with a project in a bad location
      try {
        getMetaStore().deleteProject(workspace.getUniqueId(), project.getFullName());
      } catch (CoreException e1) {
        //swallow secondary error
        LogHelper.log(e1);
      }
      if (authFail) {
        return null;
      }
      //we are unable to write in the platform location!
      String msg = NLS.bind("Cannot create project: {0}", project.getFullName());
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
      return null;
    }

    return project;
View Full Code Here


    if (path.segmentCount() != 3)
      return false;
    String workspaceId = path.segment(0);
    String projectName = path.segment(2);
    try {
      ProjectInfo project = getMetaStore().readProject(workspaceId, projectName);
      if (project == null) {
        //nothing to do if project does not exist
        return true;
      }
View Full Code Here

      }
      return null;
    }
    String projectId = SimpleMetaStoreUtil.encodeProjectIdFromProjectName(projectName);
    JSONObject jsonObject = SimpleMetaStoreUtil.readMetaFile(userMetaFolder, projectId);
    ProjectInfo projectInfo = new ProjectInfo();
    if (jsonObject == null) {
      if (SimpleMetaStoreUtil.isMetaFolder(workspaceMetaFolder, projectId) && !SimpleMetaStoreUtil.isMetaFile(userMetaFolder, projectId)) {
        // the project folder exists but the project json file does not, so create it
        File projectMetaFolder = SimpleMetaStoreUtil.readMetaFolder(workspaceMetaFolder, projectId);
        Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
        if (logger.isDebugEnabled()) {
          logger.info("SimpleMetaStore.readProject: the project folder " + projectMetaFolder.toString() + " exists but the project json file does not, so creating it in " + workspaceId); //$NON-NLS-1$
        }
        URI projectLocation = projectMetaFolder.toURI();
        projectInfo.setFullName(projectName);
        projectInfo.setWorkspaceId(workspaceId);
        projectInfo.setContentLocation(projectLocation);
        createProject(projectInfo);
        jsonObject = SimpleMetaStoreUtil.readMetaFile(userMetaFolder, projectId);
      } else {
        // both the project folder and project json do not exist, no project
        // OR both the project folder and project json exist, but bad project JSON file == no project
        return null;
      }
    }
    try {
      projectInfo.setUniqueId(jsonObject.getString(MetadataInfo.UNIQUE_ID));
      projectInfo.setWorkspaceId(jsonObject.getString("WorkspaceId"));
      projectInfo.setFullName(jsonObject.getString(UserConstants2.FULL_NAME));
      if (jsonObject.has("ContentLocation")) {
        String decodedContentLocation = SimpleMetaStoreUtil.decodeProjectContentLocation(jsonObject.getString("ContentLocation"));
        projectInfo.setContentLocation(new URI(decodedContentLocation));
      }
      setProperties(projectInfo, jsonObject.getJSONObject("Properties"));
      projectInfo.flush();
    } catch (JSONException e) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.readProject: could not read project " + projectName + " for userId " + userId, e));
    } catch (URISyntaxException e) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.readProject: could not read project " + projectName + " for userId " + userId, e));
    }
View Full Code Here

          newWorkspaceIds.add(newWorkspaceId);

          // next update each of the project JSON with the new userId and location
          List<String> projectNames = workspaceInfo.getProjectNames();
          for (String projectName : projectNames) {
            ProjectInfo projectInfo = readProject(oldWorkspaceId, projectName);
            // Set temporary properties to indicate a userId change
            projectInfo.setProperty("newUserId", newUserId);
            projectInfo.setProperty("newWorkspaceId", newWorkspaceId);
            updateProject(projectInfo);
          }
        }
        // update the UserRights in the properties
        try {
View Full Code Here

      Path basePath = new Path(baseLocation);
      if (basePath.segmentCount() < 2)
        return null;
      String workspaceId = basePath.segment(0);
      String projectName = basePath.segment(1);
      ProjectInfo projectInfo = OrionConfiguration.getMetaStore().readProject(workspaceId, projectName);
      if (projectInfo == null) {
        return null;
      }
      IFileStore projectStore = OrionConfiguration.getMetaStore().getDefaultContentLocation(projectInfo);
      String encodedProjectRoot = projectStore.toURI().toString() + "/";
View Full Code Here

*/
public class ProjectInfoTests {

  @Test
  public void testUniqueId() {
    ProjectInfo projectInfo = new ProjectInfo();
    String id = "id";
    projectInfo.setUniqueId(id);
    assertEquals(id, projectInfo.getUniqueId());
  }
View Full Code Here

    assertEquals(id, projectInfo.getUniqueId());
  }

  @Test
  public void testFullName() {
    ProjectInfo projectInfo = new ProjectInfo();
    String fullName = "Test Project";
    projectInfo.setFullName(fullName);
    assertEquals(fullName, projectInfo.getFullName());
  }
View Full Code Here

    assertEquals(fullName, projectInfo.getFullName());
  }

  @Test
  public void testContentLocation() throws URISyntaxException {
    ProjectInfo projectInfo = new ProjectInfo();
    String contentLocation = "file:/home/test/james/root";
    projectInfo.setContentLocation(new URI(contentLocation));
    assertEquals(contentLocation, projectInfo.getContentLocation().toString());
  }
View Full Code Here

    assertEquals(contentLocation, projectInfo.getContentLocation().toString());
  }

  @Test
  public void testProperties() {
    ProjectInfo projectInfo = new ProjectInfo();
    String key1 = "key1";
    String value1 = "value1";
    String key2 = "key2";
    String value2 = "value2";
    assertNull(projectInfo.getProperty(key1));
    assertNull(projectInfo.getProperty(key2));
    assertEquals(0, projectInfo.getProperties().size());
    projectInfo.setProperty(key1, value1);
    assertEquals(value1, projectInfo.getProperty(key1));
    assertEquals(1, projectInfo.getProperties().size());
    projectInfo.setProperty(key2, value2);
    assertEquals(value1, projectInfo.getProperty(key1));
    assertEquals(value2, projectInfo.getProperty(key2));
    assertEquals(2, projectInfo.getProperties().size());
    projectInfo.setProperty(key2, null);
    assertNull(projectInfo.getProperty(key2));
    assertEquals(1, projectInfo.getProperties().size());
    projectInfo.setProperty(key1, null);
    assertNull(projectInfo.getProperty(key1));
    assertEquals(0, projectInfo.getProperties().size());
  }
View Full Code Here

        URI baseLocation = getURI(request);
        URI baseLocationFile = URIUtil.append(baseLocation, "file"); //$NON-NLS-N$
        if (workspace != null) {
          JSONArray children = new JSONArray();
          for (String projectName : workspace.getProjectNames()) {
            ProjectInfo project = OrionConfiguration.getMetaStore().readProject(workspace.getUniqueId(), projectName);
            if (isAccessAllowed(user.getUserName(), project)) {
              IPath projectPath = GitUtils.pathFromProject(workspace, project);
              Map<IPath, File> gitDirs = GitUtils.getGitDirs(projectPath, Traverse.GO_DOWN);
              for (Map.Entry<IPath, File> entry : gitDirs.entrySet()) {
                JSONObject repo = listEntry(entry.getKey().lastSegment(), 0, true, 0, baseLocationFile, entry.getKey().toPortableString());
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.core.metastore.ProjectInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.