Skip to content

Commit c2308c7

Browse files
committed
initial push for smm functionalities #980
1 parent c0b091c commit c2308c7

60 files changed

Lines changed: 6800 additions & 55 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BExIS++.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 17
3-
VisualStudioVersion = 17.9.34723.18
2+
# Visual Studio Version 18
3+
VisualStudioVersion = 18.2.11415.280
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Console", "Console", "{A24A6801-2ECC-4F47-8284-8C93277D3030}"
66
EndProject

Components/DLM/BExIS.Dlm.Entities/BExIS.Dlm.Entities.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="Party\PartyTypePair.cs" />
125125
<Compile Include="Party\PartyCustomGridColumns.cs" />
126126
<Compile Include="Properties\AssemblyInfo.cs" />
127+
<Compile Include="SpeciesMatching\SpeciesMatchingResult.cs" />
127128
</ItemGroup>
128129
<ItemGroup>
129130
<None Include="Administration\Administration.cd" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using BExIS.Dlm.Entities.Data;
2+
using BExIS.Security.Entities.Subjects;
3+
using System;
4+
using Vaiona.Entities.Common;
5+
6+
namespace BExIS.Dlm.Entities.SpeciesMatching
7+
{
8+
public class SpeciesMatchingResult : BaseEntity
9+
{
10+
11+
// original unchanged name submitted for matching
12+
public virtual string OriginalName { get; set; }
13+
14+
// cleaned name after preprocessing (e.g. trimming, removing special characters, etc.)
15+
public virtual string CleanedName { get; set; }
16+
17+
// edited name after manual corrections (if any)
18+
public virtual string EditedName { get; set; }
19+
20+
// matched name from the external source
21+
public virtual string MatchedName { get; set; }
22+
23+
// taxonomic status of the matched name (e.g. accepted, synonym, etc.)
24+
public virtual string Status { get; set; }
25+
26+
// type of the match (e.g. exact, fuzzy, etc.)
27+
public virtual string MatchType { get; set; }
28+
29+
// timestamp of the match
30+
public virtual DateTime TimestampMatch { get; set; }
31+
32+
// source of the match (e.g. Catalogue of Life, GBIF, etc.)
33+
public virtual string MatchSource { get; set; }
34+
35+
// version of the source used for matching
36+
public virtual string MatchSourceVersion { get; set; }
37+
38+
// indicates whether the match has been confirmed by the user
39+
public virtual bool ConfirmedByUser { get; set; }
40+
41+
// reference to the dataset where the original name was taken from
42+
public virtual Dataset Dataset { get; set; }
43+
44+
// reference to the specific version of the dataset
45+
// TODO: get this to work (maybe as a normal field instead of many-to-one relation)
46+
//public virtual DatasetVersion DatasetVersion { get; set; }
47+
48+
// reference to the user who owns this matching result
49+
public virtual User Creator { get; set; }
50+
}
51+
}

