Skip to content

Commit 551fe26

Browse files
committed
#2196 add properties to entity reference, refactor all functions , models, config file
also refactor xml entityreference config to json
1 parent 9ae9502 commit 551fe26

File tree

10 files changed

+131
-62
lines changed

10 files changed

+131
-62
lines changed

Components/AAA/BExIS.Security.Entities/Objects/EntityReference.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class EntityReference : BaseEntity
2727
public virtual int TargetVersion { get; set; }
2828
public virtual string Context { get; set; }
2929
public virtual string ReferenceType { get; set; }
30+
public virtual string LinkType { get; set; }
31+
public virtual string Category { get; set; }
3032
public virtual DateTime CreationDate { get; set; }
3133

3234
public EntityReference()
@@ -37,9 +39,14 @@ public EntityReference()
3739
TargetEntityId = 0;
3840
Context = "";
3941
ReferenceType = "";
42+
CreationDate = DateTime.Now;
43+
LinkType = "";
44+
Category = "";
45+
SourceVersion = 0;
46+
TargetVersion = 0;
4047
}
4148

42-
public EntityReference(long sourceId, long sourceEntityId, int sourceVersion, long targetId, long targetEntityId, int targetVersion, string context, string type, DateTime creationDate)
49+
public EntityReference(long sourceId, long sourceEntityId, int sourceVersion, long targetId, long targetEntityId, int targetVersion, string context, string type, DateTime creationDate, string linkType , string category)
4350
{
4451
SourceId = sourceId;
4552
SourceEntityId = sourceEntityId;
@@ -50,6 +57,8 @@ public EntityReference(long sourceId, long sourceEntityId, int sourceVersion, lo
5057
Context = context;
5158
ReferenceType = type;
5259
CreationDate = creationDate;
60+
Category = category;
61+
LinkType = linkType;
5362
}
5463
}
5564
}

Components/AAA/BExIS.Security.Orm.NH/Mappings/Default/Objects/EntityReference.hbm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
<property name="Context" type="string" />
2424
<property name="ReferenceType" type="string" />
25+
<property name="LinkType" type="string" />
26+
<property name="Category" type="string" />
2527
<property name="CreationDate" type="DateTime" />
2628
</class>
2729
</hibernate-mapping>

Components/AAA/BExIS.Security.Services/Objects/EntityReferenceManager.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public bool Exist(EntityReference entityReference, bool includeVersion = false,
4242
r.TargetEntityId.Equals(entityReference.TargetEntityId) &&
4343
r.TargetVersion.Equals(entityReference.TargetVersion) &&
4444
r.Context.Equals(entityReference.Context) &&
45-
r.ReferenceType.Equals(entityReference.ReferenceType)
45+
r.ReferenceType.Equals(entityReference.ReferenceType) &&
46+
r.LinkType.Equals(entityReference.LinkType) &&
47+
r.Category.Equals(entityReference.Category)
4648

4749
).Count() == 0) return false;
4850
}
@@ -55,7 +57,10 @@ public bool Exist(EntityReference entityReference, bool includeVersion = false,
5557
r.TargetEntityId.Equals(entityReference.TargetEntityId) &&
5658
r.TargetVersion.Equals(entityReference.TargetVersion) &&
5759
r.Context.Equals(entityReference.Context) &&
58-
r.ReferenceType.Equals(entityReference.ReferenceType)
60+
r.ReferenceType.Equals(entityReference.ReferenceType) &&
61+
r.LinkType.Equals(entityReference.LinkType) &&
62+
r.Category.Equals(entityReference.Category)
63+
5964

6065
).Count() == 0) return false;
6166
}
@@ -67,7 +72,10 @@ public bool Exist(EntityReference entityReference, bool includeVersion = false,
6772
r.TargetId.Equals(entityReference.TargetId) &&
6873
r.TargetEntityId.Equals(entityReference.TargetEntityId) &&
6974
r.Context.Equals(entityReference.Context) &&
70-
r.ReferenceType.Equals(entityReference.ReferenceType)
75+
r.ReferenceType.Equals(entityReference.ReferenceType) &&
76+
r.LinkType.Equals(entityReference.LinkType) &&
77+
r.Category.Equals(entityReference.Category)
78+
7179
).Count() == 0) return false;
7280
}
7381

