@ -0,0 +1,60 @@ | |||
package com.example.application.api; | |||
import com.example.application.models.Ticket; | |||
import com.nimbusds.jose.shaded.gson.JsonArray; | |||
import com.nimbusds.jose.shaded.gson.JsonElement; | |||
import com.nimbusds.jose.shaded.gson.JsonObject; | |||
import com.nimbusds.jose.shaded.gson.JsonParser; | |||
import java.net.URI; | |||
import java.net.http.HttpClient; | |||
import java.net.http.HttpRequest; | |||
import java.net.http.HttpResponse; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/*Esta clase se encarga de obtener los tickets desde redmine | |||
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"; | |||
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()); | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
return tickets; | |||
} | |||
private List<Ticket> parseTickets(String json) { | |||
List<Ticket> tickets = new ArrayList<>(); | |||
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject(); | |||
JsonArray issues = jsonObject.getAsJsonArray("issues"); | |||
for (JsonElement issueElement : issues) { | |||
JsonObject issue = issueElement.getAsJsonObject(); | |||
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)); | |||
} | |||
return tickets; | |||
} | |||
} |
@ -0,0 +1,28 @@ | |||
package com.example.application.models; | |||
/*Esta clase obtiene los detalles de los tickets*/ | |||
public class Ticket { | |||
private int id; | |||
private String subject; | |||
private String description; | |||
public Ticket(int id, String subject, String description) { | |||
this.id = id; | |||
this.subject = subject; | |||
this.description = description; | |||
} | |||
public int getId() { | |||
return id; | |||
} | |||
public String getSubject() { | |||
return subject; | |||
} | |||
public String getDescription() { | |||
return description; | |||
} | |||
} |
@ -1,2 +0,0 @@ | |||
package com.example.application.views.login;public class CustomLoginView { | |||
} |
@ -1,2 +0,0 @@ | |||
package com.example.application.views.login;public class LoginFailAuth { | |||
} |
@ -1,26 +1,47 @@ | |||
package com.example.application.views.tickets; | |||
import com.example.application.api.RedmineClient; | |||
import com.example.application.models.Ticket; | |||
import com.example.application.views.MainLayout; | |||
import com.vaadin.flow.component.html.Div; | |||
import com.vaadin.flow.component.html.H2; | |||
import com.vaadin.flow.component.grid.ColumnTextAlign; | |||
import com.vaadin.flow.component.grid.Grid; | |||
import com.vaadin.flow.component.orderedlayout.VerticalLayout; | |||
import com.vaadin.flow.router.Route; | |||
import com.vaadin.flow.server.auth.AnonymousAllowed; | |||
import java.util.List; | |||
@Route(value="mytickets", layout = MainLayout.class) | |||
@AnonymousAllowed | |||
public class MisTicketsView extends VerticalLayout { | |||
private final RedmineClient redmineClient; | |||
private final Grid<Ticket> grid; | |||
public MisTicketsView() { | |||
this.redmineClient = new RedmineClient(); | |||
this.grid = new Grid<>(Ticket.class, false); | |||
grid.addColumn(Ticket::getId).setHeader("No.") | |||
.setWidth("4em").setFlexGrow(0).setTextAlign(ColumnTextAlign.CENTER); | |||
grid.addColumn(Ticket::getSubject).setHeader("Asunto") | |||
.setAutoWidth(true).setFlexGrow(0); | |||
grid.addColumn(Ticket::getDescription).setHeader("Description") | |||
.setFlexGrow(1); | |||
grid.setSizeFull(); | |||
setSizeFull(); | |||
Div banner = new Div(); | |||
banner.setText("Aqui es donde el usuario vera sus tickets creados"); | |||
banner.getStyle() | |||
.set("display", "flex") | |||
.set("justify-content", "center") | |||
.set("align-items", "center") | |||
.set("height", "100%"); | |||
add(new H2("Mis tickets"), banner); | |||
setPadding(false); | |||
add(grid); | |||
loadTickets(); | |||
} | |||
private void loadTickets() { | |||
List<Ticket> tickets = redmineClient.getTickets(); | |||
grid.setItems(tickets); | |||
} | |||
} |