Skip to content

Commit 4eb6c83

Browse files
committed
#2197 create entity extension with store and seed data
1 parent 552f866 commit 4eb6c83

File tree

7 files changed

+316
-9
lines changed

7 files changed

+316
-9
lines changed

Components/Vaiona/Vaiona.Logging/Vaiona.Logging.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@
5858
<Compile Include="Loggers\FileLogger.cs" />
5959
<Compile Include="Properties\AssemblyInfo.cs" />
6060
</ItemGroup>
61-
<ItemGroup>
62-
<None Include="packages.config" />
63-
</ItemGroup>
6461
<ItemGroup>
6562
<ProjectReference Include="..\Vaiona.Entities\Vaiona.Entities.csproj">
6663
<Project>{0815d220-3625-4e23-bbbc-8152345637fe}</Project>
@@ -79,6 +76,9 @@
7976
<Name>Vaiona.Utils</Name>
8077
</ProjectReference>
8178
</ItemGroup>
79+
<ItemGroup>
80+
<None Include="packages.config" />
81+
</ItemGroup>
8282
<!-- Prevent PostSharp.targets to be automatically imported if PostSharp has been installed on the computer using the setup program. -->
8383
<PropertyGroup>
8484
<!--<DontImportPostSharp>True</DontImportPostSharp>-->

