dataset getpaged getsingle
This commit is contained in:
parent
d134efcb55
commit
919b60b733
|
@ -1,3 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
|
|
|
@ -55,7 +55,10 @@
|
|||
<version>20160810</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
@SpringBootApplication
|
||||
public class EuDatApplication {
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("spring.devtools.restart.enabled", "true");
|
||||
SpringApplication.run(EuDatApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ public class DatabaseConfiguration {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
|
||||
properties.setProperty("hibernate.show_sql", "true");
|
||||
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults","false");
|
||||
return properties;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,12 @@ import eu.eudat.entities.DMP;
|
|||
import eu.eudat.entities.Dataset;
|
||||
import eu.eudat.entities.DatasetProfile;
|
||||
import eu.eudat.entities.UserInfo;
|
||||
import eu.eudat.managers.DatasetManager;
|
||||
import eu.eudat.managers.ProjectManager;
|
||||
import eu.eudat.models.dataset.DatasetTableRequest;
|
||||
import eu.eudat.models.helpers.DataTableData;
|
||||
import eu.eudat.models.project.Project;
|
||||
import eu.eudat.models.project.ProjectTableRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -59,6 +65,35 @@ public class Datasets {
|
|||
@Autowired private UserInfoDao userInfoDao;
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/datasets/getPaged" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<DataTableData<eu.eudat.models.dataset.Dataset>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest) {
|
||||
try {
|
||||
DataTableData<eu.eudat.models.dataset.Dataset> dataTable = new DatasetManager().getPaged(datasetDao, datasetTableRequest);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(dataTable);
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/datasets/getSingle/{id}" }, produces="application/json")
|
||||
public @ResponseBody ResponseEntity<eu.eudat.models.dataset.Dataset> getPaged(@PathVariable String id) {
|
||||
try {
|
||||
eu.eudat.models.dataset.Dataset dataset = new DatasetManager().getSingle(datasetDao, id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(dataset);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// FETCH BY DATASET(S)
|
||||
|
||||
|
||||
|
|
|
@ -75,21 +75,22 @@ public class Users {
|
|||
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/user/whoami" }, produces="application/json;charset=UTF-8")
|
||||
public @ResponseBody ResponseEntity<Object> whoami(){
|
||||
public @ResponseBody ResponseEntity<UserInfo> 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");
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
||||
}
|
||||
|
||||
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");
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
||||
|
||||
|
||||
try {
|
||||
|
@ -98,7 +99,7 @@ public class Users {
|
|||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,10 @@ import java.util.UUID;
|
|||
|
||||
import eu.eudat.dao.Dao;
|
||||
import eu.eudat.entities.Dataset;
|
||||
import eu.eudat.entities.Project;
|
||||
import eu.eudat.entities.responses.IDLabelPair;
|
||||
import eu.eudat.models.dataset.DatasetTableRequest;
|
||||
import eu.eudat.models.project.ProjectTableRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
public interface DatasetDao extends Dao<Dataset, UUID> {
|
||||
|
@ -17,4 +20,6 @@ public interface DatasetDao extends Dao<Dataset, UUID> {
|
|||
|
||||
List<Dataset> getDatasetsOfDmp(UUID dmpID);
|
||||
|
||||
public List<Dataset> getWithCriteria(DatasetTableRequest datasetTableRequest);
|
||||
|
||||
}
|
|
@ -7,10 +7,15 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import eu.eudat.dao.JpaDao;
|
||||
import eu.eudat.entities.Dataset;
|
||||
import eu.eudat.entities.Project;
|
||||
import eu.eudat.entities.responses.IDLabelPair;
|
||||
import eu.eudat.models.dataset.DatasetTableRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("datasetDao")
|
||||
|
@ -49,5 +54,14 @@ public class DatasetDaoImpl extends JpaDao<Dataset, UUID> implements DatasetDao
|
|||
return datasets;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Dataset> getWithCriteria(DatasetTableRequest datasetTableRequest) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Dataset> criteriaQuery = criteriaBuilder .createQuery(Dataset.class);
|
||||
Root<Dataset> root = criteriaQuery.from(Dataset.class);
|
||||
TypedQuery<Dataset> typedQuery = entityManager.createQuery(criteriaQuery);
|
||||
typedQuery.setFirstResult(datasetTableRequest.getOffset());
|
||||
typedQuery.setMaxResults(datasetTableRequest.getLength());
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|||
@Entity
|
||||
@Table(name="\"DatasetProfile\"")
|
||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
|
||||
public class DatasetProfile implements Serializable {
|
||||
public class DatasetProfile implements Serializable,DataEntity {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 8203086344232867334L;
|
||||
|
@ -173,7 +173,7 @@ public class DatasetProfile implements Serializable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DatasetProfile [id=" + id + ", label=" + label + ", dataset=" + dataset + ", ruleset=" + ruleset
|
||||
return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", ruleset=" + ruleset
|
||||
+ ", viewstyle=" + viewstyle + ", definition=" + definition + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ public class Transformers {
|
|||
dpv.setDefinition(formData.getFirst("DatasetProfileViewStyle.definition"));
|
||||
|
||||
DatasetProfile dp = new DatasetProfile();
|
||||
dp.setLabel(formData.getFirst("DatasetProfile.label"));
|
||||
dp.setDefinition(formData.getFirst("DatasetProfile.definition"));
|
||||
dp.setLabel(formData.getFirst("DatasetProfileListingModel.label"));
|
||||
dp.setDefinition(formData.getFirst("DatasetProfileListingModel.definition"));
|
||||
dp.setRuleset(dpr);
|
||||
dp.setViewstyle(dpv);
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package eu.eudat.managers;
|
||||
|
||||
import eu.eudat.dao.entities.DatasetDao;
|
||||
import eu.eudat.dao.entities.ProjectDao;
|
||||
import eu.eudat.models.dataset.Dataset;
|
||||
import eu.eudat.models.dataset.DatasetTableRequest;
|
||||
import eu.eudat.models.helpers.DataTableData;
|
||||
import eu.eudat.models.project.Project;
|
||||
import eu.eudat.models.project.ProjectTableRequest;
|
||||
import eu.eudat.utilities.builders.DomainModelConverter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
public class DatasetManager {
|
||||
|
||||
public DataTableData<Dataset> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{
|
||||
List<Dataset> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, Dataset>().fromDataModel( datatasetRepository.getWithCriteria(datasetTableRequest), eu.eudat.models.dataset.Dataset.class);
|
||||
DataTableData<eu.eudat.models.dataset.Dataset> dataTable = new DataTableData<eu.eudat.models.dataset.Dataset>();
|
||||
dataTable.setData(datasets);
|
||||
dataTable.setTotalCount(datatasetRepository.count());
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
public eu.eudat.models.dataset.Dataset getSingle(DatasetDao datatasetRepository, String id) throws InstantiationException, IllegalAccessException{
|
||||
eu.eudat.models.dataset.Dataset dataset = new eu.eudat.models.dataset.Dataset();
|
||||
dataset.fromDataModel(datatasetRepository.read(UUID.fromString(id)));
|
||||
return dataset;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.models.criteria;
|
||||
|
||||
import eu.eudat.entities.Dataset;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
public class DatasetCriteria extends Criteria<Dataset>{
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package eu.eudat.models.dataset;
|
||||
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.models.datasetprofile.DatasetProfileListingModel;
|
||||
import eu.eudat.models.dmp.DataManagementPlan;
|
||||
import eu.eudat.utilities.builders.DomainModelConverter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -18,8 +18,8 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
private String description;
|
||||
private short status;
|
||||
private String properties;
|
||||
private eu.eudat.entities.DMP dmp;
|
||||
private eu.eudat.entities.DatasetProfile profile;
|
||||
private DataManagementPlan dmp;
|
||||
private DatasetProfileListingModel profile;
|
||||
private List<Registry> registries;
|
||||
private List<Service> services;
|
||||
private List<DataRepository> dataRepositories;
|
||||
|
@ -88,16 +88,20 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public eu.eudat.entities.DMP getDmp() {
|
||||
|
||||
public DataManagementPlan getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
public void setDmp(eu.eudat.entities.DMP dmp) {
|
||||
|
||||
public void setDmp(DataManagementPlan dmp) {
|
||||
this.dmp = dmp;
|
||||
}
|
||||
public eu.eudat.entities.DatasetProfile getProfile() {
|
||||
|
||||
public DatasetProfileListingModel getProfile() {
|
||||
return profile;
|
||||
}
|
||||
public void setProfile(eu.eudat.entities.DatasetProfile profile) {
|
||||
|
||||
public void setProfile(DatasetProfileListingModel profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
|
@ -106,9 +110,9 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
this.label = entity.getLabel();
|
||||
this.properties = entity.getProperties();
|
||||
this.reference = entity.getReference();
|
||||
//this.dmp = entity.getDmp();
|
||||
this.description = entity.getDescription();
|
||||
this.profile = entity.getProfile();
|
||||
this.profile = new DatasetProfileListingModel();
|
||||
this.profile.fromDataModel(entity.getProfile());
|
||||
this.registries = new DomainModelConverter<eu.eudat.entities.Registry,Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), Registry.class);
|
||||
this.dataRepositories = new DomainModelConverter<eu.eudat.entities.DataRepository,DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), DataRepository.class);
|
||||
this.services = new DomainModelConverter<eu.eudat.entities.Service,Service>().fromDataModel(entity.getServices().stream().collect(Collectors.toList()), Service.class);
|
||||
|
@ -122,9 +126,9 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
|
|||
entity.setUri(this.uri);
|
||||
entity.setProperties(this.properties);
|
||||
entity.setStatus(this.status);
|
||||
entity.setDmp(dmp);
|
||||
entity.setDmp(dmp.toDataModel());
|
||||
entity.setDescription(this.description);
|
||||
entity.setProfile(profile);
|
||||
entity.setProfile(profile.toDataModel()); ///TODO
|
||||
if(!this.registries.isEmpty()){
|
||||
entity.setRegistries(new HashSet<eu.eudat.entities.Registry>());
|
||||
for(Registry registry:this.registries){
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package eu.eudat.models.dataset;
|
||||
|
||||
import eu.eudat.models.criteria.DatasetCriteria;
|
||||
import eu.eudat.models.criteria.ProjectCriteria;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
public class DatasetTableRequest {
|
||||
private int length;
|
||||
private int offset;
|
||||
|
||||
private DatasetCriteria criteria;
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public DatasetCriteria getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public void setCriteria(DatasetCriteria criteria) {
|
||||
this.criteria = criteria;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package eu.eudat.models.datasetprofile;
|
||||
|
||||
import eu.eudat.entities.Dataset;
|
||||
import eu.eudat.entities.DatasetProfile;
|
||||
import eu.eudat.entities.DatasetProfileRuleset;
|
||||
import eu.eudat.entities.DatasetProfileViewstyle;
|
||||
import eu.eudat.models.DataModel;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 12/15/2017.
|
||||
*/
|
||||
public class DatasetProfileListingModel implements DataModel<DatasetProfile> {
|
||||
|
||||
private UUID id;
|
||||
|
||||
private String label;
|
||||
|
||||
private Short status;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified = new Date();
|
||||
|
||||
private String description;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Short getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void setModified(Date modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromDataModel(DatasetProfile entity) throws InstantiationException, IllegalAccessException {
|
||||
this.id = entity.getId();
|
||||
this.label = entity.getLabel();
|
||||
this.status = entity.getStatus();
|
||||
this.created = entity.getCreated();
|
||||
this.modified = entity.getModified();
|
||||
this.description = entity.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatasetProfile toDataModel() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package eu.eudat.proxy.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -14,15 +16,17 @@ public class ConfigLoader {
|
|||
|
||||
private ExternalUrls externalUrls;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
// public static void main(String [] args) {
|
||||
// ConfigLoader l = new ConfigLoader("file:///home/nikolas/git/OpenAIRE-EUDAT-DMP/dmp-backend/src/main/resources/ExternalUrls.xml");
|
||||
// }
|
||||
|
||||
public ConfigLoader() {
|
||||
}
|
||||
public ConfigLoader(String fileUrl) {
|
||||
System.out.println("Loaded also config file: "+fileUrl);
|
||||
private void setExternalUrls() {
|
||||
String fileUrl = this.environment.getProperty("configuration.externalUrls");
|
||||
System.out.println("Loaded also config file: " + fileUrl);
|
||||
InputStream is = null;
|
||||
try {
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
||||
|
@ -30,23 +34,23 @@ public class ConfigLoader {
|
|||
is = new URL(fileUrl).openStream();
|
||||
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
|
||||
// System.out.println(new ObjectMapper().writeValueAsString(externalUrls));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
//log the error and shutdown the system (that's a critical error)
|
||||
ex.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
try {
|
||||
if(is !=null) is.close();
|
||||
if (is != null) is.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Warning: Could not close a stream after reading from file: "+fileUrl);
|
||||
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ExternalUrls getExternalUrls() {
|
||||
this.setExternalUrls();
|
||||
return externalUrls;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ database.password = dmpt00lu$r
|
|||
|
||||
###################Allowed Proxy Service Host ############################
|
||||
eu.eudat.proxy.allowed.host = https://eestore.paas2.uninett.no
|
||||
configuration.externalUrls = file:///C:\\Users\\ikalyvas\\Documents\\Projects\\OpenAIRE-EUDAT-DMP-service-pilot\\dmp-backend\\src\\main\\resources\\ExternalUrls.xml
|
||||
#######################################################
|
||||
|
||||
########################Persistence/Hibernate Generic#############################
|
||||
|
|
Loading…
Reference in New Issue