BrightSide Workbench Full Report + Source Code
Tag.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.io.Serializable;
22 import java.util.Map;
23 import javax.json.JsonValue;
24 import javax.persistence.Entity;
25 import javax.persistence.Id;
26 import javax.persistence.IdClass;
27 import javax.persistence.Index;
28 import javax.persistence.Table;
29 import org.turro.json.IJSONizable;
30 import org.turro.string.Strings;
31 import org.turro.tags.TagMeta;
32 
37 @Entity
38 @IdClass(TagPK.class)
39 @Table(indexes={
40  @Index(name = "TagIndex", columnList = "tagName")
41 })
42 public class Tag implements Serializable, IJSONizable {
43 
44  @Id private String tagName;
45  @Id private String entityPath;
46 
47  public String getTagName() {
48  return tagName;
49  }
50 
51  public void setTagName(String tagName) {
52  this.tagName = tagName;
53  }
54 
55  public String getEntityPath() {
56  return entityPath;
57  }
58 
59  public void setEntityPath(String entityPath) {
60  this.entityPath = entityPath;
61  }
62 
63  /* Helpers */
64 
65  public boolean isEmpty() {
66  return Strings.isBlank(tagName) || Strings.isBlank(entityPath);
67  }
68 
69  public TagMeta getMeta() {
70  return TagMeta.importFrom(tagName);
71  }
72 
73  /* JSONizable */
74 
75  @Override
76  public String toJson() {
77  return toJson(this);
78  }
79 
80  @Override
81  public String toJson(Map<String, Object> properties) {
82  return toJson(this, properties);
83  }
84 
85  public static Tag fromJson(JsonValue value) {
86  return IJSONizable.fromJson(value.toString(), Tag.class);
87  }
88 
89 }
void setTagName(String tagName)
Definition: Tag.java:51
static Tag fromJson(JsonValue value)
Definition: Tag.java:85
String toJson(Map< String, Object > properties)
Definition: Tag.java:81
void setEntityPath(String entityPath)
Definition: Tag.java:59
static TagMeta importFrom(String tagName)
Definition: TagMeta.java:47