1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2020 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.core.operation
21 
22 import java.net.URI
23 
24 import cats.Show
25 import grizzled.slf4j.Logging
26 import enumeratum.values.{StringEnum, StringEnumEntry}
27 import org.make.core.CirceFormatters
28 
29 import scala.util.Try
30 
31 sealed trait ResultsLink extends Product with Serializable
32 
33 object ResultsLink extends CirceFormatters with Logging {
34 
35   def parse(value: String): Option[ResultsLink] = {
36     val result = Internal.withValueOpt(value).orElse(Try(External(new URI(value))).toOption)
37     if (result.isEmpty) {
38       logger.error(s"'$value' is not a valid ResultsLink")
39     }
40     result
41   }
42 
43   final case class External(value: URI) extends ResultsLink
44 
45   sealed abstract class Internal(val value: String) extends StringEnumEntry with ResultsLink
46   object Internal extends StringEnum[Internal] {
47     def unapply(internal: Internal): Some[String] = Some(internal.value)
48     case object Results extends Internal("results")
49     override val values: IndexedSeq[Internal] = findValues
50     final val swaggerAllowableValues = "results"
51   }
52 
53   implicit val resultsLinkShow: Show[ResultsLink] = Show.show {
54     case External(url)   => url.toString
55     case Internal(value) => value
56   }
57 
58 }
Line Stmt Id Pos Tree Symbol Tests Code
36 1019 1199 - 1213 Apply java.net.URI.<init> org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest new java.net.URI(value)
36 4232 1190 - 1214 Apply org.make.core.operation.ResultsLink.External.apply org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest ResultsLink.this.External.apply(new java.net.URI(value))
36 3173 1186 - 1224 Select scala.util.Try.toOption org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest scala.util.Try.apply[org.make.core.operation.ResultsLink.External](ResultsLink.this.External.apply(new java.net.URI(value))).toOption
36 1139 1150 - 1225 Apply scala.Option.orElse org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest ResultsLink.this.Internal.withValueOpt(value).orElse[org.make.core.operation.ResultsLink](scala.util.Try.apply[org.make.core.operation.ResultsLink.External](ResultsLink.this.External.apply(new java.net.URI(value))).toOption)
37 2793 1230 - 1230 Block <nosymbol> org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest ()
37 4704 1230 - 1230 Literal <nosymbol> org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest ()
37 4515 1234 - 1248 Select scala.Option.isEmpty org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest result.isEmpty
38 2529 1258 - 1310 Apply grizzled.slf4j.Logger.error ResultsLink.this.logger.error(("\'".+(value).+("\' is not a valid ResultsLink"): String))
38 608 1258 - 1310 Block grizzled.slf4j.Logger.error ResultsLink.this.logger.error(("\'".+(value).+("\' is not a valid ResultsLink"): String))
47 891 1593 - 1607 Select org.make.core.operation.ResultsLink.Internal.value org.make.api.question.questionapitest internal.value
47 4170 1588 - 1608 Apply scala.Some.apply org.make.api.question.questionapitest scala.Some.apply[String](internal.value)
50 3186 1759 - 1768 Literal <nosymbol> "results"
53 4449 1826 - 1916 Apply cats.Show.show org.make.api.operation.operationofquestionservicetest,org.make.api.operation.defaultmoderationoperationofquestionapicomponenttest cats.Show.show[org.make.core.operation.ResultsLink](((x0$1: org.make.core.operation.ResultsLink) => x0$1 match { case (value: java.net.URI): org.make.core.operation.ResultsLink.External((url @ _)) => url.toString() case ResultsLink.this.Internal.unapply(<unapply-selector>) <unapply> ((value @ _)) => value }))
54 1145 1866 - 1878 Apply java.net.URI.toString url.toString()