Skip to content


Browse files Browse the repository at this point in the history
refactor(projects): refactor projects route with value objects (DEV-64)…
… (#1909)

* add value objects for projects


* fix(routing): optiona IRI validation

* refactor: remov redundant traits + make sealed abstract classes private

Co-authored-by: Marcin Procyk <>
  • Loading branch information
irinaschubert and mpro7 committed Sep 29, 2021
1 parent 652c747 commit 172cf77
Show file tree
Hide file tree
Showing 8 changed files with 446 additions and 259 deletions.
Expand Up @@ -21,15 +21,14 @@ package org.knora.webapi.messages.admin.responder.projectsmessages

import java.nio.file.Path
import java.util.UUID

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import org.apache.commons.lang3.builder.HashCodeBuilder
import org.knora.webapi.IRI
import org.knora.webapi.annotation.{ApiMayChange, ServerUnique}
import org.knora.webapi.exceptions.{BadRequestException, DataConversionException, OntologyConstraintException}
import org.knora.webapi.feature.FeatureFactoryConfig
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.admin.responder.usersmessages.UserADM
import org.knora.webapi.messages.admin.responder.usersmessages.{ProjectCreatePayloadADM, UserADM}
import org.knora.webapi.messages.admin.responder.{KnoraRequestADM, KnoraResponseADM}
import{StringLiteralV2, TriplestoreJsonProtocol}
import org.knora.webapi.messages.v1.responder.projectmessages.ProjectInfoV1
Expand Down Expand Up @@ -365,13 +364,13 @@ case class ProjectDataGetRequestADM(
* Requests the creation of a new project.
* @param createRequest the [[CreateProjectApiRequestADM]] information for creation a new project.
* @param createRequest the [[ProjectCreatePayloadADM]] information for creation a new project.
* @param featureFactoryConfig the feature factory configuration.
* @param requestingUser the user making the request.
* @param apiRequestID the ID of the API request.
case class ProjectCreateRequestADM(
createRequest: CreateProjectApiRequestADM,
createRequest: ProjectCreatePayloadADM,
featureFactoryConfig: FeatureFactoryConfig,
requestingUser: UserADM,
apiRequestID: UUID
Expand Down
@@ -0,0 +1,45 @@
package org.knora.webapi.messages.admin.responder.usersmessages

import org.knora.webapi.IRI

* Project payload
sealed abstract case class ProjectCreatePayloadADM private (
id: Option[IRI],
shortname: Shortname,
shortcode: Shortcode,
longname: Option[Longname],
description: Description,
keywords: Keywords,
logo: Option[Logo],
status: Status,
selfjoin: Selfjoin

object ProjectCreatePayloadADM {

/** The create constructor */
def create(
id: Option[IRI] = None,
shortname: Shortname,
shortcode: Shortcode,
longname: Option[Longname] = None,
description: Description,
keywords: Keywords,
logo: Option[Logo] = None,
status: Status,
selfjoin: Selfjoin
): ProjectCreatePayloadADM =
new ProjectCreatePayloadADM(
id = id,
shortname = shortname,
shortcode = shortcode,
longname = longname,
description = description,
keywords = keywords,
logo = logo,
status = status,
selfjoin = selfjoin
) {}
Expand Up @@ -2,31 +2,10 @@ package org.knora.webapi.messages.admin.responder.usersmessages

import org.knora.webapi.IRI

sealed trait ValidationError
case object InvalidUsername extends ValidationError
case object InvalidEmail extends ValidationError
case object InvalidGivenOrFamilyName extends ValidationError
case object InvalidPassword extends ValidationError
case object InvalidLanguageCode extends ValidationError

trait UserCreatePayloadTraitADM {
def create(
id: Option[IRI],
username: Username,
email: Email,
givenName: GivenName,
familyName: FamilyName,
password: Password,
status: Status,
lang: LanguageCode,
systemAdmin: SystemAdmin
): UserCreatePayloadADM

* User entity representing the payload for the create user request
sealed abstract case class UserCreatePayloadADM(
sealed abstract case class UserCreatePayloadADM private (
id: Option[IRI],
username: Option[Username],
email: Option[Email],
Expand All @@ -41,10 +20,10 @@ sealed abstract case class UserCreatePayloadADM(
systemAdmin: Option[SystemAdmin]

object UserCreatePayloadADM extends UserCreatePayloadTraitADM {
object UserCreatePayloadADM {

/** The create constructor needs all attributes but id which is optional */
override def create(
def create(
id: Option[IRI] = None,
username: Username,
email: Email,
Expand Down

This file was deleted.

0 comments on commit 172cf77

Please sign in to comment.