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(projects): refactor projects route with value objects (DEV-64) #1909

Merged
merged 5 commits into from Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
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 org.knora.webapi.messages.store.triplestoremessages.{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 (
Copy link
Collaborator

@subotic subotic Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strictly speaking this does not need a smart constructor, since it doesn't do any "smart" checks on it and could be written as a final case class ProjectCreatePayloadADM(...). We can leave it like it is and if no smart checks get added over time, then we can refactor it.

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.