diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000..e4d0f50007 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] +### Changed +- Moved server default setting configurations to `../assets/server_defaults/` folder. Files follow a per project implementation hierachy pattern + +### Added +- Client Server sync - settings functionality and rest endpoint. `../rest/settings/sync` diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index 33c63ad65a..40f8cb9be4 100644 --- a/assets/config/opensrp.properties +++ b/assets/config/opensrp.properties @@ -20,7 +20,7 @@ mcts-report-delay-in-days=10 mcts.poll.time.interval.in.minutes=10 # OpenMRS configuration -openmrs.url=http://localhost:8080/openmrs/ +openmrs.url=https://openmrs.anc-stage.smartregister.org/openmrs/ openmrs.username=admin openmrs.password=Admin123 openmrs.idgen.url=/module/idgen/exportIdentifiers.form diff --git a/assets/migrations/generator/generatorConfig.xml b/assets/migrations/generator/generatorConfig.xml index 86bd00cf80..b89ca44ca6 100644 --- a/assets/migrations/generator/generatorConfig.xml +++ b/assets/migrations/generator/generatorConfig.xml @@ -2,10 +2,10 @@ + location="/Users/ndegwamartin/Workspace/opensrp-server/assets/migrations/drivers/postgresql-42.2.1.jar" /> - @@ -62,7 +62,15 @@ - --> - +
+ + +
+ +
+ --> + + diff --git a/assets/migrations/scripts/20180423072606_create_view_configurations_metadata_table.sql b/assets/migrations/scripts/20180423072606_create_view_configurations_metadata_table.sql index d1715e7117..6bc095f594 100644 --- a/assets/migrations/scripts/20180423072606_create_view_configurations_metadata_table.sql +++ b/assets/migrations/scripts/20180423072606_create_view_configurations_metadata_table.sql @@ -28,9 +28,8 @@ CREATE TABLE core.view_configuration_metadata ) WITH ( OIDS = FALSE -); +); -- //@UNDO -- SQL to undo the change goes here. DROP TABLE core.view_configuration_metadata; - diff --git a/assets/migrations/scripts/20180904141214_create_settings_table.sql.sql b/assets/migrations/scripts/20180904141214_create_settings_table.sql.sql new file mode 100644 index 0000000000..64474eb79f --- /dev/null +++ b/assets/migrations/scripts/20180904141214_create_settings_table.sql.sql @@ -0,0 +1,33 @@ +-- +-- Copyright 2010-2016 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- // create_settings_table.sql +-- Migration SQL that makes the change goes here. +CREATE TABLE core.settings +( + id bigserial NOT NULL, + json jsonb NOT NULL, + PRIMARY KEY (id) +) +WITH ( + OIDS = FALSE +) + + +-- //@UNDO +-- SQL to undo the change goes here. + +DROP TABLE core.settings diff --git a/assets/migrations/scripts/20180904141237_create_settings_metadata_table.sql.sql b/assets/migrations/scripts/20180904141237_create_settings_metadata_table.sql.sql new file mode 100644 index 0000000000..ff66cd356f --- /dev/null +++ b/assets/migrations/scripts/20180904141237_create_settings_metadata_table.sql.sql @@ -0,0 +1,36 @@ +-- +-- Copyright 2010-2016 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- // create_settings_metadata_table.sql +-- Migration SQL that makes the change goes here. + +CREATE TABLE core.settings_metadata +( + id bigserial NOT NULL, + settings_id bigint REFERENCES core.settings (id), + document_id character varying UNIQUE NOT NULL, + identifier varchar UNIQUE, + server_version bigint, + PRIMARY KEY (id) +) +WITH ( + OIDS = FALSE +); + +-- //@UNDO +-- SQL to undo the change goes here. + +DROP TABLE core.settings_metadata; diff --git a/assets/migrations/scripts/20181012141507_add_settings_metadata_columns_team_id_team_location_id_and_provider_id.sql b/assets/migrations/scripts/20181012141507_add_settings_metadata_columns_team_id_team_location_id_and_provider_id.sql new file mode 100644 index 0000000000..28121cb380 --- /dev/null +++ b/assets/migrations/scripts/20181012141507_add_settings_metadata_columns_team_id_team_location_id_and_provider_id.sql @@ -0,0 +1,31 @@ +-- +-- Copyright 2010-2016 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- // add settings metadata columns team id team location_id and provider id +-- Migration SQL that makes the change goes here. + +ALTER TABLE core.settings_metadata ADD COLUMN team VARCHAR; +ALTER TABLE core.settings_metadata ADD COLUMN team_id VARCHAR; +ALTER TABLE core.settings_metadata ADD COLUMN provider_id VARCHAR; +ALTER TABLE core.settings_metadata ADD COLUMN location_id VARCHAR; + +-- //@UNDO +-- SQL to undo the change goes here. + +ALTER TABLE core.settings_metadata DROP COLUMN team; +ALTER TABLE core.settings_metadata DROP COLUMN team_id; +ALTER TABLE core.settings_metadata DROP COLUMN provider_id; +ALTER TABLE core.settings_metadata DROP COLUMN location_id; diff --git a/assets/migrations/scripts/20181012145616_alter_settings_metadata_column_identifier_remove_constraint.sql b/assets/migrations/scripts/20181012145616_alter_settings_metadata_column_identifier_remove_constraint.sql new file mode 100644 index 0000000000..edd85a1407 --- /dev/null +++ b/assets/migrations/scripts/20181012145616_alter_settings_metadata_column_identifier_remove_constraint.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2010-2016 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +-- // alter settings metadata column identifier remove constraint +-- Migration SQL that makes the change goes here. + +ALTER TABLE core.settings_metadata DROP CONSTRAINT settings_metadata_identifier_key + +-- //@UNDO +-- SQL to undo the change goes here. + +ALTER TABLE core.settings_metadata ADD CONSTRAINT settings_metadata_identifier_key UNIQUE (identifier); \ No newline at end of file diff --git a/assets/server_defaults/anc/population_characteristics.json b/assets/server_defaults/anc/population_characteristics.json new file mode 100644 index 0000000000..b014faa21b --- /dev/null +++ b/assets/server_defaults/anc/population_characteristics.json @@ -0,0 +1,87 @@ +{ + "_id": 2, + "_rev": 1, + "type": "SettingConfiguration", + "identifier": "population_characteristics", + "serverVersion": null, + "settings": [ + { + "key": "pop_undernourish", + "label": "Undernourished prevalence 20% or higher", + "value": null, + "description": "The proportion of women in the adult population (18 years or older), with a BMI less than 18.5, is 20% or higher." + }, + { + "key": "pop_anaemia_40", + "label": "Anaemia prevalence 40% or higher", + "value": null, + "description": "The proportion of pregnant women in the population with anaemia (haemoglobin level less than 11 g/dl) is 40% or higher." + }, + { + "key": "pop_anaemia_20", + "label": "Anaemia prevalence 20% or lower", + "value": null, + "description": "The proportion of pregnant women in the population with anaemia (haemoglobin level less than 11 g/dl) is 20% or lower." + }, + { + "key": "pop_low_calcium", + "label": "Low dietary calcium intake", + "value": null, + "description": "Women in the population are likely to have low dietary calcium intake (less than 900 mg of calcium per day)." + }, + { + "key": "pop_tb", + "label": "TB prevalence 100/100,000 or high.", + "value": null, + "description": "The tuberculosis prevalence in the general population is 100 cases per 100,000 persons or greater." + }, + { + "key": "pop_vita", + "label": "Vitamin A deficiency 5% or higher", + "value": null, + "description": "The prevalence of night blindness is 5% or higher in pregnant women or 5% or higher in children 24–59 months of age, or the proportion of pregnant women with a serum retinol level less than 0.7 mol/L is 20% or higher. " + }, + { + "key": "pop_helminth", + "label": "Soil-transmitted helminth infection prevalence 20% or higher", + "value": null, + "description": "The percentage of individuals in the general population infected with at least one species of soil-transmitted helminth is 20% or higher." + }, + { + "key": "pop_hiv_incidence", + "label": "HIV incidence greater than 3 per 100 person-years in the absence of PrEP", + "value": null, + "description": "Women in the population have a substantial risk of HIV infection. Substantial risk of HIV infection is provisionally defined as HIV incidence greater than 3 per 100 person–years in the absence of pre-exposure prophylaxis (PrEP)." + }, + { + "key": "pop_hiv_prevalence", + "label": "HIV prevalence 5% or higher", + "value": null, + "description": "The HIV prevalence in pregnant women in the population is 5% or higher." + }, + { + "key": "pop_malaria", + "label": "Malaria-endemic setting", + "value": null, + "description": "This is a malaria-endemic setting." + }, + { + "key": "pop_syphilis", + "label": "Syphilis prevalence 5% or higher", + "value": null, + "description": "The prevalence of syphilis in pregnant women in the population is 5% or higher." + }, + { + "key": "pop_hepb", + "label": "Hep B prevalence is intermediate (2% or higher) or high (5% or higher)", + "value": null, + "description": "The proportion of Hepatitis B surface antigen (HBsAg) seroprevalance in the general population is 2% or higher." + }, + { + "key": "pop_hepc", + "label": "Hep C prevalence is intermediate (2% or higher) or high (5% or higher)", + "value": null, + "description": "The proportion of Hepatitis C virus (HCV) antibody seroprevalence in the general population is 2% or higher. " + } + ] +} \ No newline at end of file diff --git a/assets/server_defaults/anc/site_characteristics.json b/assets/server_defaults/anc/site_characteristics.json new file mode 100644 index 0000000000..fb405a9d6a --- /dev/null +++ b/assets/server_defaults/anc/site_characteristics.json @@ -0,0 +1,37 @@ +{ + "_id": "1", + "_rev": "v1", + "type": "SettingConfiguration", + "identifier": "site_characteristics", + "locationId": "", + "providerId": "", + "teamId": "", + "dateCreated": "1970-10-04T10:17:09.993+03:00", + "serverVersion": 1, + "settings": [ + { + "key": "site_ipv_assess", + "label": "Minimum requirements for IPV assessment", + "value": null, + "description": "Are all of the following in place at your facility: \r\n\ta. A protocol or standard operating procedure for Intimate Partner Violence (IPV); \r\n\tb. A health worker trained on how to ask about IPV and how to provide the minimum response or beyond;\r\n\tc. A private setting; \r\n\td. A way to ensure confidentiality; \r\n\te. Time to allow for appropriate disclosure; and\r\n\tf. A system for referral in place. " + }, + { + "key": "site_anc_hiv", + "label": "Generalized HIV epidemic", + "value": null, + "description": "Is the HIV prevalence consistently > 1% in pregnant women attending antenatal clinics at your facility?" + }, + { + "key": "site_ultrasound", + "label": "Ultrasound available", + "value": null, + "description": "Is an ultrasound machine available and functional at your facility and a trained health worker available to use it?" + }, + { + "key": "site_bp_tool", + "label": "Automated BP measurement tool", + "value": null, + "description": "Does your facility use an automated blood pressure (BP) measurement tool?" + } + ] +} \ No newline at end of file diff --git a/assets/tbreach_default_view_configs/README.txt b/assets/server_defaults/tb-reach/view_configurations/README.txt similarity index 100% rename from assets/tbreach_default_view_configs/README.txt rename to assets/server_defaults/tb-reach/view_configurations/README.txt diff --git a/assets/tbreach_default_view_configs/common_register_header.json b/assets/server_defaults/tb-reach/view_configurations/common_register_header.json similarity index 100% rename from assets/tbreach_default_view_configs/common_register_header.json rename to assets/server_defaults/tb-reach/view_configurations/common_register_header.json diff --git a/assets/tbreach_default_view_configs/common_register_row.json b/assets/server_defaults/tb-reach/view_configurations/common_register_row.json similarity index 100% rename from assets/tbreach_default_view_configs/common_register_row.json rename to assets/server_defaults/tb-reach/view_configurations/common_register_row.json diff --git a/assets/tbreach_default_view_configs/component_patient_details_bmi.json b/assets/server_defaults/tb-reach/view_configurations/component_patient_details_bmi.json similarity index 100% rename from assets/tbreach_default_view_configs/component_patient_details_bmi.json rename to assets/server_defaults/tb-reach/view_configurations/component_patient_details_bmi.json diff --git a/assets/tbreach_default_view_configs/component_patient_details_contact_screening.json b/assets/server_defaults/tb-reach/view_configurations/component_patient_details_contact_screening.json similarity index 100% rename from assets/tbreach_default_view_configs/component_patient_details_contact_screening.json rename to assets/server_defaults/tb-reach/view_configurations/component_patient_details_contact_screening.json diff --git a/assets/tbreach_default_view_configs/component_patient_details_demographics.json b/assets/server_defaults/tb-reach/view_configurations/component_patient_details_demographics.json similarity index 100% rename from assets/tbreach_default_view_configs/component_patient_details_demographics.json rename to assets/server_defaults/tb-reach/view_configurations/component_patient_details_demographics.json diff --git a/assets/tbreach_default_view_configs/component_patient_details_followup.json b/assets/server_defaults/tb-reach/view_configurations/component_patient_details_followup.json similarity index 100% rename from assets/tbreach_default_view_configs/component_patient_details_followup.json rename to assets/server_defaults/tb-reach/view_configurations/component_patient_details_followup.json diff --git a/assets/tbreach_default_view_configs/component_patient_details_results.json b/assets/server_defaults/tb-reach/view_configurations/component_patient_details_results.json similarity index 100% rename from assets/tbreach_default_view_configs/component_patient_details_results.json rename to assets/server_defaults/tb-reach/view_configurations/component_patient_details_results.json diff --git a/assets/tbreach_default_view_configs/component_patient_details_service_history.json b/assets/server_defaults/tb-reach/view_configurations/component_patient_details_service_history.json similarity index 100% rename from assets/tbreach_default_view_configs/component_patient_details_service_history.json rename to assets/server_defaults/tb-reach/view_configurations/component_patient_details_service_history.json diff --git a/assets/tbreach_default_view_configs/home.json b/assets/server_defaults/tb-reach/view_configurations/home.json similarity index 100% rename from assets/tbreach_default_view_configs/home.json rename to assets/server_defaults/tb-reach/view_configurations/home.json diff --git a/assets/tbreach_default_view_configs/intreatment_register.json b/assets/server_defaults/tb-reach/view_configurations/intreatment_register.json similarity index 100% rename from assets/tbreach_default_view_configs/intreatment_register.json rename to assets/server_defaults/tb-reach/view_configurations/intreatment_register.json diff --git a/assets/tbreach_default_view_configs/intreatment_register_header.json b/assets/server_defaults/tb-reach/view_configurations/intreatment_register_header.json similarity index 100% rename from assets/tbreach_default_view_configs/intreatment_register_header.json rename to assets/server_defaults/tb-reach/view_configurations/intreatment_register_header.json diff --git a/assets/tbreach_default_view_configs/intreatment_register_row.json b/assets/server_defaults/tb-reach/view_configurations/intreatment_register_row.json similarity index 100% rename from assets/tbreach_default_view_configs/intreatment_register_row.json rename to assets/server_defaults/tb-reach/view_configurations/intreatment_register_row.json diff --git a/assets/tbreach_default_view_configs/lang_en.json b/assets/server_defaults/tb-reach/view_configurations/lang_en.json similarity index 100% rename from assets/tbreach_default_view_configs/lang_en.json rename to assets/server_defaults/tb-reach/view_configurations/lang_en.json diff --git a/assets/tbreach_default_view_configs/lang_fr.json b/assets/server_defaults/tb-reach/view_configurations/lang_fr.json similarity index 100% rename from assets/tbreach_default_view_configs/lang_fr.json rename to assets/server_defaults/tb-reach/view_configurations/lang_fr.json diff --git a/assets/tbreach_default_view_configs/lang_sw.json b/assets/server_defaults/tb-reach/view_configurations/lang_sw.json similarity index 100% rename from assets/tbreach_default_view_configs/lang_sw.json rename to assets/server_defaults/tb-reach/view_configurations/lang_sw.json diff --git a/assets/tbreach_default_view_configs/login.json b/assets/server_defaults/tb-reach/view_configurations/login.json similarity index 100% rename from assets/tbreach_default_view_configs/login.json rename to assets/server_defaults/tb-reach/view_configurations/login.json diff --git a/assets/tbreach_default_view_configs/main.json b/assets/server_defaults/tb-reach/view_configurations/main.json similarity index 100% rename from assets/tbreach_default_view_configs/main.json rename to assets/server_defaults/tb-reach/view_configurations/main.json diff --git a/assets/tbreach_default_view_configs/patient_details_intreatment.json b/assets/server_defaults/tb-reach/view_configurations/patient_details_intreatment.json similarity index 100% rename from assets/tbreach_default_view_configs/patient_details_intreatment.json rename to assets/server_defaults/tb-reach/view_configurations/patient_details_intreatment.json diff --git a/assets/tbreach_default_view_configs/patient_details_positive.json b/assets/server_defaults/tb-reach/view_configurations/patient_details_positive.json similarity index 100% rename from assets/tbreach_default_view_configs/patient_details_positive.json rename to assets/server_defaults/tb-reach/view_configurations/patient_details_positive.json diff --git a/assets/tbreach_default_view_configs/patient_details_presumptive.json b/assets/server_defaults/tb-reach/view_configurations/patient_details_presumptive.json similarity index 100% rename from assets/tbreach_default_view_configs/patient_details_presumptive.json rename to assets/server_defaults/tb-reach/view_configurations/patient_details_presumptive.json diff --git a/assets/tbreach_default_view_configs/positive_register.json b/assets/server_defaults/tb-reach/view_configurations/positive_register.json similarity index 100% rename from assets/tbreach_default_view_configs/positive_register.json rename to assets/server_defaults/tb-reach/view_configurations/positive_register.json diff --git a/assets/tbreach_default_view_configs/positive_register_header.json b/assets/server_defaults/tb-reach/view_configurations/positive_register_header.json similarity index 100% rename from assets/tbreach_default_view_configs/positive_register_header.json rename to assets/server_defaults/tb-reach/view_configurations/positive_register_header.json diff --git a/assets/tbreach_default_view_configs/positive_register_row.json b/assets/server_defaults/tb-reach/view_configurations/positive_register_row.json similarity index 100% rename from assets/tbreach_default_view_configs/positive_register_row.json rename to assets/server_defaults/tb-reach/view_configurations/positive_register_row.json diff --git a/assets/tbreach_default_view_configs/presumptive_register.json b/assets/server_defaults/tb-reach/view_configurations/presumptive_register.json similarity index 100% rename from assets/tbreach_default_view_configs/presumptive_register.json rename to assets/server_defaults/tb-reach/view_configurations/presumptive_register.json diff --git a/assets/tbreach_default_view_configs/presumptive_register_header.json b/assets/server_defaults/tb-reach/view_configurations/presumptive_register_header.json similarity index 100% rename from assets/tbreach_default_view_configs/presumptive_register_header.json rename to assets/server_defaults/tb-reach/view_configurations/presumptive_register_header.json diff --git a/assets/tbreach_default_view_configs/presumptive_register_row.json b/assets/server_defaults/tb-reach/view_configurations/presumptive_register_row.json similarity index 100% rename from assets/tbreach_default_view_configs/presumptive_register_row.json rename to assets/server_defaults/tb-reach/view_configurations/presumptive_register_row.json diff --git a/assets/tbreach_default_view_configs/setup_view_configs.sh b/assets/server_defaults/tb-reach/view_configurations/setup_view_configs.sh similarity index 100% rename from assets/tbreach_default_view_configs/setup_view_configs.sh rename to assets/server_defaults/tb-reach/view_configurations/setup_view_configs.sh diff --git a/opensrp-common/src/main/java/org/opensrp/common/AllConstants.java b/opensrp-common/src/main/java/org/opensrp/common/AllConstants.java index 1ffeca436f..ae4152c7b3 100644 --- a/opensrp-common/src/main/java/org/opensrp/common/AllConstants.java +++ b/opensrp-common/src/main/java/org/opensrp/common/AllConstants.java @@ -1,374 +1,376 @@ package org.opensrp.common; public class AllConstants { - + public static final String OPENSRP_FORM_DATABASE_CONNECTOR = "opensrpFormDatabaseConnector"; - + public static final String OPENSRP_DATABASE_CONNECTOR = "opensrpDatabaseConnector"; - + public static final String OPENSRP_MCTS_DATABASE_CONNECTOR = "opensrpMCTSDatabaseConnector"; - + public static final String SPACE = " "; - + public static final String BOOLEAN_TRUE_VALUE = "true"; - + public static final String BOOLEAN_FALSE_VALUE = "false"; - + public static final String AUTO_CLOSE_PNC_CLOSE_REASON = "Auto Close PNC"; - + public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; - + public static final String EMPTY_STRING = ""; - + public static final String OPENSRP_ERRORTRACE_DATABASE = "opensrpErrorTraceDatabaseConnector"; - + public static final int CLIENTS_FETCH_BATCH_SIZE = 100; - + public static class BaseEntity { - + public static final String BASE_ENTITY_ID = "baseEntityId"; - + public static final String ADDRESS_TYPE = "addressType"; - + public static final String START_DATE = "startDate"; - + public static final String END_DATE = "endDate"; - + public static final String LATITUDE = "latitude"; - + public static final String LONGITUTE = "longitute"; - + public static final String GEOPOINT = "geopoint"; - + public static final String POSTAL_CODE = "postalCode"; - + public static final String SUB_TOWN = "subTown"; - + public static final String TOWN = "town"; - + public static final String SUB_DISTRICT = "subDistrict"; - + public static final String COUNTY_DISTRICT = "countyDistrict"; - + public static final String CITY_VILLAGE = "cityVillage"; - + public static final String STATE_PROVINCE = "stateProvince"; - + public static final String COUNTRY = "country"; - + public static final String LAST_UPDATE = "lastEdited"; - + public static final String SERVER_VERSIOIN = "serverVersion"; - + public static final String MOTHERS_INDENTIFIER = "mother"; - + } - + public static class Client extends BaseEntity { - + public static final String FIRST_NAME = "firstName"; - + public static final String MIDDLE_NAME = "middleName"; - + public static final String LAST_NAME = "lastName"; - + public static final String BIRTH_DATE = "birthdate"; - + public static final String DEATH_DATE = "deathdate"; - + public static final String BIRTH_DATE_APPROX = "birthdateApprox"; - + public static final String DEATH_DATE_APPROX = "deathdateApprox"; - + public static final String GENDER = "gender"; - + public static final String ZEIR_ID = "zeir_id"; - + public static final String OPENMRS_UUID_IDENTIFIER_TYPE = "OPENMRS_UUID"; } - + public static class Event { - + public static final String FORM_SUBMISSION_ID = "formSubmissionId"; - + public static final String EVENT_TYPE = "eventType"; - + public static final String EVENT_ID = "eventId"; - + public static final String LOCATION_ID = "locationId"; - + public static final String EVENT_DATE = "eventDate"; - + public static final String PROVIDER_ID = "providerId"; - + public static final String ENTITY_TYPE = "entityType"; - + public static final String OPENMRS_UUID_IDENTIFIER_TYPE = "OPENMRS_UUID"; - + public static final String TEAM = "team"; - + public static final String TEAM_ID = "teamId"; - + public static final String MVACC_DATE_FORMAT = "dd-MM-yyyy HH:mm"; - + public static final String MVACC_UUID_IDENTIFIER_TYPE = "MVACC_UUID"; - + public static final String BIRTH_REGISTRATION = "Birth Registration"; - + + public static final String SETTING_CONFIGURATIONS = "settingConfigurations"; + } - + public static class Stock { - + public static final String IDENTIFIER = "identifier"; - + public static final String VACCINE_TYPE_ID = "vaccine_type_id"; - + public static final String TRANSACTION_TYPE = "transaction_type"; - + public static final String PROVIDERID = "providerid"; - + public static final String VALUE = "value"; - + public static final String DATE_CREATED = "date_created"; - + public static final String TO_FROM = "to_from"; - + public static final String DATE_UPDATED = "date_updated"; - + public static final String TIMESTAMP = "timeStamp"; - + public static final String TYPE = "type"; - + } - + public static class Action { - + public static final String TIMESTAMP = "timeStamp"; - + } - + public static class Form { - + public static final String ENTITY_ID = "entityId"; - + public static final String ANM_ID = "anmId"; - + public static final String FORM_NAME = "formName"; - + public static final String INSTANCE_ID = "instanceId"; - + public static final String CLIENT_VERSION = "clientVersion"; - + public static final String SERVER_VERSION = "serverVersion"; } - + public static class HTTP { - + public static final String ACCESS_CONTROL_ALLOW_ORIGIN_HEADER = "Access-Control-Allow-Origin"; - + public static final String WWW_AUTHENTICATE_HEADER = "www-authenticate"; } - + public static class OpenSRPEvent { - + public static final String OPENSRP_DATABASE_CONNECTOR = "opensrpDatabaseConnector"; - + public static final String OPENSRP_MCTS_DATABASE_CONNECTOR = "opensrpMCTSDatabaseConnector"; - + public static final String SPACE = " "; - + public static final String BOOLEAN_TRUE_VALUE = "true"; - + public static final String BOOLEAN_FALSE_VALUE = "false"; - + public static final String AUTO_CLOSE_PNC_CLOSE_REASON = "Auto Close PNC"; - + public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; - + public static final String EMPTY_STRING = ""; - + public static final String OPENSRP_ERRORTRACE_DATABASE = "opensrpErrorTraceDatabaseConnector"; - + public static final String FORM_SUBMISSION = "FORM_SUBMISSION"; - + public static class BaseEntity { - + public static final String BASE_ENTITY_ID = "baseEntityId"; - + public static final String ADDRESS_TYPE = "addressType"; - + public static final String START_DATE = "startDate"; - + public static final String END_DATE = "endDate"; - + public static final String LATITUDE = "latitude"; - + public static final String LONGITUTE = "longitute"; - + public static final String GEOPOINT = "geopoint"; - + public static final String POSTAL_CODE = "postalCode"; - + public static final String SUB_TOWN = "subTown"; - + public static final String TOWN = "town"; - + public static final String SUB_DISTRICT = "subDistrict"; - + public static final String COUNTY_DISTRICT = "countyDistrict"; - + public static final String CITY_VILLAGE = "cityVillage"; - + public static final String STATE_PROVINCE = "stateProvince"; - + public static final String COUNTRY = "country"; - + public static final String LAST_UPDATE = "lastEdited"; - + public static final String SERVER_VERSIOIN = "serverVersion"; - + } - + public static class Client extends BaseEntity { - + public static final String FIRST_NAME = "firstName"; - + public static final String MIDDLE_NAME = "middleName"; - + public static final String LAST_NAME = "lastName"; - + public static final String BIRTH_DATE = "birthdate"; - + public static final String DEATH_DATE = "deathdate"; - + public static final String BIRTH_DATE_APPROX = "birthdateApprox"; - + public static final String DEATH_DATE_APPROX = "deathdateApprox"; - + public static final String GENDER = "gender"; - + public static final String ZEIR_ID = "zeir_id"; } - + public static class Event { - + public static final String FORM_SUBMISSION_ID = "formSubmissionId"; - + public static final String EVENT_TYPE = "eventType"; - + public static final String EVENT_ID = "eventId"; - + public static final String LOCATION_ID = "locationId"; - + public static final String EVENT_DATE = "eventDate"; - + public static final String PROVIDER_ID = "providerId"; - + public static final String ENTITY_TYPE = "entityType"; - + } - + public static class Action { - + public static final String TIMESTAMP = "timeStamp"; - + } - + public static class Form { - + public static final String ENTITY_ID = "entityId"; - + public static final String ANM_ID = "anmId"; - + public static final String FORM_NAME = "formName"; - + public static final String INSTANCE_ID = "instanceId"; - + public static final String CLIENT_VERSION = "clientVersion"; - + public static final String SERVER_VERSION = "serverVersion"; } - + public static class HTTP { - + public static final String ACCESS_CONTROL_ALLOW_ORIGIN_HEADER = "Access-Control-Allow-Origin"; - + public static final String WWW_AUTHENTICATE_HEADER = "www-authenticate"; } - + } - + public enum Config { FORM_ENTITY_PARSER_LAST_SYNCED_FORM_SUBMISSION, FORM_ENTITY_PARSER_LAST_MIGRATED_FORM_SUBMISSION, // Used when executing data migrations EVENTS_PARSER_LAST_PROCESSED_EVENT // Used to track last time events processed } - + public static final String FORM_SCHEDULE_SUBJECT = "FORM-SCHEDULE"; - + public static final String EVENTS_SCHEDULE_SUBJECT = "EVENTS-SCHEDULE"; - + public static class Report { - + public static final String FORM_SUBMISSION_ID = "formSubmissionId"; - + public static final String REPORT_TYPE = "reportType"; - + public static final String REPORT_ID = "reportId"; - + public static final String LOCATION_ID = "locationId"; - + public static final String REPORT_DATE = "reportDate"; - + public static final String PROVIDER_ID = "providerId"; - + public static final int FIRST_REPORT_MONTH_OF_YEAR = 3; - + public static final int REPORTING_MONTH_START_DAY = 26; - + public static final int REPORTING_MONTH_END_DAY = 25; - + public static final double LOW_BIRTH_WEIGHT_THRESHOLD = 2.5; - + public static final int INFANT_MORTALITY_THRESHOLD_IN_YEARS = 1; - + public static final int CHILD_MORTALITY_THRESHOLD_IN_YEARS = 5; - + public static final int CHILD_EARLY_NEONATAL_MORTALITY_THRESHOLD_IN_DAYS = 7; - + public static final int CHILD_NEONATAL_MORTALITY_THRESHOLD_IN_DAYS = 28; - + public static final int CHILD_DIARRHEA_THRESHOLD_IN_YEARS = 5; } - + public static class ReportDataParameters { - + public static final String ANM_IDENTIFIER = "anmIdentifier"; - + public static final String SERVICE_PROVIDED_DATA_TYPE = "serviceProvided"; - + public static final String ANM_REPORT_DATA_TYPE = "anmReportData"; - + public static final String SERVICE_PROVIDER_TYPE = "serviceProviderType"; - + public static final String EXTERNAL_ID = "externalId"; - + public static final String INDICATOR = "indicator"; - + public static final String SERVICE_PROVIDED_DATE = "date"; - + public static final String DRISTHI_ENTITY_ID = "dristhiEntityId"; - + public static final String VILLAGE = "village"; - + public static final String SUB_CENTER = "subCenter"; - + public static final String PHC = "phc"; - + public static final String QUANTITY = "quantity"; - + public static final String SERVICE_PROVIDER_ANM = "ANM"; } - + public static class DHIS2Constants { public static final String DHIS2_TRACK_DATA_SYNCER_SUBJECT = "DHIS2 TRACK DATA SYNCER"; @@ -377,4 +379,9 @@ public static class DHIS2Constants { public static final String DHIS2_TRACK_DATA_SYNCER_VERSION_MARKER_EVENT = "DHIS2 TRACK DATA SYNCER VERSION MARKER EVENT"; } + + public static class KEY { + + public static final String VALIDATED_RECORDS = "validated_records"; + } } diff --git a/opensrp-core/src/main/java/org/opensrp/domain/postgres/Settings.java b/opensrp-core/src/main/java/org/opensrp/domain/postgres/Settings.java new file mode 100644 index 0000000000..931676a721 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/domain/postgres/Settings.java @@ -0,0 +1,69 @@ +package org.opensrp.domain.postgres; + +public class Settings { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column core.settings.id + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + private Long id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column core.settings.json + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + private Object json; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column core.settings.id + * + * @return the value of core.settings.id + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public Long getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column core.settings.id + * + * @param id the value for core.settings.id + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public void setId(Long id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column core.settings.json + * + * @return the value of core.settings.json + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public Object getJson() { + return json; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column core.settings.json + * + * @param json the value for core.settings.json + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public void setJson(Object json) { + this.json = json; + } +} \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsExample.java b/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsExample.java new file mode 100644 index 0000000000..73652f6b33 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsExample.java @@ -0,0 +1,456 @@ +package org.opensrp.domain.postgres; + +import java.util.ArrayList; +import java.util.List; + +public class SettingsExample { + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + protected String orderByClause; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + protected boolean distinct; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + protected List oredCriteria; + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public SettingsExample() { + oredCriteria = new ArrayList(); + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public String getOrderByClause() { + return orderByClause; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public boolean isDistinct() { + return distinct; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public List getOredCriteria() { + return oredCriteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + protected abstract static class GeneratedCriteria { + protected List jsonCriteria; + + protected List allCriteria; + + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + jsonCriteria = new ArrayList(); + } + + public List getJsonCriteria() { + return jsonCriteria; + } + + protected void addJsonCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + jsonCriteria.add(new Criterion(condition, value, "org.opensrp.repository.postgres.handler.SettingTypeHandler")); + allCriteria = null; + } + + protected void addJsonCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + jsonCriteria.add(new Criterion(condition, value1, value2, "org.opensrp.repository.postgres.handler.SettingTypeHandler")); + allCriteria = null; + } + + public boolean isValid() { + return criteria.size() > 0 + || jsonCriteria.size() > 0; + } + + public List getAllCriteria() { + if (allCriteria == null) { + allCriteria = new ArrayList(); + allCriteria.addAll(criteria); + allCriteria.addAll(jsonCriteria); + } + return allCriteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + allCriteria = null; + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + allCriteria = null; + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + allCriteria = null; + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andJsonIsNull() { + addCriterion("json is null"); + return (Criteria) this; + } + + public Criteria andJsonIsNotNull() { + addCriterion("json is not null"); + return (Criteria) this; + } + + public Criteria andJsonEqualTo(Object value) { + addJsonCriterion("json =", value, "json"); + return (Criteria) this; + } + + public Criteria andJsonNotEqualTo(Object value) { + addJsonCriterion("json <>", value, "json"); + return (Criteria) this; + } + + public Criteria andJsonGreaterThan(Object value) { + addJsonCriterion("json >", value, "json"); + return (Criteria) this; + } + + public Criteria andJsonGreaterThanOrEqualTo(Object value) { + addJsonCriterion("json >=", value, "json"); + return (Criteria) this; + } + + public Criteria andJsonLessThan(Object value) { + addJsonCriterion("json <", value, "json"); + return (Criteria) this; + } + + public Criteria andJsonLessThanOrEqualTo(Object value) { + addJsonCriterion("json <=", value, "json"); + return (Criteria) this; + } + + public Criteria andJsonIn(List values) { + addJsonCriterion("json in", values, "json"); + return (Criteria) this; + } + + public Criteria andJsonNotIn(List values) { + addJsonCriterion("json not in", values, "json"); + return (Criteria) this; + } + + public Criteria andJsonBetween(Object value1, Object value2) { + addJsonCriterion("json between", value1, value2, "json"); + return (Criteria) this; + } + + public Criteria andJsonNotBetween(Object value1, Object value2) { + addJsonCriterion("json not between", value1, value2, "json"); + return (Criteria) this; + } + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table core.settings + * + * @mbg.generated do_not_delete_during_merge Tue Sep 04 17:59:18 EAT 2018 + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsMetadata.java b/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsMetadata.java new file mode 100644 index 0000000000..6a9725eb23 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsMetadata.java @@ -0,0 +1,212 @@ +package org.opensrp.domain.postgres; + +public class SettingsMetadata { + + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private Long id; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.settings_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private Long settingsId; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.document_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private String documentId; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.identifier + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private String identifier; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.server_version + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private Long serverVersion; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.team + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private String team; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.team_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private String teamId; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.provider_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private String providerId; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column core.settings_metadata.location_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + private String locationId; + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.id + * @return the value of core.settings_metadata.id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public Long getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.id + * @param id the value for core.settings_metadata.id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setId(Long id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.settings_id + * @return the value of core.settings_metadata.settings_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public Long getSettingsId() { + return settingsId; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.settings_id + * @param settingsId the value for core.settings_metadata.settings_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setSettingsId(Long settingsId) { + this.settingsId = settingsId; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.document_id + * @return the value of core.settings_metadata.document_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public String getDocumentId() { + return documentId; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.document_id + * @param documentId the value for core.settings_metadata.document_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setDocumentId(String documentId) { + this.documentId = documentId; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.identifier + * @return the value of core.settings_metadata.identifier + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public String getIdentifier() { + return identifier; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.identifier + * @param identifier the value for core.settings_metadata.identifier + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.server_version + * @return the value of core.settings_metadata.server_version + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public Long getServerVersion() { + return serverVersion; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.server_version + * @param serverVersion the value for core.settings_metadata.server_version + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setServerVersion(Long serverVersion) { + this.serverVersion = serverVersion; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.team + * @return the value of core.settings_metadata.team + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public String getTeam() { + return team; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.team + * @param team the value for core.settings_metadata.team + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setTeam(String team) { + this.team = team; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.team_id + * @return the value of core.settings_metadata.team_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public String getTeamId() { + return teamId; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.team_id + * @param teamId the value for core.settings_metadata.team_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setTeamId(String teamId) { + this.teamId = teamId; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.provider_id + * @return the value of core.settings_metadata.provider_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public String getProviderId() { + return providerId; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.provider_id + * @param providerId the value for core.settings_metadata.provider_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setProviderId(String providerId) { + this.providerId = providerId; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column core.settings_metadata.location_id + * @return the value of core.settings_metadata.location_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public String getLocationId() { + return locationId; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column core.settings_metadata.location_id + * @param locationId the value for core.settings_metadata.location_id + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setLocationId(String locationId) { + this.locationId = locationId; + } +} \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsMetadataExample.java b/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsMetadataExample.java new file mode 100644 index 0000000000..2b0bcd512b --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/domain/postgres/SettingsMetadataExample.java @@ -0,0 +1,870 @@ +package org.opensrp.domain.postgres; + +import java.util.ArrayList; +import java.util.List; + +public class SettingsMetadataExample { + /** + * This field was generated by MyBatis Generator. This field corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + protected String orderByClause; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + protected boolean distinct; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + protected List oredCriteria; + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public SettingsMetadataExample() { + oredCriteria = new ArrayList(); + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public String getOrderByClause() { + return orderByClause; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public boolean isDistinct() { + return distinct; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public List getOredCriteria() { + return oredCriteria; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + /** + * This class was generated by MyBatis Generator. This class corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + protected abstract static class GeneratedCriteria { + + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andSettingsIdIsNull() { + addCriterion("settings_id is null"); + return (Criteria) this; + } + + public Criteria andSettingsIdIsNotNull() { + addCriterion("settings_id is not null"); + return (Criteria) this; + } + + public Criteria andSettingsIdEqualTo(Long value) { + addCriterion("settings_id =", value, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdNotEqualTo(Long value) { + addCriterion("settings_id <>", value, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdGreaterThan(Long value) { + addCriterion("settings_id >", value, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdGreaterThanOrEqualTo(Long value) { + addCriterion("settings_id >=", value, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdLessThan(Long value) { + addCriterion("settings_id <", value, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdLessThanOrEqualTo(Long value) { + addCriterion("settings_id <=", value, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdIn(List values) { + addCriterion("settings_id in", values, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdNotIn(List values) { + addCriterion("settings_id not in", values, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdBetween(Long value1, Long value2) { + addCriterion("settings_id between", value1, value2, "settingsId"); + return (Criteria) this; + } + + public Criteria andSettingsIdNotBetween(Long value1, Long value2) { + addCriterion("settings_id not between", value1, value2, "settingsId"); + return (Criteria) this; + } + + public Criteria andDocumentIdIsNull() { + addCriterion("document_id is null"); + return (Criteria) this; + } + + public Criteria andDocumentIdIsNotNull() { + addCriterion("document_id is not null"); + return (Criteria) this; + } + + public Criteria andDocumentIdEqualTo(String value) { + addCriterion("document_id =", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdNotEqualTo(String value) { + addCriterion("document_id <>", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdGreaterThan(String value) { + addCriterion("document_id >", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdGreaterThanOrEqualTo(String value) { + addCriterion("document_id >=", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdLessThan(String value) { + addCriterion("document_id <", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdLessThanOrEqualTo(String value) { + addCriterion("document_id <=", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdLike(String value) { + addCriterion("document_id like", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdNotLike(String value) { + addCriterion("document_id not like", value, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdIn(List values) { + addCriterion("document_id in", values, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdNotIn(List values) { + addCriterion("document_id not in", values, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdBetween(String value1, String value2) { + addCriterion("document_id between", value1, value2, "documentId"); + return (Criteria) this; + } + + public Criteria andDocumentIdNotBetween(String value1, String value2) { + addCriterion("document_id not between", value1, value2, "documentId"); + return (Criteria) this; + } + + public Criteria andIdentifierIsNull() { + addCriterion("identifier is null"); + return (Criteria) this; + } + + public Criteria andIdentifierIsNotNull() { + addCriterion("identifier is not null"); + return (Criteria) this; + } + + public Criteria andIdentifierEqualTo(String value) { + addCriterion("identifier =", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierNotEqualTo(String value) { + addCriterion("identifier <>", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierGreaterThan(String value) { + addCriterion("identifier >", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierGreaterThanOrEqualTo(String value) { + addCriterion("identifier >=", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierLessThan(String value) { + addCriterion("identifier <", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierLessThanOrEqualTo(String value) { + addCriterion("identifier <=", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierLike(String value) { + addCriterion("identifier like", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierNotLike(String value) { + addCriterion("identifier not like", value, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierIn(List values) { + addCriterion("identifier in", values, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierNotIn(List values) { + addCriterion("identifier not in", values, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierBetween(String value1, String value2) { + addCriterion("identifier between", value1, value2, "identifier"); + return (Criteria) this; + } + + public Criteria andIdentifierNotBetween(String value1, String value2) { + addCriterion("identifier not between", value1, value2, "identifier"); + return (Criteria) this; + } + + public Criteria andServerVersionIsNull() { + addCriterion("server_version is null"); + return (Criteria) this; + } + + public Criteria andServerVersionIsNotNull() { + addCriterion("server_version is not null"); + return (Criteria) this; + } + + public Criteria andServerVersionEqualTo(Long value) { + addCriterion("server_version =", value, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionNotEqualTo(Long value) { + addCriterion("server_version <>", value, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionGreaterThan(Long value) { + addCriterion("server_version >", value, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionGreaterThanOrEqualTo(Long value) { + addCriterion("server_version >=", value, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionLessThan(Long value) { + addCriterion("server_version <", value, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionLessThanOrEqualTo(Long value) { + addCriterion("server_version <=", value, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionIn(List values) { + addCriterion("server_version in", values, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionNotIn(List values) { + addCriterion("server_version not in", values, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionBetween(Long value1, Long value2) { + addCriterion("server_version between", value1, value2, "serverVersion"); + return (Criteria) this; + } + + public Criteria andServerVersionNotBetween(Long value1, Long value2) { + addCriterion("server_version not between", value1, value2, "serverVersion"); + return (Criteria) this; + } + + public Criteria andTeamIsNull() { + addCriterion("team is null"); + return (Criteria) this; + } + + public Criteria andTeamIsNotNull() { + addCriterion("team is not null"); + return (Criteria) this; + } + + public Criteria andTeamEqualTo(String value) { + addCriterion("team =", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamNotEqualTo(String value) { + addCriterion("team <>", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamGreaterThan(String value) { + addCriterion("team >", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamGreaterThanOrEqualTo(String value) { + addCriterion("team >=", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamLessThan(String value) { + addCriterion("team <", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamLessThanOrEqualTo(String value) { + addCriterion("team <=", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamLike(String value) { + addCriterion("team like", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamNotLike(String value) { + addCriterion("team not like", value, "team"); + return (Criteria) this; + } + + public Criteria andTeamIn(List values) { + addCriterion("team in", values, "team"); + return (Criteria) this; + } + + public Criteria andTeamNotIn(List values) { + addCriterion("team not in", values, "team"); + return (Criteria) this; + } + + public Criteria andTeamBetween(String value1, String value2) { + addCriterion("team between", value1, value2, "team"); + return (Criteria) this; + } + + public Criteria andTeamNotBetween(String value1, String value2) { + addCriterion("team not between", value1, value2, "team"); + return (Criteria) this; + } + + public Criteria andTeamIdIsNull() { + addCriterion("team_id is null"); + return (Criteria) this; + } + + public Criteria andTeamIdIsNotNull() { + addCriterion("team_id is not null"); + return (Criteria) this; + } + + public Criteria andTeamIdEqualTo(String value) { + addCriterion("team_id =", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdNotEqualTo(String value) { + addCriterion("team_id <>", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdGreaterThan(String value) { + addCriterion("team_id >", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdGreaterThanOrEqualTo(String value) { + addCriterion("team_id >=", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdLessThan(String value) { + addCriterion("team_id <", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdLessThanOrEqualTo(String value) { + addCriterion("team_id <=", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdLike(String value) { + addCriterion("team_id like", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdNotLike(String value) { + addCriterion("team_id not like", value, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdIn(List values) { + addCriterion("team_id in", values, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdNotIn(List values) { + addCriterion("team_id not in", values, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdBetween(String value1, String value2) { + addCriterion("team_id between", value1, value2, "teamId"); + return (Criteria) this; + } + + public Criteria andTeamIdNotBetween(String value1, String value2) { + addCriterion("team_id not between", value1, value2, "teamId"); + return (Criteria) this; + } + + public Criteria andProviderIdIsNull() { + addCriterion("provider_id is null"); + return (Criteria) this; + } + + public Criteria andProviderIdIsNotNull() { + addCriterion("provider_id is not null"); + return (Criteria) this; + } + + public Criteria andProviderIdEqualTo(String value) { + addCriterion("provider_id =", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdNotEqualTo(String value) { + addCriterion("provider_id <>", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdGreaterThan(String value) { + addCriterion("provider_id >", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdGreaterThanOrEqualTo(String value) { + addCriterion("provider_id >=", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdLessThan(String value) { + addCriterion("provider_id <", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdLessThanOrEqualTo(String value) { + addCriterion("provider_id <=", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdLike(String value) { + addCriterion("provider_id like", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdNotLike(String value) { + addCriterion("provider_id not like", value, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdIn(List values) { + addCriterion("provider_id in", values, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdNotIn(List values) { + addCriterion("provider_id not in", values, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdBetween(String value1, String value2) { + addCriterion("provider_id between", value1, value2, "providerId"); + return (Criteria) this; + } + + public Criteria andProviderIdNotBetween(String value1, String value2) { + addCriterion("provider_id not between", value1, value2, "providerId"); + return (Criteria) this; + } + + public Criteria andLocationIdIsNull() { + addCriterion("location_id is null"); + return (Criteria) this; + } + + public Criteria andLocationIdIsNotNull() { + addCriterion("location_id is not null"); + return (Criteria) this; + } + + public Criteria andLocationIdEqualTo(String value) { + addCriterion("location_id =", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdNotEqualTo(String value) { + addCriterion("location_id <>", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdGreaterThan(String value) { + addCriterion("location_id >", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdGreaterThanOrEqualTo(String value) { + addCriterion("location_id >=", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdLessThan(String value) { + addCriterion("location_id <", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdLessThanOrEqualTo(String value) { + addCriterion("location_id <=", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdLike(String value) { + addCriterion("location_id like", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdNotLike(String value) { + addCriterion("location_id not like", value, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdIn(List values) { + addCriterion("location_id in", values, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdNotIn(List values) { + addCriterion("location_id not in", values, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdBetween(String value1, String value2) { + addCriterion("location_id between", value1, value2, "locationId"); + return (Criteria) this; + } + + public Criteria andLocationIdNotBetween(String value1, String value2) { + addCriterion("location_id not between", value1, value2, "locationId"); + return (Criteria) this; + } + } + + /** + * This class was generated by MyBatis Generator. This class corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + public static class Criterion { + + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table core.settings_metadata + * + * @mbg.generated do_not_delete_during_merge Tue Sep 04 17:59:18 EAT 2018 + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } +} \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/domain/setting/Setting.java b/opensrp-core/src/main/java/org/opensrp/domain/setting/Setting.java new file mode 100644 index 0000000000..770804f075 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/domain/setting/Setting.java @@ -0,0 +1,54 @@ +package org.opensrp.domain.setting; + +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.annotate.JsonSubTypes; +import org.codehaus.jackson.annotate.JsonSubTypes.Type; + +@JsonSubTypes({ @Type(value = SettingConfiguration.class, name = "Setting") }) +public class Setting { + + @JsonProperty + private String key; + + @JsonProperty + private String value; + + @JsonProperty + private String label; + + @JsonProperty + private String description; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/opensrp-core/src/main/java/org/opensrp/domain/setting/SettingConfiguration.java b/opensrp-core/src/main/java/org/opensrp/domain/setting/SettingConfiguration.java new file mode 100644 index 0000000000..51a7a85656 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/domain/setting/SettingConfiguration.java @@ -0,0 +1,98 @@ +package org.opensrp.domain.setting; + +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; +import org.ektorp.support.TypeDiscriminator; +import org.opensrp.domain.BaseDataObject; + +@TypeDiscriminator("doc.type == 'SettingConfiguration'") +public class SettingConfiguration extends BaseDataObject { + + private static final long serialVersionUID = 1890883609898207738L; + + @JsonProperty + private String identifier; + + @JsonProperty + private String teamId; + + @JsonProperty + private String providerId; + + @JsonProperty + private String locationId; + + @JsonProperty + private String childLocationId; + + @JsonProperty + private String version; + + @JsonProperty + private List settings; + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public String getTeamId() { + return teamId; + } + + public void setTeamId(String teamId) { + this.teamId = teamId; + } + + public String getProviderId() { + return providerId; + } + + public void setProviderId(String providerId) { + this.providerId = providerId; + } + + public String getLocationId() { + return locationId; + } + + public void setLocationId(String locationId) { + this.locationId = locationId; + } + + public String getChildLocationId() { + return childLocationId; + } + + public void setChildLocationId(String childLocationId) { + this.childLocationId = childLocationId; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getSettings() { + return settings; + } + + public void setSettings(List settings) { + this.settings = settings; + } +} diff --git a/opensrp-core/src/main/java/org/opensrp/repository/SettingRepository.java b/opensrp-core/src/main/java/org/opensrp/repository/SettingRepository.java new file mode 100644 index 0000000000..28e3988f11 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/SettingRepository.java @@ -0,0 +1,25 @@ +package org.opensrp.repository; + +import java.util.List; + +import org.opensrp.domain.postgres.Settings; +import org.opensrp.domain.postgres.SettingsMetadata; +import org.opensrp.domain.setting.SettingConfiguration; + +public interface SettingRepository extends BaseRepository { + + List findAllSettings(); + + List findAllSettingsByVersion(Long lastSyncedServerVersion, String teamId); + + List findAllLatestSettingsByVersion(Long lastSyncedServerVersion, String teamId); + + List findByEmptyServerVersion(); + + SettingsMetadata saveSetting(SettingConfiguration settingConfiguration, SettingsMetadata settingMetadata); + + SettingsMetadata getSettingMetadataByIdentifierAndTeamId(String identifier, String teamId); + + Settings getSettingById(Long id); + +} diff --git a/opensrp-core/src/main/java/org/opensrp/repository/couch/SettingRepositoryImpl.java b/opensrp-core/src/main/java/org/opensrp/repository/couch/SettingRepositoryImpl.java new file mode 100644 index 0000000000..48f55ac79d --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/couch/SettingRepositoryImpl.java @@ -0,0 +1,82 @@ +package org.opensrp.repository.couch; + +import java.util.List; + +import org.ektorp.ComplexKey; +import org.ektorp.CouchDbConnector; +import org.ektorp.support.CouchDbRepositorySupport; +import org.ektorp.support.View; +import org.opensrp.common.AllConstants; +import org.opensrp.domain.postgres.Settings; +import org.opensrp.domain.postgres.SettingsMetadata; +import org.opensrp.domain.setting.SettingConfiguration; +import org.opensrp.repository.SettingRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Repository; + +@Repository("couchSettingRepository") +@Primary +public class SettingRepositoryImpl extends CouchDbRepositorySupport implements SettingRepository { + + @Autowired + protected SettingRepositoryImpl(@Qualifier(AllConstants.OPENSRP_DATABASE_CONNECTOR) CouchDbConnector db) { + super(SettingConfiguration.class, db); + initStandardDesignDocument(); + } + + @View(name = "all_settings", map = "function(doc) { if (doc.type==='Setting') { emit(doc.identifier); }}") + public List findAllSettings() { + return db.queryView(createQuery("all_settings").includeDocs(true), SettingConfiguration.class); + } + + @View(name = "settings_by_version", map = "function(doc) { if (doc.type==='Setting') { emit([doc.serverVersion], null); }}") + public List findAllSettingsByVersion(Long lastSyncedServerVersion, String teamId) { + ComplexKey startKey = ComplexKey.of(lastSyncedServerVersion); + ComplexKey endKey = ComplexKey.of(Long.MAX_VALUE); + return db.queryView(createQuery("settings_by_version").includeDocs(true).startKey(startKey).endKey(endKey), + SettingConfiguration.class); + } + + /** + * Get all Settings without a server version + * + * @return settings + */ + @View(name = "settings_by_empty_server_version", map = "function(doc) { if ( doc.type == 'Setting' && !doc.serverVersion) { emit(doc._id, doc); } }") + public List findByEmptyServerVersion() { + return db.queryView(createQuery("settings_by_empty_server_version").limit(200).includeDocs(true), + SettingConfiguration.class); + } + + @Override + public void safeRemove(SettingConfiguration entity) { + remove(entity); + } + + @Override + public SettingsMetadata saveSetting(SettingConfiguration settingConfiguration, SettingsMetadata settingMetadata) { + //To Be Implemented + return null; + } + + @Override + public List findAllLatestSettingsByVersion(Long lastSyncedServerVersion, String t) { + // TODO Auto-generated method stub + return null; + } + + @Override + public SettingsMetadata getSettingMetadataByIdentifierAndTeamId(String identifier, String teamId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Settings getSettingById(Long id) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/SettingRepositoryImpl.java b/opensrp-core/src/main/java/org/opensrp/repository/postgres/SettingRepositoryImpl.java new file mode 100644 index 0000000000..ec6df2915e --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/SettingRepositoryImpl.java @@ -0,0 +1,317 @@ +package org.opensrp.repository.postgres; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.UUID; + +import org.opensrp.domain.postgres.Settings; +import org.opensrp.domain.postgres.SettingsMetadata; +import org.opensrp.domain.postgres.SettingsMetadataExample; +import org.opensrp.domain.setting.SettingConfiguration; +import org.opensrp.repository.SettingRepository; +import org.opensrp.repository.postgres.mapper.custom.CustomSettingMapper; +import org.opensrp.repository.postgres.mapper.custom.CustomSettingMetadataMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository("settingRepositoryPostgres") +public class SettingRepositoryImpl extends BaseRepositoryImpl implements SettingRepository { + + @Autowired + private CustomSettingMapper settingMapper; + + @Autowired + private CustomSettingMetadataMapper settingMetadataMapper; + + @Override + public SettingConfiguration get(String id) { + return convert(settingMetadataMapper.selectByDocumentId(id)); + } + + public Settings addSetting(SettingConfiguration entity) { + org.opensrp.domain.postgres.Settings pgSetting = null; + + if (entity == null || entity.getIdentifier() == null) { + return pgSetting; + } + + if (retrievePrimaryKey(entity) != null) { // Setting already added + return pgSetting; + } + + if (entity.getId() == null) + entity.setId(UUID.randomUUID().toString()); + setRevision(entity); + + pgSetting = convert(entity, null); + if (pgSetting == null) { + return pgSetting; + } + + int rowsAffected = settingMapper.insertSelectiveAndSetId(pgSetting); + if (rowsAffected < 1 || pgSetting.getId() == null) { + return pgSetting; + } + + SettingsMetadata metadata = createMetadata(entity, pgSetting.getId()); + if (metadata != null) { + settingMetadataMapper.insertSelective(metadata); + } + + return pgSetting; + } + + @Override + public void update(SettingConfiguration entity) { + if (entity == null || entity.getId() == null || entity.getIdentifier() == null) { + return; + } + + Long id = retrievePrimaryKey(entity); + + if (id == null) { // Setting not exists + return; + } + + setRevision(entity); + + org.opensrp.domain.postgres.Settings pgSetting = convert(entity, id); + + if (pgSetting == null) { + return; + } + + SettingsMetadata metadata = createMetadata(entity, id); + if (metadata == null) { + return; + } + + int rowsAffected = settingMapper.updateByPrimaryKey(pgSetting); + if (rowsAffected < 1) { + return; + } + + SettingsMetadataExample metadataExample = new SettingsMetadataExample(); + metadataExample.createCriteria().andSettingsIdEqualTo(id); + metadata.setId(settingMetadataMapper.selectByExample(metadataExample).get(0).getId()); + settingMetadataMapper.updateByPrimaryKey(metadata); + + } + + @Override + public List getAll() { + return convert(settingMetadataMapper.selectMany(new SettingsMetadataExample(), 0, DEFAULT_FETCH_SIZE)); + } + + @Override + public void safeRemove(SettingConfiguration entity) { + if (entity == null) { + return; + } + + Long id = retrievePrimaryKey(entity); + if (id == null) { + return; + } + + SettingsMetadataExample metadataExample = new SettingsMetadataExample(); + metadataExample.createCriteria().andSettingsIdEqualTo(id); + int rowsAffected = settingMetadataMapper.deleteByExample(metadataExample); + if (rowsAffected < 1) { + return; + } + + settingMapper.deleteByPrimaryKey(id); + + } + + @Override + public List findAllSettings() { + return getAll(); + } + + @Override + public List findAllSettingsByVersion(Long lastSyncedServerVersion, String teamId) { + SettingsMetadataExample metadataExample = new SettingsMetadataExample(); + metadataExample.createCriteria().andTeamIdEqualTo(teamId) + .andServerVersionGreaterThanOrEqualTo(lastSyncedServerVersion); + metadataExample.or(metadataExample.createCriteria().andTeamIdIsNull() + .andServerVersionGreaterThanOrEqualTo(lastSyncedServerVersion)); + return convert(settingMetadataMapper.selectMany(metadataExample, 0, DEFAULT_FETCH_SIZE)); + } + + @Override + public List findAllLatestSettingsByVersion(Long lastSyncedServerVersion, String teamId) { + SettingsMetadataExample metadataExample = new SettingsMetadataExample(); + metadataExample.createCriteria().andTeamIdEqualTo(teamId) + .andServerVersionGreaterThanOrEqualTo(lastSyncedServerVersion); + metadataExample.or(metadataExample.createCriteria().andTeamIdIsNull() + .andServerVersionGreaterThanOrEqualTo(lastSyncedServerVersion)); + metadataExample.setOrderByClause("server_version DESC"); + // metadataExample.gr("server_version DESC"); + return convert(settingMetadataMapper.selectMany(metadataExample, 0, DEFAULT_FETCH_SIZE)); + } + + @Override + public List findByEmptyServerVersion() { + SettingsMetadataExample metadataExample = new SettingsMetadataExample(); + metadataExample.createCriteria().andServerVersionIsNull(); + metadataExample.or(metadataExample.createCriteria().andServerVersionEqualTo(0l)); + return convert(settingMetadataMapper.selectMany(metadataExample, 0, DEFAULT_FETCH_SIZE)); + } + + @Override + protected Long retrievePrimaryKey(SettingConfiguration settingConfiguration) { + if (getUniqueField(settingConfiguration) == null) { + return null; + } + String documentId = settingConfiguration.getId(); + + SettingsMetadataExample metadataExample = new SettingsMetadataExample(); + metadataExample.createCriteria().andDocumentIdEqualTo(documentId); + + org.opensrp.domain.postgres.Settings pgSetting = settingMetadataMapper.selectByDocumentId(documentId); + if (pgSetting == null) { + return null; + } + return pgSetting.getId(); + } + + @Override + protected Object getUniqueField(SettingConfiguration settingConfiguration) { + return settingConfiguration == null ? null : settingConfiguration.getId(); + } + + // private Methods + private SettingConfiguration convert(org.opensrp.domain.postgres.Settings setting) { + if (setting == null || setting.getJson() == null || !(setting.getJson() instanceof SettingConfiguration)) { + return null; + } + return (SettingConfiguration) setting.getJson(); + } + + private org.opensrp.domain.postgres.Settings convert(SettingConfiguration entity, Long id) { + if (entity == null) { + return null; + } + + org.opensrp.domain.postgres.Settings pgSetting = new org.opensrp.domain.postgres.Settings(); + pgSetting.setId(id); + pgSetting.setJson(entity); + + return pgSetting; + } + + private List convert(List settings) { + if (settings == null || settings.isEmpty()) { + return new ArrayList<>(); + } + + List settingValues = new ArrayList<>(); + for (org.opensrp.domain.postgres.Settings setting : settings) { + SettingConfiguration convertedSetting = convert(setting); + if (convertedSetting != null) { + settingValues.add(convertedSetting); + } + } + return settingValues; + } + + private SettingsMetadata createMetadata(SettingConfiguration entity, Long id) { + SettingsMetadata metadata = new SettingsMetadata(); + metadata.setSettingsId(id); + metadata.setDocumentId(entity.getId()); + metadata.setIdentifier(entity.getIdentifier()); + metadata.setServerVersion(entity.getServerVersion()); + return metadata; + } + + @Override + public SettingsMetadata saveSetting(SettingConfiguration entity, SettingsMetadata metadata) { + if (entity == null || entity.getIdentifier() == null) { + return null; + } + + if (entity.getId() == null) { + entity.setId(UUID.randomUUID().toString()); + } + setRevision(entity); + + Settings settings = convert(entity, Long.valueOf(entity.getId())); + if (settings == null) { + return null; + } + + int rowsAffected = entity.getId() != null ? settingMapper.updateByPrimaryKeySelective(settings) + : settingMapper.insertSelectiveAndSetId(settings); + if (rowsAffected < 1 || settings.getId() == null) { + return null; + } + + SettingsMetadata settingsMetadata = metadata != null ? metadata : createMetadata(entity, settings.getId()); + settingsMetadata.setServerVersion(Calendar.getInstance().getTimeInMillis()); + if (settingsMetadata != null) { + + if (settingsMetadata.getId() != null) { + + settingMetadataMapper.updateByPrimaryKeySelective(settingsMetadata); + } else { + + settingMetadataMapper.insertSelective(settingsMetadata); + } + } + + return settingsMetadata; + + } + + @Override + public void add(SettingConfiguration entity) { + if (entity == null || entity.getIdentifier() == null) { + return; + } + + if (retrievePrimaryKey(entity) != null) { // Event already added + return; + } + + if (entity.getId() == null) + entity.setId(UUID.randomUUID().toString()); + setRevision(entity); + + Settings settings = convert(entity, null); + if (settings == null) { + return; + } + + int rowsAffected = settingMapper.insertSelectiveAndSetId(settings); + if (rowsAffected < 1 || settings.getId() == null) { + return; + } + + SettingsMetadata settingsMetadata = createMetadata(entity, settings.getId()); + if (settingsMetadata != null) { + settingMetadataMapper.insertSelective(settingsMetadata); + } + + } + + @Override + public SettingsMetadata getSettingMetadataByIdentifierAndTeamId(String identifier, String teamId) { + SettingsMetadataExample example = new SettingsMetadataExample(); + example.createCriteria().andIdentifierEqualTo(identifier).andTeamIdEqualTo(teamId); + + List settingsMetadata = settingMetadataMapper.selectByExample(example); + + return !settingsMetadata.isEmpty() ? settingsMetadata.get(0) : null; + + } + + @Override + public Settings getSettingById(Long id) { + + return settingMapper.selectByPrimaryKey(id); + + } +} diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/handler/SettingTypeHandler.java b/opensrp-core/src/main/java/org/opensrp/repository/postgres/handler/SettingTypeHandler.java new file mode 100644 index 0000000000..9844cb84c8 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/handler/SettingTypeHandler.java @@ -0,0 +1,73 @@ +package org.opensrp.repository.postgres.handler; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.TypeHandler; +import org.opensrp.domain.setting.SettingConfiguration; +import org.postgresql.util.PGobject; + +public class SettingTypeHandler extends BaseTypeHandler implements TypeHandler { + + @Override + public void setParameter(PreparedStatement ps, int i, SettingConfiguration parameter, JdbcType jdbcType) throws SQLException { + try { + if (parameter != null) { + String jsonString = mapper.writeValueAsString(parameter); + PGobject jsonObject = new PGobject(); + jsonObject.setType("jsonb"); + jsonObject.setValue(jsonString); + ps.setObject(i, jsonObject); + } + } + catch (Exception e) { + throw new SQLException(e); + } + } + + @Override + public SettingConfiguration getResult(ResultSet rs, String columnName) throws SQLException { + try { + String jsonString = rs.getString(columnName); + if (StringUtils.isBlank(jsonString)) { + return null; + } + return mapper.readValue(jsonString, SettingConfiguration.class); + } + catch (Exception e) { + throw new SQLException(e); + } + } + + @Override + public SettingConfiguration getResult(ResultSet rs, int columnIndex) throws SQLException { + try { + String jsonString = rs.getString(columnIndex); + if (StringUtils.isBlank(jsonString)) { + return null; + } + return mapper.readValue(jsonString, SettingConfiguration.class); + } + catch (Exception e) { + throw new SQLException(e); + } + } + + @Override + public SettingConfiguration getResult(CallableStatement cs, int columnIndex) throws SQLException { + try { + String jsonString = cs.getString(columnIndex); + if (StringUtils.isBlank(jsonString)) { + return null; + } + return mapper.readValue(jsonString, SettingConfiguration.class); + } + catch (Exception e) { + throw new SQLException(e); + } + } +} diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/SettingsMapper.java b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/SettingsMapper.java new file mode 100644 index 0000000000..681d9f959a --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/SettingsMapper.java @@ -0,0 +1,96 @@ +package org.opensrp.repository.postgres.mapper; + +import java.util.List; +import org.apache.ibatis.annotations.Param; +import org.opensrp.domain.postgres.Settings; +import org.opensrp.domain.postgres.SettingsExample; + +public interface SettingsMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + long countByExample(SettingsExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int deleteByExample(SettingsExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int deleteByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int insert(Settings record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int insertSelective(Settings record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + List selectByExample(SettingsExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + Settings selectByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int updateByExampleSelective(@Param("record") Settings record, @Param("example") SettingsExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int updateByExample(@Param("record") Settings record, @Param("example") SettingsExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int updateByPrimaryKeySelective(Settings record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table core.settings + * + * @mbg.generated Tue Sep 04 17:59:18 EAT 2018 + */ + int updateByPrimaryKey(Settings record); +} \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/SettingsMetadataMapper.java b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/SettingsMetadataMapper.java new file mode 100644 index 0000000000..1efeb55201 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/SettingsMetadataMapper.java @@ -0,0 +1,76 @@ +package org.opensrp.repository.postgres.mapper; + +import java.util.List; +import org.apache.ibatis.annotations.Param; +import org.opensrp.domain.postgres.SettingsMetadata; +import org.opensrp.domain.postgres.SettingsMetadataExample; + +public interface SettingsMetadataMapper { + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + long countByExample(SettingsMetadataExample example); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int deleteByExample(SettingsMetadataExample example); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int deleteByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int insert(SettingsMetadata record); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int insertSelective(SettingsMetadata record); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + List selectByExample(SettingsMetadataExample example); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + SettingsMetadata selectByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int updateByExampleSelective(@Param("record") SettingsMetadata record, + @Param("example") SettingsMetadataExample example); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int updateByExample(@Param("record") SettingsMetadata record, @Param("example") SettingsMetadataExample example); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int updateByPrimaryKeySelective(SettingsMetadata record); + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table core.settings_metadata + * @mbg.generated Fri Oct 12 19:34:12 EAT 2018 + */ + int updateByPrimaryKey(SettingsMetadata record); +} \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/CustomSettingMapper.java b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/CustomSettingMapper.java new file mode 100644 index 0000000000..bbeacc042d --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/CustomSettingMapper.java @@ -0,0 +1,9 @@ +package org.opensrp.repository.postgres.mapper.custom; + +import org.opensrp.domain.postgres.Settings; +import org.opensrp.repository.postgres.mapper.SettingsMapper; + +public interface CustomSettingMapper extends SettingsMapper { + + int insertSelectiveAndSetId(Settings setting); +} diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/CustomSettingMetadataMapper.java b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/CustomSettingMetadataMapper.java new file mode 100644 index 0000000000..435128d056 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/CustomSettingMetadataMapper.java @@ -0,0 +1,18 @@ +package org.opensrp.repository.postgres.mapper.custom; + +import java.util.List; + +import org.apache.ibatis.annotations.Param; +import org.opensrp.domain.postgres.Settings; +import org.opensrp.domain.postgres.SettingsMetadataExample; +import org.opensrp.repository.postgres.mapper.SettingsMetadataMapper; + +public interface CustomSettingMetadataMapper extends SettingsMetadataMapper { + + List selectMany(@Param("example") SettingsMetadataExample settingsExample, @Param("offset") int offset, + @Param("limit") int limit); + + Settings selectByDocumentId(String documentId); + +} + diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/xml/CustomSettingsMapper.xml b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/xml/CustomSettingsMapper.xml new file mode 100644 index 0000000000..9a931971c0 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/xml/CustomSettingsMapper.xml @@ -0,0 +1,27 @@ + + + + + + insert into core.settings + + + id, + + + json, + + + + + #{id,jdbcType=BIGINT}, + + + #{json,jdbcType=OTHER,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler}, + + + + \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/xml/CustomSettingsMetadataMapper.xml b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/xml/CustomSettingsMetadataMapper.xml new file mode 100644 index 0000000000..1f2fe05241 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/custom/xml/CustomSettingsMetadataMapper.xml @@ -0,0 +1,72 @@ + + + + + + v.id, v.json + + + + from core.settings_metadata m + join + core.settings v on m.settings_id = v.id + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and + #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/xml/SettingsMapper.xml b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/xml/SettingsMapper.xml new file mode 100644 index 0000000000..fbc2fad2d2 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/xml/SettingsMapper.xml @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + + + and ${criterion.condition} #{criterion.value,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} and #{criterion.secondValue,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + + + and ${criterion.condition} + + #{listItem,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + + + and ${criterion.condition} #{criterion.value,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} and #{criterion.secondValue,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + + + and ${criterion.condition} + + #{listItem,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + + + + + + + + + + + + id, json + + + + + + delete from core.settings + where id = #{id,jdbcType=BIGINT} + + + + delete from core.settings + + + + + + + insert into core.settings (id, json + ) + values (#{id,jdbcType=BIGINT}, #{json,jdbcType=OTHER,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + ) + + + + insert into core.settings + + + id, + + + json, + + + + + #{id,jdbcType=BIGINT}, + + + #{json,jdbcType=OTHER,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler}, + + + + + + + update core.settings + + + id = #{record.id,jdbcType=BIGINT}, + + + json = #{record.json,jdbcType=OTHER,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler}, + + + + + + + + + update core.settings + set id = #{record.id,jdbcType=BIGINT}, + json = #{record.json,jdbcType=OTHER,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + + + + + + + update core.settings + + + json = #{json,jdbcType=OTHER,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler}, + + + where id = #{id,jdbcType=BIGINT} + + + + update core.settings + set json = #{json,jdbcType=OTHER,typeHandler=org.opensrp.repository.postgres.handler.SettingTypeHandler} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/xml/SettingsMetadataMapper.xml b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/xml/SettingsMetadataMapper.xml new file mode 100644 index 0000000000..85dbbece08 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/repository/postgres/mapper/xml/SettingsMetadataMapper.xml @@ -0,0 +1,351 @@ + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + id, settings_id, document_id, identifier, server_version, team, team_id, provider_id, + location_id + + + + + + delete from core.settings_metadata + where id = #{id,jdbcType=BIGINT} + + + + delete from core.settings_metadata + + + + + + + insert into core.settings_metadata (id, settings_id, document_id, + identifier, server_version, team, + team_id, provider_id, location_id + ) + 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} + ) + + + + insert into core.settings_metadata + + + id, + + + settings_id, + + + document_id, + + + identifier, + + + server_version, + + + team, + + + team_id, + + + provider_id, + + + location_id, + + + + + #{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}, + + + + + + + update core.settings_metadata + + + id = #{record.id,jdbcType=BIGINT}, + + + settings_id = #{record.settingsId,jdbcType=BIGINT}, + + + document_id = #{record.documentId,jdbcType=VARCHAR}, + + + identifier = #{record.identifier,jdbcType=VARCHAR}, + + + server_version = #{record.serverVersion,jdbcType=BIGINT}, + + + team = #{record.team,jdbcType=VARCHAR}, + + + team_id = #{record.teamId,jdbcType=VARCHAR}, + + + provider_id = #{record.providerId,jdbcType=VARCHAR}, + + + location_id = #{record.locationId,jdbcType=VARCHAR}, + + + + + + + + + update core.settings_metadata + set id = #{record.id,jdbcType=BIGINT}, + settings_id = #{record.settingsId,jdbcType=BIGINT}, + document_id = #{record.documentId,jdbcType=VARCHAR}, + identifier = #{record.identifier,jdbcType=VARCHAR}, + server_version = #{record.serverVersion,jdbcType=BIGINT}, + team = #{record.team,jdbcType=VARCHAR}, + team_id = #{record.teamId,jdbcType=VARCHAR}, + provider_id = #{record.providerId,jdbcType=VARCHAR}, + location_id = #{record.locationId,jdbcType=VARCHAR} + + + + + + + update core.settings_metadata + + + settings_id = #{settingsId,jdbcType=BIGINT}, + + + document_id = #{documentId,jdbcType=VARCHAR}, + + + identifier = #{identifier,jdbcType=VARCHAR}, + + + server_version = #{serverVersion,jdbcType=BIGINT}, + + + team = #{team,jdbcType=VARCHAR}, + + + team_id = #{teamId,jdbcType=VARCHAR}, + + + provider_id = #{providerId,jdbcType=VARCHAR}, + + + location_id = #{locationId,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + + update core.settings_metadata + set settings_id = #{settingsId,jdbcType=BIGINT}, + document_id = #{documentId,jdbcType=VARCHAR}, + identifier = #{identifier,jdbcType=VARCHAR}, + server_version = #{serverVersion,jdbcType=BIGINT}, + team = #{team,jdbcType=VARCHAR}, + team_id = #{teamId,jdbcType=VARCHAR}, + provider_id = #{providerId,jdbcType=VARCHAR}, + location_id = #{locationId,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/opensrp-core/src/main/java/org/opensrp/service/SettingService.java b/opensrp-core/src/main/java/org/opensrp/service/SettingService.java new file mode 100644 index 0000000000..648a2e2f42 --- /dev/null +++ b/opensrp-core/src/main/java/org/opensrp/service/SettingService.java @@ -0,0 +1,82 @@ +package org.opensrp.service; + +import java.util.List; + +import org.joda.time.DateTime; +import org.opensrp.domain.postgres.Settings; +import org.opensrp.domain.postgres.SettingsMetadata; +import org.opensrp.domain.setting.SettingConfiguration; +import org.opensrp.repository.SettingRepository; +import org.opensrp.util.DateTimeTypeConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +@Service +public class SettingService { + + private static Logger logger = LoggerFactory.getLogger(SettingService.class.toString()); + + private SettingRepository settingRepository; + + Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") + .registerTypeAdapter(DateTime.class, new DateTimeTypeConverter()).create(); + + @Autowired + public void setSettingRepository(SettingRepository settingRepository) { + this.settingRepository = settingRepository; + } + + public List findSettingsByVersionAndTeamId(Long lastSyncedServerVersion, String teamId) { + return settingRepository.findAllSettingsByVersion(lastSyncedServerVersion, teamId); + } + + public List findLatestSettingsByVersionAndTeamId(Long lastSyncedServerVersion, String teamId) { + return settingRepository.findAllLatestSettingsByVersion(lastSyncedServerVersion, teamId); + } + + public void addServerVersion() { + try { + List settingConfigurations = settingRepository.findByEmptyServerVersion(); + logger.info("RUNNING addServerVersion settings size: " + settingConfigurations.size()); + long currentTimeMillis = System.currentTimeMillis(); + for (SettingConfiguration settingConfiguration : settingConfigurations) { + try { + Thread.sleep(1); + settingConfiguration.setServerVersion(currentTimeMillis); + settingRepository.update(settingConfiguration); + currentTimeMillis += 1; + } + catch (InterruptedException e) { + logger.error(e.getMessage()); + } + } + } + catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + public synchronized SettingsMetadata saveSetting(String jsonSettingConfiguration) { + + SettingConfiguration settingConfigurations = gson.fromJson(jsonSettingConfiguration, + new TypeToken() {}.getType()); + + SettingsMetadata metadata = settingRepository.getSettingMetadataByIdentifierAndTeamId(settingConfigurations.getIdentifier(), settingConfigurations.getTeamId()); + Settings settings; + + if (metadata != null) { + + settings = settingRepository.getSettingById(metadata.getSettingsId()); + settingConfigurations.setId(String.valueOf(settings.getId())); + + } + return settingRepository.saveSetting(settingConfigurations, metadata); + } + +} diff --git a/opensrp-web/src/main/java/org/opensrp/web/rest/SettingResource.java b/opensrp-web/src/main/java/org/opensrp/web/rest/SettingResource.java new file mode 100644 index 0000000000..6df1040349 --- /dev/null +++ b/opensrp-web/src/main/java/org/opensrp/web/rest/SettingResource.java @@ -0,0 +1,100 @@ +package org.opensrp.web.rest; + +import static java.text.MessageFormat.format; +import static org.opensrp.web.rest.RestUtils.getStringFilter; +import static org.springframework.web.bind.annotation.RequestMethod.POST; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.joda.time.DateTime; +import org.json.JSONArray; +import org.json.JSONObject; +import org.opensrp.common.AllConstants; +import org.opensrp.common.AllConstants.BaseEntity; +import org.opensrp.domain.postgres.SettingsMetadata; +import org.opensrp.domain.setting.SettingConfiguration; +import org.opensrp.service.SettingService; +import org.opensrp.util.DateTimeTypeConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +@Controller +@RequestMapping(value = "/rest/settings") +public class SettingResource { + + private SettingService settingService; + + private static Logger logger = LoggerFactory.getLogger(EventResource.class.toString()); + + private String TEAM_ID = "teamId"; + + Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") + .registerTypeAdapter(DateTime.class, new DateTimeTypeConverter()).create(); + + @Autowired + public void setSettingService(SettingService settingService) { + this.settingService = settingService; + } + + @RequestMapping(method = RequestMethod.GET, value = "/sync") + @ResponseBody + public List findSettingsByVersion(HttpServletRequest request) { + String serverVersion = getStringFilter(BaseEntity.SERVER_VERSIOIN, request); + String teamId = getStringFilter(TEAM_ID, request); + Long lastSyncedServerVersion = null; + if (serverVersion != null) { + lastSyncedServerVersion = Long.valueOf(serverVersion) + 1; + } + return settingService.findLatestSettingsByVersionAndTeamId(lastSyncedServerVersion, teamId); + } + + @RequestMapping(headers = { "Accept=application/json" }, method = POST, value = "/sync") + public ResponseEntity saveSetting(@RequestBody String data) { + JSONObject response = new JSONObject(); + + try { + JSONObject syncData = new JSONObject(data); + + if (!syncData.has("settingConfigurations")) { + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } else { + + JSONArray clientSettings = syncData.getJSONArray(AllConstants.Event.SETTING_CONFIGURATIONS); + JSONArray dbSettingsArray = new JSONArray(); + + SettingsMetadata dbSettingMetadata = null; + + for (int i = 0; i < clientSettings.length(); i++) { + + dbSettingMetadata = settingService.saveSetting(clientSettings.getString(i).toString()); + dbSettingsArray.put(dbSettingMetadata.getIdentifier()); + + } + + response.append("validated_records", dbSettingsArray); + + } + + } + + catch (Exception e) { + logger.error(format("Sync data processing failed with exception {0}.- ", e)); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + + return new ResponseEntity(response, HttpStatus.OK); + } +}