Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify publication handling. In case of co-publication, only co-publication is attached to user profile. #245

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions aspnetcore/src/api.Tests/Services_Tests/TtvSqlServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Xunit;
using api.Services;
using api.Models.Common;
using api.Models.Ttv;
using Xunit;
using api.Services;
using api.Models.Common;
using api.Models.Ttv;
using api.Models.ProfileEditor.Items;
using System;
using System.Collections.Generic;

namespace api.Tests
{
[Collection("Get SQL query from TtvSqlService")]
namespace api.Tests
{
[Collection("Get SQL query from TtvSqlService")]
public class TtvSqlServiceTests
{
public FactFieldValue GetFactFieldValueForTest()
Expand Down Expand Up @@ -489,10 +489,19 @@ public void Test_getSqlQuery_Select_FactContribution_01()
TtvSqlService ttvSqlService = new();
string expectedSqlString =
$@"SELECT DISTINCT
dim_research_activity_id AS 'DimResearchActivityId',
dim_research_dataset_id AS 'DimResearchDatasetId',
dim_publication_id AS 'DimPublicationId'
FROM fact_contribution WHERE dim_name_id = 1234 AND (dim_research_activity_id!=-1 OR dim_research_dataset_id!=-1 OR dim_publication_id!=-1)";
fc.dim_research_activity_id AS 'DimResearchActivityId',
fc.dim_research_dataset_id AS 'DimResearchDatasetId',
fc.dim_publication_id AS 'DimPublicationId',
COALESCE(dp.dim_publication_id, -1) AS 'CoPublication_Parent_DimPublicationId'
FROM
fact_contribution AS fc
JOIN
dim_publication AS dp ON fc.dim_publication_id=dp.id
WHERE
fc.dim_name_id = 1234 AND
(
fc.dim_research_activity_id!=-1 OR fc.dim_research_dataset_id!=-1 OR fc.dim_publication_id!=-1
)";
// Act
string actualSqlString = ttvSqlService.GetSqlQuery_Select_FactContribution(1234);
// Assert
Expand Down Expand Up @@ -898,5 +907,5 @@ public void GetSqlQuery_Select_GetHiddenInUserprofile()
// Assert
Assert.Equal(expectedSqlString, actualSqlString);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public partial class FactContributionTableMinimalDTO
public int DimResearchActivityId { get; set; }
public int DimResearchDatasetId { get; set; }
public int DimPublicationId { get; set; }
public int CoPublication_Parent_DimPublicationId { get; set; }
}
}
17 changes: 13 additions & 4 deletions aspnetcore/src/api/Services/TtvSqlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,19 @@ FROM dim_education
public string GetSqlQuery_Select_FactContribution(int dimNameId)
{
return $@"SELECT DISTINCT
dim_research_activity_id AS 'DimResearchActivityId',
dim_research_dataset_id AS 'DimResearchDatasetId',
dim_publication_id AS 'DimPublicationId'
FROM fact_contribution WHERE dim_name_id = {dimNameId} AND (dim_research_activity_id!=-1 OR dim_research_dataset_id!=-1 OR dim_publication_id!=-1)";
fc.dim_research_activity_id AS 'DimResearchActivityId',
fc.dim_research_dataset_id AS 'DimResearchDatasetId',
fc.dim_publication_id AS 'DimPublicationId',
COALESCE(dp.dim_publication_id, -1) AS 'CoPublication_Parent_DimPublicationId'
FROM
fact_contribution AS fc
JOIN
dim_publication AS dp ON fc.dim_publication_id=dp.id
WHERE
fc.dim_name_id = {dimNameId} AND
(
fc.dim_research_activity_id!=-1 OR fc.dim_research_dataset_id!=-1 OR fc.dim_publication_id!=-1
)";
}

// Return SQL SELECT statement for br_participates_in_funding_group
Expand Down
11 changes: 8 additions & 3 deletions aspnetcore/src/api/Services/UserProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,21 @@ public async Task AddTtvDataToUserProfile(DimKnownPerson dimKnownPerson, DimUser
foreach (FactContributionTableMinimalDTO fc in factContributions)
{
// publication
if (fc.DimPublicationId != -1 && !existingPublicationIds.Contains(fc.DimPublicationId))
//
// Co-publications have multiple rows in table fact_contribution. Here only the "main" publication should be included.
// If FactContributionTableMinimalDTO.CoPublication_Parent_DimPublicationId has value (other than -1), that must be used.
// Otherwise FactContributionTableMinimalDTO.DimPublicationId must be used.
int publicationId = fc.CoPublication_Parent_DimPublicationId > 0 ? fc.CoPublication_Parent_DimPublicationId : fc.DimPublicationId;
if (publicationId != -1 && !existingPublicationIds.Contains(publicationId))
{
FactFieldValue factFieldValuePublication = this.GetEmptyFactFieldValue();
factFieldValuePublication.DimUserProfileId = dimUserProfile.Id;
factFieldValuePublication.DimFieldDisplaySettingsId = dimFieldDisplaySetting_publication.Id;
factFieldValuePublication.DimPublicationId = fc.DimPublicationId;
factFieldValuePublication.DimPublicationId = publicationId;
factFieldValuePublication.DimRegisteredDataSourceId = dimName.DimRegisteredDataSourceId;
_ttvContext.FactFieldValues.Add(factFieldValuePublication);
// Prevent duplicate key error with publications
existingPublicationIds.Add(fc.DimPublicationId);
existingPublicationIds.Add(publicationId);
}

// research activity
Expand Down
Loading