diff --git a/src/main/java/mx/gob/jumapacelaya/api/RedmineClient.java b/src/main/java/mx/gob/jumapacelaya/api/RedmineClient.java index 4f4e99e..4f57d39 100644 --- a/src/main/java/mx/gob/jumapacelaya/api/RedmineClient.java +++ b/src/main/java/mx/gob/jumapacelaya/api/RedmineClient.java @@ -152,18 +152,9 @@ public class RedmineClient { } } - // Verifica y obtiene el autor - Ticket.User author = null; - if (issue.has("author") && !issue.get("author").isJsonNull()) { - JsonObject authorJson = issue.getAsJsonObject("author"); - if (authorJson.has("name") && !authorJson.get("name").isJsonNull()) { - String username = authorJson.get("name").getAsString(); - author = new Ticket.User(username); - } - } // Agrega el ticket a la lista - tickets.add(new Ticket(id, subject, description, status, date != null ? date.toString() : "", author)); + tickets.add(new Ticket(id, subject, description, status, date != null ? date.toString() : "")); } } else { System.out.println("La respuesta JSON no contiene la clave 'issues'"); @@ -338,8 +329,8 @@ public class RedmineClient { } - public Map getTicketTypes() { - Map ticketTypes = new HashMap<>(); + public Map getTicketTypes() { + Map ticketTypes = new HashMap<>(); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(REDMINE_URL + "/trackers.json")) @@ -361,18 +352,41 @@ public class RedmineClient { } - private Map parseTicketTypes(String json) { - Map ticketMap = new HashMap<>(); + private Map parseTicketTypes(String json) { + Map ticketMap = new HashMap<>(); JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject(); jsonObject.getAsJsonArray("trackers").forEach(trackerElement -> { JsonObject tracker = trackerElement.getAsJsonObject(); String name = tracker.get("name").getAsString(); String id = tracker.get("id").getAsString(); - ticketMap.put(name, id); + String description = tracker.has("description") && !tracker.get("description").isJsonNull() ? tracker.get("description").getAsString() : "Descripcion no disponible"; + ticketMap.put(name, new TicketType(id, description)); }); return ticketMap; } + public static class TicketType { + private final String id; + private final String description; + + public TicketType(String id, String description) { + this.id = id; + this.description = description; + } + + public String getId() { + return id; + } + + public String getDescription() { + return description; + } + + public String getTicketTypeDescription(String type, Map ticketTypes) { + return ticketTypes.getOrDefault(type, new TicketType("N/A", "Descripción no disponible para este tipo de ticket")).getDescription(); + } + } + public static RedmineUser createRedmineUser(String username, String firstname, String lastname, String mail) { HttpClient client = HttpClient.newHttpClient(); diff --git a/src/main/java/mx/gob/jumapacelaya/models/Ticket.java b/src/main/java/mx/gob/jumapacelaya/models/Ticket.java index 2c909db..dc364dc 100644 --- a/src/main/java/mx/gob/jumapacelaya/models/Ticket.java +++ b/src/main/java/mx/gob/jumapacelaya/models/Ticket.java @@ -16,7 +16,7 @@ public class Ticket { private User author; - public Ticket(int id, String subject, String description, String status, String dateCreate, User author) { + public Ticket(int id, String subject, String description, String status, String dateCreate) { this.id = id; this.subject = subject; this.description = description; diff --git a/src/main/java/mx/gob/jumapacelaya/views/crearnuevoticket/CrearnuevoTicketView.java b/src/main/java/mx/gob/jumapacelaya/views/crearnuevoticket/CrearnuevoTicketView.java index 009fab9..3457987 100644 --- a/src/main/java/mx/gob/jumapacelaya/views/crearnuevoticket/CrearnuevoTicketView.java +++ b/src/main/java/mx/gob/jumapacelaya/views/crearnuevoticket/CrearnuevoTicketView.java @@ -7,6 +7,7 @@ import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.button.ButtonVariant; import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.html.H2; +import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.notification.NotificationVariant; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; @@ -43,12 +44,14 @@ public class CrearnuevoTicketView extends VerticalLayout { private MultiFileMemoryBuffer buffer; private Upload uploadFile; private String selectedTrackerId; + private Span ticketTypeDesc; public CrearnuevoTicketView(RedmineClient api, UserService service) { this.api = api; this.userService = service; this.buffer = new MultiFileMemoryBuffer(); this.uploadFile = createUploadComponent(); + this.ticketTypeDesc = new Span(); RedmineUser user = userService.getRedmineUser(); @@ -66,7 +69,7 @@ public class CrearnuevoTicketView extends VerticalLayout { Button createButton = new Button("Enviar ticket", event -> handleCreateButton(user, tipoTickets, asunto, descripcion)); createButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY, ButtonVariant.LUMO_LARGE); - VerticalLayout fieldsLayout = new VerticalLayout(descripcion, uploadFile); + VerticalLayout fieldsLayout = new VerticalLayout(descripcion, uploadFile, ticketTypeDesc); fieldsLayout.setAlignItems(Alignment.CENTER); HorizontalLayout firstFields = new HorizontalLayout(tipoTickets, asunto); VerticalLayout buttonLayout = new VerticalLayout(createButton); @@ -110,7 +113,7 @@ public class CrearnuevoTicketView extends VerticalLayout { ComboBox tipoTickets = new ComboBox<>("Tipo de ticket"); tipoTickets.setPlaceholder("Seleccione un tipo de ticket"); - Map ticketTypesMap = api.getTicketTypes(); + Map ticketTypesMap = api.getTicketTypes(); Set ticketTypesSet = Set.of("Acceso/Permiso/Bajas", "Soporte de Software", "Capacitacion de Software", "Configuracion de Software", "Digitalizacion GIS", "Documento", "Funcionalidad", "Reporte", "Soporte o Mantenimiento"); @@ -118,7 +121,13 @@ public class CrearnuevoTicketView extends VerticalLayout { .filter(ticketTypesSet::contains) .collect(Collectors.toList()); tipoTickets.setItems(filteredTicketTypes); - tipoTickets.addValueChangeListener(event -> selectedTrackerId = ticketTypesMap.get(event.getValue())); + + tipoTickets.addValueChangeListener(event -> { + String selectedType = event.getValue(); + RedmineClient.TicketType ticketType = ticketTypesMap.get(selectedType); + ticketTypeDesc.setText(ticketType != null ? ticketType.getDescription() : "Descripcion no disponible para este tipo de ticket"); + selectedTrackerId = ticketType != null ? ticketType.getId() : null; + }); return tipoTickets; } @@ -135,6 +144,7 @@ public class CrearnuevoTicketView extends VerticalLayout { return textArea; } + private void handleFileUpload(String fileName) { try (InputStream inputStream = buffer.getInputStream(fileName); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { @@ -218,6 +228,7 @@ public class CrearnuevoTicketView extends VerticalLayout { asunto.clear(); descripcion.clear(); tipoTickets.clear(); + ticketTypeDesc.setText(""); asunto.setInvalid(false); descripcion.setInvalid(false); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f80ff87..a490922 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,13 +18,13 @@ spring.ldap.password=Dr3na%134$4guA ########PRODUCTIVO################################# -redmine.url=https://proyman.jumapacelaya.gob.mx/ -redmine.api_key=9cc9e89cbbf08a6252045d56bd3d3ffec90adbad +#redmine.url=https://proyman.jumapacelaya.gob.mx/ +#redmine.api_key=9cc9e89cbbf08a6252045d56bd3d3ffec90adbad ########LOCAL###################################### -#redmine.url=http://localhost:3000 -#redmine.api_key=9cc9e89cbbf08a6252045d56bd3d3ffec90adbad +redmine.url=http://localhost:3000 +redmine.api_key=9cc9e89cbbf08a6252045d56bd3d3ffec90adbad ###CONFIGURACION DEL TAMANO MAXIMO PERMITIDO PARA ARCHIVOS###