Skip to content

Commit

Permalink
Showing 2 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -121,6 +121,20 @@ trait WriteService {
}
}

private def shouldUpdateNotes(existing: domain.Concept, changed: domain.Concept): Boolean = {
// Function that sets values we don't want to include when comparing concepts to check if we should update notes
val withComparableValues =
(concept: domain.Concept) =>
concept.copy(
revision = None,
created = NDLADate.fromUnixTime(0),
updated = NDLADate.fromUnixTime(0),
responsible = None,
updatedBy = Seq.empty
)
withComparableValues(existing) != withComparableValues(changed)
}

private def updateNotes(
old: domain.Concept,
updated: api.UpdatedConcept,
@@ -129,8 +143,11 @@ trait WriteService {
): domain.Concept = {
val isNewLanguage =
!old.supportedLanguages.contains(updated.language) && changed.supportedLanguages.contains(updated.language)
val newLanguageEditorNote =
if (isNewLanguage) Seq(s"New language '${updated.language}' added.")
val dataChanged = shouldUpdateNotes(old, changed);

val newEditorNote =
if (isNewLanguage) Seq(s"New language '${updated.language}' added")
else if (dataChanged) Seq(s"Updated ${old.conceptType}")
else Seq.empty

val changedResponsibleNote =
@@ -139,7 +156,7 @@ trait WriteService {
Seq("Responsible changed")
case _ => Seq.empty
}
val allNewNotes = newLanguageEditorNote ++ changedResponsibleNote
val allNewNotes = newEditorNote ++ changedResponsibleNote

changed.copy(editorNotes =
changed.editorNotes ++ allNewNotes.map(domain.EditorNote(_, user.id, changed.status, clock.now()))
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ class WriteServiceTest extends UnitSuite with TestEnvironment {
articleIds = Seq.empty,
editorNotes = Some(
Seq(
api.EditorNote("New language 'en' added.", "", api.Status("IN_PROGRESS", Seq.empty), today)
api.EditorNote("New language 'en' added", "", api.Status("IN_PROGRESS", Seq.empty), today)
)
)
)
@@ -130,7 +130,7 @@ class WriteServiceTest extends UnitSuite with TestEnvironment {
articleIds = Seq.empty,
editorNotes = Some(
Seq(
api.EditorNote("New language 'nn' added.", "", api.Status("IN_PROGRESS", Seq.empty), today)
api.EditorNote("New language 'nn' added", "", api.Status("IN_PROGRESS", Seq.empty), today)
)
)
)
@@ -193,7 +193,7 @@ class WriteServiceTest extends UnitSuite with TestEnvironment {
responsible = Some(api.ConceptResponsible("123", today)),
editorNotes = Some(
Seq(
api.EditorNote("New language 'en' added.", "", api.Status("IN_PROGRESS", Seq.empty), today),
api.EditorNote("New language 'en' added", "", api.Status("IN_PROGRESS", Seq.empty), today),
api.EditorNote("Responsible changed", "", api.Status("IN_PROGRESS", Seq.empty), today)
)
)
@@ -265,24 +265,24 @@ class WriteServiceTest extends UnitSuite with TestEnvironment {
val responsibleId = "ResponsibleId"
val updatedApiConcept =
api.UpdatedConcept(
"nb",
None,
None,
Right(None),
None,
None,
None,
Some(Seq.empty),
None,
None,
Right(Some(responsibleId)),
None,
None
language = "nb",
title = None,
content = None,
metaImage = Right(None),
copyright = None,
tags = None,
subjectIds = None,
articleIds = Some(Seq(42)),
status = None,
visualElement = None,
responsibleId = Right(Some(responsibleId)),
conceptType = None,
glossData = None
)
val expectedConcept = concept.copy(
updated = today,
supportedLanguages = Set("nb"),
articleIds = Seq.empty,
articleIds = Seq(42),
responsible = Some(api.ConceptResponsible(responsibleId, today)),
editorNotes = Some(
Seq(

0 comments on commit 9d236d9

Please sign in to comment.