1 /*
2 * Copyright (C) 2017-2019 Centre National d'Etudes Spatiales (CNES).
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 package fr.cnes.doi.plugin.impl.db.service;
20
21 import java.util.List;
22
23 import fr.cnes.doi.exception.DOIDbException;
24 import fr.cnes.doi.db.model.DOIProject;
25 import fr.cnes.doi.db.model.DOIUser;
26
27 /**
28 * Interface between server and database
29 */
30 public interface DOIDbDataAccessService {
31
32 /**
33 * Get all DOI users from data base
34 *
35 * @return list of DOIUser
36 * @throws DOIDbException When an Database exception happens
37 */
38 public List<DOIUser> getAllDOIusers() throws DOIDbException;
39
40 /**
41 * Get all DOI projects from data base
42 *
43 * @return list of DOI projects
44 * @throws DOIDbException When an Database exception happens
45 */
46 public List<DOIProject> getAllDOIProjects() throws DOIDbException;
47
48 /**
49 * Get Projects related to a given username
50 *
51 * @param username username
52 * @return List of projects
53 * @throws DOIDbException When an Database exception happens
54 */
55 public List<DOIProject> getAllDOIProjectsForUser(String username) throws DOIDbException;
56
57 /**
58 * Get Users from a given project.
59 *
60 * @param suffix suffix
61 * @return List of DOIUser
62 * @throws DOIDbException When an Database exception happens
63 */
64 public List<DOIUser> getAllDOIUsersForProject(int suffix) throws DOIDbException;
65
66 /**
67 * Add a DOI user
68 *
69 * @param username username
70 * @param admin True when the user is admin otherwise False
71 * @throws DOIDbException When an Database exception happens
72 */
73 public void addDOIUser(String username, Boolean admin) throws DOIDbException;
74
75 /**
76 * Add a DOI user
77 *
78 * @param username username
79 * @param admin True when the user is admin otherwise False
80 * @param email email
81 * @throws DOIDbException When an Database exception happens
82 */
83 public void addDOIUser(String username, Boolean admin, String email) throws DOIDbException;
84
85 /**
86 * Remove a DOI user
87 *
88 * @param username username
89 * @throws DOIDbException When an Database exception happens
90 */
91 public void removeDOIUser(String username) throws DOIDbException;
92
93 /**
94 * Remove a DOI project
95 *
96 * @param suffix suffix
97 * @throws DOIDbException When an Database exception happens
98 */
99 public void removeDOIProject(int suffix) throws DOIDbException;
100
101 /**
102 * Add a DOI project
103 *
104 * @param suffix suffix
105 * @param projectname project name
106 * @throws DOIDbException When an Database exception happens
107 */
108 public void addDOIProject(int suffix, String projectname) throws DOIDbException;
109
110 /**
111 * Assign a DOI project to a user
112 *
113 * @param username user name
114 * @param suffix suffix related to a project
115 * @throws DOIDbException When an Database exception happens
116 */
117 public void addDOIProjectToUser(String username, int suffix) throws DOIDbException;
118
119 /**
120 * Remove a DOI project from a user
121 *
122 * @param username user name
123 * @param suffix suffix related to a project
124 * @throws DOIDbException When an Database exception happens
125 */
126 public void removeDOIProjectFromUser(String username, int suffix) throws DOIDbException;
127
128 /**
129 * Add admin right to a user
130 *
131 * @param username user name
132 * @throws DOIDbException When an Database exception happens
133 */
134 public void setAdmin(String username) throws DOIDbException;
135
136 /**
137 * Remove admin right from a user
138 *
139 * @param username user name
140 * @throws DOIDbException When an Database exception happens
141 */
142 public void unsetAdmin(String username) throws DOIDbException;
143
144 /**
145 * Check if user is an admin user
146 *
147 * @param username user name
148 * @return false if user is not admin or doesn't exist
149 * @throws DOIDbException When an Database exception happens
150 */
151 public boolean isAdmin(String username) throws DOIDbException;
152
153 /**
154 * Check if user exists in the database
155 *
156 * @param username user name
157 * @throws DOIDbException When an Database exception happens
158 * @return false if user does not exist
159 */
160 public boolean isUserExist(String username) throws DOIDbException;
161
162 /**
163 * Rename DOI project from its suffix.
164 *
165 * @param suffix suffix
166 * @param newprojectname new project name
167 * @throws DOIDbException When an Database exception happens
168 */
169 public void renameDOIProject(int suffix, String newprojectname) throws DOIDbException;
170
171 /**
172 * Get Project name from its suffix.
173 *
174 * @param suffix suffix
175 * @return project name
176 * @throws fr.cnes.doi.exception.DOIDbException When an Database exception
177 * happens
178 */
179 public String getDOIProjectName(int suffix) throws DOIDbException;
180
181 /**
182 * Add token
183 *
184 * @param token Adds a token to the database
185 * @throws fr.cnes.doi.exception.DOIDbException When an Database exception
186 * happens
187 */
188 public void addToken(String token) throws DOIDbException;
189
190 /**
191 * Delete token
192 *
193 * @param token token to delete
194 * @throws fr.cnes.doi.exception.DOIDbException When an Database exception
195 * happens
196 */
197 public void deleteToken(String token) throws DOIDbException;
198
199 /**
200 * Get tokens
201 *
202 * @return List of tokens
203 * @throws fr.cnes.doi.exception.DOIDbException When an Database exception
204 * happens
205 */
206 public List<String> getTokens() throws DOIDbException;
207
208 /**
209 * Close and release all the Data access connections.
210 *
211 * @throws DOIDbException When an error occurs
212 */
213 public void close() throws DOIDbException;
214
215 }