Virtual Checker built with Angular + Firebase + Flutter + JakartaEE + Microprofile + PostgreSQL on Azure - Parte 4






This post is about the inspector backend,  it will be deployed in our payara server.


The source code is on GitHub: https://github.com/joedayz/ws-inspector


1. This project will be using Jakarta EE, Microprofile, Blaze Persistence, Apache DeltaSpike, Lombok and Firebase-Admin as principal dependencies. See the pom.xml in GitHub.

2. In webapp/WEB-INF we have the beans.xml, glassfish-resource.xml and glassfish-web.xml:


beans.xml


glassfish-web.xml (context root)


glassfish-resources.xml




3. We will use the publicKey.pem generated in our first post to validate if the user has been authenticated or has the authorization to execute some method. 



4. firebase-sdk.json is the file downloaded from firebase.com mandatory to interact with our firebase account.


5. persistence.xml shows the JDBC resource configured in our payara server.





6. apache-deltaspike.properties is configured according to transaction type: JTA.

globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy = org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy


7.  The model will be according to the database model explained in my last post.

For example it is the configuration for the table "asegurado" in the "core" scheme.

@Getter
@Setter
@Entity
@Table(name = "asegurado", schema = "core")
public class AseguradoModel {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_asegurado")
private Long idAsegurado;

@Column(name = "nombre")
private String nombre;

@Column(name = "apellido_paterno")
private String apellidoPaterno;

@Column(name = "apellido_materno")
private String apellidoMaterno;

@Column(name = "id_ct_tipo_documento")
private String idCtTipoDocumento;

@Column(name = "numero_documento")
private String numeroDocumento;

@Column(name = "direccion")
private String direccion;

@Column(name = "id_distrito")
private Integer idDistrito;

@Column(name = "telefono_movil")
private String telefonoMovil;

@Column(name = "telefono_fijo")
private String telefonoFijo;

@Column(name = "correo")
private String correo;

@Column(name = "usuario_creacion", updatable = false)
private String usuarioCreacion;

@Column(name = "usuario_modificacion")
private String usuarioModificacion;

@Column(name = "fecha_creacion", updatable = false)
private LocalDateTime fechaCreacion;

@Column(name = "fecha_modificacion")
private LocalDateTime fechaModificacion;
}

It is the table "inspeccion" in the "inspeccion" scheme:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "inspeccion", schema = "inspeccion")
public class InspeccionModel {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_inspeccion")
private Long idInspeccion;

@Column(name = "id_vehiculo_asegurado")
private Integer idVehiculoAsegurado;

@Column(name = "codigo_inspeccion")
private String codigoInspeccion;

@Column(name = "codigo_inspeccion_legall")
private String codigoInspeccionLegall;

@Column(name = "id_ct_estado_inspeccion")
private String estado;

@Column(name = "id_tramite")
private Integer idTramite;

@Column(name = "id_distrito")
private String idDistrito;

@Column(name = "id_empleado_inspector")
private Integer idEmpleadoInspector;

@Column(name = "observaciones")
private String observaciones;

@Column(name = "latitude")
private Double latitude;

@Column(name = "longitude")
private Double longitude;

@Column(name = "fecha_termino")
private LocalDateTime fechaTermino;

@Column(name = "direccion_inspeccion")
private String direccionInspeccion;

@Column(name = "usuario_creacion", updatable = false)
private String usuarioCreacion;

@Column(name = "fecha_creacion", updatable = false)
private LocalDateTime fechaCreacion;

@Column(name = "usuario_modificacion")
private String usuarioModificacion;

@Column(name = "fecha_modificacion")
private LocalDateTime fechaModificacion;
}

If you need use some view (vw_inspecciones) the declaration is similar:


@Getter
@Setter
@Entity
@Table(name = "vw_inspecciones", schema = "public")
public class InspeccionView {

@Id
@Column(name = "id_informe")
private Long id;

@Column(name = "id_inspeccion")
private Long idInspeccion;

@Column(name = "codigo_inspeccion")
private String codigoInspeccion;

@Column(name = "codigo_inspeccion_legall")
private String codigoInspeccionLegall;

@Column(name = "observaciones")
private String observaciones;

@Column(name = "informe_fecha_programada")
private LocalDateTime fechaProgramada;

@Column(name = "id_distrito")
private String idDistrito;

@Column(name = "id_empleado_inspector")
private String idEmpleadoInspector;

@Column(name = "usuario_creacion")
private String usuarioCreacion;

@Column(name = "id_tramite")
private Integer idTramite;

@Column(name = "nro_tramite_compania_seguro")
private String numeroTramite;

@Column(name = "contacto")
private String contacto;

@Column(name = "placa")
private String placa;

@Column(name = "id_ct_motivo")
private String idCtMotivo;

@Column(name = "id_estado")
private String idEstado;

@Column(name = "estado")
private String estado;

@Column(name = "contratante_nombre")
private String contratanteNombre;

@Column(name = "contratante_razon_social")
private String contratanteRazonSocial;

@Column(name = "asegurado_nombre")
private String nombreApellido;

@Column(name = "telefono_fijo")
private String telefonoFijo;

@Column(name = "telefono_movil")
private String telefono;

@Column(name = "correo")
private String correo;

@Column(name = "direccion")
private String direccion;

@Column(name = "id_marca")
private String idMarca;

@Column(name = "marca")
private String marca;

@Column(name = "id_modelo")
private String idModelo;

@Column(name = "modelo")
private String modelo;

@Column(name = "id_vehiculo_asegurado")
private String idVehiculoAsegurado;

@Column(name = "id_asegurado")
private String idAsegurado;

public String getEstado() {
switch (estado) {
case "Pendiente":
return Constantes.ON_HOLD;
case "Digitado":
return Constantes.AVAILABLE;
case "Terminado":
return Constantes.COMPLETE;
default:
return estado;
}
}


}

