2017-10-20 17:11:40 +02:00
|
|
|
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;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2017-11-16 16:43:17 +01:00
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
2017-10-20 17:11:40 +02:00
|
|
|
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 dao.entities.DMPDao;
|
|
|
|
import dao.entities.DMPProfileDao;
|
|
|
|
import dao.entities.DataRepositoryDao;
|
|
|
|
import dao.entities.DatasetDao;
|
|
|
|
import dao.entities.DatasetProfileDao;
|
|
|
|
import dao.entities.DatasetProfileRulesetDao;
|
|
|
|
import dao.entities.DatasetProfileViewstyleDao;
|
|
|
|
import dao.entities.OrganisationDao;
|
|
|
|
import dao.entities.ProjectDao;
|
|
|
|
import dao.entities.RegistryDao;
|
|
|
|
import dao.entities.ResearcherDao;
|
|
|
|
import dao.entities.ServiceDao;
|
2017-11-16 16:43:17 +01:00
|
|
|
import dao.entities.UserInfoDao;
|
2017-10-20 17:11:40 +02:00
|
|
|
import entities.DMP;
|
|
|
|
import entities.DMPProfile;
|
|
|
|
import entities.DataRepository;
|
|
|
|
import entities.Dataset;
|
|
|
|
import entities.DatasetProfile;
|
|
|
|
import entities.DatasetProfileRuleset;
|
|
|
|
import entities.Organisation;
|
|
|
|
import entities.Project;
|
|
|
|
import entities.Registry;
|
|
|
|
import entities.Researcher;
|
|
|
|
import entities.Service;
|
2017-11-16 16:43:17 +01:00
|
|
|
import entities.UserInfo;
|
2017-10-20 17:11:40 +02:00
|
|
|
import helpers.SerializerProvider;
|
|
|
|
import helpers.Transformers;
|
|
|
|
import 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;
|
2017-11-16 16:43:17 +01:00
|
|
|
@Autowired private UserInfoDao userInfoDao;
|
|
|
|
|
|
|
|
|
2017-11-27 15:08:13 +01:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/users/{id}" }, produces="application/json;charset=UTF-8")
|
|
|
|
public @ResponseBody ResponseEntity<Object> getUserByID(@PathVariable("id") String id){
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
//now get the user the caller asked for...
|
|
|
|
UserInfo userAsked4 = userInfoDao.getUserInfo(id);
|
|
|
|
|
|
|
|
try {
|
|
|
|
return new ResponseEntity<Object>(SerializerProvider.toJson(userAsked4), HttpStatus.OK);
|
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-16 16:43:17 +01:00
|
|
|
|
2017-11-16 18:24:05 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/user/whoami" }, produces="application/json;charset=UTF-8")
|
2017-11-16 16:43:17 +01:00
|
|
|
public @ResponseBody ResponseEntity<Object> 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 new ResponseEntity<Object>(SerializerProvider.toJson(userInfo), HttpStatus.OK);
|
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-20 17:11:40 +02:00
|
|
|
|
|
|
|
|
2017-10-23 18:06:24 +02:00
|
|
|
|
2017-10-20 17:11:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|