144 |
Not found :(
145 |
Sorry, but the page you were trying to view does not exist.
146 |
It looks like this was the result of either:
147 |
148 | - a mistyped address
149 | - an out-of-date link
150 |
151 |
154 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/angular-spring-boot-webapp/src/test/frontend/spec/services/srv.eventSpec.js:
--------------------------------------------------------------------------------
1 | describe('Service: EventService', function () {
2 | 'use strict';
3 |
4 | // load the controller's module
5 | beforeEach(module('ngSpringBootApp'));
6 |
7 | var service,
8 | domain,
9 | scope,
10 | httpBackend;
11 |
12 | // Initialize the service
13 | beforeEach(inject(function (EventService, $rootScope, $httpBackend, Domain) {
14 | scope = $rootScope.$new();
15 | service = EventService;
16 | httpBackend = $httpBackend;
17 | domain = Domain;
18 | }));
19 |
20 | describe('error handling', function () {
21 | it('should not call normal handler', function (done) {
22 | httpBackend.expectGET('/api/events').respond(400);
23 | service.listAllEvents(function () {
24 | fail();
25 | }, function () {
26 | done();
27 | });
28 | httpBackend.flush();
29 | });
30 | });
31 |
32 | describe('normal handling', function () {
33 |
34 | describe('read', function () {
35 |
36 | it('should list events', function (done) {
37 | var events;
38 | httpBackend.expectGET('/api/events').respond(200, [{
39 | 'insertDate': '2015-07-07',
40 | 'deleted': false,
41 | 'eventId': '144',
42 | 'eventDescription': 'Beschreibung',
43 | 'startDate': '2015-07-17',
44 | 'endDate': '2015-07-17'
45 | }, {
46 | 'insertDate': '2015-07-07',
47 | 'deleted': false,
48 | 'eventId': '145',
49 | 'eventDescription': 'Beschreibung',
50 | 'startDate': '2015-07-28',
51 | 'endDate': '2015-07-30'
52 | }]);
53 | service.listAllEvents(function (response) {
54 | events = response;
55 | expect(events.length).toBe(2);
56 | expect(events[0].eventId).toBe('144');
57 | expect(events[1].eventId).toBe('145');
58 | done();
59 | });
60 | httpBackend.flush();
61 | });
62 |
63 | it('get event by eventId for customer', function (done) {
64 | var event;
65 | httpBackend.expectGET('/api/events/1').respond(200, {
66 | 'insertDate': '2015-07-07',
67 | 'deleted': false,
68 | 'eventId': '145',
69 | 'eventDescription': 'Beschreibung',
70 | 'startDate': '2015-07-28',
71 | 'endDate': '2015-07-30'
72 | });
73 | service.getEvent('1', function (response) {
74 | event = response;
75 | expect(event.eventId).toBe('145');
76 | done();
77 | });
78 | httpBackend.flush();
79 | });
80 | });
81 |
82 | describe('write', function () {
83 |
84 | it('should create event', function (done) {
85 | httpBackend.expectPOST('/api/events').respond(200);
86 | service.saveEvent(domain.Event.build({
87 | insertDate: new Date(),
88 | eventDescription: 'event',
89 | startDate: new Date(),
90 | endDate: new Date()
91 | }), function () {
92 | done();
93 | });
94 | httpBackend.flush();
95 | });
96 |
97 | it('should update event', function (done) {
98 | httpBackend.expectPUT('/api/events/1').respond(200);
99 | service.saveEvent(domain.Event.build({
100 | insertDate: new Date(),
101 | eventId: 1,
102 | eventDescription: 'event',
103 | startDate: new Date(),
104 | endDate: new Date()
105 | }), function () {
106 | done();
107 | });
108 | httpBackend.flush();
109 | });
110 |
111 | });
112 | });
113 | });
114 |
--------------------------------------------------------------------------------
/angular-spring-boot-webapp/src/main/frontend/scripts/services/srv.domain.js:
--------------------------------------------------------------------------------
1 | app.factory('Domain', function () {
2 | 'use strict';
3 |
4 | // reference for base
5 | var referenceBaseDateHours = new Date(1970, 1, 2, 0, 0, 0, 0),
6 | // use for date DTO normalization
7 | normalizerBaseDateHours = new Date(1970, 1, 2, 12, 0, 0, 0);
8 |
9 | // HELPER functions
10 |
11 | function convertDateStringToDate(time) {
12 | if (time) {
13 | var date = new Date(referenceBaseDateHours.getTime()),
14 | res = time.split('-');
15 | date.setYear(res[0]);
16 | date.setMonth(res[1]);
17 | date.setDate(res[2]);
18 | return date;
19 | } else {
20 | return null;
21 | }
22 | }
23 |
24 | /**
25 | * User Object
26 | */
27 | function User(username, userId, permissions, customers) {
28 | this.username = username;
29 | this.userId = userId;
30 | this.permissions = permissions;
31 | this.customers = customers;
32 | }
33 |
34 |
35 | //Public object methods, assigned to prototype
36 |
37 |
38 | User.prototype.isValid = function () {
39 | if (this.username && this.username !== 'anonymousUser') {
40 | return true;
41 | } else {
42 | return false;
43 | }
44 | };
45 | // Static method, assigned to class, e.g. builders
46 | // Instance ('this') is not available in static context
47 | User.build = function (username, userId, permissions, customers) {
48 | return new User(username, userId, permissions, customers);
49 |
50 | };
51 |
52 | /**
53 | * Event Object
54 | */
55 | function Event() {
56 | this.eventId = null;
57 | this.eventDescription = null;
58 | this.insertDate = null;
59 | this.startDate = null;
60 | this.endDate = null;
61 | }
62 |
63 |
64 | Event.prototype.convertToDTO = function () {
65 | var date = new Date(normalizerBaseDateHours.getTime());
66 | this.startDate.setHours(date.getHours());
67 | this.startDate.setMinutes(date.getMinutes());
68 | if (this.endDate) {
69 | this.endDate.setHours(date.getHours());
70 | this.endDate.setMinutes(date.getMinutes());
71 | }
72 | return this;
73 | };
74 |
75 | Event.prototype.convertFromDTO = function () {
76 | // easy way to get a clean copy
77 | var copy = Event.build(this);
78 | // convert times
79 | if (copy.startDate) {
80 | copy.startDate = convertDateStringToDate(this.startDate);
81 | }
82 | if (copy.endDate) {
83 | copy.endDate = convertDateStringToDate(this.endDate);
84 | }
85 | return copy;
86 | };
87 |
88 | function UserProfile(){
89 | this.userName = null;
90 | this.password = null;
91 | this.passwordConfirmation = null;
92 | this.customerName = null;
93 | this.customerId = null;
94 | this.branchNumber = null;
95 | }
96 |
97 | UserProfile.prototype.isValid = function () {
98 | if(this.userName && this.password && this.passwordConfirmation && this.customerName && this.password === this.passwordConfirmation){
99 | return true;
100 | }
101 | return false;
102 | };
103 |
104 | UserProfile.build = function(data){
105 | if(!data) {
106 | return new UserProfile();
107 | }else{
108 | var userProfile = new UserProfile();
109 | for(var key in data){
110 | if (key.charAt(0) !== '$' && data.hasOwnProperty(key)) {
111 | userProfile[key] = data[key];
112 | }
113 | }
114 | return userProfile;
115 | }
116 | };
117 |
118 | // Static method, assigned to class, e.g. builders
119 | // Instance ('this') is not available in static context
120 | Event.build = function (data) {
121 | if (!data) {
122 | return new Event();
123 | } else {
124 | var event = new Event();
125 | for (var key in data) {
126 | if (key.charAt(0) !== '$' && data.hasOwnProperty(key)) {
127 | event[key] = data[key];
128 | }
129 | }
130 | return event;
131 | }
132 | };
133 |
134 |
135 |
136 | return {
137 | User: User,
138 | Event: Event,
139 | UserProfile: UserProfile
140 | };
141 | });
--------------------------------------------------------------------------------
/angular-spring-boot-webapp/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration
2 | // http://karma-runner.github.io/0.12/config/configuration-file.html
3 | // Generated on 2015-06-18 using
4 | // generator-karma 1.0.0
5 |
6 | module.exports = function (config) {
7 | 'use strict';
8 |
9 | config.set({
10 | // enable / disable watching file and executing tests whenever any file changes
11 | autoWatch: true,
12 |
13 | // base path, that will be used to resolve files and exclude
14 | basePath: '.',
15 |
16 | // testing framework to use (jasmine/mocha/qunit/...)
17 | // as well as any additional frameworks (requirejs/chai/sinon/...)
18 | frameworks: [
19 | "jasmine"
20 | ],
21 |
22 | // list of files / patterns to load in the browser
23 | files: [
24 | // bower:js
25 | 'bower_components/jquery/dist/jquery.js',
26 | 'bower_components/es5-shim/es5-shim.js',
27 | 'bower_components/angular/angular.js',
28 | 'bower_components/angular-animate/angular-animate.js',
29 | 'bower_components/angular-block-ui/dist/angular-block-ui.js',
30 | 'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
31 | 'bower_components/angular-cookies/angular-cookies.js',
32 | 'bower_components/angular-invocation-handler/dist/angular-invocation-handler.js',
33 | 'bower_components/angular-resource/angular-resource.js',
34 | 'bower_components/angular-route/angular-route.js',
35 | 'bower_components/angular-sanitize/angular-sanitize.js',
36 | 'bower_components/angular-touch/angular-touch.js',
37 | 'bower_components/angular-translate/angular-translate.js',
38 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/affix.js',
39 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/alert.js',
40 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/button.js',
41 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/carousel.js',
42 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/collapse.js',
43 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/dropdown.js',
44 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab.js',
45 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition.js',
46 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/scrollspy.js',
47 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/modal.js',
48 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tooltip.js',
49 | 'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/popover.js',
50 | 'bower_components/ng-table/dist/ng-table.min.js',
51 | 'bower_components/angular-mocks/angular-mocks.js',
52 | // endbower
53 | "src/main/frontend/scripts/**/*.js",
54 | "src/test/frontend/mocks/**/*.js",
55 | "src/test/frontend/spec/**/*.js"
56 | ],
57 |
58 | // list of files / patterns to exclude
59 | exclude: [],
60 |
61 | // web server port
62 | port: 9080,
63 |
64 | // Start these browsers, currently available:
65 | // - Chrome
66 | // - ChromeCanary
67 | // - Firefox
68 | // - Opera
69 | // - Safari (only Mac)
70 | // - PhantomJS
71 | // - IE (only Windows)
72 | browsers: [
73 | "PhantomJS"
74 | ],
75 |
76 | // Which plugins to enable
77 | plugins: [
78 | "karma-phantomjs-launcher",
79 | "karma-jasmine",
80 | "karma-junit-reporter"
81 | ],
82 |
83 | reporters: [
84 | "progress",
85 | "junit"
86 | ],
87 |
88 | junitReporter: {
89 | outputDir: 'target', // results will be saved as $outputDir/$browserName.xml
90 | suite: 'ng-spring-boot'
91 | },
92 |
93 | // Continuous Integration mode
94 | // if true, it capture browsers, run tests and exit
95 | singleRun: false,
96 |
97 | colors: true,
98 |
99 | // level of logging
100 | // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
101 | logLevel: config.LOG_INFO,
102 |
103 | // Uncomment the following lines if you are using grunt's server to run the tests
104 | // proxies: {
105 | // '/': 'http://localhost:9000/'
106 | // },
107 | // URL root prevent conflicts with the site root
108 | // urlRoot: '_karma_'
109 | });
110 | };
111 |
--------------------------------------------------------------------------------
/angular-spring-boot-webapp/src/test/frontend/spec/services/srv.authSpec.js:
--------------------------------------------------------------------------------
1 | describe('Service: authenticationService', function () {
2 | 'use strict';
3 |
4 |
5 | // load the controller's module
6 | beforeEach(module('ngSpringBootAppMock'));
7 |
8 | var service,
9 | redirectService,
10 | rootScope,
11 | httpBackend;
12 |
13 | // Initialize the service
14 | beforeEach(inject(function (_$rootScope_,
15 | _$httpBackend_,
16 | RedirectService,
17 | AuthenticationService) {
18 | rootScope = _$rootScope_;
19 | redirectService = RedirectService;
20 | service = AuthenticationService;
21 | httpBackend = _$httpBackend_;
22 | spyOn(redirectService, 'redirect').and.callFake(function () {
23 | });
24 | }));
25 |
26 | describe('error handling', function () {
27 |
28 | it('should not login with spring errors', function (done) {
29 | httpBackend.expectPOST('./login').respond(400);
30 | service.login({username: 'abc', password: '123'}, function () {
31 | fail();
32 | }, function (user) {
33 | expect(user.isValid()).not.toBeTruthy();
34 | done();
35 | });
36 | httpBackend.flush();
37 | });
38 |
39 | it('should login with user errors', function (done) {
40 | httpBackend.expectPOST('./login').respond(200);
41 | httpBackend.expectGET('./api/login/user').respond(400, {
42 | username: 'abcUser',
43 | userRoles: ['role1', 'roles2']
44 | });
45 | service.login({username: 'abc', password: '123'}, function () {
46 | fail();
47 | }, function (user) {
48 | expect(user.isValid()).not.toBeTruthy();
49 | done();
50 | });
51 | httpBackend.flush();
52 | });
53 |
54 | it('should logout with errors', function (done) {
55 | httpBackend.expectPOST('./logout').respond(400);
56 | service.logout(function () {
57 | fail();
58 | }, function (user) {
59 | expect(user.isValid()).not.toBeTruthy();
60 | done();
61 | }
62 | );
63 | httpBackend.flush();
64 | });
65 | });
66 |
67 | describe('normal handling', function () {
68 |
69 | it('should login successfully', function (done) {
70 | httpBackend.expectPOST('./login').respond(200);
71 | httpBackend.expectGET('./api/login/user').respond(200, {
72 | username: 'abcUser',
73 | userRoles: ['role1', 'roles2']
74 | });
75 | service.login({username: 'abc', password: '123'}, function (user) {
76 | expect(user.isValid()).toBeTruthy();
77 | expect(user.username).toBe('abcUser');
78 | done();
79 | });
80 | httpBackend.flush();
81 | });
82 |
83 | it('should revalidate existing user session', function (done) {
84 | httpBackend.expectGET('./api/login/user').respond(200, {
85 | username: 'abcUser',
86 | userRoles: ['role1', 'roles2']
87 | });
88 | service.checkUser(function (user) {
89 | expect(user.isValid()).toBeTruthy();
90 | done();
91 | }, function () {
92 | fail();
93 | });
94 | httpBackend.flush();
95 | });
96 |
97 | it('should logout successfully', function (done) {
98 | httpBackend.expectPOST('./logout').respond(200);
99 | service.logout(function (user) {
100 | expect(user.isValid()).not.toBeTruthy();
101 | done();
102 | });
103 | httpBackend.flush();
104 | });
105 |
106 | it('should invalidate non existing user session', function (done) {
107 | httpBackend.expectGET('./api/login/user').respond(400);
108 | service.checkUser(function () {
109 | fail();
110 | }, function (user) {
111 | expect(user.isValid()).not.toBeTruthy();
112 | done();
113 | });
114 | httpBackend.flush();
115 | });
116 |
117 | it('should handle invalid user details', function (done) {
118 | httpBackend.expectGET('./api/login/user').respond(200, {
119 | user: 'abcUser'
120 | });
121 | service.checkUser(function (user) {
122 | expect(user.isValid()).not.toBeTruthy();
123 | done();
124 | }, function () {
125 | fail();
126 | });
127 | httpBackend.flush();
128 | });
129 | });
130 | });
131 |
--------------------------------------------------------------------------------
/angular-spring-boot-webapp/src/main/java/ngSpring/demo/controllers/EventController.java:
--------------------------------------------------------------------------------
1 | package ngSpring.demo.controllers;
2 |
3 | import io.swagger.annotations.Api;
4 | import io.swagger.annotations.ApiOperation;
5 | import io.swagger.annotations.ApiResponse;
6 | import io.swagger.annotations.ApiResponses;
7 | import ngSpring.demo.domain.dto.EventDTO;
8 | import ngSpring.demo.domain.entities.Event;
9 | import ngSpring.demo.exceptions.BusinessException;
10 | import ngSpring.demo.exceptions.EntityNotFoundException;
11 | import ngSpring.demo.exceptions.ValidationException;
12 | import ngSpring.demo.repositories.EventRepository;
13 | import ngSpring.demo.transformer.impl.EventTransformer;
14 | import ngSpring.demo.util.Message;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.data.domain.Sort;
17 | import org.springframework.data.domain.Sort.Order;
18 | import org.springframework.http.HttpStatus;
19 | import org.springframework.http.ResponseEntity;
20 | import org.springframework.web.bind.annotation.*;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Iterator;
24 | import java.util.List;
25 |
26 |
27 | //tag::swagger-docs[]
28 | @Api(basePath = "/api/events", value = "Events", description = "Operations with Events", produces = "application/json")
29 | //end::swagger-docs[]
30 | //tag::events-rest-api[]
31 | @RestController
32 | @RequestMapping(value = "/api/events")
33 | @ResponseStatus(HttpStatus.OK)
34 | public class EventController {
35 | //end::events-rest-api[]
36 |
37 | @Autowired
38 | private EventTransformer eventTransformer;
39 |
40 | @Autowired
41 | private EventRepository eventRepository;
42 |
43 | private Sort sort = new Sort(new Order(Sort.Direction.ASC, "startDate"));
44 |
45 | @RequestMapping(method = RequestMethod.GET)
46 | public List