├── AngularCrudFrontend
├── .angular-cli.json
├── .editorconfig
├── .gitignore
├── README.md
├── e2e
│ ├── app.e2e-spec.ts
│ ├── app.po.ts
│ └── tsconfig.e2e.json
├── karma.conf.js
├── package-lock.json
├── package.json
├── protractor.conf.js
├── src
│ ├── app
│ │ ├── app.component.css
│ │ ├── app.component.html
│ │ ├── app.component.spec.ts
│ │ ├── app.component.ts
│ │ ├── app.module.ts
│ │ └── configurations
│ │ │ ├── configuration-list
│ │ │ ├── configuration-list.component.css
│ │ │ ├── configuration-list.component.html
│ │ │ └── configuration-list.component.ts
│ │ │ ├── configuration
│ │ │ ├── configuration.component.css
│ │ │ ├── configuration.component.html
│ │ │ └── configuration.component.ts
│ │ │ ├── configurations.component.css
│ │ │ ├── configurations.component.html
│ │ │ ├── configurations.component.ts
│ │ │ └── shared
│ │ │ ├── configuration.model.ts
│ │ │ └── configuration.service.ts
│ ├── assets
│ │ └── .gitkeep
│ ├── custom.js
│ ├── environments
│ │ ├── environment.prod.ts
│ │ └── environment.ts
│ ├── favicon.ico
│ ├── index.html
│ ├── main.ts
│ ├── polyfills.ts
│ ├── styles.css
│ ├── test.ts
│ ├── tsconfig.app.json
│ ├── tsconfig.spec.json
│ └── typings.d.ts
├── tsconfig.json
└── tslint.json
├── README.md
└── SpringBootCrudApi
├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── cengenes
│ │ └── configuration
│ │ └── api
│ │ ├── DynamicConfigurationServiceApplication.java
│ │ ├── conf
│ │ ├── LocalizationConfiguration.java
│ │ └── SwaggerConfig.java
│ │ ├── controller
│ │ ├── ConfigurationAngularController.java
│ │ └── ControllerExceptionHandler.java
│ │ ├── converter
│ │ ├── ConfigurationDtoToEntityConverter.java
│ │ └── ConfigurationEntityToDtoConverter.java
│ │ ├── dto
│ │ ├── ConfigurationDto.java
│ │ └── Response.java
│ │ ├── entity
│ │ └── Configuration.java
│ │ ├── exception
│ │ ├── DynamicConfigurationApiException.java
│ │ ├── EntityNotFoundException.java
│ │ └── MissingMandatoryFieldException.java
│ │ ├── repository
│ │ └── ConfigurationRepository.java
│ │ ├── service
│ │ ├── ConfigurationService.java
│ │ └── imp
│ │ │ └── ConfigurationServiceImp.java
│ │ ├── types
│ │ └── RequestStatus.java
│ │ └── validator
│ │ └── ConfigurationInfoValidator.java
└── resources
│ ├── application.properties
│ ├── db-init
│ └── configuration
│ │ └── configuration-h2.sql
│ └── i18n
│ ├── messages_en.properties
│ └── messages_tr.properties
└── test
└── java
└── com
└── cengenes
└── configuration
└── api
├── conf
├── BaseIT.java
└── BaseMockitoTest.java
├── controller
└── ConfigurationControllerIT.java
└── service
└── ConfigurationServiceTest.java
/AngularCrudFrontend/.angular-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "project": {
4 | "name": "angular-crud"
5 | },
6 | "apps": [
7 | {
8 | "root": "src",
9 | "outDir": "dist",
10 | "assets": [
11 | "assets",
12 | "favicon.ico"
13 | ],
14 | "index": "index.html",
15 | "main": "main.ts",
16 | "polyfills": "polyfills.ts",
17 | "test": "test.ts",
18 | "tsconfig": "tsconfig.app.json",
19 | "testTsconfig": "tsconfig.spec.json",
20 | "prefix": "app",
21 | "styles": [
22 | "styles.css",
23 | "../node_modules/ngx-toastr/toastr.css"
24 | ],
25 | "scripts": ["custom.js"],
26 | "environmentSource": "environments/environment.ts",
27 | "environments": {
28 | "dev": "environments/environment.ts",
29 | "prod": "environments/environment.prod.ts"
30 | }
31 | }
32 | ],
33 | "e2e": {
34 | "protractor": {
35 | "config": "./protractor.conf.js"
36 | }
37 | },
38 | "lint": [
39 | {
40 | "project": "src/tsconfig.app.json",
41 | "exclude": "**/node_modules/**"
42 | },
43 | {
44 | "project": "src/tsconfig.spec.json",
45 | "exclude": "**/node_modules/**"
46 | },
47 | {
48 | "project": "e2e/tsconfig.e2e.json",
49 | "exclude": "**/node_modules/**"
50 | }
51 | ],
52 | "test": {
53 | "karma": {
54 | "config": "./karma.conf.js"
55 | }
56 | },
57 | "defaults": {
58 | "styleExt": "css",
59 | "component": {}
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | testem.log
34 | /typings
35 |
36 | # e2e
37 | /e2e/*.js
38 | /e2e/*.map
39 |
40 | # System Files
41 | .DS_Store
42 | Thumbs.db
43 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/README.md:
--------------------------------------------------------------------------------
1 | # AngularCRUD
2 |
3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.4.5.
4 |
5 | ## Development server
6 |
7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8 |
9 | ## Code scaffolding
10 |
11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12 |
13 | ## Build
14 |
15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
16 |
17 | ## Running unit tests
18 |
19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20 |
21 | ## Running end-to-end tests
22 |
23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24 |
25 | ## Further help
26 |
27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
28 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/e2e/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('angular-crud App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to app!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/e2e/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": [
9 | "jasmine",
10 | "jasminewd2",
11 | "node"
12 | ]
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-crud",
3 | "version": "0.0.0",
4 | "license": "MIT",
5 | "scripts": {
6 | "ng": "ng",
7 | "start": "ng serve",
8 | "build": "ng build",
9 | "test": "ng test",
10 | "lint": "ng lint",
11 | "e2e": "ng e2e"
12 | },
13 | "private": true,
14 | "dependencies": {
15 | "@angular/animations": "^4.2.4",
16 | "@angular/common": "^4.2.4",
17 | "@angular/compiler": "^4.2.4",
18 | "@angular/core": "^4.2.4",
19 | "@angular/forms": "^4.2.4",
20 | "@angular/http": "^4.2.4",
21 | "@angular/platform-browser": "^4.2.4",
22 | "@angular/platform-browser-dynamic": "^4.2.4",
23 | "@angular/router": "^4.2.4",
24 | "core-js": "^2.4.1",
25 | "ngx-toastr": "^6.5.0",
26 | "rxjs": "^5.4.2",
27 | "zone.js": "^0.8.14"
28 | },
29 | "devDependencies": {
30 | "@angular/cli": "1.4.5",
31 | "@angular/compiler-cli": "^4.2.4",
32 | "@angular/language-service": "^4.2.4",
33 | "@types/jasmine": "~2.5.53",
34 | "@types/jasminewd2": "~2.0.2",
35 | "@types/node": "~6.0.60",
36 | "codelyzer": "~3.2.0",
37 | "jasmine-core": "~2.6.2",
38 | "jasmine-spec-reporter": "~4.1.0",
39 | "karma": "~1.7.0",
40 | "karma-chrome-launcher": "~2.1.1",
41 | "karma-cli": "~1.0.1",
42 | "karma-coverage-istanbul-reporter": "^1.2.1",
43 | "karma-jasmine": "~1.1.0",
44 | "karma-jasmine-html-reporter": "^0.2.2",
45 | "protractor": "~5.1.2",
46 | "ts-node": "~3.2.0",
47 | "tslint": "~5.7.0",
48 | "typescript": "~2.3.3"
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/app.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enesacikoglu/SpringBootAngular4Crud/1608cd1db98791b23a34580ef4284cbc4daf2177/AngularCrudFrontend/src/app/app.component.css
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 | describe('AppComponent', () => {
4 | beforeEach(async(() => {
5 | TestBed.configureTestingModule({
6 | declarations: [
7 | AppComponent
8 | ],
9 | }).compileComponents();
10 | }));
11 | it('should create the app', async(() => {
12 | const fixture = TestBed.createComponent(AppComponent);
13 | const app = fixture.debugElement.componentInstance;
14 | expect(app).toBeTruthy();
15 | }));
16 | it(`should have as title 'app'`, async(() => {
17 | const fixture = TestBed.createComponent(AppComponent);
18 | const app = fixture.debugElement.componentInstance;
19 | expect(app.title).toEqual('app');
20 | }));
21 | it('should render title in a h1 tag', async(() => {
22 | const fixture = TestBed.createComponent(AppComponent);
23 | fixture.detectChanges();
24 | const compiled = fixture.debugElement.nativeElement;
25 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
26 | }));
27 | });
28 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.css']
7 | })
8 | export class AppComponent {
9 | title = 'app';
10 | }
11 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule} from '@angular/forms'
4 | import { HttpModule } from '@angular/http'
5 |
6 | import { AppComponent } from './app.component';
7 | import { ConfigurationsComponent } from './configurations/configurations.component';
8 | import { ConfigurationComponent } from './configurations/configuration/configuration.component';
9 | import { ConfigurationListComponent } from './configurations/configuration-list/configuration-list.component';
10 | import { ToastrModule } from 'ngx-toastr';
11 |
12 | @NgModule({
13 | declarations: [
14 | AppComponent,
15 | ConfigurationsComponent,
16 | ConfigurationComponent,
17 | ConfigurationListComponent
18 | ],
19 | imports: [
20 | BrowserModule,
21 | FormsModule,
22 | HttpModule,
23 | ToastrModule.forRoot()
24 | ],
25 | providers: [],
26 | bootstrap: [AppComponent]
27 | })
28 | export class AppModule { }
29 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configuration-list/configuration-list.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enesacikoglu/SpringBootAngular4Crud/1608cd1db98791b23a34580ef4284cbc4daf2177/AngularCrudFrontend/src/app/configurations/configuration-list/configuration-list.component.css
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configuration-list/configuration-list.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Application Name |
8 | Configuration Name |
9 | Value |
10 | Active |
11 | Action |
12 |
13 |
14 | {{configuration.applicationName}} |
15 | {{configuration.name}} |
16 | {{configuration.value}} |
17 | {{configuration.isActive}} |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | |
26 |
27 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configuration-list/configuration-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | import { ConfigurationService } from '../shared/configuration.service'
4 | import { Configuration } from '../shared/configuration.model';
5 | import { ToastrService } from 'ngx-toastr';
6 | @Component({
7 | selector: 'app-configuration-list',
8 | templateUrl: './configuration-list.component.html',
9 | styleUrls: ['./configuration-list.component.css']
10 | })
11 | export class ConfigurationListComponent implements OnInit {
12 |
13 | constructor(private configurationService: ConfigurationService,private toastr : ToastrService) { }
14 |
15 | ngOnInit() {
16 | this.configurationService.getConfigurationList();
17 | }
18 |
19 | showForEdit(conf: Configuration) {
20 | this.configurationService.selectedConfiguration = Object.assign({}, conf);;
21 | }
22 |
23 |
24 | onDelete(id: number) {
25 | if (confirm('Are you sure to delete this record ?') == true) {
26 | this.configurationService.deleteConfiguration(id)
27 | .subscribe(x => {
28 | this.configurationService.getConfigurationList();
29 | this.toastr.warning("Deleted Successfully","configuration Register");
30 | })
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configuration/configuration.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enesacikoglu/SpringBootAngular4Crud/1608cd1db98791b23a34580ef4284cbc4daf2177/AngularCrudFrontend/src/app/configurations/configuration/configuration.component.css
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configuration/configuration.component.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configuration/configuration.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { NgForm } from '@angular/forms'
3 |
4 | import { ConfigurationService } from '../shared/configuration.service'
5 | import { ToastrService } from 'ngx-toastr'
6 |
7 | @Component({
8 | selector: 'app-configuration',
9 | templateUrl: './configuration.component.html',
10 | styleUrls: ['./configuration.component.css']
11 | })
12 | export class ConfigurationComponent implements OnInit {
13 |
14 | constructor(private configurationService: ConfigurationService, private toastr: ToastrService) { }
15 |
16 | public types = [
17 | { value: 'String', display: 'String' },
18 | { value: 'Double', display: 'Double' },
19 | { value: 'Integer', display: 'Integer' },
20 | { value: 'Boolean', display: 'Boolean' }
21 | ]
22 |
23 | ngOnInit() {
24 | this.resetForm();
25 | }
26 |
27 | resetForm(form?: NgForm) {
28 | if (form != null)
29 | form.reset();
30 | this.configurationService.selectedConfiguration = {
31 | id: null,
32 | name: '',
33 | type: this.types[0].value,
34 | value: '',
35 | isActive: false,
36 | applicationName: ''
37 | }
38 | }
39 |
40 | onSubmit(form: NgForm) {
41 | if (form.value.id == null) {
42 | this.configurationService.postConfiguration(form.value)
43 | .subscribe(data => {
44 | this.resetForm(form);
45 | this.configurationService.getConfigurationList();
46 | this.toastr.success('New Record Added Succcessfully', 'Configuration Register');
47 | })
48 | }
49 | else {
50 | this.configurationService.putConfiguration(form.value.id, form.value)
51 | .subscribe(data => {
52 | this.resetForm(form);
53 | this.configurationService.getConfigurationList();
54 | this.toastr.info('Record Updated Successfully!', 'configuration Register');
55 | });
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configurations.component.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enesacikoglu/SpringBootAngular4Crud/1608cd1db98791b23a34580ef4284cbc4daf2177/AngularCrudFrontend/src/app/configurations/configurations.component.css
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configurations.component.html:
--------------------------------------------------------------------------------
1 |
2 |
Configuration Save
3 |
4 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/configurations.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | import {ConfigurationService} from './shared/configuration.service'
4 | @Component({
5 | selector: 'app-configurations',
6 | templateUrl: './configurations.component.html',
7 | styleUrls: ['./configurations.component.css'],
8 | providers:[ConfigurationService]
9 | })
10 | export class ConfigurationsComponent implements OnInit {
11 |
12 | constructor(private configurationService : ConfigurationService) { }
13 |
14 | ngOnInit() {
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/shared/configuration.model.ts:
--------------------------------------------------------------------------------
1 | export class Configuration {
2 | id : number;
3 | name:string;
4 | type:string;
5 | value:string;
6 | isActive:Boolean;
7 | applicationName:string;
8 | }
9 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/app/configurations/shared/configuration.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Http, Response, Headers, RequestOptions, RequestMethod } from '@angular/http';
3 | import { Observable } from 'rxjs/Observable';
4 | import 'rxjs/add/operator/map';
5 | import 'rxjs/add/operator/toPromise';
6 |
7 | import { Configuration } from './configuration.model'
8 |
9 | @Injectable()
10 | export class ConfigurationService {
11 |
12 | selectedConfiguration: Configuration;
13 | configurationList: Configuration[];
14 | constructor(private http: Http) { }
15 |
16 | postConfiguration(conf: Configuration) {
17 | var body = JSON.stringify(conf);
18 | var headerOptions = new Headers({ 'Content-Type': 'application/json' });
19 | var requestOptions = new RequestOptions({ method: RequestMethod.Post, headers: headerOptions });
20 | return this.http.post('http://localhost:8080/api/ang/configuration', body, requestOptions).map(x => x.json());
21 | }
22 |
23 | putConfiguration(id, conf) {
24 | var body = JSON.stringify(conf);
25 | var headerOptions = new Headers({ 'Content-Type': 'application/json' });
26 | var requestOptions = new RequestOptions({ method: RequestMethod.Put, headers: headerOptions });
27 | return this.http.put('http://localhost:8080/api/ang/configuration/' + id,
28 | body,
29 | requestOptions).map(res => res.json());
30 | }
31 | getConfigurationList() {
32 | this.http.get('http://localhost:8080/api/ang/configurations')
33 | .map((data: Response) => {
34 | return data.json() as Configuration[];
35 | }).toPromise().then(x => {
36 | this.configurationList = x;
37 | })
38 | }
39 |
40 | deleteConfiguration(id: number) {
41 | return this.http.delete('http://localhost:8080/api/ang/configuration/' + id).map(res => res.json());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enesacikoglu/SpringBootAngular4Crud/1608cd1db98791b23a34580ef4284cbc4daf2177/AngularCrudFrontend/src/assets/.gitkeep
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/custom.js:
--------------------------------------------------------------------------------
1 | $(document).ready(function(){
2 | $("#inputfilter").keyup(function(){
3 | filter = new RegExp($(this).val(),'i');
4 | $("#confTable tbody tr").filter(function(){
5 | $(this).each(function(){
6 | found = false;
7 | $(this).find("td:first").each(function(){
8 | content = $(this).html();
9 | if(content.match(filter))
10 | {
11 | found = true
12 | }
13 | });
14 | if(!found)
15 | {
16 | $(this).hide();
17 | }
18 | else
19 | {
20 | $(this).show();
21 | }
22 | });
23 | });
24 | });
25 | });
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enesacikoglu/SpringBootAngular4Crud/1608cd1db98791b23a34580ef4284cbc4daf2177/AngularCrudFrontend/src/favicon.ico
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | AngularCRUD
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.log(err));
13 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** Evergreen browsers require these. **/
41 | import 'core-js/es6/reflect';
42 | import 'core-js/es7/reflect';
43 |
44 |
45 | /**
46 | * Required to support Web Animations `@angular/platform-browser/animations`.
47 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
48 | **/
49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
50 |
51 |
52 |
53 | /***************************************************************************************************
54 | * Zone JS is required by Angular itself.
55 | */
56 | import 'zone.js/dist/zone'; // Included with Angular CLI.
57 |
58 |
59 |
60 | /***************************************************************************************************
61 | * APPLICATION IMPORTS
62 | */
63 |
64 | /**
65 | * Date, currency, decimal and percent pipes.
66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
67 | */
68 | // import 'intl'; // Run `npm install --save intl`.
69 | /**
70 | * Need to import at least one locale-data with intl.
71 | */
72 | // import 'intl/locale-data/jsonp/en';
73 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | form.conf-form{
3 | background-color: #dbdbdb;
4 | border-radius: 4px;
5 | padding: 10px;
6 | }
7 | div.validation-error{
8 | color: red;
9 | text-align: center;
10 | }
11 |
12 | button:hover,a.btn:hover{
13 | cursor: pointer;
14 | }
15 |
16 |
17 | .abc-checkbox input[type=checkbox]:checked + label:after {
18 | font-family: 'Glyphicons Halflings';
19 | content: "\e013";
20 | }
21 |
22 | .abc-checkbox label:after {
23 | padding-left: 4px;
24 | padding-top: 2px;
25 | font-size: 9px;
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "baseUrl": "./",
6 | "module": "es2015",
7 | "types": []
8 | },
9 | "exclude": [
10 | "test.ts",
11 | "**/*.spec.ts"
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | },
13 | "files": [
14 | "test.ts"
15 | ],
16 | "include": [
17 | "**/*.spec.ts",
18 | "**/*.d.ts"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "outDir": "./dist/out-tsc",
5 | "sourceMap": true,
6 | "declaration": false,
7 | "moduleResolution": "node",
8 | "emitDecoratorMetadata": true,
9 | "experimentalDecorators": true,
10 | "target": "es5",
11 | "typeRoots": [
12 | "node_modules/@types"
13 | ],
14 | "lib": [
15 | "es2017",
16 | "dom"
17 | ]
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AngularCrudFrontend/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "eofline": true,
15 | "forin": true,
16 | "import-blacklist": [
17 | true,
18 | "rxjs"
19 | ],
20 | "import-spacing": true,
21 | "indent": [
22 | true,
23 | "spaces"
24 | ],
25 | "interface-over-type-literal": true,
26 | "label-position": true,
27 | "max-line-length": [
28 | true,
29 | 140
30 | ],
31 | "member-access": false,
32 | "member-ordering": [
33 | true,
34 | {
35 | "order": [
36 | "static-field",
37 | "instance-field",
38 | "static-method",
39 | "instance-method"
40 | ]
41 | }
42 | ],
43 | "no-arg": true,
44 | "no-bitwise": true,
45 | "no-console": [
46 | true,
47 | "debug",
48 | "info",
49 | "time",
50 | "timeEnd",
51 | "trace"
52 | ],
53 | "no-construct": true,
54 | "no-debugger": true,
55 | "no-duplicate-super": true,
56 | "no-empty": false,
57 | "no-empty-interface": true,
58 | "no-eval": true,
59 | "no-inferrable-types": [
60 | true,
61 | "ignore-params"
62 | ],
63 | "no-misused-new": true,
64 | "no-non-null-assertion": true,
65 | "no-shadowed-variable": true,
66 | "no-string-literal": false,
67 | "no-string-throw": true,
68 | "no-switch-case-fall-through": true,
69 | "no-trailing-whitespace": true,
70 | "no-unnecessary-initializer": true,
71 | "no-unused-expression": true,
72 | "no-use-before-declare": true,
73 | "no-var-keyword": true,
74 | "object-literal-sort-keys": false,
75 | "one-line": [
76 | true,
77 | "check-open-brace",
78 | "check-catch",
79 | "check-else",
80 | "check-whitespace"
81 | ],
82 | "prefer-const": true,
83 | "quotemark": [
84 | true,
85 | "single"
86 | ],
87 | "radix": true,
88 | "semicolon": [
89 | true,
90 | "always"
91 | ],
92 | "triple-equals": [
93 | true,
94 | "allow-null-check"
95 | ],
96 | "typedef-whitespace": [
97 | true,
98 | {
99 | "call-signature": "nospace",
100 | "index-signature": "nospace",
101 | "parameter": "nospace",
102 | "property-declaration": "nospace",
103 | "variable-declaration": "nospace"
104 | }
105 | ],
106 | "typeof-compare": true,
107 | "unified-signatures": true,
108 | "variable-name": false,
109 | "whitespace": [
110 | true,
111 | "check-branch",
112 | "check-decl",
113 | "check-operator",
114 | "check-separator",
115 | "check-type"
116 | ],
117 | "directive-selector": [
118 | true,
119 | "attribute",
120 | "app",
121 | "camelCase"
122 | ],
123 | "component-selector": [
124 | true,
125 | "element",
126 | "app",
127 | "kebab-case"
128 | ],
129 | "use-input-property-decorator": true,
130 | "use-output-property-decorator": true,
131 | "use-host-property-decorator": true,
132 | "no-input-rename": true,
133 | "no-output-rename": true,
134 | "use-life-cycle-interface": true,
135 | "use-pipe-transform-interface": true,
136 | "component-class-suffix": true,
137 | "directive-class-suffix": true,
138 | "invoke-injectable": true
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SpringBootAngular4Crud
2 |
3 | 
4 |
5 | # Angular 4 Frontend
6 |
7 | This project was generated to make crud operations via ANGULAR 4.
8 |
9 | ## SpringBootCrudApi
10 |
11 | RestFul Service uses following Technologies:
12 |
13 | * Spring-boot
14 | * Hibernate
15 | * JaCoCo
16 | * H2 DB
17 | * Swagger2
18 |
19 | ## Build
20 |
21 | Run mvn clean install
22 |
23 | ## Run
24 |
25 | First run SpringBootCrudApi then run Angular4 project.
26 |
27 | ## SpringBootService
28 |
29 | Run spring-boot-run.
30 |
31 | ## Angular
32 | On the package.json directory for angular run in order :
33 |
34 | * npm install
35 | * ng serve
36 |
37 | Add/Remove/Edit Configurations on http://localhost:4200/
38 |
39 | ## Running Integration Test
40 |
41 | Run mvn clean verify -P integration-test
42 |
43 | ## Running Service Unit Tests
44 |
45 | Run mvn clean verify -P all-tests
46 |
47 | ## Documentation
48 |
49 | To get more look at http://localhost:8080/swagger-ui.html#/
50 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/SpringBootCrudApi/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enesacikoglu/SpringBootAngular4Crud/1608cd1db98791b23a34580ef4284cbc4daf2177/SpringBootCrudApi/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/SpringBootCrudApi/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
2 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 |
8 | com.cengenes
9 | SpringBootCrudApi
10 | 1.0.0
11 | jar
12 |
13 | DynamicConfigurationService
14 | Demo project for Spring Boot
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-parent
19 | 1.5.9.RELEASE
20 |
21 |
22 |
23 |
24 | 2.7.0
25 | UTF-8
26 | UTF-8
27 | 1.8
28 | 0.7.9
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-thymeleaf
36 |
37 |
38 |
39 |
40 | io.springfox
41 | springfox-swagger2
42 | ${springfox-swagger2.version}
43 |
44 |
45 | io.springfox
46 | springfox-swagger-ui
47 | ${springfox-swagger2.version}
48 |
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-starter-actuator
53 |
54 |
55 | org.springframework.boot
56 | spring-boot-actuator-docs
57 |
58 |
59 | org.springframework.boot
60 | spring-boot-starter-data-jpa
61 |
62 |
63 |
64 | org.springframework.boot
65 | spring-boot-starter-web
66 |
67 |
68 |
69 | org.springframework.boot
70 | spring-boot-devtools
71 | runtime
72 |
73 |
74 | com.h2database
75 | h2
76 | runtime
77 |
78 |
79 | org.springframework.boot
80 | spring-boot-starter-test
81 | test
82 |
83 |
84 |
85 |
86 |
87 |
88 | org.springframework.boot
89 | spring-boot-maven-plugin
90 |
91 |
92 | org.jacoco
93 | jacoco-maven-plugin
94 | ${org.jacoco.version}
95 |
96 |
97 |
98 | prepare-agent
99 |
100 |
101 |
102 | report
103 | test
104 |
105 | report
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/DynamicConfigurationServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class DynamicConfigurationServiceApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(DynamicConfigurationServiceApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/conf/LocalizationConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.conf;
2 |
3 | import java.util.Locale;
4 |
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.context.support.ResourceBundleMessageSource;
8 | import org.springframework.web.servlet.LocaleResolver;
9 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
11 | import org.springframework.web.servlet.i18n.CookieLocaleResolver;
12 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
13 |
14 | /**
15 | *
16 | * @author enes.acikoglu
17 | *
18 | */
19 |
20 | @Configuration
21 | public class LocalizationConfiguration extends WebMvcConfigurerAdapter {
22 |
23 | @Bean
24 | public LocaleResolver localeResolver() {
25 | CookieLocaleResolver slr = new CookieLocaleResolver();
26 | slr.setDefaultLocale(new Locale("tr"));
27 | return slr;
28 | }
29 |
30 | @Bean
31 | public ResourceBundleMessageSource messageSource() {
32 | ResourceBundleMessageSource source = new ResourceBundleMessageSource();
33 | source.setBasenames("i18n/messages");
34 | source.setUseCodeAsDefaultMessage(true);
35 | source.setDefaultEncoding("UTF-8");
36 | return source;
37 | }
38 |
39 | @Bean
40 | public LocaleChangeInterceptor localeChangeInterceptor() {
41 | LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
42 | localeChangeInterceptor.setParamName("lang");
43 | return localeChangeInterceptor;
44 | }
45 |
46 | @Override
47 | public void addInterceptors(InterceptorRegistry registry) {
48 | registry.addInterceptor(localeChangeInterceptor());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/conf/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.conf;
2 |
3 | import static springfox.documentation.builders.PathSelectors.regex;
4 |
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | import com.google.common.base.Predicate;
9 |
10 | import springfox.documentation.builders.RequestHandlerSelectors;
11 | import springfox.documentation.spi.DocumentationType;
12 | import springfox.documentation.spring.web.plugins.Docket;
13 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
14 |
15 | @Configuration
16 | @EnableSwagger2
17 | public class SwaggerConfig {
18 | @Bean
19 | public Docket api() {
20 | return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(postPaths())
21 | .build();
22 |
23 | }
24 |
25 | private Predicate postPaths() {
26 | return regex("/api.*");
27 | }
28 | }
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/controller/ConfigurationAngularController.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.controller;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.validation.BindingResult;
7 | import org.springframework.web.bind.annotation.CrossOrigin;
8 | import org.springframework.web.bind.annotation.DeleteMapping;
9 | import org.springframework.web.bind.annotation.GetMapping;
10 | import org.springframework.web.bind.annotation.PathVariable;
11 | import org.springframework.web.bind.annotation.PostMapping;
12 | import org.springframework.web.bind.annotation.PutMapping;
13 | import org.springframework.web.bind.annotation.RequestBody;
14 | import org.springframework.web.bind.annotation.RequestMapping;
15 |
16 | import org.springframework.web.bind.annotation.ResponseStatus;
17 | import org.springframework.web.bind.annotation.RestController;
18 | import com.cengenes.configuration.api.entity.Configuration;
19 | import com.cengenes.configuration.api.repository.ConfigurationRepository;
20 |
21 | @RestController
22 | @RequestMapping("/api/ang/")
23 | @CrossOrigin(origins = "http://localhost:4200", allowedHeaders = "*")
24 | public class ConfigurationAngularController {
25 |
26 | @Autowired
27 | private ConfigurationRepository configurationRepository;
28 |
29 | @GetMapping("/configuration/{id}")
30 | public ResponseEntity> getConfigurationById(@PathVariable Long id) {
31 |
32 | return new ResponseEntity<>(configurationRepository.findOne(id), HttpStatus.OK);
33 | }
34 |
35 | @PostMapping("/configuration")
36 | public ResponseEntity> saveConfiguration(@RequestBody Configuration request) {
37 |
38 | return new ResponseEntity<>(configurationRepository.save(request), HttpStatus.CREATED);
39 | }
40 |
41 | @GetMapping("/configurations")
42 | public ResponseEntity> findAllConfigurations() {
43 |
44 | return new ResponseEntity<>(configurationRepository.findAll(), HttpStatus.OK);
45 | }
46 |
47 | @GetMapping("/configuration/appname/{appname}")
48 | public ResponseEntity> getAllActiveConfigurationsByApplicationName(@PathVariable String appname) {
49 |
50 | return new ResponseEntity<>(configurationRepository.findByApplicationNameAndIsActive(appname, Boolean.TRUE),
51 | HttpStatus.OK);
52 | }
53 |
54 | @PutMapping("/configuration/{id}")
55 | public ResponseEntity> updateConfiguration(@RequestBody Configuration request, BindingResult result) {
56 |
57 | Configuration update = configurationRepository.saveAndFlush(request);
58 |
59 | return new ResponseEntity<>(update, HttpStatus.OK);
60 | }
61 |
62 | @DeleteMapping("/configuration/{id}")
63 | @ResponseStatus(HttpStatus.NO_CONTENT)
64 | public void delete(@PathVariable Long id) {
65 | configurationRepository.delete(id);
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/controller/ControllerExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.controller;
2 |
3 | import java.util.Locale;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 |
7 | import org.springframework.context.MessageSource;
8 | import org.springframework.context.i18n.LocaleContextHolder;
9 | import org.springframework.http.HttpStatus;
10 | import org.springframework.web.bind.annotation.ExceptionHandler;
11 | import org.springframework.web.bind.annotation.ResponseStatus;
12 | import org.springframework.web.bind.annotation.RestControllerAdvice;
13 |
14 | import com.cengenes.configuration.api.dto.Response;
15 | import com.cengenes.configuration.api.exception.EntityNotFoundException;
16 | import com.cengenes.configuration.api.exception.MissingMandatoryFieldException;
17 | import com.cengenes.configuration.api.types.RequestStatus;
18 |
19 | /**
20 | * @author enes.acikoglu
21 | */
22 | @RestControllerAdvice
23 | public class ControllerExceptionHandler {
24 |
25 | private MessageSource messageSource;
26 |
27 | public ControllerExceptionHandler(MessageSource messageSource) {
28 | this.messageSource = messageSource;
29 | }
30 |
31 | @ExceptionHandler(EntityNotFoundException.class)
32 | @ResponseStatus(HttpStatus.NOT_FOUND)
33 | public Response handleNotFoundException(HttpServletRequest request, Exception exception) {
34 | return createLocalizedResponse(exception);
35 | }
36 |
37 | @ExceptionHandler(MissingMandatoryFieldException.class)
38 | @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
39 | public Response handleMissingFieldException(HttpServletRequest request, Exception exception) {
40 | return createLocalizedResponse(exception);
41 | }
42 |
43 | /**
44 | * Parse exception that is configured with localization ENG/TR languages.
45 | *
46 | * @param exception
47 | * @return Custom Response Message.
48 | */
49 | private Response createLocalizedResponse(Exception exception) {
50 |
51 | Response response = new Response();
52 |
53 | Locale locale = LocaleContextHolder.getLocale();
54 | String message = messageSource.getMessage(exception.getMessage(), null, locale);
55 | String[] split = message.split(";");
56 | response.setErrorCode(split[0]);
57 | response.setErrorMessage(split[1]);
58 |
59 | response.setStatus(RequestStatus.FAILURE);
60 | return response;
61 | }
62 | }
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/converter/ConfigurationDtoToEntityConverter.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.converter;
2 |
3 | import org.springframework.core.convert.converter.Converter;
4 | import org.springframework.stereotype.Component;
5 |
6 | import com.cengenes.configuration.api.dto.ConfigurationDto;
7 | import com.cengenes.configuration.api.entity.Configuration;
8 |
9 | @Component
10 | public class ConfigurationDtoToEntityConverter implements Converter {
11 |
12 | @Override
13 | public Configuration convert(ConfigurationDto dto) {
14 |
15 | Configuration entity = new Configuration();
16 |
17 | entity.setName(dto.getName());
18 | entity.setType(dto.getType());
19 | entity.setValue(dto.getValue());
20 | entity.setIsActive(dto.getIsActive());
21 | entity.setApplicationName(dto.getApplicationName());
22 |
23 | return entity;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/converter/ConfigurationEntityToDtoConverter.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.converter;
2 |
3 | import org.springframework.core.convert.converter.Converter;
4 | import org.springframework.stereotype.Component;
5 |
6 | import com.cengenes.configuration.api.dto.ConfigurationDto;
7 | import com.cengenes.configuration.api.entity.Configuration;
8 |
9 | @Component
10 | public class ConfigurationEntityToDtoConverter implements Converter {
11 |
12 | @Override
13 | public ConfigurationDto convert(Configuration entity) {
14 |
15 | ConfigurationDto configurationDto = new ConfigurationDto();
16 |
17 | configurationDto.setName(entity.getName());
18 | configurationDto.setType(entity.getType());
19 | configurationDto.setValue(entity.getValue());
20 | configurationDto.setIsActive(entity.getIsActive());
21 | configurationDto.setApplicationName(entity.getApplicationName());
22 |
23 | return configurationDto;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/dto/ConfigurationDto.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.dto;
2 |
3 | import javax.validation.constraints.NotNull;
4 |
5 | public class ConfigurationDto {
6 |
7 | @NotNull
8 | private String name;
9 |
10 | @NotNull
11 | private String type;
12 |
13 | @NotNull
14 | private String value;
15 |
16 | @NotNull
17 | private Boolean isActive;
18 |
19 | @NotNull
20 | private String applicationName;
21 |
22 | public String getName() {
23 | return name;
24 | }
25 |
26 | public void setName(String name) {
27 | this.name = name;
28 | }
29 |
30 | public String getType() {
31 | return type;
32 | }
33 |
34 | public void setType(String type) {
35 | this.type = type;
36 | }
37 |
38 | public String getValue() {
39 | return value;
40 | }
41 |
42 | public void setValue(String value) {
43 | this.value = value;
44 | }
45 |
46 | public Boolean getIsActive() {
47 | return isActive;
48 | }
49 |
50 | public void setIsActive(Boolean isActive) {
51 | this.isActive = isActive;
52 | }
53 |
54 | public String getApplicationName() {
55 | return applicationName;
56 | }
57 |
58 | public void setApplicationName(String applicationName) {
59 | this.applicationName = applicationName;
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return "ConfigurationDto [name=" + name + ", type=" + type + ", value=" + value + ", isActive=" + isActive
65 | + ", applicationName=" + applicationName + "]";
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/dto/Response.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.dto;
2 |
3 | import com.cengenes.configuration.api.types.RequestStatus;
4 |
5 | /**
6 | * @author enes.acikoglu
7 | */
8 | public class Response {
9 |
10 | private RequestStatus status;
11 | private String errorCode;
12 | private String errorMessage;
13 |
14 | public RequestStatus getStatus() {
15 | return status;
16 | }
17 |
18 | public void setStatus(RequestStatus status) {
19 | this.status = status;
20 | }
21 |
22 | public String getErrorCode() {
23 | return errorCode;
24 | }
25 |
26 | public void setErrorCode(String errorCode) {
27 | this.errorCode = errorCode;
28 | }
29 |
30 | public String getErrorMessage() {
31 | return errorMessage;
32 | }
33 |
34 | public void setErrorMessage(String errorMessage) {
35 | this.errorMessage = errorMessage;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/entity/Configuration.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.entity;
2 |
3 | import java.util.Date;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Entity;
7 | import javax.persistence.GeneratedValue;
8 | import javax.persistence.GenerationType;
9 | import javax.persistence.Id;
10 | import javax.persistence.Table;
11 | import javax.persistence.Temporal;
12 | import javax.persistence.TemporalType;
13 |
14 | import org.springframework.data.annotation.CreatedDate;
15 | import org.springframework.data.annotation.LastModifiedDate;
16 |
17 | @Entity
18 | @Table(name = "configuration")
19 | public class Configuration {
20 |
21 | @Id
22 | @GeneratedValue(strategy = GenerationType.TABLE)
23 | @Column(name = "ID")
24 | private Long id;
25 |
26 | @Column(name = "NAME")
27 | private String name;
28 |
29 | @Column(name = "TYPE_")
30 | private String type;
31 |
32 | @Column(name = "VALUE_")
33 | private String value;
34 |
35 | @Column(name = "ISACTIVE")
36 | private Boolean isActive;
37 |
38 | @Column(name = "APPLICATION_NAME")
39 | private String applicationName;
40 |
41 | @Column(nullable = true, updatable = false)
42 | @Temporal(TemporalType.TIMESTAMP)
43 | @CreatedDate
44 | private Date createdAt;
45 |
46 | @Column(nullable = true)
47 | @Temporal(TemporalType.TIMESTAMP)
48 | @LastModifiedDate
49 | private Date updatedAt;
50 |
51 | public Long getId() {
52 | return id;
53 | }
54 |
55 | public void setId(Long id) {
56 | this.id = id;
57 | }
58 |
59 | public String getName() {
60 | return name;
61 | }
62 |
63 | public void setName(String name) {
64 | this.name = name;
65 | }
66 |
67 | public String getType() {
68 | return type;
69 | }
70 |
71 | public void setType(String type) {
72 | this.type = type;
73 | }
74 |
75 | public String getValue() {
76 | return value;
77 | }
78 |
79 | public void setValue(String value) {
80 | this.value = value;
81 | }
82 |
83 | public Boolean getIsActive() {
84 | return isActive;
85 | }
86 |
87 | public void setIsActive(Boolean isActive) {
88 | this.isActive = isActive;
89 | }
90 |
91 | public String getApplicationName() {
92 | return applicationName;
93 | }
94 |
95 | public void setApplicationName(String applicationName) {
96 | this.applicationName = applicationName;
97 | }
98 |
99 | @Override
100 | public String toString() {
101 | return "Configuration [id=" + id + ", name=" + name + ", type=" + type + ", value=" + value + ", isActive="
102 | + isActive + ", applicationName=" + applicationName + "]";
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/exception/DynamicConfigurationApiException.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.exception;
2 |
3 | /**
4 | * @author enes.acikoglu
5 | */
6 | public abstract class DynamicConfigurationApiException extends RuntimeException {
7 |
8 | /**
9 | *
10 | */
11 | private static final long serialVersionUID = 1256671219899520653L;
12 |
13 | public DynamicConfigurationApiException(String message) {
14 | super(message);
15 | }
16 |
17 | public DynamicConfigurationApiException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/exception/EntityNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.exception;
2 |
3 | public class EntityNotFoundException extends DynamicConfigurationApiException {
4 |
5 | /**
6 | *
7 | */
8 | private static final long serialVersionUID = 1595331078979818402L;
9 |
10 | public EntityNotFoundException(String message) {
11 | super(message);
12 | }
13 |
14 | public EntityNotFoundException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 | }
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/exception/MissingMandatoryFieldException.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.exception;
2 |
3 | public class MissingMandatoryFieldException extends DynamicConfigurationApiException {
4 |
5 | /**
6 | *
7 | */
8 | private static final long serialVersionUID = -1901236013226031468L;
9 |
10 | public MissingMandatoryFieldException(String message) {
11 | super(message);
12 | }
13 |
14 | public MissingMandatoryFieldException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 | }
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/repository/ConfigurationRepository.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.repository;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.jpa.repository.JpaRepository;
6 |
7 | import com.cengenes.configuration.api.entity.Configuration;
8 |
9 | public interface ConfigurationRepository extends JpaRepository {
10 |
11 | List findByApplicationNameAndIsActive(String applicationName, Boolean isActive);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/service/ConfigurationService.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.domain.Page;
6 | import org.springframework.data.domain.Pageable;
7 |
8 | import com.cengenes.configuration.api.dto.ConfigurationDto;
9 | import com.cengenes.configuration.api.entity.Configuration;
10 |
11 | public interface ConfigurationService {
12 |
13 | Page findAll(Pageable pageable);
14 |
15 | ConfigurationDto findOne(Long id);
16 |
17 | List findActiveApplicationsByName(String applicationName);
18 |
19 | Configuration save(ConfigurationDto entity);
20 |
21 | ConfigurationDto update(Long id, ConfigurationDto request);
22 |
23 | void delete(Long id);
24 |
25 | List findAll();
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/service/imp/ConfigurationServiceImp.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.service.imp;
2 |
3 | import java.util.List;
4 | import java.util.stream.Collectors;
5 |
6 | import javax.transaction.Transactional;
7 |
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.data.domain.Page;
10 | import org.springframework.data.domain.Pageable;
11 | import org.springframework.stereotype.Service;
12 |
13 | import com.cengenes.configuration.api.converter.ConfigurationDtoToEntityConverter;
14 | import com.cengenes.configuration.api.converter.ConfigurationEntityToDtoConverter;
15 | import com.cengenes.configuration.api.dto.ConfigurationDto;
16 | import com.cengenes.configuration.api.entity.Configuration;
17 | import com.cengenes.configuration.api.exception.EntityNotFoundException;
18 | import com.cengenes.configuration.api.repository.ConfigurationRepository;
19 | import com.cengenes.configuration.api.service.ConfigurationService;
20 | import com.cengenes.configuration.api.validator.ConfigurationInfoValidator;
21 |
22 | @Service
23 | @Transactional
24 | public class ConfigurationServiceImp implements ConfigurationService {
25 |
26 | @Autowired
27 | private ConfigurationRepository configurationRepository;
28 |
29 | @Autowired
30 | private ConfigurationEntityToDtoConverter entityToDtoConverter;
31 |
32 | @Autowired
33 | private ConfigurationDtoToEntityConverter dtoToEntityConverter;
34 |
35 | @Autowired
36 | private ConfigurationInfoValidator configurationInfoValidator;
37 |
38 | @Override
39 | public ConfigurationDto findOne(Long id) {
40 |
41 | Configuration configuration = configurationRepository.findOne(id);
42 |
43 | if (configuration == null)
44 | throw new EntityNotFoundException("entity.notFound");
45 |
46 | return entityToDtoConverter.convert(configuration);
47 | }
48 |
49 | @Override
50 | public Configuration save(ConfigurationDto entity) {
51 | configurationInfoValidator.validate(entity);
52 | return configurationRepository.save(dtoToEntityConverter.convert(entity));
53 | }
54 |
55 | @Override
56 | public List findActiveApplicationsByName(String applicationName) {
57 |
58 | List configurations = configurationRepository.findByApplicationNameAndIsActive(applicationName,
59 | Boolean.TRUE);
60 |
61 | if (configurations.isEmpty())
62 | throw new EntityNotFoundException("entity.notFound");
63 |
64 | return configurations.parallelStream().map(entityToDtoConverter::convert).collect(Collectors.toList());
65 | }
66 |
67 | @Override
68 | public ConfigurationDto update(Long id, ConfigurationDto request) {
69 |
70 | configurationInfoValidator.validate(request);
71 |
72 | Configuration existingEntity = configurationRepository.findOne(id);
73 |
74 | if (existingEntity == null)
75 | throw new EntityNotFoundException("entity.notFound");
76 |
77 | Configuration newEntity = dtoToEntityConverter.convert(request);
78 |
79 | newEntity.setId(existingEntity.getId());
80 |
81 | return entityToDtoConverter.convert((configurationRepository.save(newEntity)));
82 | }
83 |
84 | @Override
85 | public void delete(Long id) {
86 |
87 | Configuration existingEntity = configurationRepository.findOne(id);
88 |
89 | if (existingEntity == null)
90 | throw new EntityNotFoundException("entity.notFound");
91 |
92 | configurationRepository.delete(id);
93 |
94 | }
95 |
96 | @Override
97 | public Page findAll(Pageable pageable) {
98 | return configurationRepository.findAll(pageable);
99 | }
100 |
101 | @Override
102 | public List findAll() {
103 | return configurationRepository.findAll().parallelStream().map(entityToDtoConverter::convert)
104 | .collect(Collectors.toList());
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/types/RequestStatus.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.types;
2 |
3 | public enum RequestStatus {
4 | SUCCESS, FAILURE;
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/java/com/cengenes/configuration/api/validator/ConfigurationInfoValidator.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.validator;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | import com.cengenes.configuration.api.dto.ConfigurationDto;
6 | import com.cengenes.configuration.api.exception.MissingMandatoryFieldException;
7 |
8 | @Component
9 | public class ConfigurationInfoValidator {
10 |
11 | public void validate(ConfigurationDto configurationDto) {
12 |
13 | if (configurationDto == null || configurationDto.getName() == null
14 | || configurationDto.getApplicationName() == null || configurationDto.getType() == null
15 | || configurationDto.getValue() == null || configurationDto.getIsActive() == null)
16 |
17 | throw new MissingMandatoryFieldException("missing.field");
18 |
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | security.user.name=test
2 | security.user.password=1
3 |
4 |
5 | # H2
6 | spring.h2.console.enabled=true
7 | spring.h2.console.path=/h2
8 |
9 |
10 | spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
11 | spring.datasource.driverClassName=org.h2.Driver
12 | spring.datasource.username=test
13 | spring.datasource.password=1
14 | spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
15 |
16 |
17 |
18 |
19 | #spring h2 in-memory database enabled
20 | spring.datasource.platform=h2
21 | spring.datasource.continueOnError=false
22 | spring.jpa.hibernate.ddl-auto=create-drop
23 | spring.datasource.data=classpath:/db-init/configuration/configuration-h2.sql
24 | spring.jpa.properties.hibernate.show_sql=true
25 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/resources/db-init/configuration/configuration-h2.sql:
--------------------------------------------------------------------------------
1 | insert into configuration(ID,NAME,TYPE_,VALUE_,ISACTIVE,APPLICATION_NAME) values(9999,'AppName','String','Url',1,'EnesApp');
2 | insert into configuration(ID,NAME,TYPE_,VALUE_,ISACTIVE,APPLICATION_NAME) values(10000,'TimeOut','Integer','61',1,'EnesApp');
3 | insert into configuration(ID,NAME,TYPE_,VALUE_,ISACTIVE,APPLICATION_NAME) values(10001,'Count','Double','100000',1,'SampleApp');
4 | insert into configuration(ID,NAME,TYPE_,VALUE_,ISACTIVE,APPLICATION_NAME) values(10002,'IsChanged','Boolean','false',1,'EnesApp');
5 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/resources/i18n/messages_en.properties:
--------------------------------------------------------------------------------
1 | entity.notFound = 1;Specified entity does not exist
2 | missing.field = 2;Mandatory fields can not be empty
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/main/resources/i18n/messages_tr.properties:
--------------------------------------------------------------------------------
1 | entity.notFound = 1;Belirtilen nesne sistemde bulunmuyor
2 | missing.field = 2;Zorunlu alanlar bos gecilemez
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/test/java/com/cengenes/configuration/api/conf/BaseIT.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.conf;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 | import org.springframework.test.annotation.DirtiesContext;
6 | import org.springframework.test.annotation.DirtiesContext.ClassMode;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | @RunWith(SpringRunner.class)
10 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
11 | @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
12 | public abstract class BaseIT {
13 | }
14 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/test/java/com/cengenes/configuration/api/conf/BaseMockitoTest.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.conf;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.mockito.runners.MockitoJUnitRunner;
5 |
6 | @RunWith(MockitoJUnitRunner.class)
7 | public abstract class BaseMockitoTest {
8 | }
9 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/test/java/com/cengenes/configuration/api/controller/ConfigurationControllerIT.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.controller;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import static org.hamcrest.CoreMatchers.equalTo;
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 |
7 | import java.util.List;
8 |
9 | import org.hamcrest.MatcherAssert;
10 | import org.hamcrest.Matchers;
11 | import org.junit.Test;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.test.web.client.TestRestTemplate;
14 | import org.springframework.http.HttpStatus;
15 | import org.springframework.http.ResponseEntity;
16 |
17 | import com.cengenes.configuration.api.conf.BaseIT;
18 | import com.cengenes.configuration.api.dto.ConfigurationDto;
19 | import com.cengenes.configuration.api.dto.Response;
20 | import com.cengenes.configuration.api.entity.Configuration;
21 | import com.cengenes.configuration.api.repository.ConfigurationRepository;
22 | import com.cengenes.configuration.api.types.RequestStatus;
23 |
24 | public class ConfigurationControllerIT extends BaseIT {
25 |
26 | @Autowired
27 | TestRestTemplate testRestTemplate;
28 |
29 | @Autowired
30 | ConfigurationRepository confgurationRepository;
31 |
32 | @Test
33 | public void should_create_configuration() throws Exception {
34 | // Given
35 | ConfigurationDto request = this.createSampleConfigurationLoginformation();
36 |
37 | // When
38 | ResponseEntity responseEntity = testRestTemplate.postForEntity("/api/ang/configuration/",
39 | request, Configuration.class);
40 |
41 | // Then
42 | assertThat(responseEntity).isNotNull();
43 | assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
44 |
45 | Configuration configurationResponse = responseEntity.getBody();
46 | assertThat(configurationResponse).isNotNull();
47 | assertThat(configurationResponse.getId()).isNotNull();
48 | }
49 |
50 | @Test
51 | public void should_return_all_configurations() {
52 |
53 | confgurationRepository.save(new Configuration());
54 | confgurationRepository.save(new Configuration());
55 | confgurationRepository.save(new Configuration());
56 |
57 | ResponseEntity entityList = testRestTemplate.getForEntity("/api/ang/configurations", List.class);
58 |
59 | assertThat(entityList).isNotNull();
60 | assertThat(entityList.getStatusCode()).isEqualTo(HttpStatus.OK);
61 | assertThat(entityList.getBody().size()).isGreaterThan(2);
62 | }
63 |
64 | @Test
65 | public void should_post_return_406_for_missing_fields() throws Exception {
66 |
67 | // given
68 | ConfigurationDto request = new ConfigurationDto();
69 |
70 | // when
71 | ResponseEntity responseEntity = testRestTemplate.postForEntity("/api/ang/configuration", request,
72 | Response.class);
73 |
74 | // then
75 | assertThat(responseEntity.getBody().getStatus(), equalTo(RequestStatus.FAILURE));
76 | assertThat(responseEntity.getBody().getErrorCode(), equalTo("2"));
77 | assertThat(responseEntity.getBody().getErrorMessage(), equalTo("Zorunlu alanlar bos gecilemez"));
78 | assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_ACCEPTABLE);
79 | MatcherAssert.assertThat(responseEntity.getStatusCode(), Matchers.equalTo(HttpStatus.NOT_ACCEPTABLE));
80 |
81 | }
82 |
83 | @Test
84 | public void should_get_return_404_for_invalid_application_name() throws Exception {
85 |
86 | // given
87 | final String WRONG_APP_NAME = "Invalid App";
88 |
89 | // when
90 | ResponseEntity responseEntity = testRestTemplate
91 | .getForEntity("/api/ang/configuration/appname/" + WRONG_APP_NAME, Response.class);
92 |
93 | // then
94 | assertThat(responseEntity.getBody().getStatus(), equalTo(RequestStatus.FAILURE));
95 | assertThat(responseEntity.getBody().getErrorCode(), equalTo("1"));
96 | assertThat(responseEntity.getBody().getErrorMessage(), equalTo("Belirtilen nesne sistemde bulunmuyor"));
97 | assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
98 | MatcherAssert.assertThat(responseEntity.getStatusCode(), Matchers.equalTo(HttpStatus.NOT_FOUND));
99 |
100 | }
101 |
102 | private final ConfigurationDto createSampleConfigurationLoginformation() {
103 |
104 | ConfigurationDto request = new ConfigurationDto();
105 | request.setApplicationName("Trendyol");
106 | request.setName("Time Out");
107 | request.setType("Integer");
108 | request.setValue("6161");
109 | request.setIsActive(false);
110 |
111 | return request;
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/SpringBootCrudApi/src/test/java/com/cengenes/configuration/api/service/ConfigurationServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.cengenes.configuration.api.service;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import static org.mockito.Matchers.any;
5 | import static org.mockito.Mockito.when;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import org.junit.Before;
11 | import org.junit.Test;
12 | import org.mockito.InjectMocks;
13 | import org.mockito.Mock;
14 |
15 | import com.cengenes.configuration.api.conf.BaseMockitoTest;
16 | import com.cengenes.configuration.api.converter.ConfigurationDtoToEntityConverter;
17 | import com.cengenes.configuration.api.converter.ConfigurationEntityToDtoConverter;
18 | import com.cengenes.configuration.api.dto.ConfigurationDto;
19 | import com.cengenes.configuration.api.entity.Configuration;
20 | import com.cengenes.configuration.api.repository.ConfigurationRepository;
21 | import com.cengenes.configuration.api.service.imp.ConfigurationServiceImp;
22 | import com.cengenes.configuration.api.validator.ConfigurationInfoValidator;
23 |
24 | public class ConfigurationServiceTest extends BaseMockitoTest {
25 |
26 | @InjectMocks
27 | private ConfigurationServiceImp configurationService;
28 |
29 | @Mock
30 | public ConfigurationRepository configurationRepository;
31 |
32 | @Mock
33 | private ConfigurationEntityToDtoConverter entityToDtoConverter;
34 |
35 | @Mock
36 | private ConfigurationDtoToEntityConverter dtoToEntityConverter;
37 |
38 | @Mock
39 | private ConfigurationInfoValidator configurationInfoValidator;
40 |
41 | public Configuration entity;
42 |
43 | @Before
44 | public void before() {
45 |
46 | entity = new Configuration();
47 | entity.setApplicationName("Trendyol");
48 | entity.setName("Time Out");
49 | entity.setType("Integer");
50 | entity.setValue("6161");
51 | entity.setIsActive(true);
52 | }
53 |
54 | @Test
55 | public void should_return_one_configuration() {
56 |
57 | when(configurationRepository.findOne(1L)).thenReturn(entity);
58 | when(entityToDtoConverter.convert(entity)).thenReturn(createSampleConfigurationLoginformation());
59 |
60 | ConfigurationDto foundedConfiguration = configurationService.findOne(1L);
61 |
62 | assertThat(foundedConfiguration).isNotNull();
63 | assertThat(foundedConfiguration.getApplicationName()).isEqualTo(entity.getApplicationName());
64 | assertThat(foundedConfiguration.getName()).isNotNull();
65 | assertThat(foundedConfiguration.getName()).isEqualTo(entity.getName());
66 | assertThat(foundedConfiguration.getType()).isEqualTo(entity.getType());
67 | assertThat(foundedConfiguration.getValue()).isEqualTo(entity.getValue());
68 | assertThat(foundedConfiguration.getIsActive()).isEqualTo(entity.getIsActive());
69 | }
70 |
71 | @Test
72 | public void should_save_configuration() {
73 |
74 | when(configurationRepository.save(entity)).thenReturn(entity);
75 | when(dtoToEntityConverter.convert(any(ConfigurationDto.class))).thenReturn(entity);
76 |
77 | Configuration foundedConfiguration = configurationService.save(createSampleConfigurationLoginformation());
78 |
79 | assertThat(foundedConfiguration).isNotNull();
80 | assertThat(foundedConfiguration.getApplicationName()).isEqualTo(entity.getApplicationName());
81 | assertThat(foundedConfiguration.getName()).isNotNull();
82 | assertThat(foundedConfiguration.getName()).isEqualTo(entity.getName());
83 | assertThat(foundedConfiguration.getType()).isEqualTo(entity.getType());
84 | assertThat(foundedConfiguration.getValue()).isEqualTo(entity.getValue());
85 | assertThat(foundedConfiguration.getIsActive()).isEqualTo(entity.getIsActive());
86 | }
87 |
88 | @Test
89 | public void should_find_active_application_configration() {
90 |
91 | final String APP_NAME = "Trendyol";
92 |
93 | List mockEntityList = new ArrayList<>();
94 | mockEntityList.add(createSampleConfigurationEntity());
95 |
96 | when(configurationRepository.findByApplicationNameAndIsActive(APP_NAME, Boolean.TRUE)).thenReturn(mockEntityList);
97 | when(entityToDtoConverter.convert(any(Configuration.class)))
98 | .thenReturn(createSampleConfigurationLoginformation());
99 |
100 | List foundedConfigurationList = configurationService.findActiveApplicationsByName(APP_NAME);
101 |
102 | assertThat(foundedConfigurationList).isNotNull();
103 | assertThat(foundedConfigurationList.size()).isEqualTo(1);
104 | assertThat(foundedConfigurationList.get(0).getName()).isEqualTo(entity.getName());
105 | assertThat(foundedConfigurationList.get(0).getType()).isEqualTo(entity.getType());
106 | assertThat(foundedConfigurationList.get(0).getValue()).isEqualTo(entity.getValue());
107 | assertThat(foundedConfigurationList.get(0).getIsActive()).isEqualTo(true);
108 | }
109 |
110 | @Test
111 | public void should_find_all_configurations() {
112 |
113 | Configuration entity_I = createSampleConfigurationEntity();
114 | entity_I.setApplicationName("X");
115 |
116 | Configuration entity_II = createSampleConfigurationEntity();
117 | entity_II.setApplicationName("Y");
118 |
119 | List configurationList = new ArrayList<>();
120 | configurationList.add(entity_I);
121 | configurationList.add(entity_II);
122 |
123 | when(configurationRepository.findAll()).thenReturn(configurationList);
124 |
125 | List returnedList = configurationService.findAll();
126 | assertThat(returnedList).isNotNull();
127 | assertThat(returnedList.size()).isEqualTo(2);
128 |
129 | }
130 |
131 | private final ConfigurationDto createSampleConfigurationLoginformation() {
132 |
133 | ConfigurationDto request = new ConfigurationDto();
134 | request.setApplicationName("Trendyol");
135 | request.setName("Time Out");
136 | request.setType("Integer");
137 | request.setValue("6161");
138 | request.setIsActive(true);
139 |
140 | return request;
141 | }
142 |
143 | private final Configuration createSampleConfigurationEntity() {
144 |
145 | Configuration entity = new Configuration();
146 | entity.setApplicationName("Trendyol");
147 | entity.setName("Time Out");
148 | entity.setType("Integer");
149 | entity.setValue("6161");
150 | entity.setIsActive(true);
151 |
152 | return entity;
153 | }
154 | }
155 |
--------------------------------------------------------------------------------