BrightSide Workbench Full Report + Source Code
ConnectorAttribute.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.contacts.proposal;
19 
20 import java.util.List;
21 import org.turro.contacts.Connector;
22 import org.turro.contacts.Contact;
23 import org.turro.contacts.db.ContactsPU;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.elephant.security.IUser;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.Dao;
28 
33 public class ConnectorAttribute extends GenericAttribute<Connector> {
34 
36  super(attribute);
37  duplication = (IUser.CONNECTOR_EMAIL.equals(attribute.getDescription()) ||
38  IUser.CONNECTOR_TRADE.equals(attribute.getDescription()) ||
39  IUser.CONNECTOR_FISCAL.equals(attribute.getDescription())) ?
42  }
43 
44  @Override
45  protected List<Connector> generateRelated() {
46  Dao dao = new ContactsPU();
47  WhereClause wc = new WhereClause();
48  wc.addClause("select connector from Connector as connector");
49  wc.addClause("where connector.value = :value");
50  wc.addNamedValue("value", attribute.getValue());
51  return dao.getResultList(wc);
52  }
53 
54  @Override
55  public void addToContact(Contact contact) {
56  attribute.setContact(contact);
57  contact.getConnectors().add(attribute);
58  }
59 
60  @Override
61  public String getAsString() {
62  return attribute.getFullConnector();
63  }
64 
65  @Override
66  public Contact getContact() {
67  return attribute.getContact();
68  }
69 
70  @Override
71  public String getAttributeName() {
72  return I_.get("Connector");
73  }
74 
75  @Override
77  return new IAttribute() {
78 
79  @Override
80  public String getAsString() {
81  return a.getFullConnector();
82  }
83 
84  @Override
85  public Contact getContact() {
86  return a.getContact();
87  }
88 
89  @Override
90  public Object getValue() {
91  return a;
92  }
93  };
94  }
95 
96 }
org.turro.contacts.Contact getContact()
Definition: Connector.java:99
Set< Connector > getConnectors()
Definition: Contact.java:367
IAttribute generateAttributeAdapter(final Connector a)
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41
static final String CONNECTOR_EMAIL
Definition: IUser.java:27
static final String CONNECTOR_FISCAL
Definition: IUser.java:29
static final String CONNECTOR_TRADE
Definition: IUser.java:28