Search in sources :

Example 41 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class UserApi method getUserByName.

/**
 * Get user by user name
 *
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid username supplied
 * <p><b>404</b> - User not found
 * @param username The name that needs to be fetched. Use user1 for testing.
 * @return User
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public User getUserByName(String username) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'username' is set
    if (username == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'username' when calling getUserByName");
    }
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("username", username);
    String path = UriComponentsBuilder.fromPath("/user/{username}").buildAndExpand(uriVariables).toUriString();
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    final String[] accepts = { "application/xml", "application/json" };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = {};
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
    String[] authNames = new String[] {};
    ParameterizedTypeReference<User> returnType = new ParameterizedTypeReference<User>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) User(com.baeldung.petstore.client.model.User) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType)

Example 42 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class UserApi method createUsersWithArrayInput.

/**
 * Creates list of users with given input array
 *
 * <p><b>0</b> - successful operation
 * @param body List of user object
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public void createUsersWithArrayInput(List<User> body) throws RestClientException {
    Object postBody = body;
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUsersWithArrayInput");
    }
    String path = UriComponentsBuilder.fromPath("/user/createWithArray").build().toUriString();
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    final String[] accepts = { "application/xml", "application/json" };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = {};
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
    String[] authNames = new String[] {};
    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {
    };
    apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType)

Example 43 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class UserApi method loginUser.

/**
 * Logs user into the system
 *
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid username/password supplied
 * @param username The user name for login
 * @param password The password for login in clear text
 * @return String
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public String loginUser(String username, String password) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'username' is set
    if (username == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'username' when calling loginUser");
    }
    // verify the required parameter 'password' is set
    if (password == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'password' when calling loginUser");
    }
    String path = UriComponentsBuilder.fromPath("/user/login").build().toUriString();
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    queryParams.putAll(apiClient.parameterToMultiValueMap(null, "username", username));
    queryParams.putAll(apiClient.parameterToMultiValueMap(null, "password", password));
    final String[] accepts = { "application/xml", "application/json" };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = {};
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
    String[] authNames = new String[] {};
    ParameterizedTypeReference<String> returnType = new ParameterizedTypeReference<String>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType)

Example 44 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class UserApi method logoutUser.

/**
 * Logs out current logged in user session
 *
 * <p><b>0</b> - successful operation
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public void logoutUser() throws RestClientException {
    Object postBody = null;
    String path = UriComponentsBuilder.fromPath("/user/logout").build().toUriString();
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    final String[] accepts = { "application/xml", "application/json" };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = {};
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
    String[] authNames = new String[] {};
    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {
    };
    apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType)

Example 45 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project sic by belluccifranco.

the class PuntoDeVentaGUI method btn_ContinuarActionPerformed.

// GEN-LAST:event_txt_Decuento_porcentajeActionPerformed
private void btn_ContinuarActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_btn_ContinuarActionPerformed
    if (renglones.isEmpty()) {
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_factura_sin_renglones"), "Error", JOptionPane.ERROR_MESSAGE);
    } else {
        this.calcularResultados();
        try {
            if (!cmb_TipoComprobante.getSelectedItem().equals(TipoDeComprobante.PEDIDO)) {
                List<RenglonFactura> productosFaltantes = new ArrayList();
                renglones.stream().filter(r -> {
                    String uri = "/productos/" + r.getId_ProductoItem() + "/stock/disponibilidad?cantidad=" + r.getCantidad();
                    return (!RestClient.getRestTemplate().getForObject(uri, boolean.class));
                }).forEachOrdered(r -> productosFaltantes.add(r));
                if (productosFaltantes.isEmpty()) {
                    CerrarVentaGUI gui_CerrarVenta = new CerrarVentaGUI(this, true);
                    gui_CerrarVenta.setVisible(true);
                    if (gui_CerrarVenta.isExito()) {
                        this.limpiarYRecargarComponentes();
                    }
                } else {
                    ProductosFaltantesGUI gui_ProductosFaltantes = new ProductosFaltantesGUI(productosFaltantes);
                    gui_ProductosFaltantes.setModal(true);
                    gui_ProductosFaltantes.setLocationRelativeTo(this);
                    gui_ProductosFaltantes.setVisible(true);
                }
            } else {
                // El Id es 0 cuando, se genera un pedido desde el punto de venta entrando por el botón nuevo de administrar pedidos.
                if (pedido == null || pedido.getId_Pedido() == 0) {
                    this.construirPedido();
                }
                PaginaRespuestaRest<Pedido> response = RestClient.getRestTemplate().exchange("/pedidos/busqueda/criteria?" + "idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa() + "&nroPedido=" + pedido.getNroPedido(), HttpMethod.GET, null, new ParameterizedTypeReference<PaginaRespuestaRest<Pedido>>() {
                }).getBody();
                List<Pedido> pedidos = response.getContent();
                if (pedidos.isEmpty()) {
                    Pedido p = RestClient.getRestTemplate().postForObject("/pedidos", pedido, Pedido.class);
                    this.lanzarReportePedido(p);
                    this.limpiarYRecargarComponentes();
                } else if ((pedido.getEstado() == EstadoPedido.ABIERTO || pedido.getEstado() == null) && modificarPedido == true) {
                    this.actualizarPedido(pedido);
                    JOptionPane.showMessageDialog(this, "El pedido se actualizó correctamente.", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                }
            }
        } catch (RestClientResponseException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } catch (ResourceAccessException ex) {
            LOGGER.error(ex.getMessage());
            JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : TipoDeComprobante(sic.modelo.TipoDeComprobante) RenderTabla(sic.util.RenderTabla) Arrays(java.util.Arrays) RestClient(sic.RestClient) RenglonPedido(sic.modelo.RenglonPedido) UsuarioActivo(sic.modelo.UsuarioActivo) JDialog(javax.swing.JDialog) FormaDePago(sic.modelo.FormaDePago) Date(java.util.Date) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) LoggerFactory(org.slf4j.LoggerFactory) Utilidades(sic.util.Utilidades) Transportista(sic.modelo.Transportista) Point(java.awt.Point) KeyAdapter(java.awt.event.KeyAdapter) RenglonFactura(sic.modelo.RenglonFactura) Rol(sic.modelo.Rol) ArrayList(java.util.ArrayList) Movimiento(sic.modelo.Movimiento) SwingUtilities(javax.swing.SwingUtilities) ResourceBundle(java.util.ResourceBundle) RestClientResponseException(org.springframework.web.client.RestClientResponseException) Pedido(sic.modelo.Pedido) Empresa(sic.modelo.Empresa) ImageIcon(javax.swing.ImageIcon) Cliente(sic.modelo.Cliente) ParseException(java.text.ParseException) ConfiguracionDelSistema(sic.modelo.ConfiguracionDelSistema) Producto(sic.modelo.Producto) Desktop(java.awt.Desktop) Logger(org.slf4j.Logger) Files(java.nio.file.Files) EstadoPedido(sic.modelo.EstadoPedido) FacturaVenta(sic.modelo.FacturaVenta) HttpMethod(org.springframework.http.HttpMethod) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) KeyEvent(java.awt.event.KeyEvent) JOptionPane(javax.swing.JOptionPane) File(java.io.File) List(java.util.List) JTable(javax.swing.JTable) EmpresaActiva(sic.modelo.EmpresaActiva) PaginaRespuestaRest(sic.modelo.PaginaRespuestaRest) RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) ArrayList(java.util.ArrayList) ResourceAccessException(org.springframework.web.client.ResourceAccessException) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) RenglonFactura(sic.modelo.RenglonFactura) RestClientResponseException(org.springframework.web.client.RestClientResponseException)

Aggregations

ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)57 MediaType (org.springframework.http.MediaType)29 HttpHeaders (org.springframework.http.HttpHeaders)25 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)22 List (java.util.List)20 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)18 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)12 URI (java.net.URI)11 Test (org.junit.Test)10 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)8 URISyntaxException (java.net.URISyntaxException)7 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)7 DataBuffer (org.springframework.core.io.buffer.DataBuffer)6 HttpEntity (org.springframework.http.HttpEntity)6 Resources (org.springframework.hateoas.Resources)5 Traverson (org.springframework.hateoas.client.Traverson)5 IOException (java.io.IOException)4 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)4