Minor edit

This commit is contained in:
Nikolaos Laskaris 2017-10-18 10:58:37 +03:00
parent deb527eef0
commit f8490cbc2b
7 changed files with 50 additions and 1 deletions

View File

@ -4,7 +4,11 @@ import java.util.UUID;
import dao.Dao; import dao.Dao;
import entities.DMPResearcher; import entities.DMPResearcher;
import entities.Researcher;
public interface DMPResearcherDao extends Dao<DMPResearcher, UUID> { 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 java.util.UUID;
import javax.persistence.TypedQuery;
import org.hibernate.NonUniqueResultException;
import dao.JpaDao; import dao.JpaDao;
import entities.DMPResearcher; import entities.DMPResearcher;
import entities.Researcher;
public class DMPResearcherDaoImpl extends JpaDao<DMPResearcher, UUID> implements DMPResearcherDao { public class DMPResearcherDaoImpl extends JpaDao<DMPResearcher, UUID> implements DMPResearcherDao {
@ -12,6 +16,20 @@ public class DMPResearcherDaoImpl extends JpaDao<DMPResearcher, UUID> implements
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; 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 dao.Dao;
import entities.Registry; import entities.Registry;
import entities.Researcher;
import entities.responses.IDLabelPair; import entities.responses.IDLabelPair;
public interface RegistryDao extends Dao<Registry, UUID> { public interface RegistryDao extends Dao<Registry, UUID> {
@ -12,5 +13,6 @@ public interface RegistryDao extends Dao<Registry, UUID> {
List<UUID> listAllIDs(); List<UUID> listAllIDs();
List<IDLabelPair> listAllIDsLabels(); List<IDLabelPair> listAllIDsLabels();
} }

View File

@ -10,6 +10,7 @@ import org.hibernate.query.Query;
import dao.JpaDao; import dao.JpaDao;
import entities.Registry; import entities.Registry;
import entities.Researcher;
import entities.responses.IDLabelPair; import entities.responses.IDLabelPair;
public class RegistryDaoImpl extends JpaDao<Registry, UUID> implements RegistryDao { public class RegistryDaoImpl extends JpaDao<Registry, UUID> implements RegistryDao {
@ -37,6 +38,6 @@ public class RegistryDaoImpl extends JpaDao<Registry, UUID> implements RegistryD
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -12,5 +12,7 @@ public interface ResearcherDao extends Dao<Researcher, UUID> {
List<UUID> listAllIDs(); List<UUID> listAllIDs();
List<IDLabelPair> listAllIDsLabels(); List<IDLabelPair> listAllIDsLabels();
Researcher getResearcherByEmail(String email);
} }

View File

@ -38,6 +38,16 @@ public class ResearcherDaoImpl extends JpaDao<Researcher, UUID> implements Resea
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@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

@ -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") @RequestMapping(method = RequestMethod.GET, value = { "/researcher/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllResearchers(){ public @ResponseBody ResponseEntity<Object> getAllResearchers(){