BrightSide Workbench Full Report + Source Code
elephant-jpa/src/main/java/org/turro/elephant/entities/db/Activity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.db;
20 
21 import java.util.Date;
22 import javax.persistence.Entity;
23 import javax.persistence.Id;
24 import javax.persistence.IdClass;
25 import javax.persistence.Temporal;
26 import org.turro.elephant.context.Application;
27 import org.turro.entities.Entities;
28 import org.turro.entities.IElephantEntity;
29 import org.turro.marker.ElephantMarker;
30 import org.turro.string.Strings;
31 
36 @Entity
37 @IdClass(ActivityPK.class)
38 public class Activity implements java.io.Serializable {
39 
40  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
41  @Id private Date activityDate;
42 
43  @Id private String entityPath;
44  @Id private String activityPath;
45 
46  private String reason;
47  private String sortPath;
48 
49  public Date getActivityDate() {
50  return activityDate;
51  }
52 
53  public void setActivityDate(Date activityDate) {
54  this.activityDate = activityDate;
55  }
56 
57  public String getEntityPath() {
58  return entityPath;
59  }
60 
61  public void setEntityPath(String entityPath) {
62  this.entityPath = entityPath;
63  }
64 
65  public String getActivityPath() {
66  return activityPath;
67  }
68 
69  public void setActivityPath(String activityPath) {
70  this.activityPath = activityPath;
71  }
72 
73  public String getReason() {
74  return reason;
75  }
76 
77  public void setReason(String reason) {
78  this.reason = reason;
79  }
80 
81  public String getSortPath() {
82  return sortPath;
83  }
84 
85  public void setSortPath(String sortPath) {
91  this.sortPath = sortPath + IElephantEntity.PATH_SEPARATOR;
92  }
93 
94  /* Utils */
95 
96  private transient Object activity;
97  private transient IElephantEntity entity, mainEntity;
98  private transient String activityText;
99 
100  public Object getActivity() {
101  if(activity == null) {
102  activity = Entities.getObject(activityPath);
103  }
104  return activity;
105  }
106 
108  if(entity == null) {
109  entity = Entities.getController(entityPath);
110  }
111  return entity;
112  }
113 
115  if(mainEntity == null) {
116  mainEntity = Entities.getMainEntity(getEntity().getEntity());
117  }
118  return mainEntity;
119  }
120 
121  public String getActivityText() {
122  if(Strings.isBlank(activityText)) {
123  activityText = formatActivityText();
124  }
125  return activityText;
126  }
127 
128  private String formatActivityText() {
130  marker.put("activity", this);
131  return marker.parse("activity", "laformat");
132  }
133 
134 }
static IElephantEntity getController(String path)
Definition: Entities.java:78
static Object getObject(String path)
Definition: Entities.java:43
static IElephantEntity getMainEntity(Object entity)
Definition: Entities.java:60
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)