|
|
@ -26,7 +26,6 @@ import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import static org.atmosphere.annotation.AnnotationUtil.logger; |
|
|
@ -36,27 +35,27 @@ import static org.atmosphere.annotation.AnnotationUtil.logger; |
|
|
|
@PageTitle("Nuevo ticket") |
|
|
|
public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
|
|
|
|
private final RedmineClient api; // Definir el campo final para el RedmineClient |
|
|
|
private final RedmineClient api; |
|
|
|
private final UserService userService; |
|
|
|
private MemoryBuffer buffer; |
|
|
|
private Upload uploadFile; |
|
|
|
private String fileUploadToken; |
|
|
|
private String selectedTrackerId; |
|
|
|
|
|
|
|
// Inyectar el RedmineClient a través del constructor |
|
|
|
public CrearnuevoTicketView(RedmineClient api, UserService service) { |
|
|
|
this.api = api; // Asignar el RedmineClient inyectado al campo de la clase |
|
|
|
this.api = api; |
|
|
|
this.userService = service; |
|
|
|
|
|
|
|
// Obtener la URL de Redmine, apiKey y username desde las propiedades del servidor |
|
|
|
RedmineUser user = userService.getRedmineUser(); |
|
|
|
//String apiKey = (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("apiKey"); |
|
|
|
//String username = (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("username"); |
|
|
|
|
|
|
|
|
|
|
|
// Combo de los tipos de tickets |
|
|
|
// ComboBox para los tipos de tickets |
|
|
|
ComboBox<String> tipoTickets = new ComboBox<>("Tipo de ticket"); |
|
|
|
List<String> types = api.getTicketTypes(); // Llamar al método sin pasar apiKey |
|
|
|
tipoTickets.setItems(types); |
|
|
|
Map<String, String> ticketTypesMap = api.getTicketTypes(); |
|
|
|
tipoTickets.setItems(ticketTypesMap.keySet()); |
|
|
|
tipoTickets.addValueChangeListener(event -> { |
|
|
|
String selectedName = event.getValue(); |
|
|
|
selectedTrackerId = ticketTypesMap.get(selectedName); |
|
|
|
}); |
|
|
|
|
|
|
|
// Campo de texto para el asunto |
|
|
|
TextField asunto = new TextField("Asunto"); |
|
|
@ -80,7 +79,6 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
|
|
|
|
if (fileName != null && inputStream != null) { |
|
|
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { |
|
|
|
// Lee los bytes del archivo |
|
|
|
byte[] bufferArray = new byte[1024]; |
|
|
|
int bytesRead; |
|
|
|
while ((bytesRead = inputStream.read(bufferArray)) != -1) { |
|
|
@ -112,10 +110,18 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Obtener el tipo de ticket seleccionado |
|
|
|
if (selectedTrackerId == null) { |
|
|
|
Notification.show("Por favor seleccione un tipo de ticket.", 3000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, String> issueDetails = new HashMap<>(); |
|
|
|
issueDetails.put("project_id", "soporte-tecnico-t-i"); |
|
|
|
issueDetails.put("subject", asunto.getValue()); |
|
|
|
issueDetails.put("description", descripcion.getValue()); |
|
|
|
issueDetails.put("tracker_id", selectedTrackerId); // Añadir el tracker_id |
|
|
|
|
|
|
|
String fileUploadToken = null; |
|
|
|
String fileName = null; |
|
|
@ -146,7 +152,6 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
buttonLayout.setMargin(true); |
|
|
|
|
|
|
|
add(new H2("Crear nuevo ticket"), firstFields, fieldsLayout, buttonLayout); |
|
|
|
//this.userService = userService; |
|
|
|
} |
|
|
|
|
|
|
|
private void handleResponse(String response, TextField asunto, TextArea descripcion, ComboBox<String> tipoTickets) { |
|
|
|