public final class DOIDbDataAccessServiceImpl extends Object implements DOIDbDataAccessService
DOIDbDataAccessService
using JDBC.Modifier and Type | Field and Description |
---|---|
static String |
DB_MAX_ACTIVE_CONNECTIONS
Maximum number of active connections that can be allocated at the same
time.
|
static String |
DB_MAX_IDLE_CONNECTIONS
Minimum number of connection object that are to be kept alive in the pool
|
static String |
DB_MIN_IDLE_CONNECTIONS
Minimum number of connection object that are to be kept alive in the pool
|
static String |
DB_PWD
Database password
|
static String |
DB_URL
Database url
|
static String |
DB_USER
Database user
|
private JDBCConnector |
dbConnector
Connection to the DOI database.
|
private static String |
DELETE_ASSIGN
Delete part of the assign.
|
private static String |
DELETE_ASSIGN_SUFFIX
Delete assignation based on the project DOI suffix.
|
private static String |
DELETE_ASSIGN_USER_AND_SUFFIX
Delete assignation based on username and project DOI suffix.
|
private static String |
DELETE_ASSIGN_USERNAME
Delete assignation based on the username.
|
private static String |
DELETE_DOI_USERS
Delete a user based on its username.
|
private static String |
DELETE_PROJECT
Delete part of the project.
|
private static String |
DELETE_PROJECT_WITH_SUFFIX
Delete a project based on its DOI suffix.
|
private static String |
DELETE_TOKEN
Delete token.
|
private static String |
FIELD_ADMIN
SQL field that contains the information telling if a user is admin
"admin".
|
private static String |
FIELD_EMAIL
SQL field that contains the email user "email".
|
private static String |
FIELD_PROJECT_SUFFIX
SQL field that contains the DOI suffix for the project name
"suffix".
|
private static String |
FIELD_PROJECTNAME
SQL field that contains the projectname related to a user
"projectname".
|
private static String |
FIELD_TOKEN
SQL field that contains the authentication token.
|
private static String |
FIELD_USERNAME
SQL field that contains the username "username".
|
private static String |
INSERT_DOI_ASSIGN
Insert assignation information.
|
private static String |
INSERT_DOI_PROJECTS
Insert project information.
|
private static String |
INSERT_DOI_USERS
Insert user information.
|
private static String |
INSERT_FULL_DOI_UERS
Insert user information.
|
private static String |
INSERT_TOKEN
Insert token.
|
private static org.apache.logging.log4j.Logger |
LOGGER
Logger.
|
private static String |
SELECT_DOI_USERS
Select user information.
|
private static String |
SELECT_EXISTS_SUFFIX
Checks if the project exists based on its DOI suffix.
|
private static String |
SELECT_EXISTS_USERNAME
Checks if the user exists based on its username.
|
private static String |
SELECT_PROJECT_SUFFIX
Select a specific project based on the DOI suffix.
|
private static String |
SELECT_PROJECTS
Select project information.
|
private static String |
SELECT_PROJECTS_WITH_CTX_SUFFIX
Select user information bases on the DOI suffix.
|
private static String |
SELECT_PROJECTS_WITH_CTX_USER
Select project information for a specific user.
|
private static String |
SELECT_TOKEN
Select all tokens.
|
private static String |
SELECT_USERS_CLAUSE_USER
Select user information based on its username.
|
private static String |
UPDATE_ADMIN_FALSE
Unsets a user as admin.
|
private static String |
UPDATE_ADMIN_TRUE
Sets a user as admin.
|
private static String |
UPDATE_PROJECT
Update project information.
|
Constructor and Description |
---|
DOIDbDataAccessServiceImpl()
Constructor.
|
DOIDbDataAccessServiceImpl(String dbUrl,
String dbUser,
String dbPwd,
Map<String,Integer> options)
Create the implementation of DOI database by creation the JDBC connection
from a specific configuration file.
|
Modifier and Type | Method and Description |
---|---|
void |
addDOIProject(int suffix,
String projectname)
Add a DOI project
|
void |
addDOIProjectToUser(String username,
int suffix)
Assign a DOI project to a user
|
void |
addDOIUser(String username,
Boolean admin)
Add a DOI user
|
void |
addDOIUser(String username,
Boolean admin,
String email)
Add a DOI user
|
void |
addToken(String token)
Add token
|
void |
close()
Close and release all the Data access connections.
|
private void |
closeAndRelease(Connection conn,
PreparedStatement... statements)
Close the statements and free the connection.
|
void |
deleteToken(String token)
Delete token
|
List<DOIProject> |
getAllDOIProjects()
Get all DOI projects from data base
|
List<DOIProject> |
getAllDOIProjectsForUser(String username)
Get Projects related to a given username
|
List<DOIUser> |
getAllDOIusers()
Get all DOI users from data base
|
List<DOIUser> |
getAllDOIUsersForProject(int suffix)
Get Users from a given project.
|
String |
getDOIProjectName(int suffix)
Get Project name from its suffix.
|
private List<DOIProject> |
getDOIProjects(PreparedStatement statement)
Returns the list of DOI projects
|
private DOIUser |
getDoiUserFromDb(String username)
Returns the DOI user from the username.
|
private List<DOIUser> |
getDOIUSers(PreparedStatement statement)
Returns the list of DOI users
|
private List<String> |
getProjectName(PreparedStatement statement)
Returns the list of projectName.
|
List<String> |
getTokens()
Get tokens
|
private List<String> |
getTokens(PreparedStatement statement)
Returns the list of tokens.
|
void |
init(String dbUrl,
String dbUser,
String dbPwd,
Map<String,Integer> options)
Initialize the JDBC connection when it is not defined.
|
boolean |
isAdmin(String username)
Check if user is an admin user
|
private boolean |
isQueryExist(PreparedStatement statement)
Returns true when the query returns a non empty result otherwise false.
|
boolean |
isUserExist(String username)
Check if user exists in the database
|
void |
removeDOIProject(int suffix)
Remove a DOI project
|
void |
removeDOIProjectFromUser(String username,
int suffix)
Remove a DOI project from a user
|
void |
removeDOIUser(String username)
Remove a DOI user
|
void |
renameDOIProject(int suffix,
String newprojectname)
Rename DOI project from its suffix.
|
void |
setAdmin(String username)
Add admin right to a user
|
void |
unsetAdmin(String username)
Remove admin right from a user
|
private void |
updateQueries(PreparedStatement... statements)
Updates queries.
|
public static final String DB_URL
public static final String DB_USER
public static final String DB_PWD
public static final String DB_MIN_IDLE_CONNECTIONS
public static final String DB_MAX_IDLE_CONNECTIONS
public static final String DB_MAX_ACTIVE_CONNECTIONS
private static final org.apache.logging.log4j.Logger LOGGER
private static final String FIELD_USERNAME
private static final String FIELD_ADMIN
private static final String FIELD_EMAIL
private static final String FIELD_PROJECTNAME
private static final String FIELD_PROJECT_SUFFIX
private static final String FIELD_TOKEN
private static final String SELECT_DOI_USERS
private static final String SELECT_PROJECTS
private static final String SELECT_PROJECT_SUFFIX
private static final String SELECT_PROJECTS_WITH_CTX_USER
private static final String SELECT_PROJECTS_WITH_CTX_SUFFIX
private static final String SELECT_USERS_CLAUSE_USER
private static final String SELECT_EXISTS_USERNAME
private static final String SELECT_EXISTS_SUFFIX
private static final String SELECT_TOKEN
private static final String DELETE_PROJECT
private static final String DELETE_PROJECT_WITH_SUFFIX
private static final String DELETE_DOI_USERS
private static final String DELETE_ASSIGN
private static final String DELETE_ASSIGN_USERNAME
private static final String DELETE_ASSIGN_SUFFIX
private static final String DELETE_ASSIGN_USER_AND_SUFFIX
private static final String DELETE_TOKEN
private static final String INSERT_DOI_USERS
private static final String INSERT_FULL_DOI_UERS
private static final String INSERT_DOI_PROJECTS
private static final String INSERT_DOI_ASSIGN
private static final String INSERT_TOKEN
private static final String UPDATE_ADMIN_TRUE
private static final String UPDATE_ADMIN_FALSE
private static final String UPDATE_PROJECT
private JDBCConnector dbConnector
public DOIDbDataAccessServiceImpl()
public DOIDbDataAccessServiceImpl(String dbUrl, String dbUser, String dbPwd, Map<String,Integer> options)
dbUrl
- database URLdbUser
- database userdbPwd
- database passwordoptions
- database optionspublic void init(String dbUrl, String dbUser, String dbPwd, Map<String,Integer> options)
dbUrl
- database URLdbUser
- database userdbPwd
- database passwordoptions
- database optionsprivate List<DOIProject> getDOIProjects(PreparedStatement statement) throws SQLException
statement
- Query to T_DOI_PROJECTSQLException
- When an SQL execption occursprivate List<DOIUser> getDOIUSers(PreparedStatement statement) throws SQLException
statement
- Query to T_DOI_USERSSQLException
- When an SQL execption occursprivate List<String> getTokens(PreparedStatement statement) throws SQLException
statement
- Query to T_DOI_USERSSQLException
- When an SQL execption occursprivate void updateQueries(PreparedStatement... statements) throws SQLException
statements
- statementsSQLException
- - if a problem occursprivate List<String> getProjectName(PreparedStatement statement) throws SQLException
statement
- Query to T_DOI_PROJECTSQLException
- When an SQL execption occursprivate boolean isQueryExist(PreparedStatement statement) throws SQLException
statement
- querySQLException
- When an SQL execption occursprivate void closeAndRelease(Connection conn, PreparedStatement... statements)
conn
- connection to closeAndReleasestatements
- statements to closeAndReleasepublic List<DOIUser> getAllDOIusers() throws DOIDbException
getAllDOIusers
in interface DOIDbDataAccessService
DOIDbException
- When an Database exception happenspublic List<DOIProject> getAllDOIProjects() throws DOIDbException
getAllDOIProjects
in interface DOIDbDataAccessService
DOIDbException
- When an Database exception happenspublic List<DOIProject> getAllDOIProjectsForUser(String username) throws DOIDbException
getAllDOIProjectsForUser
in interface DOIDbDataAccessService
username
- usernameDOIDbException
- When an Database exception happenspublic List<DOIUser> getAllDOIUsersForProject(int suffix) throws DOIDbException
getAllDOIUsersForProject
in interface DOIDbDataAccessService
suffix
- suffixDOIDbException
- When an Database exception happenspublic void addDOIUser(String username, Boolean admin) throws DOIDbException
addDOIUser
in interface DOIDbDataAccessService
username
- usernameadmin
- True when the user is admin otherwise FalseDOIDbException
- When an Database exception happenspublic void addDOIProject(int suffix, String projectname) throws DOIDbException
addDOIProject
in interface DOIDbDataAccessService
suffix
- suffixprojectname
- project nameDOIDbException
- When an Database exception happenspublic void addDOIProjectToUser(String username, int suffix) throws DOIDbException
addDOIProjectToUser
in interface DOIDbDataAccessService
username
- user namesuffix
- suffix related to a projectDOIDbException
- When an Database exception happenspublic void removeDOIProjectFromUser(String username, int suffix) throws DOIDbException
removeDOIProjectFromUser
in interface DOIDbDataAccessService
username
- user namesuffix
- suffix related to a projectDOIDbException
- When an Database exception happenspublic void setAdmin(String username) throws DOIDbException
setAdmin
in interface DOIDbDataAccessService
username
- user nameDOIDbException
- When an Database exception happenspublic void unsetAdmin(String username) throws DOIDbException
unsetAdmin
in interface DOIDbDataAccessService
username
- user nameDOIDbException
- When an Database exception happenspublic void renameDOIProject(int suffix, String newprojectname) throws DOIDbException
renameDOIProject
in interface DOIDbDataAccessService
suffix
- suffixnewprojectname
- new project nameDOIDbException
- When an Database exception happenspublic String getDOIProjectName(int suffix) throws DOIDbException
getDOIProjectName
in interface DOIDbDataAccessService
suffix
- suffixDOIDbException
- When an Database exception
happenspublic void addToken(String token) throws DOIDbException
addToken
in interface DOIDbDataAccessService
token
- Adds a token to the databaseDOIDbException
- When an Database exception
happenspublic void deleteToken(String token) throws DOIDbException
deleteToken
in interface DOIDbDataAccessService
token
- token to deleteDOIDbException
- When an Database exception
happenspublic List<String> getTokens() throws DOIDbException
getTokens
in interface DOIDbDataAccessService
DOIDbException
- When an Database exception
happenspublic void removeDOIUser(String username) throws DOIDbException
removeDOIUser
in interface DOIDbDataAccessService
username
- usernameDOIDbException
- When an Database exception happenspublic void addDOIUser(String username, Boolean admin, String email) throws DOIDbException
addDOIUser
in interface DOIDbDataAccessService
username
- usernameadmin
- True when the user is admin otherwise Falseemail
- emailDOIDbException
- When an Database exception happenspublic void removeDOIProject(int suffix) throws DOIDbException
removeDOIProject
in interface DOIDbDataAccessService
suffix
- suffixDOIDbException
- When an Database exception happenspublic boolean isAdmin(String username) throws DOIDbException
isAdmin
in interface DOIDbDataAccessService
username
- user nameDOIDbException
- When an Database exception happensprivate DOIUser getDoiUserFromDb(String username) throws DOIDbException
username
- username in the DBDOIDbException
- - if a database error occurs.public boolean isUserExist(String username) throws DOIDbException
isUserExist
in interface DOIDbDataAccessService
username
- user nameDOIDbException
- When an Database exception happenspublic void close() throws DOIDbException
close
in interface DOIDbDataAccessService
DOIDbException
- When an error occursCopyright © 2017–2020 CNES. All rights reserved.