Merge branches 'Development' and 'Development' of https://gitlab.eudat.eu/dmp/OpenAIRE-EUDAT-DMP-service-pilot into Development

This commit is contained in:
Diamantis Tziotzios 2017-12-19 11:54:05 +02:00
commit 84845284f5
17 changed files with 165 additions and 56 deletions

View File

@ -1,6 +1,8 @@
package eu.eudat.configurations; package eu.eudat.configurations;
import eu.eudat.handlers.PrincipalArgumentResolver; import eu.eudat.handlers.PrincipalArgumentResolver;
import eu.eudat.services.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@ -13,9 +15,10 @@ import java.util.List;
@Configuration @Configuration
public class WebMVCConfiguration extends WebMvcConfigurerAdapter { public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
@Autowired
AuthenticationService authenticationService;
@Override @Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new PrincipalArgumentResolver()); argumentResolvers.add(new PrincipalArgumentResolver(this.authenticationService));
} }
} }

View File

@ -9,9 +9,11 @@ import javax.transaction.Transactional;
import eu.eudat.entities.DMP; import eu.eudat.entities.DMP;
import eu.eudat.entities.Dataset; import eu.eudat.entities.Dataset;
import eu.eudat.entities.UserInfo; import eu.eudat.entities.UserInfo;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.models.criteria.OrganisationCriteria; import eu.eudat.models.criteria.OrganisationCriteria;
import eu.eudat.models.criteria.ResearcherCriteria; import eu.eudat.models.criteria.ResearcherCriteria;
import eu.eudat.models.dmp.DataManagementPlan; import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.models.dmp.DataManagementPlanTableRequest; import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.helpers.responses.*; import eu.eudat.models.helpers.responses.*;
@ -100,6 +102,19 @@ public class DMPs {
} }
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/get" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<List<DataManagementPlan>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria) {
try {
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(dMPDao, dataManagementPlanCriteria);
return new ResponseItem<List<DataManagementPlan>>().status(HttpStatus.OK).payload(dataTable);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<List<DataManagementPlan>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// @RequestMapping(method = RequestMethod.GET, value = { "/dmps" }, produces="text/plain") // @RequestMapping(method = RequestMethod.GET, value = { "/dmps" }, produces="text/plain")

View File

@ -5,6 +5,7 @@ import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.login.LoginInfo; import eu.eudat.models.login.LoginInfo;
import eu.eudat.models.security.Principal; import eu.eudat.models.security.Principal;
import eu.eudat.security.CustomAuthenticationProvider; import eu.eudat.security.CustomAuthenticationProvider;
import eu.eudat.services.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -14,12 +15,14 @@ import org.springframework.web.bind.annotation.*;
*/ */
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping(value = "/login") @RequestMapping(value = "/auth")
public class Login { public class Login {
@Autowired @Autowired
private CustomAuthenticationProvider customAuthenticationProvider; private CustomAuthenticationProvider customAuthenticationProvider;
@Autowired
private AuthenticationService authenticationService;
@RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) { public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) {
try { try {
@ -30,4 +33,27 @@ public class Login {
return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()); return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
} }
} }
@RequestMapping(method = RequestMethod.POST, value = { "/me" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<Principal> authMe(Principal principal) {
try {
return new ResponseItem<Principal>().payload(this.authenticationService.Touch(principal.getToken())).status(HttpStatus.OK);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/logout" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<Principal> logout(Principal principal) {
try {
this.authenticationService.Logout(principal.getToken());
return new ResponseItem<Principal>().status(HttpStatus.OK);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
} }

View File

@ -8,7 +8,9 @@ import java.util.UUID;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.helpers.responses.*; import eu.eudat.models.helpers.responses.*;
import eu.eudat.models.project.ProjectCriteriaRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -108,6 +110,30 @@ public class Projects {
} }
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = { "/projects/inactivate/{id}" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<eu.eudat.entities.Project> inactivate(@PathVariable String id) {
try {
Project inactivate = new ProjectManager().inactivate(projectDao,id);
return new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.OK);
}catch (Exception ex){
return new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/projects/get" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<List<eu.eudat.models.project.Project>> getPaged(@RequestBody ProjectCriteriaRequest projectCriteria) {
try {
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteria(projectDao, projectCriteria);
return new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(HttpStatus.OK);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<List<eu.eudat.models.project.Project>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/external/projects" }, produces="application/json") @RequestMapping(method = RequestMethod.GET, value = { "/external/projects" }, produces="application/json")

View File

@ -36,6 +36,7 @@ public class DMPDaoImpl implements DMPDao {
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%")); if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd())); if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart())); if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart()));
if(criteria.getProjects()!=null&&!criteria.getProjects().isEmpty())query.where(((builder, root) -> root.get("project").in(criteria.getProjectEntities())));
return query; return query;
} }

View File

@ -40,8 +40,7 @@ public final class PrincipalArgumentResolver implements HandlerMethodArgumentRes
return principal; return principal;
} }
@Autowired public PrincipalArgumentResolver(AuthenticationService authenticationService){
private void PrincipalArgumentResolver(AuthenticationService authenticationService){
this.authenticationService = authenticationService; this.authenticationService = authenticationService;
} }

View File

@ -5,6 +5,9 @@ import java.util.UUID;
import eu.eudat.dao.entities.DMPDao; import eu.eudat.dao.entities.DMPDao;
import eu.eudat.entities.DMP; import eu.eudat.entities.DMP;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.models.dmp.DataManagementPlanTableRequest; import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.helpers.DataTableData;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
@ -27,4 +30,10 @@ public class DataManagementPlanManager {
datamanagementPlan.fromDataModel(dmpsRepository.find(UUID.fromString(id))); datamanagementPlan.fromDataModel(dmpsRepository.find(UUID.fromString(id)));
return datamanagementPlan; return datamanagementPlan;
} }
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria) throws IllegalAccessException, InstantiationException{
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria());
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = new DomainModelConverter<eu.eudat.entities.DMP, eu.eudat.models.dmp.DataManagementPlan>().fromDataModel( items.toList(), eu.eudat.models.dmp.DataManagementPlan.class);
return datamanagementPlans;
}
} }

