コード例 #1
0
        public ActionResult Details(JhroCaseViewModel vm)
        {
            if (vm != null)
            {
                JhroCase jc = null;
                if (vm.Id > 0)
                {
                    jc = this.sourceTasks.GetJhroCase(vm.Id);
                }
                else if (!string.IsNullOrEmpty(vm.CaseNumber))
                {
                    jc = this.sourceTasks.GetJhroCase(vm.CaseNumber);
                }

                if (jc != null)
                {
                    ViewBag.JhroCase = jc;

                    HrdbCase hrdbCase = (HrdbCase)StreamUtil.Deserialize(jc.HrdbContentsSerialized);

                    return(View(hrdbCase));
                }
            }
            return(new HttpNotFoundResult());
        }
コード例 #2
0
        public JsonNetResult FindMatchingEventCandidates(int id)
        {
            JhroCase jc = this.sourceTasks.GetJhroCase(id);

            if (jc != null)
            {
                // if not already linked to an Event...
                if (!jc.Events.Any())
                {
                    HrdbCase hrdbCase = (HrdbCase)StreamUtil.Deserialize(jc.HrdbContentsSerialized);

                    // ...find potential matching Events to link to this case
                    return(JsonNet(new
                    {
                        Events = this.eventMatchingTasks.FindMatchingEventCandidates(jc, hrdbCase)
                    }));
                }
                else
                {
                    Response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                    Response.StatusDescription = "That case already has an event linked.";
                    return(JsonNet(Response.StatusDescription));
                }
            }
            else
            {
                Response.StatusCode        = (int)HttpStatusCode.NotFound;
                Response.StatusDescription = "That case doesn't exist.";
                return(JsonNet(Response.StatusDescription));
            }
        }
コード例 #3
0
        public IDictionary <string, HrdbCase> GetAndPersistHrdbCases(DateTime from, DateTime to, ISession session)
        {
            var profiler = MiniProfiler.Current;
            IDictionary <string, HrdbCase> dict = null;

            using (profiler.Step("Calling webservice..."))
                dict = this.hrdbRepo.GetHrdbCases(from, to);

            using (profiler.Step("Persisting cases..."))
            {
                foreach (KeyValuePair <string, HrdbCase> kvp in dict)
                {
                    JhroCase jc = this.sourceTasks.GetJhroCase(session, kvp.Value.CaseCode);
                    if (jc == null)
                    {
                        jc = new JhroCase()
                        {
                            CaseNumber = kvp.Key
                        }
                    }
                    ;

                    // serialize data received over the wire
                    jc.HrdbContentsSerialized = StreamUtil.Serialize(kvp.Value);

                    this.sourceTasks.SaveJhroCase(session, jc);
                }
            }

            return(dict);
        }
    }
コード例 #4
0
        public JsonNetResult CreateModal(JhroCaseViewModel vm)
        {
            JhroCase existing = this.sourceTasks.GetJhroCase(vm.CaseNumber);

            if (existing != null)
            {
                ModelState.AddModelError("CaseNumber", "Case code already exists.");
            }

            if (ModelState.IsValid)
            {
                JhroCase jhroCase = new JhroCase();
                jhroCase.CaseNumber = vm.CaseNumber;
                jhroCase            = this.sourceTasks.SaveJhroCase(jhroCase);
                return(JsonNet(new
                {
                    Id = jhroCase.Id,
                    CaseNumber = jhroCase.CaseNumber,
                    WasSuccessful = true
                }));
            }
            else
            {
                return(JsonNet(this.GetErrorsForJson()));
            }
        }
