Class SurveyRepositoryImpl
java.lang.Object
it.unimib.unimibmodules.repository.SurveyRepositoryImpl
- All Implemented Interfaces:
SurveyRepository
,SurveyRepositoryReadOnly
@Component("surveyRepository")
public class SurveyRepositoryImpl
extends Object
implements SurveyRepository, SurveyRepositoryReadOnly
Repository for the Survey. It adds business logic to Survey instances before
accessing the database trough DAO.
- Version:
- 0.4.1
- Author:
- Luca Milazzo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SurveyDAO
The instance of SurveyDAO that will be used to perform actions to the DBprivate final SurveyQuestionsDAO
The instance of SurveyDAO that will be used to perform actions to the DBprivate final UserRepositoryImpl
The instance of SurveyDAO that will be used to perform actions to the DB -
Constructor Summary
ConstructorsConstructorDescriptionSurveyRepositoryImpl
(SurveyDAO surveyDAO, SurveyQuestionsDAO surveyQuestionsDAO, UserRepositoryImpl userRepository) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts a new instance of Survey in the databasevoid
Inserts a new Set of surveys in the databaseget
(int id) Finds the survey identified by id in the databasegetAll()
Returns all surveys from the database.getAllLazy
(int offset, int limit) Returns all surveys from the database with Lazy Loading parameters.getByCompilationCode
(String code) Finds all the surveys in the database where text is contained in their names or in their identifier.getByTextLazy
(String text, int offset, int limit) Finds all the surveys in the database where text is contained in their names or in their identifier with Lazy Loading parameters.getListToSave
(Set<SurveyQuestions> surveyQuestions, int surveyId) It's used by modifyQuestions in order to find all the questions to create or maintainvoid
modifyName
(String name, int id) Updates the name of the survey in the database.void
modifyQuestions
(Set<SurveyQuestions> surveyQuestions, int surveyId) Updates the questions list of the survey.void
remove
(int id) Deletes from the database the survey identified by id.void
Deletes all the surveys in the database.
-
Field Details
-
surveyDAO
The instance of SurveyDAO that will be used to perform actions to the DB -
surveyQuestionsDAO
The instance of SurveyDAO that will be used to perform actions to the DB -
userRepository
The instance of SurveyDAO that will be used to perform actions to the DB
-
-
Constructor Details
-
SurveyRepositoryImpl
@Autowired public SurveyRepositoryImpl(SurveyDAO surveyDAO, SurveyQuestionsDAO surveyQuestionsDAO, UserRepositoryImpl userRepository)
-
-
Method Details
-
add
Inserts a new instance of Survey in the database- Specified by:
add
in interfaceSurveyRepository
- Parameters:
survey
- an instance of Survey- Throws:
FormatException
- See Also:
-
addAll
Inserts a new Set of surveys in the database- Parameters:
surveySet
- a Set of Survey- Throws:
FormatException
- See Also:
-
get
Finds the survey identified by id in the database- Specified by:
get
in interfaceSurveyRepository
- Specified by:
get
in interfaceSurveyRepositoryReadOnly
- Parameters:
id
- the id of the survey to be found- Returns:
- an instance of Survey if there is a survey identified by id
- Throws:
NotFoundException
- if the survey doesn't exist- See Also:
-
getAll
Returns all surveys from the database.- Specified by:
getAll
in interfaceSurveyRepository
- Returns:
- a Set of Surveys
- Throws:
NotFoundException
- if no survey exists- See Also:
-
getAllLazy
Returns all surveys from the database with Lazy Loading parameters.- Specified by:
getAllLazy
in interfaceSurveyRepository
- Parameters:
offset
- offset for lazy loadinglimit
- for limiting the result length- Returns:
- a Set of Surveys
- Throws:
NotFoundException
- if no survey exists- See Also:
-
getByText
Finds all the surveys in the database where text is contained in their names or in their identifier.- Specified by:
getByText
in interfaceSurveyRepository
- Parameters:
text
- the text to search- Returns:
- a list of Surveys where the text has been matched
- Throws:
NotFoundException
- if no survey has been found- See Also:
-
getByTextLazy
Finds all the surveys in the database where text is contained in their names or in their identifier with Lazy Loading parameters.- Specified by:
getByTextLazy
in interfaceSurveyRepository
- Parameters:
text
- the text to searchoffset
- offset for lazy loadinglimit
- for limiting the result length- Returns:
- a list of Surveys where the text has been matched
- Throws:
NotFoundException
- if no survey has been found- See Also:
-
getByCompilationCode
- Specified by:
getByCompilationCode
in interfaceSurveyRepository
- Throws:
NotFoundException
-
remove
Deletes from the database the survey identified by id.- Specified by:
remove
in interfaceSurveyRepository
- Parameters:
id
- the id of the survey to be deleted- Throws:
FormatException
- See Also:
-
removeAll
public void removeAll()Deletes all the surveys in the database. -
modifyName
public void modifyName(String name, int id) throws FormatException, NotFoundException, EmptyFieldException Updates the name of the survey in the database.- Specified by:
modifyName
in interfaceSurveyRepository
- Parameters:
id
- survey idname
- new name- Throws:
FormatException
NotFoundException
EmptyFieldException
- See Also:
-
getListToSave
It's used by modifyQuestions in order to find all the questions to create or maintain- Parameters:
surveyQuestions
- the new questions list of SurveysurveyId
- the survey id- Throws:
FormatException
- See Also:
-
modifyQuestions
public void modifyQuestions(Set<SurveyQuestions> surveyQuestions, int surveyId) throws FormatException Updates the questions list of the survey.- Specified by:
modifyQuestions
in interfaceSurveyRepository
- Parameters:
surveyQuestions
- the new questions list of SurveysurveyId
- the survey id- Throws:
FormatException
- See Also:
-