Results 1 to 3 of 3
  1. #1
    walkout__ is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default How to count sum of worklogs with same date on JIRA?

    How to count sum of worklogs with same date on JIRA?

    Here is code:

    Java Code:
    package com.i4ware.plugin.timesheet;
    
    import java.io.IOException;
    
    import com.atlassian.jira.issue.Issue;
    import com.atlassian.jira.issue.IssueManager;
    import com.atlassian.jira.project.Project;
    import com.atlassian.jira.project.ProjectManager;
    import org.ofbiz.core.entity.DelegatorInterface;
    import org.ofbiz.core.entity.EntityExpr;
    import org.ofbiz.core.entity.EntityOperator;
    import org.ofbiz.core.entity.GenericEntityException;
    import org.ofbiz.core.entity.GenericValue;
    import org.ofbiz.core.util.UtilMisc;
    import org.apache.commons.lang.StringEscapeUtils;
    import com.atlassian.crowd.embedded.api.User;
    
    import com.atlassian.jira.issue.worklog.Worklog;
    import com.atlassian.jira.issue.worklog.WorklogManager;
    import com.atlassian.jira.issue.worklog.WorklogImpl;
    import com.i4ware.plugin.util.WorklogUtil;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.atlassian.jira.util.json.JSONObject;
    import com.atlassian.jira.util.json.JSONException;
    import com.atlassian.jira.util.json.JSONArray;
    
    import java.io.UnsupportedEncodingException;
    import java.sql.Timestamp;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.util.TimeZone;
    import java.util.TreeMap;
    import java.util.TreeSet;
    import java.lang.Long;
    import java.util.Collection;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.lang.Class;
    
    public class LoadServlet extends HttpServlet
    {
    	
        /** value is made for JSON {"success":true} or {"success":false}. */
        private Boolean value;
        /** tasks Object. i.e tasks = arr; */
        private Object issues;
        /** limit int. i.e
         * limit = Integer.valueOf(request.getParameter("limit")).intValue();.
         */
        private int limit;
        /** pages int. variable of total count of rows i.e pages = numRows;. */
        private int pages;
        private String json;
        private JSONObject obj;
        
        private long count;
        
        private Project project;
        
    	private IssueManager issueManager;
    	private WorklogManager worklogManager;
    	private Class cls;
    	
    	private String startDate;
    	private String endDate;
    	private ProjectManager projectManager;
    	
    	public LoadServlet(IssueManager issueManager, ProjectManager projectManager, WorklogManager worklogManager)
    	{
    		this.issueManager = issueManager;
    		this.projectManager = projectManager;
    		this.worklogManager = worklogManager;
    	}
    	
    	@Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
        {
    		resp.setContentType("application/json");		
        
        }
    	
    	@Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
        {		
    		
    		String projectIdreq = req.getParameter("project");
    		String monthReq = req.getParameter("month");
    		String yearReq = req.getParameter("year");
            
            project = projectManager.getProjectObjByKey(projectIdreq);
            
            long projectId = project.getId();
            
            Calendar calendar = Calendar.getInstance(); 
    
            DateFormat monthFormat = new SimpleDateFormat("M");
            DateFormat yearFormat = new SimpleDateFormat("yyyy");
            DateFormat day = new SimpleDateFormat("EEE");
            DateFormat itter = new SimpleDateFormat("M-d-yyyy");
       
            int m = Integer.valueOf(req.getParameter("month")).intValue();
            int y = Integer.valueOf(req.getParameter("year")).intValue();
            calendar.set(y, m - 1, 1);
            int lastDate = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            
            int ii = 1;
            int iii = 1;        
            
            JSONArray arr = new JSONArray();
            int i = 1;
            
            try {
            	
            	Collection<Long> issueIds = issueManager.getIssueIdsForProject(projectId);
            	
                List<Issue> issuesList = issueManager.getIssueObjects(issueIds);
                
                Iterator iterator = issuesList.iterator();
                
                Hashtable numbers = new Hashtable();
                
                while (iterator.hasNext()) {
            		
                	Issue issueIter = issueManager.getIssueObject(iterator.next().toString());
                	
                	User assignee = issueIter.getAssigneeUser();
                	
                	List<Worklog> worklog = worklogManager.getByIssue(issueIter);
                	
                	Iterator<Worklog> worklogIterator = worklog.iterator();           	
            		
            	    try {	
            		JSONObject obj = new JSONObject()
            		        .put("id", issueIter.getKey())
            				.put("title",issueIter.getSummary())
            				.put("user_id",issueIter.getAssigneeId())
            				.put("assignee",assignee.getDisplayName())
                            .put("initial_estimate",issueIter.getOriginalEstimate() / 3600)
                            .put("remaining_estimate",issueIter.getEstimate() / 3600);
            		
            		while (worklogIterator.hasNext()) {
            			
            			   //System.out.println(worklogIterator.next().toString());
            			
            			   Worklog itr = worklogIterator.next();
            			   
            			   Issue iss = itr.	getIssue();
    
            		       startDate = itter.format(itr.getStartDate());
            		       long timeSpent = itr.getTimeSpent();
            		       
            		       numbers.put( iss.getKey() + "_" + startDate, timeSpent);
            		               		       
            		       String strDate = iss.getKey() + "_" + startDate;
            		       long n = (Long)numbers.get(strDate);
            		       
            		       //if (strDate.equals(iss.getKey() + "_" + startDate))
            		       
            		       //if (n != null) {
            		           System.out.println(strDate + " = " + n);
            		       //}
            		       
            		       /*if (startDate.equals(itter.format(itr.getStartDate()))) {
            		    	   timeSpent = timeSpent+timeSpent;
            		       }*/
            	           
            	           obj.put(startDate,timeSpent / 3600);
            		
            		}
            		
            		arr.put(obj);
                    } catch (JSONException jerr) {
                	jerr.printStackTrace(); 
                    }
            	
            	i++;
            		
            	}
            
            } catch (GenericEntityException e) {
            	e.printStackTrace(); 
            }
            
            issues = arr;
            pages = 1;
            value = Boolean.valueOf(!"false"
                    .equalsIgnoreCase((String) "true"));
            
            
            try {
            
            json = new JSONObject()
            .put("tasks", issues)
            .put("totalCount", pages)
            .put("success", value)
            .toString();
            
            } catch (JSONException err) {
            	err.printStackTrace();
            }
            
    		resp.setContentType("application/json");		
    		resp.getWriter().write(json);
            resp.getWriter().close();
        
        }
    }
    Here is user interface that I try to do:

    How to count sum of worklogs with same date on JIRA?-jira-timesheet-04.png
    Last edited by walkout__; 04-26-2012 at 08:14 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: How to count sum of worklogs with same date on JIRA?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    walkout__ is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to count sum of worklogs with same date on JIRA?

    Yes.. I am cross posted my question to get answed soon as possible.

Similar Threads

  1. Atlassian JIRA 5.0.1
    By java software in forum Java Software
    Replies: 0
    Last Post: 03-30-2012, 01:29 PM
  2. Replies: 5
    Last Post: 02-16-2012, 10:26 AM
  3. Atlassian JIRA 4.4.3
    By java software in forum Java Software
    Replies: 0
    Last Post: 10-20-2011, 08:42 PM
  4. Replies: 4
    Last Post: 07-27-2011, 12:57 PM
  5. JIRA Client 1.3
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-14-2008, 07:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •