Skip to content

Commit ea5e8b6

Browse files
committed
Additional logging
1 parent 706d602 commit ea5e8b6

File tree

5 files changed

+91
-7
lines changed

5 files changed

+91
-7
lines changed

src/Colectica.Curation.ViewModel/ViewModels/FileViewModel.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,11 @@ public bool IsReadOnly
105105

106106
if (!IsUserCurator)
107107
{
108-
return true;
109-
}
110-
111-
if (this.File.CatalogRecord.Status == CatalogRecordStatus.New ||
112-
this.File.CatalogRecord.Status == CatalogRecordStatus.Processing)
113-
{
114-
return true;
108+
// If it is new, the depositor can still edit it.
109+
if (this.File.CatalogRecord.Status != CatalogRecordStatus.New)
110+
{
111+
return true;
112+
}
115113
}
116114

117115
return false;

src/Colectica.Curation.Web/Controllers/CatalogRecordController.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Colectica.Curation.Web.Areas.Ddi.Utility;
2525
using Colectica.Curation.Web.Models;
2626
using Colectica.Curation.Web.Utility;
27+
using log4net;
2728
using Newtonsoft.Json;
2829
using System;
2930
using System.Collections.Generic;
@@ -207,6 +208,8 @@ public ActionResult Create()
207208

208209
public ActionResult General(Guid id)
209210
{
211+
var logger = LogManager.GetLogger("CatalogRecordController");
212+
210213
using (var db = ApplicationDbContext.Create())
211214
{
212215
var record = GetRecord(id, db);
@@ -261,6 +264,9 @@ public ActionResult General(Guid id)
261264
OrganizationHelper.DoesUserHaveRight(db, User, record.Organization.Id, Right.CanApprove);
262265
model.CuratorCount = record.Curators.Count;
263266

267+
logger.Debug($"IsCurator: {model.IsUserCurator}");
268+
logger.Debug($"IsApprover: {model.IsUserApprover}");
269+
264270
return View(model);
265271
}
266272
}
@@ -1089,13 +1095,19 @@ public ActionResult RemovePersistentId(CatalogRecordGeneralViewModel model)
10891095
[HttpPost]
10901096
public ActionResult General(CatalogRecordGeneralViewModel model)
10911097
{
1098+
var logger = LogManager.GetLogger("CatalogRecordController");
1099+
logger.Debug("Entering CatalogRecordController.General() POST handler");
1100+
10921101
if (Request.Form.AllKeys.Contains("RemovePersistentId"))
10931102
{
1103+
logger.Debug("Removing persistent ID");
10941104
return RemovePersistentId(model);
10951105
}
10961106

10971107
using (var db = ApplicationDbContext.Create())
10981108
{
1109+
logger.Debug("Created database object");
1110+
10991111
var user = db.Users
11001112
.Where(x => x.UserName == User.Identity.Name)
11011113
.FirstOrDefault();
@@ -1104,6 +1116,7 @@ public ActionResult General(CatalogRecordGeneralViewModel model)
11041116
return RedirectToAction("Index");
11051117
}
11061118

1119+
logger.Debug("Got user object");
11071120

11081121
// Fetch the appropriate catalog record by ID.
11091122
Guid id = model.CatalogRecordId;
@@ -1113,13 +1126,17 @@ public ActionResult General(CatalogRecordGeneralViewModel model)
11131126
EnsureUserIsAllowed(record, db);
11141127
EnsureUserCanEdit(record, db, user);
11151128

1129+
logger.Debug("User is allowed");
1130+
11161131
if (record.IsLocked)
11171132
{
1133+
logger.Debug("Record is locked. Throwing.");
11181134
throw new HttpException(400, "This operation cannot be performed while the record is locked");
11191135
}
11201136

11211137
// Copy information from the POST to the CatalogRecord.
11221138
Mapper.Map(model, record);
1139+
logger.Debug("Mapped");
11231140

11241141
// Manually map authors based on the AuthorIDs property
11251142
record.Authors.Clear();
@@ -1130,6 +1147,8 @@ public ActionResult General(CatalogRecordGeneralViewModel model)
11301147
}
11311148
record.AuthorsText = string.Join(", ", record.Authors.Select(x => x.FullName));
11321149

1150+
logger.Debug("Authors retrieved");
1151+
11331152
// Up the version.
11341153
record.Version++;
11351154
record.LastUpdatedDate = DateTime.UtcNow;
@@ -1146,9 +1165,13 @@ public ActionResult General(CatalogRecordGeneralViewModel model)
11461165
};
11471166
db.Events.Add(log);
11481167

1168+
logger.Debug("Logged");
1169+
11491170
// Save the updated record.
11501171
db.SaveChanges();
11511172

1173+
logger.Debug("Saved to database");
1174+
11521175
return RedirectToAction("Methods", new { id = id });
11531176
}
11541177
}
@@ -1158,11 +1181,15 @@ public ActionResult Methods(CatalogRecordMethodsViewModel model)
11581181
{
11591182
using (var db = ApplicationDbContext.Create())
11601183
{
1184+
var logger = LogManager.GetLogger("CatalogRecordController");
1185+
logger.Debug("Entering CatalogRecord.Methods() POST handler");
1186+
11611187
var user = db.Users
11621188
.Where(x => x.UserName == User.Identity.Name)
11631189
.FirstOrDefault();
11641190
if (user == null)
11651191
{
1192+
logger.Debug("Could not get user. Returning");
11661193
return RedirectToAction("Index");
11671194
}
11681195

@@ -1172,17 +1199,24 @@ public ActionResult Methods(CatalogRecordMethodsViewModel model)
11721199

11731200
var record = GetRecord(id, db);
11741201

1202+
logger.Debug("Got record");
1203+
11751204
EnsureUserIsAllowed(record, db);
11761205
EnsureUserCanEdit(record, db, user);
11771206

1207+
logger.Debug("User is allowed");
1208+
11781209
if (record.IsLocked)
11791210
{
1211+
logger.Debug("Record is locked. Throwing.");
11801212
throw new HttpException(400, "This operation cannot be performed while the record is locked");
11811213
}
11821214

11831215
// Copy information from the POST to the CatalogRecord.
11841216
Mapper.Map(model, record);
11851217

1218+
logger.Debug("Mapped");
1219+
11861220
if (Request.Form["FieldDates.isRange"] != null)
11871221
{
11881222
model.FieldDates.isRange = true;
@@ -1220,6 +1254,7 @@ public ActionResult Methods(CatalogRecordMethodsViewModel model)
12201254
record.UnitOfObservation = model.UnitOfObservationOtherSpecify;
12211255
}
12221256

1257+
logger.Debug("Done manually mapping");
12231258

12241259
// Log the editing of the catalog record.
12251260
var log = new Event()
@@ -1233,9 +1268,13 @@ public ActionResult Methods(CatalogRecordMethodsViewModel model)
12331268
};
12341269
db.Events.Add(log);
12351270

1271+
logger.Debug("Logged");
1272+
12361273
// Save the updated record.
12371274
db.SaveChanges();
12381275

1276+
logger.Debug("Saved to database");
1277+
12391278
return RedirectToAction("Files", new { id = id });
12401279
}
12411280
}

src/Colectica.Curation.Web/Controllers/ErrorController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// with Colectica Curation Tools. If not, see <https://www.gnu.org/licenses/>.
1717

1818
using Colectica.Curation.Web.Models;
19+
using log4net;
1920
using System;
2021
using System.Collections.Generic;
2122
using System.Linq;
@@ -28,7 +29,11 @@ public class ErrorController : CurationControllerBase
2829
{
2930
public ActionResult Index(int statusCode, Exception exception, bool isAjaxRequest)
3031
{
32+
var logger = LogManager.GetLogger("ErrorController");
33+
logger.Debug("Entering ErrorController.Index()");
34+
3135
Response.StatusCode = statusCode;
36+
logger.Debug("Finished setting status code");
3237

3338
// If it's not an AJAX request that triggered this action then just retun the view
3439
if (!isAjaxRequest)

src/Colectica.Curation.Web/Controllers/FileController.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using Colectica.Curation.Common.Utility;
3636
using System.Net.Mime;
3737
using Colectica.Curation.Models;
38+
using log4net;
3839

3940
namespace Colectica.Curation.Web.Controllers
4041
{
@@ -200,10 +201,15 @@ public ActionResult General(Guid id)
200201
{
201202
using (var db = ApplicationDbContext.Create())
202203
{
204+
var logger = LogManager.GetLogger("FileController");
205+
203206
var file = GetFile(id, db);
207+
logger.Debug("Got file");
204208

205209
EnsureUserIsAllowed(file.CatalogRecord, db);
206210

211+
logger.Debug("User is allowed");
212+
207213
var model = new FileViewModel(file) as FileViewModel;
208214

209215
model.TermsOfUse = file.CatalogRecord.Organization.TermsOfService;
@@ -215,6 +221,14 @@ public ActionResult General(Guid id)
215221
string[] autoDetectedFileTypes = { ".dta", ".sav", ".rdata", ".csv", ".do", ".r", ".sps" };
216222
model.IsFileTypeAutoDetected = autoDetectedFileTypes.Contains(lowerExtension);
217223

224+
logger.Debug("Mapped");
225+
226+
logger.Debug($"Record Status: {model.File.CatalogRecord.Status}");
227+
logger.Debug($"IsCurator: {model.IsUserCurator}");
228+
logger.Debug($"IsApprover: {model.IsUserApprover}");
229+
logger.Debug($"IsReadOnly: {model.IsReadOnly}");
230+
logger.Debug($"Persistent link: {model.File.PersistentLink}");
231+
218232
return View(model);
219233
}
220234
}
@@ -622,18 +636,25 @@ public ActionResult RemovePersistentId(FileViewModel model)
622636
[HttpPost]
623637
public ActionResult General(FileViewModel model)
624638
{
639+
var logger = LogManager.GetLogger("FileController");
640+
logger.Debug("Entering FileController.General() POST handler");
641+
625642
if (Request.Form.AllKeys.Contains("RemovePersistentId"))
626643
{
644+
logger.Debug("Removing persistent ID");
627645
return RemovePersistentId(model);
628646
}
629647

630648
using (var db = ApplicationDbContext.Create())
631649
{
650+
logger.Debug("Created database object");
651+
632652
var user = db.Users
633653
.Where(x => x.UserName == User.Identity.Name)
634654
.FirstOrDefault();
635655
if (user == null)
636656
{
657+
logger.Debug("No user. Returning.");
637658
return RedirectToAction("Index");
638659
}
639660

@@ -644,15 +665,20 @@ public ActionResult General(FileViewModel model)
644665
EnsureUserIsAllowed(file.CatalogRecord, db);
645666
EnsureUserCanEdit(file.CatalogRecord, db);
646667

668+
logger.Debug("User is allowed");
669+
647670
if (file.CatalogRecord.IsLocked)
648671
{
672+
logger.Debug("Catalog record is locked. Throwing.");
649673
throw new HttpException(400, "This operation cannot be performed while the record is locked");
650674
}
651675

652676
string changeSummary = ManagedFileChangeDetector.GetChangeSummary(file, model);
677+
logger.Debug("Got change summary");
653678

654679
// Copy the information from the POST to the ManagedFile, ignoring read-only properties.
655680
Mapper.Map(model, file);
681+
logger.Debug("Mapped");
656682

657683
// Log the editing of the file.
658684
var log = new Event()
@@ -667,9 +693,13 @@ public ActionResult General(FileViewModel model)
667693
log.RelatedManagedFiles.Add(file);
668694
db.Events.Add(log);
669695

696+
logger.Debug("Logged");
697+
670698
// Save the updated record.
671699
db.SaveChanges();
700+
logger.Debug("Wrote to database");
672701

702+
logger.Debug("Returning from FileController.General() POST handler");
673703
return RedirectToAction("General", new { id = file.Id });
674704
}
675705
}

src/Colectica.Curation.Web/Global.asax.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Colectica.Curation.Operations;
2020
using Colectica.Curation.Web.Controllers;
2121
using Colectica.Curation.Web.Utility;
22+
using log4net;
2223
using System;
2324
using System.Collections.Generic;
2425
using System.Linq;
@@ -36,6 +37,10 @@ public class MvcApplication : System.Web.HttpApplication
3637
{
3738
protected void Application_Start()
3839
{
40+
var logger = LogManager.GetLogger("MvcApplication");
41+
logger.Info("Entering Application_Start()");
42+
logger.Info("Version: " + RevisionInfo.FullVersionString);
43+
3944
string addinsPath = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath,
4045
"CurationAddins");
4146

@@ -56,7 +61,12 @@ protected void Application_Start()
5661

5762
protected void Application_Error(object sender, EventArgs e)
5863
{
64+
var logger = LogManager.GetLogger("Application_Error");
65+
logger.Debug("Entering Application_Error()");
66+
5967
Exception lastError = Server.GetLastError();
68+
logger.Error("Unhandled error", lastError);
69+
6070
Server.ClearError();
6171

6272
int statusCode = 0;
@@ -87,6 +97,8 @@ protected void Application_Error(object sender, EventArgs e)
8797

8898
controller.Execute(requestContext);
8999
Response.End();
100+
101+
logger.Debug("Leaving Application_Error()");
90102
}
91103
}
92104
}

0 commit comments

Comments
 (0)