Skip to content

Commit

Permalink
Add possibility to exclude main pulibcations from search result.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkikos committed Oct 11, 2024
1 parent 9453f0e commit 6e7cebf
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,10 @@ public class GetPublicationsQueryParameters : PaginationQueryParameters
/// </summary>
/// <see cref="Publication.ShowCoPublications"/>
public bool? ShowCoPublications { get; set; }

/// <summary>
/// If the selection is true, main publications will be filtered out.
/// </summary>
/// <see cref="Publication.HideMainPublications"/>
public bool? HideMainPublications { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ private static IEnumerable<Func<QueryContainerDescriptor<Publication>, QueryCont
.Value(false)));
}

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

if (parameters.CreatedFrom is not null)
{
filters.Add(x => x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ public class PublicationSearchParameters
public string? ModifiedTo { get; set; }

public bool? ShowCoPublications { get; set; }

public bool? HideMainPublications { get; set; }
}
3 changes: 2 additions & 1 deletion aspnetcore/src/Repositories/Maps/PublicationProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ 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
.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)));

Expand Down
5 changes: 5 additions & 0 deletions aspnetcore/src/Service.Models/Publication/Publication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public class Publication
/// </summary>
public bool IsCoPublication { get; set; }

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

/// <summary>
/// Osajulkaisun yhteisjulkaisu - TEMPORARY NAME
/// </summary>
Expand Down
57 changes: 43 additions & 14 deletions aspnetcore/test/Indexer.Tests/Maps/PublicationProfileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication()
}

[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_CoPublication_When_DimPublicationId_Null()
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsCoPublication_When_DimPublicationId_Null()
{
// Arrange
var entity = GetEntity();
Expand All @@ -56,7 +56,7 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_CoPublicati
}

[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_CoPublication_When_DimPublicationId_MinusOne()
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_IsCoPublication_When_DimPublicationId_MinusOne()
{
// Arrange
var entity = GetEntity();
Expand All @@ -72,27 +72,54 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication_Not_CoPublicati
}

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

// Act
var result = Act_Map(entity);

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

[Fact]
public void ProjectTo_DimPublication_ShouldBeMappedToPublication_IsCoPublication_IsMainPublication()
{
// Arrange
// Yhteisjulkaisu
var entity_mainPublication = GetEntity();
entity_mainPublication.PublicationId = "yhteisjulkaisu";
entity_mainPublication.Id = 1;
// Osajulkaisu
var entity_coPublication = GetEntity();
// Entity - Yhteisjulkaisu
entity_mainPublication.PublicationId = "main publication id";
entity_mainPublication.Id = 1;
entity_mainPublication.InverseDimPublicationNavigation.Add(entity_coPublication);
// Entity - Osajulkaisu
entity_coPublication.PublicationId = "co publication id";
entity_coPublication.DimPublicationNavigation = entity_mainPublication;
entity_coPublication.DimPublicationId = 1;

var model = GetModel();
model.IsCoPublication = true;
model.Yhteisjulkaisu = "yhteisjulkaisu";
entity_coPublication.DimPublicationId = entity_mainPublication.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.IsCoPublication = true;
model_coPublication.Yhteisjulkaisu = "main publication id";

// Act
var result = Act_Map(entity_coPublication);
var resultCoPublication = Act_Map(entity_coPublication);
var resultMainPublication = Act_Map(entity_mainPublication);

// Assert
result.Should().BeEquivalentTo(model, options => options);
resultMainPublication.Should().BeEquivalentTo(model_mainPublication, options => options);
resultCoPublication.Should().BeEquivalentTo(model_coPublication, options => options);
}

[Fact]
Expand All @@ -118,6 +145,7 @@ public void ProjectTo_DimPublication_ShouldBeMappedToPublication_MainPublication

var model = GetModel();
model.Id = "yhteisjulkaisu";
model.IsMainPublication = true;
model.IsCoPublication = false;
model.Osajulkaisut = new List<string> { "osajulkaisu1", "osajulkaisu2" };

Expand Down Expand Up @@ -594,6 +622,7 @@ private Publication GetModel()
NameSv = "publisherOpenAccessCodeSv",
NameEn = "publisherOpenAccessCodeEn"
},
Yhteisjulkaisu = null,
Osajulkaisut = new List<string> {},
Created = new DateTime(2023, 3, 10, 10, 43, 00),
Modified = new DateTime(2023, 3, 10, 10, 44, 00)
Expand Down

0 comments on commit 6e7cebf

Please sign in to comment.