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

refactor: Remove unused or dead code #2827

Merged
merged 17 commits into from
Sep 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,8 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val projectIri = incunabulaProjectIri
val resourceClassIri = s"$INCUNABULA_ONTOLOGY_IRI#book"

val result = SharedTestDataADM.rootUser.permissions.hasPermissionFor(
ResourceCreateOperation(resourceClassIri),
projectIri,
None
)
val result =
SharedTestDataADM.rootUser.permissions.hasPermissionFor(ResourceCreateOperation(resourceClassIri), projectIri)

result should be(true)
}
Expand All @@ -837,7 +834,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val resourceClassIri = s"$INCUNABULA_ONTOLOGY_IRI#book"

val result = SharedTestDataADM.incunabulaProjectAdminUser.permissions
.hasPermissionFor(ResourceCreateOperation(resourceClassIri), projectIri, None)
.hasPermissionFor(ResourceCreateOperation(resourceClassIri), projectIri)

result should be(true)
}
Expand All @@ -848,7 +845,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val resourceClassIri = s"$INCUNABULA_ONTOLOGY_IRI#book"

val result = SharedTestDataADM.incunabulaMemberUser.permissions
.hasPermissionFor(ResourceCreateOperation(resourceClassIri), projectIri, None)
.hasPermissionFor(ResourceCreateOperation(resourceClassIri), projectIri)

result should be(true)
}
Expand All @@ -857,11 +854,8 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val projectIri = incunabulaProjectIri
val resourceClassIri = s"$INCUNABULA_ONTOLOGY_IRI#book"

val result = SharedTestDataADM.normalUser.permissions.hasPermissionFor(
ResourceCreateOperation(resourceClassIri),
projectIri,
None
)
val result =
SharedTestDataADM.normalUser.permissions.hasPermissionFor(ResourceCreateOperation(resourceClassIri), projectIri)

result should be(false)
}
Expand All @@ -872,11 +866,11 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val allowedResourceClassIri02 = s"$IMAGES_ONTOLOGY_IRI#bildformat"

val result1 = SharedTestDataADM.imagesReviewerUser.permissions
.hasPermissionFor(ResourceCreateOperation(allowedResourceClassIri01), projectIri, None)
.hasPermissionFor(ResourceCreateOperation(allowedResourceClassIri01), projectIri)
result1 should be(true)

val result2 = SharedTestDataADM.imagesReviewerUser.permissions
.hasPermissionFor(ResourceCreateOperation(allowedResourceClassIri02), projectIri, None)
.hasPermissionFor(ResourceCreateOperation(allowedResourceClassIri02), projectIri)
result2 should be(true)
}

Expand All @@ -885,7 +879,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
val notAllowedResourceClassIri = s"$IMAGES_ONTOLOGY_IRI#person"