コード例 #5
0
        public IDictionary <string, IList <object> > FindMatchingEventCandidates(JhroCase jhroCase, HrdbCase hrdbCase)
        {
            IDictionary <string, IList <object> > results = new Dictionary <string, IList <object> >();

            string caseCode = jhroCase != null ? jhroCase.CaseNumber : (hrdbCase != null ? hrdbCase.CaseCode : null);

            // search Event.Notes field for mention of the case code
            results["CodeInEventNotes"] = this.eventTasks.SearchEventNotes(caseCode).Select(x => x.ToShortHeadlineJSON()).ToList();

            // search EventSource commentaries and notes for mention of the case code
            results["CodeInEventSourceCommentary"] = this.sourceAttachmentTasks.SearchEventSources(caseCode)
                                                     .Select(x => x.Event)
                                                     .Distinct()
                                                     .Select(x => x.ToShortHeadlineJSON())
                                                     .ToList();

            // search fields indexed by Lucene
            if (hrdbCase != null)
            {
                results["DateAndLocation"] = this.luceneTasks
                                             .FindMatchingEventCandidates(hrdbCase.StartDate.HasValue ? hrdbCase.StartDate : null,
                                                                          hrdbCase.EndDate.HasValue ? hrdbCase.EndDate : null,
                                                                          hrdbCase.CaseCode, hrdbCase.TownVillage, hrdbCase.Subregion, hrdbCase.Region)
                                             .Select(x => this.eventTasks.GetEvent(new EventDataTableView(x).Id).ToShortHeadlineJSON())
                                             .Distinct()
                                             .ToList();
            }

            return(results);
        }
コード例 #6
0
 public JhroCaseViewModel(JhroCase jhroCase)
 {
     if (jhroCase != null)
     {
         this.Id         = jhroCase.Id;
         this.CaseNumber = jhroCase.CaseNumber;
     }
 }
コード例 #7
0
ファイル: SourceTasks.cs プロジェクト: ruacol/profiling2
 public JhroCase SaveJhroCase(JhroCase jhroCase)
 {
     if (jhroCase != null)
     {
         return(this.jhroCaseRepo.SaveOrUpdate(jhroCase));
     }
     return(jhroCase);
 }
コード例 #8
0
ファイル: Event.cs プロジェクト: ruacol/profiling2
        // data modification methods

        public virtual void AddJhroCase(JhroCase jc)
        {
            if (this.JhroCases.Contains(jc))
            {
                return;
            }

            this.JhroCases.Add(jc);
        }
コード例 #9
0
        public JsonNetResult Name(int id)
        {
            JhroCase jhroCase = this.sourceTasks.GetJhroCase(id);

            if (jhroCase != null)
            {
                return(JsonNet(new
                {
                    Id = id,
                    Name = jhroCase.CaseNumber
                }));
            }
            else
            {
                return(JsonNet(string.Empty));
            }
        }
コード例 #10
0
ファイル: EventsController.cs プロジェクト: ruacol/profiling2
        public ActionResult LinkCases()
        {
            foreach (Event e in this.eventTasks.GetAllEvents().Where(x => x.EventSources.Where(y => y.HasCaseCode()).Any()))
            {
                foreach (string code in e.GetCaseCodesInEventSources())
                {
                    JhroCase jc = this.sourceTasks.GetJhroCase(code);
                    if (jc != null)
                    {
                        e.AddJhroCase(jc);
                        this.eventTasks.SaveEvent(e);
                        log.Info("Linking EventID=" + e.Id.ToString() + " with JhroCase.CaseNumber=" + jc.CaseNumber);
                    }
                }
            }

            return(RedirectToAction("WithCases"));
        }
コード例 #11
0
        public ActionResult Link(int id)
        {
            JhroCase jc = this.sourceTasks.GetJhroCase(id);

            if (jc != null)
            {
                int eventId;
                if (int.TryParse(Request.QueryString["eventId"], out eventId))
                {
                    Event e = this.eventTasks.GetEvent(eventId);
                    if (e != null)
                    {
                        e.AddJhroCase(jc);
                        e = this.eventTasks.SaveEvent(e);
                        return(RedirectToAction("Case", "Hrdb", new { area = "Profiling", id = id }));
                    }
                }
            }
            return(new HttpNotFoundResult());
        }
