Skip to content

Commit

Permalink
OK-591 Handle info as String
Browse files Browse the repository at this point in the history
  • Loading branch information
msiukola committed Oct 2, 2024
1 parent 6f4b14b commit 6335ba6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public String createNextSiirtotiedosto() {
logger.info("New process: {}", uusi);

try {
siirtotiedostoServiceImpl.createSiirtotiedostot(LocalDateTime.now(), LocalDateTime.now());
// Todo, add entitycounts
String resultInfo =
siirtotiedostoServiceImpl.createSiirtotiedostot(LocalDateTime.now(), LocalDateTime.now());
uusi.setSuccess(true);
uusi.setInfo(resultInfo);
uusi.setRunEnd(OffsetDateTime.now());
siirtotiedostoProsessiRepositoryImpl.persist(uusi);
} catch (Exception e) {
Expand All @@ -44,7 +45,7 @@ public String createNextSiirtotiedosto() {
e);
uusi.setErrorMessage(e.getMessage());
uusi.setSuccess(false);
uusi.setInfo(null);
uusi.setInfo("{}");
uusi.setRunEnd(OffsetDateTime.now());
siirtotiedostoProsessiRepositoryImpl.persist(uusi);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package fi.vm.sade.service.valintaperusteet.ovara.ajastus;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.sql.Timestamp;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Type;

@Entity
@Table(name = "siirtotiedosto", schema = "public")
public class SiirtotiedostoProsessi {
@Id
@Column(name = "execution_uuid")
Expand All @@ -32,8 +26,7 @@ public class SiirtotiedostoProsessi {
private OffsetDateTime runEnd;

@Column(name = "info")
@Type(type = "com.vladmihalcea.hibernate.type.json.JsonNodeBinaryType")
private JsonNode info;
private String info;

@Column(name = "success")
private Boolean success;
Expand All @@ -49,7 +42,7 @@ public SiirtotiedostoProsessi(
OffsetDateTime windodwEnd,
OffsetDateTime runStart,
OffsetDateTime runEnd,
JsonNode info,
String info,
Boolean success,
String errorMessage) {
this.executionUuid = executionUuid;
Expand All @@ -72,12 +65,7 @@ public SiirtotiedostoProsessi(Object[] result) {
this.windowEnd = ((Timestamp) result[2]).toInstant().atOffset(ZoneOffset.UTC);
this.runStart = ((Timestamp) result[3]).toInstant().atOffset(ZoneOffset.UTC);
this.runEnd = ((Timestamp) result[4]).toInstant().atOffset(ZoneOffset.UTC);
try {
this.info = mapper.readTree((String) result[5]);
} catch (Exception e) {
System.out.println("Ei saatu jsonia parsittua");
e.printStackTrace();
}
this.info = (String) result[5];
this.success = (Boolean) result[6];
this.errorMessage = (String) result[7];
}
Expand All @@ -100,11 +88,11 @@ public void setSuccess(Boolean success) {
this.success = success;
}

public JsonNode getInfo() {
public String getInfo() {
return info;
}

public void setInfo(JsonNode info) {
public void setInfo(String info) {
this.info = info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SiirtotiedostoProsessi findLatestSuccessful() {
@Override
public void persist(SiirtotiedostoProsessi sp) {
System.out.println("Persisting: " + sp);
String infoStr = sp.getInfo() != null ? sp.getInfo().toString() : "{}";
String infoStr = sp.getInfo() != null ? sp.getInfo() : "{}";
this.jdbcTemplate.update(
"insert into siirtotiedosto (execution_uuid, window_start, window_end, run_start, run_end, info, success, error_message) "
+ "values (?::uuid, ?::timestamptz, ?::timestamptz, ?::timestamptz, ?::timestamptz, ?::jsonb, ?, ?)",
Expand Down

0 comments on commit 6335ba6

Please sign in to comment.