diff --git a/dmp-backend/src/main/java/dao/entities/DMPResearcherDao.java b/dmp-backend/src/main/java/dao/entities/DMPResearcherDao.java index db9537448..c97e6c78d 100644 --- a/dmp-backend/src/main/java/dao/entities/DMPResearcherDao.java +++ b/dmp-backend/src/main/java/dao/entities/DMPResearcherDao.java @@ -4,7 +4,11 @@ import java.util.UUID; import dao.Dao; import entities.DMPResearcher; +import entities.Researcher; public interface DMPResearcherDao extends Dao { + + Researcher getResearcherByEmail(String email); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/DMPResearcherDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DMPResearcherDaoImpl.java index e7f469c46..1c420680b 100644 --- a/dmp-backend/src/main/java/dao/entities/DMPResearcherDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DMPResearcherDaoImpl.java @@ -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 implements DMPResearcherDao { @@ -12,6 +16,20 @@ public class DMPResearcherDaoImpl extends JpaDao implements // TODO Auto-generated method stub return null; } + + @Override + public Researcher getResearcherByEmail(String email) { + String queryString = "FROM Researcher researcher where primaryEmail=:email"; + TypedQuery typedQuery = entityManager.createQuery(queryString, Researcher.class); + typedQuery.setParameter("email", email); + try { + return typedQuery.getSingleResult(); + }catch(Exception ex) { + System.out.println(ex.getMessage()); + return null; + } + + } } diff --git a/dmp-backend/src/main/java/dao/entities/RegistryDao.java b/dmp-backend/src/main/java/dao/entities/RegistryDao.java index a4d921610..eebeed1fe 100644 --- a/dmp-backend/src/main/java/dao/entities/RegistryDao.java +++ b/dmp-backend/src/main/java/dao/entities/RegistryDao.java @@ -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 { @@ -12,5 +13,6 @@ public interface RegistryDao extends Dao { List listAllIDs(); List listAllIDsLabels(); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java b/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java index dc59ec05a..1c8bb1a17 100644 --- a/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java @@ -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 implements RegistryDao { @@ -37,6 +38,6 @@ public class RegistryDaoImpl extends JpaDao implements RegistryD }) .collect(Collectors.toList()); } - + } diff --git a/dmp-backend/src/main/java/dao/entities/ResearcherDao.java b/dmp-backend/src/main/java/dao/entities/ResearcherDao.java index 16e74cd34..1cf3913ed 100644 --- a/dmp-backend/src/main/java/dao/entities/ResearcherDao.java +++ b/dmp-backend/src/main/java/dao/entities/ResearcherDao.java @@ -12,5 +12,7 @@ public interface ResearcherDao extends Dao { List listAllIDs(); List listAllIDsLabels(); + + Researcher getResearcherByEmail(String email); } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java b/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java index bdf592e21..6a9d78691 100644 --- a/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java @@ -38,6 +38,16 @@ public class ResearcherDaoImpl extends JpaDao implements Resea }) .collect(Collectors.toList()); } + + + @Override + public Researcher getResearcherByEmail(String email) { + String queryString = "FROM Researcher researcher where researcher.primaryEmail=:email"; + TypedQuery typedQuery = entityManager.createQuery(queryString, Researcher.class); + + + return null; + } } diff --git a/dmp-backend/src/main/java/entities/DatasetProfileRuleset.java b/dmp-backend/src/main/java/entities/DatasetProfileRuleset.java index fe8b02d22..a87db74db 100644 --- a/dmp-backend/src/main/java/entities/DatasetProfileRuleset.java +++ b/dmp-backend/src/main/java/entities/DatasetProfileRuleset.java @@ -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; diff --git a/dmp-backend/src/main/java/entities/DatasetProfileViewstyle.java b/dmp-backend/src/main/java/entities/DatasetProfileViewstyle.java index 84a548ede..c4abd72d0 100644 --- a/dmp-backend/src/main/java/entities/DatasetProfileViewstyle.java +++ b/dmp-backend/src/main/java/entities/DatasetProfileViewstyle.java @@ -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\"") diff --git a/dmp-backend/src/main/java/rest/entities/Datasets.java b/dmp-backend/src/main/java/rest/entities/Datasets.java index 6b9c8e65c..487c29711 100644 --- a/dmp-backend/src/main/java/rest/entities/Datasets.java +++ b/dmp-backend/src/main/java/rest/entities/Datasets.java @@ -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 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 - 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); - } + + 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 { + 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 createEmptyDatasetProfile() { + + + @RequestMapping(method = RequestMethod.POST, value = { "/createEmptyDatasetProfile" }) + public @ResponseBody ResponseEntity 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()); } } - */ + diff --git a/dmp-backend/src/main/java/rest/entities/Researchers.java b/dmp-backend/src/main/java/rest/entities/Researchers.java index ef659665c..c38840d60 100644 --- a/dmp-backend/src/main/java/rest/entities/Researchers.java +++ b/dmp-backend/src/main/java/rest/entities/Researchers.java @@ -96,6 +96,18 @@ public class Researchers { } } + @RequestMapping(method = RequestMethod.GET, value = { "/researcher/getByEmail" }, produces="application/json") + public @ResponseBody ResponseEntity 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 getAllResearchers(){ diff --git a/dmp-frontend/src/app/projects/projects.component.ts b/dmp-frontend/src/app/projects/projects.component.ts index 61da8b3d9..ba4a9b4c1 100644 --- a/dmp-frontend/src/app/projects/projects.component.ts +++ b/dmp-frontend/src/app/projects/projects.component.ts @@ -35,8 +35,22 @@ 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); + }); + } + ); + } diff --git a/dmp-frontend/src/app/services/server.service.ts b/dmp-frontend/src/app/services/server.service.ts index 7d35432ad..dd8cfa73a 100644 --- a/dmp-frontend/src/app/services/server.service.ts +++ b/dmp-frontend/src/app/services/server.service.ts @@ -69,22 +69,29 @@ export class ServerService { } - getDummyProjects(){ - let projects :Project[] =[]; + getProjects(){ + + let headers = new HttpHeaders().set("google-token", this.tokenService.getToken()); - let project = new Project; - project.name = "Project1"; - project.id = "Project1Id"; + console.log("google-token: "+ this.tokenService.getToken()); + + return this.httpClient.get("http://dl010.madgik.di.uoa.gr:8080/dmp-backend-no-sec/rest/project/listAllLabelIDs"); - projects.push(project); + // let projects :Project[] =[]; + + // let project = new Project; + // project.name = "Project1"; + // project.id = "Project1Id"; - let project2 = new Project; - project2.name = "Project2"; - project2.id = "Project2Id"; + // projects.push(project); - projects.push(project2); + // let project2 = new Project; + // project2.name = "Project2"; + // project2.id = "Project2Id"; - return projects; + // projects.push(project2); + + // return projects; } } \ No newline at end of file