diff --git a/nio-server/app/models/ConsentFact.scala b/nio-server/app/models/ConsentFact.scala index 59d2e43..d87f802 100644 --- a/nio-server/app/models/ConsentFact.scala +++ b/nio-server/app/models/ConsentFact.scala @@ -344,7 +344,6 @@ case class PartialConsentFact( metaData = metaData.map(meta => lastConsentFact.metaData.map(m => m.combine(meta)).getOrElse(meta)).orElse(lastConsentFact.metaData), sendToKafka = sendToKafka.orElse(lastConsentFact.sendToKafka) ) - println(s"Merged data : $this, \n $lastConsentFact, \n $finalConsent") finalConsent } } @@ -470,9 +469,9 @@ case class ConsentFact( this.copy(groups = this.groups.map( group => group.copy( consents = group.consents.map ( consent => - consent.copy(expiredAt = indexed.get(KeyPermissionGroup(group.key, consent.key)) + consent.copy(expiredAt = consent.expiredAt.orElse(indexed.get(KeyPermissionGroup(group.key, consent.key)) .flatMap(_.headOption) - .flatMap(_._2.getValidityPeriod) + .flatMap(_._2.getValidityPeriod)) ) ) ) diff --git a/nio-server/app/service/ConsentManagerService.scala b/nio-server/app/service/ConsentManagerService.scala index 68793d0..b033a9e 100644 --- a/nio-server/app/service/ConsentManagerService.scala +++ b/nio-server/app/service/ConsentManagerService.scala @@ -51,13 +51,12 @@ class ConsentManagerService( author: String, metadata: Option[Seq[(String, String)]], organisation: Organisation, - consentFactInput: ConsentFact, + consentFact: ConsentFact, maybeLastConsentFact: Option[ConsentFact] = None, command: JsValue ): IO[AppErrorWithStatus, ConsentFact] = for { - _ <- IO.fromEither(organisation.isValidWith(consentFactInput, maybeLastConsentFact)).mapError(m => AppErrorWithStatus(m)) - consentFact: ConsentFact = consentFactInput.setUpValidityPeriods(organisation) + _ <- IO.fromEither(organisation.isValidWith(consentFact, maybeLastConsentFact)).mapError(m => AppErrorWithStatus(m)) organisationKey: String = organisation.key userId: String = consentFact.userId _ <- validateOffersStructures(tenant, organisationKey, userId, consentFact.offers).doOnError{ e => NioLogger.error(s"validate offers structure $e") } @@ -302,7 +301,7 @@ class ConsentManagerService( AppErrorWithStatus("error.specified.version.not.latest") }) .flatMap { organisation => - createOrReplace(tenant, author, metadata, organisation, consentFact, command = command) + createOrReplace(tenant, author, metadata, organisation, consentFact.setUpValidityPeriods(organisation), command = command) } // Update consent fact with the same organisation version @@ -316,7 +315,7 @@ class ConsentManagerService( } ) .flatMap { organisation => - createOrReplace(tenant, author, metadata, organisation, consentFact, Some(lastConsentFactStored), command = command) + createOrReplace(tenant, author, metadata, organisation, consentFact.setUpValidityPeriods(organisation), Some(lastConsentFactStored), command = command) } // Update consent fact with the new organisation version @@ -333,7 +332,7 @@ class ConsentManagerService( _ => AppErrorWithStatus("error.version.higher.than.release") }) .flatMap { organisation => - createOrReplace(tenant, author, metadata, organisation, consentFact, Option(lastConsentFactStored), command = command) + createOrReplace(tenant, author, metadata, organisation, consentFact.setUpValidityPeriods(organisation), Option(lastConsentFactStored), command = command) } // Cannot rollback and update a consent fact to an old organisation version