diff --git a/dmp-admin/src/app/app.module.ts b/dmp-admin/src/app/app.module.ts index 2dc57045a..615c8976a 100644 --- a/dmp-admin/src/app/app.module.ts +++ b/dmp-admin/src/app/app.module.ts @@ -19,6 +19,7 @@ import { DatasetProfileService } from './services/dataset-profile.service'; import { DmpsServiceService } from './services/dmps-service.service'; import { ProjectService } from './services/project-service'; import { ServiceService } from './services/service-service'; +import { ResearcherService } from './services/researcher-service'; import { OrganisationService } from './services/organisation-service'; import { DmpProfileService } from './services/dmpprofile-service'; import { RegistryService } from './services/registry-service'; @@ -31,6 +32,8 @@ import { DmpProfileTableFilterPipe } from './pipes/dmp-profile-table-filter.pipe import { ProjectTableFilterPipe } from './pipes/project-table-filter.pipe'; import { RegistryTableFilterPipe } from './pipes/registry-table-filter.pipe'; import { OrganisationTableFilterPipe } from './pipes/organisation-table-filter.pipe'; +import { ResearcherTableFilterPipe } from './pipes/researcher-table-filter.pipe'; + import { GooggleSignInComponent } from './login/googgle-sign-in/googgle-sign-in.component'; import { MainSignInComponent } from './login/main-sign-in/main-sign-in.component'; @@ -49,6 +52,7 @@ import { DmpProfileEditorComponent } from './managers/dmp-profile-editor/dmp-pro import { OrganisationEditorComponent } from './managers/organisation-editor/organisation-editor.component'; import { RegistryEditorComponent } from './managers/registry-editor/registry-editor.component'; import { ServiceEditorComponent } from './managers/service-editor/service-editor.component'; +import { ResearcherEditorComponent } from './managers/researcher-editor/researcher-editor.component'; @@ -61,6 +65,7 @@ import { ServiceEditorComponent } from './managers/service-editor/service-editor OrganisationTableFilterPipe, RegistryTableFilterPipe, ServiceTableFilterPipe, + ResearcherTableFilterPipe, AppComponent, GooggleSignInComponent, @@ -76,7 +81,8 @@ import { ServiceEditorComponent } from './managers/service-editor/service-editor OrganisationEditorComponent, RegistryEditorComponent, ServiceEditorComponent, - MainSignInComponent + MainSignInComponent, + ResearcherEditorComponent ], imports: [ BrowserModule, @@ -90,7 +96,7 @@ import { ServiceEditorComponent } from './managers/service-editor/service-editor NgbModule.forRoot(), AppRouting ], - providers: [ DatasetsServiceService, TokenService, DmpsServiceService, + providers: [ DatasetsServiceService, TokenService, DmpsServiceService, ResearcherService, DialogService, DatasetProfileService, ProjectService, OrganisationService, DmpProfileService, RegistryService, ServiceService, NativeLoginService, HttpModule, Toolbox, HttpClient, RestBase], bootstrap: [AppComponent] diff --git a/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts b/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts index e4f88c1b4..2881383f1 100644 --- a/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts +++ b/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts @@ -45,6 +45,7 @@ export class MainSignInComponent implements OnInit { this.nativeLogin.login(this.creds.username, this.creds.password).subscribe( response => { + simple_notifier("success",null,"Successful login"); this.tokenService.setLoggedIn(true); diff --git a/dmp-admin/src/app/main-window/main-window.component.html b/dmp-admin/src/app/main-window/main-window.component.html index a98c2963c..54c8892b4 100644 --- a/dmp-admin/src/app/main-window/main-window.component.html +++ b/dmp-admin/src/app/main-window/main-window.component.html @@ -59,6 +59,13 @@
  • All services
  • + + + @@ -76,78 +83,3 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/dmp-admin/src/app/managers/dmp-editor/dmp-editor.component.ts b/dmp-admin/src/app/managers/dmp-editor/dmp-editor.component.ts index 39a4589d6..0c77497ad 100644 --- a/dmp-admin/src/app/managers/dmp-editor/dmp-editor.component.ts +++ b/dmp-admin/src/app/managers/dmp-editor/dmp-editor.component.ts @@ -137,10 +137,11 @@ export class DmpEditorComponent implements OnInit { this.dmpsServiceService.delete(dmp).subscribe( (response) => { simple_notifier("success",null,"Deleted dataset"); - console.log(response); + this.getAllDmps(false); + this.switchToTable(); }, (err) => { - + simple_notifier("danger",null,"Could not delete dmp"); } ) } diff --git a/dmp-admin/src/app/managers/dmp-profile-editor/dmp-profile-editor.component.ts b/dmp-admin/src/app/managers/dmp-profile-editor/dmp-profile-editor.component.ts index 65a9f7189..42ad076ec 100644 --- a/dmp-admin/src/app/managers/dmp-profile-editor/dmp-profile-editor.component.ts +++ b/dmp-admin/src/app/managers/dmp-profile-editor/dmp-profile-editor.component.ts @@ -111,9 +111,11 @@ export class DmpProfileEditorComponent implements OnInit { this.dmpProfileService.delete(dmpProfile).subscribe( (response) => { simple_notifier("success",null,"Deleted DMP Profile"); + this.getAllDmpProfiles(false); + this.switchToTable(); }, (err) => { - + simple_notifier("danger",null,"Could not delete DMP Profile"); } ) } diff --git a/dmp-admin/src/app/managers/organisation-editor/organisation-editor.component.ts b/dmp-admin/src/app/managers/organisation-editor/organisation-editor.component.ts index 54272a416..d91a877b5 100644 --- a/dmp-admin/src/app/managers/organisation-editor/organisation-editor.component.ts +++ b/dmp-admin/src/app/managers/organisation-editor/organisation-editor.component.ts @@ -111,10 +111,11 @@ export class OrganisationEditorComponent implements OnInit { this.organisationService.delete(organisation).subscribe( (response) => { simple_notifier("success",null,"Deleted organisation"); + this.refreshTable(false); + this.switchToTable(); }, (err) => { simple_notifier("danger",null,"Could not delete organisation"); - console.log(err); } ) } diff --git a/dmp-admin/src/app/managers/project-editor/project-editor.component.ts b/dmp-admin/src/app/managers/project-editor/project-editor.component.ts index f3218aea4..8a4703332 100644 --- a/dmp-admin/src/app/managers/project-editor/project-editor.component.ts +++ b/dmp-admin/src/app/managers/project-editor/project-editor.component.ts @@ -116,11 +116,11 @@ export class ProjectEditorComponent implements OnInit { this.projectService.delete(project).subscribe( (response) => { simple_notifier("success",null,"Deleted project"); - console.log(response); + this.getAllProjects(false); + this.switchToTable(); }, (err) => { simple_notifier("danger",null,"Could not delete project"); - console.log(err); } ) } diff --git a/dmp-admin/src/app/managers/registry-editor/registry-editor.component.ts b/dmp-admin/src/app/managers/registry-editor/registry-editor.component.ts index 007e1085b..31df22a8d 100644 --- a/dmp-admin/src/app/managers/registry-editor/registry-editor.component.ts +++ b/dmp-admin/src/app/managers/registry-editor/registry-editor.component.ts @@ -113,9 +113,11 @@ export class RegistryEditorComponent implements OnInit { this.registryService.delete(registry).subscribe( (response) => { simple_notifier("success",null,"Deleted registry"); + this.switchToTable(); + this.refreshTable(false); }, (err) => { - + simple_notifier("danger",null,"Could not delete registry"); } ) } diff --git a/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.css b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.css new file mode 100644 index 000000000..002b130b0 --- /dev/null +++ b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.css @@ -0,0 +1,33 @@ +.invisible { + display:none; +} + +.visible { + display:block; +} + +tr.hover:hover > * { + background-color: #eeeeee; +} + +.editor-container{ + padding-top: 10px; + padding-right: 10px; + padding-bottom: 10px; + padding-left: 10px; +} + +.button-150px { + max-width: 150px; +} + +.ng-template{ + text-align: right; +} + +.grayout-empty-table { + opacity: 0.6; /* Real browsers */ + filter: alpha(opacity = 60); /* MSIE */ + text-align: center; + vertical-align: middle; +} \ No newline at end of file diff --git a/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.html b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.html new file mode 100644 index 000000000..43aa334e8 --- /dev/null +++ b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.html @@ -0,0 +1,120 @@ + +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    IDLabelUriPrimaryEmailDefinitionReference
    No elements
    {{researcher.id}}{{researcher?.label}}{{researcher?.uri}}{{researcher?.primaryEmail}}{{researcher?.definition}}{{researcher?.reference}}
    + +
    +
    + + +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +

    Form value: {{ researcherEditorForm.value | json }}

    +
    + +
    + +
    + + + + + + Manage researchers + + + + Create researcher + + + Edit this researcher + + + Delete this + + + + Show full tree connections + + + \ No newline at end of file diff --git a/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.spec.ts b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.spec.ts new file mode 100644 index 000000000..88793a6a9 --- /dev/null +++ b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ResearcherEditorComponent } from './researcher-editor.component'; + +describe('ResearcherEditorComponent', () => { + let component: ResearcherEditorComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ResearcherEditorComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ResearcherEditorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.ts b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.ts new file mode 100644 index 000000000..b9c96c688 --- /dev/null +++ b/dmp-admin/src/app/managers/researcher-editor/researcher-editor.component.ts @@ -0,0 +1,134 @@ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { ResearcherService } from '../../services/researcher-service'; +import { ContextMenuComponent } from 'ngx-contextmenu'; +import { ReactiveFormsModule } from '@angular/forms'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; + +import '../../../assets/custom.js'; +declare function simple_notifier(type: string, title: string, message:string): any; + +@Component({ + selector: 'app-researcher-editor', + templateUrl: './researcher-editor.component.html', + styleUrls: ['./researcher-editor.component.css'] +}) +export class ResearcherEditorComponent implements OnInit { + + constructor(private researcherService : ResearcherService, private fb: FormBuilder) { + + } + + //whole dmp data model + tableData : any[] = new Array(); + + //researcher editor data model + editingResearcher: any = {}; + researcherEditorForm : any; + + //required by the table + public filterQuery = ""; + public rowsOnPage = 10; + //public sortBy = "email"; + public sortOrder = "asc"; + + //visibility rules for containers + tableVisible: boolean = true; + editorVisible: boolean = false; + + + // for tableIds + showIDs : boolean = false; + + + + ngOnInit() { + this.getAllResearchers(false); + this.createResearcherEditorForm(); + } + + createResearcherEditorForm(){ + this.researcherEditorForm = this.fb.group({ + id: null, + label: ['', Validators.required ], + uri: '', + primaryEmail: '', + definition: '', + reference: '' + }); + + } + + switchToTable(){ + this.tableVisible = true; + this.editorVisible = false; + } + + switchToEditor(researcherID){ + + this.tableVisible = false; + this.editorVisible = true; + if(researcherID == null){ + this.editingResearcher = {id: null, label: "", uri: "", primaryEmail: "", definition: "", reference: "" }; + } + else{ + this.editingResearcher = this.tableData.filter((researcher) => researcher.id === researcherID)[0]; + } + } + + + getAllResearchers(showNotification : boolean){ + this.researcherService.getAllResearchers().subscribe( (data) => { + this.tableData = data; + if(showNotification) + simple_notifier("info",null,"Refreshed the table"); + }); + } + + + editResearcher(researcher){ + this.switchToEditor(researcher); + } + + newResearcher(){ + this.switchToEditor(null); + } + + + + save(mouseEvent){ + this.researcherService.create(this.researcherEditorForm.value).subscribe( + response => { + simple_notifier("success",null,"Saved resercher"); + this.getAllResearchers(false); + }, + err => { + simple_notifier("danger",null,"Could not save researcher"); + } + ); + } + + delete(resercher){ + this.researcherService.delete(resercher).subscribe( + (response) => { + simple_notifier("success",null,"Deleted researcher"); + this.getAllResearchers(false); + this.switchToTable(); + }, + (err) => { + simple_notifier("danger",null,"Could not delete researcher"); + } + ) + } + + + + refreshTable($event){ + this.getAllResearchers(true); + } + + + @ViewChild(ContextMenuComponent) public basicMenu: ContextMenuComponent; + + + +} diff --git a/dmp-admin/src/app/pipes/researcher-table-filter.pipe.ts b/dmp-admin/src/app/pipes/researcher-table-filter.pipe.ts new file mode 100644 index 000000000..64d8b5c56 --- /dev/null +++ b/dmp-admin/src/app/pipes/researcher-table-filter.pipe.ts @@ -0,0 +1,29 @@ +import * as _ from "lodash"; +import {Pipe, PipeTransform} from "@angular/core"; + +@Pipe({ + name: "researcherTableFilter" +}) +export class ResearcherTableFilterPipe implements PipeTransform { + + transform(array: any[], query: string): any { + + if (query) { + + return _.filter(array, row => { + if (row.uri == null) row.uri = ""; + if (row.label == null) row.label = ""; + if (row.id == null) row.id = ""; + return ( + + row.label.indexOf(query) > -1 || + + //row.version == query || + row.id.indexOf(query) > -1 + ) + }); + + } + return array; + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/routes.ts b/dmp-admin/src/app/routes.ts index 50a463cc8..9d87c9a9e 100644 --- a/dmp-admin/src/app/routes.ts +++ b/dmp-admin/src/app/routes.ts @@ -10,6 +10,7 @@ import { ProjectEditorComponent } from './managers/project-editor/project-editor import { ServiceEditorComponent } from './managers/service-editor/service-editor.component'; import { RegistryEditorComponent } from './managers/registry-editor/registry-editor.component'; import { OrganisationEditorComponent } from './managers/organisation-editor/organisation-editor.component'; +import { ResearcherEditorComponent } from './managers/researcher-editor/researcher-editor.component'; import { MainWindowComponent } from './main-window/main-window.component'; @@ -57,6 +58,10 @@ export const routes: Routes = [ path: 'registries', component: RegistryEditorComponent }, + { + path: 'researchers', + component: ResearcherEditorComponent + }, { path: 'main', component: MainWindowComponent diff --git a/dmp-admin/src/app/services/researcher-service.ts b/dmp-admin/src/app/services/researcher-service.ts new file mode 100644 index 000000000..25ff71cdf --- /dev/null +++ b/dmp-admin/src/app/services/researcher-service.ts @@ -0,0 +1,46 @@ +import { Component, Input, OnInit, AfterViewChecked, ViewChild } from '@angular/core'; +import { HttpClient , HttpHeaders, HttpParams} from '@angular/common/http'; +import { TokenService, TokenProvider } from './login/token.service' +import { Injectable } from '@angular/core'; +import { Toolbox } from '../services/toolbox'; +import {RestBase} from './rest-base'; +import 'rxjs/Rx'; + + +@Injectable() +export class ResearcherService implements OnInit { + + + constructor(public restBase: RestBase) { + } + + ngOnInit(){ + + } + + getResearcherIdsLabels() { + return this.restBase.get("researcher/listAllLabelIDs"); + } + + getResearcherIds(){ + return this.restBase.get("researchers"); + } + + getAllResearchers(){ + return this.restBase.get("researcher/getAll"); + } + + create(researcher){ + return this.restBase.post("researcher/create", researcher); + } + + + delete(researcherID){ + var researcher = {"id": researcherID}; + return this.restBase.post("researcher/delete", researcher); + } + + +} + + diff --git a/dmp-admin/src/app/services/rest-base.ts b/dmp-admin/src/app/services/rest-base.ts index f610ef02e..dc9ff97e0 100644 --- a/dmp-admin/src/app/services/rest-base.ts +++ b/dmp-admin/src/app/services/rest-base.ts @@ -22,12 +22,13 @@ export class RestBase { restpath: string = "rest"; - loginPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/"; + loginPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/login/"; restBasePath: string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/"+this.restpath+"/"; public login(path : string, data : any){ - return this.http.post(this.loginPath + path, JSON.stringify(data)); + let options = { headers: new HttpHeaders().set('Content-Type', 'application/json') }; + return this.http.post(this.loginPath + path, JSON.stringify(data), options); } public get(path : string){ diff --git a/dmp-backend/src/main/java/entities/DataRepository.java b/dmp-backend/src/main/java/entities/DataRepository.java index 70c58534e..f1ca03ec8 100644 --- a/dmp-backend/src/main/java/entities/DataRepository.java +++ b/dmp-backend/src/main/java/entities/DataRepository.java @@ -23,8 +23,7 @@ import org.hibernate.annotations.Type; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; - -@Entity(name="\"DataRepository\"") +@Entity @Table(name="\"DataRepository\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") public class DataRepository implements Serializable { diff --git a/dmp-backend/src/main/java/rest/entities/DataRepositories.java b/dmp-backend/src/main/java/rest/entities/DataRepositories.java index 940aa35f5..0edaab611 100644 --- a/dmp-backend/src/main/java/rest/entities/DataRepositories.java +++ b/dmp-backend/src/main/java/rest/entities/DataRepositories.java @@ -2,6 +2,9 @@ package rest.entities; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; + +import javax.transaction.Transactional; import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -66,11 +69,11 @@ public class DataRepositories { @Autowired private ServiceDao serviceDao; - + private ObjectMapper objectMapper = new ObjectMapper(); // MANAGE DATAREPOSITORy(IES) - @RequestMapping(method = RequestMethod.GET, value = { "/datarepositories" }) + @RequestMapping(method = RequestMethod.GET, value = { "/datarepos" }) public @ResponseBody ResponseEntity listDataRepositories(){ try { List allIDs = dataRepositoryDao.listAllIDs(); @@ -82,7 +85,7 @@ public class DataRepositories { } - @RequestMapping(method = RequestMethod.GET, value = { "/datarepositories/{id}" }) + @RequestMapping(method = RequestMethod.GET, value = { "/datarepos/{id}" }) public @ResponseBody ResponseEntity getDataRepository(@PathVariable("id") String id) { try { DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id)); @@ -93,28 +96,58 @@ public class DataRepositories { } } + - @RequestMapping(method = RequestMethod.POST, value = { "/setDataRepository" }, consumes = "application/json") - public @ResponseBody ResponseEntity setDataRepository(@RequestBody DataRepository dataRepository) { - String reason = ""; - DataRepository storedDataRepository = null; - //try first to create + @RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json") + public @ResponseBody ResponseEntity getAllDataRepositories(){ + try { - storedDataRepository = dataRepositoryDao.create(dataRepository); - return ResponseEntity.status(HttpStatus.CREATED).body("Created dataRepository with id: " + storedDataRepository.getId()); + List allDataRepositories = dataRepositoryDao.getAll(); + + //sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom + List datareposStrL = allDataRepositories.parallelStream().map((datarepoObj) -> { + try { + return objectMapper.writeValueAsString(datarepoObj); + } catch (JsonProcessingException e) { + return ""; + } + }).collect(Collectors.toList()); + + return new ResponseEntity("["+String.join(",", datareposStrL)+"]", HttpStatus.OK); + } - catch(Exception e) { - reason += e.getMessage(); - //try updating - try { - storedDataRepository = dataRepositoryDao.update(dataRepository); - return ResponseEntity.status(HttpStatus.CREATED).body("Updated dataRepository with id: " + storedDataRepository.getId()); - } - catch(Exception ex) { - reason += (System.lineSeparator()+e.getMessage()); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update dataRepository! Reason: " + reason); - } + catch(Exception ex) { + ex.printStackTrace(); + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } + + } + + + @Transactional + @RequestMapping(method = RequestMethod.POST, value = { "/datarepo/create" }, consumes = "application/json", produces="application/json") + public @ResponseBody ResponseEntity setOrganisation(@RequestBody DataRepository dataRepository) { + DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository); + try { + return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDataRepository)); + } catch (JsonProcessingException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create data repository!\"}"); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/datarepo/delete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity delete(@RequestBody DataRepository dataRepository) { + + DataRepository dr = new DataRepository(); + dr.setId(dataRepository.getId()); + try { + dataRepositoryDao.delete(dr); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted data repository!\"}"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete data repository!\"}"); + } + } diff --git a/dmp-backend/src/main/java/rest/entities/DmpProfiles.java b/dmp-backend/src/main/java/rest/entities/DmpProfiles.java index dba6e2c45..6a59bcce6 100644 --- a/dmp-backend/src/main/java/rest/entities/DmpProfiles.java +++ b/dmp-backend/src/main/java/rest/entities/DmpProfiles.java @@ -142,7 +142,7 @@ public class DmpProfiles { try { return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDMPProfile)); } catch (JsonProcessingException e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP Profile!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP Profile!\"}"); } } @@ -154,9 +154,9 @@ public class DmpProfiles { dmpp.setId(dmpprofile.getId()); try { dMPProfileDao.delete(dmpp); - return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted DMP Profile!\"}"); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP Profile!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP Profile!\"}"); } } diff --git a/dmp-backend/src/main/java/rest/entities/Organisations.java b/dmp-backend/src/main/java/rest/entities/Organisations.java index 49b91704e..85258c0ec 100644 --- a/dmp-backend/src/main/java/rest/entities/Organisations.java +++ b/dmp-backend/src/main/java/rest/entities/Organisations.java @@ -127,7 +127,7 @@ public class Organisations { try { return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdOrganisation)); } catch (JsonProcessingException e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create organisation!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create organisation!\"}"); } } @@ -139,9 +139,9 @@ public class Organisations { org.setId(organisation.getId()); try { organisationDao.delete(org); - return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted organisation!\"}"); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete organisation!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete organisation!\"}"); } } diff --git a/dmp-backend/src/main/java/rest/entities/Projects.java b/dmp-backend/src/main/java/rest/entities/Projects.java index b642a49c8..f9fdf63d1 100644 --- a/dmp-backend/src/main/java/rest/entities/Projects.java +++ b/dmp-backend/src/main/java/rest/entities/Projects.java @@ -139,7 +139,7 @@ public class Projects { try { return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdProject)); } catch (JsonProcessingException e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\"}"); } } @@ -151,9 +151,9 @@ public class Projects { p.setId(project.getId()); try { projectDao.delete(p); - return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted Project entity!\"}"); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Project!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Project!\"}"); } } diff --git a/dmp-backend/src/main/java/rest/entities/Registries.java b/dmp-backend/src/main/java/rest/entities/Registries.java index 54b14b22f..08489c17a 100644 --- a/dmp-backend/src/main/java/rest/entities/Registries.java +++ b/dmp-backend/src/main/java/rest/entities/Registries.java @@ -140,7 +140,7 @@ public class Registries { try { return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdRegistry)); } catch (JsonProcessingException e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\"}"); } } @@ -152,9 +152,9 @@ public class Registries { r.setId(registry.getId()); try { registryDao.delete(r); - return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted registry!\"}"); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete registry!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete registry!\"}"); } } diff --git a/dmp-backend/src/main/java/rest/entities/Researchers.java b/dmp-backend/src/main/java/rest/entities/Researchers.java index 2e5d4827c..ef659665c 100644 --- a/dmp-backend/src/main/java/rest/entities/Researchers.java +++ b/dmp-backend/src/main/java/rest/entities/Researchers.java @@ -2,6 +2,9 @@ package rest.entities; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; + +import javax.transaction.Transactional; import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -66,6 +69,8 @@ public class Researchers { @Autowired private ServiceDao serviceDao; + private ObjectMapper objectMapper = new ObjectMapper(); + // MANAGE RESEARCHER(S) @RequestMapping(method = RequestMethod.GET, value = { "/researchers" }) @@ -91,31 +96,57 @@ public class Researchers { } } - - @RequestMapping(method = RequestMethod.POST, value = { "/setResearcher" }, consumes = "application/json") - public @ResponseBody ResponseEntity setResearcher(@RequestBody Researcher researcher) { - String reason = ""; - Researcher storedResearcher = null; - //try first to create + + @RequestMapping(method = RequestMethod.GET, value = { "/researcher/getAll" }, produces="application/json") + public @ResponseBody ResponseEntity getAllResearchers(){ try { - storedResearcher = researcherDao.create(researcher); - return ResponseEntity.status(HttpStatus.CREATED).body("Created researcher with id: " + storedResearcher.getId()); + List allResearchers = researcherDao.getAll(); + + //sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom + List researcherStrL = allResearchers.parallelStream().map((researcherObj) -> { + try { + return objectMapper.writeValueAsString(researcherObj); + } catch (JsonProcessingException e) { + return ""; + } + }).collect(Collectors.toList()); + + return new ResponseEntity("["+String.join(",", researcherStrL)+"]", HttpStatus.OK); + } - catch(Exception e) { - reason += e.getMessage(); - //try updating - try { - storedResearcher = researcherDao.update(researcher); - return ResponseEntity.status(HttpStatus.CREATED).body("Updated researcher with id: " + storedResearcher.getId()); - } - catch(Exception ex) { - reason += (System.lineSeparator()+e.getMessage()); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update researcher! Reason: " + reason); - } + catch(Exception ex) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } + @Transactional + @RequestMapping(method = RequestMethod.POST, value = { "/researcher/create" }, consumes = "application/json", produces="application/json") + public @ResponseBody ResponseEntity setResearcher(@RequestBody Researcher researcher) { + Researcher createdResearcher = researcherDao.update(researcher); + try { + return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdResearcher)); + } catch (JsonProcessingException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create researcher!\"}"); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/researcher/delete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity delete(@RequestBody Researcher researcher) { + + Researcher res = new Researcher(); + res.setId(researcher.getId()); + try { + researcherDao.delete(res); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted researcher!\"}"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete researcher!\"}"); + } + + } + + } diff --git a/dmp-backend/src/main/java/rest/entities/Services.java b/dmp-backend/src/main/java/rest/entities/Services.java index 645e95ceb..768a48012 100644 --- a/dmp-backend/src/main/java/rest/entities/Services.java +++ b/dmp-backend/src/main/java/rest/entities/Services.java @@ -128,7 +128,7 @@ public class Services { try { return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdService)); } catch (JsonProcessingException e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create service entity!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create service entity!\"}"); } } @@ -140,9 +140,9 @@ public class Services { s.setId(service.getId()); try { serviceDao.delete(s); - return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted Service entity!\"}"); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Service entity!\""); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Service entity!\"}"); } } diff --git a/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java b/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java index e905aec77..71b458f81 100644 --- a/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java +++ b/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java @@ -32,13 +32,8 @@ public class CustomAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { - System.out.println("AUTHENTICATION"); - System.out.println(authentication); - if (authentication != null) { - System.out.println((String)authentication.getCredentials()); - String token = (String)authentication.getCredentials(); TokenValidator tokenValidator = null;