@ -19,18 +19,14 @@ para poder mostrarlo en la vista de visualizacion de tickets*/
public class RedmineClient {
/ / private static final String REDMINE_URL = "http://localhost:3000" ;
/ / private static final String API_KEY = "cf3be6168e66c99892c6212ea0bc64e8ab1c6848" ;
private static final int PAGE_SIZE = 25 ;
static String REDMINE_URL ;
static String API_KEY ;
/ / private final RestTemplate restTemplate ;
public RedmineClient ( String redmineUrl , String apiKey ) {
REDMINE_URL = redmineUrl ;
API_KEY = apiKey ;
/ / this . restTemplate = new RestTemplate ( ) ;
}
public List < Ticket > getTickets ( ) {
@ -40,9 +36,8 @@ public class RedmineClient {
while ( true ) {
HttpRequest request = HttpRequest . newBuilder ( )
. uri ( URI . create ( REDMINE_URL + "/issues.json?key=" + PAGE_SIZE + "&offset=" + offset ) )
. uri ( URI . create ( REDMINE_URL + "/issues.json?key=" + API_KEY + "&offset=" + offset ) )
. header ( "Content-Type" , "application/json" )
. header ( "X-Redmine-API-Key" , API_KEY )
. build ( ) ;
try {
@ -74,16 +69,27 @@ public class RedmineClient {
JsonArray issues = jsonObject . getAsJsonArray ( "issues" ) ;
for ( JsonElement issueElement : issues ) {
JsonObject issue = issueElement . getAsJsonObject ( ) ;
System . out . println ( issue ) ;
int id = issue . get ( "id" ) . getAsInt ( ) ;
String subject = issue . get ( "subject" ) . getAsString ( ) ;
String description = issue . has ( "description" ) ? issue . get ( "description" ) . getAsString ( ) : "" ;
String status = issue . getAsJsonObject ( "status" ) . get ( "name" ) . getAsString ( ) ;
/ / Aqui se obtiene el nombre del autor quien crea el ticket
JsonObject authorJson = issue . getAsJsonObject ( "author" ) ;
Ticket . User author = null ;
if ( authorJson ! = null ) {
String username = authorJson . get ( "name" ) . getAsString ( ) ;
author = new Ticket . User ( username ) ;
System . out . println ( "Author JSON: " + authorJson ) ;
JsonElement nameElement = authorJson . get ( "name" ) ;
if ( nameElement ! = null ) {
String username = nameElement . getAsString ( ) ;
System . out . println ( "Autor del ticket: " + username ) ;
author = new Ticket . User ( username ) ;
} else {
System . out . println ( "Campo name no encontrado en el autor: " + authorJson ) ;
}
} else {
System . out . println ( "Autor es NULL para el ticket id: " + id ) ;
}
tickets . add ( new Ticket ( id , subject , description , status , author ) ) ;
}
@ -93,8 +99,15 @@ public class RedmineClient {
public List < Ticket > getTicketsCreatedBy ( String username ) {
List < Ticket > allTickets = getTickets ( ) ;
List < Ticket > filteredTickets = allTickets . stream ( )
. filter ( ticket - > ticket . getAuthor ( ) ! = null & & username . equals ( ticket . getAuthor ( ) . getUsername ( ) ) )
. collect ( Collectors . toList ( ) ) ;
. filter ( ticket - > {
if ( ticket . getAuthor ( ) ! = null ) {
String ticketUsername = ticket . getAuthor ( ) . getUsername ( ) ;
System . out . println ( "Comparando: " + username + " con " + ticketUsername ) ;
return username . equals ( ticketUsername ) ;
}
return false ;
} )
. collect ( Collectors . toList ( ) ) ;
System . out . println ( "Total de tickets creados por " + username + ": " + filteredTickets . size ( ) ) ;
return filteredTickets ;
}