コード例 #12
0
ファイル: EventsController.cs プロジェクト: ruacol/profiling2
        [Transaction]  // HrdbCaseViewModel creates a location if none exists
        public ActionResult Import(JhroCaseViewModel vm)
        {
            JhroCase jc = null;

            if (vm.Id > 0)
            {
                jc = this.sourceTasks.GetJhroCase(vm.Id);
            }
            else if (!string.IsNullOrEmpty(vm.CaseNumber))
            {
                jc = this.sourceTasks.GetJhroCase(vm.CaseNumber);
            }

            if (jc != null)
            {
                ModelState.Remove("CaseNumber");  // undo unintended validation check (happens because we use JhroCaseViewModel not as intended)
                return(View(new HrdbCaseViewModel(jc)));
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
コード例 #13
0
ファイル: EventsController.cs プロジェクト: ruacol/profiling2
        public ActionResult Import(HrdbCaseViewModel vm)
        {
            JhroCase jc = this.sourceTasks.GetJhroCase(vm.Id);

            // if an existing Event is selected, ignore validation errors to do with new event
            if (vm.EventId.HasValue)
            {
                // TODO brittle
                ModelState.Remove("Event.ViolationIds");
                ModelState.Remove("Event.LocationId");
            }

            if (ModelState.IsValid)
            {
                Event e = null;
                if (vm.EventId.HasValue)
                {
                    e = this.eventTasks.GetEvent(vm.EventId.Value);
                    e.AddJhroCase(jc);
                }
                else
                {
                    // create new event - TODO duplicates code in other EventsController
                    e = new Event();
                    Mapper.Map <EventViewModel, Event>(vm.Event, e);
                    if (!string.IsNullOrEmpty(vm.Event.ViolationIds))
                    {
                        string[] ids = vm.Event.ViolationIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                Violation v = this.eventTasks.GetViolation(result);
                                if (v != null)
                                {
                                    e.Violations.Add(v);
                                }
                            }
                        }
                    }
                    e.Location            = this.locationTasks.GetLocation(vm.Event.LocationId.Value);
                    e.EventVerifiedStatus = vm.Event.EventVerifiedStatusId.HasValue ? this.eventTasks.GetEventVerifiedStatus(vm.Event.EventVerifiedStatusId.Value) : null;
                    if (!string.IsNullOrEmpty(vm.Event.TagIds))
                    {
                        string[] ids = vm.Event.TagIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                Tag t = this.eventTasks.GetTag(result);
                                if (t != null)
                                {
                                    e.Tags.Add(t);
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(vm.Event.JhroCaseIds))
                    {
                        string[] ids = vm.Event.JhroCaseIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                JhroCase jhroCase = this.sourceTasks.GetJhroCase(result);
                                if (jhroCase != null)
                                {
                                    e.AddJhroCase(jhroCase);
                                }
                            }
                        }
                    }
                }

                // create responsibilities
                if (e != null && vm.HrdbPerpetrators != null)
                {
                    foreach (HrdbPerpetratorViewModel pvm in vm.HrdbPerpetrators)
                    {
                        if (pvm.PersonId.HasValue)
                        {
                            Person p = this.personTasks.GetPerson(pvm.PersonId.Value);
                            if (p != null)
                            {
                                if (pvm.PersonResponsibilityTypeId.HasValue)
                                {
                                    PersonResponsibilityType prt = this.responsibilityTasks.GetPersonResponsibilityType(pvm.PersonResponsibilityTypeId.Value);
                                    if (prt != null)
                                    {
                                        PersonResponsibility pr = new PersonResponsibility()
                                        {
                                            Event  = e,
                                            Person = p,
                                            PersonResponsibilityType = prt,
                                            Violations = pvm.GetViolationIds().Select(x => this.eventTasks.GetViolation(x)).ToList()
                                        };

                                        e.AddPersonResponsibility(pr);
                                    }
                                }
                            }
                        }
                        else if (pvm.OrganizationId.HasValue)
                        {
                            Organization o = this.orgTasks.GetOrganization(pvm.OrganizationId.Value);
                            if (o != null)
                            {
                                if (pvm.OrganizationResponsibilityTypeId.HasValue)
                                {
                                    OrganizationResponsibilityType ort = this.responsibilityTasks.GetOrgResponsibilityType(pvm.OrganizationResponsibilityTypeId.Value);
                                    if (ort != null)
                                    {
                                        OrganizationResponsibility or = new OrganizationResponsibility()
                                        {
                                            Event        = e,
                                            Organization = o,
                                            OrganizationResponsibilityType = ort
                                        };

                                        e.AddOrganizationResponsibility(or);
                                    }
                                }
                            }
                        }
                    }
                }

                e = this.eventTasks.SaveEvent(e);

                return(RedirectToAction("Details", "Cases", new { id = jc.Id }));
            }

            return(Import(new JhroCaseViewModel(jc)));
        }
