diff --git a/configs b/configs index 14eb3d5ff..8676bfcca 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit 14eb3d5ffab421208f131d98edbd05de135fe1a7 +Subproject commit 8676bfcca26888c391589b81e4a28d4286617d86 diff --git a/pom.xml b/pom.xml index 0e8e94a39..5e3aba9e3 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ opensrp-server-core jar - 2.12.17-SNAPSHOT + 2.12.18-SNAPSHOT opensrp-server-core OpenSRP Server Core module https://github.com/OpenSRP/opensrp-server-core diff --git a/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatus.java b/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatus.java index e083a5fe3..591118313 100644 --- a/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatus.java +++ b/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatus.java @@ -8,7 +8,7 @@ public class PlanProcessingStatus { * This field was generated by MyBatis Generator. * This field corresponds to the database column core.plan_processing_status.id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ private Long id; @@ -17,7 +17,7 @@ public class PlanProcessingStatus { * This field was generated by MyBatis Generator. * This field corresponds to the database column core.plan_processing_status.plan_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ private Long planId; @@ -26,7 +26,7 @@ public class PlanProcessingStatus { * This field was generated by MyBatis Generator. * This field corresponds to the database column core.plan_processing_status.event_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ private Long eventId; @@ -35,7 +35,7 @@ public class PlanProcessingStatus { * This field was generated by MyBatis Generator. * This field corresponds to the database column core.plan_processing_status.template_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ private Long templateId; @@ -44,7 +44,7 @@ public class PlanProcessingStatus { * This field was generated by MyBatis Generator. * This field corresponds to the database column core.plan_processing_status.status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ private Integer status; @@ -53,7 +53,7 @@ public class PlanProcessingStatus { * This field was generated by MyBatis Generator. * This field corresponds to the database column core.plan_processing_status.date_created * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ private Date dateCreated; @@ -62,17 +62,26 @@ public class PlanProcessingStatus { * This field was generated by MyBatis Generator. * This field corresponds to the database column core.plan_processing_status.date_edited * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ private Date dateEdited; + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column core.plan_processing_status.error_log + * + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 + */ + private String errorLog; + /** * This method was generated by MyBatis Generator. * This method returns the value of the database column core.plan_processing_status.id * * @return the value of core.plan_processing_status.id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Long getId() { return id; @@ -84,7 +93,7 @@ public Long getId() { * * @param id the value for core.plan_processing_status.id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setId(Long id) { this.id = id; @@ -96,7 +105,7 @@ public void setId(Long id) { * * @return the value of core.plan_processing_status.plan_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Long getPlanId() { return planId; @@ -108,7 +117,7 @@ public Long getPlanId() { * * @param planId the value for core.plan_processing_status.plan_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setPlanId(Long planId) { this.planId = planId; @@ -120,7 +129,7 @@ public void setPlanId(Long planId) { * * @return the value of core.plan_processing_status.event_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Long getEventId() { return eventId; @@ -132,7 +141,7 @@ public Long getEventId() { * * @param eventId the value for core.plan_processing_status.event_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setEventId(Long eventId) { this.eventId = eventId; @@ -144,7 +153,7 @@ public void setEventId(Long eventId) { * * @return the value of core.plan_processing_status.template_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Long getTemplateId() { return templateId; @@ -156,7 +165,7 @@ public Long getTemplateId() { * * @param templateId the value for core.plan_processing_status.template_id * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setTemplateId(Long templateId) { this.templateId = templateId; @@ -168,7 +177,7 @@ public void setTemplateId(Long templateId) { * * @return the value of core.plan_processing_status.status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Integer getStatus() { return status; @@ -180,7 +189,7 @@ public Integer getStatus() { * * @param status the value for core.plan_processing_status.status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setStatus(Integer status) { this.status = status; @@ -192,7 +201,7 @@ public void setStatus(Integer status) { * * @return the value of core.plan_processing_status.date_created * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Date getDateCreated() { return dateCreated; @@ -204,7 +213,7 @@ public Date getDateCreated() { * * @param dateCreated the value for core.plan_processing_status.date_created * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; @@ -216,7 +225,7 @@ public void setDateCreated(Date dateCreated) { * * @return the value of core.plan_processing_status.date_edited * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Date getDateEdited() { return dateEdited; @@ -228,9 +237,33 @@ public Date getDateEdited() { * * @param dateEdited the value for core.plan_processing_status.date_edited * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setDateEdited(Date dateEdited) { this.dateEdited = dateEdited; } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column core.plan_processing_status.error_log + * + * @return the value of core.plan_processing_status.error_log + * + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 + */ + public String getErrorLog() { + return errorLog; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column core.plan_processing_status.error_log + * + * @param errorLog the value for core.plan_processing_status.error_log + * + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 + */ + public void setErrorLog(String errorLog) { + this.errorLog = errorLog; + } } \ No newline at end of file diff --git a/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatusExample.java b/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatusExample.java index 6ea3f7039..836ab41d0 100644 --- a/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatusExample.java +++ b/src/main/java/org/opensrp/domain/postgres/PlanProcessingStatusExample.java @@ -9,7 +9,7 @@ public class PlanProcessingStatusExample { * This field was generated by MyBatis Generator. * This field corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ protected String orderByClause; @@ -17,7 +17,7 @@ public class PlanProcessingStatusExample { * This field was generated by MyBatis Generator. * This field corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ protected boolean distinct; @@ -25,7 +25,7 @@ public class PlanProcessingStatusExample { * This field was generated by MyBatis Generator. * This field corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ protected List oredCriteria; @@ -33,7 +33,7 @@ public class PlanProcessingStatusExample { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public PlanProcessingStatusExample() { oredCriteria = new ArrayList<>(); @@ -43,7 +43,7 @@ public PlanProcessingStatusExample() { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setOrderByClause(String orderByClause) { this.orderByClause = orderByClause; @@ -53,7 +53,7 @@ public void setOrderByClause(String orderByClause) { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public String getOrderByClause() { return orderByClause; @@ -63,7 +63,7 @@ public String getOrderByClause() { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void setDistinct(boolean distinct) { this.distinct = distinct; @@ -73,7 +73,7 @@ public void setDistinct(boolean distinct) { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public boolean isDistinct() { return distinct; @@ -83,7 +83,7 @@ public boolean isDistinct() { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public List getOredCriteria() { return oredCriteria; @@ -93,7 +93,7 @@ public List getOredCriteria() { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void or(Criteria criteria) { oredCriteria.add(criteria); @@ -103,7 +103,7 @@ public void or(Criteria criteria) { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Criteria or() { Criteria criteria = createCriteriaInternal(); @@ -115,7 +115,7 @@ public Criteria or() { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public Criteria createCriteria() { Criteria criteria = createCriteriaInternal(); @@ -129,7 +129,7 @@ public Criteria createCriteria() { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ protected Criteria createCriteriaInternal() { Criteria criteria = new Criteria(); @@ -140,7 +140,7 @@ protected Criteria createCriteriaInternal() { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public void clear() { oredCriteria.clear(); @@ -152,7 +152,7 @@ public void clear() { * This class was generated by MyBatis Generator. * This class corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ protected abstract static class GeneratedCriteria { protected List criteria; @@ -614,13 +614,83 @@ public Criteria andDateEditedNotBetween(Date value1, Date value2) { addCriterion("date_edited not between", value1, value2, "dateEdited"); return (Criteria) this; } + + public Criteria andErrorLogIsNull() { + addCriterion("error_log is null"); + return (Criteria) this; + } + + public Criteria andErrorLogIsNotNull() { + addCriterion("error_log is not null"); + return (Criteria) this; + } + + public Criteria andErrorLogEqualTo(String value) { + addCriterion("error_log =", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogNotEqualTo(String value) { + addCriterion("error_log <>", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogGreaterThan(String value) { + addCriterion("error_log >", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogGreaterThanOrEqualTo(String value) { + addCriterion("error_log >=", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogLessThan(String value) { + addCriterion("error_log <", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogLessThanOrEqualTo(String value) { + addCriterion("error_log <=", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogLike(String value) { + addCriterion("error_log like", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogNotLike(String value) { + addCriterion("error_log not like", value, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogIn(List values) { + addCriterion("error_log in", values, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogNotIn(List values) { + addCriterion("error_log not in", values, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogBetween(String value1, String value2) { + addCriterion("error_log between", value1, value2, "errorLog"); + return (Criteria) this; + } + + public Criteria andErrorLogNotBetween(String value1, String value2) { + addCriterion("error_log not between", value1, value2, "errorLog"); + return (Criteria) this; + } } /** * This class was generated by MyBatis Generator. * This class corresponds to the database table core.plan_processing_status * - * @mbg.generated do_not_delete_during_merge Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated do_not_delete_during_merge Sun Dec 12 13:48:48 EAT 2021 */ public static class Criteria extends GeneratedCriteria { protected Criteria() { @@ -632,7 +702,7 @@ protected Criteria() { * This class was generated by MyBatis Generator. * This class corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ public static class Criterion { private String condition; diff --git a/src/main/java/org/opensrp/repository/PlanProcessingStatusRepository.java b/src/main/java/org/opensrp/repository/PlanProcessingStatusRepository.java index ef96abbd3..8eb5550bd 100644 --- a/src/main/java/org/opensrp/repository/PlanProcessingStatusRepository.java +++ b/src/main/java/org/opensrp/repository/PlanProcessingStatusRepository.java @@ -14,5 +14,6 @@ public interface PlanProcessingStatusRepository extends BaseRepository selectByExample(PlanProcessingStatusExample example); @@ -58,7 +58,7 @@ public interface PlanProcessingStatusMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ PlanProcessingStatus selectByPrimaryKey(Long id); @@ -66,7 +66,7 @@ public interface PlanProcessingStatusMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ int updateByExampleSelective(@Param("record") PlanProcessingStatus record, @Param("example") PlanProcessingStatusExample example); @@ -74,7 +74,7 @@ public interface PlanProcessingStatusMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ int updateByExample(@Param("record") PlanProcessingStatus record, @Param("example") PlanProcessingStatusExample example); @@ -82,7 +82,7 @@ public interface PlanProcessingStatusMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ int updateByPrimaryKeySelective(PlanProcessingStatus record); @@ -90,7 +90,7 @@ public interface PlanProcessingStatusMapper { * This method was generated by MyBatis Generator. * This method corresponds to the database table core.plan_processing_status * - * @mbg.generated Sat Sep 11 11:04:03 EAT 2021 + * @mbg.generated Sun Dec 12 13:48:48 EAT 2021 */ int updateByPrimaryKey(PlanProcessingStatus record); } \ No newline at end of file diff --git a/src/main/java/org/opensrp/repository/postgres/mapper/xml/PlanProcessingStatusMapper.xml b/src/main/java/org/opensrp/repository/postgres/mapper/xml/PlanProcessingStatusMapper.xml index 1589b6a86..03ec107ba 100644 --- a/src/main/java/org/opensrp/repository/postgres/mapper/xml/PlanProcessingStatusMapper.xml +++ b/src/main/java/org/opensrp/repository/postgres/mapper/xml/PlanProcessingStatusMapper.xml @@ -5,7 +5,7 @@ @@ -14,12 +14,13 @@ + @@ -53,7 +54,7 @@ @@ -87,15 +88,15 @@ - id, plan_id, event_id, template_id, status, date_created, date_edited + id, plan_id, event_id, template_id, status, date_created, date_edited, error_log select count(*) from core.plan_processing_status @@ -223,7 +230,7 @@ update core.plan_processing_status @@ -248,6 +255,9 @@ date_edited = #{record.dateEdited,jdbcType=TIMESTAMP}, + + error_log = #{record.errorLog,jdbcType=VARCHAR}, + @@ -257,7 +267,7 @@ update core.plan_processing_status set id = #{record.id,jdbcType=BIGINT}, @@ -266,7 +276,8 @@ template_id = #{record.templateId,jdbcType=BIGINT}, status = #{record.status,jdbcType=INTEGER}, date_created = #{record.dateCreated,jdbcType=TIMESTAMP}, - date_edited = #{record.dateEdited,jdbcType=TIMESTAMP} + date_edited = #{record.dateEdited,jdbcType=TIMESTAMP}, + error_log = #{record.errorLog,jdbcType=VARCHAR} @@ -275,7 +286,7 @@ update core.plan_processing_status @@ -297,6 +308,9 @@ date_edited = #{dateEdited,jdbcType=TIMESTAMP}, + + error_log = #{errorLog,jdbcType=VARCHAR}, + where id = #{id,jdbcType=BIGINT} @@ -304,7 +318,7 @@ update core.plan_processing_status set plan_id = #{planId,jdbcType=BIGINT}, @@ -312,7 +326,8 @@ template_id = #{templateId,jdbcType=BIGINT}, status = #{status,jdbcType=INTEGER}, date_created = #{dateCreated,jdbcType=TIMESTAMP}, - date_edited = #{dateEdited,jdbcType=TIMESTAMP} + date_edited = #{dateEdited,jdbcType=TIMESTAMP}, + error_log = #{errorLog,jdbcType=VARCHAR} where id = #{id,jdbcType=BIGINT} \ No newline at end of file diff --git a/src/main/java/org/opensrp/service/PlanProcessingStatusService.java b/src/main/java/org/opensrp/service/PlanProcessingStatusService.java index 12d265103..d24189fb7 100644 --- a/src/main/java/org/opensrp/service/PlanProcessingStatusService.java +++ b/src/main/java/org/opensrp/service/PlanProcessingStatusService.java @@ -47,8 +47,10 @@ public void addPlanProcessingStatus(String eventIdentifier, int status) { } - public void updatePlanProcessingStatus(PlanProcessingStatus planProcessingStatus, String eventIdentifier, String planIdentifier, int status) { - getPlanProcessingStatusRepository().updatePlanProcessingStatus(planProcessingStatus, eventIdentifier, planIdentifier, status); + public void updatePlanProcessingStatus(PlanProcessingStatus planProcessingStatus, String eventIdentifier, + String planIdentifier, int status, String errorLog) { + getPlanProcessingStatusRepository().updatePlanProcessingStatus(planProcessingStatus, eventIdentifier, + planIdentifier, status, errorLog); } } diff --git a/src/main/java/org/opensrp/util/constants/PlanProcessingStatusConstants.java b/src/main/java/org/opensrp/util/constants/PlanProcessingStatusConstants.java index 5571d4bd0..f96820daa 100644 --- a/src/main/java/org/opensrp/util/constants/PlanProcessingStatusConstants.java +++ b/src/main/java/org/opensrp/util/constants/PlanProcessingStatusConstants.java @@ -5,4 +5,5 @@ public interface PlanProcessingStatusConstants { int INITIAL = 0; int PROCESSING = 1; int COMPLETE = 2; + int FAILED = 3; } diff --git a/src/test/java/org/opensrp/repository/postgres/PlanProcessingStatusRepositoryTest.java b/src/test/java/org/opensrp/repository/postgres/PlanProcessingStatusRepositoryTest.java index 71a308c46..a1a470269 100644 --- a/src/test/java/org/opensrp/repository/postgres/PlanProcessingStatusRepositoryTest.java +++ b/src/test/java/org/opensrp/repository/postgres/PlanProcessingStatusRepositoryTest.java @@ -111,13 +111,35 @@ public void testUpdatePlanProcessingStatus() { assertEquals(1l, status.getEventId().longValue()); planProcessingStatusRepository.updatePlanProcessingStatus(status, "1c3f6eac-a765-4423-bbda-c01ed6430ae8", - "3450034c-1ba5-556d-8b16-71266397b8b9", PlanProcessingStatusConstants.PROCESSING); + "3450034c-1ba5-556d-8b16-71266397b8b9", PlanProcessingStatusConstants.PROCESSING, + "missing location"); PlanProcessingStatus updatedStatus = planProcessingStatusRepository.getByPrimaryKey(1l); assertEquals(PlanProcessingStatusConstants.PROCESSING, updatedStatus.getStatus().intValue()); assertEquals(2l, updatedStatus.getPlanId().longValue()); assertEquals(1l, updatedStatus.getTemplateId().longValue()); assertEquals(2l, updatedStatus.getEventId().longValue()); + assertEquals("missing location", updatedStatus.getErrorLog()); + } + + @Test + public void testUpdatePlanProcessingStatusWithErrorLog() { + PlanProcessingStatus status = planProcessingStatusRepository.getByPrimaryKey(1l); + assertEquals(PlanProcessingStatusConstants.INITIAL, status.getStatus().intValue()); + assertEquals(1l, status.getPlanId().longValue()); + assertEquals(1l, status.getTemplateId().longValue()); + assertEquals(1l, status.getEventId().longValue()); + assertNull(status.getErrorLog()); + + planProcessingStatusRepository.updatePlanProcessingStatus(status, null,null, + PlanProcessingStatusConstants.FAILED, "Missing jurisdiction"); + + PlanProcessingStatus updatedStatus = planProcessingStatusRepository.getByPrimaryKey(1l); + assertEquals(PlanProcessingStatusConstants.FAILED, updatedStatus.getStatus().intValue()); + assertEquals(1l, updatedStatus.getPlanId().longValue()); + assertEquals(1l, updatedStatus.getTemplateId().longValue()); + assertEquals(1l, updatedStatus.getEventId().longValue()); + assertEquals("Missing jurisdiction", updatedStatus.getErrorLog()); } @Test diff --git a/src/test/java/org/opensrp/service/PlanProcessingStatusServiceTest.java b/src/test/java/org/opensrp/service/PlanProcessingStatusServiceTest.java index 96d330f7f..f09c18136 100644 --- a/src/test/java/org/opensrp/service/PlanProcessingStatusServiceTest.java +++ b/src/test/java/org/opensrp/service/PlanProcessingStatusServiceTest.java @@ -76,9 +76,9 @@ public void testAddPlanProcessingStatusCallsRepositoryMethod() { public void testUpdatePlanProcessingStatusCallsRepositoryMethod() { PlanProcessingStatus status = initTestPlanProcessingStatus(); planProcessingStatusService.updatePlanProcessingStatus( - status,"event-identifier","plan-identifier",1); + status,"event-identifier","plan-identifier",1, "missing location"); verify(planProcessingStatusRepository).updatePlanProcessingStatus( - status,"event-identifier","plan-identifier",1); + status,"event-identifier","plan-identifier",1, "missing location"); } private PlanProcessingStatus initTestPlanProcessingStatus() { diff --git a/src/test/java/org/opensrp/service/SettingServiceTest.java b/src/test/java/org/opensrp/service/SettingServiceTest.java new file mode 100644 index 000000000..bd6471e70 --- /dev/null +++ b/src/test/java/org/opensrp/service/SettingServiceTest.java @@ -0,0 +1,85 @@ +package org.opensrp.service; + +import com.google.gson.Gson; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.opensrp.api.util.LocationTree; +import org.opensrp.api.util.TreeNode; +import org.opensrp.api.domain.Location; +import org.opensrp.domain.setting.Setting; +import org.opensrp.repository.SettingRepository; +import org.opensrp.search.SettingSearchBean; + +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.verify; + +public class SettingServiceTest { + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Mock + private SettingRepository settingRepository; + + @Captor + private ArgumentCaptor settingSearchBeanArgumentCaptor; + + @Captor + private ArgumentCaptor>> mapArgumentCaptor; + + private SettingService settingService; + + @Before + public void setUp() { + settingService = new SettingService(); + settingService.setSettingRepository(this.settingRepository); + } + + @Test + public void testFindSettingsCallsRepositoryFindSettingsMethod() { + SettingSearchBean settingSearchBean = new SettingSearchBean(); + settingSearchBean.setIdentifier("id-1"); + LocationTree locationTree = new Gson().fromJson( + "{\"locationsHierarchy\":{\"map\":{\"02ebbc84-5e29-4cd5-9b79-c594058923e9\":{\"id\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"label\":\"Uganda\",\"node\":{\"locationId\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"name\":\"Uganda\",\"tags\":[\"Country\"],\"voided\":false},\"children\":{\"8340315f-48e4-4768-a1ce-414532b4c49b\":{\"id\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"label\":\"Kampala\",\"node\":{\"locationId\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"name\":\"Kampala\",\"parentLocation\":{\"locationId\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"name\":\"Uganda\",\"voided\":false},\"tags\":[\"District\"],\"voided\":false},\"children\":{\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\":{\"id\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"label\":\"KCCA\",\"node\":{\"locationId\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"name\":\"KCCA\",\"parentLocation\":{\"locationId\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"name\":\"Kampala\",\"parentLocation\":{\"locationId\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"name\":\"Uganda\",\"voided\":false},\"voided\":false},\"tags\":[\"County\"],\"voided\":false},\"children\":{\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\":{\"id\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"label\":\"Central Division\",\"node\":{\"locationId\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"name\":\"Central Division\",\"parentLocation\":{\"locationId\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"name\":\"KCCA\",\"parentLocation\":{\"locationId\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"name\":\"Kampala\",\"voided\":false},\"voided\":false},\"tags\":[\"Sub-county\"],\"voided\":false},\"children\":{\"44de66fb-e6c6-4bae-92bb-386dfe626eba\":{\"id\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\",\"label\":\"Bukesa Urban Health Centre\",\"node\":{\"locationId\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\",\"name\":\"Bukesa Urban Health Centre\",\"parentLocation\":{\"locationId\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"name\":\"Central Division\",\"parentLocation\":{\"locationId\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"name\":\"KCCA\",\"voided\":false},\"voided\":false},\"tags\":[\"Health Facility\"],\"voided\":false},\"children\":{\"982eb3f3-b7e3-450f-a38e-d067f2345212\":{\"id\":\"982eb3f3-b7e3-450f-a38e-d067f2345212\",\"label\":\"Jambula Girls School\",\"node\":{\"locationId\":\"982eb3f3-b7e3-450f-a38e-d067f2345212\",\"name\":\"Jambula Girls School\",\"parentLocation\":{\"locationId\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\",\"name\":\"Bukesa Urban Health Centre\",\"parentLocation\":{\"locationId\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"name\":\"Central Division\",\"voided\":false},\"voided\":false},\"tags\":[\"School\"],\"voided\":false},\"parent\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\"},\"ee08a6e0-3f73-4c28-b186-64d5cd06f4ce\":{\"id\":\"ee08a6e0-3f73-4c28-b186-64d5cd06f4ce\",\"label\":\"Nsalo Secondary School\",\"node\":{\"locationId\":\"ee08a6e0-3f73-4c28-b186-64d5cd06f4ce\",\"name\":\"Nsalo Secondary School\",\"parentLocation\":{\"locationId\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\",\"name\":\"Bukesa Urban Health Centre\",\"parentLocation\":{\"locationId\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"name\":\"Central Division\",\"voided\":false},\"voided\":false},\"tags\":[\"School\"],\"voided\":false},\"parent\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\"}},\"parent\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\"}},\"parent\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\"}},\"parent\":\"8340315f-48e4-4768-a1ce-414532b4c49b\"}},\"parent\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\"}}}},\"parentChildren\":{\"8340315f-48e4-4768-a1ce-414532b4c49b\":[\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\"],\"02ebbc84-5e29-4cd5-9b79-c594058923e9\":[\"8340315f-48e4-4768-a1ce-414532b4c49b\"],\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\":[\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\"],\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\":[\"44de66fb-e6c6-4bae-92bb-386dfe626eba\"],\"44de66fb-e6c6-4bae-92bb-386dfe626eba\":[\"982eb3f3-b7e3-450f-a38e-d067f2345212\",\"ee08a6e0-3f73-4c28-b186-64d5cd06f4ce\"]}}}", + LocationTree.class); + Map> treeNodeHashMap = locationTree.getLocationsHierarchy(); + settingService.findSettings(settingSearchBean,treeNodeHashMap); + verify(settingRepository).findSettings(settingSearchBeanArgumentCaptor.capture(), mapArgumentCaptor.capture()); + assertNotNull(settingSearchBeanArgumentCaptor.getValue()); + assertEquals("id-1", settingSearchBeanArgumentCaptor.getValue().getIdentifier()); + } + + @Test + public void testAddOrUpdateSettingsCallsRepositoryAddOrUpdateMethod() { + Setting setting = new Setting(); + setting.setSettingsId("id-1"); + settingService.addOrUpdateSettings(setting); + verify(settingRepository).addOrUpdate(setting); + } + + @Test + public void testDeleteSettingCallsRepositoryDeleteMethod() { + settingService.deleteSetting(1l); + verify(settingRepository).delete(1l); + } + + @Test + public void testFindSettingsByIdentifierCallsRepositoryMethod() { + settingService.findSettingsByIdentifier("identifier-1"); + verify(settingRepository).findSettingsAndSettingsMetadataByIdentifier("identifier-1"); + } + + @Test(expected = IllegalArgumentException.class) + public void testSaveSettingsThrowsExceptionWhenJsonSettingConfigurationIsNull() { + settingService.saveSetting(null); + } +}