Skip to content

Commit

Permalink
Merge branch 'main' into update/minor
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Dec 19, 2024
2 parents 5a6bb6c + c87233b commit 96d6daf
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 458 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## [31.1.0](https://github.com/dasch-swiss/dsp-api/compare/v31.0.0...v31.1.0) (2024-12-16)


### Maintenances

* Patch dependency updates ([#3444](https://github.com/dasch-swiss/dsp-api/issues/3444)) ([a29e9dd](https://github.com/dasch-swiss/dsp-api/commit/a29e9dddfe2bb2f826146a069edd0cf5bda64d14))


### Enhancements

* Split license into licenseText and licenseUri (DEV-4398) ([#3436](https://github.com/dasch-swiss/dsp-api/issues/3436)) ([76d2db2](https://github.com/dasch-swiss/dsp-api/commit/76d2db25a75ffd43294e2d1d25e98f53f5d0e275))


### Bug Fixes

* Dummy filenames may not contain a file extension, remove it only if it exists (DEV-4227) ([#3442](https://github.com/dasch-swiss/dsp-api/issues/3442)) ([a6c8f2b](https://github.com/dasch-swiss/dsp-api/commit/a6c8f2bc3b78c556106e879d037f2a001306aae5))


### Tests

* Add test data to anything project ([#3441](https://github.com/dasch-swiss/dsp-api/issues/3441)) ([3660ae6](https://github.com/dasch-swiss/dsp-api/commit/3660ae63dca8809174c432605e21912e5143fe55))

## [31.0.0](https://github.com/dasch-swiss/dsp-api/compare/v30.22.0...v31.0.0) (2024-12-02)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ object ProjectEraseIT extends E2EZSpec {
None,
KnoraProject.Status.Active,
KnoraProject.SelfJoin.CanJoin,
None,
None,
None,
),
),
).orDie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import zio.*
import zio.http.Body
import zio.http.Response
import zio.test.*
import zio.test.TestAspect

import java.net.URLEncoder
import scala.jdk.CollectionConverters.IteratorHasAsScala
Expand All @@ -30,7 +29,6 @@ import org.knora.webapi.models.filemodels.UploadFileRequest
import org.knora.webapi.slice.admin.domain.model.KnoraProject.CopyrightAttribution
import org.knora.webapi.slice.admin.domain.model.KnoraProject.LicenseText
import org.knora.webapi.slice.admin.domain.model.KnoraProject.LicenseUri
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode
import org.knora.webapi.slice.admin.domain.service.KnoraProjectService
import org.knora.webapi.slice.common.KnoraIris.ValueIri
import org.knora.webapi.slice.common.jena.JenaConversions.given
Expand All @@ -45,13 +43,7 @@ object CopyrightAndLicensesSpec extends E2EZSpec {
private val aLicenseText = LicenseText.unsafeFrom("CC BY-SA 4.0")
private val aLicenseUri = LicenseUri.unsafeFrom("https://creativecommons.org/licenses/by-sa/4.0/")

private val projectCopyrightAttribution = CopyrightAttribution.unsafeFrom("2024, On Project")
private val projectLicenseText = LicenseText.unsafeFrom("Apache-2.0")
private val projectLicenseUri = LicenseUri.unsafeFrom("https://www.apache.org/licenses/LICENSE-2.0")

private val givenProjectHasNoCopyrightAttributionAndLicenseSuite = suite(
"given the project does not have a license and does not have a copyright attribution ",
)(
private val givenProjectHasNoCopyrightAttributionAndLicenseSuite = suite("Creating Resources")(
test(
"when creating a resource without copyright attribution and license" +
"the creation response should not contain the license and copyright attribution",
Expand Down Expand Up @@ -118,124 +110,12 @@ object CopyrightAndLicensesSpec extends E2EZSpec {
actualLicenseUri == aLicenseUri.value,
)
},
test(
"when creating a resource without copyright attribution and license " +
"and when providing the project with copyright attribution and license " +
"and then updating the value" +
"the response when getting the updated value should contain the license and copyright attribution of the project",
) {
for {
createResourceResponseModel <- createStillImageResource()
_ <- addCopyrightAttributionAndLicenseToProject()
resourceId <- resourceId(createResourceResponseModel)
valueId <- valueId(createResourceResponseModel)
_ <- updateValue(resourceId, valueId)
valueGetResponse <- getValueFromApi(createResourceResponseModel)
actualCopyright <- copyrightValue(valueGetResponse)
actualLicenseText <- licenseTextValue(valueGetResponse)
actualLicenseUri <- licenseUriValue(valueGetResponse)
} yield assertTrue(
actualCopyright == projectCopyrightAttribution.value,
actualLicenseText == projectLicenseText.value,
actualLicenseUri == projectLicenseUri.value,
)
},
) @@ TestAspect.before(removeCopyrightAttributionAndLicenseFromProject())

private val givenProjectHasCopyrightAttributionAndLicenseSuite = suite(
"given the project has a license and has a copyright attribution",
)(
test(
"when creating a resource without copyright attribution and without license " +
"then the response when getting the created value should contain the default license and default copyright attribution",
) {
for {
createResourceResponseModel <- createStillImageResource()
valueResponseModel <- getValueFromApi(createResourceResponseModel)
actualCopyright <- copyrightValue(valueResponseModel)
actualLicenseText <- licenseTextValue(valueResponseModel)
actualLicenseUri <- licenseUriValue(valueResponseModel)
} yield assertTrue(
actualCopyright == projectCopyrightAttribution.value,
actualLicenseText == projectLicenseText.value,
actualLicenseUri == projectLicenseUri.value,
)
},
test(
"when creating a resource without copyright attribution and without license " +
"then the create response contain the license and copyright attribution from resource",
) {
for {
createResourceResponseModel <- createStillImageResource()
actualCopyright <- copyrightValue(createResourceResponseModel)
actualLicenseText <- licenseTextValue(createResourceResponseModel)
actualLicenseUri <- licenseUriValue(createResourceResponseModel)
} yield assertTrue(
actualCopyright == projectCopyrightAttribution.value,
actualLicenseText == projectLicenseText.value,
actualLicenseUri == projectLicenseUri.value,
)
},
test(
"when creating a resource with copyright attribution and license " +
"then the create response contain the license and copyright attribution from resource",
) {
for {
createResourceResponseModel <-
createStillImageResource(Some(aCopyrightAttribution), Some(aLicenseText), Some(aLicenseUri))
actualCopyright <- copyrightValue(createResourceResponseModel)
actualLicenseText <- licenseTextValue(createResourceResponseModel)
actualLicenseUri <- licenseUriValue(createResourceResponseModel)
} yield assertTrue(
actualCopyright == aCopyrightAttribution.value,
actualLicenseText == aLicenseText.value,
actualLicenseUri == aLicenseUri.value,
)
},
test(
"when creating a resource with copyright attribution and without license " +
"then the response when getting the created value should contain the license and copyright attribution from resource",
) {
for {
createResourceResponseModel <-
createStillImageResource(Some(aCopyrightAttribution), Some(aLicenseText), Some(aLicenseUri))
valueResponseModel <- getValueFromApi(createResourceResponseModel)
actualCopyright <- copyrightValue(valueResponseModel)
actualLicenseText <- licenseTextValue(valueResponseModel)
actualLicenseUri <- licenseUriValue(valueResponseModel)
} yield assertTrue(
actualCopyright == aCopyrightAttribution.value,
actualLicenseText == aLicenseText.value,
actualLicenseUri == aLicenseUri.value,
)
},
) @@ TestAspect.before(addCopyrightAttributionAndLicenseToProject())
)

val e2eSpec: Spec[Scope & env, Any] = suite("Copyright Attribution and Licenses")(
givenProjectHasNoCopyrightAttributionAndLicenseSuite,
givenProjectHasCopyrightAttributionAndLicenseSuite,
)

private def removeCopyrightAttributionAndLicenseFromProject() =
setCopyrightAttributionAndLicenseToProject(None, None, None)
private def addCopyrightAttributionAndLicenseToProject() =
setCopyrightAttributionAndLicenseToProject(
Some(projectCopyrightAttribution),
Some(projectLicenseText),
Some(projectLicenseUri),
)
private def setCopyrightAttributionAndLicenseToProject(
copyrightAttribution: Option[CopyrightAttribution],
licenseText: Option[LicenseText],
licenseUri: Option[LicenseUri],
) =
for {
projectService <- ZIO.service[KnoraProjectService]
prj <- projectService.findByShortcode(Shortcode.unsafeFrom("0001")).someOrFail(new Exception("Project not found"))
change = prj.copy(copyrightAttribution = copyrightAttribution, licenseText = licenseText, licenseUri = licenseUri)
updated <- projectService.save(change)
} yield updated

private def failResponse(msg: String)(response: Response) =
response.body.asString.flatMap(bodyStr => ZIO.fail(Exception(s"$msg\nstatus: ${response.status}\nbody: $bodyStr")))

Expand All @@ -262,34 +142,6 @@ object CopyrightAndLicensesSpec extends E2EZSpec {
} yield createResourceResponseModel
}

private def updateValue(resourceIri: String, valueId: ValueIri) = {
val jsonLd =
s"""
|{
| "@id": "${resourceIri}",
| "@type": "anything:ThingPicture",
| "knora-api:hasStillImageFileValue": {
| "@id" : "${valueId.smartIri.toComplexSchema.toIri}",
| "@type": "knora-api:StillImageFileValue",
| "knora-api:fileValueHasFilename": "test.jpg"
| },
| "@context": {
| "knora-api": "http://api.knora.org/ontology/knora-api/v2#",
| "anything": "http://0.0.0.0:3333/ontology/0001/anything/v2#"
| }
|}
|""".stripMargin
for {
_ <- Console.printLine(jsonLd)
_ <- ModelOps.fromJsonLd(jsonLd).mapError(Exception(_))
responseBody <-
sendPutRequestAsRoot("/v2/values", Body.fromString(jsonLd))
.filterOrElseWith(_.status.isSuccess)(failResponse(s"Value update failed $valueId resource $resourceIri."))
.flatMap(_.body.asString)
model <- ModelOps.fromJsonLd(responseBody).mapError(Exception(_))
} yield model
}

private def getResourceFromApi(resourceId: String) = for {
responseBody <- sendGetRequest(s"/v2/resources/${URLEncoder.encode(resourceId, "UTF-8")}")
.filterOrElseWith(_.status.isSuccess)(failResponse(s"Failed to get resource $resourceId."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ object IntegrationTestAdminJsonProtocol extends TriplestoreJsonProtocol {
"ontologies",
"status",
"selfjoin",
"copyrightAttribution",
"licenseText",
"licenseUri",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
logo = Some(Logo.unsafeFrom("/fu/bar/baz.jpg")),
status = Status.Active,
selfjoin = SelfJoin.CannotJoin,
copyrightAttribution = Some(CopyrightAttribution.unsafeFrom("2024, Example Project")),
licenseText = Some(LicenseText.unsafeFrom("CC-BY-4.0")),
licenseUri = Some(LicenseUri.unsafeFrom("https://creativecommons.org/licenses/by/4.0/")),
),
SharedTestDataADM.rootUser,
),
Expand All @@ -177,12 +174,6 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
received.project.description should be(
Seq(StringLiteralV2.from(value = "project description", language = Some("en"))),
)
received.project.copyrightAttribution should be(Some(CopyrightAttribution.unsafeFrom("2024, Example Project")))
received.project.licenseText should be(Some(LicenseText.unsafeFrom("CC-BY-4.0")))
received.project.licenseUri should be(
Some(LicenseUri.unsafeFrom("https://creativecommons.org/licenses/by/4.0/")),
)

newProjectIri.set(received.project.id)

// Check Administrative Permissions
Expand Down Expand Up @@ -265,9 +256,6 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
logo = Some(Logo.unsafeFrom("/fu/bar/baz.jpg")),
status = Status.Active,
selfjoin = SelfJoin.CannotJoin,
None,
None,
None,
),
SharedTestDataADM.rootUser,
),
Expand All @@ -280,9 +268,6 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
received.project.description should be(
Seq(StringLiteralV2.from(value = "project description", language = Some("en"))),
)
received.project.copyrightAttribution should be(None)
received.project.licenseText should be(None)
received.project.licenseUri should be(None)
}

"CREATE a project that its info has special characters" in {
Expand All @@ -305,9 +290,6 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
logo = Some(Logo.unsafeFrom("/fu/bar/baz.jpg")),
status = Status.Active,
selfjoin = SelfJoin.CannotJoin,
None,
None,
None,
),
SharedTestDataADM.rootUser,
),
Expand Down Expand Up @@ -340,9 +322,6 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
logo = Some(Logo.unsafeFrom("/fu/bar/baz.jpg")),
status = Status.Active,
selfjoin = SelfJoin.CannotJoin,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
),
SharedTestDataADM.rootUser,
),
Expand All @@ -365,9 +344,6 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
logo = Some(Logo.unsafeFrom("/fu/bar/baz.jpg")),
status = Status.Active,
selfjoin = SelfJoin.CannotJoin,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
),
SharedTestDataADM.rootUser,
),
Expand Down
Loading

0 comments on commit 96d6daf

Please sign in to comment.