diff --git a/config_server/src/main/resources/application.properties b/config_server/src/main/resources/application.properties index 3ca6e45..953d9a5 100644 --- a/config_server/src/main/resources/application.properties +++ b/config_server/src/main/resources/application.properties @@ -2,7 +2,7 @@ server.port=8888 spring.cloud.config.server.git.uri=https://github.com/esensar/steleks_config spring.cloud.config.server.git.clone-on-start=true security.user.name=root -security.user.password=skorpion +security.user.password=root encrypt.key-store.location=classpath:config-server.jks encrypt.key-store.password=my-s70r3-s3cr3t encrypt.key-store.alias=config-server-key diff --git a/events/src/main/java/ba/steleks/EventController.java b/events/src/main/java/ba/steleks/controller/EventController.java similarity index 80% rename from events/src/main/java/ba/steleks/EventController.java rename to events/src/main/java/ba/steleks/controller/EventController.java index e688329..c26a877 100644 --- a/events/src/main/java/ba/steleks/EventController.java +++ b/events/src/main/java/ba/steleks/controller/EventController.java @@ -1,11 +1,11 @@ -package ba.steleks; +package ba.steleks.controller; +import ba.steleks.error.exception.ExternalServiceException; import ba.steleks.repository.EventsJpaRepository; -import ba.steleks.repository.model.Event; +import ba.steleks.model.Event; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.data.rest.webmvc.RepositoryRestController; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; @@ -15,9 +15,7 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; -import javax.xml.ws.http.HTTPException; import java.net.URI; -import java.util.HashMap; /** * Created by admin on 01/04/2017. @@ -37,7 +35,7 @@ public class EventController { } @RequestMapping(path = "/events", method = RequestMethod.POST) - public ResponseEntity add(@RequestBody Event event) { + public ResponseEntity add(@RequestBody Event event) throws ExternalServiceException { String oviUseriNeki = "http://localhost:8090/users/{id}"; try { @@ -50,9 +48,9 @@ public class EventController { return ResponseEntity.created(location).body(result); } catch (Exception ex) { if (ex instanceof HttpClientErrorException && ((HttpClientErrorException) ex).getStatusCode() == HttpStatus.NOT_FOUND) { - return ResponseEntity.badRequest().body(HttpStatus.BAD_REQUEST); + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST); } else { - return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).body("Users service is dead! It's dead! There is no hope. It's all gone!"); + throw new ExternalServiceException(); } } } diff --git a/events/src/main/java/ba/steleks/controller/MediaController.java b/events/src/main/java/ba/steleks/controller/MediaController.java new file mode 100644 index 0000000..9ed1308 --- /dev/null +++ b/events/src/main/java/ba/steleks/controller/MediaController.java @@ -0,0 +1,54 @@ +package ba.steleks.controller;/** + * Created by ensar on 02/04/17. + */ + +import ba.steleks.error.exception.ExternalServiceException; +import ba.steleks.model.Event; +import ba.steleks.model.Media; +import ba.steleks.repository.MediaJpaRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.data.rest.webmvc.RepositoryRestController; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import java.net.URI; + +@RepositoryRestController +public class MediaController { + + private MediaJpaRepository repository; + private RestTemplate restTemplate; + + @Autowired + public MediaController(RestTemplateBuilder restTemplateBuilder, MediaJpaRepository repository) { + this.repository = repository; + this.restTemplate = restTemplateBuilder.build(); + } + + @RequestMapping(path = "/medias", method = RequestMethod.POST) + public ResponseEntity add(@RequestBody Media media) throws ExternalServiceException { + + String oviUseriNeki = "http://localhost:8090/users/{id}"; + try { + String response = restTemplate.getForObject(oviUseriNeki, String.class, media.getCreatedById()); + Media result = repository.save(media); + URI location = ServletUriComponentsBuilder + .fromCurrentRequest().path("/{id}") + .buildAndExpand(result.getId()).toUri(); + return ResponseEntity.created(location).body(result); + } catch (Exception ex) { + if (ex instanceof HttpClientErrorException && ((HttpClientErrorException) ex).getStatusCode() == HttpStatus.NOT_FOUND) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST); + } else { + throw new ExternalServiceException(); + } + } + } +} diff --git a/events/src/main/java/ba/steleks/error/RestErrorHandler.java b/events/src/main/java/ba/steleks/error/RestErrorHandler.java new file mode 100644 index 0000000..ff4c989 --- /dev/null +++ b/events/src/main/java/ba/steleks/error/RestErrorHandler.java @@ -0,0 +1,59 @@ +package ba.steleks.error; + +import ba.steleks.error.exception.ExternalServiceException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.client.HttpStatusCodeException; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by admin on 01/04/2017. + */ +@ControllerAdvice +public class RestErrorHandler { + + @ExceptionHandler(javax.validation.ConstraintViolationException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ResponseBody + public Map handleCustomException(javax.validation.ConstraintViolationException ex) { + + Map map= new HashMap(); + map.put("status", HttpStatus.BAD_REQUEST.toString()); + map.put("error", ex.getLocalizedMessage()); + + return map; + + } + + @ExceptionHandler(ExternalServiceException.class) + @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) + @ResponseBody + public Map handleExternalServiceException(ExternalServiceException ex) { + + Map map= new HashMap(); + map.put("status", HttpStatus.SERVICE_UNAVAILABLE.toString()); + map.put("error", HttpStatus.SERVICE_UNAVAILABLE.getReasonPhrase()); + + return map; + + } + + @ExceptionHandler(HttpStatusCodeException.class) + @ResponseBody + public ResponseEntity> handleAllExceptions(HttpStatusCodeException ex) { + Map map= new HashMap(); + map.put("status", ex.getStatusCode().toString()); + map.put("error", ex.getStatusCode().getReasonPhrase()); + + return ResponseEntity.status(ex.getStatusCode()).body(map); + + } + +} diff --git a/events/src/main/java/ba/steleks/error/exception/ExternalServiceException.java b/events/src/main/java/ba/steleks/error/exception/ExternalServiceException.java new file mode 100644 index 0000000..b80c1d2 --- /dev/null +++ b/events/src/main/java/ba/steleks/error/exception/ExternalServiceException.java @@ -0,0 +1,8 @@ +package ba.steleks.error.exception;/** + * Created by ensar on 02/04/17. + */ + +import javax.naming.ServiceUnavailableException; + +public class ExternalServiceException extends ServiceUnavailableException { +} diff --git a/events/src/main/java/ba/steleks/repository/model/Event.java b/events/src/main/java/ba/steleks/model/Event.java similarity index 98% rename from events/src/main/java/ba/steleks/repository/model/Event.java rename to events/src/main/java/ba/steleks/model/Event.java index d1d3fc8..356541a 100644 --- a/events/src/main/java/ba/steleks/repository/model/Event.java +++ b/events/src/main/java/ba/steleks/model/Event.java @@ -1,4 +1,4 @@ -package ba.steleks.repository.model; +package ba.steleks.model; import javax.persistence.*; import java.sql.Timestamp; diff --git a/events/src/main/java/ba/steleks/repository/model/EventType.java b/events/src/main/java/ba/steleks/model/EventType.java similarity index 95% rename from events/src/main/java/ba/steleks/repository/model/EventType.java rename to events/src/main/java/ba/steleks/model/EventType.java index ce1786a..55a1320 100644 --- a/events/src/main/java/ba/steleks/repository/model/EventType.java +++ b/events/src/main/java/ba/steleks/model/EventType.java @@ -1,4 +1,4 @@ -package ba.steleks.repository.model; +package ba.steleks.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/events/src/main/java/ba/steleks/repository/model/Media.java b/events/src/main/java/ba/steleks/model/Media.java similarity index 64% rename from events/src/main/java/ba/steleks/repository/model/Media.java rename to events/src/main/java/ba/steleks/model/Media.java index 175802c..e114e09 100644 --- a/events/src/main/java/ba/steleks/repository/model/Media.java +++ b/events/src/main/java/ba/steleks/model/Media.java @@ -1,10 +1,8 @@ -package ba.steleks.repository.model; +package ba.steleks.model; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import java.sql.Date; +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Date; /** * Created by admin on 23/03/2017. @@ -18,7 +16,8 @@ public class Media { private long id; private String contentUrl; - private Date creationDate; + @Column(updatable = false, insertable = false) + private Timestamp creationDate; private long createdById; public Media() { @@ -40,11 +39,11 @@ public class Media { this.contentUrl = contentUrl; } - public Date getCreationDate() { + public Timestamp getCreationDate() { return creationDate; } - public void setCreationDate(Date creationDate) { + public void setCreationDate(Timestamp creationDate) { this.creationDate = creationDate; } @@ -55,4 +54,10 @@ public class Media { public void setCreatedById(long createdById) { this.createdById = createdById; } + + @PrePersist + @PreUpdate + protected void onCreate() { + this.creationDate = new Timestamp(new Date().getTime()); + } } diff --git a/events/src/main/java/ba/steleks/repository/EventTypeJpaRepository.java b/events/src/main/java/ba/steleks/repository/EventTypeJpaRepository.java index 023aeb1..832223d 100644 --- a/events/src/main/java/ba/steleks/repository/EventTypeJpaRepository.java +++ b/events/src/main/java/ba/steleks/repository/EventTypeJpaRepository.java @@ -1,6 +1,6 @@ package ba.steleks.repository; -import ba.steleks.repository.model.EventType; +import ba.steleks.model.EventType; import org.springframework.data.repository.PagingAndSortingRepository; /** diff --git a/events/src/main/java/ba/steleks/repository/EventsJpaRepository.java b/events/src/main/java/ba/steleks/repository/EventsJpaRepository.java index e6a1ad6..da2f3e5 100644 --- a/events/src/main/java/ba/steleks/repository/EventsJpaRepository.java +++ b/events/src/main/java/ba/steleks/repository/EventsJpaRepository.java @@ -3,11 +3,9 @@ */ package ba.steleks.repository; -import ba.steleks.repository.model.Event; +import ba.steleks.model.Event; import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - public interface EventsJpaRepository extends PagingAndSortingRepository { } diff --git a/events/src/main/java/ba/steleks/repository/MediaJpaRepository.java b/events/src/main/java/ba/steleks/repository/MediaJpaRepository.java index b28a028..0202b4d 100644 --- a/events/src/main/java/ba/steleks/repository/MediaJpaRepository.java +++ b/events/src/main/java/ba/steleks/repository/MediaJpaRepository.java @@ -1,6 +1,6 @@ package ba.steleks.repository; -import ba.steleks.repository.model.Media; +import ba.steleks.model.Media; import org.springframework.data.repository.PagingAndSortingRepository; /** diff --git a/events/src/main/java/ba/steleks/repository/config-client-development.properties b/events/src/main/java/ba/steleks/repository/config-client-development.properties deleted file mode 100644 index e83e8c0..0000000 --- a/events/src/main/java/ba/steleks/repository/config-client-development.properties +++ /dev/null @@ -1 +0,0 @@ -user.password={"description":"No key was installed for encryption service","status":"NO_KEY"} diff --git a/events/src/main/resources/application.properties b/events/src/main/resources/application.properties index bfe3465..6693c6c 100644 --- a/events/src/main/resources/application.properties +++ b/events/src/main/resources/application.properties @@ -1,7 +1,7 @@ server.port = 9020 spring.datasource.url = jdbc:mysql://localhost:3306/events spring.datasource.username = root -spring.datasource.password = skorpion +spring.datasource.password = root spring.jpa.generate-ddl=true user.password=dizda # diff --git a/events/src/main/resources/bootstrap.properties b/events/src/main/resources/bootstrap.properties index 8a74bcf..cf02ab0 100644 --- a/events/src/main/resources/bootstrap.properties +++ b/events/src/main/resources/bootstrap.properties @@ -2,4 +2,4 @@ spring.application.name=steleks # N.B. this is the default: spring.cloud.config.uri=http://localhost:8888 spring.cloud.config.username=root -spring.cloud.config.password=skorpion \ No newline at end of file +spring.cloud.config.password=root \ No newline at end of file diff --git a/teams/src/main/java/ba/steleks/repository/module/Participant.java b/teams/src/main/java/ba/steleks/model/Participant.java similarity index 94% rename from teams/src/main/java/ba/steleks/repository/module/Participant.java rename to teams/src/main/java/ba/steleks/model/Participant.java index 2c56f88..7151567 100644 --- a/teams/src/main/java/ba/steleks/repository/module/Participant.java +++ b/teams/src/main/java/ba/steleks/model/Participant.java @@ -1,10 +1,9 @@ -package ba.steleks.repository.module; +package ba.steleks.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import java.io.Serializable; /** * Created by admin on 24/03/2017. diff --git a/teams/src/main/java/ba/steleks/repository/module/Team.java b/teams/src/main/java/ba/steleks/model/Team.java similarity index 96% rename from teams/src/main/java/ba/steleks/repository/module/Team.java rename to teams/src/main/java/ba/steleks/model/Team.java index ad3bd45..14c3417 100644 --- a/teams/src/main/java/ba/steleks/repository/module/Team.java +++ b/teams/src/main/java/ba/steleks/model/Team.java @@ -1,7 +1,6 @@ -package ba.steleks.repository.module; +package ba.steleks.model; import javax.persistence.*; -import javax.security.auth.Subject; import java.util.Set; /** diff --git a/teams/src/main/java/ba/steleks/repository/module/TeamCategory.java b/teams/src/main/java/ba/steleks/model/TeamCategory.java similarity index 94% rename from teams/src/main/java/ba/steleks/repository/module/TeamCategory.java rename to teams/src/main/java/ba/steleks/model/TeamCategory.java index 56ecf02..b25d4d8 100644 --- a/teams/src/main/java/ba/steleks/repository/module/TeamCategory.java +++ b/teams/src/main/java/ba/steleks/model/TeamCategory.java @@ -1,4 +1,4 @@ -package ba.steleks.repository.module; +package ba.steleks.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/teams/src/main/java/ba/steleks/repository/module/TeamMedia.java b/teams/src/main/java/ba/steleks/model/TeamMedia.java similarity index 89% rename from teams/src/main/java/ba/steleks/repository/module/TeamMedia.java rename to teams/src/main/java/ba/steleks/model/TeamMedia.java index 6a8dc6c..d12281a 100644 --- a/teams/src/main/java/ba/steleks/repository/module/TeamMedia.java +++ b/teams/src/main/java/ba/steleks/model/TeamMedia.java @@ -1,7 +1,6 @@ -package ba.steleks.repository.module; +package ba.steleks.model; import javax.persistence.*; -import java.util.Set; /** * Created by admin on 23/03/2017. diff --git a/teams/src/main/java/ba/steleks/repository/ParticipantJpaRepository.java b/teams/src/main/java/ba/steleks/repository/ParticipantJpaRepository.java index 3a5645a..4a3fe26 100644 --- a/teams/src/main/java/ba/steleks/repository/ParticipantJpaRepository.java +++ b/teams/src/main/java/ba/steleks/repository/ParticipantJpaRepository.java @@ -1,6 +1,6 @@ package ba.steleks.repository; -import ba.steleks.repository.module.Participant; +import ba.steleks.model.Participant; import org.springframework.data.repository.PagingAndSortingRepository; /** diff --git a/teams/src/main/java/ba/steleks/repository/TeamCategoryJpaRepository.java b/teams/src/main/java/ba/steleks/repository/TeamCategoryJpaRepository.java index 4465812..23bf537 100644 --- a/teams/src/main/java/ba/steleks/repository/TeamCategoryJpaRepository.java +++ b/teams/src/main/java/ba/steleks/repository/TeamCategoryJpaRepository.java @@ -1,6 +1,6 @@ package ba.steleks.repository; -import ba.steleks.repository.module.TeamCategory; +import ba.steleks.model.TeamCategory; import org.springframework.data.repository.PagingAndSortingRepository; /** diff --git a/teams/src/main/java/ba/steleks/repository/TeamsJpaRepository.java b/teams/src/main/java/ba/steleks/repository/TeamsJpaRepository.java index efcabbf..b4558cb 100644 --- a/teams/src/main/java/ba/steleks/repository/TeamsJpaRepository.java +++ b/teams/src/main/java/ba/steleks/repository/TeamsJpaRepository.java @@ -1,6 +1,6 @@ package ba.steleks.repository; -import ba.steleks.repository.module.Team; +import ba.steleks.model.Team; import org.springframework.data.repository.PagingAndSortingRepository; /** diff --git a/teams/src/main/java/ba/steleks/repository/TeamsMediaJpaRepository.java b/teams/src/main/java/ba/steleks/repository/TeamsMediaJpaRepository.java index 4ae9832..d8b6560 100644 --- a/teams/src/main/java/ba/steleks/repository/TeamsMediaJpaRepository.java +++ b/teams/src/main/java/ba/steleks/repository/TeamsMediaJpaRepository.java @@ -1,6 +1,6 @@ package ba.steleks.repository; -import ba.steleks.repository.module.TeamMedia; +import ba.steleks.model.TeamMedia; import org.springframework.data.repository.PagingAndSortingRepository; diff --git a/teams/src/main/resources/application.properties b/teams/src/main/resources/application.properties index c849d32..0b71ced 100644 --- a/teams/src/main/resources/application.properties +++ b/teams/src/main/resources/application.properties @@ -1,6 +1,6 @@ server.port=9010 spring.datasource.url = jdbc:mysql://localhost:3306/teams spring.datasource.username = root -spring.datasource.password = skorpion +spring.datasource.password = root spring.jpa.generate-ddl=true diff --git a/users/src/main/java/ba/steleks/controller/UserController.java b/users/src/main/java/ba/steleks/controller/UserController.java deleted file mode 100644 index 4c334d4..0000000 --- a/users/src/main/java/ba/steleks/controller/UserController.java +++ /dev/null @@ -1,37 +0,0 @@ -package ba.steleks.controller; - -import ba.steleks.repository.UsersJpaRepository; -import ba.steleks.repository.model.User; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.rest.webmvc.RepositoryRestController; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.net.URI; - -/** - * Created by admin on 02/04/2017. - */ -@RepositoryRestController -public class UserController { - - @Autowired - private UsersJpaRepository repository; - - @RequestMapping(path = "/users", method = RequestMethod.POST) - public ResponseEntity add(@RequestBody User user) { - System.out.println("doslo je do poziva"); - User result = repository.save(user); - URI location = ServletUriComponentsBuilder - .fromCurrentRequest().path("/{id}") - .buildAndExpand(result.getId()).toUri(); - return ResponseEntity.created(location).body(result); - } -} diff --git a/users/src/main/java/ba/steleks/repository/model/Course.java b/users/src/main/java/ba/steleks/model/Course.java similarity index 94% rename from users/src/main/java/ba/steleks/repository/model/Course.java rename to users/src/main/java/ba/steleks/model/Course.java index e500d94..40084f7 100644 --- a/users/src/main/java/ba/steleks/repository/model/Course.java +++ b/users/src/main/java/ba/steleks/model/Course.java @@ -1,4 +1,4 @@ -package ba.steleks.repository.model;/** +package ba.steleks.model;/** * Created by ensar on 23/03/17. */ diff --git a/users/src/main/java/ba/steleks/repository/model/MembershipType.java b/users/src/main/java/ba/steleks/model/MembershipType.java similarity index 95% rename from users/src/main/java/ba/steleks/repository/model/MembershipType.java rename to users/src/main/java/ba/steleks/model/MembershipType.java index 8442a71..aee6989 100644 --- a/users/src/main/java/ba/steleks/repository/model/MembershipType.java +++ b/users/src/main/java/ba/steleks/model/MembershipType.java @@ -1,4 +1,4 @@ -package ba.steleks.repository.model;/** +package ba.steleks.model;/** * Created by ensar on 23/03/17. */ diff --git a/users/src/main/java/ba/steleks/repository/model/User.java b/users/src/main/java/ba/steleks/model/User.java similarity index 94% rename from users/src/main/java/ba/steleks/repository/model/User.java rename to users/src/main/java/ba/steleks/model/User.java index 889114a..909683d 100644 --- a/users/src/main/java/ba/steleks/repository/model/User.java +++ b/users/src/main/java/ba/steleks/model/User.java @@ -1,12 +1,9 @@ -package ba.steleks.repository.model;/** +package ba.steleks.model;/** * Created by ensar on 22/03/17. */ -import org.hibernate.validator.constraints.NotBlank; - import javax.persistence.*; import javax.validation.constraints.NotNull; -import java.sql.Time; import java.sql.Timestamp; import java.util.Date; import java.util.Set; @@ -27,8 +24,7 @@ public class User { private String firstName; @NotNull private String lastName; - @NotNull - @Column(updatable = false, insertable = false) + @Column(updatable = false, insertable = false, columnDefinition="DATETIME default NOW()") private Timestamp registrationDate; @NotNull private String email; @@ -161,4 +157,5 @@ public class User { protected void onCreate() { this.registrationDate = new Timestamp(new Date().getTime()); } + } diff --git a/users/src/main/java/ba/steleks/repository/model/UserRole.java b/users/src/main/java/ba/steleks/model/UserRole.java similarity index 94% rename from users/src/main/java/ba/steleks/repository/model/UserRole.java rename to users/src/main/java/ba/steleks/model/UserRole.java index 4079fb1..5338eff 100644 --- a/users/src/main/java/ba/steleks/repository/model/UserRole.java +++ b/users/src/main/java/ba/steleks/model/UserRole.java @@ -1,4 +1,4 @@ -package ba.steleks.repository.model;/** +package ba.steleks.model;/** * Created by ensar on 22/03/17. */ diff --git a/users/src/main/java/ba/steleks/repository/CoursesJpaRepository.java b/users/src/main/java/ba/steleks/repository/CoursesJpaRepository.java index b749077..5361879 100644 --- a/users/src/main/java/ba/steleks/repository/CoursesJpaRepository.java +++ b/users/src/main/java/ba/steleks/repository/CoursesJpaRepository.java @@ -4,7 +4,7 @@ package ba.steleks.repository; * Created by ensar on 22/03/17. */ -import ba.steleks.repository.model.Course; +import ba.steleks.model.Course; import org.springframework.data.repository.PagingAndSortingRepository; diff --git a/users/src/main/java/ba/steleks/repository/MembershipTypesJpaRepository.java b/users/src/main/java/ba/steleks/repository/MembershipTypesJpaRepository.java index 5eafc2b..bb02859 100644 --- a/users/src/main/java/ba/steleks/repository/MembershipTypesJpaRepository.java +++ b/users/src/main/java/ba/steleks/repository/MembershipTypesJpaRepository.java @@ -4,7 +4,7 @@ package ba.steleks.repository; * Created by ensar on 22/03/17. */ -import ba.steleks.repository.model.MembershipType; +import ba.steleks.model.MembershipType; import org.springframework.data.repository.PagingAndSortingRepository; diff --git a/users/src/main/java/ba/steleks/repository/RestErrorHandler.java b/users/src/main/java/ba/steleks/repository/RestErrorHandler.java index cba63b5..57f33b1 100644 --- a/users/src/main/java/ba/steleks/repository/RestErrorHandler.java +++ b/users/src/main/java/ba/steleks/repository/RestErrorHandler.java @@ -8,6 +8,7 @@ import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.data.rest.webmvc.support.RepositoryConstraintViolationExceptionMessage; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; @@ -35,13 +37,21 @@ public class RestErrorHandler extends ResponseEntityExceptionHandler { public Map handleCustomException(javax.validation.ConstraintViolationException ex) { Map map= new HashMap(); - map.put("status", "400"); - map.put("error", "Bad request"); + map.put("status", HttpStatus.BAD_REQUEST.toString()); + map.put("error", ex.getLocalizedMessage()); return map; } + @ExceptionHandler(HttpStatusCodeException.class) + @ResponseBody + public ResponseEntity> handleAllExceptions(HttpStatusCodeException ex) { + Map map= new HashMap(); + map.put("status", ex.getStatusCode().toString()); + map.put("error", ex.getLocalizedMessage()); + return ResponseEntity.status(ex.getStatusCode()).body(map); + } } diff --git a/users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java b/users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java index e1caecd..9e6773b 100644 --- a/users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java +++ b/users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java @@ -4,8 +4,7 @@ package ba.steleks.repository; * Created by ensar on 22/03/17. */ -import ba.steleks.repository.model.User; -import ba.steleks.repository.model.UserRole; +import ba.steleks.model.UserRole; import org.springframework.data.repository.PagingAndSortingRepository; diff --git a/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java b/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java index 15334af..a2516b6 100644 --- a/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java +++ b/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java @@ -4,17 +4,9 @@ package ba.steleks.repository; * Created by ensar on 22/03/17. */ -import ba.steleks.repository.model.User; -import ba.steleks.repository.model.UserRole; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; +import ba.steleks.model.User; import org.springframework.data.repository.PagingAndSortingRepository; -import javax.transaction.Transactional; - public interface UsersJpaRepository extends PagingAndSortingRepository { } diff --git a/users/src/main/resources/application.properties b/users/src/main/resources/application.properties index e687b7f..3ac2dce 100644 --- a/users/src/main/resources/application.properties +++ b/users/src/main/resources/application.properties @@ -1,6 +1,6 @@ server.port = 8090 spring.datasource.url = jdbc:mysql://localhost:3306/users spring.datasource.username = root -spring.datasource.password = skorpion +spring.datasource.password = root spring.jpa.generate-ddl=true