BrightSide Workbench Full Report + Source Code
AxTalentCategory.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2024 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.io.Serializable;
22 import java.util.Map;
23 import javax.json.JsonValue;
24 import javax.persistence.Entity;
25 import javax.persistence.Id;
26 import org.turro.alliance.db.AlliancePU;
27 import org.turro.elephant.db.IdUtils;
28 import org.turro.jpa.entity.IDaoEntity;
29 import org.turro.json.IJSONizable;
30 import org.turro.math.Zero;
31 import org.turro.string.Strings;
32 
37 @Entity
38 public class AxTalentCategory implements Serializable, IDaoEntity, IJSONizable {
39 
40  @Id private Long categoryId;
41 
42  private String name;
43 
44  public Long getCategoryId() {
45  return categoryId;
46  }
47 
48  public void setCategoryId(Long categoryId) {
49  this.categoryId = categoryId;
50  }
51 
52  public String getName() {
53  return name;
54  }
55 
56  public void setName(String name) {
57  this.name = name;
58  }
59 
60  /* IDaoEntity */
61 
62  @Override
63  public Object entityId() {
64  return categoryId;
65  }
66 
67  @Override
68  public boolean isEmpty() {
69  return Strings.isBlank(name);
70  }
71 
72  @Override
73  public void prepareSave() {
74  IDaoEntity.super.prepareSave();
75  if(Zero.orNull(categoryId)) {
76  categoryId = IdUtils.getNewLongIdFromLong(new AlliancePU(), "AxTalentCategory", "categoryId");
77  }
78  }
79 
80  /* JSONizable */
81 
82  @Override
83  public String toJson() {
84  return toJson(this);
85  }
86 
87  @Override
88  public String toJson(Map<String, Object> properties) {
89  return toJson(this, properties);
90  }
91 
92  public static AxTalentCategory fromJson(JsonValue value) {
93  return IJSONizable.fromJson(value.toString(), AxTalentCategory.class);
94  }
95 
96 }
97 
static AxTalentCategory fromJson(JsonValue value)
String toJson(Map< String, Object > properties)
static long getNewLongIdFromLong(Dao dao, String table, String field)
Definition: IdUtils.java:33
static boolean orNull(Number value)
Definition: Zero.java:26