├── student-management-system ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── studentmgr │ │ │ │ ├── common │ │ │ │ ├── messages │ │ │ │ │ ├── InfoMessage.java │ │ │ │ │ └── ErrorMessage.java │ │ │ │ ├── sse │ │ │ │ │ ├── ListenerType.java │ │ │ │ │ ├── SubmissionEvent.java │ │ │ │ │ └── SseEmitterApplicationEventListener.java │ │ │ │ ├── exception │ │ │ │ │ ├── DataAccessException.java │ │ │ │ │ ├── ListenerTypeNotFound.java │ │ │ │ │ ├── ResourceNotFoundException.java │ │ │ │ │ ├── BadRequestException.java │ │ │ │ │ ├── RequiredFieldMissingException.java │ │ │ │ │ ├── OldPasswordNotMatch.java │ │ │ │ │ ├── UnauthorizedAccessException.java │ │ │ │ │ ├── DuplicateEmailRegisteredException.java │ │ │ │ │ └── ServiceException.java │ │ │ │ ├── dao │ │ │ │ │ ├── SequenceDao.java │ │ │ │ │ ├── GenericDao.java │ │ │ │ │ └── impl │ │ │ │ │ │ ├── SequenceDaoImpl.java │ │ │ │ │ │ └── GenericDaoImpl.java │ │ │ │ ├── model │ │ │ │ │ ├── Sequence.java │ │ │ │ │ └── EntityBase.java │ │ │ │ ├── response │ │ │ │ │ └── CommonResponse.java │ │ │ │ └── service │ │ │ │ │ ├── GenericService.java │ │ │ │ │ └── impl │ │ │ │ │ └── GenericServiceImpl.java │ │ │ │ ├── config │ │ │ │ ├── AppConfiguration.java │ │ │ │ └── SetupRoom.java │ │ │ │ ├── dao │ │ │ │ ├── RoomDao.java │ │ │ │ ├── MeetingDao.java │ │ │ │ ├── StudentDao.java │ │ │ │ └── impl │ │ │ │ │ ├── RoomDaoImpl.java │ │ │ │ │ ├── MeetingDaoImpl.java │ │ │ │ │ └── StudentDaoImpl.java │ │ │ │ ├── service │ │ │ │ ├── RoomService.java │ │ │ │ ├── MeetingService.java │ │ │ │ ├── StudentService.java │ │ │ │ └── impl │ │ │ │ │ ├── RoomServiceImpl.java │ │ │ │ │ ├── StudentServiceImpl.java │ │ │ │ │ └── MeetingServiceImpl.java │ │ │ │ ├── model │ │ │ │ ├── Room.java │ │ │ │ ├── Meeting.java │ │ │ │ └── Student.java │ │ │ │ ├── App.java │ │ │ │ └── controller │ │ │ │ └── TemplateController.java │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── _logback.xml │ │ └── webapp │ │ │ └── WEB-INF │ │ │ └── jsp │ │ │ ├── list.jsp │ │ │ └── save.jsp │ └── test │ │ └── java │ │ └── com │ │ └── thk │ │ └── homeservice │ │ └── AppTest.java ├── target │ └── classes │ │ ├── application.yml │ │ └── _logback.xml ├── .project ├── .classpath └── pom.xml ├── .gitignore └── README.md /student-management-system/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/messages/InfoMessage.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.messages; 2 | 3 | public class InfoMessage { 4 | } 5 | -------------------------------------------------------------------------------- /student-management-system/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/config/AppConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | @Configuration 6 | public class AppConfiguration { 7 | } 8 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/dao/RoomDao.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.dao; 2 | 3 | import com.studentmgr.common.dao.GenericDao; 4 | import com.studentmgr.model.Room; 5 | 6 | public interface RoomDao extends GenericDao{ 7 | } 8 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/dao/MeetingDao.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.dao; 2 | 3 | import com.studentmgr.common.dao.GenericDao; 4 | import com.studentmgr.model.Meeting; 5 | 6 | public interface MeetingDao extends GenericDao{ 7 | } 8 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/dao/StudentDao.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.dao; 2 | 3 | import com.studentmgr.common.dao.GenericDao; 4 | import com.studentmgr.model.Student; 5 | 6 | public interface StudentDao extends GenericDao{ 7 | } 8 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/service/RoomService.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.service; 2 | 3 | import com.studentmgr.common.service.GenericService; 4 | import com.studentmgr.model.Room; 5 | 6 | public interface RoomService extends GenericService{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/service/MeetingService.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.service; 2 | 3 | import com.studentmgr.common.service.GenericService; 4 | import com.studentmgr.model.Meeting; 5 | 6 | public interface MeetingService extends GenericService{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.service; 2 | 3 | import com.studentmgr.common.service.GenericService; 4 | import com.studentmgr.model.Student; 5 | 6 | public interface StudentService extends GenericService{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /student-management-system/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/sse/ListenerType.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.sse; 2 | 3 | public enum ListenerType { 4 | 5 | USER, 6 | ITEM, 7 | ITEM_TYPES; 8 | 9 | public String prepareKey(String id){ 10 | return this.name() + "-" + id; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/model/Room.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.model; 2 | 3 | import org.springframework.data.mongodb.core.mapping.Document; 4 | 5 | import com.studentmgr.common.model.EntityBase; 6 | 7 | @Document(collection = "Room") 8 | public class Room extends EntityBase{ 9 | 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /student-management-system/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: student-management-system 5 | mvc: 6 | view: 7 | prefix: /WEB-INF/jsp/ 8 | suffix: .jsp 9 | 10 | # Mongo properties 11 | data: 12 | mongodb: 13 | host: localhost 14 | port: 27017 15 | database: std_mgr_db 16 | 17 | 18 | # HTTP Server 19 | server: 20 | port: 8080 # HTTP (Tomcat) port 21 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/DataAccessException.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | public class DataAccessException extends Exception{ 4 | 5 | private static final long serialVersionUID = -8983030260917870356L; 6 | 7 | public DataAccessException(Exception exception) { 8 | super(exception); 9 | } 10 | 11 | public DataAccessException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/ListenerTypeNotFound.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | import org.springframework.web.bind.annotation.ResponseStatus; 4 | 5 | @ResponseStatus(reason="ListenerType Not Found") //500 6 | public class ListenerTypeNotFound extends RuntimeException{ 7 | 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = -6747852635122018488L; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/dao/SequenceDao.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.dao; 2 | 3 | import com.studentmgr.common.exception.DataAccessException; 4 | import com.studentmgr.common.model.Sequence; 5 | 6 | public interface SequenceDao extends GenericDao{ 7 | 8 | Integer getNextSequenceId(String key) throws DataAccessException; 9 | Integer getNextSequenceId(String key, Integer start) throws DataAccessException; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /student-management-system/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring properties 2 | spring: 3 | application: 4 | name: student-management-system 5 | mvc: 6 | view: 7 | prefix: /WEB-INF/jsp/ 8 | suffix: .jsp 9 | 10 | # Mongo properties 11 | data: 12 | mongodb: 13 | host: @mongo.host@ 14 | port: @mongo.port@ 15 | database: @mongo.database@ 16 | 17 | 18 | # HTTP Server 19 | server: 20 | port: @http.port@ # HTTP (Tomcat) port 21 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/dao/impl/RoomDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.dao.impl; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | import com.studentmgr.common.dao.impl.GenericDaoImpl; 6 | import com.studentmgr.dao.RoomDao; 7 | import com.studentmgr.model.Room; 8 | 9 | @Repository 10 | public class RoomDaoImpl extends GenericDaoImpl implements RoomDao { 11 | 12 | public RoomDaoImpl() { 13 | super(Room.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/dao/impl/MeetingDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.dao.impl; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | import com.studentmgr.common.dao.impl.GenericDaoImpl; 6 | import com.studentmgr.dao.MeetingDao; 7 | import com.studentmgr.model.Meeting; 8 | 9 | @Repository 10 | public class MeetingDaoImpl extends GenericDaoImpl implements MeetingDao { 11 | 12 | public MeetingDaoImpl() { 13 | super(Meeting.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/dao/impl/StudentDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.dao.impl; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | import com.studentmgr.common.dao.impl.GenericDaoImpl; 6 | import com.studentmgr.dao.StudentDao; 7 | import com.studentmgr.model.Student; 8 | 9 | @Repository 10 | public class StudentDaoImpl extends GenericDaoImpl implements StudentDao { 11 | 12 | public StudentDaoImpl() { 13 | super(Student.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value=HttpStatus.NOT_FOUND) //404 7 | public class ResourceNotFoundException extends RuntimeException{ 8 | 9 | private static final long serialVersionUID = -2217466109027636423L; 10 | 11 | public ResourceNotFoundException() { 12 | } 13 | 14 | public ResourceNotFoundException(String message){ 15 | super(message); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/BadRequestException.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Bad Request") //400 7 | public class BadRequestException extends RuntimeException{ 8 | 9 | private static final long serialVersionUID = -6659322898478118584L; 10 | 11 | public BadRequestException() { 12 | } 13 | 14 | public BadRequestException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/RequiredFieldMissingException.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value=HttpStatus.BAD_REQUEST) //400 7 | public class RequiredFieldMissingException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = 3582955683863543348L; 10 | 11 | public RequiredFieldMissingException(Object... fields) { 12 | super(String.format("Required Field Missing [%s]", fields)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/model/Sequence.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | @Document(collection="Sequence") 7 | public class Sequence { 8 | 9 | @Id 10 | private String id; 11 | 12 | private int seq; 13 | 14 | public String getId() { 15 | return id; 16 | } 17 | 18 | public void setId(String id) { 19 | this.id = id; 20 | } 21 | 22 | public int getSeq() { 23 | return seq; 24 | } 25 | 26 | public void setSeq(int seq) { 27 | this.seq = seq; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/OldPasswordNotMatch.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Old Password Not Match") //400 7 | public class OldPasswordNotMatch extends RuntimeException{ 8 | 9 | private static final long serialVersionUID = -7106944187406637244L; 10 | 11 | public OldPasswordNotMatch() { 12 | } 13 | 14 | public OldPasswordNotMatch(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/UnauthorizedAccessException.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value=HttpStatus.UNAUTHORIZED) //400 7 | public class UnauthorizedAccessException extends RuntimeException{ 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = -878810853364598782L; 13 | 14 | public UnauthorizedAccessException() { 15 | } 16 | 17 | public UnauthorizedAccessException(String message) { 18 | super(message); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/response/CommonResponse.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.response; 2 | 3 | public class CommonResponse { 4 | 5 | private int status; 6 | private Object message; 7 | 8 | public CommonResponse(int status, Object message) { 9 | this.status = status; 10 | this.message = message; 11 | } 12 | public int getStatus() { 13 | return status; 14 | } 15 | public void setStatus(int status) { 16 | this.status = status; 17 | } 18 | public Object getMessage() { 19 | return message; 20 | } 21 | public void setMessage(Object message) { 22 | this.message = message; 23 | } 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/service/GenericService.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.service; 2 | 3 | import java.util.List; 4 | 5 | import com.studentmgr.common.exception.DataAccessException; 6 | import com.studentmgr.common.exception.ServiceException; 7 | 8 | public interface GenericService{ 9 | 10 | T getById(Object id) throws ServiceException; 11 | 12 | T add(T obj) throws ServiceException; 13 | 14 | T edit(T obj) throws ServiceException; 15 | 16 | boolean delete(T object) throws ServiceException; 17 | 18 | List getAll() throws ServiceException; 19 | 20 | ServiceException translateException(DataAccessException de); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/sse/SubmissionEvent.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.sse; 2 | 3 | public class SubmissionEvent { 4 | 5 | private String key; 6 | private Object message; 7 | 8 | public SubmissionEvent(ListenerType type , String id, Object message) { 9 | this.key = type.prepareKey(id); 10 | this.message = message; 11 | } 12 | public String getKey() { 13 | return key; 14 | } 15 | public void setKey(String key) { 16 | this.key = key; 17 | } 18 | public Object getMessage() { 19 | return message; 20 | } 21 | public void setMessage(Object message) { 22 | this.message = message; 23 | } 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/DuplicateEmailRegisteredException.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value=HttpStatus.FORBIDDEN, reason="Duplicate Email Registered") //403 7 | public class DuplicateEmailRegisteredException extends RuntimeException{ 8 | 9 | private static final long serialVersionUID = 4333940983178070455L; 10 | 11 | public DuplicateEmailRegisteredException() { 12 | } 13 | 14 | public DuplicateEmailRegisteredException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/exception/ServiceException.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.exception; 2 | 3 | public class ServiceException extends Exception { 4 | 5 | private static final long serialVersionUID = -7796502366163043439L; 6 | 7 | public static final String SERVICE_FAILED = "SERVICE_FAILED"; 8 | public static final String DATA_ACCESS_FAILED = "DATA_ACCESS_FAILED"; 9 | 10 | public ServiceException(Exception exception) { 11 | super(exception); 12 | } 13 | 14 | public ServiceException(String message, Exception exception) { 15 | super(message, exception); 16 | } 17 | 18 | public ServiceException(String message) { 19 | super(message); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-Spring-boot-Student-Management-System 2 | 3 | Command-line Instructions 4 | 5 | Prerequisites: 6 | 7 | • Install the latest version of Java and Maven. 8 | 9 | 10 | Eclipse Instructions 11 | 12 | Prerequisites: 13 | 14 | • Install Eclipse, the Maven plugin, and optionally the GitHub plugin. 15 | • Set up Eclipse Preferences 16 | 17 | • Window > Preferences... (or on Mac, Eclipse > Preferences...) 18 | 19 | Select Maven 20 | 21 | • check on "Download Artifact Sources" 22 | • check on "Download Artifact JavaDoc" 23 | 24 | 25 | 26 | Run 27 | 28 | • Right-click on project 29 | • Run As > Java Application 30 | • If asked, type "student-management-system" and click OK 31 | 32 | Database 33 | • MongoDB 34 | 35 | 36 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/App.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.support.SpringBootServletInitializer; 7 | 8 | @SpringBootApplication 9 | public class App extends SpringBootServletInitializer{ 10 | 11 | @Override 12 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 13 | return application.sources(App.class); 14 | } 15 | 16 | public static void main( String[] args ) 17 | { 18 | SpringApplication.run(App.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/service/impl/RoomServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.service.impl; 2 | 3 | import javax.annotation.PostConstruct; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.studentmgr.common.service.impl.GenericServiceImpl; 9 | import com.studentmgr.dao.RoomDao; 10 | import com.studentmgr.model.Room; 11 | import com.studentmgr.service.RoomService; 12 | 13 | @Service 14 | public class RoomServiceImpl extends GenericServiceImpl implements RoomService{ 15 | 16 | @Autowired 17 | protected RoomDao roomDao; 18 | 19 | @PostConstruct 20 | void init() { 21 | init(Room.class, roomDao); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/service/impl/StudentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.service.impl; 2 | 3 | import javax.annotation.PostConstruct; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.studentmgr.common.service.impl.GenericServiceImpl; 8 | import com.studentmgr.dao.StudentDao; 9 | import com.studentmgr.model.Student; 10 | import com.studentmgr.service.StudentService; 11 | 12 | @Service 13 | public class StudentServiceImpl extends GenericServiceImpl implements StudentService{ 14 | 15 | @Autowired 16 | protected StudentDao studentDao; 17 | 18 | @PostConstruct 19 | void init() { 20 | init(Student.class, studentDao); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/service/impl/MeetingServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.service.impl; 2 | 3 | import javax.annotation.PostConstruct; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.studentmgr.common.service.impl.GenericServiceImpl; 9 | import com.studentmgr.dao.MeetingDao; 10 | import com.studentmgr.model.Meeting; 11 | import com.studentmgr.service.MeetingService; 12 | 13 | @Service 14 | public class MeetingServiceImpl extends GenericServiceImpl implements MeetingService{ 15 | 16 | @Autowired 17 | protected MeetingDao meetingDao; 18 | 19 | @PostConstruct 20 | void init() { 21 | init(Meeting.class, meetingDao); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /student-management-system/src/test/java/com/thk/homeservice/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.thk.homeservice; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /student-management-system/target/classes/_logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %d{HH:mm:ss} [%level] [%logger{36}] %msg%n 11 | 12 | 13 | 14 | 15 | ${LOG_FILE} 16 | 17 | %d{HH:mm:ss} [%level] [%logger{36}] %msg%n 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /student-management-system/src/main/resources/_logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %d{HH:mm:ss} [%level] [%logger{36}] %msg%n 11 | 12 | 13 | 14 | 15 | ${LOG_FILE} 16 | 17 | %d{HH:mm:ss} [%level] [%logger{36}] %msg%n 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/messages/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.messages; 2 | 3 | public class ErrorMessage { 4 | public static final String USER_OBJECT_IS_NULL = "USER_OBJECT_IS_NULL"; 5 | public static final String ITEM_OBJECT_IS_NULL = "ITEM_OBJECT_IS_NULL"; 6 | public static final String USER_UNABLE_TO_LOAD_TOKEN = "USER_UNABLE_TO_LOAD_TOKEN"; 7 | public static final String USER_NOT_FOUND = "USER_NOT_FOUND"; 8 | public static final String ITEM_NOT_FOUND = "ITEM_NOT_FOUND"; 9 | public static final String EMPTY_USER_ID = "EMPTY_USER_ID"; 10 | public static final String DUPLICATE_USER = "DUPLICATE_USER"; 11 | public static final String UNABLE_TO_ADD_ITEM_INTO_ITEMTYPE = "UNABLE_TO_ADD_ITEM_INTO_ITEMTYPE"; 12 | public static final String MESSAGE_OBJECT_IS_NULL = "MESSAGE_OBJECT_IS_NULL"; 13 | public static final String RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND"; 14 | } 15 | -------------------------------------------------------------------------------- /student-management-system/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | student-management-system 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/model/Meeting.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.model; 2 | 3 | import org.springframework.data.mongodb.core.mapping.DBRef; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | import com.studentmgr.common.model.EntityBase; 7 | 8 | @Document(collection = "Meeting") 9 | public class Meeting extends EntityBase{ 10 | 11 | private String title; 12 | 13 | private String date; 14 | 15 | @DBRef 16 | private Room room; 17 | 18 | public String getTitle() { 19 | return title; 20 | } 21 | 22 | public void setTitle(String title) { 23 | this.title = title; 24 | } 25 | 26 | public String getDate() { 27 | return date; 28 | } 29 | 30 | public void setDate(String date) { 31 | this.date = date; 32 | } 33 | 34 | public Room getRoom() { 35 | return room; 36 | } 37 | 38 | public void setRoom(Room room) { 39 | this.room = room; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/config/SetupRoom.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import com.studentmgr.common.exception.ServiceException; 7 | import com.studentmgr.model.Room; 8 | import com.studentmgr.service.RoomService; 9 | 10 | @Component 11 | public class SetupRoom { 12 | 13 | @Autowired 14 | public SetupRoom(RoomService roomService) { 15 | 16 | Room r1 = new Room(); 17 | r1.setId("r1"); 18 | 19 | Room r2 = new Room(); 20 | r2.setId("r2"); 21 | 22 | Room r3 = new Room(); 23 | r3.setId("r3"); 24 | 25 | Room r4 = new Room(); 26 | r4.setId("r4"); 27 | 28 | try { 29 | roomService.add(r1); 30 | roomService.add(r2); 31 | roomService.add(r3); 32 | roomService.add(r4); 33 | } catch (ServiceException e) { 34 | e.printStackTrace(); 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/sse/SseEmitterApplicationEventListener.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.sse; 2 | 3 | import java.io.IOException; 4 | import java.util.Hashtable; 5 | import java.util.Map; 6 | import org.springframework.context.event.EventListener; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; 10 | 11 | @Component 12 | public class SseEmitterApplicationEventListener { 13 | 14 | @EventListener 15 | public void submissionEventHandler(SubmissionEvent event) throws IOException { 16 | 17 | String key = event.getKey(); 18 | Object message = event.getMessage(); 19 | 20 | SseEmitter sseEmitter = sseEmitters.get(key); 21 | 22 | if ( sseEmitter == null ) { 23 | return; 24 | } 25 | 26 | sseEmitter.send(message, MediaType.APPLICATION_JSON); 27 | } 28 | 29 | public void addSseEmitters(ListenerType listenerType ,String id, SseEmitter sseEmitter) { 30 | sseEmitters.put(listenerType.prepareKey(id), sseEmitter); 31 | } 32 | 33 | private static Map sseEmitters = new Hashtable<>(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /student-management-system/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.model; 2 | 3 | import org.springframework.data.mongodb.core.mapping.Document; 4 | 5 | import com.studentmgr.common.model.EntityBase; 6 | 7 | @Document(collection = "Student") 8 | public class Student extends EntityBase { 9 | 10 | public static final String GENDER_MALE = "male"; 11 | public static final String GENDER_FEMALE = "female"; 12 | 13 | private String name; 14 | 15 | private int sid; 16 | 17 | private String gender; 18 | 19 | private String address; 20 | 21 | private String contactNo; 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public int getSid() { 32 | return sid; 33 | } 34 | 35 | public void setSid(int sid) { 36 | this.sid = sid; 37 | } 38 | 39 | public String getGender() { 40 | return gender; 41 | } 42 | 43 | public void setGender(String gender) { 44 | this.gender = gender; 45 | } 46 | 47 | public String getAddress() { 48 | return address; 49 | } 50 | 51 | public void setAddress(String address) { 52 | this.address = address; 53 | } 54 | 55 | public String getContactNo() { 56 | return contactNo; 57 | } 58 | 59 | public void setContactNo(String contactNo) { 60 | this.contactNo = contactNo; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/model/EntityBase.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | public abstract class EntityBase{ 6 | 7 | public static final Integer STATUS_DELETED = -999; 8 | 9 | @Id 10 | private String id; 11 | 12 | protected Integer status; 13 | 14 | public String getId() { 15 | return id; 16 | } 17 | 18 | public void setId(String id) { 19 | this.id = id; 20 | } 21 | 22 | public Integer getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(Integer status) { 27 | this.status = status; 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | final int prime = 31; 33 | int result = 1; 34 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 35 | return result; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | if (this == obj) 41 | return true; 42 | if (obj == null) 43 | return false; 44 | if (getClass() != obj.getClass()) 45 | return false; 46 | EntityBase other = (EntityBase) obj; 47 | if (id == null) { 48 | if (other.id != null) 49 | return false; 50 | } else if (!id.equals(other.id)) 51 | return false; 52 | return true; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "EntityBase{" + 58 | "id=" + id + 59 | '}'; 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/dao/GenericDao.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.dao; 2 | 3 | import java.util.List; 4 | import org.springframework.data.mongodb.core.MongoOperations; 5 | 6 | import com.studentmgr.common.exception.DataAccessException; 7 | 8 | public interface GenericDao { 9 | /** 10 | * This method delete given object from the database. 11 | * 12 | * @param id 13 | * - Object id to load 14 | * @throws DataAccessException 15 | * - throws if an error occurs 16 | */ 17 | T getById(Object id) throws DataAccessException; 18 | 19 | /** 20 | * This method delete given objects from the database. 21 | * 22 | * @param id 23 | * @return 24 | * @throws DataAccessException 25 | */ 26 | List getAllById(Object id) throws DataAccessException; 27 | 28 | /** 29 | * This method queries all the objects 30 | * 31 | * @throws DataAccessException 32 | * - throws if an error occurs 33 | */ 34 | List getAll() throws DataAccessException; 35 | 36 | /** 37 | * This method delete given object from the database. 38 | * 39 | * @param object 40 | * - instance of Object class 41 | * @throws DataAccessException 42 | * - throws if an error occurs 43 | */ 44 | void delete(T object) throws DataAccessException; 45 | 46 | /** 47 | * This method insert a given object to the database. 48 | * 49 | * @param object 50 | * - instance of Object class 51 | * @throws DataAccessException 52 | * - throws if an error occurs 53 | */ 54 | void add(T object) throws DataAccessException; 55 | 56 | /** 57 | * This method update given object in the database. 58 | * 59 | * @param object 60 | * - instance of Object class 61 | * @throws DataAccessException 62 | * - throws if an error occurs 63 | */ 64 | void modify(T object) throws DataAccessException; 65 | 66 | MongoOperations getMongoOperations(); 67 | 68 | } 69 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/service/impl/GenericServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import com.studentmgr.common.dao.GenericDao; 6 | import com.studentmgr.common.exception.DataAccessException; 7 | import com.studentmgr.common.exception.ServiceException; 8 | import com.studentmgr.common.service.GenericService; 9 | 10 | public class GenericServiceImpl implements GenericService { 11 | 12 | @SuppressWarnings("unused") 13 | private Class type; 14 | protected GenericDao genericDao; 15 | 16 | protected void init(Class type, GenericDao dao) { 17 | this.type = type; 18 | this.genericDao = dao; 19 | } 20 | 21 | @Override 22 | public T getById(Object id) throws ServiceException{ 23 | try{ 24 | return genericDao.getById(id); 25 | }catch(DataAccessException de){ 26 | throw translateException(de); 27 | } 28 | } 29 | 30 | @Override 31 | public List getAll() throws ServiceException{ 32 | try{ 33 | return genericDao.getAll(); 34 | }catch(DataAccessException de){ 35 | throw translateException(de); 36 | } 37 | } 38 | 39 | @Override 40 | public T add(T obj) throws ServiceException{ 41 | try{ 42 | genericDao.add(obj); 43 | return obj; 44 | }catch(DataAccessException de){ 45 | throw translateException(de); 46 | } 47 | } 48 | 49 | @Override 50 | public T edit(T obj) throws ServiceException{ 51 | try{ 52 | genericDao.modify(obj); 53 | return obj; 54 | }catch(DataAccessException de){ 55 | throw translateException(de); 56 | } 57 | } 58 | 59 | @Override 60 | public boolean delete(T object) throws ServiceException{ 61 | try{ 62 | genericDao.delete(object); 63 | return true; 64 | }catch(DataAccessException de){ 65 | throw translateException(de); 66 | } 67 | } 68 | 69 | @Override 70 | public ServiceException translateException(DataAccessException de) { 71 | return new ServiceException(de); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/dao/impl/SequenceDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.dao.impl; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.data.mongodb.core.FindAndModifyOptions; 6 | import org.springframework.data.mongodb.core.query.Criteria; 7 | import org.springframework.data.mongodb.core.query.Query; 8 | import org.springframework.data.mongodb.core.query.Update; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.studentmgr.common.dao.SequenceDao; 12 | import com.studentmgr.common.exception.DataAccessException; 13 | import com.studentmgr.common.model.Sequence; 14 | 15 | @Repository 16 | public class SequenceDaoImpl extends GenericDaoImplimplements SequenceDao { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(SequenceDaoImpl.class); 19 | 20 | public SequenceDaoImpl() { 21 | super(Sequence.class); 22 | } 23 | 24 | @Override 25 | public Integer getNextSequenceId(String key) throws DataAccessException { 26 | return getNextSequenceId(key, 1); 27 | } 28 | 29 | @Override 30 | public Integer getNextSequenceId(String key, Integer start) throws DataAccessException { 31 | 32 | if (logger.isDebugEnabled()) 33 | logger.debug("getNextSequenceId {}", key); 34 | 35 | try { 36 | // get sequence id 37 | Query query = new Query(Criteria.where("id").is(key)); 38 | 39 | // increase sequence id by 1 40 | Update update = new Update(); 41 | update.inc("seq", 1); 42 | 43 | // return new increased id 44 | FindAndModifyOptions options = new FindAndModifyOptions(); 45 | options.returnNew(true); 46 | 47 | // this is the magic happened. 48 | Sequence seqId = mongoOperations.findAndModify(query, update, options, Sequence.class); 49 | 50 | // if no id, throws SequenceException 51 | // optional, just a way to tell user when the sequence id is failed 52 | // to 53 | // generate. 54 | if (seqId == null) { 55 | seqId = new Sequence(); 56 | seqId.setId(key); 57 | seqId.setSeq(start); 58 | mongoOperations.insert(seqId); 59 | return start; 60 | } else { 61 | return seqId.getSeq(); 62 | } 63 | 64 | } catch (Exception e) { 65 | throw new DataAccessException(e); 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /student-management-system/src/main/webapp/WEB-INF/jsp/list.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 23 | 24 |
25 | 26 |
27 |

Students

28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 65 | 66 | 67 | 68 | 69 |
NameSidGenderAddressContact NoAction
${student.name}${student.sid}${student.gender}${student.address}${student.contactNo} 52 |
53 | 59 |
60 | 61 | 62 |
63 |
64 |
70 |
71 |
72 | 73 |
74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/controller/TemplateController.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.controller; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.ui.Model; 12 | import org.springframework.util.StringUtils; 13 | import org.springframework.web.bind.annotation.ModelAttribute; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestMethod; 16 | import org.springframework.web.bind.annotation.RequestParam; 17 | 18 | import com.studentmgr.common.exception.ServiceException; 19 | import com.studentmgr.model.Student; 20 | import com.studentmgr.service.StudentService; 21 | 22 | @Controller 23 | public class TemplateController { 24 | 25 | private static final Logger LOG = LoggerFactory.getLogger(TemplateController.class); 26 | 27 | @Autowired 28 | private StudentService studentService; 29 | 30 | @RequestMapping("/") 31 | public String listPage(Model model){ 32 | 33 | List students = new ArrayList<>(); 34 | try{ 35 | students = studentService.getAll(); 36 | }catch(Exception e){ 37 | LOG.error(e.getMessage()); 38 | } 39 | 40 | model.addAttribute("students", students); 41 | 42 | return "list"; 43 | } 44 | 45 | @RequestMapping("/save") 46 | public String savePage(@RequestParam(value="q", required=false) String id, Model model) throws ServiceException{ 47 | 48 | Student student = null; 49 | if(!StringUtils.isEmpty(id)) 50 | student = studentService.getById(id); 51 | 52 | model.addAttribute("genderList", Arrays.asList(Student.GENDER_MALE, Student.GENDER_FEMALE)); 53 | model.addAttribute("student", student); 54 | return "save"; 55 | } 56 | 57 | @RequestMapping(value="/save", method=RequestMethod.POST) 58 | public String saveBooking(@ModelAttribute Student student) throws ServiceException{ 59 | 60 | if(StringUtils.isEmpty(student.getId())){ 61 | student.setId(null); 62 | studentService.add(student); 63 | } 64 | else 65 | studentService.edit(student); 66 | 67 | return "redirect:/"; 68 | } 69 | 70 | @RequestMapping("/delete") 71 | public String deleteBooking(@ModelAttribute Student student) throws ServiceException{ 72 | studentService.delete(student); 73 | return "redirect:/"; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /student-management-system/src/main/webapp/WEB-INF/jsp/save.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 23 | 24 |
25 | 26 |
27 |

New Student

28 |
29 | 30 | 31 | 32 |
33 | Name 34 | 42 |
43 | 44 |
45 | Sid 46 | 54 |
55 | 56 |
57 | Gender 58 | 69 |
70 | 71 |
72 | Address 73 | 82 |
83 | 84 |
85 | Contact No 86 | 94 |
95 | 96 | 97 | 98 |
99 |
100 | 101 |
102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /student-management-system/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.studentmgr 6 | student-management-system 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | student-management-system 11 | http://maven.apache.org 12 | 13 | 14 | 15 | 1.8 16 | 17 | 18 | 8080 19 | localhost 20 | 27017 21 | std_mgr_db 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-parent 30 | 1.5.2.RELEASE 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-web 39 | 40 | 41 | 42 | 43 | org.springframework.data 44 | spring-data-mongodb 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-tomcat 51 | provided 52 | 53 | 54 | 55 | javax.servlet 56 | jstl 57 | 58 | 59 | 60 | org.apache.tomcat.embed 61 | tomcat-embed-jasper 62 | provided 63 | 64 | 65 | 66 | org.eclipse.jdt.core.compiler 67 | ecj 68 | 4.6.1 69 | provided 70 | 71 | 72 | 73 | org.webjars 74 | bootstrap 75 | 3.3.7 76 | 77 | 78 | 79 | 80 | org.springframework.boot 81 | spring-boot-devtools 82 | true 83 | 84 | 85 | 86 | 87 | ch.qos.logback 88 | logback-classic 89 | 90 | 91 | 92 | ch.qos.logback 93 | logback-core 94 | 95 | 96 | 97 | 98 | 99 | org.springframework.boot 100 | spring-boot-starter-test 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | org.springframework.boot 110 | spring-boot-maven-plugin 111 | 112 | 113 | 114 | repackage 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /student-management-system/src/main/java/com/studentmgr/common/dao/impl/GenericDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.studentmgr.common.dao.impl; 2 | 3 | import java.util.List; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.cache.annotation.CacheConfig; 8 | import org.springframework.cache.annotation.CacheEvict; 9 | import org.springframework.cache.annotation.Cacheable; 10 | import org.springframework.cache.annotation.Caching; 11 | import org.springframework.data.mongodb.core.MongoOperations; 12 | import org.springframework.data.mongodb.core.query.Criteria; 13 | import org.springframework.data.mongodb.core.query.Query; 14 | 15 | import com.studentmgr.common.dao.GenericDao; 16 | import com.studentmgr.common.exception.DataAccessException; 17 | 18 | @CacheConfig(cacheResolver="dynamicCacheResolver") 19 | public class GenericDaoImpl implements GenericDao { 20 | 21 | private static final Logger logger = LoggerFactory.getLogger(GenericDaoImpl.class); 22 | 23 | @Autowired 24 | protected MongoOperations mongoOperations; 25 | 26 | private Class type; 27 | 28 | public GenericDaoImpl(Class type) { 29 | this.type = type; 30 | } 31 | 32 | @Override 33 | @Caching(evict = { 34 | @CacheEvict(cacheResolver="dynamicCacheResolver", allEntries = true) 35 | } 36 | ) 37 | public void add(T object) throws DataAccessException { 38 | if (logger.isDebugEnabled()) 39 | logger.debug("type {} add", type); 40 | try { 41 | mongoOperations.insert(object); 42 | } catch (Exception e) { 43 | throw new DataAccessException(e); 44 | } 45 | } 46 | 47 | @Override 48 | @Caching(evict = { 49 | @CacheEvict(cacheResolver="dynamicCacheResolver", allEntries = true), 50 | @CacheEvict(cacheResolver="dynamicCacheResolver", key="#object.id") 51 | } 52 | ) 53 | public void modify(T object) throws DataAccessException { 54 | if (logger.isDebugEnabled()) 55 | logger.debug("type {} modify", type); 56 | try { 57 | mongoOperations.save(object); 58 | } catch (Exception e) { 59 | throw new DataAccessException(e); 60 | } 61 | } 62 | 63 | @Override 64 | @Cacheable(key="#id") 65 | public T getById(Object id) throws DataAccessException { 66 | if (logger.isDebugEnabled()) 67 | logger.debug("type {} getById", type); 68 | try{ 69 | return mongoOperations.findById(id, type); 70 | }catch(Exception e){ 71 | throw new DataAccessException(e); 72 | } 73 | } 74 | 75 | @Override 76 | @Cacheable(key="#id") 77 | public List getAllById(Object id) throws DataAccessException { 78 | if (logger.isDebugEnabled()) 79 | logger.debug("type {} getById", type); 80 | try{ 81 | return mongoOperations.find(new Query(Criteria.where("id").is(id)), type); 82 | }catch(Exception e){ 83 | throw new DataAccessException(e); 84 | } 85 | } 86 | 87 | @Override 88 | @Cacheable 89 | public List getAll() throws DataAccessException { 90 | if (logger.isDebugEnabled()) 91 | logger.debug("type {} getAll", type); 92 | 93 | try { 94 | return mongoOperations.findAll(type); 95 | } catch (Exception e) { 96 | throw new DataAccessException(e); 97 | } 98 | } 99 | 100 | @Override 101 | public void delete(T object) throws DataAccessException { 102 | if (logger.isDebugEnabled()) 103 | logger.debug("type {} delete", type); 104 | try { 105 | mongoOperations.remove(object); 106 | } catch (Exception e) { 107 | throw new DataAccessException(e); 108 | } 109 | 110 | } 111 | 112 | @Override 113 | public MongoOperations getMongoOperations() { 114 | return mongoOperations; 115 | } 116 | } 117 | --------------------------------------------------------------------------------