@ -20,26 +20,38 @@ 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 ;
public List < Ticket > getTickets ( ) {
List < Ticket > tickets = new ArrayList < > ( ) ;
HttpClient client = HttpClient . newHttpClient ( ) ;
HttpRequest request = HttpRequest . newBuilder ( )
. uri ( URI . create ( REDMINE_URL + "/issues.json" ) )
. header ( "Content-Type" , "application/json" )
. header ( "X-Redmine-API-Key" , API_KEY )
. build ( ) ;
try {
HttpResponse < String > response = client . send ( request , HttpResponse . BodyHandlers . ofString ( ) ) ;
if ( response . statusCode ( ) = = 200 ) {
String responseBody = response . body ( ) ;
tickets = parseTickets ( responseBody ) ;
} else {
System . err . println ( "Error en la respuesta: " + response . statusCode ( ) ) ;
int offset = 0 ;
while ( true ) {
HttpRequest request = HttpRequest . newBuilder ( )
. uri ( URI . create ( REDMINE_URL + "/issues.json?limit=" + PAGE_SIZE + "&offset=" + offset ) )
. header ( "Content-Type" , "application/json" )
. header ( "X-Redmine-API-Key" , API_KEY )
. build ( ) ;
try {
HttpResponse < String > response = client . send ( request , HttpResponse . BodyHandlers . ofString ( ) ) ;
if ( response . statusCode ( ) = = 200 ) {
String responseBody = response . body ( ) ;
List < Ticket > pageTickets = parseTickets ( responseBody ) ;
tickets . addAll ( pageTickets ) ;
if ( pageTickets . size ( ) < PAGE_SIZE ) {
break ;
}
offset + = PAGE_SIZE ;
} else {
System . err . println ( "Error en la respuesta: " + response . statusCode ( ) ) ;
break ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
break ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
return tickets ;
}
@ -53,7 +65,8 @@ public class RedmineClient {
int id = issue . get ( "id" ) . getAsInt ( ) ;
String subject = issue . get ( "subject" ) . getAsString ( ) ;
String description = issue . has ( "description" ) ? issue . get ( "description" ) . getAsString ( ) : "" ;
tickets . add ( new Ticket ( id , subject , description ) ) ;
String status = issue . getAsJsonObject ( "status" ) . get ( "name" ) . getAsString ( ) ;
tickets . add ( new Ticket ( id , subject , description , status ) ) ;
}
return tickets ;
}