Skip to content

Commit

Permalink
Merge pull request #466 from opensrp/830-add-metadata-version-field
Browse files Browse the repository at this point in the history
830 : Add metadata_version field in the setting metadata table
  • Loading branch information
rehammuzzamil authored Jun 4, 2021
2 parents d0e5d38 + d10d591 commit abc75d8
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 19 deletions.
2 changes: 1 addition & 1 deletion configs
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<artifactId>opensrp-server-core</artifactId>
<packaging>jar</packaging>
<version>2.11.4-SNAPSHOT</version>
<version>2.11.5-SNAPSHOT</version>
<name>opensrp-server-core</name>
<description>OpenSRP Server Core module</description>
<url>https://github.com/OpenSRP/opensrp-server-core</url>
Expand Down
34 changes: 29 additions & 5 deletions src/main/java/org/opensrp/domain/postgres/SettingsMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class SettingsMetadata {
* @mbg.generated Fri Apr 24 10:25:50 EAT 2020
*/
private String settingDescription;

/**
*
* This field was generated by MyBatis Generator.
Expand All @@ -154,6 +154,12 @@ public class SettingsMetadata {
*/
private String inheritedFrom;

/**
* This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.metadata_version
* @mbg.generated Fri May 21 17:49:57 PKT 2021
*/
private Long metadataVersion;

/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column core.settings_metadata.id
Expand Down Expand Up @@ -501,7 +507,7 @@ public void setSettingKey(String settingKey) {
public String getSettingDescription() {
return settingDescription;
}

/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column core.settings_metadata.setting_description
Expand All @@ -513,7 +519,7 @@ public String getSettingDescription() {
public void setSettingDescription(String settingDescription) {
this.settingDescription = settingDescription;
}

/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column core.settings_metadata.setting_label
Expand All @@ -525,7 +531,7 @@ public void setSettingDescription(String settingDescription) {
public void setSettingLabel(String settingLabel) {
this.settingLabel = settingLabel;
}

/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column core.settings_metadata.setting_label
Expand All @@ -537,7 +543,7 @@ public void setSettingLabel(String settingLabel) {
public String getSettingLabel() {
return settingLabel;
}

/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column core.settings_metadata.inherited_from
Expand All @@ -561,4 +567,22 @@ public String getInheritedFrom() {
public void setInheritedFrom(String inheritedFrom) {
this.inheritedFrom = inheritedFrom;
}

/**
* This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.metadata_version
* @return the value of core.settings_metadata.metadata_version
* @mbg.generated Fri May 21 17:49:57 PKT 2021
*/
public Long getMetadataVersion() {
return metadataVersion;
}

/**
* This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.metadata_version
* @param metadataVersion the value for core.settings_metadata.metadata_version
* @mbg.generated Fri May 21 17:49:57 PKT 2021
*/
public void setMetadataVersion(Long metadataVersion) {
this.metadataVersion = metadataVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,67 @@ public SettingsMetadataExampleGeneratedCriteria.Criteria andInheritedFromNotBetw
addCriterion("inherited_from not between", value1, value2, "inheritedFrom");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionIsNull() {
addCriterion("metadata_version is null");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionIsNotNull() {
addCriterion("metadata_version is not null");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionEqualTo(Long value) {
addCriterion("metadata_version =", value, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionNotEqualTo(Long value) {
addCriterion("metadata_version <>", value, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionGreaterThan(Long value) {
addCriterion("metadata_version >", value, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionGreaterThanOrEqualTo(Long value) {
addCriterion("metadata_version >=", value, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionLessThan(Long value) {
addCriterion("metadata_version <", value, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionLessThanOrEqualTo(Long value) {
addCriterion("metadata_version <=", value, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionIn(List<Long> values) {
addCriterion("metadata_version in", values, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionNotIn(List<Long> values) {
addCriterion("metadata_version not in", values, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionBetween(Long value1, Long value2) {
addCriterion("metadata_version between", value1, value2, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

public SettingsMetadataExampleGeneratedCriteria.Criteria andMetadataVersionNotBetween(Long value1, Long value2) {
addCriterion("metadata_version not between", value1, value2, "metadataVersion");
return (SettingsMetadataExampleGeneratedCriteria.Criteria) this;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ public List<SettingConfiguration> findAllSettings() {
@Override
public List<SettingConfiguration> findSettings(SettingSearchBean settingQueryBean,
Map<String, TreeNode<String, Location>> treeNodeHashMap) {
return findSettings(settingQueryBean, DEFAULT_FETCH_SIZE, treeNodeHashMap);
Integer limit;
limit = settingQueryBean.getLimit() == null || settingQueryBean.getLimit() == 0? DEFAULT_FETCH_SIZE : settingQueryBean.getLimit();
return findSettings(settingQueryBean, limit, treeNodeHashMap);
}

@Override
Expand Down Expand Up @@ -212,6 +214,10 @@ public List<SettingsAndSettingsMetadataJoined> findSettingsAndSettingsMetadata(S
criteria.andServerVersionGreaterThanOrEqualTo(settingQueryBean.getServerVersion());
}

if (settingQueryBean.getMetadataVersion() != null) {
criteria.andMetadataVersionGreaterThan(settingQueryBean.getMetadataVersion());
}

if (settingQueryBean.isResolveSettings()) {
return fetchSettingsPerLocation(settingQueryBean, metadataExample, treeNodeHashMap, limit, criteria);
} else {
Expand Down Expand Up @@ -452,6 +458,9 @@ private Setting convertToSetting(SettingsMetadata settingsMetadata, boolean isV1
setting.setDescription(settingsMetadata.getSettingDescription());
setting.setLabel(settingsMetadata.getSettingLabel());
setting.setSettingIdentifier(settingsMetadata.getIdentifier());
if (settingsMetadata.getMetadataVersion() != null) {
setting.setMetadataVersion(settingsMetadata.getMetadataVersion());
}
if (!isV1Settings) {
setting.setProviderId(settingsMetadata.getProviderId());
setting.setSettingsId(String.valueOf(settingsMetadata.getSettingsId()));
Expand Down Expand Up @@ -701,6 +710,7 @@ private List<SettingsMetadata> createMetadata(SettingConfiguration settingConfig
metadata.setIdentifier(settingConfiguration.getIdentifier());
checkIdentityAttributtes(settingConfiguration, metadata);
metadata.setServerVersion(settingConfiguration.getServerVersion());
metadata.setMetadataVersion(settingConfiguration.getMetadataVersion());
metadata.setJson(convertToSetting(metadata, false)); //always want to create the json on the settings
// creation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<result column="setting_description" jdbcType="VARCHAR" property="settingsMetadata.settingDescription" />
<result column="setting_label" jdbcType="VARCHAR" property="settingsMetadata.settingLabel" />
<result column="inherited_from" jdbcType="VARCHAR" property="settingsMetadata.inheritedFrom" />
<result column="metadata_version" jdbcType="BIGINT" property="settingsMetadata.metadataVersion" />
</resultMap>

<sql id="Base_Column_List">
Expand Down Expand Up @@ -92,7 +93,8 @@
setting_key,
setting_description,
setting_label,
inherited_from
inherited_from,
metadata_version
) VALUES
<foreach collection="settingsMetadata" item="setting" separator="," close=";">
(
Expand All @@ -111,7 +113,8 @@
#{setting.settingKey,jdbcType=VARCHAR},
#{setting.settingDescription,jdbcType=VARCHAR},
#{setting.settingLabel,jdbcType=VARCHAR},
#{setting.inheritedFrom,jdbcType=VARCHAR}
#{setting.inheritedFrom,jdbcType=VARCHAR},
nextVal('core.setting_metadata_version_seq')
)
</foreach>
</insert>
Expand All @@ -134,7 +137,8 @@
setting_key = #{setting.settingKey},
setting_description = #{setting.settingDescription},
setting_label = #{setting.settingLabel},
inherited_from = #{setting.inheritedFrom}
inherited_from = #{setting.inheritedFrom},
metadata_version = nextVal('core.setting_metadata_version_seq')
WHERE uuid = #{setting.uuid}
AND setting_key = #{setting.settingKey}
</foreach>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<result column="setting_description" jdbcType="VARCHAR" property="settingDescription" />
<result column="setting_label" jdbcType="VARCHAR" property="settingLabel" />
<result column="inherited_from" jdbcType="VARCHAR" property="inheritedFrom" />
<result column="metadata_version" jdbcType="BIGINT" property="metadataVersion" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
Expand Down Expand Up @@ -101,7 +102,7 @@
-->
id, settings_id, document_id, identifier, server_version, team, team_id, provider_id,
location_id, uuid, json, setting_type, setting_value, setting_key, setting_description,
inherited_from
inherited_from, metadata_version
</sql>
<select id="selectByExample" parameterType="org.opensrp.domain.postgres.SettingsMetadataExample" resultMap="BaseResultMap">
<!--
Expand Down Expand Up @@ -162,15 +163,16 @@
insert into core.settings_metadata (id, settings_id, document_id,
identifier, server_version, team,
team_id, provider_id, location_id,
uuid, json, setting_type,
uuid, json, setting_type,
setting_value, setting_key, setting_description, setting_label,
inherited_from)
inherited_from, metadata_version)
values (#{id,jdbcType=BIGINT}, #{settingsId,jdbcType=BIGINT}, #{documentId,jdbcType=VARCHAR},
#{identifier,jdbcType=VARCHAR}, #{serverVersion,jdbcType=BIGINT}, #{team,jdbcType=VARCHAR},
#{teamId,jdbcType=VARCHAR}, #{providerId,jdbcType=VARCHAR}, #{locationId,jdbcType=VARCHAR},
#{uuid,jdbcType=VARCHAR}, #{json,jdbcType=OTHER}, #{settingType,jdbcType=VARCHAR},
#{uuid,jdbcType=VARCHAR}, #{json,jdbcType=OTHER}, #{settingType,jdbcType=VARCHAR},
#{settingValue,jdbcType=VARCHAR}, #{settingKey,jdbcType=VARCHAR}, #{settingDescription,jdbcType=VARCHAR},
#{settingLabel,jdbcType=VARCHAR},#{inheritedFrom,jdbcType=VARCHAR})
#{settingLabel,jdbcType=VARCHAR},#{inheritedFrom,jdbcType=VARCHAR},
nextVal('core.setting_metadata_version_seq'))
</insert>
<insert id="insertSelective" parameterType="org.opensrp.domain.postgres.SettingsMetadata">
<!--
Expand Down Expand Up @@ -231,6 +233,9 @@
<if test="inheritedFrom != null">
inherited_from,
</if>
<if test="metadataVersion != null">
metadata_version,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
Expand Down Expand Up @@ -284,6 +289,7 @@
<if test="inheritedFrom != null">
#{inheritedFrom,jdbcType=VARCHAR},
</if>
nextVal('core.setting_metadata_version_seq')
</trim>
</insert>
<select id="countByExample" parameterType="org.opensrp.domain.postgres.SettingsMetadataExample" resultType="java.lang.Long">
Expand Down Expand Up @@ -356,6 +362,9 @@
<if test="record.inheritedFrom != null">
inherited_from = #{record.inheritedFrom,jdbcType=VARCHAR},
</if>
<if test="record.metadataVersion != null">
metadata_version = nextVal('core.setting_metadata_version_seq'),
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
Expand Down Expand Up @@ -384,7 +393,8 @@
setting_key = #{record.settingKey,jdbcType=VARCHAR},
setting_description = #{record.settingDescription,jdbcType=VARCHAR},
setting_label = #{record.settingLabel,jdbcType=VARCHAR},
inherited_from = #{record.inheritedFrom,jdbcType=VARCHAR}
inherited_from = #{record.inheritedFrom,jdbcType=VARCHAR},
metadata_version = nextVal('core.setting_metadata_version_seq')
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
Expand Down Expand Up @@ -445,6 +455,9 @@
<if test="inheritedFrom != null">
inherited_from = #{inheritedFrom,jdbcType=VARCHAR},
</if>
<if test="metadataVersion != null">
metadata_version = nextVal('core.setting_metadata_version_seq'),
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
Expand All @@ -470,7 +483,8 @@
setting_key = #{settingKey,jdbcType=VARCHAR},
setting_description = #{settingDescription,jdbcType=VARCHAR},
setting_label = #{settingLabel,jdbcType=VARCHAR},
inherited_from = #{inheritedFrom,jdbcType=VARCHAR}
inherited_from = #{inheritedFrom,jdbcType=VARCHAR},
metadata_version = nextVal('core.setting_metadata_version_seq')
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
23 changes: 22 additions & 1 deletion src/main/java/org/opensrp/search/SettingSearchBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ public class SettingSearchBean extends BaseDataObject {

@JsonIgnore
private boolean resolveSettings;

private Long primaryKey;

private String documentId;

private Long metadataVersion ;

private Integer limit;

public String getProviderId() {
return providerId;
}
Expand Down Expand Up @@ -121,4 +126,20 @@ public boolean isV1Settings() {
public void setV1Settings(boolean v1Settings) {
this.v1Settings = v1Settings;
}

public Long getMetadataVersion() {
return metadataVersion;
}

public void setMetadataVersion(Long metadataVersion) {
this.metadataVersion = metadataVersion;
}

public Integer getLimit() {
return limit;
}

public void setLimit(Integer limit) {
this.limit = limit;
}
}
Loading

0 comments on commit abc75d8

Please sign in to comment.