Пример #1
0
        private async Task <string> get_revision(string p_document_url)
        {
            string result = null;

            var    document_curl = new cURL("GET", null, p_document_url, null, Program.config_timer_user_name, Program.config_timer_password);
            string document_json = null;

            try
            {
                document_json = await document_curl.executeAsync();

                var request_result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (document_json);
                IDictionary <string, object> updater = request_result as IDictionary <string, object>;
                result = updater ["_rev"].ToString();
            }
            catch (Exception ex)
            {
                if (!(ex.Message.IndexOf("(404) Object Not Found") > -1))
                {
                    //System.Console.WriteLine ("c_sync_document.get_revision");
                    //System.Console.WriteLine (ex);
                }
            }

            return(result);
        }
Пример #2
0
        private async Task <bool> sync_document(string p_document_json, string p_target_db_url, string p_user_name, string p_password)
        {
            bool result = false;

            string revision_id = await get_revision(p_target_db_url);

            string storage_document_json = null;

            if (!string.IsNullOrEmpty(revision_id))
            {
                storage_document_json = set_revision(p_document_json, revision_id);
            }
            else
            {
                storage_document_json = p_document_json;
            }

            var curl = new cURL("PUT", null, p_target_db_url, storage_document_json, p_user_name, p_password);

            try
            {
                string curl_result = await curl.executeAsync();

                System.Console.WriteLine("db_setupController.sync_document");
                System.Console.WriteLine(curl_result);
                result = true;
            }
            catch (Exception ex)
            {
                //System.Console.WriteLine("c_sync_document de_id");
                //System.Console.WriteLine(ex);
            }

            return(result);
        }
