Skip to content

Commit

Permalink
refactor: Remove type annotations which produce compiler warnings (#2829
Browse files Browse the repository at this point in the history
)
  • Loading branch information
seakayone authored Sep 8, 2023
1 parent 36b835e commit c754042
Show file tree
Hide file tree
Showing 15 changed files with 437 additions and 531 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -865,25 +865,22 @@ final case class InferringGravsearchTypeInspector(
allEntityInfo = t._2

// Iterate over the inference rules until no new type information can be inferred.
intermediateResult: IntermediateTypeInspectionResult = doIterations(
iterationNumber = 1,
intermediateResult = previousResult,
entityInfo = allEntityInfo,
usageIndex = usageIndex
)
intermediateResult = doIterations(
iterationNumber = 1,
intermediateResult = previousResult,
entityInfo = allEntityInfo,
usageIndex = usageIndex
)

// refine the determined types before sending to the next inspector
refinedIntermediateResult: IntermediateTypeInspectionResult = refineDeterminedTypes(
intermediateResult = intermediateResult,
entityInfo = allEntityInfo
)
refinedIntermediateResult = refineDeterminedTypes(intermediateResult, allEntityInfo)

// sanitize the inconsistent resource types inferred for an entity
sanitizedResults: IntermediateTypeInspectionResult = sanitizeInconsistentResourceTypes(
refinedIntermediateResult,
usageIndex.querySchema,
entityInfo = allEntityInfo
)
sanitizedResults = sanitizeInconsistentResourceTypes(
refinedIntermediateResult,
usageIndex.querySchema,
entityInfo = allEntityInfo
)
} yield sanitizedResults
}

Expand Down Expand Up @@ -970,16 +967,15 @@ final case class InferringGravsearchTypeInspector(

// The ontology responder may return the requested information in the internal schema. Convert each entity
// definition back to the input schema.
additionalEntityInfoInInputSchemas: EntityInfoGetResponseV2 = convertEntityInfoResponseToInputSchemas(
usageIndex = usageIndexWithAdditionalClasses,
entityInfo = additionalEntityInfo
)
additionalEntityInfoInInputSchemas = convertEntityInfoResponseToInputSchemas(
usageIndex = usageIndexWithAdditionalClasses,
entityInfo = additionalEntityInfo
)

// Combine all the entity info into one object.
allEntityInfo: EntityInfoGetResponseV2 =
initialEntityInfoInInputSchemas.copy(
classInfoMap = initialEntityInfoInInputSchemas.classInfoMap ++ additionalEntityInfoInInputSchemas.classInfoMap
)
allEntityInfo = initialEntityInfoInInputSchemas.copy(classInfoMap =
initialEntityInfoInInputSchemas.classInfoMap ++ additionalEntityInfoInInputSchemas.classInfoMap
)

} yield (usageIndexWithAdditionalClasses, allEntityInfo)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ object DateValueContentV2 {
dateRange = CalendarDateRangeV2(startCalendarDate, endCalendarDate)

// Convert the CalendarDateRangeV2 to start and end Julian Day Numbers.
(startJDN: Int, endJDN: Int) = dateRange.toJulianDayRange
(startJDN, endJDN) = dateRange.toJulianDayRange

} yield DateValueContentV2(
ontologySchema = ApiV2Complex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1292,14 +1292,14 @@ final case class ListsResponderADMLive(
s"Node is not repositioned correctly in specified parent node. Please report this as a bug."
)
}
leftPositions: Seq[Int] = siblingsPositionedBefore.map(child => child.position)
leftPositions = siblingsPositionedBefore.map(child => child.position)
_ = if (leftPositions != leftPositions.sorted) {
throw UpdateNotPerformedException(
s"Something has gone wrong with shifting nodes. Please report this as a bug."
)
}
siblingsPositionedAfter = rest.slice(1, rest.length)
rightSiblings: Seq[Int] = siblingsPositionedAfter.map(child => child.position)
rightSiblings = siblingsPositionedAfter.map(child => child.position)
_ = if (rightSiblings != rightSiblings.sorted) {
throw UpdateNotPerformedException(
s"Something has gone wrong with shifting nodes. Please report this as a bug."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ final case class PermissionsResponderADMLive(
}

/* materialize implicit membership in 'http://www.knora.org/ontology/knora-base#ProjectAdmin' group for each project */
projectAdmins: Seq[(IRI, IRI)] =
projectAdmins =
if (projectIris.nonEmpty) {
for {
projectAdminForGroup <- isInProjectAdminGroups
Expand All @@ -266,7 +266,7 @@ final case class PermissionsResponderADMLive(
}

/* materialize implicit membership in 'http://www.knora.org/ontology/knora-base#SystemAdmin' group */
systemAdmin: Seq[(IRI, IRI)] =
systemAdmin =
if (isInSystemAdminGroup) {
Seq((OntologyConstants.KnoraAdmin.SystemProject, OntologyConstants.KnoraAdmin.SystemAdmin))
} else {
Expand Down Expand Up @@ -440,7 +440,7 @@ final case class PermissionsResponderADMLive(
allPermissions <- allPermissionsFuture

// remove instances with empty PermissionADM sets
cleanedAllPermissions: Seq[Seq[PermissionADM]] = allPermissions.filter(_.nonEmpty)
cleanedAllPermissions = allPermissions.filter(_.nonEmpty)

/* Combine permission sequences */
combined = cleanedAllPermissions.foldLeft(Seq.empty[PermissionADM]) { (acc, seq) =>
Expand All @@ -466,14 +466,14 @@ final case class PermissionsResponderADMLive(
.query(Select(sparql.admin.txt.getAdministrativePermissionsForProject(projectIRI)))
.map(_.results.bindings)

permissionsWithProperties: Map[String, Map[String, String]] =
permissionsWithProperties =
permissionsQueryResponseRows
.groupBy(_.rowMap("s"))
.map { case (permissionIri: String, rows: Seq[VariableResultsRow]) =>
(permissionIri, rows.map(row => (row.rowMap("p"), row.rowMap("o"))).toMap)
}

administrativePermissions: Seq[AdministrativePermissionADM] =
administrativePermissions =
permissionsWithProperties.map { case (permissionIri: IRI, propsMap: Map[String, String]) =>
/* parse permissions */
val hasPermissions: Set[PermissionADM] =
Expand Down Expand Up @@ -535,9 +535,9 @@ final case class PermissionsResponderADMLive(
permissionQueryResponse <-
triplestore.query(Select(sparql.admin.txt.getAdministrativePermissionForProjectAndGroup(projectIri, groupIri)))

permissionQueryResponseRows: Seq[VariableResultsRow] = permissionQueryResponse.results.bindings
permissionQueryResponseRows = permissionQueryResponse.results.bindings

permission: Option[AdministrativePermissionADM] =
permission =
if (permissionQueryResponseRows.nonEmpty) {

/* check if we only got one administrative permission back */
Expand Down Expand Up @@ -729,9 +729,9 @@ final case class PermissionsResponderADMLive(
permissionQueryResponse <-
triplestore.query(Select(sparql.admin.txt.getObjectAccessPermission(Some(resourceIri), None)))

permissionQueryResponseRows: Seq[VariableResultsRow] = permissionQueryResponse.results.bindings
permissionQueryResponseRows = permissionQueryResponse.results.bindings

permission: Option[ObjectAccessPermissionADM] =
permission =
if (permissionQueryResponseRows.nonEmpty) {

val groupedPermissionsQueryResponse: Map[String, Seq[String]] =
Expand Down Expand Up @@ -780,9 +780,9 @@ final case class PermissionsResponderADMLive(
Select(sparql.admin.txt.getObjectAccessPermission(resourceIri = None, valueIri = Some(valueIri)))
)

permissionQueryResponseRows: Seq[VariableResultsRow] = permissionQueryResponse.results.bindings
permissionQueryResponseRows = permissionQueryResponse.results.bindings

permission: Option[ObjectAccessPermissionADM] =
permission =
if (permissionQueryResponseRows.nonEmpty) {

val groupedPermissionsQueryResponse: Map[String, Seq[String]] =
Expand Down Expand Up @@ -823,16 +823,16 @@ final case class PermissionsResponderADMLive(
triplestore.query(Select(sparql.admin.txt.getDefaultObjectAccessPermissionsForProject(projectIri)))

/* extract response rows */
permissionsQueryResponseRows: Seq[VariableResultsRow] = permissionsQueryResponse.results.bindings
permissionsQueryResponseRows = permissionsQueryResponse.results.bindings

permissionsWithProperties: Map[String, Map[String, String]] =
permissionsWithProperties =
permissionsQueryResponseRows
.groupBy(_.rowMap("s"))
.map { case (permissionIri: String, rows: Seq[VariableResultsRow]) =>
(permissionIri, rows.map(row => (row.rowMap("p"), row.rowMap("o"))).toMap)
}

permissions: Seq[DefaultObjectAccessPermissionADM] =
permissions =
permissionsWithProperties.map { case (permissionIri: IRI, propsMap: Map[String, String]) =>
/* parse permissions */
val hasPermissions: Set[PermissionADM] =
Expand Down Expand Up @@ -1030,28 +1030,8 @@ final case class PermissionsResponderADMLive(

} yield groupPermissions

val allPermissionsFuture: Task[Seq[Seq[PermissionADM]]] = ZioHelper.sequence(gpf)

/* combines all permissions for each group and removes duplicates */
val result: Task[Set[PermissionADM]] = for {
allPermissions <- allPermissionsFuture

// remove instances with empty PermissionADM sets
cleanedAllPermissions: Seq[Seq[PermissionADM]] = allPermissions.filter(_.nonEmpty)

/* Combine permission sequences */
combined = cleanedAllPermissions.foldLeft(Seq.empty[PermissionADM]) { (acc, seq) =>
acc ++ seq
}
/* Remove possible duplicate permissions */
result: Set[PermissionADM] = PermissionUtilADM.removeDuplicatePermissions(combined)

_ =
logger.debug(
s"defaultObjectAccessPermissionsForGroupsGetADM - INPUT [ projectIri: $projectIri, groups: $groups ], RESULT [ $result ]"
)
} yield result
result
ZioHelper.sequence(gpf).map(_.flatten).map(PermissionUtilADM.removeDuplicatePermissions(_))
}

/**
Expand Down Expand Up @@ -1148,11 +1128,8 @@ final case class PermissionsResponderADMLive(
) =
for {
/* Get the groups the user is member of. */
userGroupsOption <- ZIO.attempt(targetUser.permissions.groupsPerProject.get(projectIri))
userGroups: Seq[IRI] = userGroupsOption match {
case Some(groups) => groups
case None => Seq.empty[IRI]
}
userGroups <-
ZIO.attempt(targetUser.permissions.groupsPerProject.get(projectIri).map(_.toSet).getOrElse(Set.empty[IRI]))

/* Explicitly add 'SystemAdmin' and 'KnownUser' groups. */
extendedUserGroups: List[IRI] =
Expand Down Expand Up @@ -1999,13 +1976,10 @@ final case class PermissionsResponderADMLive(
permissionQueryResponse <- triplestore.query(Select(sparql.admin.txt.getPermissionByIRI(permissionIri)))

/* extract response rows */
permissionQueryResponseRows: Seq[VariableResultsRow] = permissionQueryResponse.results.bindings

groupedPermissionsQueryResponse: Map[String, Seq[String]] = permissionQueryResponseRows
.groupBy(_.rowMap("p"))
.map { case (predicate, rows) =>
predicate -> rows.map(_.rowMap("o"))
}
permissionQueryResponseRows = permissionQueryResponse.results.bindings
groupedPermissionsQueryResponse = permissionQueryResponseRows.groupBy(_.rowMap("p")).map {
case (predicate, rows) => predicate -> rows.map(_.rowMap("o"))
}

/* check if we have found something */
_ = if (groupedPermissionsQueryResponse.isEmpty)
Expand All @@ -2025,12 +1999,12 @@ final case class PermissionsResponderADMLive(
permissionIri = permissionIri
)

permissionType: Option[String] = groupedPermissionsQueryResponse
.getOrElse(
OntologyConstants.Rdf.Type,
throw InconsistentRepositoryDataException(s"RDF type is not returned.")
)
.headOption
permissionType = groupedPermissionsQueryResponse
.getOrElse(
OntologyConstants.Rdf.Type,
throw InconsistentRepositoryDataException(s"RDF type is not returned.")
)
.headOption
permission = permissionType match {
case Some(OntologyConstants.KnoraAdmin.DefaultObjectAccessPermission) =>
val hasPermissions = PermissionUtilADM.parsePermissionsWithType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,9 @@ final case class ProjectsResponderADMLive(
.map(_.statements.toList)

// get project member IRI from results rows
userIris: Seq[IRI] =
if (statements.nonEmpty) {
statements.map(_._1.toString)
} else {
Seq.empty[IRI]
}
userIris =
if (statements.nonEmpty) { statements.map(_._1.toString) }
else { Seq.empty[IRI] }

maybeUserFutures: Seq[Task[Option[UserADM]]] =
userIris.map { userIri =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.knora.webapi.messages.store.triplestoremessages.IriSubjectV2
import org.knora.webapi.messages.store.triplestoremessages.LiteralV2
import org.knora.webapi.messages.twirl.queries.sparql
import org.knora.webapi.messages.util.PermissionUtilADM
import org.knora.webapi.messages.util.PermissionUtilADM.EntityPermission
import org.knora.webapi.responders.Responder
import org.knora.webapi.store.triplestore.api.TriplestoreService
import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Construct
Expand Down Expand Up @@ -90,26 +89,26 @@ final case class SipiResponderADMLive(
s"Filename ${request.filename} is used in more than one file value"
)

fileValueIriSubject: IriSubjectV2 = queryResponse.statements.keys.head match {
case iriSubject: IriSubjectV2 => iriSubject
case _ =>
throw InconsistentRepositoryDataException(
s"The subject of the file value with filename ${request.filename} is not an IRI"
)
}

assertions: Seq[(String, String)] = queryResponse.statements(fileValueIriSubject).toSeq.flatMap {
case (predicate: SmartIri, values: Seq[LiteralV2]) =>
values.map { value =>
predicate.toString -> value.toString
}
}

maybeEntityPermission: Option[EntityPermission] = PermissionUtilADM.getUserPermissionFromAssertionsADM(
entityIri = fileValueIriSubject.toString,
assertions = assertions,
requestingUser = request.requestingUser
)
fileValueIriSubject = queryResponse.statements.keys.head match {
case iriSubject: IriSubjectV2 => iriSubject
case _ =>
throw InconsistentRepositoryDataException(
s"The subject of the file value with filename ${request.filename} is not an IRI"
)
}

assertions = queryResponse.statements(fileValueIriSubject).toSeq.flatMap {
case (predicate: SmartIri, values: Seq[LiteralV2]) =>
values.map { value =>
predicate.toString -> value.toString
}
}

maybeEntityPermission = PermissionUtilADM.getUserPermissionFromAssertionsADM(
entityIri = fileValueIriSubject.toString,
assertions = assertions,
requestingUser = request.requestingUser
)

_ =
logger.debug(
Expand Down
Loading

0 comments on commit c754042

Please sign in to comment.