Components/DLM/BExIS.Dlm.Orm.NH/BExIS.Dlm.Orm.NH.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
<SubType>Designer</SubType>
240240
</Content>
241241
<Content Include="Mappings\Default\Party\PartyTypePair.hbm.xml" />
242+
<Content Include="Mappings\Default\SpeciesMatching\SpeciesMatchingResult.hbm.xml" />
242243
<Content Include="Mappings\PostgreSQL82Dialect\NativeObjects\Queries.hbm.xml">
243244
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
244245
<SubType>Designer</SubType>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="BExIS.Dlm.Entities" namespace="BExIS.Dlm.Entities.SpeciesMatching">
3+
4+
<class name="SpeciesMatchingResult" table="smm_species_matching_result" lazy="true">
5+
<id name="Id" column="id" type="Int64">
6+
<generator class="native"/>
7+
</id>
8+
9+
<property name="OriginalName" column="original_name" type="string" not-null="false" />
10+
11+
<property name="CleanedName" column="cleaned_name" type="string" not-null="false" />
12+
13+
<property name="EditedName" column="edited_name" type="string" not-null="false" />
14+
15+
<property name="MatchedName" column="matched_name" type="string" not-null="false" />
16+
17+
<property name="Status" column="status" type="string" not-null="false" />
18+
19+
<property name="MatchType" column="match_type" type="string" not-null="false" />
20+
21+
<property name="TimestampMatch" column="timestamp_match" type="DateTime" not-null="false" />
22+
23+
<property name="MatchSource" column="match_source" type="string" not-null="false" />
24+
25+
<property name="MatchSourceVersion" column="match_source_version" type="string" not-null="false" />
26+
27+
<property name="ConfirmedByUser" column="confirmed_by_user" type="bool" not-null="false" />
28+
29+
<!-- Mapping entity associations -->
30+
31+
<!--Dataset-->
32+
<many-to-one name="Dataset" class="BExIS.Dlm.Entities.Data.Dataset" not-null="false" column="DatasetRef" />
33+
34+
<!--Creator-->
35+
<many-to-one name="Creator" class="BExIS.Security.Entities.Subjects.User" not-null="false" column="UserRef" />
36+
37+
<!--DatasetVersion (does not work this way ... Error: refers to unmapped ...-->
38+
<!--
39+
<many-to-one class="DatasetVersion" name="DatasetVersion" column="DatasetVersionRef">
40+
</many-to-one>
41+
-->
42+
43+
</class>
44+
45+
</hibernate-mapping>

Components/DLM/BExIS.Dlm.Services/BExIS.Dlm.Services.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
<Compile Include="Party\PartyRelationshipTypeManager.cs" />
167167
<Compile Include="Party\PartyTypeManager.cs" />
168168
<Compile Include="Properties\AssemblyInfo.cs" />
169+
<Compile Include="SpeciesMatching\SpeciesMatchingResultManager.cs" />
169170
<Compile Include="TypeSystem\DataTypeCode.cs" />
170171
<Compile Include="TypeSystem\DataTypeInfo.cs" />
171172
<Compile Include="TypeSystem\DataTypeUtility.cs" />
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using BExIS.Dlm.Entities.Data;
2+
using BExIS.Dlm.Entities.SpeciesMatching;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics.Contracts;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Vaiona.Persistence.Api;
10+
11+
namespace BExIS.Dlm.Services.SpeciesMatching
12+
{
13+
public class SpeciesMatchingResultManager : IDisposable
14+
{
15+
16+
private IUnitOfWork guow = null;
17+
18+
public SpeciesMatchingResultManager()
19+
{
20+
guow = this.GetIsolatedUnitOfWork();
21+
this.Repo = guow.GetReadOnlyRepository<SpeciesMatchingResult>();
22+
}
23+
24+
private bool isDisposed = false;
25+
26+
~SpeciesMatchingResultManager()
27+
{
28+
Dispose(true);
29+
}
30+
31+
public void Dispose()
32+
{
33+
Dispose(true);
34+
}
35+
36+
protected virtual void Dispose(bool disposing)
37+
{
38+
if (!isDisposed)
39+
{
40+
if (disposing)
41+
{
42+
if (guow != null)
43+
guow.Dispose();
44+
isDisposed = true;
45+
}
46+
}
47+
}
48+
49+
public IReadOnlyRepository<SpeciesMatchingResult> Repo { get; private set; }
50+
51+
public SpeciesMatchingResult Create(SpeciesMatchingResult matchingResult)
52+
{
53+
if (matchingResult == null) throw new ArgumentNullException("Species matching result must not be null.");
54+
if (matchingResult.Creator == null) throw new ArgumentNullException("Creator type must not be null.");
55+
if (matchingResult.Dataset == null) throw new ArgumentNullException("Dataset must not be null.");
56+
if (matchingResult.OriginalName == null) throw new ArgumentNullException("Dataset must not be null.");
57+
58+
using (IUnitOfWork uow = this.GetUnitOfWork())
59+
{
60+
try
61+
{
62+
IRepository<SpeciesMatchingResult> repo = uow.GetRepository<SpeciesMatchingResult>();
63+
repo.Put(matchingResult);
64+
uow.Commit();
65+
66+
return (matchingResult);
67+
}
68+
catch (Exception ex)
69+
{
70+
throw new Exception("SpeciesMatchingResult creation failed.", ex);
71+
}
72+
}
73+
}
74+
75+
public SpeciesMatchingResult Update(SpeciesMatchingResult matchingResult)
76+
{
77+
if (matchingResult == null) throw new ArgumentNullException("Species matching result must not be null.");
78+
79+
Contract.Ensures(Contract.Result<SpeciesMatchingResult>() != null && Contract.Result<SpeciesMatchingResult>().Id >= 0);
80+
81+
using (IUnitOfWork uow = this.GetUnitOfWork())
82+
{
83+
try
84+
{
85+
IRepository<SpeciesMatchingResult> repo = uow.GetRepository<SpeciesMatchingResult>();
86+
repo.Merge(matchingResult);
87+
var merged = repo.Get(matchingResult.Id);
88+
repo.Put(merged);
89+
uow.Commit();
90+
91+
return (merged);
92+
}
93+
catch (Exception ex)
94+
{
95+
throw new Exception("SpeciesMatchingResult creation failed.", ex);
96+
}
97+
}
98+
}
99+
public bool Delete(long id)
100+
{
101+
if (id == 0) throw new ArgumentException("Species matching result must not be null.");
102+
103+
Contract.Ensures(Contract.Result<SpeciesMatchingResult>() != null && Contract.Result<SpeciesMatchingResult>().Id >= 0);
104+
105+
using (IUnitOfWork uow = this.GetUnitOfWork())
106+
{
107+
IRepository<SpeciesMatchingResult> repo = uow.GetRepository<SpeciesMatchingResult>();
108+
109+
var e = repo.Get(id);
110+
111+
if (e != null)
112+
{
113+
repo.Delete(e);
114+
uow.Commit();
115+
116+
return true;
117+
}
118+
else
119+
{
120+
throw new ArgumentException(string.Format("the species matching result with the id {0} does not exist", id));
121+
}
122+
}
123+
}
124+
125+
public bool Delete(SpeciesMatchingResult matchingResult)
126+
{
127+
if (matchingResult == null) throw new ArgumentNullException("Entity template must not be null.");
128+
129+
Contract.Ensures(Contract.Result<SpeciesMatchingResult>() != null && Contract.Result<SpeciesMatchingResult>().Id >= 0);
130+
131+
using (IUnitOfWork uow = this.GetUnitOfWork())
132+
{
133+
IRepository<SpeciesMatchingResult> repo = uow.GetRepository<SpeciesMatchingResult>();
134+
135+
repo.Delete(matchingResult);
136+
uow.Commit();
137+
138+
return true;
139+
}
140+
}
141+
142+
}
143+
}

Components/DLM/BExIS.Dlm.Tests/BExIS.Dlm.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
<Compile Include="Services\Party\PartyManagerTests.cs" />
228228
<Compile Include="Services\Party\PartyRelationshipTypeManagerTest.cs" />
229229
<Compile Include="Services\Party\PartyTypeManagerTests.cs" />
230+
<Compile Include="Services\SpeciesMatching\SpeciesMatchingResultManagerTest.cs" />
230231
</ItemGroup>
231232
<ItemGroup>
232233
<None Include="app.config">
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using BExIS.App.Testing;
2+
using BExIS.Dlm.Entities.Data;
3+
using BExIS.Dlm.Entities.SpeciesMatching;
4+
using BExIS.Dlm.Services.Data;
5+
using BExIS.Dlm.Services.MetadataStructure;
6+
using BExIS.Dlm.Services.SpeciesMatching;
7+
using BExIS.Security.Services.Objects;
8+
using BExIS.Security.Services.Subjects;
9+
using BExIS.Utils.Config;
10+
using NUnit.Framework;
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Linq;
14+
using System.Text;
15+
using System.Threading.Tasks;
16+
17+
namespace BExIS.Dlm.Tests.Services.SpeciesMatching
18+
{
19+
internal class SpeciesMatchingResultManagerTest
20+
{
21+
private TestSetupHelper helper = null;
22+
23+
[OneTimeSetUp]
24+
public void OneTimeSetUp()
25+
{
26+
helper = new TestSetupHelper(WebApiConfig.Register, false);
27+
}
28+
29+
[OneTimeTearDown]
30+
public void OneTimeTearDown()
31+
{
32+
}
33+
34+
[Test()]
35+
public void Create_Valid_EntityTemplate()
36+
{
37+
using (var speciesMatchingResultManager = new SpeciesMatchingResultManager())
38+
using (var userManager = new UserManager())
39+
using (var datasetManager = new DatasetManager())
40+
{
41+
//Arrange
42+
SpeciesMatchingResult matchingResult = new SpeciesMatchingResult();
43+
44+
var user = userManager.Users.FirstOrDefault();
45+
var dataset = datasetManager.DatasetRepo.Get().FirstOrDefault();
46+
47+
matchingResult.OriginalName = "Sunflower";
48+
matchingResult.CleanedName = "";
49+
matchingResult.EditedName = "";
50+
matchingResult.MatchedName = "";
51+
matchingResult.Status = "";
52+
matchingResult.MatchType = "";
53+
matchingResult.TimestampMatch = DateTime.Now;
54+
matchingResult.MatchSource = "";
55+
matchingResult.MatchSourceVersion = "";
56+
matchingResult.ConfirmedByUser = false;
57+
matchingResult.Dataset = dataset;
58+
matchingResult.Creator = user;
59+
60+
//Act
61+
var created = speciesMatchingResultManager.Create(matchingResult);
62+
var fromdb = speciesMatchingResultManager.Repo.Get().LastOrDefault();
63+
64+
//Assert
65+
Assert.IsNotNull(created);
66+
Assert.IsNotNull(fromdb);
67+
Assert.That(created.Id.Equals(fromdb.Id));
68+
}
69+
}
70+
}
71+
}

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

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

0 commit comments

Comments
 (0)