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;
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.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@ -13,9 +15,10 @@ import java.util.List;
@Configuration
public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
@Autowired
AuthenticationService authenticationService;
@Override
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.Dataset;
import eu.eudat.entities.UserInfo;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.models.criteria.OrganisationCriteria;
import eu.eudat.models.criteria.ResearcherCriteria;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.helpers.responses.*;
@ -98,7 +100,20 @@ public class DMPs {
eu.eudat.entities.DMP createdProject = dMPDao.createOrUpdate(dataManagementPlan.toDataModel());
return ResponseEntity.status(HttpStatus.CREATED).body(createdProject);
}
@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());
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -5,6 +5,7 @@ import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.login.LoginInfo;
import eu.eudat.models.security.Principal;
import eu.eudat.security.CustomAuthenticationProvider;
import eu.eudat.services.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
@ -14,12 +15,14 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@CrossOrigin
@RequestMapping(value = "/login")
@RequestMapping(value = "/auth")
public class Login {
@Autowired
private CustomAuthenticationProvider customAuthenticationProvider;
@Autowired
private AuthenticationService authenticationService;
@RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) {
try {
@ -30,4 +33,27 @@ public class Login {
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 eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.helpers.responses.*;
import eu.eudat.models.project.ProjectCriteriaRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -106,8 +108,32 @@ public class Projects {
return new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
@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")

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.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.getProjects()!=null&&!criteria.getProjects().isEmpty())query.where(((builder, root) -> root.get("project").in(criteria.getProjectEntities())));
return query;
}

View File

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

View File

@ -5,6 +5,9 @@ import java.util.UUID;
import eu.eudat.dao.entities.DMPDao;
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.helpers.DataTableData;
import eu.eudat.queryable.QueryableList;
@ -27,4 +30,10 @@ public class DataManagementPlanManager {
datamanagementPlan.fromDataModel(dmpsRepository.find(UUID.fromString(id)));
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 eu.eudat.dao.entities.ProjectDao;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectCriteriaRequest;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter;
@ -27,4 +29,17 @@ public class ProjectManager {
project.fromDataModel(projectRepository.find(UUID.fromString(id)));
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;
import eu.eudat.entities.DMP;
import eu.eudat.models.project.Project;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class DataManagementPlanCriteria extends Criteria<DMP>{
private Date periodStart;
private Date periodEnd;
private List<Project> projects;
public Date getPeriodStart() {
return periodStart;
}
@ -23,4 +28,16 @@ public class DataManagementPlanCriteria extends Criteria<DMP>{
public void setPeriodEnd(Date 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 enum Status {
ACTIVE((short) 0), INACTIVE((short) 1);
ACTIVE((short) 1), INACTIVE((short) 0),DELETED((short)99);
private short value;
private Status(short value) { this.value = value; }
@ -24,6 +24,8 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
return ACTIVE;
case 1:
return INACTIVE;
case 99:
return INACTIVE;
default:
throw new RuntimeException("Unsupported Project Status");
}
@ -201,7 +203,7 @@ public class Project implements DataModel<eu.eudat.entities.Project>{
entity.setStartdate(this.startDate);
entity.setCreated(this.created == null? new Date():this.created);
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.setDescription(this.description);
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 { RouterModule, Routes } from '@angular/router';
import { PageNotFoundComponent } from './not-found.component';
@ -19,35 +20,16 @@ const appRoutes: Routes = [
{ path: 'dynamic-form/:id', component: DynamicFormComponent, canActivate: [AuthGuard] },
//{ path: 'dataset', component: DatasetsComponent },
{ path: 'login', component: MainSignInComponent},
{ path: 'projects', component: ProjectListingComponent},
{ path: 'project/:id', component: ProjectEditorComponent},
{ path: 'projects/new', component: ProjectEditorComponent},
{ 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 }
{ 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: "unauthorized", loadChildren: './unauthorized/unauthorized.module#UnauthorizedModule' },
{ path: 'welcome', component: HomepageComponent, canActivate: [AuthGuard]},
{ path: '', redirectTo: '/welcome', pathMatch: 'full' },
];

View File

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

View File

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

View File

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

View File

@ -3,8 +3,8 @@
<span class="navbar-spacer"></span>
<div *ngIf="isAuthenticated()">
<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>
<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>
</mat-toolbar>