@@ -85,9 +93,9 @@ public void Create(EntityReference entityReference)
8593
}
8694
}
8795

88-
public EntityReference Create(long sourceId, long sourceEntityId, int sourceEntityVersion, long targetId, long targetEntityId, int targetEntityVersion, string context, string type)
96+
public EntityReference Create(long sourceId, long sourceEntityId, int sourceEntityVersion, long targetId, long targetEntityId, int targetEntityVersion, string context, string type, string linkType, string category)
8997
{
90-
EntityReference entityReference = new EntityReference(sourceId, sourceEntityId, sourceEntityVersion, targetId, targetEntityId, targetEntityVersion, context, type, DateTime.Now);
98+
EntityReference entityReference = new EntityReference(sourceId, sourceEntityId, sourceEntityVersion, targetId, targetEntityId, targetEntityVersion, context, type, DateTime.Now, linkType, category);
9199

92100
using (var uow = this.GetUnitOfWork())
93101
{

Components/UI/BExIS.UI/Models/ReferenceModels.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class ReferenceModel
4040

4141
public string Context { get; set; }
4242
public string ReferenceType { get; set; }
43+
public string LinkType { get; set; }
44+
public string Category { get; set; }
4345

4446
public ReferenceModel()
4547
{
@@ -48,6 +50,8 @@ public ReferenceModel()
4850
Source = new ReferenceElementModel();
4951
Context = "";
5052
ReferenceType = "";
53+
LinkType = "";
54+
Category = "";
5155
}
5256
}
5357

@@ -100,6 +104,7 @@ public class CreateSimpleReferenceModel
100104
[Required]
101105
public String ReferenceType { get; set; }
102106

107+
103108
public CreateSimpleReferenceModel()
104109
{
105110
Context = "";
@@ -113,4 +118,39 @@ public CreateSimpleReferenceModel(long sourceId, long sourceTypeId, int sourceVe
113118
Context = "";
114119
}
115120
}
121+
122+
public class ReferenceConfig
123+
{
124+
public List<ReferenceConfigElement> ReferenceTypes { get; set; }
125+
public List<string> EntityWhiteList { get; set; }
126+
127+
public ReferenceConfig()
128+
{
129+
ReferenceTypes = new List<ReferenceConfigElement>();
130+
EntityWhiteList = new List<string>();
131+
}
132+
}
133+
134+
public class ReferenceConfigElement
135+
{
136+
/*
137+
"description": "has dwc:Event extension",
138+
"referenceType": "HasEvent",
139+
"linkType": "extension",
140+
"category": "extension"
141+
},
142+
*/
143+
public string ReferenceType { get; set; }
144+
public string Description { get; set; }
145+
public string LinkType { get; set; }
146+
public string Category { get; set; }
147+
148+
public ReferenceConfigElement()
149+
{
150+
ReferenceType="";
151+
Description = "";
152+
LinkType = "";
153+
Category = "";
154+
}
155+
}
116156
}

Components/Utils/BExIS.Utils.Data/BExIS.Utils.Data.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4545
<HintPath>..\..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
4646
</Reference>
47+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
48+
<HintPath>..\..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
49+
</Reference>
4750
<Reference Include="System" />
4851
<Reference Include="System.Core" />
4952
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