コード例 #14
0
        public HrdbCaseViewModel(JhroCase jc)
        {
            if (jc != null)
            {
                this.Id = jc.Id;
                if (jc.Events != null && jc.Events.Any())
                {
                    // currently assuming one Event (but data model can take multiple)
                    this.EventId = jc.Events[0].Id;
                }

                HrdbCase hc = (HrdbCase)StreamUtil.Deserialize(jc.HrdbContentsSerialized);
                if (hc != null)
                {
                    this.HrdbCase = hc;

                    this.HrdbPerpetrators = hc.Perpetrators.Select(x => new HrdbPerpetratorViewModel(x)).ToList();

                    // pre-populate new Event fields
                    this.Event = new EventViewModel();
                    this.Event.PopulateDropDowns(ServiceLocator.Current.GetInstance <IEventTasks>().GetAllEventVerifiedStatuses());
                    this.Event.ViolationIds = string.Join(",", this.HrdbPerpetrators.Select(x => x.GetViolationIds()).Aggregate(new List <int>(), (x, y) => x.Concat(y).ToList()));
                    this.Event.NarrativeEn  = string.Join("\n\n", new string[] { "Summary", hc.Summary, "Analysis", hc.AnalysisDesc, "Facts", hc.FactAnalysis, "Legal", hc.LegalAnalysis, "Methodology", hc.Methodology });
                    if (hc.StartDate.HasValue)
                    {
                        this.Event.YearOfStart  = hc.StartDate.Value.Year;
                        this.Event.MonthOfStart = hc.StartDate.Value.Month;
                        this.Event.DayOfStart   = hc.StartDate.Value.Day;
                    }
                    if (hc.EndDate.HasValue)
                    {
                        this.Event.YearOfEnd  = hc.EndDate.Value.Year;
                        this.Event.MonthOfEnd = hc.EndDate.Value.Month;
                        this.Event.DayOfEnd   = hc.EndDate.Value.Day;
                    }
                    // location
                    Location loc = ServiceLocator.Current.GetInstance <ILocationTasks>().GetOrCreateLocation(hc.IncidentAddr, hc.TownVillage, hc.Subregion, hc.Region, hc.GetLatitude(), hc.GetLongitude());
                    if (loc != null)
                    {
                        this.Event.LocationId = loc.Id;
                    }
                    // notes
                    this.Event.EventVerifiedStatusId = ServiceLocator.Current.GetInstance <IEventTasks>().GetEventVerifiedStatus(
                        hc.IsComplaintCode() ? EventVerifiedStatus.ALLEGATION : EventVerifiedStatus.JHRO_VERIFIED).Id;
                    this.Event.JhroCaseIds = jc.Id.ToString();
                }
            }

            this.OrganizationResponsibilityTypes = ServiceLocator.Current.GetInstance <IResponsibilityTasks>().GetOrgResponsibilityTypes()
                                                   .Select(x => new SelectListItem()
            {
                Text = x.OrganizationResponsibilityTypeName, Value = x.Id.ToString()
            })
                                                   .ToList();

            this.PersonResponsibilityTypes = ServiceLocator.Current.GetInstance <IResponsibilityTasks>().GetPersonResponsibilityTypes()
                                             .Select(x => new SelectListItem()
            {
                Text = x.PersonResponsibilityTypeName, Value = x.Id.ToString()
            })
                                             .ToList();
        }
コード例 #15
0
ファイル: JhroCaseQueries.cs プロジェクト: ruacol/profiling2
        public void SaveJhroCase(ISession session, JhroCase jhroCase)
        {
            ISession thisSession = session == null ? this.Session : session;

            thisSession.SaveOrUpdate(jhroCase);
        }
