BrightSide Workbench Full Report + Source Code
AxTag.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.alliance.db.entities;
20 
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Set;
24 import javax.json.JsonValue;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.ProjectGrant;
27 import org.turro.importer.ImporterRegister;
28 import org.turro.json.IJSONizable;
29 import org.turro.plugin.contacts.CompoundId;
30 import org.turro.tags.Tags;
31 
36 public class AxTag implements IJSONizable {
37 
38  private final String tagName, entityRoot, entityId;
39  private final long memberId;
40 
41  public AxTag(long memberId, String tag, String entityRoot, String entityId) {
42  this.memberId = memberId;
43  this.tagName = tag;
44  this.entityRoot = entityRoot;
45  this.entityId = entityId;
46  }
47 
48  public String getTagName() {
49  return tagName;
50  }
51 
52  public String getEntityRoot() {
53  return entityRoot;
54  }
55 
56  public String getEntityId() {
57  return entityId;
58  }
59 
60  public String stringifyId() {
61  return new CompoundId(entityId, memberId).stringify();
62  }
63 
64  /* Factory */
65 
66  public static Set<AxTag> from(long memberId, Dossier dossier) {
67  Set<AxTag> tags = new HashSet<>();
68  Tags.getTags(dossier).forEach(ti -> {
69  tags.add(new AxTag(memberId, ti.getTagName(), "/axproject/", Long.toString(dossier.getId())));
70  });
71  return tags;
72  }
73 
74  public static Set<AxTag> from(long memberId, ProjectGrant projectGrant) {
75  Set<AxTag> tags = new HashSet<>();
76  Tags.getTags(projectGrant).forEach(ti -> {
77  tags.add(new AxTag(memberId, ti.getTagName(), "/axproject-grant/", Long.toString(projectGrant.getId())));
78  });
79  return tags;
80  }
81 
82  public static AxTag from(long memberId, ImporterRegister register) {
83  return new AxTag(memberId, register.getString("tag"), register.getString("entityRoot"), register.getString("entityId"));
84  }
85 
86  /* JSONizable */
87 
88  @Override
89  public String toJson() {
90  return toJson(this);
91  }
92 
93  @Override
94  public String toJson(Map<String, Object> properties) {
95  return toJson(this, properties);
96  }
97 
98  public static AxTag fromJson(JsonValue value) {
99  return IJSONizable.fromJson(value.toString(), AxTag.class);
100  }
101 
102 }
String toJson(Map< String, Object > properties)
Definition: AxTag.java:94
static AxTag fromJson(JsonValue value)
Definition: AxTag.java:98
static Set< AxTag > from(long memberId, ProjectGrant projectGrant)
Definition: AxTag.java:74
AxTag(long memberId, String tag, String entityRoot, String entityId)
Definition: AxTag.java:41
static AxTag from(long memberId, ImporterRegister register)
Definition: AxTag.java:82
static Set< AxTag > from(long memberId, Dossier dossier)
Definition: AxTag.java:66
static TagSet getTags(Object entity)
Definition: Tags.java:351