1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 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.history
21 
22 import java.time.ZonedDateTime
23 
24 import enumeratum.values.{StringEnum, StringEnumEntry}
25 import org.make.core.SprayJsonFormatters._
26 import org.make.core.proposal.{ProposalId, QualificationKey, VoteKey}
27 import spray.json.DefaultJsonProtocol._
28 import spray.json.{DefaultJsonProtocol, RootJsonFormat}
29 
30 object HistoryActions {
31 
32   sealed abstract class VoteTrust(val value: String) extends StringEnumEntry with Product with Serializable {
33     def isTrusted: Boolean
34     def isInSequence: Boolean
35     def isInSegment: Boolean
36   }
37 
38   object VoteTrust extends StringEnum[VoteTrust] {
39 
40     case object Trusted extends VoteTrust("trusted") {
41       override val isTrusted: Boolean = true
42       override val isInSequence: Boolean = false
43       override val isInSegment: Boolean = false
44     }
45 
46     case object Troll extends VoteTrust("troll") {
47       override val isTrusted: Boolean = false
48       override val isInSequence: Boolean = false
49       override val isInSegment: Boolean = false
50     }
51 
52     case object Sequence extends VoteTrust("sequence") {
53       override val isTrusted: Boolean = true
54       override val isInSequence: Boolean = true
55       override val isInSegment: Boolean = false
56     }
57 
58     case object Segment extends VoteTrust("segment") {
59       override val isTrusted: Boolean = true
60       override val isInSequence: Boolean = true
61       override val isInSegment: Boolean = true
62     }
63 
64     override val values: IndexedSeq[VoteTrust] = findValues
65 
66   }
67 
68   final case class VoteAndQualifications(
69     voteKey: VoteKey,
70     qualificationKeys: Map[QualificationKey, VoteTrust],
71     date: ZonedDateTime,
72     trust: VoteTrust
73   )
74 
75   object VoteAndQualifications {
76     implicit val formatter: RootJsonFormat[VoteAndQualifications] =
77       DefaultJsonProtocol.jsonFormat4(VoteAndQualifications.apply)
78   }
79 
80   sealed trait VoteRelatedAction extends Product with Serializable {
81     def proposalId: ProposalId
82     def date: ZonedDateTime
83     def trust: VoteTrust
84   }
85 
86   sealed trait GenericVoteAction extends VoteRelatedAction {
87     def key: VoteKey
88   }
89 
90   sealed trait GenericQualificationAction extends VoteRelatedAction {
91     def key: QualificationKey
92   }
93 
94   final case class VoteAction(proposalId: ProposalId, date: ZonedDateTime, key: VoteKey, trust: VoteTrust)
95       extends GenericVoteAction
96   final case class UnvoteAction(proposalId: ProposalId, date: ZonedDateTime, key: VoteKey, trust: VoteTrust)
97       extends GenericVoteAction
98   final case class QualificationAction(
99     proposalId: ProposalId,
100     date: ZonedDateTime,
101     key: QualificationKey,
102     trust: VoteTrust
103   ) extends GenericQualificationAction
104   final case class UnqualificationAction(
105     proposalId: ProposalId,
106     date: ZonedDateTime,
107     key: QualificationKey,
108     trust: VoteTrust
109   ) extends GenericQualificationAction
110 
111 }
Line Stmt Id Pos Tree Symbol Tests Code
41 3700 1446 - 1450 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest true
42 1799 1494 - 1499 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest false
43 993 1542 - 1547 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest false
47 4099 1646 - 1651 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest false
48 2172 1695 - 1700 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest false
49 5404 1743 - 1748 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest false
53 3454 1853 - 1857 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest true
54 2631 1901 - 1905 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest true
55 458 1948 - 1953 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest false
59 3707 2056 - 2060 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest true
60 1814 2104 - 2108 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest true
61 5251 2151 - 2155 Literal <nosymbol> org.make.api.avro.avrocompatibilitytest,org.make.api.makekafkatest,org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest true
77 660 2539 - 2539 Select org.make.core.SprayJsonFormatters.zonedDateTimeFormatter org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.core.SprayJsonFormatters.zonedDateTimeFormatter
77 4279 2540 - 2567 Apply org.make.core.history.HistoryActions.VoteAndQualifications.apply org.scalatest.testsuite HistoryActions.this.VoteAndQualifications.apply(voteKey, qualificationKeys, date, trust)
77 3633 2539 - 2539 ApplyToImplicitArgs org.make.core.SprayJsonFormatters.stringEnumFormatter org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.history.HistoryActions.VoteTrust]((VoteTrust: enumeratum.values.StringEnum[org.make.core.history.HistoryActions.VoteTrust]))
77 5339 2539 - 2539 ApplyToImplicitArgs org.make.core.SprayJsonFormatters.stringEnumFormatter org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.proposal.QualificationKey]((QualificationKey: enumeratum.values.StringEnum[org.make.core.proposal.QualificationKey]))
77 1735 2508 - 2568 ApplyToImplicitArgs spray.json.ProductFormatsInstances.jsonFormat4 org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest spray.json.DefaultJsonProtocol.jsonFormat4[org.make.core.proposal.VoteKey, Map[org.make.core.proposal.QualificationKey,org.make.core.history.HistoryActions.VoteTrust], java.time.ZonedDateTime, org.make.core.history.HistoryActions.VoteTrust, org.make.core.history.HistoryActions.VoteAndQualifications](((voteKey: org.make.core.proposal.VoteKey, qualificationKeys: Map[org.make.core.proposal.QualificationKey,org.make.core.history.HistoryActions.VoteTrust], date: java.time.ZonedDateTime, trust: org.make.core.history.HistoryActions.VoteTrust) => HistoryActions.this.VoteAndQualifications.apply(voteKey, qualificationKeys, date, trust)))(org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.proposal.VoteKey]((VoteKey: enumeratum.values.StringEnum[org.make.core.proposal.VoteKey])), spray.json.DefaultJsonProtocol.mapFormat[org.make.core.proposal.QualificationKey, org.make.core.history.HistoryActions.VoteTrust](org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.proposal.QualificationKey]((QualificationKey: enumeratum.values.StringEnum[org.make.core.proposal.QualificationKey])), org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.history.HistoryActions.VoteTrust]((VoteTrust: enumeratum.values.StringEnum[org.make.core.history.HistoryActions.VoteTrust]))), org.make.core.SprayJsonFormatters.zonedDateTimeFormatter, org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.history.HistoryActions.VoteTrust]((VoteTrust: enumeratum.values.StringEnum[org.make.core.history.HistoryActions.VoteTrust])), (ClassTag.apply[org.make.core.history.HistoryActions.VoteAndQualifications](classOf[org.make.core.history.HistoryActions$$VoteAndQualifications]): scala.reflect.ClassTag[org.make.core.history.HistoryActions.VoteAndQualifications]))
77 2061 2539 - 2539 ApplyToImplicitArgs org.make.core.SprayJsonFormatters.stringEnumFormatter org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.proposal.VoteKey]((VoteKey: enumeratum.values.StringEnum[org.make.core.proposal.VoteKey]))
77 2569 2539 - 2539 ApplyToImplicitArgs spray.json.CollectionFormats.mapFormat org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest spray.json.DefaultJsonProtocol.mapFormat[org.make.core.proposal.QualificationKey, org.make.core.history.HistoryActions.VoteTrust](org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.proposal.QualificationKey]((QualificationKey: enumeratum.values.StringEnum[org.make.core.proposal.QualificationKey])), org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.history.HistoryActions.VoteTrust]((VoteTrust: enumeratum.values.StringEnum[org.make.core.history.HistoryActions.VoteTrust])))
77 3711 2539 - 2539 ApplyToImplicitArgs org.make.core.SprayJsonFormatters.stringEnumFormatter org.make.api.sessionhistory.sessionhistorycoordinatortest,org.make.api.technical.crm.crmservicecomponenttest org.make.core.SprayJsonFormatters.stringEnumFormatter[org.make.core.history.HistoryActions.VoteTrust]((VoteTrust: enumeratum.values.StringEnum[org.make.core.history.HistoryActions.VoteTrust]))