Package edu.wpi.cs.wpisuitetng.modules.defecttracker.models

Examples of edu.wpi.cs.wpisuitetng.modules.defecttracker.models.Defect


    if(issues.size() > 0) {
      // TODO: pass errors to client through exception
      throw new BadRequestException();
    }
   
    Defect defect = validator.getLastExistingDefect();
    defect.getEvents().add(newComment);
    db.save(defect, s.getProject());
    db.save(defect.getEvents()); // TODO: remove this when we can change save depth

    return newComment;
  }
View Full Code Here


  /**
   * Adds a tab that allows the user to create a new Defect
   * @return The created Tab
   */
  public Tab addCreateDefectTab() {
    return addDefectTab(new Defect(), Mode.CREATE);
  }
View Full Code Here

    updateMapper.getBlacklist().add("project"); // never allow project changing
  }

  @Override
  public Defect makeEntity(Session s, String content) throws WPISuiteException {
    final Defect newDefect = Defect.fromJSON(content);
   
    // TODO: increment properly, ensure uniqueness using ID generator.  This is a gross hack.
    newDefect.setId(Count() + 1);
   
    List<ValidationIssue> issues = validator.validate(s, newDefect, Mode.CREATE);
    if(issues.size() > 0) {
      // TODO: pass errors to client through exception
      for (ValidationIssue issue : issues) {
View Full Code Here

    return defects;
  }

  @Override
  public Defect[] getAll(Session s) {
    return db.retrieveAll(new Defect(), s.getProject()).toArray(new Defect[0]);
  }
View Full Code Here

  }
 
  @Override
  public void deleteAll(Session s) throws WPISuiteException {
    ensureRole(s, Role.ADMIN);
    db.deleteAll(new Defect(), s.getProject());
  }
View Full Code Here

 
  @Override
  public int Count() {
    // TODO: there must be a faster way to do this with db4o
    // note that this is not project-specific - ids are unique across projects
    return db.retrieveAll(new Defect()).size();
  }
View Full Code Here

    return db.retrieveAll(new Defect()).size();
  }

  @Override
  public Defect update(Session session, String content) throws WPISuiteException {
    Defect updatedDefect = Defect.fromJSON(content);
   
    List<ValidationIssue> issues = validator.validate(session, updatedDefect, Mode.EDIT);
    if(issues.size() > 0) {
      // TODO: pass errors to client through exception
      throw new BadRequestException();
    }

    /*
     * Because of the disconnected objects problem in db4o, we can't just save updatedDefect.
     * We have to get the original defect from db4o, copy properties from updatedDefect,
     * then save the original defect again.
     */
    Defect existingDefect = validator.getLastExistingDefect();
    Date originalLastModified = existingDefect.getLastModifiedDate();
   
    DefectChangeset changeset = new DefectChangeset();
    // core should make sure the session user exists
    // if this can't find the user, something's horribly wrong
    changeset.setUser((User) db.retrieve(User.class, "username", session.getUsername()).get(0));
    ChangesetCallback callback = new ChangesetCallback(changeset);
   
    // copy values to old defect and fill in our changeset appropriately
    updateMapper.map(updatedDefect, existingDefect, callback);
   
    if(changeset.getChanges().size() == 0) {
      // stupid user didn't even change anything!
      // don't bother saving to database, reset last modified date
      existingDefect.setLastModifiedDate(originalLastModified);
    } else {
      // add changeset to Defect events, save to database
      existingDefect.getEvents().add(changeset);
      // TODO: events field doesn't persist without explicit save - is this a bug?
      if(!db.save(existingDefect, session.getProject()) || !db.save(existingDefect.getEvents())) {
        throw new WPISuiteException();
      }
    }
   
    return existingDefect;
View Full Code Here

    invalidUser = new User("idontexist", "blah", "1234", 99);
   
    tag = new Tag("tag");
    bob = new User("bob", "bob", "1234", 1);
    existingUser = new User("joe", "joe", "1234", 2);
    existingDefect = new Defect(1, "An existing defect", "", bob);
    existingDefect.setCreationDate(new Date(0));
    existingDefect.setLastModifiedDate(new Date(0));
    existingDefect.setEvents(new ArrayList<DefectEvent>());
   
    otherDefect = new Defect(2, "A defect in a different project", "", bob);
    otherProject = new Project("other", "2");
   
    testProject = new Project("test", "1");
    mockSsid = "abc123";
    defaultSession = new Session(bob, testProject, mockSsid);
   
    //need copies to simulate db4o cross-container problem
    tagCopy = new Tag("tag");
    bobCopy = new User(null, "bob", null, -1);
    goodNewDefect = new Defect(-1, "This is a good title", "", bobCopy);
    goodNewDefect.setAssignee(bobCopy);
    goodNewDefect.getTags().add(tagCopy);
    goodNewDefect.setStatus(DefectStatus.CONFIRMED); // ignored
    ignoredEvents = new ArrayList<DefectEvent>();
    goodNewDefect.setEvents(ignoredEvents); // ignored
   
    existingUserCopy = new User(null, "joe", null, -1);
    goodUpdatedDefect = new Defect(1, "A changed title", "A changed description", bobCopy);
    goodUpdatedDefect.setAssignee(existingUserCopy);
    goodUpdatedDefect.setEvents(new ArrayList<DefectEvent>());
    goodUpdatedDefect.getTags().add(tagCopy);
    goodUpdatedDefect.setStatus(DefectStatus.CONFIRMED);
   
View Full Code Here

  public void setUp() throws Exception {
    bob = new User("bob", "bob", "1234", 1);
    testProject = new Project("test", "1");
    mockSsid = "abc123";
    defaultSession = new Session(bob, testProject, mockSsid);
    defect = new Defect(1, "title", "description", bob);
   
    User bobCopy = new User(null, "bob", null, -1);
    goodNewComment = new Comment(1, bobCopy, "hello");
   
    db = new MockData(new HashSet<Object>());
View Full Code Here

    if(defect == null) {
      issues.add(new ValidationIssue("Defect cannot be null"));
      return issues;
    }
   
    Defect oldDefect = null;
    if(mode == Mode.EDIT) {
      oldDefect = getExistingDefect(defect.getId(), session.getProject(), issues, "id");
    }
    lastExistingDefect = oldDefect;
   
    if(mode == Mode.CREATE) {
      // new defects should always have new status
      defect.setStatus(DefectStatus.NEW);
    } else if(defect.getStatus() == null) {
      issues.add(new ValidationIssue("Cannot be null", "status"));
    }
   
    // make sure title and description size are within constraints
    if(defect.getTitle() == null || defect.getTitle().length() > 150
        || defect.getTitle().length() < 5) {
      issues.add(new ValidationIssue("Required, must be 5-150 characters", "title"));
    }
    if(defect.getDescription() == null) {
      // empty descriptions are okay
      defect.setDescription("");
    } else if(defect.getDescription().length() > 5000) {
      issues.add(new ValidationIssue("Cannot be greater than 5000 characters", "description"));
    }
   
    // make sure the creator and assignee exist and aren't duplicated
    if(mode == Mode.EDIT) {
      if(oldDefect != null) {
        defect.setCreator(oldDefect.getCreator());
      }
    } else if(defect.getCreator() == null) {
      issues.add(new ValidationIssue("Required", "creator"));
    } else {
      User creator = getExistingUser(defect.getCreator().getUsername(), issues, "creator");
      if(creator != null) {
        if(!creator.getUsername().equals(session.getUsername())) {
          issues.add(new ValidationIssue("Must match currently logged in user", "creator"));
        } else {
          defect.setCreator(creator);
        }
      }
    }
   
    if(defect.getAssignee() != null) { // defects can be missing an assignee
      User assignee = getExistingUser(defect.getAssignee().getUsername(), issues, "assignee");
      if(assignee != null) {
        defect.setAssignee(assignee);
      }
    }
   
   
    if(defect.getTags() == null) {
      defect.setTags(new HashSet<Tag>());
    }
    final Set<Tag> tags = defect.getTags();
    if(tags.size() > 100) {
      issues.add(new ValidationIssue("Cannot have more than 100 tags", "tags"));
    } else {
      // need to make a new set because we can't modify existing set as we iterate over it
      final Set<Tag> newTags = new HashSet<Tag>();
      // validate each tag
      for(Tag tag : tags) {
        if(tag == null) {
          issues.add(new ValidationIssue("Cannot be null", "tags"));
          break;
        }
        List<Model> existingModels = data.retrieve(Tag.class, "name", tag.getName(),
            session.getProject());
        if(existingModels.size() > 0 && existingModels.get(0) != null) {
          // make sure we don't insert duplicate tags
          newTags.add((Tag) existingModels.get(0));
        } else if(tag.getName() == null || tag.getName().length() < 1) {
          // tags with empty names aren't allowed
          // TODO: this validation should probably happen in Tag's EntityManager
          issues.add(new ValidationIssue("Names can't be empty", "tags"));
          break;
        } else { //doesn't already exist, is valid
          newTags.add(tag);
        }
      }
      defect.setTags(newTags);
    }
   
    // make sure we're not being spoofed with some weird date
    final Date now = new Date();
    if(oldDefect != null) {
      defect.setCreationDate(oldDefect.getCreationDate());
    } else {
      defect.setCreationDate(now);
    }
    defect.setLastModifiedDate((Date)now.clone());
   
    if(oldDefect != null) {
      defect.setEvents(oldDefect.getEvents());
    } else {
      // new defects should never have any events
      defect.setEvents(new ArrayList<DefectEvent>());
    }
   
View Full Code Here

TOP

Related Classes of edu.wpi.cs.wpisuitetng.modules.defecttracker.models.Defect

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.