From 66447e29e9a28a26715ca04329dab207b29ecbaa Mon Sep 17 00:00:00 2001 From: annabakouli Date: Fri, 15 Dec 2017 12:26:25 +0200 Subject: [PATCH] no message --- .../main/java/eu/eudat/controllers/Users.java | 114 ++++++++++++++++++ dmp-frontend/src/app/services/rest-base.ts | 7 +- 2 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 dmp-backend/src/main/java/eu/eudat/controllers/Users.java diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Users.java b/dmp-backend/src/main/java/eu/eudat/controllers/Users.java new file mode 100644 index 000000000..34effad1e --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Users.java @@ -0,0 +1,114 @@ +package eu.eudat.controllers; + +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; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import eu.eudat.dao.entities.DMPDao; +import eu.eudat.dao.entities.DMPProfileDao; +import eu.eudat.dao.entities.DataRepositoryDao; +import eu.eudat.dao.entities.DatasetDao; +import eu.eudat.dao.entities.DatasetProfileDao; +import eu.eudat.dao.entities.DatasetProfileRulesetDao; +import eu.eudat.dao.entities.DatasetProfileViewstyleDao; +import eu.eudat.dao.entities.OrganisationDao; +import eu.eudat.dao.entities.ProjectDao; +import eu.eudat.dao.entities.RegistryDao; +import eu.eudat.dao.entities.ResearcherDao; +import eu.eudat.dao.entities.ServiceDao; +import eu.eudat.dao.entities.UserInfoDao; +import eu.eudat.entities.DMP; +import eu.eudat.entities.DMPProfile; +import eu.eudat.entities.DataRepository; +import eu.eudat.entities.Dataset; +import eu.eudat.entities.DatasetProfile; +import eu.eudat.entities.DatasetProfileRuleset; +import eu.eudat.entities.Organisation; +import eu.eudat.entities.Project; +import eu.eudat.entities.Registry; +import eu.eudat.entities.Researcher; +import eu.eudat.entities.Service; +import eu.eudat.entities.UserInfo; +import eu.eudat.helpers.Transformers; +import eu.eudat.responses.RestResponse; + + +@RestController +@CrossOrigin +public class Users { + + @Autowired private DataRepositoryDao dataRepositoryDao; + @Autowired private DatasetDao datasetDao; + @Autowired private DatasetProfileDao datasetProfileDao; + @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; + @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; + @Autowired private DMPDao dMPDao; + @Autowired private DMPProfileDao dMPProfileDao; + @Autowired private OrganisationDao organisationDao; + @Autowired private ProjectDao projectDao; + @Autowired private RegistryDao registryDao; + @Autowired private ResearcherDao researcherDao; + @Autowired private ServiceDao serviceDao; + @Autowired private UserInfoDao userInfoDao; + + + + @RequestMapping(method = RequestMethod.GET, value = { "/user/whoami" }, produces="application/json;charset=UTF-8") + public @ResponseBody ResponseEntity whoami(){ + + + String userID = null; + try { + userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString(); + } catch(NullPointerException ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here"); + } + + UserInfo userInfo = userInfoDao.getUserInfo(userID); + + + if(userInfo==null) //this should normally never happer + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here"); + + + try { + + return ResponseEntity.status(HttpStatus.OK).body(userInfo); + } + catch(Exception ex) { + ex.printStackTrace(); + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + + + + + + + + +} + diff --git a/dmp-frontend/src/app/services/rest-base.ts b/dmp-frontend/src/app/services/rest-base.ts index 868eeab67..53ce4e7c1 100644 --- a/dmp-frontend/src/app/services/rest-base.ts +++ b/dmp-frontend/src/app/services/rest-base.ts @@ -20,7 +20,6 @@ export class RestBase { protocol: string = "http"; hostname: string ="192.168.32.103" port: number = 8080; - webappname: string = "dmp-backend"; /* protocol: string = "http"; @@ -30,9 +29,9 @@ export class RestBase { */ - proxyPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/proxy/"; - loginPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/login/"; - restPath: string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/rest/"; + proxyPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/proxy/"; + loginPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/login/"; + restPath: string = this.protocol+"://"+this.hostname+":"+this.port;