Components/Utils/BExIS.Utils.Data/Helpers/EntityReferenceHelper.cs

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BExIS.Security.Entities.Objects;
22
using BExIS.Security.Services.Objects;
33
using BExIS.UI.Models.EntityReference;
4+
using Newtonsoft.Json;
45
using System;
56
using System.Collections.Generic;
67
using System.IO;
@@ -15,9 +16,11 @@ namespace BExIS.Utils.Data.Helpers
1516
{
1617
public class EntityReferenceHelper
1718
{
19+
private ReferenceConfig _config = null;
20+
1821
public EntityReferenceHelper()
1922
{
20-
23+
_config = getReferenceConfig();
2124
}
2225

2326
public bool EntityExist(long id, long typeId)
@@ -193,21 +196,17 @@ public EntityReference Convert(CreateSimpleReferenceModel model)
193196
tmp.ReferenceType = model.ReferenceType;
194197
tmp.CreationDate = DateTime.Now;
195198

196-
return tmp;
197-
}
199+
// get additional informations
200+
ReferenceConfigElement config = GetReferenceConfigByType(model.ReferenceType);
198201

199-
//public EntityReference Convert(SimpleReferenceModel model, long sourceId, long sourceTypeId)
200-
//{
201-
// EntityReference tmp = new EntityReference();
202-
// tmp.SourceId = sourceId;
203-
// tmp.SourceEntityId = sourceTypeId;
204-
// tmp.TargetId = model.Id;
205-
// tmp.TargetEntityId = model.TypeId;
206-
// tmp.Context = model.Context;
207-
// tmp.ReferenceType = model.ReferenceType;
202+
if (config != null)
203+
{
204+
tmp.LinkType = config.LinkType;
205+
tmp.Category = config.Category;
206+
}
208207

209-
// return tmp;
210-
//}
208+
return tmp;
209+
}
211210

212211
public SimpleSourceReferenceModel GetSimpleReferenceModel(long id, long typeId, int version)
213212
{
@@ -248,6 +247,8 @@ public ReferenceModel Convert(EntityReference entityReference)
248247
tmp.Context = entityReference.Context;
249248
tmp.ReferenceType = entityReference.ReferenceType;
250249
tmp.RefId = entityReference.Id;
250+
tmp.LinkType = entityReference.LinkType;
251+
tmp.Category = entityReference.Category;
251252

252253
return tmp;
253254
}
@@ -346,54 +347,58 @@ public List<ReferenceModel> GetTargetReferences(long id, long typeid, int versio
346347

347348
#region Entity Reference Config
348349

349-
/// <summary>
350-
/// this function return a list of all reference types. This types are listed in the entity reference config.xml in the workspace
351-
/// </summary>
352-
/// <returns></returns>
353-
public SelectList GetReferencesTypes()
350+
private ReferenceConfig getReferenceConfig()
354351
{
355-
string filepath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "EntityReferenceConfig.xml");
352+
string filepath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "EntityReferenceConfig.json");
356353
string dir = Path.GetDirectoryName(filepath);
357354

358355
if (Directory.Exists(dir) && File.Exists(filepath))
359356
{
360-
XDocument xdoc = XDocument.Load(filepath);
357+
ReferenceConfig referenceConfig = new ReferenceConfig();
358+
referenceConfig = JsonConvert.DeserializeObject<ReferenceConfig>(File.ReadAllText(filepath));
361359

362-
var types = xdoc.Root.Descendants("referenceType").Select(e => new SelectListItem()
363-
{
364-
Text = String.IsNullOrEmpty(e.Attribute("description").Value) ? e.Value : e.Attribute("description").Value,
365-
Value = e.Value
366-
}).ToList();
367-
368-
return new SelectList(types, "Value", "Text");
360+
return referenceConfig;
369361
}
370362
else
371363
{
372-
throw new FileNotFoundException("File EntityReferenceConfig.xml not found in :" + dir, "EntityReferenceConfig.xml");
364+
throw new FileNotFoundException("File EntityReferenceConfig.json not found in :" + dir, "EntityReferenceConfig.json");
373365
}
374366
}
375367

376-
public SelectList GetReferencesHelpTypes()
368+
private ReferenceConfigElement GetReferenceConfigByType(string type)
377369
{
378-
string filepath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "EntityReferenceConfig.xml");
379-
string dir = Path.GetDirectoryName(filepath);
380-
381-
if (Directory.Exists(dir) && File.Exists(filepath))
370+
if (_config != null)
382371
{
383-
XDocument xdoc = XDocument.Load(filepath);
372+
return _config.ReferenceTypes.Where(e => e.ReferenceType.Equals(type)).FirstOrDefault();
373+
}
374+
375+
return null;
376+
}
384377