val result = SharedTestDataADM.imagesReviewerUser.permissions
.hasPermissionFor(ResourceCreateOperation(notAllowedResourceClassIri), projectIri, None)
.hasPermissionFor(ResourceCreateOperation(notAllowedResourceClassIri), projectIri)
result should be(false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,14 @@ case class ListNodeGetResponseADM(node: NodeADM) extends ListItemGetResponseADM(
*
* @param nodeinfo the basic information about a node.
*/
abstract class NodeInfoGetResponseADM(nodeinfo: ListNodeInfoADM) extends KnoraResponseADM with ListADMJsonProtocol
abstract class NodeInfoGetResponseADM() extends KnoraResponseADM with ListADMJsonProtocol

/**
* Provides basic information about a root node without it's children.
*
* @param listinfo the basic information about a list.
*/
case class RootNodeInfoGetResponseADM(listinfo: ListRootNodeInfoADM) extends NodeInfoGetResponseADM(listinfo) {
case class RootNodeInfoGetResponseADM(listinfo: ListRootNodeInfoADM) extends NodeInfoGetResponseADM() {

def toJsValue: JsValue = listInfoGetResponseADMFormat.write(this)
}
Expand All @@ -402,7 +402,7 @@ case class RootNodeInfoGetResponseADM(listinfo: ListRootNodeInfoADM) extends Nod
*
* @param nodeinfo the basic information about a list node.
*/
case class ChildNodeInfoGetResponseADM(nodeinfo: ListChildNodeInfoADM) extends NodeInfoGetResponseADM(nodeinfo) {
case class ChildNodeInfoGetResponseADM(nodeinfo: ListChildNodeInfoADM) extends NodeInfoGetResponseADM() {

def toJsValue: JsValue = listNodeInfoGetResponseADMFormat.write(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,17 +762,15 @@ case class DefaultObjectAccessPermissionsForProjectGetResponseADM(
def toJsValue: JsValue = defaultObjectAccessPermissionsForProjectGetResponseADMFormat.write(this)
}

abstract class PermissionGetResponseADM(permissionItem: PermissionItemADM)
extends KnoraResponseADM
with PermissionsADMJsonProtocol
abstract class PermissionGetResponseADM() extends KnoraResponseADM with PermissionsADMJsonProtocol

/**
* Represents an answer to a request for getting a default object access permission.
*
* @param defaultObjectAccessPermission the retrieved [[DefaultObjectAccessPermissionADM]].
*/
case class DefaultObjectAccessPermissionGetResponseADM(defaultObjectAccessPermission: DefaultObjectAccessPermissionADM)
extends PermissionGetResponseADM(defaultObjectAccessPermission) {
extends PermissionGetResponseADM() {
def toJsValue: JsValue = defaultObjectAccessPermissionGetResponseADMFormat.write(this)
}

Expand All @@ -782,7 +780,7 @@ case class DefaultObjectAccessPermissionGetResponseADM(defaultObjectAccessPermis
* @param administrativePermission the retrieved [[AdministrativePermissionADM]].
*/
case class AdministrativePermissionGetResponseADM(administrativePermission: AdministrativePermissionADM)
extends PermissionGetResponseADM(administrativePermission) {
extends PermissionGetResponseADM() {
def toJsValue: JsValue = administrativePermissionGetResponseADMFormat.write(this)
}

Expand Down Expand Up @@ -897,11 +895,7 @@ case class PermissionsDataADM(
* @param insideProject the IRI of the project inside which the operation will be performed.
* @return a boolean value.
*/
def hasPermissionFor(
operation: OperationADM,
insideProject: IRI,
objectAccessPermissions: Option[Set[PermissionADM]]
): Boolean =
def hasPermissionFor(operation: OperationADM, insideProject: IRI): Boolean =
// println(s"hasPermissionFor - administrativePermissionsPerProject: ${administrativePermissionsPerProject}, operation: $operation, insideProject: $insideProject")
if (this.isSystemAdmin) {
/* A member of the SystemAdmin group is allowed to perform any operation */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.time.Instant
import java.util.UUID

import dsp.errors.AssertionException
import dsp.errors.BadRequestException
import dsp.errors.InconsistentRepositoryDataException
import dsp.errors.NotFoundException
Expand Down Expand Up @@ -818,7 +817,6 @@
val transformedValuePropertyAssertions: RdfPropertyValues = resource.valuePropertyAssertions.map {
case (propIri: SmartIri, values: Seq[ValueRdfData]) =>
val transformedValues: Seq[ValueRdfData] = transformValuesByNestingResources(
resourceIri = resourceIri,
values = values,
flatResourcesWithValues = flatResourcesWithValues,
visibleResources = visibleResources,
Expand Down Expand Up @@ -905,7 +903,6 @@
/**
* Transforms a resource's values by nesting dependent resources in link values.
*
* @param resourceIri the IRI of the resource.
* @param values the values of the resource.
* @param flatResourcesWithValues the complete set of resources with their values, before permission filtering.
* @param visibleResources the resources that the user has permission to see.
Expand All @@ -917,7 +914,6 @@
* @return the transformed values.
*/
private def transformValuesByNestingResources(
resourceIri: IRI,
values: Seq[ValueRdfData],
flatResourcesWithValues: RdfResources,
visibleResources: RdfResources,
Expand All @@ -937,7 +933,7 @@
if (dependentResourceIrisVisible.contains(dependentResourceIri)) {
// Yes. Nest it in the link value.
val dependentResource: ResourceWithValueRdfData = nestResources(
resourceIri = dependentResourceIri,
dependentResourceIri,
flatResourcesWithValues = flatResourcesWithValues,
visibleResources = visibleResources,
dependentResourceIrisVisible = dependentResourceIrisVisible,
Expand Down Expand Up @@ -1004,7 +1000,6 @@
* @param valueObjectValueHasString the value's `knora-base:valueHasString`.
* @param valueCommentOption the value's comment, if any.
* @param mappings the mappings needed for standoff conversions and XSL transformations.
* @param queryStandoff if `true`, make separate queries to get the standoff for the text value.
* @param requestingUser the user making the request.
* @return a [[TextValueContentV2]].
*/
Expand Down Expand Up @@ -1058,20 +1053,10 @@
*
* @param valueType the IRI of the file value type
* @param valueObject the given [[ValueRdfData]].
* @param valueObjectValueHasString the value's `knora-base:valueHasString`.
* @param valueCommentOption the value's comment, if any.
* @param mappings the mappings needed for standoff conversions and XSL transformations.
* @param requestingUser the user making the request.
* @return a [[FileValueContentV2]].
*/
private def makeFileValueContentV2(
valueType: IRI,
valueObject: ValueRdfData,
valueObjectValueHasString: String,
valueCommentOption: Option[String],
mappings: Map[IRI, MappingAndXSLTransformation],
requestingUser: UserADM
): Task[FileValueContentV2] = {
private def makeFileValueContentV2(valueType: IRI, valueObject: ValueRdfData, valueCommentOption: Option[IRI]) = {

Check warning on line 1059 in webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala#L1059

Method is longer than 50 lines.
val fileValue = FileValueV2(
internalMimeType = valueObject.requireStringObject(OntologyConstants.KnoraBase.InternalMimeType.toSmartIri),
internalFilename = valueObject.requireStringObject(OntologyConstants.KnoraBase.InternalFilename.toSmartIri),
Expand Down Expand Up @@ -1139,15 +1124,14 @@
)
)

case _ => throw InconsistentRepositoryDataException(s"Unexpected file value type: $valueType")
case _ => ZIO.fail(InconsistentRepositoryDataException(s"Unexpected file value type: $valueType"))
}
}

/**
* Given a [[ValueRdfData]], constructs a [[LinkValueContentV2]].
*
* @param valueObject the given [[ValueRdfData]].
* @param valueObjectValueHasString the value's `knora-base:valueHasString`.
* @param valueCommentOption the value's comment, if any.
* @param mappings the mappings needed for standoff conversions and XSL transformations.
* @param queryStandoff if `true`, make separate queries to get the standoff for text values.
Expand All @@ -1158,14 +1142,13 @@
*/
private def makeLinkValueContentV2(
valueObject: ValueRdfData,
valueObjectValueHasString: String,
valueCommentOption: Option[String],
valueCommentOption: Option[IRI],
mappings: Map[IRI, MappingAndXSLTransformation],
queryStandoff: Boolean,
versionDate: Option[Instant],
targetSchema: ApiV2Schema,
requestingUser: UserADM
): Task[LinkValueContentV2] = {
) = {
val referredResourceIri: IRI = if (valueObject.isIncomingLink) {
valueObject.requireIriObject(OntologyConstants.Rdf.Subject.toSmartIri)
} else {
Expand Down Expand Up @@ -1216,14 +1199,13 @@
* @return a [[ValueContentV2]] representing a value.
*/
private def createValueContentV2FromValueRdfData(
resourceIri: IRI,
valueObject: ValueRdfData,
mappings: Map[IRI, MappingAndXSLTransformation],
queryStandoff: Boolean,
versionDate: Option[Instant] = None,
targetSchema: ApiV2Schema,
requestingUser: UserADM
): Task[ValueContentV2] = {
) = {
// every knora-base:Value (any of its subclasses) has a string representation, but it is not necessarily returned with text values.
val valueObjectValueHasString: Option[String] =
valueObject.maybeStringObject(OntologyConstants.KnoraBase.ValueHasString.toSmartIri)
Expand Down Expand Up @@ -1386,27 +1368,19 @@
case OntologyConstants.KnoraBase.LinkValue =>
makeLinkValueContentV2(
valueObject = valueObject,
valueObjectValueHasString = valueObjectValueHasString.getOrElse(
throw AssertionException(s"Value <${valueObject.subjectIri}> has no knora-base:valueHasString")
),
valueCommentOption = valueCommentOption,
mappings = mappings,
queryStandoff = queryStandoff,
versionDate = versionDate,
requestingUser = requestingUser,
targetSchema = targetSchema
targetSchema = targetSchema,
requestingUser = requestingUser
)

case fileValueClass: IRI if OntologyConstants.KnoraBase.FileValueClasses.contains(fileValueClass) =>
makeFileValueContentV2(
valueType = fileValueClass,
valueObject = valueObject,
valueObjectValueHasString = valueObjectValueHasString.getOrElse(
throw AssertionException(s"Value <${valueObject.subjectIri}> has no knora-base:valueHasString")
),
valueCommentOption = valueCommentOption,
mappings = mappings,
requestingUser = requestingUser
valueCommentOption = valueCommentOption
)

case other => throw NotImplementedException(s"Not implemented yet: $other")
Expand Down Expand Up @@ -1489,12 +1463,11 @@
for {
valueContent <-
createValueContentV2FromValueRdfData(
resourceIri = resourceIri,
valueObject = valObj,
mappings = mappings,
queryStandoff = queryStandoff,
requestingUser = requestingUser,
targetSchema = targetSchema
targetSchema = targetSchema,
requestingUser = requestingUser
)

attachedToUser = valObj.requireIriObject(OntologyConstants.KnoraBase.AttachedToUser.toSmartIri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,8 @@ case class JsonLDObject(value: Map[String, JsonLDValue]) extends JsonLDValue {
ZIO.serviceWithZIO[IriConverter] { c =>
val resourceProps: Map[IRI, JsonLDValue] = value - JsonLDKeywords.ID - JsonLDKeywords.TYPE
resourceProps match {
case emptyMap if resourceProps.isEmpty =>
ZIO.fail("No value submitted")
case tooMany if resourceProps.size > 1 =>
ZIO.fail(s"Only one value can be submitted per request using this route")
case _ if resourceProps.isEmpty => ZIO.fail("No value submitted")
case _ if resourceProps.size > 1 => ZIO.fail(s"Only one value can be submitted per request using this route")
case singleProp =>
singleProp.head match {
case (key: IRI, jsonLDValue: JsonLDValue) =>
Expand Down Expand Up @@ -1147,7 +1145,7 @@ case class JsonLDArray(value: Seq[JsonLDValue]) extends JsonLDValue {
*
* @return a map of language keys to values.
*/
def toObjsWithLang()(implicit stringFormatter: StringFormatter): Seq[StringLiteralV2] =
def toObjsWithLang(): Seq[StringLiteralV2] =
value.map {
case obj: JsonLDObject =>
val validationFun: (String, => Nothing) => String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.knora.webapi.messages.util.search

import org.knora.webapi._
import org.knora.webapi.config.AppConfig
import org.knora.webapi.messages.IriConversions._
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.messages.StringFormatter
Expand Down Expand Up @@ -64,15 +63,13 @@ object FullTextMainQueryGenerator {
* @param valueObjectIris the IRIs of the value objects to be queried.
* @param targetSchema the target API schema.
* @param schemaOptions the schema options submitted with the request.
* @param appConfig the application's configuration.
* @return a [[ConstructQuery]].
*/
def createMainQuery(
resourceIris: Set[IRI],
valueObjectIris: Set[IRI],
targetSchema: ApiV2Schema,
schemaOptions: Set[SchemaOption],
appConfig: AppConfig
schemaOptions: Set[SchemaOption]
): ConstructQuery = {
implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.knora.webapi.messages.util.ConstructResponseUtilV2.ResourceWithValueR
import org.knora.webapi.messages.util.ConstructResponseUtilV2.ValueRdfData
import org.knora.webapi.messages.util.search.gravsearch.mainquery.GravsearchMainQueryGenerator.ValueObjectVariablesAndValueObjectIris
import org.knora.webapi.messages.util.search.gravsearch.prequery.GravsearchToPrequeryTransformer
import org.knora.webapi.messages.util.search.gravsearch.types.GravsearchTypeInspectionResult

object MainQueryResultProcessor {

Expand All @@ -30,7 +29,6 @@ object MainQueryResultProcessor {
* @param allResourceVariablesFromTypeInspection all variables representing resources.
* @param dependentResourceIrisFromTypeInspection Iris of dependent resources used in the input query.
* @param transformer the transformer that was used to turn the input query into the prequery.
* @param typeInspectionResult results of type inspection of the input query.
* @return results with only the values the user asked for in the input query's CONSTRUCT clause.
*/
// TODO apparently not needed, work is taken care in ConstructResponseUtilV2.nestResources
Expand All @@ -39,9 +37,7 @@ object MainQueryResultProcessor {
valueObjectVarsAndIrisPerMainResource: ValueObjectVariablesAndValueObjectIris,
allResourceVariablesFromTypeInspection: Set[QueryVariable],
dependentResourceIrisFromTypeInspection: Set[IRI],
transformer: GravsearchToPrequeryTransformer,
typeInspectionResult: GravsearchTypeInspectionResult,
inputQuery: ConstructQuery
transformer: GravsearchToPrequeryTransformer
): RdfResources = {
implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

Expand Down