This view exists in the database in the public scheme:


That's a short overview of our model. You can see the other classes in this package:




8. The repository layer is very easy if you use the deltaspike  data module:

- For example, you can declare an interface as repository and extends of some interface as EntityRepository that will generate the CRUD methods.  



These are the methods that will be generated thanks to EntityRepository:


- You can generate your own finders:





- Fortunately for us there is an integration between blaze and deltaspike to use views as entities, I used this integration to work with the view "vw_inspecciones" declared in our entity InspeccionView.


9. Before looking at our service layer. We see the producers created for the project in the config package:


Log Producer


It then can be injected in some class to produce log in this way:



FirebaseConfig to work with our firebase account:



Note: It use the file firebase-sdk.json that must be in src/main/resources.

EntityManagerProducer where we use the reference of our persistence unit ("legall_pu"):



CriteriaBuilderFactoryProducer uses blaze-persistence to have a rich criteria API for JPA providers:


EntityViewManagerProducer use the BlazePersistence - Entity View ModuleBlaze Persistence entity views try to solve these and many more problems a developer faces when having to implement efficient model mapping in a JPA application. It allows to define DTOs as interfaces and provides the mappings to the JPA model via annotations. It favors convention-over-configuration by providing smart defaults that allow to omit most mappings. By applying DTOs to a query builder through the ObjectBuilder extension point it is possible to separate query logic from the projections while still enjoying high performance queries.


Finally CorsFilter to evict problems of CORS with our frontend:



10. Now is the moment of see our JAXRSConfiguration where will be using MicroProfile JWT



This is very simple and minimalist. I love that.


- Our controllers depend on the roles allowed. 


- We have some DTOs for request and response:






11. In our service layer we use the repositories and create the business logic:




In some cases is necessary the sincronization with firebase, for example for a re-schedule of inspection:

 




It backend will be used by our frontend and mobile application in the next articles. 


Enjoy!

Joe





Share:

Virtual Checker built with Angular + Firebase + Flutter + JakartaEE + Microprofile + PostgreSQL on Azure - Parte 3

 

In this post, we will be discussing the database model.  We have 4 schemas: admin, core, inspection and public.


Admin Scheme


Core Scheme


Inspeccion Scheme


Public scheme



This is the view in my DataGrip:


In the next article, we will be showing the backend of our solution.

Enjoy!

Joe






 



Share:

The Call for Papers for TDC 2021 Future International

 




The Call for Papers for TDC 2021 Future International is going to be open until October 15th. Submit your talks now. I am part of the APIs and Microservices track | Technical Committee. https://lnkd.in/etEFqM5P

Animate a enviar tu propuesta para el TDC 2021 Future International y aumenta tu networking y reputación mostrando tu experiencia. Soy parte del comité técnico del track APIs y Microservicios. https://lnkd.in/etEFqM5P#thedeveloperconference #perujug #microservices #apis

Enjoy!

Joe
Share:

Virtual Checker built with Angular + Firebase + Flutter + JakartaEE + Microprofile + PostgreSQL on Azure - Parte 2

 




In the last post, we start with the explanation of our authentication/authorization server that provides JWT Tokens. 

In this post, we start to build the first version of our angular application. 

Source Code: https://github.com/joedayz/web-inspector (tag v1.0)


1. Create the angular application with Angular CLI

npm install -g @angular/cli

2. Add these dependencies: Angular Material, Angular JWT, Angular Font Awesome, Angular2 Test Mask, SweetAlert2.

3. In Assets we have some fonts and images for our web admin:


4. In environments configure the principal PATHS:



Note:  localhost must be changed with the domain name or IP of your server.

 

5. The routing shows the initial navigation: 



app-routing.module.ts

The GuardService makes sure that a person necessarily always logs in.


6. Angular Material components are declared in a unique module.  It permits to add more easily in other modules. 


7. The main Dashboard has a drop-down menu, and toolbar and will serve to display the content in the central part.





The result is:



Note: We need to log in for access to the dashboard. It cannot be accessed directly because exists a GuardService.

8. Finally the Login:



The LoginService has the logic that calls the authentication service to get one access token if the username and password is a valid user in our Azure PostgreSQL. 


The LoginService shows how the data is sent to the authentication service. The Token returned is saved in the session storage.

endpoint = `${environment.AUTH_ENDPOINT}/login`;    


And that's all, for now. In the next post, we show an advanced version of its web admin.

Enjoy!


Joe










Share: