Skip to content

Commit 2092065

Browse files
Generic creation of citation formats used in API #2258
1 parent ab7f231 commit 2092065

File tree

5 files changed

+52
-49
lines changed

5 files changed

+52
-49
lines changed

Console/BExIS.Web.Shell/Areas/DDM/BExIS.Modules.Ddm.UI/Controllers/Api/CitationController.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using BExIS.App.Bootstrap.Attributes;
22
using BExIS.Dim.Helpers.Mappings;
3-
using BExIS.Dim.Services;
43
using BExIS.Dim.Services.Mappings;
54
using BExIS.Dlm.Entities.Data;
65
using BExIS.Dlm.Services.Data;
@@ -11,7 +10,6 @@
1110
using BExIS.Security.Services.Authorization;
1211
using BExIS.Security.Services.Objects;
1312
using BExIS.Security.Services.Subjects;
14-
using BExIS.UI.Models;
1513
using BExIS.Utils.Route;
1614
using NameParser;
1715
using Newtonsoft.Json;
@@ -35,7 +33,7 @@ public class CitationController : ApiController
3533
{
3634
[BExISApiAuthorize]
3735
[GetRoute("api/datasets/citations")]
38-
[ResponseType(typeof(CitationModel))]
36+
//[ResponseType(typeof(CitationModel))]
3937
public HttpResponseMessage Get([FromUri] CitationFormat format = CitationFormat.Bibtex)
4038
{
4139
return GetAllCitations();
@@ -352,14 +350,14 @@ private HttpResponseMessage GetCitation(long id, CitationFormat format, int vers
352350
var useTags = Convert.ToBoolean(moduleSettings.GetValueByKey("use_tags"));
353351

354352
CitationDataModel model = CitationsHelper.CreateCitationDataModel(datasetVersion, format);
355-
CitationModel citationModel = new CitationModel();
356-
353+
string citationString = "";
357354
if (CitationsHelper.IsCitationDataModelValid(model))
358-
citationModel.CitationString = CitationsHelper.GetCitationString(model, format, isPublic, datasetVersion.Dataset.Id, useTags);
355+
citationString = CitationsHelper.GetCitationString(model, format, isPublic, datasetVersion.Dataset.Id, useTags);
359356
else
360-
citationModel.CitationString = "Citation metadata is incomplete.";
357+
citationString = "Citation metadata is incomplete.";
361358

362-
return Request.CreateResponse<CitationModel>(HttpStatusCode.OK, citationModel);
359+
HttpResponseMessage response = new HttpResponseMessage { Content = new StringContent(citationString, Encoding.UTF8, "application/text") };
360+
return response;
363361
}
364362
}
365363

Console/BExIS.Web.Shell/Areas/DDM/BExIS.Modules.Ddm.UI/Ddm.Settings.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
"options": [],
6464
"type": "JSON",
6565
"value": {
66-
"publisher": "BEXIS2 DevOps Team",
67-
"instance": "BEXIS2 - DevOps Test",
6866
"numberOfAuthors": 0,
6967
"showCitation": true,
7068
"defaultViewCitationFormat": "Text",

Console/BExIS.Web.Shell/Areas/DDM/BExIS.Modules.Ddm.UI/Helpers/CitationsHelper.cs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44
using BExIS.Dlm.Entities.Data;
55
using BExIS.Dlm.Services.Data;
66
using BExIS.Modules.Ddm.UI.Models;
7-
using BExIS.Security.Entities.Versions;
87
using BExIS.Security.Services.Authorization;
98
using BExIS.Security.Services.Objects;
109
using NameParser;
1110
using System;
1211
using System.Collections.Generic;
1312
using System.ComponentModel.DataAnnotations;
14-
using System.Data;
1513
using System.Linq;
16-
using System.Security.Policy;
1714
using System.Text;
1815
using System.Web;
1916
using System.Xml;
2017
using System.Xml.Serialization;
21-
using Telerik.Web.Mvc.Infrastructure;
2218
using Vaiona.Web.Mvc.Modularity;
2319

2420
namespace BExIS.Modules.Ddm.UI.Helpers
@@ -36,7 +32,7 @@ public static CitationDataModel CreateCitationDataModel(DatasetVersion datasetVe
3632
{
3733
var metadata = datasetVersion.Metadata;
3834

39-
var concept = conceptManager.MappingConceptRepository.Query(c => c.Name.ToLower() == "citation_" + format).FirstOrDefault();
35+
var concept = conceptManager.MappingConceptRepository.Query(c => c.Name.ToLower() == "citation_" + format.ToString().ToLower()).FirstOrDefault();
4036

4137
if (concept == null)
4238
return null;
@@ -105,7 +101,6 @@ public static CitationDataModel CreateCitationDataModel(DatasetVersion datasetVe
105101
}
106102

107103
// URL
108-
109104
if (String.IsNullOrEmpty(model.URL))
110105
{
111106
model.URL = HttpContext.Current.Request.Url.Host;
@@ -144,7 +139,6 @@ public static bool IsCitationDataModelValid(CitationDataModel model)
144139
{
145140
return false;
146141
}
147-
148142
}
149143

150144
public static string GetCitationString(CitationDataModel model, CitationFormat format, bool isPublic, long entityId, bool useTags)
@@ -159,6 +153,8 @@ public static string GetCitationString(CitationDataModel model, CitationFormat f
159153
return GenerateRis(entityId, model, isPublic, useTags);
160154
case CitationFormat.Text:
161155
return GenerateText(entityId, model, isPublic, useTags);
156+
case CitationFormat.APA:
157+
return GetApaFromCitationDataModel(model);
162158
default:
163159
return "";
164160
}
@@ -230,21 +226,21 @@ public static string GenerateBibtex(long entityId,CitationDataModel model, bool
230226
if (!String.IsNullOrEmpty(model.DOI))
231227
bibtex += "doi ={" + model.DOI + "},\n";
232228

233-
if (!String.IsNullOrEmpty(model.Type))
229+
if (!String.IsNullOrEmpty(model.EntityName))
234230
{
235231
if (isPublic)
236-
bibtex += "type ={Dataset. Published.},\n";
232+
bibtex += "type ={" + model.EntityName + ". Published.},\n";
237233
else
238-
bibtex += "type ={Dataset. Unpublished.},\n";
234+
bibtex += "type ={" + model.EntityName + ". Unpublished.},\n";
239235
}
240-
if(!String.IsNullOrEmpty(model.Note))
241-
bibtex += "note ={Dataset ID: " + entityId + "},\n";
236+
if(String.IsNullOrEmpty(model.Note))
237+
bibtex += "note ={" + model.EntityName + " ID: " + entityId + "},\n";
238+
else
239+
bibtex += "note ={"+ model.Note + "},\n";
242240

243241
bibtex += "}";
244242

245243
return bibtex;
246-
247-
248244
}
249245

250246
public static string GenerateRis(long entityId, CitationDataModel model, bool isPublic, bool useTags)
@@ -253,15 +249,15 @@ public static string GenerateRis(long entityId, CitationDataModel model, bool is
253249
{
254250
return string.Empty;
255251
}
256-
string ris = "TY - " + model.EntityType + " \n";
252+
string ris = "TY - " + model.EntryType + " \n";
257253
ris += "T1 - " + model.Title + "\n";
258254

259255
foreach (string author in model.Authors)
260256
{
261257
ris += "AU - " + author + "\n";
262258
}
263259
ris += "PY - " + model.Year + " \n";
264-
ris += " ET- " + model.Version + " \n";
260+
ris += "ET - " + model.Version + " \n";
265261
ris += "PB - " + model.Publisher + " \n";
266262

267263
if (!String.IsNullOrEmpty(model.DOI))
@@ -283,15 +279,14 @@ public static string GenerateRis(long entityId, CitationDataModel model, bool is
283279
if (isPublic)
284280
ris += "N1 - " + model.EntityName +" ID: " + entityId + ", Published. \n";
285281
else
286-
ris += "N1 - " + model.EntityName + " ID: " + entityId + ", Unpublished. \n`";
287-
ris += "ER -";
282+
ris += "N1 - " + model.EntityName + " ID: " + entityId + ", Unpublished. \n";
283+
ris += "ER -";
288284

289285
return ris;
290286
}
291287

292288
public static string GenerateText(long entityId,CitationDataModel model, bool isPublic, bool useTags)
293289
{
294-
295290
string text = "";
296291
var lastAuthor = model.Authors.Last();
297292
foreach (string author in model.Authors)
@@ -326,7 +321,10 @@ public static string GenerateText(long entityId,CitationDataModel model, bool is
326321
else
327322
text += url + ". ";
328323

329-
text += model.EntityName + " ID= " + entityId;
324+
if(String.IsNullOrEmpty(model.Note))
325+
text += model.EntityName + " ID= " + entityId;
326+
else
327+
text += model.Note;
330328
}
331329

332330
return text;

Console/BExIS.Web.Shell/Areas/DDM/BExIS.Modules.Ddm.UI/Helpers/DdmSeedDataGenerator.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,29 @@ private void createCitationMappingConcept()
206206

207207
//title
208208
if (!keys.Any(k => k.Name.Equals("data/title")))
209-
conceptManager.CreateMappingKey("Title", "", "", true, false, "data/title", concept);
209+
conceptManager.CreateMappingKey("Title", "", "", false, false, "data/title", concept);
210210
//version
211211
if (!keys.Any(k => k.Name.Equals("data/version")))
212-
conceptManager.CreateMappingKey("Version", "", "", false, false, "data/version", concept);
212+
conceptManager.CreateMappingKey("Version", "", "", true, false, "data/version", concept);
213213
//year
214214
if (!keys.Any(k => k.Name.Equals("data/year")))
215-
conceptManager.CreateMappingKey("Year", "", "", false, false, "data/year", concept);
215+
conceptManager.CreateMappingKey("Year", "", "", true, false, "data/year", concept);
216+
216217
//entityType
217218
if (!keys.Any(k => k.Name.Equals("data/entityType")))
218219
conceptManager.CreateMappingKey("EntityType", "", "", true, false, "data/entityType", concept);
219220

220-
//entryTypeType
221-
if (!keys.Any(k => k.Name.Equals("data/entryType")))
222-
conceptManager.CreateMappingKey("EntryType", "", "", true, false, "data/entryType", concept);
221+
//entryType
222+
if (value == CitationFormat.Text)
223+
{
224+
if (!keys.Any(k => k.Name.Equals("data/entryType")))
225+
conceptManager.CreateMappingKey("EntryType", "", "", true, false, "data/entryType", concept);
226+
}
227+
else
228+
{
229+
if (!keys.Any(k => k.Name.Equals("data/entryType")))
230+
conceptManager.CreateMappingKey("EntryType", "", "", false, false, "data/entryType", concept);
231+
}
223232

224233
//publisher
225234
if (!keys.Any(k => k.Name.Equals("data/publisher")))
@@ -228,32 +237,32 @@ private void createCitationMappingConcept()
228237
if (value == CitationFormat.Bibtex)
229238
{
230239
if (!keys.Any(k => k.Name.Equals("data/keyword")))
231-
conceptManager.CreateMappingKey("Keyword", "", "", true, false, "data/keyword", concept);
240+
conceptManager.CreateMappingKey("Keyword", "", "", false, false, "data/keyword", concept);
232241
}
233242

234243
//note
235244
if (!keys.Any(k => k.Name.Equals("data/note")))
236-
conceptManager.CreateMappingKey("Note", "", "", false, false, "data/note", concept);
245+
conceptManager.CreateMappingKey("Note", "", "", true, false, "data/note", concept);
237246

238247
//doi
239248
if (!keys.Any(k => k.Name.Equals("data/doi")))
240-
conceptManager.CreateMappingKey("Doi", "", "", false, false, "data/doi", concept);
249+
conceptManager.CreateMappingKey("DOI", "", "", true, false, "data/doi", concept);
241250

242251
//projects
243252
MappingKey projects = null;
244253
if (!keys.Any(k => k.Name.Equals("data/projects")))
245-
projects = conceptManager.CreateMappingKey("Projects", "", "", false, true, "data/projects", concept);
254+
projects = conceptManager.CreateMappingKey("Projects", "", "", true, true, "data/projects", concept);
246255

247256
if (!keys.Any(k => k.Name.Equals("data/projects/project")))
248-
conceptManager.CreateMappingKey("Project", "", "", false, false, "data/projects/project", concept, projects);
257+
conceptManager.CreateMappingKey("Project", "", "", true, false, "data/projects/project", concept, projects);
249258

250259
//authors
251260
MappingKey authors = null;
252261
if (!keys.Any(k => k.Name.Equals("data/authorNames")))
253-
authors = conceptManager.CreateMappingKey("AuthorNames", "", "", true, true, "data/authorNames", concept);
262+
authors = conceptManager.CreateMappingKey("AuthorNames", "", "", false, true, "data/authorNames", concept);
254263

255264
if (!keys.Any(k => k.Name.Equals("data/authorNames/authorName")))
256-
conceptManager.CreateMappingKey("AuthorName", "", "", true, false, "data/authorNames/authorName", concept, authors);
265+
conceptManager.CreateMappingKey("AuthorName", "", "", false, false, "data/authorNames/authorName", concept, authors);
257266
}
258267
}
259268
}

Console/BExIS.Web.Shell/Areas/DDM/BExIS.Modules.Ddm.UI/Models/CitationModels.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public class CitationDataModel
6464
[MinCapacity(1), NoNullOrEmptyItems]
6565
public List<string> Authors { get; set; }
6666

67-
[XmlElement("entityType")]
68-
[Required(ErrorMessage = "Entity Type is required")]
69-
[MinLength(1, ErrorMessage = "Entity Type cannot be empty")]
70-
public string EntityType { get; set; }
67+
//[XmlElement("entityType")]
68+
//[Required(ErrorMessage = "Entity Type is required")]
69+
//[MinLength(1, ErrorMessage = "Entity Type cannot be empty")]
70+
//public string EntityType { get; set; }
7171

7272
[XmlElement("entryType")]
7373
[Required(ErrorMessage = "Entry Type is required")]
@@ -78,8 +78,8 @@ public class CitationDataModel
7878
public string EntityName { get; set; }
7979

8080
[XmlElement("publisher")]
81-
[Required(ErrorMessage = "Title is required")]
82-
[MinLength(1, ErrorMessage = "Title cannot be empty")]
81+
[Required(ErrorMessage = "Publisher is required")]
82+
[MinLength(1, ErrorMessage = "Publisher cannot be empty")]
8383
public string Publisher { get; set; }
8484

8585
[XmlElement("keyword")]

0 commit comments

Comments
 (0)