예제 #1
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);
    }
  }
예제 #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);
    }
  }