2
* Copyright 2005-2012 Restlet S.A.S.
4
* The contents of this file are subject to the terms of one of the following
5
* open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
6
* 1.0 (the "Licenses"). You can select the license that you prefer but you may
7
* not use this file except in compliance with one of these Licenses.
9
* You can obtain a copy of the Apache 2.0 license at
10
* http://www.opensource.org/licenses/apache-2.0
12
* You can obtain a copy of the LGPL 3.0 license at
13
* http://www.opensource.org/licenses/lgpl-3.0
15
* You can obtain a copy of the LGPL 2.1 license at
16
* http://www.opensource.org/licenses/lgpl-2.1
18
* You can obtain a copy of the CDDL 1.0 license at
19
* http://www.opensource.org/licenses/cddl1
21
* You can obtain a copy of the EPL 1.0 license at
22
* http://www.opensource.org/licenses/eclipse-1.0
24
* See the Licenses for the specific language governing permissions and
25
* limitations under the Licenses.
27
* Alternatively, you can obtain a royalty free commercial license with less
28
* limitations, transferable or non-transferable, directly at
29
* http://www.restlet.com/products/restlet-framework
31
* Restlet is a registered trademark of Restlet S.A.S.
34
package org.restlet.example.ext.rdf.foaf.objects;
36
import java.util.List;
38
import org.restlet.example.ext.rdf.foaf.data.DataFacade;
43
public class ObjectsFacade {
46
protected DataFacade dataFacade;
48
public ObjectsFacade(DataFacade dataFacade) {
50
this.dataFacade = dataFacade;
54
* Add a new Contact object in the database.
59
* new Contact object to be added.
60
* @return the contact object completed with its identifiant.
62
public Contact createContact(User user, Contact contact) {
63
contact = this.dataFacade.createContact(user, contact);
64
user.getContacts().add(contact);
65
this.dataFacade.updateUser(user);
71
* Add a new User object in the database.
74
* new User object to be added.
75
* @return the user object completed with its identfiant.
76
* @throws ObjectsException
78
public User createUser(User user) throws ObjectsException {
79
user = this.dataFacade.createUser(user);
89
* the contact to be deleted.
91
public void deleteContact(User user, Contact contact) {
92
// Remove the contact from the mailbox's list of contacts.
93
boolean found = false;
94
for (int i = 0; (i < user.getContacts().size()) && !found; i++) {
95
final Contact contact2 = user.getContacts().get(i);
96
if (contact2.getId().equals(contact.getId())) {
97
user.getContacts().remove(i);
102
this.dataFacade.deleteContact(contact);
103
this.dataFacade.updateUser(user);
110
* the user to be deleted.
112
public void deleteUser(User user) {
113
// Delete the user and its mailboxes.
114
for (final Contact contact : user.getContacts()) {
115
this.dataFacade.deleteContact(contact);
117
this.dataFacade.deleteUser(user);
121
* Get a contact by its id.
125
* @return a Contact object or null if no contact has been found.
127
public Contact getContactById(String contactId) {
128
return this.dataFacade.getContactById(contactId);
132
* Get a user by its id.
136
* @return a User object or null if no user has been found.
138
public User getUserById(String userId) {
139
return this.dataFacade.getUserById(userId);
143
* Get the list of all users.
145
* @return the list of all users.
147
public List<User> getUsers() {
148
return this.dataFacade.getUsers();
157
* the contact to be update.
159
public void updateContact(User user, Contact contact) {
160
this.dataFacade.updateContact(contact);
167
* the user to be upated.
169
public void updateUser(User user) {
170
this.dataFacade.updateUser(user);