Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove license and copyright from Project (DEV-4479) #3445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ object SharedTestDataADM {
),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/* represents the full ProjectADM of the default shared ontologies project */
Expand All @@ -186,9 +183,6 @@ object SharedTestDataADM {
ontologies = Seq.empty[IRI],
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/**
Expand Down Expand Up @@ -301,9 +295,6 @@ object SharedTestDataADM {
ontologies = Seq(SharedOntologyTestDataADM.IMAGES_ONTOLOGY_IRI),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/* represents the full ProjectADM of the images project in the external format */
Expand All @@ -318,9 +309,6 @@ object SharedTestDataADM {
ontologies = Seq(SharedOntologyTestDataADM.IMAGES_ONTOLOGY_IRI_LocalHost),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/* represents the full GroupADM of the images ProjectAdmin group */
Expand Down Expand Up @@ -484,9 +472,6 @@ object SharedTestDataADM {
ontologies = Seq(SharedOntologyTestDataADM.INCUNABULA_ONTOLOGY_IRI),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/* represents the ProjectADM of the incunabula project in the external format*/
Expand Down Expand Up @@ -522,9 +507,6 @@ object SharedTestDataADM {
ontologies = Seq(SharedOntologyTestDataADM.INCUNABULA_ONTOLOGY_IRI_LocalHost),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/**
Expand Down Expand Up @@ -637,9 +619,6 @@ object SharedTestDataADM {
ontologies = Seq(SharedOntologyTestDataADM.ANYTHING_ONTOLOGY_IRI, SharedOntologyTestDataADM.SomethingOntologyIri),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

def anythingProjectExternal: Project = Project(
Expand All @@ -656,9 +635,6 @@ object SharedTestDataADM {
),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/* represents the full GroupADM of the Thing searcher group */
Expand Down Expand Up @@ -696,9 +672,6 @@ object SharedTestDataADM {
),
status = true,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)

/* represents the user profile of 'superuser' as found in admin-data.ttl */
Expand Down Expand Up @@ -748,8 +721,5 @@ object SharedTestDataADM {
ontologies = Seq("http://www.knora.org/ontology/0804/dokubib"),
status = false,
selfjoin = false,
copyrightAttribution = None,
licenseText = None,
licenseUri = None,
)
}
Loading
Loading