Пример #3
0
        public async System.Threading.Tasks.Task <mmria.common.metadata.UI_Specification> Get(string id = "default-ui-specification")
        {
            Log.Information("Recieved message.");
            var result = new mmria.common.metadata.UI_Specification();

            try
            {
                string ui_specification_url = Program.config_couchdb_url + $"/metadata/" + id;

                var    ui_specification_curl = new cURL("GET", null, ui_specification_url, null, Program.config_timer_user_name, Program.config_timer_password);
                string responseFromServer    = await ui_specification_curl.executeAsync();

                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings {
                    NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
                    MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore
                };
                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.metadata.UI_Specification> (responseFromServer, settings);
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
Пример #4
0
        private async Task <bool> url_endpoint_exists(string p_target_db_url, string p_user_name, string p_password)
        {
            bool result = false;

            var curl = new cURL("HEAD", null, p_target_db_url, null, p_user_name, p_password);

            try
            {
                await curl.executeAsync();

                /*
                 * HTTP/1.1 200 OK
                 * Cache-Control: must-revalidate
                 * Content-Type: application/json
                 * Date: Mon, 12 Aug 2013 01:27:41 GMT
                 * Server: CouchDB (Erlang/OTP)*/
                result = true;
            }
            catch (Exception ex)
            {
                // do nothing for now
            }


            return(result);
        }
Пример #5
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post
        (
            [FromBody] mmria.common.metadata.app metadata
        )
        {
            string object_string = null;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                object_string = Newtonsoft.Json.JsonConvert.SerializeObject(metadata, settings);

                string metadata_url = Program.config_couchdb_url + "/metadata/" + metadata._id;

                var metadata_curl = new cURL("PUT", null, metadata_url, object_string, Program.config_timer_user_name, Program.config_timer_password);


                string responseFromServer = await metadata_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);

                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #6
0
        public async System.Threading.Tasks.Task <System.Dynamic.ExpandoObject> Delete(string migration_plan_id = null, string rev = null)
        {
            if (migration_plan_id == "2016-06-12T13:49:24.759Z")
            {
                return(null);
            }

            try
            {
                string request_string = null;

                if (!string.IsNullOrWhiteSpace(migration_plan_id) && !string.IsNullOrWhiteSpace(rev))
                {
                    request_string = Program.config_couchdb_url + "/metadata/" + migration_plan_id + "?rev=" + rev;
                }
                else
                {
                    return(null);
                }

                var delete_report_curl = new cURL("DELETE", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);

                string responseFromServer = await delete_report_curl.executeAsync();;
                var    result             = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (responseFromServer);

                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
Пример #7
0
        public async System.Threading.Tasks.Task <FileStreamResult> Get(string id)
        {
            HttpResponseMessage result = new HttpResponseMessage(System.Net.HttpStatusCode.NoContent);
            FileStream          stream = null;
            string file_name           = null;

            var    get_item_curl      = new cURL("GET", null, Program.config_couchdb_url + "/export_queue/" + id, null, Program.config_timer_user_name, Program.config_timer_password);
            string responseFromServer = await get_item_curl.executeAsync();

            export_queue_item export_queue_item = Newtonsoft.Json.JsonConvert.DeserializeObject <export_queue_item> (responseFromServer);

            file_name = export_queue_item.file_name;

            var path = System.IO.Path.Combine(Configuration["mmria_settings:export_directory"], export_queue_item.file_name);

            result         = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
            stream         = new FileStream(path, FileMode.Open, FileAccess.Read);
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            export_queue_item.status = "Downloaded";

            Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
            settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            string object_string = Newtonsoft.Json.JsonConvert.SerializeObject(export_queue_item, settings);
            var    set_item_curl = new cURL("PUT", null, Program.config_couchdb_url + "/export_queue/" + export_queue_item._id, object_string, Program.config_timer_user_name, Program.config_timer_password);

            responseFromServer = await set_item_curl.executeAsync();



            return(File(stream, "application/octet-stream", file_name));
        }
Пример #8
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post()
        {
            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            //if(!string.IsNullOrWhiteSpace(json))
            try
            {
                System.IO.Stream dataStream0 = this.Request.Body;
                // Open the stream using a StreamReader for easy access.
                //dataStream0.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader reader0 = new System.IO.StreamReader(dataStream0);
                // Read the content.
                string validator_js_text = await reader0.ReadToEndAsync();

                string metadata_url = Program.config_couchdb_url + "/metadata/de-identified-list";

                var de_identified_curl = new cURL("PUT", null, metadata_url, validator_js_text, Program.config_timer_user_name, Program.config_timer_password, "text/*");

                string responseFromServer = await de_identified_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);

                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #9
0
        public async Task <System.Dynamic.ExpandoObject> Get(string case_id)
        {
            try
            {
                string request_string = Program.config_couchdb_url + "/mmrds/_all_docs?include_docs=true";

                if (!string.IsNullOrWhiteSpace(case_id))
                {
                    request_string = Program.config_couchdb_url + "/mmrds/" + case_id;

                    var    case_curl          = new cURL("GET", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);
                    string responseFromServer = await case_curl.executeAsync();

                    var result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (responseFromServer);

                    if (mmria.server.util.authorization_case.is_authorized_to_handle_jurisdiction_id(User, mmria.server.util.ResourceRightEnum.ReadCase, result))
                    {
                        return(result);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
Пример #10
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post
        (
            [FromBody] session Post_Request

        )
        {
            try
            {
                mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();
                string request_string = Program.config_couchdb_url + $"/session/{Post_Request._id}";

                try
                {
                    var    check_document_curl = new cURL("GET", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);
                    string check_document_json = await check_document_curl.executeAsync();

                    var check_document_expando_object = Newtonsoft.Json.JsonConvert.DeserializeObject <session> (check_document_json);

                    var userName = User.Identities.First(
                        u => u.IsAuthenticated &&
                        u.HasClaim(c => c.Type == ClaimTypes.Name)).FindFirst(ClaimTypes.Name).Value;


                    if (!userName.Equals(check_document_expando_object.user_id, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Write($"unauthorized PUT {Post_Request._id} by: {userName}");
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    // do nothing for now document doesn't exsist.
                    System.Console.WriteLine($"err caseController.Post\n{ex}");
                }

                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                var object_string = Newtonsoft.Json.JsonConvert.SerializeObject(Post_Request, settings);

                cURL document_curl = new cURL("PUT", null, request_string, object_string, Program.config_timer_user_name, Program.config_timer_password);

                try
                {
                    string responseFromServer = await document_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
Пример #11
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post
        (
            [FromBody] mmria.common.metadata.UI_Specification ui_specification
        )
        {
            string ui_specification_json;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                if
                (
                    ui_specification.data_type == null ||
                    ui_specification.data_type != "ui-specification" ||
                    ui_specification._id == "2016-06-12T13:49:24.759Z" ||
                    ui_specification._id == "de-identified-list"

                )
                {
                    return(null);
                }

                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings {
                    NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
                    MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore
                };
                ui_specification_json = Newtonsoft.Json.JsonConvert.SerializeObject(ui_specification, settings);

                string ui_specification_url = Program.config_couchdb_url + "/metadata/" + ui_specification._id;


                cURL document_curl = new cURL("PUT", null, ui_specification_url, ui_specification_json, Program.config_timer_user_name, Program.config_timer_password);


                try
                {
                    string responseFromServer = await document_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);
                }
                catch (Exception ex)
                {
                    Log.Information($"jurisdiction_treeController:{ex}");
                }


                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
        public async System.Threading.Tasks.Task <System.Dynamic.ExpandoObject> Delete(string _id = null, string rev = null)
        {
            try
            {
                string request_string = null;

                if (!string.IsNullOrWhiteSpace(_id) && !string.IsNullOrWhiteSpace(rev))
                {
                    request_string = Program.config_couchdb_url + "/jurisdiction/" + _id + "?rev=" + rev;
                }
                else
                {
                    return(null);
                }

                var delete_report_curl  = new cURL("DELETE", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);
                var check_document_curl = new cURL("GET", null, Program.config_couchdb_url + "/jurisdiction/" + _id, null, Program.config_timer_user_name, Program.config_timer_password);
                // check if doc exists

                try
                {
                    string document_json = null;
                    document_json = await check_document_curl.executeAsync();

                    var check_document_curl_result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.user_role_jurisdiction> (document_json);
                    IDictionary <string, object> result_dictionary = check_document_curl_result as IDictionary <string, object>;

                    if (!mmria.server.util.authorization_user.is_authorized_to_handle_jurisdiction_id(User, mmria.server.util.ResourceRightEnum.WriteUser, check_document_curl_result))
                    {
                        return(null);
                    }

                    if (result_dictionary.ContainsKey("_rev"))
                    {
                        request_string = Program.config_couchdb_url + "/jurisdiction/" + _id + "?rev=" + result_dictionary ["_rev"];
                        //System.Console.WriteLine ("json\n{0}", object_string);
                    }
                }
                catch (Exception ex)
                {
                    // do nothing for now document doesn't exsist.
                    System.Console.WriteLine($"err caseController.Delete\n{ex}");
                }

                string responseFromServer = await delete_report_curl.executeAsync();;
                var    result             = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (responseFromServer);

                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post
        (
            [FromBody] mmria.common.model.couchdb.user_role_jurisdiction user_role_jurisdiction
        )
        {
            string user_role_jurisdiction_json;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                if (!mmria.server.util.authorization_user.is_authorized_to_handle_jurisdiction_id(User, mmria.server.util.ResourceRightEnum.WriteUser, user_role_jurisdiction))
                {
                    return(null);
                }

                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling  = Newtonsoft.Json.NullValueHandling.Ignore;
                user_role_jurisdiction_json = Newtonsoft.Json.JsonConvert.SerializeObject(user_role_jurisdiction, settings);

                string jurisdiction_tree_url = Program.config_couchdb_url + "/jurisdiction/" + user_role_jurisdiction._id;


                cURL document_curl = new cURL("PUT", null, jurisdiction_tree_url, user_role_jurisdiction_json, Program.config_timer_user_name, Program.config_timer_password);


                try
                {
                    string responseFromServer = await document_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);
                }
                catch (Exception ex)
                {
                    Log.Information($"jurisdiction_treeController:{ex}");
                }


                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
Пример #14
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post
        (
            [FromBody] mmria.common.model.couchdb.jurisdiction_tree jurisdiction_tree
        )
        {
            string jurisdiction_json;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                jurisdiction_json          = Newtonsoft.Json.JsonConvert.SerializeObject(jurisdiction_tree, settings);

                string jurisdiction_tree_url = Program.config_couchdb_url + "/jurisdiction/jurisdiction_tree";

                cURL document_curl = new cURL("PUT", null, jurisdiction_tree_url, jurisdiction_json, Program.config_timer_user_name, Program.config_timer_password);

                if (!string.IsNullOrWhiteSpace(this.Request.Cookies["AuthSession"]))
                {
                    string auth_session_value = this.Request.Cookies["AuthSession"];
                    document_curl.AddHeader("Cookie", "AuthSession=" + auth_session_value);
                    document_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_value);
                }

                try
                {
                    string responseFromServer = await document_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);
                }
                catch (Exception ex)
                {
                    Log.Information($"jurisdiction_treeController:{ex}");
                }

                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
Пример #15
0
        public async System.Threading.Tasks.Task <List <mmria.common.model.couchdb.migration_plan> > Get(string id)
        {
            List <mmria.common.model.couchdb.migration_plan> result = new List <mmria.common.model.couchdb.migration_plan>();

            try
            {
                string request_string = this.get_couch_db_url() + "/metadata/_all_docs?include_docs=true";

                if (!string.IsNullOrWhiteSpace(id))
                {
                    if (id == "2016-06-12T13:49:24.759Z")
                    {
                        return(null);
                    }

                    request_string = this.get_couch_db_url() + "/metadata/" + id;
                }

                var migration_plan_curl = new cURL("GET", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);
                var responseFromServer  = await migration_plan_curl.executeAsync();

                if (!string.IsNullOrWhiteSpace(id))
                {
                    result.Add(Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.migration_plan>(responseFromServer));
                }
                else
                {
                    var response_header = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.get_response_header <mmria.common.model.couchdb.migration_plan> >(responseFromServer);

                    foreach (var row in response_header.rows)
                    {
                        if (row.doc != null && row.doc.data_type == "migration-plan")
                        {
                            result.Add(row.doc);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #16
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.user> Get(string id)
        {
            mmria.common.model.couchdb.user result = null;
            try
            {
                string request_string = Program.config_couchdb_url + "/_users/" + id;

                var user_curl          = new cURL("PUT", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);
                var responseFromServer = await user_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.user>(responseFromServer);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #17
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> PutCheckCode
        (

        )
        {
            string check_code_json;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                System.IO.Stream dataStream0 = this.Request.Body;
                // Open the stream using a StreamReader for easy access.
                //dataStream0.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader reader0 = new System.IO.StreamReader(dataStream0);
                // Read the content.
                check_code_json = await reader0.ReadToEndAsync();

                string metadata_url = Program.config_couchdb_url + "/metadata/2016-06-12T13:49:24.759Z/mmria-check-code.js";

                var metadata_curl = new cURL("PUT", null, metadata_url, check_code_json, Program.config_timer_user_name, Program.config_timer_password, "text/*");

                if (!string.IsNullOrWhiteSpace(this.Request.Headers["If-Match"]))
                {
                    string If_Match = this.Request.Headers["If-Match"];
                    metadata_curl.AddHeader("If-Match", If_Match);
                }

                string responseFromServer = await metadata_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);

                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #18
0
        public async System.Threading.Tasks.Task <List <mmria.common.metadata.UI_Specification> > List()
        {
            Log.Information("Recieved message.");
            var result = new List <mmria.common.metadata.UI_Specification>();

            try
            {
                string ui_specification_url = Program.config_couchdb_url + $"/metadata/_all_docs?include_docs=true";

                var    curl = new cURL("GET", null, ui_specification_url, null, Program.config_timer_user_name, Program.config_timer_password);
                string responseFromServer = await curl.executeAsync();

                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings {
                    NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
                    MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore
                };
                var ui_specification_list = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.get_response_header <mmria.common.metadata.UI_Specification> > (responseFromServer, settings);

                foreach (var row in ui_specification_list.rows)
                {
                    var ui_specification = row.doc;
                    if
                    (
                        ui_specification.data_type == null ||
                        ui_specification.data_type != "ui-specification" ||
                        ui_specification._id == "2016-06-12T13:49:24.759Z" ||
                        ui_specification._id == "de-identified-list"
                    )
                    {
                        continue;
                    }
                    result.Add(row.doc);
                }
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
Пример #19
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.jurisdiction_tree> Get()
        {
            Log.Information("Recieved message.");
            mmria.common.model.couchdb.jurisdiction_tree result = null;

            try
            {
                string jurisdiction_tree_url = Program.config_couchdb_url + $"/jurisdiction/jurisdiction_tree";

                var    jurisdiction_curl    = new cURL("GET", null, jurisdiction_tree_url, null, Program.config_timer_user_name, Program.config_timer_password);
                string response_from_server = await jurisdiction_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.jurisdiction_tree>(response_from_server);
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
Пример #20
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post([FromBody] mmria.common.model.couchdb.migration_plan migration_plan)
        {
            //bool valid_login = false;

            string object_string = null;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                object_string = Newtonsoft.Json.JsonConvert.SerializeObject(migration_plan, settings);

                if (migration_plan._id == "2016-06-12T13:49:24.759Z")
                {
                    return(null);
                }

                string migration_plan_db_url = this.get_couch_db_url() + "/metadata/" + migration_plan._id;

                var migration_plan_curl = new cURL("PUT", null, migration_plan_db_url, object_string, Program.config_timer_user_name, Program.config_timer_password);
                var responseFromServer  = await migration_plan_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);

                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #21
0
        // GET api/values
        //public IEnumerable<master_record> Get()
        public async Task <System.Dynamic.ExpandoObject> Get(string case_id = null)
        {
            try
            {
                string request_string = Program.config_couchdb_url + "/de_id/_all_docs?include_docs=true";

                if (!string.IsNullOrWhiteSpace(case_id))
                {
                    request_string = Program.config_couchdb_url + "/de_id/" + case_id;
                }


                var    request_curl       = new cURL("GET", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);
                string responseFromServer = await request_curl.executeAsync();

                var result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (responseFromServer);

                return(result);



                /*
                 * < HTTP/1.1 200 OK
                 * < Set-Cookie: AuthSession=YW5uYTo0QUIzOTdFQjrC4ipN-D-53hw1sJepVzcVxnriEw;
                 * < Version=1; Path=/; HttpOnly
                 * > ...
                 * <
                 * {"ok":true}*/
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
Пример #22
0
        public async Task <System.Dynamic.ExpandoObject> Delete(string case_id = null, string rev = null)
        {
            try
            {
                string request_string = null;
                mmria.server.util.c_sync_document sync_document = null;

                if (!string.IsNullOrWhiteSpace(case_id) && !string.IsNullOrWhiteSpace(rev))
                {
                    request_string = Program.config_couchdb_url + "/mmrds/" + case_id + "?rev=" + rev;
                }
                else
                {
                    return(null);
                }

                var delete_report_curl  = new cURL("DELETE", null, request_string, null, Program.config_timer_user_name, Program.config_timer_password);
                var check_document_curl = new cURL("GET", null, Program.config_couchdb_url + "/mmrds/" + case_id, null, Program.config_timer_user_name, Program.config_timer_password);

                string document_json = null;
                // check if doc exists
                try
                {
                    document_json = await check_document_curl.executeAsync();

                    var check_docuement_curl_result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (document_json);
                    IDictionary <string, object> result_dictionary = check_docuement_curl_result as IDictionary <string, object>;
                    if (result_dictionary.ContainsKey("_rev"))
                    {
                        request_string = Program.config_couchdb_url + "/mmrds/" + case_id + "?rev=" + result_dictionary ["_rev"];
                        //System.Console.WriteLine ("json\n{0}", object_string);
                    }
                }
                catch (Exception ex)
                {
                    // do nothing for now document doesn't exsist.
                    System.Console.WriteLine($"err caseController.Delete\n{ex}");
                }

                string responseFromServer = await delete_report_curl.executeAsync();;
                var    result             = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (responseFromServer);


                if (!string.IsNullOrWhiteSpace(document_json))
                {
                    var Sync_Document_Message = new mmria.server.model.actor.Sync_Document_Message
                                                (
                        case_id,
                        document_json,
                        "DELETE"
                                                );

                    _actorSystem.ActorOf(Props.Create <mmria.server.model.actor.Synchronize_Case>()).Tell(Sync_Document_Message);
                }
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
Пример #23
0
        /*
         * DELETE /recipes/FishStew?rev=1-9c65296036141e575d32ba9c034dd3ee HTTP/1.1
         * Accept: application/json
         * Host: localhost:5984
         * or
         *
         * DELETE /recipes/FishStew HTTP/1.1
         * Accept: application/json
         * If-Match: 1-9c65296036141e575d32ba9c034dd3ee
         * Host: localhost:5984
         *
         *
         * HTTP/1.1 200 OK
         * Cache-Control: must-revalidate
         * Content-Length: 71
         * Content-Type: application/json
         * Date: Wed, 14 Aug 2013 12:23:13 GMT
         * ETag: "2-056f5f44046ecafc08a2bc2b9c229e20"
         * Server: CouchDB (Erlang/OTP)
         *
         * {
         * "id": "FishStew",
         * "ok": true,
         * "rev": "2-056f5f44046ecafc08a2bc2b9c229e20"
         * }
         *
         *
         */
        public async System.Threading.Tasks.Task <System.Dynamic.ExpandoObject> Delete(string case_id = null, string rev = null)
        {
            try
            {
                string request_string = null;

                if (!string.IsNullOrWhiteSpace(case_id) && !string.IsNullOrWhiteSpace(rev))
                {
                    request_string = Program.config_couchdb_url + "/mmrds/" + case_id + "?rev=" + rev;
                }
                else
                {
                    return(null);
                }

                var delete_report_curl  = new cURL("DELETE", null, request_string, null);
                var check_document_curl = new cURL("GET", null, Program.config_couchdb_url + "/mmrds/" + case_id, null, null, null);

                if (this.Request.Headers.Contains("Cookie") && this.Request.Headers.GetValues("Cookie").Count() > 0)
                {
                    string[] cookie_set = this.Request.Headers.GetValues("Cookie").First().Split(';');
                    for (int i = 0; i < cookie_set.Length; i++)
                    {
                        string[] auth_session_token = cookie_set[i].Split('=');
                        if (auth_session_token[0].Trim() == "AuthSession")
                        {
                            delete_report_curl.AddHeader("Cookie", "AuthSession=" + auth_session_token[1]);
                            delete_report_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_token[1]);
                            check_document_curl.AddHeader("Cookie", "AuthSession=" + auth_session_token [1]);
                            check_document_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_token [1]);
                            break;
                        }
                    }
                }


                // check if doc exists

                try
                {
                    string document_json = null;
                    document_json = await check_document_curl.executeAsync();

                    var check_docuement_curl_result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (document_json);
                    IDictionary <string, object> result_dictionary = check_docuement_curl_result as IDictionary <string, object>;
                    if (result_dictionary.ContainsKey("_rev"))
                    {
                        request_string = Program.config_couchdb_url + "/mmrds/" + case_id + "?rev=" + result_dictionary ["_rev"];
                        //System.Console.WriteLine ("json\n{0}", object_string);
                    }
                }
                catch (Exception ex)
                {
                    // do nothing for now document doesn't exsist.
                    System.Console.Write($" caseController Delete 1 Error {ex}");
                }



                string responseFromServer = await delete_report_curl.executeAsync();

                var result = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (responseFromServer);

                return(result);
            }
            catch (Exception ex)
            {
                System.Console.Write($" caseController Delete 2 Error {ex}");
            }

            return(null);
        }
Пример #24
0
        public async Task <mmria.common.model.couchdb.get_sortable_view_reponse_header <mmria.common.model.couchdb.user_role_jurisdiction> > Get
        (
            int skip          = 0,
            int take          = 25,
            string sort       = "by_date_created",
            string search_key = null,
            bool descending   = false
        )
        {
            /*
             *
             * http://localhost:5984/de_id/_design/sortable/_view/conflicts
             *
             *
             * by_date_created
             * by_created_by
             * by_date_last_updated
             * by_last_updated_by
             * by_role_name
             * by_user_id
             * by_parent_id
             * by_jurisdiction_id
             * by_is_active
             * by_effective_start_date
             * by_effective_end_date
             *
             *
             * date_created
             * created_by
             * date_last_updated
             * last_updated_by
             * role_name
             * user_id
             * parent_id
             * jurisdiction_id
             * is_active
             * effective_start_date
             * effective_end_date
             *
             */

            var    jurisdiction_hashset = mmria.server.util.authorization_user.get_current_jurisdiction_id_set_for(User);
            string sort_view            = sort.ToLower();

            switch (sort_view)
            {
            case "by_date_created":
            case "by_created_by":
            case "by_date_last_updated":
            case "by_last_updated_by":
            case "by_role_name":
            case "by_user_id":
            case "by_parent_id":
            case "by_jurisdiction_id":
            case "by_is_active":
            case "by_effective_start_date":
            case "by_effective_end_date":
                break;

            default:
                sort_view = "by_date_created";
                break;
            }



            try
            {
                System.Text.StringBuilder request_builder = new System.Text.StringBuilder();
                request_builder.Append(Program.config_couchdb_url);
                request_builder.Append($"/jurisdiction/_design/sortable/_view/{sort_view}?");


                if (string.IsNullOrWhiteSpace(search_key))
                {
                    if (skip > -1)
                    {
                        request_builder.Append($"skip={skip}");
                    }
                    else
                    {
                        request_builder.Append("skip=0");
                    }


                    if (take > -1)
                    {
                        request_builder.Append($"&limit={take}");
                    }

                    if (descending)
                    {
                        request_builder.Append("&descending=true");
                    }
                }
                else
                {
                    request_builder.Append("skip=0");

                    if (descending)
                    {
                        request_builder.Append("&descending=true");
                    }
                }

                var    user_role_jurisdiction_curl = new cURL("GET", null, request_builder.ToString(), null, Program.config_timer_user_name, Program.config_timer_password);
                string response_from_server        = await user_role_jurisdiction_curl.executeAsync();

                var case_view_response = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.get_sortable_view_reponse_header <mmria.common.model.couchdb.user_role_jurisdiction> >(response_from_server);

                if (string.IsNullOrWhiteSpace(search_key))
                {
                    var result = new mmria.common.model.couchdb.get_sortable_view_reponse_header <mmria.common.model.couchdb.user_role_jurisdiction>();
                    result.offset     = case_view_response.offset;
                    result.total_rows = case_view_response.total_rows;

                    foreach (mmria.common.model.couchdb.get_sortable_view_response_item <mmria.common.model.couchdb.user_role_jurisdiction> cvi in case_view_response.rows)
                    {
                        bool is_jurisdiction_ok = false;
                        foreach (string jurisdiction_item in jurisdiction_hashset)
                        {
                            var regex = new System.Text.RegularExpressions.Regex("^" + @jurisdiction_item);
                            if (cvi.value.jurisdiction_id == null)
                            {
                                cvi.value.jurisdiction_id = "/";
                            }

                            if (regex.IsMatch(cvi.value.jurisdiction_id))
                            {
                                is_jurisdiction_ok = true;
                                break;
                            }
                        }

                        if (is_jurisdiction_ok)
                        {
                            result.rows.Add(cvi);
                        }
                    }
                    result.total_rows = result.rows.Count;
                    return(result);
                }
                else
                {
                    string key_compare = search_key.ToLower().Trim(new char [] { '"' });

                    var result = new mmria.common.model.couchdb.get_sortable_view_reponse_header <mmria.common.model.couchdb.user_role_jurisdiction>();
                    result.offset     = case_view_response.offset;
                    result.total_rows = case_view_response.total_rows;

                    //foreach(mmria.common.model.couchdb.user_role_jurisdiction cvi in case_view_response.rows)
                    foreach (mmria.common.model.couchdb.get_sortable_view_response_item <mmria.common.model.couchdb.user_role_jurisdiction> cvi in case_view_response.rows)
                    {
/*
 * date_created
 * created_by
 * date_last_updated
 * last_updated_by
 * role_name
 * user_id
 * parent_id
 * jurisdiction_id
 * is_active
 * effective_start_date
 * effective_end_date
 */

                        bool add_item = false;
                        if (cvi.value.jurisdiction_id != null && cvi.value.jurisdiction_id.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }

                        if (cvi.value.is_active != null && cvi.value.is_active.HasValue)
                        {
                            if (bool.TryParse(key_compare, out bool is_active))
                            {
                                if (cvi.value.is_active.Value == is_active)
                                {
                                    add_item = true;
                                }
                            }
                        }

                        if (cvi.value.role_name != null && cvi.value.role_name.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }

                        if (cvi.value.user_id != null && cvi.value.user_id.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }


                        if (cvi.value.effective_start_date != null && cvi.value.effective_start_date.HasValue)
                        {
                            if (DateTime.TryParse(key_compare, out DateTime is_date))
                            {
                                if (cvi.value.effective_start_date.Value == is_date)
                                {
                                    add_item = true;
                                }
                            }
                        }

                        if (cvi.value.effective_end_date != null && cvi.value.effective_end_date.HasValue)
                        {
                            if (DateTime.TryParse(key_compare, out DateTime is_date))
                            {
                                if (cvi.value.effective_end_date.Value == is_date)
                                {
                                    add_item = true;
                                }
                            }
                        }



                        if (cvi.value.date_created != null && cvi.value.date_created.HasValue)
                        {
                            if (DateTime.TryParse(key_compare, out DateTime is_date))
                            {
                                if (cvi.value.date_created.Value == is_date)
                                {
                                    add_item = true;
                                }
                            }
                        }



                        if (cvi.value.date_last_updated != null && cvi.value.date_last_updated.HasValue)
                        {
                            if (DateTime.TryParse(key_compare, out DateTime is_date))
                            {
                                if (cvi.value.date_last_updated.Value == is_date)
                                {
                                    add_item = true;
                                }
                            }
                        }

                        if (cvi.value.created_by != null && cvi.value.created_by.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }

                        if (cvi.value.last_updated_by != null && cvi.value.last_updated_by.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }


                        bool is_jurisdiction_ok = false;
                        foreach (string jurisdiction_item in jurisdiction_hashset)
                        {
                            var regex = new System.Text.RegularExpressions.Regex("^" + @jurisdiction_item);

                            if (cvi.value.jurisdiction_id == null)
                            {
                                cvi.value.jurisdiction_id = "/";
                            }


                            if (regex.IsMatch(cvi.value.jurisdiction_id))
                            {
                                is_jurisdiction_ok = true;
                                break;
                            }
                        }

                        if (add_item && is_jurisdiction_ok)
                        {
                            result.rows.Add(cvi);
                        }
                    }

                    result.total_rows = result.rows.Count;
                    result.rows       = result.rows.Skip(skip).Take(take).ToList();

                    return(result);
                }


                /*
                 * < HTTP/1.1 200 OK
                 * < Set-Cookie: AuthSession=YW5uYTo0QUIzOTdFQjrC4ipN-D-53hw1sJepVzcVxnriEw;
                 * < Version=1; Path=/; HttpOnly
                 * > ...
                 * <
                 * {"ok":true}*/
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
Пример #25
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post()
        {
            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            //if(!string.IsNullOrWhiteSpace(json))
            try
            {
                System.IO.Stream dataStream0 = this.Request.Body;
                // Open the stream using a StreamReader for easy access.
                //dataStream0.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader reader0 = new System.IO.StreamReader(dataStream0);
                // Read the content.
                string validator_js_text = await reader0.ReadToEndAsync();

                string metadata_url = Program.config_couchdb_url + "/metadata/2016-06-12T13:49:24.759Z/validator.js";

                var validator_curl = new cURL("PUT", null, metadata_url, validator_js_text, Program.config_timer_user_name, Program.config_timer_password, "text/*");

/*
 *                              System.Net.WebRequest request = System.Net.WebRequest.Create(new System.Uri(metadata_url));
 *                              request.Method = "PUT";
 *                              request.ContentType = "text/*";
 *                              request.ContentLength = validator_js_text.Length;
 *                              request.PreAuthenticate = false;
 *
 *                              if (!string.IsNullOrWhiteSpace(this.Request.Cookies["AuthSession"]))
 *                              {
 *                                      string auth_session_value = this.Request.Cookies["AuthSession"];
 *                                      request.Headers.Add("Cookie", "AuthSession=" + auth_session_value);
 *                                      request.Headers.Add("X-CouchDB-WWW-Authenticate", auth_session_value);
 *                                      request.Headers.Add("X-CouchDB-WWW-Authenticate", auth_session_value);
 *                              }
 */
                if (!string.IsNullOrWhiteSpace(this.Request.Headers["If-Match"]))
                {
                    string If_Match = this.Request.Headers["If-Match"];
                    validator_curl.AddHeader("If-Match", If_Match);
                }

                try
                {
                    /*
                     * streamWriter.Write(validator_js_text);
                     * streamWriter.Flush();
                     * streamWriter.Close();
                     *
                     * System.Net.WebResponse response = (System.Net.HttpWebResponse) await request.GetResponseAsync();
                     * System.IO.Stream dataStream = response.GetResponseStream ();
                     * System.IO.StreamReader reader = new System.IO.StreamReader (dataStream);
                     *
                     *                                      if(response.Headers["Set-Cookie"] != null)
                     * {
                     *      this.Response.Headers.Add("Set-Cookie", response.Headers["Set-Cookie"]);
                     * }
                     */
                    string responseFromServer = await validator_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);



                    //System.Threading.Tasks.Task.Run( new Action(()=> { var f = new GenerateSwaggerFile(); System.IO.File.WriteAllText(Program.config_file_root_folder + "/api-docs/api.json", f.generate(metadata)); }));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }



                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #26
0
        public async Task <IDictionary <string, string> > Get
        (
            string p_target_db_user_name,
            string p_target_db_password

        )
        {
            Dictionary <string, string> result = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            //var curl = new cURL ("GET", null, p_source_db + "/mmrds/_all_docs?include_docs=true", null, p_user_name, p_password);
            if (!await url_endpoint_exists(Program.config_couchdb_url, p_target_db_user_name, p_target_db_password))
            {
                result.Add("End point url NOT available:", Program.config_couchdb_url);
                return(result);
            }

            try
            {
                string current_directory = AppContext.BaseDirectory;
                if (!System.IO.Directory.Exists(System.IO.Path.Combine(current_directory, "database-scripts")))
                {
                    current_directory = System.IO.Directory.GetCurrentDirectory();
                }

                if (await url_endpoint_exists(Program.config_couchdb_url + "/metadata", p_target_db_user_name, p_target_db_password))
                {
                    var metadata_curl = new cURL("DELETE", null, Program.config_couchdb_url + "/metadata", null, p_target_db_user_name, p_target_db_password);
                    Log.Information($"metadata_curl\n{await metadata_curl.executeAsync ()}");
                }

                try
                {
                    await mmria.server.util.c_db_setup.UpdateMetadata(current_directory);
                }
                catch (Exception ex)
                {
                    Log.Information($"unable to configure metadata:\n{ex}");
                }



                if (!await url_endpoint_exists(Program.config_couchdb_url + "/mmrds", p_target_db_user_name, p_target_db_password))
                {
                    var mmrds_curl = new cURL("PUT", null, Program.config_couchdb_url + "/mmrds", null, p_target_db_user_name, p_target_db_password);
                    Log.Information($"mmrds_curl\n{ await mmrds_curl.executeAsync ()}");

                    await new cURL("PUT", null, Program.config_couchdb_url + "/mmrds/_security", "{\"admins\":{\"names\":[],\"roles\":[\"form_designer\"]},\"members\":{\"names\":[],\"roles\":[\"abstractor\",\"data_analyst\",\"timer\"]}}", p_target_db_user_name, p_target_db_password).executeAsync();
                    Log.Information($"mmrds/_security completed successfully");
                }

                try
                {
                    string case_design_sortable = System.IO.File.OpenText(System.IO.Path.Combine(current_directory, "database-scripts/case_design_sortable.json")).ReadToEnd();

                    await sync_document(case_design_sortable, Program.config_couchdb_url + "/mmrds/_design/sortable", p_target_db_user_name, p_target_db_password);


                    string case_store_design_auth = System.IO.File.OpenText(System.IO.Path.Combine(current_directory, "database-scripts/case_store_design_auth.json")).ReadToEnd();
                    await sync_document(case_store_design_auth, Program.config_couchdb_url + "/mmrds/_design/auth", p_target_db_user_name, p_target_db_password);
                }
                catch (Exception ex)
                {
                    Log.Information($"unable to configure mmrds database:\n{ex}");
                }


                if (!await url_endpoint_exists(Program.config_couchdb_url + "/export_queue", p_target_db_user_name, p_target_db_password))
                {
                    System.Console.WriteLine("Creating export_queue db.");
                    var export_queue_curl = new cURL("PUT", null, Program.config_couchdb_url + "/export_queue", null, p_target_db_user_name, p_target_db_password);
                    System.Console.WriteLine(await export_queue_curl.executeAsync());
                    await new cURL("PUT", null, Program.config_couchdb_url + "/export_queue/_security", "{\"admins\":{\"names\":[],\"roles\":[\"abstractor\"]},\"members\":{\"names\":[],\"roles\":[\"abstractor\"]}}", p_target_db_user_name, p_target_db_password).executeAsync();
                }
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
                result.Add("db_setupController.Get Exception", ex.ToString());
            }
            return(result);
        }
        public async System.Threading.Tasks.Task <IList <mmria.common.model.couchdb.user_role_jurisdiction> > Get(string p_urj_id)
        {
            Log.Information("Recieved message.");
            var result = new List <mmria.common.model.couchdb.user_role_jurisdiction>();

            try
            {
                string jurisdiction_url = Program.config_couchdb_url + $"/jurisdiction/" + p_urj_id;
                if (string.IsNullOrWhiteSpace(p_urj_id))
                {
                    jurisdiction_url = Program.config_couchdb_url + $"/jurisdiction/_all_docs?include_docs=true";

                    var    case_curl          = new cURL("GET", null, jurisdiction_url, null, Program.config_timer_user_name, Program.config_timer_password);
                    string responseFromServer = await case_curl.executeAsync();

                    //var user_role_list = Newtonsoft.Json.JsonConvert.DeserializeObject<mmria.common.model.couchdb.user_role_jurisdiction[]> (responseFromServer);

                    //var user_role_list_expando_object = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Dynamic.ExpandoObject> (responseFromServer);

                    var user_role_list = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.get_response_header <mmria.common.model.couchdb.user_role_jurisdiction> > (responseFromServer);



                    foreach (var row in user_role_list.rows)
                    {
                        var user_role_jurisdiction = row.doc;

                        if
                        (
                            user_role_jurisdiction.data_type != null &&
                            user_role_jurisdiction.data_type == mmria.common.model.couchdb.user_role_jurisdiction.user_role_jursidiction_const &&
                            mmria.server.util.authorization_user.is_authorized_to_handle_jurisdiction_id(User, mmria.server.util.ResourceRightEnum.ReadUser, user_role_jurisdiction))
                        {
                            result.Add(user_role_jurisdiction);
                        }
                    }
                }
                else
                {
                    jurisdiction_url = Program.config_couchdb_url + $"/jurisdiction/" + p_urj_id;
                    var    case_curl          = new cURL("GET", null, jurisdiction_url, null, Program.config_timer_user_name, Program.config_timer_password);
                    string responseFromServer = await case_curl.executeAsync();

                    var user_role_jurisdiction = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.user_role_jurisdiction> (responseFromServer);


                    if
                    (
                        user_role_jurisdiction.data_type != null &&
                        user_role_jurisdiction.data_type == mmria.common.model.couchdb.user_role_jurisdiction.user_role_jursidiction_const &&
                        mmria.server.util.authorization_user.is_authorized_to_handle_jurisdiction_id(User, mmria.server.util.ResourceRightEnum.ReadUser, user_role_jurisdiction)
                    )
                    {
                        result.Add(user_role_jurisdiction);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Information($"{ex}");
            }

            return(result);
        }
Пример #28
0
        public async Task <mmria.common.model.couchdb.document_put_response> Post
        (
            [FromBody] System.Dynamic.ExpandoObject queue_request
        )
        {
            string auth_session_token = null;

            string object_string = null;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();


            try
            {
                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                object_string = Newtonsoft.Json.JsonConvert.SerializeObject(queue_request, settings);

                var    byName  = (IDictionary <string, object>)queue_request;
                var    temp_id = byName["_id"];
                string id_val  = null;

                if (temp_id is DateTime)
                {
                    id_val = string.Concat(((DateTime)temp_id).ToString("s"), "Z");
                }
                else
                {
                    id_val = temp_id.ToString();
                }

                var home_record = (IDictionary <string, object>)byName["home_record"];
                if (!home_record.ContainsKey("jurisdiction_id"))
                {
                    home_record.Add("jurisdiction_id", "/");
                }

                if (!mmria.server.util.authorization_case.is_authorized_to_handle_jurisdiction_id(User, mmria.server.util.ResourceRightEnum.WriteCase, home_record["jurisdiction_id"].ToString()))
                {
                    Console.Write($"unauthorized PUT {home_record["jurisdiction_id"]}: {byName["_id"]}");
                    return(result);
                }


                // begin - check if doc exists
                try
                {
                    var    check_document_curl = new cURL("GET", null, Program.config_couchdb_url + "/mmrds/" + id_val, null, Program.config_timer_user_name, Program.config_timer_password);
                    string check_document_json = await check_document_curl.executeAsync();

                    var check_document_expando_object = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Dynamic.ExpandoObject> (check_document_json);
                    IDictionary <string, object> result_dictionary = check_document_expando_object as IDictionary <string, object>;

                    if (!mmria.server.util.authorization_case.is_authorized_to_handle_jurisdiction_id(User, mmria.server.util.ResourceRightEnum.WriteCase, check_document_expando_object))
                    {
                        Console.Write($"unauthorized PUT {result_dictionary["jurisdiction_id"]}: {result_dictionary["_id"]}");
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    // do nothing for now document doesn't exsist.
                    System.Console.WriteLine($"err caseController.Post\n{ex}");
                }
                // end - check if doc exists



                string metadata_url  = Program.config_couchdb_url + "/mmrds/" + id_val;
                cURL   document_curl = new cURL("PUT", null, metadata_url, object_string, Program.config_timer_user_name, Program.config_timer_password);

                try
                {
                    string responseFromServer = await document_curl.executeAsync();

                    result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);
                }
                catch (Exception ex)
                {
                    Console.Write("auth_session_token: {0}", auth_session_token);
                    Console.WriteLine(ex);
                }

                var Sync_Document_Message = new mmria.server.model.actor.Sync_Document_Message
                                            (
                    id_val,
                    object_string
                                            );

                _actorSystem.ActorOf(Props.Create <mmria.server.model.actor.Synchronize_Case>()).Tell(Sync_Document_Message);


                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                Console.Write("auth_session_token: {0}", auth_session_token);
                Console.WriteLine(ex);
            }

            return(result);
        }
Пример #29
0
        public async System.Threading.Tasks.Task <mmria.common.model.couchdb.document_put_response> Post()
        {
            //bool valid_login = false;
            //mmria.common.data.api.Set_Queue_Request queue_request = null;
            export_queue_item queue_item         = null;
            string            auth_session_token = null;

            string object_string = null;

            mmria.common.model.couchdb.document_put_response result = new mmria.common.model.couchdb.document_put_response();

            try
            {
                System.IO.Stream dataStream0 = await this.Request.Content.ReadAsStreamAsync();

                // Open the stream using a StreamReader for easy access.
                //dataStream0.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader reader0 = new System.IO.StreamReader(dataStream0);
                // Read the content.
                object_string = reader0.ReadToEnd();

                queue_item = Newtonsoft.Json.JsonConvert.DeserializeObject <export_queue_item>(object_string);
            }
            catch (Exception ex)
            {
                //Console.WriteLine (ex);
            }

            //if(queue_request.case_list.Length == 1)
            try
            {
                Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
                object_string = Newtonsoft.Json.JsonConvert.SerializeObject(queue_item, settings);

                string export_queue_request_url = Program.config_couchdb_url + "/export_queue/" + queue_item._id;

                var export_queue_curl = new cURL("PUT", null, export_queue_request_url, object_string, null, null);

                if (this.Request.Headers.Contains("Cookie") && this.Request.Headers.GetValues("Cookie").Count() > 0)
                {
                    string[] cookie_set = this.Request.Headers.GetValues("Cookie").First().Split(';');
                    for (int i = 0; i < cookie_set.Length; i++)
                    {
                        string[] auth_session_token_item = cookie_set[i].Split('=');
                        if (auth_session_token_item[0].Trim() == "AuthSession")
                        {
                            auth_session_token = auth_session_token_item[1];
                            export_queue_curl.AddHeader("Cookie", "AuthSession=" + auth_session_token);
                            export_queue_curl.AddHeader("X-CouchDB-WWW-Authenticate", auth_session_token);


                            break;
                        }
                    }
                }


                string responseFromServer = await export_queue_curl.executeAsync();

                result = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.document_put_response>(responseFromServer);


                if (!result.ok)
                {
                }
            }
            catch (Exception ex)
            {
                //Console.Write("auth_session_token: {0}", auth_session_token);
                //Console.WriteLine (ex);
            }

            return(result);
        }
Пример #30
0
        public async Task <mmria.common.model.couchdb.get_sortable_view_reponse_header <mmria.common.model.couchdb.migration_plan> > Get
        (
            int skip          = 0,
            int take          = 25,
            string sort       = "by_date_created",
            string search_key = null,
            bool descending   = false
        )
        {
            string sort_view = sort.ToLower();

            switch (sort_view)
            {
            case "by_date_created":
            case "by_created_by":
            case "by_date_last_updated":
            case "by_last_updated_by":
            case "by_name":
            case "by_description":
                break;

            default:
                sort_view = "by_date_created";
                break;
            }

            try
            {
                System.Text.StringBuilder request_builder = new System.Text.StringBuilder();
                request_builder.Append(Program.config_couchdb_url);
                request_builder.Append($"/metadata/_design/sortable/_view/{sort_view}?");
                //http://localhost:5984/metadata/_design/sortable/_view/by_date_last_updated

                if (string.IsNullOrWhiteSpace(search_key))
                {
                    if (skip > -1)
                    {
                        request_builder.Append($"skip={skip}");
                    }
                    else
                    {
                        request_builder.Append("skip=0");
                    }


                    if (take > -1)
                    {
                        request_builder.Append($"&limit={take}");
                    }

                    if (descending)
                    {
                        request_builder.Append("&descending=true");
                    }
                }
                else
                {
                    request_builder.Append("skip=0");

                    if (descending)
                    {
                        request_builder.Append("&descending=true");
                    }
                }


                var    migration_plan_curl  = new cURL("GET", null, request_builder.ToString(), null, Program.config_timer_user_name, Program.config_timer_password);
                string response_from_server = await migration_plan_curl.executeAsync();

                var migration_plan_view_response = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.common.model.couchdb.get_sortable_view_reponse_header <mmria.common.model.couchdb.migration_plan> >(response_from_server);

                if (string.IsNullOrWhiteSpace(search_key))
                {
                    return(migration_plan_view_response);
                }
                else
                {
                    string key_compare = search_key.ToLower().Trim(new char [] { '"' });

                    var result = new mmria.common.model.couchdb.get_sortable_view_reponse_header <mmria.common.model.couchdb.migration_plan>();
                    result.offset     = migration_plan_view_response.offset;
                    result.total_rows = migration_plan_view_response.total_rows;

                    foreach (mmria.common.model.couchdb.get_sortable_view_response_item <mmria.common.model.couchdb.migration_plan> cvi in migration_plan_view_response.rows)
                    {
                        bool add_item = false;

                        if (cvi.value.name != null && cvi.value.name.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }

                        if (cvi.value.description != null && cvi.value.description.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }

                        if (cvi.value.date_created != null && cvi.value.date_created.HasValue)
                        {
                            if (DateTime.TryParse(key_compare, out DateTime is_date))
                            {
                                if (cvi.value.date_created.Value == is_date)
                                {
                                    add_item = true;
                                }
                            }
                        }

                        if (cvi.value.date_last_updated != null && cvi.value.date_last_updated.HasValue)
                        {
                            if (DateTime.TryParse(key_compare, out DateTime is_date))
                            {
                                if (cvi.value.date_last_updated.Value == is_date)
                                {
                                    add_item = true;
                                }
                            }
                        }

                        if (cvi.value.created_by != null && cvi.value.created_by.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }

                        if (cvi.value.last_updated_by != null && cvi.value.last_updated_by.Equals(key_compare, StringComparison.OrdinalIgnoreCase))
                        {
                            add_item = true;
                        }


                        if (add_item)
                        {
                            result.rows.Add(cvi);
                        }
                    }

                    result.total_rows = result.rows.Count;
                    result.rows       = result.rows.Skip(skip).Take(take).ToList();

                    return(result);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }