-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce GroupIri PathVariable and move GroupIri to slice admin package
- Loading branch information
Showing
13 changed files
with
91 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/GroupIri.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.knora.webapi.slice.admin.domain.model | ||
|
||
import sttp.tapir.Codec | ||
import sttp.tapir.CodecFormat | ||
|
||
import dsp.valueobjects.Iri | ||
import dsp.valueobjects.Iri.validateAndEscapeIri | ||
import dsp.valueobjects.UuidUtil | ||
|
||
final case class GroupIri private (value: String) extends Iri | ||
|
||
object GroupIri { | ||
|
||
implicit val tapirCodec: Codec[String, GroupIri, CodecFormat.TextPlain] = | ||
Codec.string.mapEither(GroupIri.from)(_.value) | ||
|
||
def unsafeFrom(value: String): GroupIri = from(value).fold(e => throw new IllegalArgumentException(e), identity) | ||
|
||
def from(value: String): Either[String, GroupIri] = | ||
if (value.isEmpty) Left("Group IRI cannot be empty.") | ||
Check notice on line 20 in webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/GroupIri.scala Codacy Production / Codacy Static Code Analysiswebapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/GroupIri.scala#L20
|
||
else if (!(Iri.isIri(value) && value.startsWith("http://rdfh.ch/groups/"))) | ||
Check notice on line 21 in webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/GroupIri.scala Codacy Production / Codacy Static Code Analysiswebapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/GroupIri.scala#L21
|
||
Left("Group IRI is invalid.") | ||
else if (UuidUtil.hasValidLength(value.split("/").last) && !UuidUtil.hasSupportedVersion(value)) | ||
Left("Invalid UUID used to create IRI. Only versions 4 and 5 are supported.") | ||
else | ||
validateAndEscapeIri(value).toEither | ||
.map(GroupIri.apply) | ||
.left | ||
.map(_ => "Group IRI is invalid.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.