BrightSide Workbench Full Report + Source Code
AddressAttribute.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.Address;
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 AddressAttribute extends GenericAttribute<Address> {
34 
36  super(attribute);
37  duplication = IUser.ADDRESS_FISCAL.equals(attribute.getDescription()) ?
40  }
41 
42  @Override
43  protected List<Address> generateRelated() {
44  Dao dao = new ContactsPU();
45  WhereClause wc = new WhereClause();
46  wc.addClause("select address from Address as address");
47  wc.addClause("where address.street = :street");
48  wc.addClause("and address.city = :city");
49  wc.addNamedValue("street", attribute.getStreet());
50  wc.addNamedValue("city", attribute.getCity());
51  return dao.getResultList(wc);
52  }
53 
54  @Override
55  public void addToContact(Contact contact) {
56  attribute.setContact(contact);
57  contact.getAddresses().add(attribute);
58  }
59 
60  @Override
61  public String getAsString() {
62  return attribute.getFullAddress();
63  }
64 
65  @Override
66  public Contact getContact() {
67  return attribute.getContact();
68  }
69 
70  @Override
71  public String getAttributeName() {
72  return I_.get("Address");
73  }
74 
75  @Override
77  return new IAttribute() {
78 
79  @Override
80  public String getAsString() {
81  return a.getFullAddress();
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: Address.java:166
Set< Address > getAddresses()
Definition: Contact.java:355
IAttribute generateAttributeAdapter(final Address a)
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41
static final String ADDRESS_FISCAL
Definition: IUser.java:31