-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from q-rapids/update-taiga-connector
Update taiga connector
- Loading branch information
Showing
3 changed files
with
448 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,271 +1,161 @@ | ||
package connect.taiga; | ||
|
||
import com.google.gson.Gson; | ||
import model.github.GithubIssues; | ||
import org.apache.kafka.clients.consumer.internals.SubscriptionState; | ||
import rest.RESTInvoker; | ||
import model.taiga.*; | ||
|
||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.*; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import model.taiga.CustomAttributes; | ||
import model.taiga.CustomAttributesValues; | ||
import model.taiga.Epic; | ||
import model.taiga.Issue; | ||
import model.taiga.Milestone; | ||
import model.taiga.Project; | ||
import model.taiga.Task; | ||
import model.taiga.User; | ||
import model.taiga.UserStory; | ||
import rest.RESTInvoker; | ||
|
||
public class TaigaApi { | ||
|
||
private static Gson gson = new Gson(); | ||
private static Gson gson = new Gson(); | ||
private static DateFormat dfZULU = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); | ||
private static DateFormat onlyDate = new SimpleDateFormat("yyyy-MM-dd"); | ||
|
||
public static Issue[] getIssuesByProjectId(String url, String projectId, String token) { | ||
//Request of the project's issues | ||
public TaigaApi() { | ||
} | ||
|
||
RESTInvoker ri = new RESTInvoker(url+"/issues?project="+projectId, token); | ||
public static Issue[] getIssuesByProjectId(String url, String projectId, String token) { | ||
RESTInvoker ri = new RESTInvoker(url + "/issues?project=" + projectId, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.Issue[] iss = gson.fromJson(json, model.taiga.Issue[].class); | ||
/*for(model.taiga.Issue i : iss) { | ||
System.out.println(i.subject); | ||
System.out.println(i.status_extra_info.name); | ||
if(i.assigned_to_extra_info!=null) System.out.println(i.assigned_to_extra_info.username); | ||
}*/ | ||
return iss; | ||
} | ||
|
||
public static UserStory[] getUserStroriesByProjectId(String url, String projectId, String token) { | ||
//Request of the project's user stories | ||
|
||
RESTInvoker ri = new RESTInvoker(url+"/userstories?project="+projectId, token); | ||
public static UserStory[] getUserStoriesByProjectId(String url, String projectId, String token) { | ||
RESTInvoker ri = new RESTInvoker(url + "/userstories?project=" + projectId, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.UserStory[] us = gson.fromJson(json, model.taiga.UserStory[].class); | ||
/*for(model.taiga.UserStory u : us) { | ||
System.out.println(u.subject); | ||
if(u.epics!=null) { | ||
for (Epic e : u.epics) { | ||
System.out.println(e.id); | ||
System.out.println(e.subject); | ||
} | ||
} | ||
else System.out.println("HI HA UN NULL????"); | ||
}*/ | ||
return us; | ||
} | ||
|
||
public static UserStory getUserStroryById(String url, String Id, String token) { | ||
//Request of the project's user stories | ||
|
||
RESTInvoker ri = new RESTInvoker(url+"/userstories/"+Id, token); | ||
public static UserStory getUserStoryById(String url, String Id, String token) { | ||
RESTInvoker ri = new RESTInvoker(url + "/userstories/" + Id, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.UserStory us = gson.fromJson(json, model.taiga.UserStory.class); | ||
return us; | ||
} | ||
|
||
public static Milestone[] getMilestonesByProjectId(String url, String projectId, String token) throws Exception { | ||
//Request of the project's epics | ||
|
||
RESTInvoker ri = new RESTInvoker(url+"/milestones?project="+projectId, token); | ||
public static Map<Integer, Milestone> getMilestonesByProjectId(String url, String projectId, String token) { | ||
RESTInvoker ri = new RESTInvoker(url + "/milestones?project=" + projectId, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.Milestone[] mil = gson.fromJson(json, model.taiga.Milestone[].class); | ||
/*LocalDateTime now = LocalDateTime.now(); | ||
Date today=onlyDate.parse(now.toString()); | ||
for(model.taiga.Milestone m : mil) { | ||
if(!m.closed && (m.estimated_start.compareTo(today)<0) ) { | ||
System.out.println(m.name); | ||
} | ||
}*/ | ||
return mil; | ||
Map<Integer, Milestone> m = new HashMap(); | ||
for (int i = 0; i < mil.length; ++i) { | ||
m.put(mil[i].id, mil[i]); | ||
} | ||
return m; | ||
} | ||
|
||
public static Task[] getTasks(String url, String projectId, String token) { | ||
//Request of the project's tasks. Tasks can be from a project, milestone or user story | ||
|
||
RESTInvoker ri = new RESTInvoker(url+"/tasks?project="+projectId, token); | ||
RESTInvoker ri = new RESTInvoker(url + "/tasks?project=" + projectId, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.Task[] task = gson.fromJson(json, model.taiga.Task[].class); | ||
/*for(model.taiga.Task t : task) { | ||
System.out.println(t.subject); | ||
System.out.println(t.id); | ||
System.out.println(t.milestone_slug); | ||
System.out.println(t.status_extra_info.name); | ||
if(t.assigned_to_extra_info!=null) System.out.println(t.assigned_to_extra_info.username); | ||
}*/ | ||
return task; | ||
} | ||
|
||
public static Epic[] getEpicsByProjectID(String url, String projectId, String token) { | ||
//Request of the project's epics | ||
|
||
RESTInvoker ri = new RESTInvoker(url+"/epics?project="+projectId,token); | ||
RESTInvoker ri = new RESTInvoker(url + "/epics?project=" + projectId, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.Epic[] ep = gson.fromJson(json, model.taiga.Epic[].class); | ||
/*for(model.taiga.Epic e : ep) { | ||
System.out.println(e.id); | ||
System.out.println(e.subject); | ||
}*/ | ||
return ep; | ||
} | ||
|
||
public static Integer getProjectId(String url, String slug, String token) { | ||
RESTInvoker ri = new RESTInvoker(url + "/projects/by_slug?slug=" + slug,token); | ||
RESTInvoker ri = new RESTInvoker(url + "/projects/by_slug?slug=" + slug, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.Project pr = gson.fromJson(json, model.taiga.Project.class); | ||
return pr.id; | ||
} | ||
|
||
public static Project getProject(String url, String id, String token) { | ||
|
||
RESTInvoker ri = new RESTInvoker(url+"/projects/"+id, token); | ||
RESTInvoker ri = new RESTInvoker(url + "/projects/" + id, token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.Project pr = gson.fromJson(json, model.taiga.Project.class); | ||
//Request of other project stats | ||
RESTInvoker ri2 = new RESTInvoker(url+"/projects/"+id+"/stats", token); | ||
RESTInvoker ri2 = new RESTInvoker(url + "/projects/" + id + "/stats", token); | ||
String json2 = ri2.getDataFromServer(""); | ||
model.taiga.Project pr2 = gson.fromJson(json2, model.taiga.Project.class); | ||
pr.closed_points=pr2.closed_points; | ||
pr.defined_points=pr2.defined_points; | ||
pr.total_points=pr2.total_points; | ||
pr.closed_points = pr2.closed_points; | ||
pr.defined_points = pr2.defined_points; | ||
pr.total_points = pr2.total_points; | ||
return pr; | ||
|
||
} | ||
|
||
public static String Login(String url, String name, String password) { | ||
RESTInvoker ri = new RESTInvoker(url+"/auth", name, password); | ||
String json=ri.restlogin(url+"/auth", name, password); | ||
RESTInvoker ri = new RESTInvoker(url + "/auth", name, password); | ||
String json = ri.restlogin(url + "/auth", name, password); | ||
model.taiga.User u = gson.fromJson(json, model.taiga.User.class); | ||
return u.auth_token; | ||
} | ||
|
||
public static Map<Integer,String> getCustomAttributesIDs(String url, String type, String projectID, String token, String[] customAttributes) { | ||
|
||
Map<Integer, String> WantedIDs = new HashMap<>(); | ||
if(type=="task") { | ||
public static Map<Integer, String> getCustomAttributesIDs(String url, String type, String projectID, String token) { | ||
Map<Integer, String> WantedIDs = new HashMap(); | ||
int i; | ||
if (type == "task") { | ||
RESTInvoker ri = new RESTInvoker(url + "/task-custom-attributes?project=" + projectID, token); | ||
|
||
String json = ri.getDataFromServer(""); | ||
model.taiga.CustomAttributes[] attributes = gson.fromJson(json, model.taiga.CustomAttributes[].class); | ||
|
||
for (int i = 0; i < attributes.length; ++i) { | ||
if(Arrays.asList(customAttributes).contains(attributes[i].name)) { | ||
WantedIDs.put(attributes[i].id, attributes[i].name); | ||
} | ||
for(i = 0; i < attributes.length; ++i) { | ||
WantedIDs.put(attributes[i].id, attributes[i].name.toUpperCase()); | ||
} | ||
} | ||
if(type=="userstory") { | ||
RESTInvoker ri2 = new RESTInvoker(url + "/userstory-custom-attributes?project=" + projectID, token); | ||
|
||
if (type == "userstory") { | ||
RESTInvoker ri2 = new RESTInvoker(url + "/userstory-custom-attributes?project=" + projectID, token); | ||
String json2 = ri2.getDataFromServer(""); | ||
model.taiga.CustomAttributes[] attributes = gson.fromJson(json2, model.taiga.CustomAttributes[].class); | ||
for (int i = 0; i < attributes.length; ++i) { | ||
if(Arrays.asList(customAttributes).contains(attributes[i].name)) { | ||
WantedIDs.put(attributes[i].id, attributes[i].name); | ||
} | ||
|
||
for(i = 0; i < attributes.length; ++i) { | ||
WantedIDs.put(attributes[i].id, attributes[i].name.toUpperCase()); | ||
} | ||
} | ||
return WantedIDs; | ||
|
||
return WantedIDs; | ||
} | ||
|
||
|
||
public static Map<String, String> getCustomAttributes(Integer ID, String type, String url, String token, Map<Integer,String> WantedIDs) { | ||
Map<String, String> temp = new HashMap<>(); | ||
if(type=="task") { | ||
public static Map<String, String> getCustomAttributes(Integer ID, String type, String url, String token, Map<Integer, String> WantedIDs) { | ||
Map<String, String> temp = new HashMap(); | ||
if (type == "task") { | ||
RESTInvoker ri = new RESTInvoker(url + "/tasks/custom-attributes-values/" + ID.toString(), token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.CustomAttributesValues values = gson.fromJson(json, model.taiga.CustomAttributesValues.class); | ||
WantedIDs.forEach((k, v) -> temp.put(v, values.attributes_values.get(k.toString()))); | ||
} | ||
else if(type=="userstory") { | ||
WantedIDs.forEach((k, v) -> { | ||
temp.put(v, values.attributes_values.get(k.toString())); | ||
}); | ||
} else if (type == "userstory") { | ||
RESTInvoker ri = new RESTInvoker(url + "/userstories/custom-attributes-values/" + ID.toString(), token); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.CustomAttributesValues values = gson.fromJson(json, model.taiga.CustomAttributesValues.class); | ||
WantedIDs.forEach((k, v) -> temp.put(v, values.attributes_values.get(k.toString()))); | ||
WantedIDs.forEach((k, v) -> { | ||
temp.put(v, values.attributes_values.get(k.toString())); | ||
}); | ||
} | ||
return temp; | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
Integer piD = getProjectId("https://api.taiga.io/api/v1","aleixlinares-test", null); | ||
public static void main(String[] args) throws InterruptedException { | ||
Integer piD = getProjectId("https://api.taiga.io/api/v1", "aleixlinares-test", null); | ||
System.out.println(piD); | ||
String projectId= piD.toString(); | ||
|
||
try { | ||
Milestone m[] = getMilestonesByProjectId("https://api.taiga.io/api/v1", projectId, null); | ||
} catch (Exception e) { | ||
System.out.println("no va"); | ||
} | ||
|
||
|
||
|
||
/*RESTInvoker ri = new RESTInvoker("https://api.taiga.io/api/v1/auth", "aleix.linares@estudiantat.upc.edu", "rfc.185,ws"); | ||
String json = ri.restlogin("https://api.taiga.io/api/v1/auth", "aleix.linares@estudiantat.upc.edu", "rfc.185,ws"); | ||
model.taiga.User u = gson.fromJson(json, model.taiga.User.class); | ||
System.out.println(u.username); | ||
System.out.println(u.auth_token); | ||
Integer piD = getProjectId("https://api.taiga.io/api/v1","aleixlinares-test", u.auth_token); | ||
System.out.println(piD); | ||
String projectId= piD.toString(); | ||
String test = "Estimated Effort,Actual Effort"; | ||
String testarray[] = test.split(","); | ||
System.out.println(getCustomAttributesIDs("https://api.taiga.io/api/v1", "task", projectId, u.auth_token, testarray)); | ||
//UserStory[] us = getUserStroriesByProjectId("https://api.taiga.io/api/v1", projectId, u.auth_token); | ||
Task[] tasks = getTasks("https://api.taiga.io/api/v1", projectId, u.auth_token); | ||
Map<Integer,String> WantedIDs = getCustomAttributesIDs("https://api.taiga.io/api/v1","task", projectId, u.auth_token, testarray); | ||
System.out.println(WantedIDs); | ||
for(int i=0; i<tasks.length; ++i) { | ||
Map<String,String> m = getCustomAttributes(tasks[i].id,"task", "https://api.taiga.io/api/v1", u.auth_token, WantedIDs); | ||
System.out.println(m.get("Actual Effort")); | ||
String projectId = piD.toString(); | ||
UserStory[] t = getUserStoriesByProjectId("https://api.taiga.io/api/v1", projectId, null); | ||
Map<Integer, String> m = getCustomAttributesIDs("https://api.taiga.io/api/v1", "userstory", projectId, null); | ||
System.out.println(m); | ||
|
||
for(int i = 0; i < t.length; ++i) { | ||
Map<String, String> ms = getCustomAttributes(t[i].id, "userstory", "https://api.taiga.io/api/v1", null, m); | ||
System.out.println(t[i].subject); | ||
System.out.println(ms.get("PRIORIDAD")); | ||
} | ||
|
||
/* RESTInvoker ri2= new RESTInvoker("https://api.taiga.io/api/v1/task-custom-attributes?project=" +projectId , u.auth_token); | ||
String json2 = ri2.getDataFromServer(""); | ||
model.taiga.TaskCustomAttributes[] t = gson.fromJson(json2,model.taiga.TaskCustomAttributes[].class); | ||
System.out.println(t[0].name); | ||
System.out.println(t[0].id); | ||
System.out.println(t[1].name); | ||
System.out.println(t[1].id); | ||
System.out.println(t[2].name); | ||
System.out.println(t[2].id); | ||
for (Integer i = 0; i < tasks.length; i++) { | ||
RESTInvoker ri3 = new RESTInvoker("https://api.taiga.io/api/v1/tasks/custom-attributes-values/" + tasks[i].id.toString(), u.auth_token); | ||
String json3 = ri3.getDataFromServer(""); | ||
model.taiga.TaskCustomAttributesValues t2 = gson.fromJson(json3, model.taiga.TaskCustomAttributesValues.class); | ||
System.out.println("CUSTOM ATTRIBUTES "+ t2.task.toString()); | ||
System.out.println(t2.version); | ||
t2.attributes_values.forEach((k,v)-> System.out.println("KEY: "+ k.toString() + " VALUE: " + v.toString())); | ||
System.out.println("ESTIMATED EFFORT? --> " + t2.attributes_values.get("19129")); | ||
} | ||
//Request of a project | ||
/* System.out.println("Projecte Eventic"); | ||
RESTInvoker ri = new RESTInvoker("https://api.taiga.io/api/v1/projects/by_slug?slug=csansoon-eventic", "Aleix Linares", "rfc.185,ws"); | ||
String json = ri.getDataFromServer(""); | ||
model.taiga.Project pr = gson.fromJson(json, model.taiga.Project.class); | ||
//Request of other project stats | ||
RESTInvoker ri2 = new RESTInvoker("https://api.taiga.io/api/v1/projects/399143/stats", "Aleix Linares", "rfc.185,ws"); | ||
String json2 = ri2.getDataFromServer(""); | ||
model.taiga.Project pr2 = gson.fromJson(json2, model.taiga.Project.class); | ||
pr.closed_points=pr2.closed_points; | ||
pr.defined_points=pr2.defined_points; | ||
pr.total_points=pr2.total_points; | ||
*/ | ||
//pr.issues = getIssuesByProjectId("https://api.taiga.io/api/v1/issues", "399143", "Taiga Username", "Taiga Password"); | ||
//pr.userStories = getUserStroriesByProjectId("https://api.taiga.io/api/v1/userstories", "399143", "Aleix Linares", "rfc.185,ws"); | ||
//pr.milestones = getMilestonesByProjectId("https://api.taiga.io/api/v1/milestones", "399143", "Taiga Username", "Taiga Password"); | ||
//Task[] tasks = getTasks("https://api.taiga.io/api/v1", projectId, u.auth_token); | ||
//pr.epics = getEpicsByProjectID("https://api.taiga.io/api/v1/epics", "399143", "Aleix Linares", "rfc.185,ws"); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.