adding add comment to issuezilla functionality for huge number of duplicates persist_103381_root
authorjsedek@netbeans.org
Thu, 20 Sep 2007 08:37:40 +0000
changeset 25439110b91e91dc
parent 2542 bd2644d650e4
child 2544 29cda1d5216a
adding add comment to issuezilla functionality for huge number of duplicates
logger/uihandlerserver/src/java/org/netbeans/server/uihandler/DbInsertion.java
logger/uihandlerserver/test/org/netbeans/server/uihandler/IssuezillaInsertionTest.java
     1.1 --- a/logger/uihandlerserver/src/java/org/netbeans/server/uihandler/DbInsertion.java	Wed Sep 19 18:31:21 2007 +0000
     1.2 +++ b/logger/uihandlerserver/src/java/org/netbeans/server/uihandler/DbInsertion.java	Thu Sep 20 08:37:40 2007 +0000
     1.3 @@ -325,19 +325,20 @@
     1.4          if (GUEST_USER.equals(exc.getNbuserId().getName())){
     1.5              return;
     1.6          }
     1.7 +        BugReporter reporter = BugReporterFactory.getDefaultReporter();
     1.8 +        Properties props = new Properties();
     1.9 +        props.setProperty("username", userName); // NOI18N
    1.10 +        props.setProperty("password", passwd); // NOI18N
    1.11          for (IssueZillaInsertionFilter filter : getFilters()) {
    1.12              switch (filter.isInsertable(exc)) {
    1.13                  case INSERT:
    1.14 -                    BugReporter reporter = BugReporterFactory.getDefaultReporter();
    1.15 -                    Properties props = new Properties();
    1.16 -                    props.setProperty("username", userName); // NOI18N
    1.17 -                    props.setProperty("password", passwd); // NOI18N
    1.18                      reporter.reportException(exc, props);
    1.19                      return;
    1.20                  case CANCEL:
    1.21                      return;
    1.22                  case ADDCOMMENT:
    1.23 -                    
    1.24 +                    String addComment = filter.addComment(exc);
    1.25 +                    reporter.postTextComment(PersistenceUtils.getOriginal(exc).getIssuezillaid(), props, addComment);
    1.26                      return;
    1.27                  default: // continue with next filter
    1.28              }
    1.29 @@ -587,9 +588,9 @@
    1.30  
    1.31          public InsertionResult isInsertable(org.netbeans.modules.exceptions.entity.Exceptions exc) {
    1.32              org.netbeans.modules.exceptions.entity.Exceptions original = PersistenceUtils.getOriginal(exc);
    1.33 -            if (original.getIssuezillaid() == null) return DbInsertion.InsertionResult.NONE;
    1.34 +            if (original.getIssuezillaid() == null || original.getIssuezillaid() == 0) return DbInsertion.InsertionResult.NONE;
    1.35              int duplicatesCount = original.getDuplicates();
    1.36 -            if (duplicatesCount / getDuplicatesNo() == 0){
    1.37 +            if (duplicatesCount % getDuplicatesNo() == 0){
    1.38                  return DbInsertion.InsertionResult.ADDCOMMENT;
    1.39              }
    1.40              return DbInsertion.InsertionResult.NONE;
     2.1 --- a/logger/uihandlerserver/test/org/netbeans/server/uihandler/IssuezillaInsertionTest.java	Wed Sep 19 18:31:21 2007 +0000
     2.2 +++ b/logger/uihandlerserver/test/org/netbeans/server/uihandler/IssuezillaInsertionTest.java	Thu Sep 20 08:37:40 2007 +0000
     2.3 @@ -89,7 +89,8 @@
     2.4      public void testQEUserFilter() throws Exception{
     2.5          TestHandler handler = new TestHandler();
     2.6          Logger.getLogger(BugReporterFactory.class.getName()).addHandler(handler);
     2.7 -        
     2.8 +        DbInsertion.setDuplicatesNo(new Long(2));
     2.9 +
    2.10          String directUserName = "exceptions";
    2.11          LogRecord rec= new LogRecord(Level.SEVERE, "TESTING LOG RECORD");
    2.12          ArrayList<String> params = new ArrayList<String>(7);
    2.13 @@ -126,9 +127,26 @@
    2.14          int issuezillaId = 10;
    2.15          org.netbeans.modules.exceptions.entity.Exceptions exc =
    2.16                   perUtils.getEntity(org.netbeans.modules.exceptions.entity.Exceptions.class, issueId);
    2.17 -        
    2.18          exc.setIssuezillaid(issuezillaId);
    2.19          perUtils.merge(exc);
    2.20 +
    2.21 +        String undirectUser = "tester";
    2.22 +        params.set(3, undirectUser);
    2.23 +        params.set(6, undirectUser);
    2.24 +        rec.setParameters(params.toArray());
    2.25 +        dbInsertionResult =  new DbInsertion(rec, thrown, "file", 1).start();
    2.26 +        waitLogsParsed();
    2.27 +        result = handler.getResult();
    2.28 +        assertNotNull("MANY DUPLICATES FILTER - ADD COMMENT", result);
    2.29 +        parameters = result.getParameters();
    2.30 +        assertEquals(Integer.toString(issuezillaId), parameters[0].toString());
    2.31 +        assertEquals(undirectUser, parameters[1]);
    2.32 +        assertEquals(undirectUser, parameters[2]);
    2.33 +        String str = (String) parameters[3];
    2.34 +        assertNotNull("GENERATED MESSAGE", str);
    2.35 +        assertTrue(str.contains("MORE"));
    2.36 +        handler.flush();
    2.37 +        
    2.38          Issue issue = new Issue();
    2.39          issue.setIssueId(issuezillaId);
    2.40          issue.setIssueStatus("RESOLVED");
    2.41 @@ -147,11 +165,12 @@
    2.42      
    2.43      public void testGetDuplicates() throws Exception{
    2.44          LogRecord rec= new LogRecord(Level.SEVERE, "TESTING LOG RECORD");
    2.45 +        String userName = "GUEST";
    2.46          ArrayList<String> params = new ArrayList<String>(7);
    2.47          params.add("Linux, 2.6.15-1.2054_FC5smp, i386");
    2.48          params.add("Java HotSpot(TM) Client VM, 1.6.0-b105");
    2.49          params.add("NetBeans IDE Dev (Build 200702121900)");
    2.50 -        params.add("GUEST");
    2.51 +        params.add(userName);
    2.52          params.add("UnknownError : Summary Message");
    2.53          params.add("COMMENT");
    2.54          params.add("test");
    2.55 @@ -165,7 +184,10 @@
    2.56          org.netbeans.modules.exceptions.entity.Exceptions rootException = all.get(all.size()-1);
    2.57          rootId = rootException.getId();
    2.58          List<Nbuser> users = perUtils.getAll(Nbuser.class);
    2.59 -        Nbuser user = users.get(users.size()-1);
    2.60 +        Nbuser user=null;
    2.61 +        for (Nbuser us : users) {
    2.62 +            if (userName.equals(us.getName())) user = us;
    2.63 +        }
    2.64          assertNotNull(rootException);
    2.65          assertEquals(0, rootException.getDuplicates());
    2.66          assertEquals(0, rootException.getDuplicatesFromDistinctUsers());
    2.67 @@ -181,7 +203,7 @@
    2.68          assertEquals(2, rootException.getDuplicates());
    2.69          assertEquals(1, rootException.getDuplicatesFromDistinctUsers());
    2.70          assertEquals(2, rootException.getDuplicatesFromOneUser(user));
    2.71 -        String userName = "exceptions";
    2.72 +        userName = "exceptions";
    2.73          params.set(3, userName);
    2.74          params.set(6, "petrzajac");
    2.75          rec.setParameters(params.toArray());