Components/XML/BExIS.Xml.Helpers/BExIS.Xml.Helpers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="IOHelper.cs" />
7575
<Compile Include="Mapping\XmlMapperManager.cs" />
7676
<Compile Include="Mapping\XmlSchemaManager.cs" />
77+
<Compile Include="ExtensionStore.cs" />
7778
<Compile Include="SampleStore.cs" />
7879
<Compile Include="PublicationStore.cs" />
7980
<Compile Include="XExtentsions.cs" />
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
using BExIS.Dlm.Entities.Data;
2+
using BExIS.Dlm.Services.Data;
3+
using BExIS.Dlm.Services.MetadataStructure;
4+
using BExIS.Security.Services.Objects;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using Vaiona.Persistence.Api;
9+
10+
namespace BExIS.Xml.Helpers
11+
{
12+
public class ExtensionStore : IEntityStore
13+
{
14+
private const string _entityName = "Extension";
15+
16+
public List<EntityStoreItem> GetEntities()
17+
{
18+
return GetEntities(0, 0);
19+
}
20+
21+
public List<EntityStoreItem> GetEntities(int skip, int take)
22+
{
23+
bool withPaging = (take > 0);
24+
25+
using (var uow = this.GetUnitOfWork())
26+
using (DatasetManager dm = new DatasetManager())
27+
using (MetadataStructureManager metadataStructureManager = new MetadataStructureManager())
28+
{
29+
XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();
30+
var entities = new List<EntityStoreItem>();
31+
32+
try
33+
{
34+
List<long> metadataStructureIds = metadataStructureManager.Repo.Query().Select(m => m.Id).ToList();
35+
36+
List<long> metadataSturctureIdsForDatasets = new List<long>();
37+
metadataSturctureIdsForDatasets = metadataStructureIds.Where(m => xmlDatasetHelper.HasEntity(m, _entityName)).ToList();
38+
39+
foreach (var msid in metadataSturctureIdsForDatasets)
40+
{
41+
var datasetIds = new List<long>();
42+
// get all datasets based on metadata data structure id
43+
if (withPaging)
44+
{
45+
datasetIds = dm.DatasetRepo
46+
.Query(d => d.MetadataStructure.Id.Equals(msid))
47+
.Skip(skip)
48+
.Take(take)
49+
.Select(d => d.Id).ToList();
50+
}
51+
else
52+
{
53+
datasetIds = dm.DatasetRepo.Query(d => d.MetadataStructure.Id.Equals(msid)).Select(d => d.Id).ToList();
54+
}
55+
56+
if (!datasetIds.Any()) continue;
57+
58+
// create tuples based on dataset id list, and get latest version of each dataset
59+
60+
List<DatasetVersion> datasetVersions = dm.GetDatasetLatestVersions(datasetIds, false);
61+
foreach (var dsv in datasetVersions)
62+
{
63+
var e = new EntityStoreItem()
64+
{
65+
Id = dsv.Dataset.Id,
66+
Title = dsv.Title,
67+
Version = dm.GetDatasetVersionCount(dsv.Dataset.Id)
68+
};
69+
70+
entities.Add(e);
71+
}
72+
}
73+
74+
return entities.ToList();
75+
}
76+
catch (Exception ex)
77+
{
78+
throw ex;
79+
}
80+
}
81+
}
82+
83+
public int CountEntities()
84+
{
85+
using (var uow = this.GetUnitOfWork())
86+
using (DatasetManager dm = new DatasetManager())
87+
using (MetadataStructureManager metadataStructureManager = new MetadataStructureManager())
88+
{
89+
XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();
90+
var entities = new List<EntityStoreItem>();
91+
int count = 0;
92+
93+
try
94+
{
95+
List<long> metadataStructureIds = metadataStructureManager.Repo.Query().Select(m => m.Id).ToList();
96+
97+
List<long> metadataSturctureIdsForDatasets = new List<long>();
98+
metadataSturctureIdsForDatasets = metadataStructureIds.Where(m => xmlDatasetHelper.HasEntity(m, _entityName)).ToList();
99+
100+
foreach (var msid in metadataSturctureIdsForDatasets)
101+
{
102+
var datasetIds = new List<long>();
103+
// get all datasets based on metadata data structure id
104+
105+
datasetIds = dm.DatasetRepo.Query(d => d.MetadataStructure.Id.Equals(msid)).Select(d => d.Id).ToList();
106+
count += datasetIds.Count;
107+
}
108+
109+
return count;
110+
}
111+
catch (Exception ex)
112+
{
113+
throw ex;
114+
}
115+
finally
116+
{
117+
dm.Dispose();
118+
}
119+
}
120+
}
121+
122+
public string GetTitleById(long id)
123+
{
124+
using (var uow = this.GetUnitOfWork())
125+
{
126+
var dm = new DatasetManager();
127+
128+
try
129+
{
130+
var dsv = dm.GetDatasetLatestVersion(id);
131+
132+
return dsv.Title;
133+
}
134+
catch
135+
{
136+
return String.Empty;
137+
}
138+
finally
139+
{
140+
dm.Dispose();
141+
}
142+
}
143+
}
144+
145+
public int CountVersions(long id)
146+
{
147+
DatasetManager dm = new DatasetManager();
148+
149+
try
150+
{
151+
var datasetIds = dm.GetDatasetLatestIds();
152+
var datasetHelper = new XmlDatasetHelper();
153+
154+
int version = dm.GetDataset(id).Versions.Count;
155+
156+
return version;
157+
}
158+
catch (Exception ex)
159+
{
160+
return 0;
161+
}
162+
finally
163+
{
164+
dm.Dispose();
165+
}
166+
}
167+
168+
public List<EntityStoreItem> GetVersionsById(long id)
169+
{
170+
DatasetManager dm = new DatasetManager();
171+
List<EntityStoreItem> tmp = new List<EntityStoreItem>();
172+
try
173+
{
174+
var datasetIds = dm.GetDatasetLatestIds();
175+
var datasetHelper = new XmlDatasetHelper();
176+
var versions = dm.GetDataset(id).Versions.OrderBy(v => v.Timestamp).ToList();
177+
178+
foreach (var v in versions)
179+
{
180+
tmp.Add(new EntityStoreItem()
181+
{
182+
Id = v.Id,
183+
Title = v.Title,
184+
Version = versions.IndexOf(v) + 1,
185+
CommitComment = "(" + v.Timestamp.ToString("dd.MM.yyyy HH:mm") + "): " + v.ChangeDescription
186+
});
187+
}
188+
189+
return tmp;
190+
}
191+
catch (Exception ex)
192+
{
193+
return tmp;
194+
}
195+
finally
196+
{
197+
dm.Dispose();
198+
}
199+
}
200+
201+
public bool HasVersions()
202+
{
203+
return true;
204+
}
205+
206+
public bool Exist(long id)
207+
{
208+
DatasetManager dm = new DatasetManager();
209+
Dataset dataset = null;
210+
211+
try
212+
{
213+
dataset = dm.GetDataset(id);
214+
return dataset != null ? true : false;
215+
}
216+
catch (Exception ex)
217+
{
218+
return false;
219+
}
220+
finally
221+
{
222+
dm.Dispose();
223+
}
224+
}
225+
}
226+
}

