Skip to content

Commit

Permalink
Modify how co-publication author and organization information is coll…
Browse files Browse the repository at this point in the history
…ected. Rename co-publication related properties.
  • Loading branch information
sarkikos committed Oct 16, 2024
1 parent 6e7cebf commit 301a17c
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 73 deletions.
8 changes: 4 additions & 4 deletions aspnetcore/src/ApiModels/Publication/Publication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ public class Publication
public DateTime? Modified { get; set; }

/// <summary>
/// Osajulkaisun yhteisjulkaisu - TEMPORARY NAME
/// Combined information of co-publications based on national publication data collection
/// </summary>
public string? Yhteisjulkaisu { get; set; }
public string? CoPublicationID { get; set; }

/// <summary>
/// Yhteisjulkaisuun liittyvät osajulkaisut - TEMPORARY NAME
/// Publication information sent by individual organisations related to co-publications as part of national publication data collection
/// </summary>
public List<String>? Osajulkaisut { get; set; }
public List<String>? OrgPublicationIDs { get; set; }
}
12 changes: 6 additions & 6 deletions aspnetcore/src/ApiModels/Query/GetPublicationsQueryParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ public class GetPublicationsQueryParameters : PaginationQueryParameters
public string? ModifiedTo { get; set; }

/// <summary>
/// If the selection is true, co-publications will be returned.
/// If the selection is true, publication information sent by individual organisations related to co-publications as part of national publication data collection will be returned. Not returned by default.
/// </summary>
/// <see cref="Publication.ShowCoPublications"/>
public bool? ShowCoPublications { get; set; }
/// <see cref="Publication.ShowOrganisationPartofCoPublication"/>
public bool? ShowOrganisationPartofCoPublication { get; set; }

/// <summary>
/// If the selection is true, main publications will be filtered out.
/// If the selection is true, combined information of co-publications based on national publication data collection will be filtered out. Returned by default.
/// </summary>
/// <see cref="Publication.HideMainPublications"/>
public bool? HideMainPublications { get; set; }
/// <see cref="Publication.HideCoPublications"/>
public bool? HideCoPublications { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ private static IEnumerable<Func<QueryContainerDescriptor<Publication>, QueryCont
{
var filters = new List<Func<QueryContainerDescriptor<Publication>, QueryContainer>>();

if (parameters.ShowCoPublications is null || (bool)parameters.ShowCoPublications == false)
if (parameters.ShowOrganisationPartofCoPublication is null || (bool)parameters.ShowOrganisationPartofCoPublication == false)
{
filters.Add(t =>
t.Term(s => s.Field(f => f.IsCoPublication)
t.Term(s => s.Field(f => f.IsOrgPublication)
.Value(false)));
}

if (parameters.HideMainPublications is not null && (bool)parameters.HideMainPublications == true)
if (parameters.HideCoPublications is not null && (bool)parameters.HideCoPublications == true)
{
filters.Add(t =>
t.Term(s => s.Field(f => f.IsMainPublication)
t.Term(s => s.Field(f => f.IsCoPublication)
.Value(false)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class PublicationSearchParameters

public string? ModifiedTo { get; set; }

public bool? ShowCoPublications { get; set; }
public bool? ShowOrganisationPartofCoPublication { get; set; }

public bool? HideMainPublications { get; set; }
public bool? HideCoPublications { get; set; }
}
13 changes: 9 additions & 4 deletions aspnetcore/src/Repositories/Maps/PublicationProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public PublicationProfile()
.ForMember(dst => dst.ApcPaymentYear, opt =>opt.MapFrom(src => (DateTime?)(src.ApcPaymentYear.HasValue ? new DateTime(src.ApcPaymentYear.Value,1,1,0,0,0,DateTimeKind.Utc) : null)))
.ForMember(dst => dst.AuthorsText, opt => opt.MapFrom(src => src.AuthorsText))
.ForMember(dst => dst.DatabaseContributions, opt => opt.MapFrom(src => src.FactContributions))
.ForMember(dst => dst.orgPublicationDTOs, opt => opt.MapFrom(src => src.InverseDimPublicationNavigation))
.ForMember(dst => dst.Format, opt => opt.MapFrom(src => src.PublicationTypeCode2Navigation))
.ForMember(dst => dst.ParentPublicationType, opt => opt.MapFrom(src => src.ParentPublicationTypeCodeNavigation))
.ForMember(dst => dst.DatabasePeerReviewed, opt => opt.MapFrom(src => src.PeerReviewed))
Expand Down Expand Up @@ -78,10 +79,10 @@ public PublicationProfile()
.ForMember(dst => dst.Authors, opt => opt.Ignore()) // Handled during in memory operations in the index repository
.ForMember(dst => dst.PeerReviewed, opt => opt.Ignore()) // Handled during in memory operations in the index repository
.ForMember(dst => dst.ParentPublication, opt => opt.Ignore()) // Handled during in memory operations in the index repository
.ForMember(dst => dst.IsCoPublication, opt => opt.MapFrom(src => src.DimPublicationId != null && src.DimPublicationId > 0)) // Publication is a co-publication, when DimPublicationId references main publication. This property is used in query filter.
.ForMember(dst => dst.IsMainPublication, opt => opt.MapFrom(src => src.InverseDimPublicationNavigation.Count > 0)) // Publication is main publication, when InverseDimPublicationNavigation references one or more co-publications. This property is used in query filter.
.ForMember(dst => dst.Yhteisjulkaisu, opt => opt.MapFrom(src => src.DimPublicationId != null && src.DimPublicationId > 0 ? src.DimPublicationNavigation.PublicationId : null))
.ForMember(dst => dst.Osajulkaisut, opt => opt.MapFrom(src => src.InverseDimPublicationNavigation.Select(t => t.PublicationId)));
.ForMember(dst => dst.IsOrgPublication, opt => opt.MapFrom(src => src.DimPublicationId != null && src.DimPublicationId > 0)) // Publication is an organization publication, when DimPublicationId references co-publication. This property is used in query filter.
.ForMember(dst => dst.IsCoPublication, opt => opt.MapFrom(src => src.InverseDimPublicationNavigation.Count > 0)) // Publication is a co-publication, when InverseDimPublicationNavigation references one or more organization publications. This property is used in query filter.
.ForMember(dst => dst.CoPublicationID, opt => opt.MapFrom(src => src.DimPublicationId != null && src.DimPublicationId > 0 ? src.DimPublicationNavigation.PublicationId : null))
.ForMember(dst => dst.OrgPublicationIDs, opt => opt.MapFrom(src => src.InverseDimPublicationNavigation.Select(t => t.PublicationId)));

CreateProjection<DimReferencedatum, ReferenceData>()
.AddTransform<string?>(s => string.IsNullOrWhiteSpace(s) ? null : s)
Expand Down Expand Up @@ -136,6 +137,10 @@ public PublicationProfile()
.ForMember(dst => dst.ArtPublicationRole, opt => opt.MapFrom(src => src.DimReferencedataActorRole))
.ForMember(dst => dst.ContributionType, opt => opt.MapFrom(src => src.ContributionType));

CreateProjection<DatabaseContext.Entities.DimPublication, OrgPublicationDTO>()
.ForMember(dst => dst.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dst => dst.DatabaseContributions, opt => opt.MapFrom(src => src.FactContributions));

CreateProjection<DimName, Name>()
.AddTransform<string?>(s => string.IsNullOrWhiteSpace(s) ? null : s)
.ForMember(dst => dst.NameId, opt => opt.MapFrom(src => src.Id))
Expand Down
8 changes: 8 additions & 0 deletions aspnetcore/src/Repositories/PublicationIndexRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public override List<object> PerformInMemoryOperations(List<object> entities)
public override object PerformInMemoryOperation(object entity)
{
Publication publication = (Publication)entity;

if (publication.orgPublicationDTOs != null && publication.orgPublicationDTOs.Count > 0)
{
foreach (OrgPublicationDTO op in publication.orgPublicationDTOs.AsEnumerable().ToList())
{
publication.DatabaseContributions.AddRange(op.DatabaseContributions);
}
}

HandleIssnAndIsbn(publication);
HandleEmptyCollections(publication);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CSC.PublicApi.Service.Models.Publication;

// DTO used when collecting DatabaseContributions from OrgPublications (yhteisjulkaisu/osajulkaisu).
public class OrgPublicationDTO
{
public string? Id { get; set; }

public List<FactContribution>? DatabaseContributions { get; set; }
}
17 changes: 10 additions & 7 deletions aspnetcore/src/Service.Models/Publication/Publication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,24 +260,24 @@ public class Publication
public DateTime? Modified { get; set; }

/// <summary>
/// Onko julkaisu osajulkaisu - TEMPORARY NAME
/// Onko julkaisu yhteisjulkaisu
/// </summary>
public bool IsCoPublication { get; set; }

/// <summary>
/// Onko julkaisu yhteisjulkaisu - TEMPORARY NAME
/// Onko julkaisu osajulkaisu
/// </summary>
public bool IsMainPublication { get; set; }
public bool IsOrgPublication { get; set; }

/// <summary>
/// Osajulkaisun yhteisjulkaisu - TEMPORARY NAME
/// Osajulkaisun yhteisjulkaisu
/// </summary>
public string? Yhteisjulkaisu { get; set; }
public string? CoPublicationID { get; set; }

/// <summary>
/// Yhteisjulkaisuun liittyvät osajulkaisut - TEMPORARY NAME
/// Yhteisjulkaisuun liittyvät osajulkaisut
/// </summary>
public List<String>? Osajulkaisut { get; set; }
public List<String>? OrgPublicationIDs { get; set; }

[Ignore]
public string? Isbn1 { get; set; }
Expand All @@ -294,6 +294,9 @@ public class Publication
[Ignore]
public List<FactContribution>? DatabaseContributions { get; set; }

[Ignore]
public List<OrgPublicationDTO>? orgPublicationDTOs { get; set; }

[Ignore]
public bool? DatabasePeerReviewed { get; set; }

Expand Down
114 changes: 70 additions & 44 deletions aspnetcore/test/Indexer.Tests/Maps/PublicationProfileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication()
}

[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsCoPublication_When_DimPublicationId_Null()
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsOrgPublication_When_DimPublicationId_Null()
{
// Arrange
var entity = GetEntity();
entity.DimPublicationId = null;
var model = GetModel();
model.IsCoPublication = false;
model.IsOrgPublication = false;

// Act
var result = Act_Map(entity);
Expand All @@ -56,28 +56,13 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsCoPublica
}

[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsCoPublication_When_DimPublicationId_MinusOne()
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsOrgPublication_When_DimPublicationId_MinusOne()
{
// Arrange
var entity = GetEntity();
entity.DimPublicationId = -1;
var model = GetModel();
model.IsCoPublication = false;

// Act
var result = Act_Map(entity);

// Assert
result.Should().BeEquivalentTo(model, options => options);
}

[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsMainPublication()
{
// Arrange
var entity = GetEntity();
var model = GetModel();
model.IsMainPublication = false;
model.IsOrgPublication = false;

// Act
var result = Act_Map(entity);
Expand All @@ -86,42 +71,82 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsMainPubli
result.Should().BeEquivalentTo(model, options => options);
}

/*
[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_IsCoPublication_IsMainPublication()
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_IsOrgPublication_IsCoPublication()
{
// Arrange
var entity_mainPublication = GetEntity();
var entity_coPublication = GetEntity();
var entity_orgPublication = GetEntity();
// Entity - Yhteisjulkaisu
entity_mainPublication.PublicationId = "main publication id";
entity_mainPublication.Id = 1;
entity_mainPublication.InverseDimPublicationNavigation.Add(entity_coPublication);
entity_coPublication.PublicationId = "co-publication id";
entity_coPublication.Id = 1;
entity_coPublication.InverseDimPublicationNavigation.Add(entity_orgPublication);
// Entity - Osajulkaisu
entity_coPublication.PublicationId = "co publication id";
entity_coPublication.DimPublicationNavigation = entity_mainPublication;
entity_coPublication.DimPublicationId = entity_mainPublication.Id;
entity_orgPublication.PublicationId = "org publication id";
entity_orgPublication.DimPublicationNavigation = entity_coPublication;
entity_orgPublication.DimPublicationId = entity_coPublication.Id;
// Model - Yhteisjulkaisu
var model_mainPublication = GetModel();
model_mainPublication.Id = "main publication id";
model_mainPublication.IsMainPublication = true;
model_mainPublication.IsCoPublication = false;
model_mainPublication.Osajulkaisut = new List<string> { "co publication id" };
// Model - Osajulkaisu
var model_coPublication = GetModel();
model_coPublication.Id = "co publication id";
model_coPublication.IsMainPublication = false;
model_coPublication.Id = "co-publication id";
model_coPublication.IsCoPublication = true;
model_coPublication.Yhteisjulkaisu = "main publication id";
model_coPublication.IsOrgPublication = false;
model_coPublication.OrgPublicationIDs = new List<string> { "org publication id" };
model_coPublication.orgPublicationDTOs = new List<OrgPublicationDTO> {
new OrgPublicationDTO {
Id = "org publication id",
DatabaseContributions = new () {
new CSC.PublicApi.Service.Models.Publication.FactContribution() {
ArtPublicationRole = new () {
Code =
"roleCode",
NameEn =
"roleNameEn",
NameFi =
"roleNameFi",
NameSv =
"roleNameSv"
},
ContributionType = "publication_author_organization",
Name = new()
{
FirstNames =
"personFirstName",
LastName =
"personLastName",
NameId = 23,
Orcid =
"pidContent"
},
OrganizationId = 42
},
new CSC.PublicApi.Service.Models.Publication.FactContribution() {
ArtPublicationRole = null,
ContributionType =
"publication_organization",
Name = null,
OrganizationId = 41
},
}
}
};
// Model - Osajulkaisu
var model_orgPublication = GetModel();
model_orgPublication.Id = "org publication id";
model_orgPublication.IsCoPublication = false;
model_orgPublication.IsOrgPublication = true;
model_orgPublication.CoPublicationID = "co-publication id";
// Act
var resultCoPublication = Act_Map(entity_coPublication);
var resultMainPublication = Act_Map(entity_mainPublication);
var resultOrgPublication = Act_Map(entity_orgPublication);
// Assert
resultMainPublication.Should().BeEquivalentTo(model_mainPublication, options => options);
resultCoPublication.Should().BeEquivalentTo(model_coPublication, options => options);
resultOrgPublication.Should().BeEquivalentTo(model_orgPublication, options => options);
}

*/
/*
[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_MainPublication_Lists_CoPublications()
{
Expand All @@ -147,15 +172,15 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication_MainPublication
model.Id = "yhteisjulkaisu";
model.IsMainPublication = true;
model.IsCoPublication = false;
model.Osajulkaisut = new List<string> { "osajulkaisu1", "osajulkaisu2" };
model.OrgPublicationIDs = new List<string> { "osajulkaisu1", "osajulkaisu2" };
// Act
var result = Act_Map(entity_mainPublication);
// Assert
result.Should().BeEquivalentTo(model, options => options);
}

*/
private Publication Act_Map(DimPublication dbEntity)
{
var entityQueryable = new List<DimPublication>
Expand Down Expand Up @@ -622,10 +647,11 @@ private Publication GetModel()
NameSv = "publisherOpenAccessCodeSv",
NameEn = "publisherOpenAccessCodeEn"
},
Yhteisjulkaisu = null,
Osajulkaisut = new List<string> {},
CoPublicationID = null,
OrgPublicationIDs = new List<string> {},
Created = new DateTime(2023, 3, 10, 10, 43, 00),
Modified = new DateTime(2023, 3, 10, 10, 44, 00)
Modified = new DateTime(2023, 3, 10, 10, 44, 00),
orgPublicationDTOs = new()
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private static object GetServiceModel()
NameEn = "artPublicationTypeNameEn"
}
},
Osajulkaisut = new List<string> {},
OrgPublicationIDs = new List<string> {},
Created = new DateTime(2023, 3, 10, 10, 43, 00),
Modified = new DateTime(2023, 3, 10, 10, 44, 00)
};
Expand Down Expand Up @@ -496,7 +496,7 @@ private static object GetApiModel()
NameEn = "artPublicationTypeNameEn"
}
},
Osajulkaisut = new(),
OrgPublicationIDs = new(),
Created = new DateTime(2023, 3, 10, 10, 43, 00),
Modified = new DateTime(2023, 3, 10, 10, 44, 00)
};
Expand Down

0 comments on commit 301a17c

Please sign in to comment.