Пример #1
0
  /**
   * @param path the location of the project
   * @return a Project entity
   */
  @TransactionAttribute(TransactionAttributeType.SUPPORTS)
  public Project getProject(String path) throws ProjectException {
    try {
      String caller = membership.getProfilePathForConnectedIdentifier();
      pep.checkSecurity(caller, path, "read");

      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, Project.RESOURCE_NAME);

      Project project = em.find(Project.class, identifier.getId());
      if (project == null) {
        throw new ProjectException("unable to find a project for id " + identifier.getId());
      }

      project.setResourcePath(path);
      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "read"),
              ""));

      return project;

    } catch (Exception e) {
      throw new ProjectException(e);
    }
  }
Пример #2
0
  /**
   * @param path the location of the project in the resource tree
   * @param name
   * @param status if the project is on alpha, beta or release state
   * @param summary
   * @param licence
   */
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateProject(String path, String name, String status, String summary, String licence)
      throws ProjectException {
    try {
      if (name == null || name == "")
        throw new ProjectException("your must specify a name for your project");
      if (summary.length() < 10)
        throw new ProjectException("describe in a more comprehensive manner your project");
      if (summary.length() > 255)
        throw new ProjectException(
            "Your project description is too long. Please make it smaller than 256 bytes.");

      String caller = membership.getProfilePathForConnectedIdentifier();

      pep.checkSecurity(caller, path, "update");
      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, Project.RESOURCE_NAME);

      Project project = em.find(Project.class, identifier.getId());
      if (project == null) {
        throw new ProjectException("unable to find a project for id " + identifier.getId());
      }
      project.setName(name);
      project.setDev_status(status);
      project.setSummary(summary);
      project.setLicence(licence);
      em.merge(project);

      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");
      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "update"),
              ""));

    } catch (Exception e) {
      ctx.setRollbackOnly();
      throw new ProjectException(e);
    }
  }
Пример #3
0
  /**
   * @param name the name of the project
   * @param summary the description of the project
   * @param path the target location of the new resource
   * @param licence
   */
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void createProject(String path, String name, String summary, String licence)
      throws ProjectException {
    logger.debug("starting project creation");
    try {

      if (name == null || name == "")
        throw new ProjectException("your must specify a name for your project");
      if (summary.length() < 10)
        throw new ProjectException("describe in a more comprehensive manner your project");
      if (summary.length() > 255)
        throw new ProjectException(
            "Your project description is too long. Please make it smaller than 256 bytes.");

      String caller = membership.getProfilePathForConnectedIdentifier();
      // create entity object
      Project project = new Project();
      project.setName(name);
      project.setSummary(summary);
      project.setLicence(licence);
      project.setId(UUID.randomUUID().toString());
      em.persist(project);
      // service orchestration
      pep.checkSecurity(caller, PathHelper.getParentPath(path), "create");

      binding.bind(project.getFactoryResourceIdentifier(), path);
      binding.setProperty(
          path, FactoryResourceProperty.CREATION_TIMESTAMP, System.currentTimeMillis() + "");
      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");
      binding.setProperty(path, FactoryResourceProperty.AUTHOR, caller);

      // create default policy
      String policyId = UUID.randomUUID().toString();
      pap.createPolicy(policyId, PAPServiceHelper.buildOwnerPolicy(policyId, caller, path));
      binding.setProperty(path, FactoryResourceProperty.OWNER, caller);
      binding.setProperty(path, FactoryResourceProperty.POLICY_ID, policyId);

      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "create"),
              ""));

    } catch (Exception e) {

      ctx.setRollbackOnly();
      throw new ProjectException(e);
    }
  }
Пример #4
0
  /**
   * update meta information about the project
   *
   * @param path the location of the project in the resource tree
   * @param os the operating system used by this project
   * @param topics
   * @param language natural language used by this project
   * @param programming_language programming language used by this project
   * @param intended_audience
   */
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTagsProject(
      String path,
      String[] os,
      String[] topics,
      String[] language,
      String[] programming_language,
      String[] intended_audience)
      throws ProjectException {
    try {
      String caller = membership.getProfilePathForConnectedIdentifier();

      pep.checkSecurity(caller, path, "update");
      FactoryResourceIdentifier identifier = binding.lookup(path);
      checkResourceType(identifier, Project.RESOURCE_NAME);

      Project project = em.find(Project.class, identifier.getId());
      if (project == null) {
        throw new ProjectException("unable to find a project for id " + identifier.getId());
      }
      project.setOs(os);
      project.setTopics(topics);
      project.setSpoken_language(language);
      project.setProgramming_language(programming_language);
      project.setIntended_audience(intended_audience);
      em.merge(project);

      binding.setProperty(
          path, FactoryResourceProperty.LAST_UPDATE_TIMESTAMP, System.currentTimeMillis() + "");
      notification.throwEvent(
          new Event(
              path,
              caller,
              ProjectService.SERVICE_NAME,
              Event.buildEventType(ProjectService.SERVICE_NAME, Project.RESOURCE_NAME, "update"),
              ""));

    } catch (Exception e) {
      ctx.setRollbackOnly();
      throw new ProjectException(e);
    }
  }