View File

@ -4,8 +4,10 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import eu.eudat.dao.entities.ProjectDao; import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.helpers.DataTableData; import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.Project; import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectCriteriaRequest;
import eu.eudat.models.project.ProjectTableRequest; import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter; import eu.eudat.utilities.builders.DomainModelConverter;
@ -27,4 +29,17 @@ public class ProjectManager {
project.fromDataModel(projectRepository.find(UUID.fromString(id))); project.fromDataModel(projectRepository.find(UUID.fromString(id)));
return project; return project;
} }
public eu.eudat.entities.Project inactivate(ProjectDao projectRepository,String id) throws InstantiationException, IllegalAccessException{
eu.eudat.entities.Project project = projectRepository.find(UUID.fromString(id));
project.setStatus(Project.Status.DELETED.getValue());
project = projectRepository.createOrUpdate(project);
return project;
}
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria) throws IllegalAccessException, InstantiationException{
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class);
return projects;
}
} }

View File

@ -1,13 +1,18 @@
package eu.eudat.models.criteria; package eu.eudat.models.criteria;
import eu.eudat.entities.DMP; import eu.eudat.entities.DMP;
import eu.eudat.models.project.Project;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class DataManagementPlanCriteria extends Criteria<DMP>{ public class DataManagementPlanCriteria extends Criteria<DMP>{
private Date periodStart; private Date periodStart;
private Date periodEnd; private Date periodEnd;
private List<Project> projects;
public Date getPeriodStart() { public Date getPeriodStart() {
return periodStart; return periodStart;
} }
@ -23,4 +28,16 @@ public class DataManagementPlanCriteria extends Criteria<DMP>{
public void setPeriodEnd(Date periodEnd) { public void setPeriodEnd(Date periodEnd) {
this.periodEnd = periodEnd; this.periodEnd = periodEnd;
} }
public List<Project> getProjects() {
return projects;
}
public void setProjects(List<Project> projects) {
this.projects = projects;
}
public List<eu.eudat.entities.Project> getProjectEntities(){
return new DomainModelConverter<eu.eudat.entities.Project,Project>().toDataModel(this.projects);
}
} }

View File

@ -0,0 +1,10 @@
package eu.eudat.models.dmp;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.models.helpers.requests.RequestItem;
/**
* Created by ikalyvas on 12/19/2017.
*/
public class DataManagementPlanCriteriaRequest extends RequestItem<DataManagementPlanCriteria>{
}

View File

@ -13,7 +13,7 @@ import eu.eudat.models.dmp.DataManagementPlan;
public class Project implements DataModel<eu.eudat.entities.Project>{ public class Project implements DataModel<eu.eudat.entities.Project>{
public enum Status { public enum Status {
ACTIVE((short) 0), INACTIVE((short) 1); ACTIVE((short) 1), INACTIVE((short) 0),DELETED((short)99);
private short value; private short value;
private Status(short value) { this.value = value; } private Status(short value) { this.value = value; }
@ -24,6 +24,8 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
return ACTIVE; return ACTIVE;
case 1: case 1:
return INACTIVE; return INACTIVE;
case 99:
return INACTIVE;
default: default:
throw new RuntimeException("Unsupported Project Status"); throw new RuntimeException("Unsupported Project Status");
} }
@ -201,7 +203,7 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
entity.setStartdate(this.startDate); entity.setStartdate(this.startDate);
entity.setCreated(this.created == null? new Date():this.created); entity.setCreated(this.created == null? new Date():this.created);
entity.setEnddate(this.endDate); entity.setEnddate(this.endDate);
entity.setStatus(this.status!=null?this.getStatus():1); entity.setStatus(this.status!=null?this.getStatus():Status.ACTIVE.getValue());
entity.setModified(new Date()); entity.setModified(new Date());
entity.setDescription(this.description); entity.setDescription(this.description);
return entity; return entity;

View File

@ -0,0 +1,10 @@
package eu.eudat.models.project;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.helpers.requests.RequestItem;
/**
* Created by ikalyvas on 12/18/2017.
*/
public class ProjectCriteriaRequest extends RequestItem<ProjectCriteria>{
}

View File

@ -1,3 +1,4 @@
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { PageNotFoundComponent } from './not-found.component'; import { PageNotFoundComponent } from './not-found.component';
@ -19,35 +20,16 @@ const appRoutes: Routes = [
{ path: 'dynamic-form/:id', component: DynamicFormComponent, canActivate: [AuthGuard] }, { path: 'dynamic-form/:id', component: DynamicFormComponent, canActivate: [AuthGuard] },
//{ path: 'dataset', component: DatasetsComponent }, //{ path: 'dataset', component: DatasetsComponent },
{ path: 'projects', component: ProjectListingComponent, canActivate: [AuthGuard]},
{ path: 'project/:id', component: ProjectEditorComponent, canActivate: [AuthGuard]},
{ path: 'projects/new', component: ProjectEditorComponent, canActivate: [AuthGuard]},
{ path: 'dmps', component: DataManagementPlanListingComponent, canActivate: [AuthGuard]},
{ path: 'dmp/:id', component: DataManagementPlanEditorComponent, canActivate: [AuthGuard]},
{ path: 'dmps/new', component: DataManagementPlanEditorComponent, canActivate: [AuthGuard]},
{ path: 'login', component: MainSignInComponent}, { path: 'login', component: MainSignInComponent},
{ path: 'projects', component: ProjectListingComponent}, { path: "unauthorized", loadChildren: './unauthorized/unauthorized.module#UnauthorizedModule' },
{ path: 'project/:id', component: ProjectEditorComponent}, { path: 'welcome', component: HomepageComponent, canActivate: [AuthGuard]},
{ path: 'projects/new', component: ProjectEditorComponent}, { path: '', redirectTo: '/welcome', pathMatch: 'full' },
{ path: 'dmps', component: DataManagementPlanListingComponent},
{ path: 'dmp/:id', component: DataManagementPlanEditorComponent},
{ path: 'dmps/new', component: DataManagementPlanEditorComponent},
// { path: 'dmps',
// component: DataManagementPlanListingComponent,
// children: [
// {
// path: "dmp",
// component: DmpDetailedComponent,
// data: {
// //breadcrumb: "Sign In"
// }
// },
// {
// path: "project",
// component: ProjectDetailedComponent,
// data: {
// //breadcrumb: "Sign Up"
// }
// }
// ]
// },
{ path: 'welcome', component: HomepageComponent},
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
]; ];

View File

@ -1,3 +1,4 @@
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
import { PaginationService } from './form/pagination/pagination-service'; import { PaginationService } from './form/pagination/pagination-service';
import { import {
TableOfContentsFieldComponent, TableOfContentsFieldComponent,

View File

@ -25,17 +25,10 @@ export class HomepageComponent implements OnInit{
ngOnInit() { ngOnInit() {
this.serverService.whoami().subscribe(
userInfo => {
this.userInfo = userInfo;
},
error => {
}
);
this.dashBoardService.getStatistics().subscribe(results =>{ this.dashBoardService.getStatistics().subscribe(results =>{
let data = results['payload']; //let data = results['payload'];
this.dashboardStatisticsData = new JsonSerializer<DashboardStatisticsModel>().fromJSONObject(data,DashboardStatisticsModel); this.dashboardStatisticsData = new JsonSerializer<DashboardStatisticsModel>().fromJSONObject(results,DashboardStatisticsModel);
}) })
} }

View File

@ -24,7 +24,7 @@ export class AuthService {
public router: Router public router: Router
) { ) {
this.actionUrl = HostConfiguration.Server + 'api/auth/'; this.actionUrl = HostConfiguration.Server + 'auth/';
this.headers = new HttpHeaders(); this.headers = new HttpHeaders();
this.headers = this.headers.set('Content-Type', 'application/json'); this.headers = this.headers.set('Content-Type', 'application/json');
@ -62,11 +62,11 @@ export class AuthService {
//} //}
public login(loginInfo: LoginInfo): Observable<Principal> { public login(loginInfo: LoginInfo): Observable<Principal> {
const url = this.actionUrl + 'login'; const url = this.actionUrl + 'externallogin';
return this.http.post(url, loginInfo, { headers: this.headers }) return this.http.post(url, loginInfo, { headers: this.headers })
.map((res: Response) => { .map((res: any) => {
const principal = this.current(new JsonSerializer<Principal>().fromJSONObject(res, Principal)); const principal = this.current(new JsonSerializer<Principal>().fromJSONObject(res.payload, Principal));
//this.loginContextSubject.next(true); //this.loginContextSubject.next(true);
return principal; return principal;
}) })

View File

@ -3,8 +3,8 @@
<span class="navbar-spacer"></span> <span class="navbar-spacer"></span>
<div *ngIf="isAuthenticated()"> <div *ngIf="isAuthenticated()">
<a mat-button class="navbar-button" routerLink="/forms">Forms</a> <a mat-button class="navbar-button" routerLink="/forms">Forms</a>
<a mat-button *ngIf="isAdmin()" class="navbar-button" routerLink="/configuration">Configuration</a> <!-- <a mat-button *ngIf="isAdmin()" class="navbar-button" routerLink="/configuration">Configuration</a>
<a mat-button *ngIf="isAdmin()" class="navbar-button" routerLink="/users">Users</a> <a mat-button *ngIf="isAdmin()" class="navbar-button" routerLink="/users">Users</a>
<button mat-icon-button class="navbar-icon" (click)="logout()"><mat-icon class="navbar-icon">exit_to_app</mat-icon></button> --><button mat-icon-button class="navbar-icon" (click)="logout()"><mat-icon class="navbar-icon">exit_to_app</mat-icon></button>
</div> </div>
</mat-toolbar> </mat-toolbar>