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 SurveyDAOThe instance of SurveyDAO that will be used to perform actions to the DBprivate final SurveyQuestionsDAOThe instance of SurveyDAO that will be used to perform actions to the DBprivate final UserRepositoryImplThe 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 TypeMethodDescriptionvoidInserts a new instance of Survey in the databasevoidInserts 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 maintainvoidmodifyName(String name, int id) Updates the name of the survey in the database.voidmodifyQuestions(Set<SurveyQuestions> surveyQuestions, int surveyId) Updates the questions list of the survey.voidremove(int id) Deletes from the database the survey identified by id.voidDeletes 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:
addin 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:
getin interfaceSurveyRepository- Specified by:
getin 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:
getAllin 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:
getAllLazyin 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:
getByTextin 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:
getByTextLazyin 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:
getByCompilationCodein interfaceSurveyRepository- Throws:
NotFoundException
-
remove
Deletes from the database the survey identified by id.- Specified by:
removein 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:
modifyNamein interfaceSurveyRepository- Parameters:
id- survey idname- new name- Throws:
FormatExceptionNotFoundExceptionEmptyFieldException- 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:
modifyQuestionsin interfaceSurveyRepository- Parameters:
surveyQuestions- the new questions list of SurveysurveyId- the survey id- Throws:
FormatException- See Also:
-