BrightSide Workbench Full Report + Source Code
RelationValidation.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.contacts;
20 
21 import java.io.Serializable;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.Id;
25 import org.turro.mail.MailValidator;
26 import org.turro.contacts.db.ContactsPU;
27 import org.turro.contacts.relation.ValidationRule;
28 import org.turro.elephant.security.IUser;
29 import org.turro.jpa.entity.IDaoEntity;
30 import org.zkoss.lang.Strings;
31 
36 @Entity
37 public class RelationValidation implements IDaoEntity, Serializable {
38 
39  @Id
40  @Column(name="IDENTIFIER")
41  private String id;
42 
43  private String providedEmail;
44 
45  private boolean validated;
46 
47  private ValidationRule rule;
48 
49  public String getId() {
50  return id;
51  }
52 
53  public void setId(String id) {
54  this.id = id;
55  }
56 
57  public String getProvidedEmail() {
58  return providedEmail;
59  }
60 
61  public void setProvidedEmail(String providedEmail) {
62  this.providedEmail = providedEmail;
63  }
64 
65  public boolean isValidated() {
66  return validated;
67  }
68 
69  public void setValidated(boolean validated) {
70  this.validated = validated;
71  }
72 
74  return rule;
75  }
76 
77  public void setRule(ValidationRule rule) {
78  this.rule = rule;
79  }
80 
81  /* IDaoEntity */
82 
83  @Override
84  public Object entityId() {
85  return id;
86  }
87 
88  @Override
89  public boolean isEmpty() {
90  return false;
91  }
92 
93  /* Helpers */
94 
95  public boolean isBad() {
96  return !Strings.isBlank(providedEmail) && !MailValidator.single().silently(providedEmail);
97  }
98 
100  return new ContactsPU().find(BusinessRelation.class, id);
101  }
102 
103  public static RelationValidation getFrom(BusinessRelation relation) {
104  RelationValidation rv = new ContactsPU().find(RelationValidation.class, relation.getId());
105  if(rv == null) {
106  rv = new RelationValidation();
107  rv.id = relation.getId();
108  Connector email = relation.getContact().getConnectorMap().get(IUser.CONNECTOR_EMAIL);
109  rv.providedEmail = email != null ? email.getValue() : null;
110  }
111  return rv;
112  }
113 
114 }
Map< String, Connector > getConnectorMap()
Definition: Contact.java:499
void setProvidedEmail(String providedEmail)
static RelationValidation getFrom(BusinessRelation relation)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27