Merge branch 'master' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot

This commit is contained in:
Nikolaos Laskaris 2017-10-18 11:29:31 +03:00
commit 3607782464
12 changed files with 153 additions and 38 deletions

View File

@ -4,7 +4,11 @@ import java.util.UUID;
import dao.Dao;
import entities.DMPResearcher;
import entities.Researcher;
public interface DMPResearcherDao extends Dao<DMPResearcher, UUID> {
Researcher getResearcherByEmail(String email);
}

View File

@ -2,9 +2,13 @@ package dao.entities;
import java.util.UUID;
import javax.persistence.TypedQuery;
import org.hibernate.NonUniqueResultException;
import dao.JpaDao;
import entities.DMPResearcher;
import entities.Researcher;
public class DMPResearcherDaoImpl extends JpaDao<DMPResearcher, UUID> implements DMPResearcherDao {
@ -13,5 +17,19 @@ public class DMPResearcherDaoImpl extends JpaDao<DMPResearcher, UUID> implements
return null;
}
@Override
public Researcher getResearcherByEmail(String email) {
String queryString = "FROM Researcher researcher where primaryEmail=:email";
TypedQuery<Researcher> typedQuery = entityManager.createQuery(queryString, Researcher.class);
typedQuery.setParameter("email", email);
try {
return typedQuery.getSingleResult();
}catch(Exception ex) {
System.out.println(ex.getMessage());
return null;
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.UUID;
import dao.Dao;
import entities.Registry;
import entities.Researcher;
import entities.responses.IDLabelPair;
public interface RegistryDao extends Dao<Registry, UUID> {
@ -13,4 +14,5 @@ public interface RegistryDao extends Dao<Registry, UUID> {
List<IDLabelPair> listAllIDsLabels();
}

View File

@ -10,6 +10,7 @@ import org.hibernate.query.Query;
import dao.JpaDao;
import entities.Registry;
import entities.Researcher;
import entities.responses.IDLabelPair;
public class RegistryDaoImpl extends JpaDao<Registry, UUID> implements RegistryDao {

View File

@ -13,4 +13,6 @@ public interface ResearcherDao extends Dao<Researcher, UUID> {
List<IDLabelPair> listAllIDsLabels();
Researcher getResearcherByEmail(String email);
}

View File

@ -40,4 +40,14 @@ public class ResearcherDaoImpl extends JpaDao<Researcher, UUID> implements Resea
}
@Override
public Researcher getResearcherByEmail(String email) {
String queryString = "FROM Researcher researcher where researcher.primaryEmail=:email";
TypedQuery<Researcher> typedQuery = entityManager.createQuery(queryString, Researcher.class);
return null;
}
}

View File

@ -39,7 +39,7 @@ public class DatasetProfileRuleset implements Serializable {
private UUID id;
@OneToOne(fetch = FetchType.EAGER, mappedBy = "ruleset", cascade = CascadeType.ALL)
@OneToOne(fetch = FetchType.EAGER, mappedBy = "ruleset")
private DatasetProfile datasetProfile;

View File

@ -38,7 +38,7 @@ public class DatasetProfileViewstyle implements Serializable {
private UUID id;
@OneToOne(fetch = FetchType.EAGER, mappedBy = "viewstyle", cascade = CascadeType.ALL)
@OneToOne(fetch = FetchType.EAGER, mappedBy = "viewstyle")
private DatasetProfile datasetProfile;
@Column(name = "\"Label\"")

View File

@ -1,8 +1,12 @@
package rest.entities;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import java.util.UUID;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -18,7 +22,9 @@ 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.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
@ -34,9 +40,11 @@ import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import entities.DMP;
import entities.DMPProfile;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.Project;
import helpers.Transformers;
import responses.RestResponse;
@ -59,7 +67,7 @@ public class Datasets {
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = new ObjectMapper();
// FETCH BY DATASET(S)
@ -211,37 +219,74 @@ public class Datasets {
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/setDatasetProfile" }, consumes = "application/json")
//@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/set" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
String reason = "";
DatasetProfile storedDatasetProfile = null;
//try first to create
System.out.println("inside setDatasetProfile");
try {
storedDatasetProfile = datasetProfileDao.create(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(storedDatasetProfile));
System.out.println(objectMapper.writeValueAsString(datasetProfile));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
catch(Exception e) {
reason += e.getMessage();
//try updating
if(datasetProfile.getRuleset()!=null && datasetProfile.getRuleset().getId()!=null){
DatasetProfileRuleset dpr = datasetProfile.getRuleset();
datasetProfileRulesetDao.update(dpr);
DatasetProfileRuleset n = new DatasetProfileRuleset();
n.setId(dpr.getId());
datasetProfile.setRuleset(n);
}
if(datasetProfile.getViewstyle()!=null && datasetProfile.getViewstyle().getId()!=null){
DatasetProfileViewstyle dpv = datasetProfile.getViewstyle();
datasetProfileViewstyleDao.update(dpv);
DatasetProfileViewstyle n = new DatasetProfileViewstyle();
n.setId(dpv.getId());
datasetProfile.setViewstyle(n);
}
datasetProfile.setDataset(null);
DatasetProfile createdDatasetProfile = datasetProfileDao.update(datasetProfile);
try {
storedDatasetProfile = datasetProfileDao.update(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(storedDatasetProfile));
}
catch(Exception ex) {
reason += (System.lineSeparator()+e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("An error occurred! Reason: " + reason);
}
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDatasetProfile));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not set dataset profile!\"}");
}
}
/*
@RequestMapping(method = RequestMethod.GET, value = { "/createEmptyDatasetProfile" })
public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile() {
@RequestMapping(method = RequestMethod.POST, value = { "/createEmptyDatasetProfile" })
public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile(@RequestParam("datasetID") String datasetID) {
DatasetProfileRuleset dpr = new DatasetProfileRuleset();
dpr.setLabel("");
dpr.setDefinition("");
dpr.setId(datasetProfileRulesetDao.create(dpr).getId());
DatasetProfileViewstyle dpv = new DatasetProfileViewstyle();
dpv.setLabel("");
dpv.setDefinition("");
dpv.setId(datasetProfileViewstyleDao.create(dpv).getId());
DatasetProfile datasetProfile = new DatasetProfile();
datasetProfile.setLabel("");
datasetProfile.setDefinition("");
datasetProfile.setRuleset(dpr);
datasetProfile.setViewstyle(dpv);
Dataset ds = new Dataset();
ds.setId(UUID.fromString(datasetID));
datasetProfile.setDataset(ds);
try {
datasetProfile = datasetProfileDao.create(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(datasetProfile));
@ -250,7 +295,7 @@ public class Datasets {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage());
}
}
*/

View File

@ -96,6 +96,18 @@ public class Researchers {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/researcher/getByEmail" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getResearcherByEmail(@RequestParam("email") String email){
try {
Researcher researcher = researcherDao.getResearcherByEmail(email);
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(researcher));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/researcher/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllResearchers(){

View File

@ -35,7 +35,21 @@ export class ProjectsComponent implements OnInit{
}
ngOnInit() {
this.projects = this.serverService.getDummyProjects()
//this.projects = this.serverService.getDummyProjects();
this.projects = [];
this.serverService.getProjects().subscribe(
response => {
console.log("response");
console.log(response);
response.forEach(resp => {
let pr = new Project();
pr.id = resp.id;
pr.name = resp.label;
this.projects.push(pr);
});
}
);
}

View File

@ -69,22 +69,29 @@ export class ServerService {
}
getDummyProjects(){
let projects :Project[] =[];
getProjects(){
let project = new Project;
project.name = "Project1";
project.id = "Project1Id";
let headers = new HttpHeaders().set("google-token", this.tokenService.getToken());
projects.push(project);
console.log("google-token: "+ this.tokenService.getToken());
let project2 = new Project;
project2.name = "Project2";
project2.id = "Project2Id";
return this.httpClient.get<any>("http://dl010.madgik.di.uoa.gr:8080/dmp-backend-no-sec/rest/project/listAllLabelIDs");
projects.push(project2);
// let projects :Project[] =[];
return projects;
// let project = new Project;
// project.name = "Project1";
// project.id = "Project1Id";
// projects.push(project);
// let project2 = new Project;
// project2.name = "Project2";
// project2.id = "Project2Id";
// projects.push(project2);
// return projects;
}
}