Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Jan 22, 2025
1 parent b0e6416 commit a5af74f
Showing 1 changed file with 17 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,20 @@ final case class OntologyTriplestoreHelpers(
}

/**
* Checks that:
* 1. The metadata of an ontology is loaded and has a `lastModificationDate`.
* 2. The `lastModificationDate` of an ontology is the same as the one we expect it to be.
* Checks that the last modification date of an ontology is the same as the one we expect it to be. If not, return
* an error message fitting for the "before update" case.
*
* @param ontologyIri The internal IRI of the ontology.
* @param expectedLastModificationDate The last modification date that the ontology is expected to have.
* @param error It will be returned if the expected last modification date is not found.
* @return A failed Task if the checks fail:
* The 1. check fails with an [[InconsistentRepositoryDataException]] and
* The 2. check fails with the provided error.
* @param internalOntologyIri the internal IRI of the ontology.
* @param expectedLastModificationDate the last modification date that should now be attached to the ontology.
* @return a failed Future if the expected last modification date is not found.
*/
private def checkOntologyLastModificationDate(
ontologyIri: SmartIri,
def checkOntologyLastModificationDateBeforeUpdate(
internalOntologyIri: SmartIri,
expectedLastModificationDate: Instant,
disableLastModificationDateCheck: Boolean,
error: => Exception,
): Task[Unit] =
for {
metadataMaybe <- loadOntologyMetadata(ontologyIri)
externalOntologyIri <- ZIO.attempt(ontologyIri.toOntologySchema(ApiV2Complex))
metadataMaybe <- loadOntologyMetadata(internalOntologyIri)
externalOntologyIri <- ZIO.attempt(internalOntologyIri.toOntologySchema(ApiV2Complex))
metadata <-
ZIO
.fromOption(metadataMaybe)
Expand All @@ -191,31 +185,16 @@ final case class OntologyTriplestoreHelpers(
}
_ <-
ZIO
.fail(error)
.when(!disableLastModificationDateCheck && existingLastModificationDate != expectedLastModificationDate)
.fail(
EditConflictException(
s"Ontology ${internalOntologyIri.toOntologySchema(ApiV2Complex)} has been modified by another user, please reload it and try again.",
),
)
.when(
!features.disableLastModificationDateCheck && existingLastModificationDate != expectedLastModificationDate,
)
} yield ()

/**
* Checks that the last modification date of an ontology is the same as the one we expect it to be. If not, return
* an error message fitting for the "before update" case.
*
* @param internalOntologyIri the internal IRI of the ontology.
* @param expectedLastModificationDate the last modification date that should now be attached to the ontology.
* @return a failed Future if the expected last modification date is not found.
*/
def checkOntologyLastModificationDateBeforeUpdate(
internalOntologyIri: SmartIri,
expectedLastModificationDate: Instant,
): Task[Unit] =
checkOntologyLastModificationDate(
internalOntologyIri,
expectedLastModificationDate,
features.disableLastModificationDateCheck,
EditConflictException(
s"Ontology ${internalOntologyIri.toOntologySchema(ApiV2Complex)} has been modified by another user, please reload it and try again.",
),
)

/**
* Gets the set of subjects that refer to an ontology or its entities.
*
Expand Down

0 comments on commit a5af74f

Please sign in to comment.