385-
var types = xdoc.Root.Descendants("referenceType").Select(e => new SelectListItem()
378+
/// <summary>
379+
/// this function return a list of all reference types. This types are listed in the entity reference config.xml in the workspace
380+
/// </summary>
381+
/// <returns></returns>
382+
public SelectList GetReferencesTypes()
383+
{
384+
385+
if (_config != null)
386+
{
387+
var types = _config.ReferenceTypes.Select(e => new SelectListItem()
386388
{
387-
Text = String.IsNullOrEmpty(e.Attribute("description").Value) ? e.Value : e.Attribute("description").Value,
388-
Value = e.Value,
389+
Text = String.IsNullOrEmpty(e.Description) ? e.ReferenceType : e.Description,
390+
Value = e.ReferenceType
389391
}).ToList();
390392

391393
return new SelectList(types, "Value", "Text");
392394
}
393-
else
394-
{
395-
throw new FileNotFoundException("File EntityReferenceConfig.xml not found in :" + dir, "EntityReferenceConfig.xml");
396-
}
395+
396+
return new SelectList(new List<SelectListItem>(), "Value", "Text");
397+
}
398+
399+
public SelectList GetReferencesHelpTypes()
400+
{
401+
return GetReferencesTypes();
397402
}
398403

399404
#endregion Entity Reference Config
@@ -406,21 +411,18 @@ public SelectList GetReferencesHelpTypes()
406411
/// <returns></returns>
407412
public SelectList GetEntityTypesWhitlist()
408413
{
409-
string filepath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "EntityReferenceConfig.xml");
410-
string dir = Path.GetDirectoryName(filepath);
411-
412-
if (Directory.Exists(dir) && File.Exists(filepath))
414+
if (_config != null)
413415
{
414-
XDocument xdoc = XDocument.Load(filepath);
415-
416-
var types = xdoc.Root.Descendants("entityType").Select(e => new SelectListItem() { Text = e.Attribute("description").Value.ToString(), Value = e.Value }).ToList();
416+
var types = _config.EntityWhiteList.Select(e => new SelectListItem()
417+
{
418+
Text = e,
419+
Value = e
420+
}).ToList();
417421

418-
return new SelectList(types, "Text", "Value");
419-
}
420-
else
421-
{
422-
throw new FileNotFoundException("File EntityReferenceConfig.xml not found in :" + dir, "EntityReferenceConfig.xml");
422+
return new SelectList(types, "Value", "Text");
423423
}
424+
425+
return new SelectList(new List<SelectListItem>(), "Value", "Text");
424426
}
425427

426428
#endregion Entity Config

Components/Utils/BExIS.Utils.Data/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net48" />
66
<package id="Microsoft.CodeAnalysis.NetAnalyzers" version="8.0.0" targetFramework="net48" developmentDependency="true" />
77
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net48" />
8+
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
89
</packages>

Console/BExIS.Web.Shell/Areas/DCM/BExIS.Modules.Dcm.UI/Controllers/Hooks/EntityReferenceController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public JsonResult GetTargetVersions(long id, long type)
170170
/// <returns></returns>
171171

172172
[HttpPost]
173-
[CustomValidateAntiForgeryToken]
173+
//[CustomValidateAntiForgeryToken]
174174
public JsonResult Delete(long id)
175175
{
176176
if (id == 0) return Json(false);

Console/BExIS.Web.Shell/Areas/DCM/BExIS.Modules.Dcm.UI/Controllers/Legacy/CreateDatasetController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,9 @@ private List<EntityReference> getAllMetadataReferences(DatasetVersion datasetVer
800800
xVersion,
801801
xpath,
802802
DefaultEntitiyReferenceType.MetadataLink.GetDisplayName(),
803-
DateTime.Now
803+
DateTime.Now,
804+
"",
805+
""
804806
));
805807
}
806808
}

Console/BExIS.Web.Shell/Areas/DCM/BExIS.Modules.Dcm.UI/Views/EntityReference/_create.cshtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
@using (Ajax.BeginForm("Create", "EntityReference", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "content_createEnityReference", OnSuccess = "createEntityReference_OnSuccess" }))
2828
{
29+
@Html.AntiForgeryToken()
30+
2931
@Html.ValidationSummary(true)
3032

3133
@Html.HiddenFor(m => m.SourceId);

0 commit comments

Comments
 (0)