コード例 #1
0
  @Override
  public Project makeEntity(Session s, String content) throws WPISuiteException {
    User theUser = s.getUser();

    logger.log(Level.FINER, "Attempting new Project creation...");

    Project p;
    try {
      p = Project.fromJSON(content);
    } catch (JsonSyntaxException e) {
      logger.log(Level.WARNING, "Invalid Project entity creation string.");
      throw new BadRequestException(
          "The entity creation string had invalid format. Entity String: " + content);
    }

    logger.log(Level.FINE, "New project: " + p.getName() + " submitted by: " + theUser.getName());
    p.setOwner(theUser);

    if (getEntity(s, p.getIdNum())[0] == null) {
      if (getEntityByName(s, p.getName())[0] == null) {
        save(s, p);
      } else {
        logger.log(Level.WARNING, "Project Name Conflict Exception during Project creation.");
        throw new ConflictException(
            "A project with the given name already exists. Entity String: " + content);
      }
    } else {
      logger.log(Level.WARNING, "ID Conflict Exception during Project creation.");
      throw new ConflictException(
          "A project with the given ID already exists. Entity String: " + content);
    }

    logger.log(Level.FINER, "Project creation success!");
    return p;
  }
コード例 #2
0
 @Override
 public void deleteAll(Session s) throws WPISuiteException {
   User theUser = s.getUser();
   logger.log(Level.INFO, "ProjectManager invoking DeleteAll...");
   if (theUser.getRole().equals(Role.ADMIN)) {
     data.deleteAll(new Project("", ""));
   } else {
     logger.log(
         Level.WARNING, "ProjectManager DeleteAll attempted by user with insufficient permission");
     throw new UnauthorizedException(
         "You do not have the required permissions to perform this action.");
   }
 }
コード例 #3
0
  public Project update(Session s, Project toUpdate, String changeSet) throws WPISuiteException {
    if (s == null) {
      throw new WPISuiteException("Null session.");
    }

    User theUser = s.getUser();
    if (theUser.equals(toUpdate.getOwner()) || theUser.getRole().equals(Role.ADMIN)) {

      // convert updateString into a Map, then load into the User
      try {
        logger.log(Level.FINE, "Project update being attempted...");
        Project change = Project.fromJSON(changeSet);

        // check if the changes contains each field of name
        if (change.getName() != null && !change.getName().equals("")) {
          // check for conflict for changing the project name
          Project isConflict = getEntityByName(s, change.getName())[0];
          if (isConflict != null && !isConflict.getIdNum().equals(change.getIdNum())) {
            throw new ConflictException(
                "ProjectManager attempted to update a Project's name to be the same as an existing project");
          }

          toUpdate.setName(change.getName());
        }

        if (change.getOwner() != null) {
          toUpdate.setOwner(change.getOwner());
        }
      } catch (ConflictException e) {
        logger.log(
            Level.WARNING,
            "ProjectManager attempted to update a Project's name to be the same as an existing project");
        throw e;
      } catch (Exception e) {
        logger.log(Level.WARNING, "ProjectManager.update() had a failure in the changeset mapper.");
        throw new DatabaseException(
            "Failure in the ProjectManager.update() changeset mapper."); // on Mapping failure
      }

      // save the changes back
      this.save(s, toUpdate);

      // check for changes in each field
      return toUpdate;
    } else {
      logger.log(Level.WARNING, "Unauthorized Project update attempted.");
      throw new UnauthorizedException(
          "You do not have the required permissions to perform this action.");
    }
  }
コード例 #4
0
  @Override
  public boolean deleteEntity(Session s1, String id) throws WPISuiteException {
    if (s1 == null) {
      throw new WPISuiteException("Null Session.");
    }
    User theUser = s1.getUser();
    Project[] model = this.getEntity(id);
    if (model[0].getPermission(theUser).equals(Permission.WRITE)
        || theUser.getRole().equals(Role.ADMIN)) {
      Model m = data.delete(data.retrieve(project, "idNum", id).get(0));
      logger.log(Level.INFO, "ProjectManager deleting project <" + id + ">");

      return (m != null) ? true : false;
    } else {
      logger.log(
          Level.WARNING, "ProjectManager Delete attempted by user with insufficient permission");
      throw new UnauthorizedException(
          "You do not have the required permissions to perform this action.");
    }
  }