BrightSide Workbench Full Report + Source Code
DefaultEntityLastActivity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.activity;
20 
21 import java.io.Serializable;
22 import java.util.Date;
23 import org.turro.assistant.AssistantConstants;
24 import org.turro.assistant.AssistantSet;
25 import org.turro.assistant.Assistants;
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 
35 public class DefaultEntityLastActivity implements Serializable, IEntityLastActivity {
36 
37  private final transient Object activity;
38  private final String entityPath, reason, activityPath, activityText;
39  private final Date date;
40  private String sortPath;
41  private transient IElephantEntity entity, mainEntity;
42  private transient AssistantSet participants;
43  private transient Object realActivity;
44 
45  public DefaultEntityLastActivity(Object activity, String entityPath, Date date, String reason) {
46  this.activityPath = Entities.getController(activity).getPath();
47  if(activityPath == null) {
48  this.activity = activity;
49  } else {
50  this.activity = null;
51  }
52  this.entityPath = entityPath;
53  this.date = date;
54  this.reason = reason;
55  this.activityText = formatActivityText();
56  setSortPath(entityPath);
57  }
58 
59  @Override
60  public String getEntityPath() {
61  return entityPath;
62  }
63 
64  @Override
65  public Date getDate() {
66  return date;
67  }
68 
69  @Override
71  if(participants == null) {
72  participants = new AssistantSet();
73  Assistants.addAssistants(entityPath, true, participants, AssistantConstants.all());
74  }
75  return participants;
76  }
77 
78  @Override
79  public Object getActivity() {
80  if(realActivity == null) {
81  realActivity = activity == null ? Entities.getController(activityPath).getEntity() : activity;
82  }
83  return realActivity;
84  }
85 
86  @Override
87  public String getReason() {
88  return reason;
89  }
90 
91  @Override
92  public String getSortPath() {
93  return sortPath;
94  }
95 
96  @Override
97  public void setSortPath(String sortPath) {
103  this.sortPath = sortPath + IElephantEntity.PATH_SEPARATOR;
104  }
105 
106  @Override
108  if(entity == null) {
109  entity = Entities.getController(entityPath);
110  }
111  return entity;
112  }
113 
114  @Override
116  if(mainEntity == null) {
117  mainEntity = Entities.getController(
119  }
120  return mainEntity;
121  }
122 
123  @Override
124  public String getActivityText() {
125  return activityText;
126  }
127 
128  private String formatActivityText() {
130  marker.put("last", this);
131  return marker.parse("activity", "laformat");
132  }
133 
134 }
DefaultEntityLastActivity(Object activity, String entityPath, Date date, String reason)
static Object getMainEntity(Object entity)
static void addAssistants(String role, AssistantSet list, Object data)
Definition: Assistants.java:35
static IElephantEntity getController(String path)
Definition: Entities.java:78
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)