コード例 #16
0
ファイル: SourceTasks.cs プロジェクト: ruacol/profiling2
 public JhroCase SaveJhroCase(ISession session, JhroCase jhroCase)
 {
     this.jhroCaseQueries.SaveJhroCase(session, jhroCase);
     return(jhroCase);
 }
コード例 #17
0
ファイル: EventsController.cs プロジェクト: ruacol/profiling2
        public JsonNetResult Edit(EventViewModel evm)
        {
            if (ModelState.IsValid)
            {
                Event e = this.eventTasks.GetEvent(evm.Id);
                if (e != null)
                {
                    Mapper.Map <EventViewModel, Event>(evm, e);
                    if (!string.IsNullOrEmpty(evm.ViolationIds))
                    {
                        string[] ids = evm.ViolationIds.Split(',');
                        e.Violations.Clear();
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                Violation v = this.eventTasks.GetViolation(result);
                                if (v != null)
                                {
                                    e.Violations.Add(v);
                                }
                            }
                        }
                    }
                    e.Location            = this.locationTasks.GetLocation(evm.LocationId.Value);
                    e.EventVerifiedStatus = evm.EventVerifiedStatusId.HasValue ? this.eventTasks.GetEventVerifiedStatus(evm.EventVerifiedStatusId.Value) : null;
                    e.Tags.Clear();
                    if (!string.IsNullOrEmpty(evm.TagIds))
                    {
                        string[] ids = evm.TagIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                Tag t = this.eventTasks.GetTag(result);
                                if (t != null)
                                {
                                    e.Tags.Add(t);
                                }
                            }
                        }
                    }
                    e.JhroCases.Clear();
                    if (!string.IsNullOrEmpty(evm.JhroCaseIds))
                    {
                        string[] ids = evm.JhroCaseIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                JhroCase jc = this.sourceTasks.GetJhroCase(result);
                                if (jc != null)
                                {
                                    e.AddJhroCase(jc);
                                }
                            }
                        }
                    }
                    e = this.eventTasks.SaveEvent(e);

                    return(JsonNet(string.Empty));
                }
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(JsonNet("Event not found."));
            }
            else
            {
                return(JsonNet(this.GetErrorsForJson()));
            }
        }
コード例 #18
0
ファイル: EventsController.cs プロジェクト: ruacol/profiling2
        public JsonNetResult Create(EventViewModel evm)
        {
            if (ModelState.IsValid)
            {
                Event e = new Event();
                Mapper.Map <EventViewModel, Event>(evm, e);
                if (!string.IsNullOrEmpty(evm.ViolationIds))
                {
                    string[] ids = evm.ViolationIds.Split(',');
                    foreach (string id in ids)
                    {
                        int result;
                        if (int.TryParse(id, out result))
                        {
                            Violation v = this.eventTasks.GetViolation(result);
                            if (v != null)
                            {
                                e.Violations.Add(v);
                            }
                        }
                    }
                }
                e.Location            = this.locationTasks.GetLocation(evm.LocationId.Value);
                e.EventVerifiedStatus = evm.EventVerifiedStatusId.HasValue ? this.eventTasks.GetEventVerifiedStatus(evm.EventVerifiedStatusId.Value) : null;
                if (!string.IsNullOrEmpty(evm.TagIds))
                {
                    string[] ids = evm.TagIds.Split(',');
                    foreach (string id in ids)
                    {
                        int result;
                        if (int.TryParse(id, out result))
                        {
                            Tag t = this.eventTasks.GetTag(result);
                            if (t != null)
                            {
                                e.Tags.Add(t);
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(evm.JhroCaseIds))
                {
                    string[] ids = evm.JhroCaseIds.Split(',');
                    foreach (string id in ids)
                    {
                        int result;
                        if (int.TryParse(id, out result))
                        {
                            JhroCase jc = this.sourceTasks.GetJhroCase(result);
                            if (jc != null)
                            {
                                e.AddJhroCase(jc);
                            }
                        }
                    }
                }
                e = this.eventTasks.SaveEvent(e);

                return(JsonNet(new
                {
                    Id = e.Id,
                    Name = e.Headline,
                    WasSuccessful = true
                }));
            }
            else
            {
                return(JsonNet(this.GetErrorsForJson()));
            }
        }