Console/BExIS.Web.Shell.Svelte/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Console/BExIS.Web.Shell/Areas/DCM/BExIS.Modules.Dcm.UI/Helpers/DCMSeedDataGenerator.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,45 @@ public void GenerateSeedData()
155155
entityManager.Update(publication);
156156
}
157157

158+
// publication
159+
var extension = entityManager.Entities.Where(e => e.Name.ToUpperInvariant() == "Extension".ToUpperInvariant()).FirstOrDefault();
160+
161+
if (extension == null)
162+
{
163+
extension = new Entity();
164+
extension.Name = "Extension";
165+
extension.EntityType = typeof(Dataset);
166+
extension.EntityStoreType = typeof(Xml.Helpers.ExtensionStore);
167+
extension.UseMetadata = true;
168+
extension.Securable = true;
169+
170+
//add to Extra
171+
172+
XmlDocument xmlDoc = new XmlDocument();
173+
XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();
174+
xmlDatasetHelper.AddReferenceToXml(xmlDoc, AttributeNames.name.ToString(), "ddm", AttributeType.parameter.ToString(), "extra/modules/module");
175+
176+
extension.Extra = xmlDoc;
177+
178+
entityManager.Create(extension);
179+
}
180+
else
181+
{
182+
XmlDocument xmlDoc = new XmlDocument();
183+
184+
if (extension.Extra != null)
185+
if (extension.Extra is XmlDocument) xmlDoc = extension.Extra as XmlDocument;
186+
else xmlDoc.AppendChild(extension.Extra);
187+
188+
//update to Extra
189+
XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();
190+
xmlDatasetHelper.AddReferenceToXml(xmlDoc, AttributeNames.name.ToString(), "ddm", AttributeType.parameter.ToString(), "extra/modules/module");
191+
192+
extension.Extra = xmlDoc;
193+
194+
entityManager.Update(extension);
195+
}
196+
158197
#endregion create entities
159198

160199
#region SECURITY
@@ -312,6 +351,14 @@ public void GenerateSeedData()
312351
ImportSchema("Publication", "BEXIS2-Publication-Schema-draft.xsd", "Metadata", publication.Name, publication.EntityType.FullName, titleXPath, descriptionXpath);
313352
}
314353

354+
if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("Extension")))
355+
{
356+
string titleXPath = "Metadata/Title/TitleType";
357+
string descriptionXpath = "Metadata/Description/DescriptionType";
358+
359+
ImportSchema("Extension", "BEXIS2-Extension.xsd", "Metadata", extension.Name, extension.EntityType.FullName, titleXPath, descriptionXpath);
360+
}
361+
315362
#endregion Add Metadata
316363

317364
#region create default entitytemplate

Console/BExIS.Web.Shell/Areas/RPM/BExIS.Modules.Rpm.UI.Svelte/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
BEGIN TRANSACTION;
2+
3+
-- entities - extension
4+
INSERT INTO public.entities (
5+
versionno,
6+
extra,
7+
entitystoretype,
8+
entitytype,
9+
name,
10+
securable,
11+
usemetadata,
12+
parentref
13+
)
14+
SELECT
15+
1,
16+
'<extra><modules><module name="name" value="ddm" type="parameter" /></modules></extra>',
17+
'BExIS.Xml.Helpers.ExtensionStore, BExIS.Xml.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null',
18+
'BExIS.Dlm.Entities.Data.Dataset, BExIS.Dlm.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null',
19+
'Extension',
20+
true,
21+
true,
22+
null
23+
24+
WHERE NOT EXISTS (SELECT * FROM public.entities WHERE name='Extension');
25+
26+
27+
28+
-- BEXIS2 Version Update
29+
INSERT INTO public.versions(
30+
versionno, extra, module, value, date)
31+
VALUES (1, null, 'Shell', '4.2.0',NOW());
32+
33+
commit;

0 commit comments

Comments
 (0)