ORVE WS (Dynamic) (12) Defiining the control tables
0. Introduction
Our goals are:
- Retrieving the INPUT records (Received from other administrations)
- Retrieving the OUTPUT records (Sent to other administrations)
To retrieve any record the WS requires at least these parameters
1. State (Estado). For INPUT these are the available states:
- RPC: Received but confirmation pending
- RR: Received and rejected
- RC: Received and confirmed
- RREEN: Received and resent
For OUTPUT:
- PE: Pending delivery
- EPC: Sent but confirmation is pending
- ER: Sent but rejected
- EC: Sent and confirmed
3. Date to in the same format.
The system knows who is our administration (Oficina or Office)
1. Additional tables or entities
We need to have control of:
- "Ids" that can identify the records and if the records have been saved and passed to the Gexflow application (an application that controls our records). To get the "Ids", the WS operation obtenerIdentificadores. An entity named Item will be created
- To have some control in annexes, it is convenient to have an entity Annex.
- It is important to have an entity to keep control of the last date we have successfully got the ids. This entity is called Control
package ximodante.orve.jpa; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; //import javax.persistence.UniqueConstraint; import javax.validation.constraints.Size; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; @Entity @Table(name = "ITEM", schema = "ORVE" // ,uniqueConstraints = @UniqueConstraint(columnNames = { "item" }) // ,indexes = {@Index (name = "idx_usuari_entityadm", columnList = "usuari, entityAdm")} ) //@Audited @ToString @NoArgsConstructor public class Item { @Getter @Setter @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @Getter @Setter @Column(unique=true) private int item; /** * The state (estado) of a record: PE, EC, RC .. * and is got as the parameter passed to the Ws operation obtererIdentificadores */ @Getter @Setter @Size(max = 10) private String estado; @Getter @Setter @Size(max = 25) private String numRegistro; /** * 0: Pending * 1: Persisted in h2 DB * 2: Persisted the SicreS 3.0 record * 3: Included in Gexflow by WS * 4: Included all annexes in Gexflow by WS * 5: No need to be persisted in Gexflow (a person that addresses to another administration) * 6: Error in WS Gexflow (DNI not correct, CP not correct ...) * 7: */ @Getter @Setter private int fase; /** * Official Record date */ @Getter @Setter @Size(max = 25) private String fecha; @Getter @Setter @Size(max = 64) private String notes; //Year of record in Gexflow @Getter @Setter @Size(max=4) private int gxYear=-1; //Record Number in Gexflow @Getter @Setter @Size(max=4) private int gxNumReg=-1; }
For the Annex entity, the code is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | package ximodante.orve.jpa; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.OneToOne; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import ximodante.sicres.multiclassjpa.DeAnexo; @Entity @Table(name = "ANNEX", schema = "ORVE" // ,uniqueConstraints = @UniqueConstraint(columnNames = { "item" }) // ,indexes = {@Index (name = "idx_usuari_entityadm", columnList = "usuari, entityAdm")} ) //@Audited @ToString @NoArgsConstructor public class Annex { @Getter @Setter @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @Getter @Setter private int item=-1; @Getter @Setter @OneToOne(cascade = CascadeType.ALL) // See https://stackoverflow.com/a/48876303/7704658 private DeAnexo annex=null; /** * 0: Pending * 1: Persisted the Sicre 3.0 record * 2: Persisted in h2 DB * 3: Included in Gexflow by WS * 5: No need to be persisted in Gexflow (a person that addresses to another administration) * 6: Error in WS Gexflow ( ...) * 7: */ @Getter @Setter private int fase=0; //Doc Id given by Gexflow @Getter @Setter private int idGexflow=-1; } |
And the code for Control entity:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | package ximodante.orve.jpa; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.validation.constraints.Size; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; @Entity @Table(name = "CONTROL", schema = "ORVE" // ,uniqueConstraints = @UniqueConstraint(columnNames = { "item" }) // ,indexes = {@Index (name = "idx_usuari_entityadm", columnList = "usuari, entityAdm")} ) //@Audited @ToString @NoArgsConstructor public class Control { @Getter @Setter @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @Getter @Setter @Size(max = 25) private String fechaDesde; @Getter @Setter @Size(max = 128) private String notes; } |
3. Steps
1. For each of the states of the field Control.codigos, a call to the WS operation obtenerIdentificadores is made. We need also the dates from and to.2. If the no errors are present, all the returned "ids" are persisted in the Item entity with a state "1".
3. Once, all "ids" have been persisted in the table ITEM, it's time to update the date from (fechaDesde) of the Table CONTROL The value assigned is the date and time of the beginning of the first call to the WS.
4. Now, let's query for all the "ids" that are in state "1" and retrieve the records using the WS operation "obtenerRegistro" as we know the "id" of the record.
5. Once the record is obtained, it's information is unwrapped to a FicheroIntercambioSICRES3 class and persisted.
6. The Item.fase attribute is assigned the value "2" and the attributes Item.numRegistro and Item.fecha are assigned too.
7. After the records have been persisted, then its time to use the Gexflow Web Services to persist records and the attached files.
8. The Item.fase attribute is assigned the value "3"
9. In some circumstances, we may be not interested in persisting a record to Gexflow. In this case the Item.fase attribute is assigned the value "4"
Take into account that transactions should be used for database consistency. Some conversion of information is needed to fill Item and Control entities and to get the parameters for calling the Gexflow WS.
3. Creating the ITEM and CONTROL tables
Just let's execute the JPATest class as we saw in a previous post.
The result of the execution is
1 2 3 4 | Hibernate: create table ORVE.CONTROL (id bigint generated by default as identity, codigos varchar(255), entidad varchar(255), fechaDesde varchar(255), notes varchar(255), unidad varchar(255), primary key (id)) Hibernate: create table ORVE.ITEM (id bigint generated by default as identity, estado varchar(255), fase integer not null, fecha varchar(255), item integer not null, notes varchar(255), numRegistro varchar(255), primary key (id)) Hibernate: alter table ORVE.ITEM drop constraint if exists UK7kcs8381qfxrn504cobrbuqn7 Hibernate: alter table ORVE.ITEM add constraint UK7kcs8381qfxrn504cobrbuqn7 unique (item) |
Comments
Post a Comment