Loading src/main/java/it/inaf/oats/vospace/persistence/JobDAO.java +39 −35 Original line number Diff line number Diff line Loading @@ -51,8 +51,8 @@ public class JobDAO { public void createJob(JobSummary jobSummary) { String sql = "INSERT INTO job(job_id, owner_id, job_type, phase, job_info," String sql = "INSERT INTO job(job_id, owner_id, job_type, phase, job_info," + " error_message, error_type, error_has_detail, error_detail) " + "VALUES (?, ?, ?, ?, ?, ? ,? ,? ,?)"; Loading Loading @@ -125,6 +125,9 @@ public class JobDAO { jobSummary.setPhase(ExecutionPhase.fromValue(rs.getString("phase"))); jobSummary.setJobInfo(getJobPayload(rs.getString("job_info"))); jobSummary.setResults(getResults(rs.getString("results"))); jobSummary.setCreationTime(toXMLGregorianCalendar(rs.getTimestamp("creation_time"))); jobSummary.setStartTime(toXMLGregorianCalendar(rs.getTimestamp("start_time"))); jobSummary.setEndTime(toXMLGregorianCalendar(rs.getTimestamp("end_time"))); // Retrieve error information if any String errorType = rs.getString("error_type"); Loading Loading @@ -265,15 +268,13 @@ public class JobDAO { String sql = "UPDATE job SET (phase, results"; ErrorSummary errorSummary = job.getErrorSummary(); if(errorSummary != null) { if (errorSummary != null) { sql += ", error_message, error_type, error_has_detail, error_detail"; } sql += ") = (?, ?"; if(errorSummary != null) { if (errorSummary != null) { sql += ", ?, ?, ?, ?"; } Loading @@ -283,8 +284,7 @@ public class JobDAO { int i = 0; ps.setObject(++i, job.getPhase().name(), Types.OTHER); ps.setObject(++i, toJson(job.getResults()), Types.OTHER); if(errorSummary != null) { if (errorSummary != null) { ps.setString(++i, errorSummary.getMessage()); ps.setObject(++i, errorSummary.getType().value(), Types.OTHER); ps.setBoolean(++i, errorSummary.isHasDetail()); Loading @@ -303,9 +303,9 @@ public class JobDAO { } public static XMLGregorianCalendar toXMLGregorianCalendar(Timestamp t) { XMLGregorianCalendar cal = null; if (t != null) { try { cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); LocalDateTime ldt = t.toLocalDateTime(); Loading @@ -317,10 +317,14 @@ public class JobDAO { cal.setSecond(ldt.getSecond()); cal.setFractionalSecond(new BigDecimal("0." + ldt.getNano())); // return calendar only if it has been fully initialized (otherwise // toString issue could appear); return null in other cases. return cal; } catch (Exception e) { LOG.error("Error while generating XMLGregorianCalendar", e); } } return cal; return null; } } src/test/java/it/inaf/oats/vospace/persistence/JobDAOTest.java +9 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import net.ivoa.xml.uws.v1.Jobs; import it.inaf.oats.vospace.exception.ErrorSummaryFactory; import it.inaf.oats.vospace.exception.PermissionDeniedException; import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {DataSourceConfig.class}) Loading Loading @@ -80,11 +82,16 @@ public class JobDAOTest { // uses the job retrieved from DAO to perform the update (reproduced a bug in job update) job = dao.getJob("123").get(); assertNotNull(job.getCreationTime()); assertNull(job.getStartTime()); job.setPhase(ExecutionPhase.EXECUTING); dao.updateJob(job); assertEquals(ExecutionPhase.EXECUTING, dao.getJob("123").get().getPhase()); job = dao.getJob("123").get(); assertEquals(ExecutionPhase.EXECUTING, job.getPhase()); assertNotNull(job.getStartTime()); assertNull(job.getEndTime()); } @Test Loading Loading @@ -143,6 +150,7 @@ public class JobDAOTest { JobSummary retrievedJob = retrievedJobOpt.get(); assertEquals(ExecutionPhase.ERROR, retrievedJob.getPhase()); assertTrue(areEqual(job.getErrorSummary(), retrievedJob.getErrorSummary())); assertNotNull(retrievedJob.getEndTime()); } @Test Loading Loading
src/main/java/it/inaf/oats/vospace/persistence/JobDAO.java +39 −35 Original line number Diff line number Diff line Loading @@ -51,8 +51,8 @@ public class JobDAO { public void createJob(JobSummary jobSummary) { String sql = "INSERT INTO job(job_id, owner_id, job_type, phase, job_info," String sql = "INSERT INTO job(job_id, owner_id, job_type, phase, job_info," + " error_message, error_type, error_has_detail, error_detail) " + "VALUES (?, ?, ?, ?, ?, ? ,? ,? ,?)"; Loading Loading @@ -125,6 +125,9 @@ public class JobDAO { jobSummary.setPhase(ExecutionPhase.fromValue(rs.getString("phase"))); jobSummary.setJobInfo(getJobPayload(rs.getString("job_info"))); jobSummary.setResults(getResults(rs.getString("results"))); jobSummary.setCreationTime(toXMLGregorianCalendar(rs.getTimestamp("creation_time"))); jobSummary.setStartTime(toXMLGregorianCalendar(rs.getTimestamp("start_time"))); jobSummary.setEndTime(toXMLGregorianCalendar(rs.getTimestamp("end_time"))); // Retrieve error information if any String errorType = rs.getString("error_type"); Loading Loading @@ -265,15 +268,13 @@ public class JobDAO { String sql = "UPDATE job SET (phase, results"; ErrorSummary errorSummary = job.getErrorSummary(); if(errorSummary != null) { if (errorSummary != null) { sql += ", error_message, error_type, error_has_detail, error_detail"; } sql += ") = (?, ?"; if(errorSummary != null) { if (errorSummary != null) { sql += ", ?, ?, ?, ?"; } Loading @@ -283,8 +284,7 @@ public class JobDAO { int i = 0; ps.setObject(++i, job.getPhase().name(), Types.OTHER); ps.setObject(++i, toJson(job.getResults()), Types.OTHER); if(errorSummary != null) { if (errorSummary != null) { ps.setString(++i, errorSummary.getMessage()); ps.setObject(++i, errorSummary.getType().value(), Types.OTHER); ps.setBoolean(++i, errorSummary.isHasDetail()); Loading @@ -303,9 +303,9 @@ public class JobDAO { } public static XMLGregorianCalendar toXMLGregorianCalendar(Timestamp t) { XMLGregorianCalendar cal = null; if (t != null) { try { cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); LocalDateTime ldt = t.toLocalDateTime(); Loading @@ -317,10 +317,14 @@ public class JobDAO { cal.setSecond(ldt.getSecond()); cal.setFractionalSecond(new BigDecimal("0." + ldt.getNano())); // return calendar only if it has been fully initialized (otherwise // toString issue could appear); return null in other cases. return cal; } catch (Exception e) { LOG.error("Error while generating XMLGregorianCalendar", e); } } return cal; return null; } }
src/test/java/it/inaf/oats/vospace/persistence/JobDAOTest.java +9 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import net.ivoa.xml.uws.v1.Jobs; import it.inaf.oats.vospace.exception.ErrorSummaryFactory; import it.inaf.oats.vospace.exception.PermissionDeniedException; import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {DataSourceConfig.class}) Loading Loading @@ -80,11 +82,16 @@ public class JobDAOTest { // uses the job retrieved from DAO to perform the update (reproduced a bug in job update) job = dao.getJob("123").get(); assertNotNull(job.getCreationTime()); assertNull(job.getStartTime()); job.setPhase(ExecutionPhase.EXECUTING); dao.updateJob(job); assertEquals(ExecutionPhase.EXECUTING, dao.getJob("123").get().getPhase()); job = dao.getJob("123").get(); assertEquals(ExecutionPhase.EXECUTING, job.getPhase()); assertNotNull(job.getStartTime()); assertNull(job.getEndTime()); } @Test Loading Loading @@ -143,6 +150,7 @@ public class JobDAOTest { JobSummary retrievedJob = retrievedJobOpt.get(); assertEquals(ExecutionPhase.ERROR, retrievedJob.getPhase()); assertTrue(areEqual(job.getErrorSummary(), retrievedJob.getErrorSummary())); assertNotNull(retrievedJob.getEndTime()); } @Test Loading