BrightSide Workbench Full Report + Source Code
WebGoal.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.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 published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (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 <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.entities.web;
20 
21 import java.io.Serializable;
22 import java.util.Objects;
23 import javax.persistence.AttributeOverride;
24 import javax.persistence.AttributeOverrides;
25 import javax.persistence.Column;
26 import javax.persistence.Embedded;
27 import javax.persistence.Entity;
28 import javax.persistence.Id;
29 import org.turro.elephant.context.Application;
30 import org.turro.elephant.context.IConstructor;
31 import org.turro.elephant.web.actions.WebActions;
32 import org.turro.elephant.web.actions.WebLink;
33 import org.turro.jpa.embeddables.Wiki;
34 import org.turro.jpa.entity.IDaoEntity;
35 import org.turro.string.Phrases;
36 import org.turro.string.Strings;
37 
42 @Entity
43 public class WebGoal implements IDaoEntity, Serializable {
44 
45  @Id private String goalAction;
46 
47  private String caption;
48  private int ordering;
49 
50  @Embedded
51  @AttributeOverrides({
52  @AttributeOverride( name = "text", column = @Column(name = "summary")),
53  @AttributeOverride( name = "wiki", column = @Column(name = "wsummary"))
54  })
55  private Wiki summary = new Wiki();
56 
57  @Embedded
58  @AttributeOverrides({
59  @AttributeOverride( name = "text", column = @Column(name = "description")),
60  @AttributeOverride( name = "wiki", column = @Column(name = "wdescription"))
61  })
62  private Wiki description = new Wiki();
63 
64  public String getGoalAction() {
65  return goalAction;
66  }
67 
68  public void setGoalAction(String goalAction) {
69  this.goalAction = goalAction;
70  }
71 
72  public String getCaption() {
73  return caption;
74  }
75 
76  public void setCaption(String caption) {
77  this.caption = caption;
78  }
79 
80  public int getOrdering() {
81  return ordering;
82  }
83 
84  public void setOrdering(int ordering) {
85  this.ordering = ordering;
86  }
87 
88  public Wiki getSummary() {
89  if(summary == null) summary = new Wiki();
90  return summary;
91  }
92 
93  public void setSummary(Wiki summary) {
94  this.summary = summary;
95  }
96 
97  public Wiki getDescription() {
98  if(description == null) description = new Wiki();
99  return description;
100  }
101 
102  public void setDescription(Wiki description) {
103  this.description = description;
104  }
105 
106  /* Utils */
107 
108  public String getCompendium() {
109  return summary == null ? "" : summary.getText();
110  }
111 
112  public String getContent() {
113  return description == null ? "" : description.getText();
114  }
115 
116  public WebLink getWebLink() {
117  return WebLink.from(WebActions.of(goalAction).link(), caption);
118  }
119 
120  public boolean isValid() {
121  return true;
122  }
123 
124  public String getItemLabel() {
125  return Phrases.start(caption).add(goalAction, "()").toString();
126  }
127 
128  public void compose() {
130  if(constructor != null) {
131  getSummary().compose(constructor);
132  getDescription().compose(constructor);
133  }
134  }
135 
136  @Override
137  public int hashCode() {
138  int hash = 7;
139  hash = 97 * hash + Objects.hashCode(this.goalAction);
140  return hash;
141  }
142 
143  @Override
144  public boolean equals(Object obj) {
145  if (this == obj) {
146  return true;
147  }
148  if (obj == null) {
149  return false;
150  }
151  if (getClass() != obj.getClass()) {
152  return false;
153  }
154  final WebGoal other = (WebGoal) obj;
155  return Objects.equals(this.goalAction, other.goalAction);
156  }
157 
158  /* IDaoEntity */
159 
160  @Override
161  public Object entityId() {
162  return goalAction;
163  }
164 
165  @Override
166  public boolean isEmpty() {
167  return Strings.isBlank(goalAction) || Strings.isBlank(caption);
168  }
169 
170 }
void setGoalAction(String goalAction)
Definition: WebGoal.java:68
void setDescription(Wiki description)
Definition: WebGoal.java:102
static WebActions of(String action)
void compose(IConstructor constructor)
Definition: Wiki.java:66