no message
This commit is contained in:
parent
3b5b2ee4c6
commit
dac219c627
|
@ -1,11 +1,14 @@
|
||||||
package eu.eudat;
|
package eu.eudat;
|
||||||
|
|
||||||
|
import eu.eudat.services.helpers.FileStorageService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class EuDatApplication extends SpringBootServletInitializer {
|
public class EuDatApplication extends SpringBootServletInitializer {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package eu.eudat.builders;
|
package eu.eudat.builders;
|
||||||
|
|
||||||
|
import eu.eudat.builders.helpers.BuilderApplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ikalyvas on 2/15/2018.
|
* Created by ikalyvas on 2/15/2018.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,10 +4,8 @@ import eu.eudat.builders.entity.*;
|
||||||
import eu.eudat.builders.model.criteria.DataRepositoryCriteriaBuilder;
|
import eu.eudat.builders.model.criteria.DataRepositoryCriteriaBuilder;
|
||||||
import eu.eudat.builders.model.criteria.ExternalDatasetCriteriaBuilder;
|
import eu.eudat.builders.model.criteria.ExternalDatasetCriteriaBuilder;
|
||||||
import eu.eudat.builders.model.criteria.RegistryCriteriaBuilder;
|
import eu.eudat.builders.model.criteria.RegistryCriteriaBuilder;
|
||||||
import eu.eudat.builders.model.models.DataTableDataBuilder;
|
import eu.eudat.builders.model.models.*;
|
||||||
import eu.eudat.builders.model.models.PrincipalBuilder;
|
import eu.eudat.models.dashboard.recent.RecentActivityData;
|
||||||
import eu.eudat.builders.model.models.ProjectBuilder;
|
|
||||||
import eu.eudat.builders.model.models.ResearcherBuilder;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +27,7 @@ public class BuilderFactoryImpl implements BuilderFactory {
|
||||||
if (tClass.equals(UserTokenBuilder.class)) return (T) new UserTokenBuilder();
|
if (tClass.equals(UserTokenBuilder.class)) return (T) new UserTokenBuilder();
|
||||||
if (tClass.equals(ResearcherBuilder.class)) return (T) new ResearcherBuilder();
|
if (tClass.equals(ResearcherBuilder.class)) return (T) new ResearcherBuilder();
|
||||||
if (tClass.equals(ExternalDatasetCriteriaBuilder.class)) return (T) new ExternalDatasetCriteriaBuilder();
|
if (tClass.equals(ExternalDatasetCriteriaBuilder.class)) return (T) new ExternalDatasetCriteriaBuilder();
|
||||||
|
if (tClass.equals(RecentActivityDataBuilder.class)) return (T) new RecentActivityDataBuilder();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
package eu.eudat.builders.entity;
|
||||||
|
|
||||||
|
import eu.eudat.builders.Builder;
|
||||||
|
import eu.eudat.entities.Content;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/16/2018.
|
||||||
|
*/
|
||||||
|
public class ContentBuilder extends Builder<Content> {
|
||||||
|
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
private String extension;
|
||||||
|
|
||||||
|
private Integer parentType;
|
||||||
|
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
private Integer locationType;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentBuilder id(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentBuilder label(String label) {
|
||||||
|
this.label = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExtension() {
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentBuilder extension(String extension) {
|
||||||
|
this.extension = extension;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getParentType() {
|
||||||
|
return parentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentBuilder parentType(Integer parentType) {
|
||||||
|
this.parentType = parentType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUri() {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentBuilder uri(String uri) {
|
||||||
|
this.uri = uri;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLocationType() {
|
||||||
|
return locationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentBuilder locationType(Integer locationType) {
|
||||||
|
this.locationType = locationType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Content build() {
|
||||||
|
Content content = new Content();
|
||||||
|
content.setExtension(extension);
|
||||||
|
content.setId(id);
|
||||||
|
content.setLabel(label);
|
||||||
|
content.setParentType(parentType);
|
||||||
|
content.setLocationType(locationType);
|
||||||
|
content.setUri(uri);
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package eu.eudat.builders.helpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/15/2018.
|
||||||
|
*/
|
||||||
|
public interface BuilderApplier<T> {
|
||||||
|
void apply(T builder);
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.builders.model.models;
|
package eu.eudat.builders.model.models;
|
||||||
|
|
||||||
import eu.eudat.builders.Builder;
|
import eu.eudat.builders.Builder;
|
||||||
|
import eu.eudat.builders.helpers.BuilderApplier;
|
||||||
import eu.eudat.models.helpers.common.DataTableData;
|
import eu.eudat.models.helpers.common.DataTableData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.builders.model.models;
|
package eu.eudat.builders.model.models;
|
||||||
|
|
||||||
import eu.eudat.builders.Builder;
|
import eu.eudat.builders.Builder;
|
||||||
|
import eu.eudat.builders.helpers.BuilderApplier;
|
||||||
import eu.eudat.models.security.Principal;
|
import eu.eudat.models.security.Principal;
|
||||||
import eu.eudat.types.Authorities;
|
import eu.eudat.types.Authorities;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.builders.model.models;
|
package eu.eudat.builders.model.models;
|
||||||
|
|
||||||
import eu.eudat.builders.Builder;
|
import eu.eudat.builders.Builder;
|
||||||
|
import eu.eudat.builders.helpers.BuilderApplier;
|
||||||
import eu.eudat.entities.UserInfo;
|
import eu.eudat.entities.UserInfo;
|
||||||
import eu.eudat.models.dmp.DataManagementPlan;
|
import eu.eudat.models.dmp.DataManagementPlan;
|
||||||
import eu.eudat.models.project.Project;
|
import eu.eudat.models.project.Project;
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package eu.eudat.builders.model.models;
|
||||||
|
|
||||||
|
import eu.eudat.builders.Builder;
|
||||||
|
import eu.eudat.builders.helpers.BuilderApplier;
|
||||||
|
import eu.eudat.models.dashboard.recent.RecentActivityData;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/14/2018.
|
||||||
|
*/
|
||||||
|
public class RecentActivityDataBuilder extends Builder<RecentActivityData> {
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
private String id;
|
||||||
|
private Date timestamp;
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentActivityDataBuilder label(String label) {
|
||||||
|
this.label = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentActivityDataBuilder id(String id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentActivityDataBuilder timestamp(Date timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentActivityDataBuilder type(Integer type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecentActivityData build() {
|
||||||
|
RecentActivityData recentActivityData = new RecentActivityData();
|
||||||
|
recentActivityData.setLabel(label);
|
||||||
|
recentActivityData.setTimestamp(timestamp);
|
||||||
|
recentActivityData.setId(id);
|
||||||
|
recentActivityData.setType(type);
|
||||||
|
return recentActivityData;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.builders.model.models;
|
package eu.eudat.builders.model.models;
|
||||||
|
|
||||||
import eu.eudat.builders.Builder;
|
import eu.eudat.builders.Builder;
|
||||||
|
import eu.eudat.builders.helpers.BuilderApplier;
|
||||||
import eu.eudat.models.dmp.Researcher;
|
import eu.eudat.models.dmp.Researcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class DevelDatabaseConfiguration {
|
||||||
private Properties additionalProperties() {
|
private Properties additionalProperties() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
|
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
|
||||||
properties.setProperty("hibernate.show_sql", "false");
|
properties.setProperty("hibernate.show_sql", "true");
|
||||||
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
|
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package eu.eudat.controllers;
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
import eu.eudat.managers.DashBoardManager;
|
import eu.eudat.managers.DashBoardManager;
|
||||||
import eu.eudat.models.dashboard.DashBoardStatistics;
|
import eu.eudat.models.dashboard.recent.RecentActivity;
|
||||||
|
import eu.eudat.models.dashboard.statistics.DashBoardStatistics;
|
||||||
import eu.eudat.models.helpers.responses.ResponseItem;
|
import eu.eudat.models.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.security.Principal;
|
import eu.eudat.models.security.Principal;
|
||||||
import eu.eudat.services.ApiContext;
|
import eu.eudat.services.ApiContext;
|
||||||
|
@ -9,10 +10,7 @@ import eu.eudat.types.ApiMessageCode;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
|
@ -47,4 +45,16 @@ public class DashBoardController extends BaseController {
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"/user/recentActivity"}, produces = "application/json")
|
||||||
|
public ResponseEntity<ResponseItem<RecentActivity>> getRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, Principal principal) {
|
||||||
|
try {
|
||||||
|
RecentActivity statistics = new DashBoardManager().getRecentActivity(this.getApiContext(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao()
|
||||||
|
, this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal, numberOfActivities);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RecentActivity>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<RecentActivity>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
|
import eu.eudat.managers.FileManager;
|
||||||
|
import eu.eudat.models.files.ContentFile;
|
||||||
|
import eu.eudat.models.helpers.responses.ResponseItem;
|
||||||
|
import eu.eudat.services.ApiContext;
|
||||||
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/15/2018.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
@RequestMapping(value = {"/api/files"})
|
||||||
|
public class FileController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public FileController(ApiContext apiContext) {
|
||||||
|
super(apiContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
||||||
|
public ResponseEntity<ResponseItem<List<ContentFile>>> handleFileUpload(@RequestParam("file") MultipartFile[] file) {
|
||||||
|
try {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(
|
||||||
|
new ResponseItem<List<ContentFile>>().status(ApiMessageCode.NO_MESSAGE).payload(FileManager.saveTempFile(file, getApiContext().getOperationsContext().getFileStorageService())));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<ContentFile>>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"/{id}"})
|
||||||
|
public ResponseEntity<Resource> handleFileUpload(@PathVariable(name = "id") String id,
|
||||||
|
@RequestParam(name = "type") String type,
|
||||||
|
@RequestParam(name = "location", required = false, defaultValue = "final") String location) {
|
||||||
|
try {
|
||||||
|
Resource resource = FileManager.getFile(id, type, getApiContext().getOperationsContext().getFileStorageService(), location);
|
||||||
|
if (!resource.exists())
|
||||||
|
resource = new UrlResource(FileController.class.getClassLoader().getResource("images/default.png"));
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "." + type + "\"")
|
||||||
|
.body(resource);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ public class Projects extends BaseController {
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataTableData<ProjectListingModel>>> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest, Principal principal) {
|
ResponseEntity<ResponseItem<DataTableData<ProjectListingModel>>> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest, Principal principal) {
|
||||||
try {
|
try {
|
||||||
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new ProjectManager().getPaged(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectTableRequest);
|
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new ProjectManager().getPaged(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectTableRequest, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -65,9 +65,10 @@ public class Projects extends BaseController {
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Project>> addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) {
|
ResponseEntity<ResponseItem<Project>> addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) {
|
||||||
try {
|
try {
|
||||||
ProjectManager.createOrUpdate(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), project, principal);
|
ProjectManager.createOrUpdate(this.getApiContext().getOperationsContext().getFileStorageService(), this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getContentDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), project, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package eu.eudat.dao.entities;
|
||||||
|
|
||||||
|
import eu.eudat.dao.DatabaseAccessLayer;
|
||||||
|
import eu.eudat.entities.Content;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/16/2018.
|
||||||
|
*/
|
||||||
|
public interface ContentDao extends DatabaseAccessLayer<Content, UUID> {
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package eu.eudat.dao.entities;
|
||||||
|
|
||||||
|
import eu.eudat.dao.DatabaseAccess;
|
||||||
|
import eu.eudat.dao.databaselayer.service.DatabaseService;
|
||||||
|
import eu.eudat.entities.Content;
|
||||||
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/16/2018.
|
||||||
|
*/
|
||||||
|
@Service("contentDao")
|
||||||
|
public class ContentDaoImpl extends DatabaseAccess<Content> implements ContentDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ContentDaoImpl(DatabaseService<Content> databaseService) {
|
||||||
|
this.setDatabaseService(databaseService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Content createOrUpdate(Content item) {
|
||||||
|
return this.getDatabaseService().createOrUpdate(item, Content.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Content> createOrUpdateAsync(Content item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Content find(UUID id) {
|
||||||
|
return this.getDatabaseService().getQueryable(Content.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Content find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Content item) {
|
||||||
|
this.getDatabaseService().delete(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryableList<Content> asQueryable() {
|
||||||
|
return this.getDatabaseService().getQueryable(Content.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||||
if (criteria.getProjects() != null && !criteria.getProjects().isEmpty())
|
if (criteria.getProjects() != null && !criteria.getProjects().isEmpty())
|
||||||
query.where(((builder, root) -> root.get("project").in(criteria.getProjectEntities())));
|
query.where(((builder, root) -> root.get("project").in(criteria.getProjectEntities())));
|
||||||
if (!criteria.getAllVersions())
|
if (!criteria.getAllVersions())
|
||||||
query.where((builder, root) -> builder.equal(root.get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class)));
|
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class)));
|
||||||
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
|
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
|
||||||
query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds()));
|
query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds()));
|
||||||
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
|
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
||||||
if (criteria.getPeriodStart() != null)
|
if (criteria.getPeriodStart() != null)
|
||||||
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
|
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
|
||||||
if (!criteria.getAllVersions())
|
if (!criteria.getAllVersions())
|
||||||
query.where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
|
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
|
||||||
if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty())
|
if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty())
|
||||||
query.where((builder, root) -> root.get("dmp").get("id").in(criteria.getDmpIds()));
|
query.where((builder, root) -> root.get("dmp").get("id").in(criteria.getDmpIds()));
|
||||||
return query;
|
return query;
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal) {
|
public QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal) {
|
||||||
query.where((builder, root) -> builder.equal(root.get("creator"), principal));
|
query.where((builder, root) -> builder.or(builder.equal(root.get("creationUser"), principal), builder.isMember(principal, root.join("dmps").get("users")))).distinct();
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
package eu.eudat.entities;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/15/2018.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "\"Content\"")
|
||||||
|
public class Content implements DataEntity<Content, UUID> {
|
||||||
|
|
||||||
|
public enum ParentType {
|
||||||
|
PROJECT(0);
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
private ParentType(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ParentType fromInteger(int value) {
|
||||||
|
switch (value) {
|
||||||
|
case 0:
|
||||||
|
return PROJECT;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported Content Parent Type Status");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LocationType {
|
||||||
|
EXTERNAL(0), INTERNAL(1);
|
||||||
|
|
||||||
|
private Integer value;
|
||||||
|
|
||||||
|
private LocationType(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocationType fromInteger(int value) {
|
||||||
|
switch (value) {
|
||||||
|
case 0:
|
||||||
|
return EXTERNAL;
|
||||||
|
case 1:
|
||||||
|
return INTERNAL;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported Content Location Type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||||
|
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@Column(name = "\"Filename\"", nullable = false)
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
@Column(name = "\"Extension\"", nullable = false)
|
||||||
|
private String extension;
|
||||||
|
|
||||||
|
@Column(name = "\"ParentType\"", nullable = false)
|
||||||
|
private Integer parentType;
|
||||||
|
|
||||||
|
@Column(name = "\"Uri\"", nullable = false)
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
@Column(name = "\"LocationType\"", nullable = false)
|
||||||
|
private Integer locationType;
|
||||||
|
|
||||||
|
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 String getExtension() {
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtension(String extension) {
|
||||||
|
this.extension = extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getParentType() {
|
||||||
|
return parentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentType(Integer parentType) {
|
||||||
|
this.parentType = parentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUri() {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUri(String uri) {
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLocationType() {
|
||||||
|
return locationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocationType(Integer locationType) {
|
||||||
|
this.locationType = locationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Content entity) {
|
||||||
|
this.extension = entity.getExtension();
|
||||||
|
this.label = entity.getLabel();
|
||||||
|
this.locationType = entity.getLocationType();
|
||||||
|
this.parentType = entity.getParentType();
|
||||||
|
this.uri = entity.getUri();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getKeys() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,6 @@ import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.hibernate.annotations.Type;
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,15 +14,19 @@ import java.util.*;
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
name = "dataManagementPlanListingModel",
|
name = "dataManagementPlanListingModel",
|
||||||
attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"),
|
attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"),
|
||||||
@NamedAttributeNode("project"), @NamedAttributeNode("profile"), @NamedAttributeNode("dataset")}
|
@NamedAttributeNode("project"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode("dataset")}
|
||||||
),
|
),
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
name = "fullyDetailed",
|
name = "fullyDetailed",
|
||||||
attributeNodes = {
|
attributeNodes = {
|
||||||
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
|
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
|
||||||
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")})
|
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")}),
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "dmpRecentActivity",
|
||||||
|
attributeNodes = {
|
||||||
|
@NamedAttributeNode("users"), @NamedAttributeNode("creator")})
|
||||||
})
|
})
|
||||||
public class DMP implements DataEntity<DMP,UUID> {
|
public class DMP implements DataEntity<DMP, UUID> {
|
||||||
|
|
||||||
public enum DMPStatus {
|
public enum DMPStatus {
|
||||||
ACTIVE((short) 0), DELETED((short) 1);
|
ACTIVE((short) 0), DELETED((short) 1);
|
||||||
|
@ -89,7 +92,7 @@ public class DMP implements DataEntity<DMP,UUID> {
|
||||||
private DMPProfile profile;
|
private DMPProfile profile;
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "\"Creator\"")
|
@JoinColumn(name = "\"Creator\"")
|
||||||
private UserInfo creator;
|
private UserInfo creator;
|
||||||
|
|
||||||
|
@ -282,6 +285,7 @@ public class DMP implements DataEntity<DMP,UUID> {
|
||||||
this.description = entity.getDescription();
|
this.description = entity.getDescription();
|
||||||
this.researchers = entity.getResearchers();
|
this.researchers = entity.getResearchers();
|
||||||
this.organisations = entity.getOrganisations();
|
this.organisations = entity.getOrganisations();
|
||||||
|
this.setModified(new Date());
|
||||||
if (entity.getUsers() != null) this.users = entity.getUsers();
|
if (entity.getUsers() != null) this.users = entity.getUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,13 @@ import java.util.*;
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
name = "datasetWizardModel",
|
name = "datasetWizardModel",
|
||||||
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("dataRepositories"), @NamedAttributeNode("externalDatasets"), @NamedAttributeNode("registries"),
|
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("dataRepositories"), @NamedAttributeNode("externalDatasets"), @NamedAttributeNode("registries"),
|
||||||
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")})
|
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}),
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "datasetRecentActivity",
|
||||||
|
attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("creator")},
|
||||||
|
subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")}))
|
||||||
})
|
})
|
||||||
public class Dataset implements DataEntity<Dataset,UUID> {
|
public class Dataset implements DataEntity<Dataset, UUID> {
|
||||||
|
|
||||||
public static Set<String> getHints() {
|
public static Set<String> getHints() {
|
||||||
return hints;
|
return hints;
|
||||||
|
@ -309,6 +313,7 @@ public class Dataset implements DataEntity<Dataset,UUID> {
|
||||||
this.setExternalDatasets(entity.getExternalDatasets());
|
this.setExternalDatasets(entity.getExternalDatasets());
|
||||||
this.setStatus(entity.getStatus());
|
this.setStatus(entity.getStatus());
|
||||||
this.setProfile(entity.getProfile());
|
this.setProfile(entity.getProfile());
|
||||||
|
this.setModified(new Date());
|
||||||
if (entity.getCreator() != null) this.creator = entity.getCreator();
|
if (entity.getCreator() != null) this.creator = entity.getCreator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package eu.eudat.entities;
|
package eu.eudat.entities;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.hibernate.annotations.Type;
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
|
@ -15,7 +12,14 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Project\"")
|
@Table(name = "\"Project\"")
|
||||||
public class Project implements DataEntity<Project,UUID> {
|
@NamedEntityGraphs({
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "projectRecentActivity",
|
||||||
|
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")},
|
||||||
|
subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
public class Project implements DataEntity<Project, UUID> {
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
|
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
|
||||||
|
@ -44,6 +48,31 @@ public class Project implements DataEntity<Project,UUID> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ProjectType {
|
||||||
|
EXTERNAL(0), INTERNAL(1);
|
||||||
|
|
||||||
|
private Integer value;
|
||||||
|
|
||||||
|
private ProjectType(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProjectType fromInteger(int value) {
|
||||||
|
switch (value) {
|
||||||
|
case 0:
|
||||||
|
return EXTERNAL;
|
||||||
|
case 1:
|
||||||
|
return INTERNAL;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported Project Type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||||
|
@ -98,12 +127,17 @@ public class Project implements DataEntity<Project,UUID> {
|
||||||
@Column(name = "\"Description\"")
|
@Column(name = "\"Description\"")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "\"Type\"")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@OneToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"Content\"")
|
||||||
|
private Content content;
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
@ -133,32 +167,26 @@ public class Project implements DataEntity<Project,UUID> {
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
public void setModified(Date modified) {
|
||||||
this.modified = modified;
|
this.modified = modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getStartdate() {
|
public Date getStartdate() {
|
||||||
return startdate;
|
return startdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setStartdate(Date startdate) {
|
public void setStartdate(Date startdate) {
|
||||||
this.startdate = startdate;
|
this.startdate = startdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getEnddate() {
|
public Date getEnddate() {
|
||||||
return enddate;
|
return enddate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setEnddate(Date enddate) {
|
public void setEnddate(Date enddate) {
|
||||||
this.enddate = enddate;
|
this.enddate = enddate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -216,23 +244,28 @@ public class Project implements DataEntity<Project,UUID> {
|
||||||
this.dmps = dmps;
|
this.dmps = dmps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UserInfo getCreationUser() {
|
public UserInfo getCreationUser() {
|
||||||
return creationUser;
|
return creationUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCreationUser(UserInfo creationUser) {
|
public void setCreationUser(UserInfo creationUser) {
|
||||||
this.creationUser = creationUser;
|
this.creationUser = creationUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getType() {
|
||||||
public String toString() {
|
return type;
|
||||||
try {
|
|
||||||
return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(this).replace("\"", """);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setType(Integer type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Content getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(Content content) {
|
||||||
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -244,6 +277,8 @@ public class Project implements DataEntity<Project,UUID> {
|
||||||
this.definition = entity.getDefinition();
|
this.definition = entity.getDefinition();
|
||||||
this.dmps = entity.getDmps();
|
this.dmps = entity.getDmps();
|
||||||
this.enddate = entity.getEnddate();
|
this.enddate = entity.getEnddate();
|
||||||
|
this.modified = new Date();
|
||||||
|
if (entity.getContent() != null) this.content = entity.getContent();
|
||||||
//this.creationUser = entity.getCreationUser(); //TODO
|
//this.creationUser = entity.getCreationUser(); //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package eu.eudat.exceptions.files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/16/2018.
|
||||||
|
*/
|
||||||
|
public class TempFileNotFoundException extends RuntimeException {
|
||||||
|
public TempFileNotFoundException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TempFileNotFoundException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TempFileNotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TempFileNotFoundException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,41 @@
|
||||||
package eu.eudat.managers;
|
package eu.eudat.managers;
|
||||||
|
|
||||||
|
import eu.eudat.builders.model.models.RecentActivityDataBuilder;
|
||||||
import eu.eudat.dao.entities.DMPDao;
|
import eu.eudat.dao.entities.DMPDao;
|
||||||
import eu.eudat.dao.entities.DatasetDao;
|
import eu.eudat.dao.entities.DatasetDao;
|
||||||
import eu.eudat.dao.entities.ProjectDao;
|
import eu.eudat.dao.entities.ProjectDao;
|
||||||
import eu.eudat.entities.UserInfo;
|
import eu.eudat.entities.UserInfo;
|
||||||
import eu.eudat.models.dashboard.DashBoardStatistics;
|
import eu.eudat.models.criteria.DataManagementPlanCriteria;
|
||||||
|
import eu.eudat.models.criteria.DatasetCriteria;
|
||||||
|
import eu.eudat.models.dashboard.recent.RecentActivity;
|
||||||
|
import eu.eudat.models.dashboard.recent.RecentActivityData;
|
||||||
|
import eu.eudat.models.dashboard.statistics.DashBoardStatistics;
|
||||||
import eu.eudat.models.security.Principal;
|
import eu.eudat.models.security.Principal;
|
||||||
|
import eu.eudat.services.ApiContext;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class DashBoardManager {
|
public class DashBoardManager {
|
||||||
|
|
||||||
public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) {
|
public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) {
|
||||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||||
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.asQueryable().count());
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
statistics.setTotalDataSetCount(datasetRepository.asQueryable().count());
|
datasetCriteria.setAllVersions(false);
|
||||||
statistics.setTotalProjectCount(projectRepository.asQueryable().count());
|
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
|
dataManagementPlanCriteria.setAllVersions(false);
|
||||||
|
|
||||||
|
CompletableFuture dmpFuture = dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria).countAsync()
|
||||||
|
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
||||||
|
CompletableFuture datasetFuture = datasetRepository.getWithCriteria(datasetCriteria).countAsync()
|
||||||
|
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
||||||
|
CompletableFuture projectFuture = projectRepository.asQueryable().countAsync()
|
||||||
|
.whenComplete((projectsStats, throwable) -> statistics.setTotalProjectCount(projectsStats));
|
||||||
|
|
||||||
|
CompletableFuture.allOf(dmpFuture, datasetFuture, projectFuture).join();
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,10 +43,55 @@ public class DashBoardManager {
|
||||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||||
UserInfo user = new UserInfo();
|
UserInfo user = new UserInfo();
|
||||||
user.setId(principal.getId());
|
user.setId(principal.getId());
|
||||||
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.asQueryable().where((builder, root) -> builder.equal(root.get("creator").get("id"), principal.getId())).count());
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
statistics.setTotalDataSetCount(datasetRepository.asQueryable().where((builder, root) -> builder.equal(root.get("creator").get("id"), principal.getId())).count());
|
datasetCriteria.setAllVersions(false);
|
||||||
statistics.setTotalProjectCount(projectRepository.asQueryable().where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId())).count());
|
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
|
dataManagementPlanCriteria.setAllVersions(false);
|
||||||
|
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), user).countAsync()
|
||||||
|
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
||||||
|
CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user).countAsync()
|
||||||
|
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
||||||
|
CompletableFuture projectFuture = projectRepository.getAuthenticated(projectRepository.asQueryable(), user).countAsync()
|
||||||
|
.whenComplete((projectsStats, throwable) -> statistics.setTotalProjectCount(projectsStats));
|
||||||
|
|
||||||
|
CompletableFuture.allOf(dmpFuture, datasetFuture, projectFuture).join();
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RecentActivity getRecentActivity(ApiContext apiContext, DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository, Principal principal, Integer numberofactivities) {
|
||||||
|
RecentActivity activity = new RecentActivity();
|
||||||
|
UserInfo user = new UserInfo();
|
||||||
|
user.setId(principal.getId());
|
||||||
|
List<RecentActivityData> activities = new LinkedList<>();
|
||||||
|
|
||||||
|
RecentActivityDataBuilder recentActivityDataBuilder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(RecentActivityDataBuilder.class);
|
||||||
|
|
||||||
|
CompletableFuture<List<RecentActivityData>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), user)
|
||||||
|
.withHint("dmpRecentActivity")
|
||||||
|
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||||
|
.take(numberofactivities)
|
||||||
|
.selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).type(RecentActivityData.RecentActivityType.DMP.getValue()).build())
|
||||||
|
.whenComplete((dmpActivities, throwable) -> activities.addAll(dmpActivities));
|
||||||
|
|
||||||
|
CompletableFuture<List<RecentActivityData>> datasets = datasetRepository.getAuthenticated(datasetRepository.asQueryable(), user)
|
||||||
|
.withHint("datasetRecentActivity")
|
||||||
|
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||||
|
.take(numberofactivities)
|
||||||
|
.selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).type(RecentActivityData.RecentActivityType.DATASET.getValue()).build())
|
||||||
|
.whenComplete((datasetActivities, throwable) -> activities.addAll(datasetActivities));
|
||||||
|
|
||||||
|
CompletableFuture<List<RecentActivityData>> projects = projectRepository.getAuthenticated(projectRepository.asQueryable(), user)
|
||||||
|
.withHint("projectRecentActivity")
|
||||||
|
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||||
|
.take(numberofactivities)
|
||||||
|
.selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).type(RecentActivityData.RecentActivityType.PROJECT.getValue()).build())
|
||||||
|
.whenComplete((projectActivities, throwable) -> activities.addAll(projectActivities));
|
||||||
|
|
||||||
|
CompletableFuture.allOf(projects, dmps, datasets).join();
|
||||||
|
Collections.sort(activities, Comparator.comparing(RecentActivityData::getTimestamp).reversed());
|
||||||
|
activity.setRecentActivities(activities.subList(0, numberofactivities));
|
||||||
|
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,18 +33,18 @@ public class DataManagementPlanManager {
|
||||||
public DataTableData<DataManagementPlanListingModel> getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
|
public DataTableData<DataManagementPlanListingModel> getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
|
||||||
UserInfo userInfo = new UserInfo();
|
UserInfo userInfo = new UserInfo();
|
||||||
userInfo.setId(principal.getId());
|
userInfo.setId(principal.getId());
|
||||||
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class));
|
||||||
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo);
|
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo);
|
||||||
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
|
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
|
||||||
|
|
||||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
|
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
|
||||||
|
|
||||||
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
|
CompletableFuture itemsFuture = pagedItems
|
||||||
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
||||||
dataTable.setData(resultList);
|
dataTable.setData(resultList);
|
||||||
});
|
});
|
||||||
|
|
||||||
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> {
|
||||||
dataTable.setTotalCount(count);
|
dataTable.setTotalCount(count);
|
||||||
});
|
});
|
||||||
CompletableFuture.allOf(itemsFuture, countFuture).join();
|
CompletableFuture.allOf(itemsFuture, countFuture).join();
|
||||||
|
@ -155,7 +155,7 @@ public class DataManagementPlanManager {
|
||||||
eu.eudat.entities.Project projectEntity = projectDao.getWithCriteria(criteria).getSingleOrDefault();
|
eu.eudat.entities.Project projectEntity = projectDao.getWithCriteria(criteria).getSingleOrDefault();
|
||||||
if (projectEntity != null) project.setId(projectEntity.getId());
|
if (projectEntity != null) project.setId(projectEntity.getId());
|
||||||
else {
|
else {
|
||||||
project.setCreationUser(userInfo);
|
project.setType(Project.ProjectType.EXTERNAL.getValue());
|
||||||
projectDao.createOrUpdate(project);
|
projectDao.createOrUpdate(project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,17 +43,18 @@ public class DatasetManager {
|
||||||
|
|
||||||
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
||||||
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||||
QueryableList<eu.eudat.entities.Dataset> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria());
|
QueryableList<eu.eudat.entities.Dataset> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
||||||
QueryableList<eu.eudat.entities.Dataset> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getAuthenticated(items, userInfo);
|
QueryableList<eu.eudat.entities.Dataset> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getAuthenticated(items, userInfo);
|
||||||
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
|
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
|
||||||
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
||||||
|
|
||||||
CompletableFuture<List<DatasetListingModel>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).
|
|
||||||
|
CompletableFuture<List<DatasetListingModel>> itemsFuture = pagedItems.
|
||||||
selectAsync(item -> new DatasetListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
selectAsync(item -> new DatasetListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
||||||
dataTable.setData(resultList);
|
dataTable.setData(resultList);
|
||||||
});
|
});
|
||||||
|
|
||||||
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> {
|
||||||
dataTable.setTotalCount(count);
|
dataTable.setTotalCount(count);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package eu.eudat.managers;
|
||||||
|
|
||||||
|
import eu.eudat.models.files.ContentFile;
|
||||||
|
import eu.eudat.services.helpers.FileStorageService;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/15/2018.
|
||||||
|
*/
|
||||||
|
public class FileManager {
|
||||||
|
|
||||||
|
public static List<ContentFile> saveTempFile(MultipartFile file[], FileStorageService fileStorageService) throws IOException {
|
||||||
|
return fileStorageService.writeToTempFileSystem(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Resource getFile(String filename, String type, FileStorageService fileStorageService, String location) throws IOException {
|
||||||
|
return fileStorageService.readFromFilesystem(filename, type, location);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,16 @@
|
||||||
package eu.eudat.managers;
|
package eu.eudat.managers;
|
||||||
|
|
||||||
|
import eu.eudat.builders.entity.ContentBuilder;
|
||||||
import eu.eudat.builders.model.models.ProjectBuilder;
|
import eu.eudat.builders.model.models.ProjectBuilder;
|
||||||
|
import eu.eudat.dao.entities.ContentDao;
|
||||||
import eu.eudat.dao.entities.ProjectDao;
|
import eu.eudat.dao.entities.ProjectDao;
|
||||||
import eu.eudat.dao.entities.UserInfoDao;
|
import eu.eudat.dao.entities.UserInfoDao;
|
||||||
|
import eu.eudat.entities.Content;
|
||||||
|
import eu.eudat.exceptions.files.TempFileNotFoundException;
|
||||||
import eu.eudat.models.HintedModelFactory;
|
import eu.eudat.models.HintedModelFactory;
|
||||||
import eu.eudat.models.external.ExternalSourcesItemModel;
|
import eu.eudat.models.external.ExternalSourcesItemModel;
|
||||||
import eu.eudat.models.external.ProjectsExternalSourcesModel;
|
import eu.eudat.models.external.ProjectsExternalSourcesModel;
|
||||||
|
import eu.eudat.models.files.ContentFile;
|
||||||
import eu.eudat.models.helpers.common.DataTableData;
|
import eu.eudat.models.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.project.Project;
|
import eu.eudat.models.project.Project;
|
||||||
import eu.eudat.models.project.ProjectCriteriaRequest;
|
import eu.eudat.models.project.ProjectCriteriaRequest;
|
||||||
|
@ -17,20 +22,25 @@ import eu.eudat.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.proxy.fetching.RemoteFetcher;
|
import eu.eudat.proxy.fetching.RemoteFetcher;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.services.ApiContext;
|
import eu.eudat.services.ApiContext;
|
||||||
|
import eu.eudat.services.helpers.FileStorageService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ProjectManager {
|
public class ProjectManager {
|
||||||
|
|
||||||
public DataTableData<eu.eudat.models.project.ProjectListingModel> getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest) throws Exception {
|
public DataTableData<eu.eudat.models.project.ProjectListingModel> getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest, Principal principal) throws Exception {
|
||||||
|
eu.eudat.entities.UserInfo userInfo = new eu.eudat.entities.UserInfo();
|
||||||
|
userInfo.setId(principal.getId());
|
||||||
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectTableRequest.getCriteria());
|
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectTableRequest.getCriteria());
|
||||||
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items, projectTableRequest);
|
QueryableList<eu.eudat.entities.Project> authItems = projectRepository.getAuthenticated(items, userInfo);
|
||||||
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<eu.eudat.models.project.ProjectListingModel>();
|
|
||||||
|
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(authItems, projectTableRequest);
|
||||||
|
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<>();
|
||||||
|
|
||||||
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> new ProjectListingModel().fromDataModel(item)).whenComplete((results, throwable) -> {
|
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> new ProjectListingModel().fromDataModel(item)).whenComplete((results, throwable) -> {
|
||||||
dataTable.setData(results);
|
dataTable.setData(results);
|
||||||
|
@ -79,8 +89,23 @@ public class ProjectManager {
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createOrUpdate(ProjectDao projectRepository, UserInfoDao userInfoRepository, eu.eudat.models.project.Project project, Principal principal) throws ParseException {
|
public static void createOrUpdate(FileStorageService fileStorageService, ProjectDao projectRepository, ContentDao contentRepository, UserInfoDao userInfoRepository, eu.eudat.models.project.Project project, Principal principal) throws ParseException, IOException {
|
||||||
eu.eudat.entities.Project projectEntity = project.toDataModel();
|
eu.eudat.entities.Project projectEntity = project.toDataModel();
|
||||||
|
for (ContentFile file : project.getFiles()) {
|
||||||
|
try {
|
||||||
|
ContentFile storedFile = fileStorageService.copyFromTempFileSystem(file);
|
||||||
|
Content content = new ContentBuilder().extension(file.getType())
|
||||||
|
.label(file.getFilename())
|
||||||
|
.locationType(Content.LocationType.INTERNAL.getValue())
|
||||||
|
.parentType(Content.ParentType.PROJECT.getValue())
|
||||||
|
.uri("LOCAL:" + storedFile.getId())
|
||||||
|
.build();
|
||||||
|
projectEntity.setContent(contentRepository.createOrUpdate(content));
|
||||||
|
} catch (TempFileNotFoundException e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
projectEntity.setCreationUser(userInfoRepository.find(principal.getId()));
|
projectEntity.setCreationUser(userInfoRepository.find(principal.getId()));
|
||||||
projectRepository.createOrUpdate(projectEntity);
|
projectRepository.createOrUpdate(projectEntity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package eu.eudat.models.dashboard.recent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/14/2018.
|
||||||
|
*/
|
||||||
|
public class RecentActivity {
|
||||||
|
private List<RecentActivityData> recentActivities;
|
||||||
|
|
||||||
|
public List<RecentActivityData> getRecentActivities() {
|
||||||
|
return recentActivities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecentActivities(List<RecentActivityData> recentActivities) {
|
||||||
|
this.recentActivities = recentActivities;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package eu.eudat.models.dashboard.recent;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/14/2018.
|
||||||
|
*/
|
||||||
|
public class RecentActivityData {
|
||||||
|
|
||||||
|
public enum RecentActivityType {
|
||||||
|
PROJECT(0), DATASET(1), DMP(2);
|
||||||
|
|
||||||
|
private Integer value;
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RecentActivityType(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RecentActivityType fromValue(Integer value) {
|
||||||
|
switch (value) {
|
||||||
|
case 0:
|
||||||
|
return PROJECT;
|
||||||
|
case 1:
|
||||||
|
return DATASET;
|
||||||
|
case 2:
|
||||||
|
return DMP;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported Recent Activity Status");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
private String id;
|
||||||
|
private Date timestamp;
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Integer type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestamp(Date timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.models.dashboard;
|
package eu.eudat.models.dashboard.statistics;
|
||||||
|
|
||||||
public class DashBoardStatistics {
|
public class DashBoardStatistics {
|
||||||
private Long totalDataManagementPlanCount;
|
private Long totalDataManagementPlanCount;
|
|
@ -0,0 +1,55 @@
|
||||||
|
package eu.eudat.models.files;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/15/2018.
|
||||||
|
*/
|
||||||
|
public class ContentFile {
|
||||||
|
private String filename;
|
||||||
|
private UUID id;
|
||||||
|
private String location;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public ContentFile() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentFile(String filename, UUID id, String location, String type) {
|
||||||
|
this.filename = filename;
|
||||||
|
this.id = id;
|
||||||
|
this.location = location;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilename() {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilename(String filename) {
|
||||||
|
this.filename = filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,9 @@ package eu.eudat.models.project;
|
||||||
import eu.eudat.entities.UserInfo;
|
import eu.eudat.entities.UserInfo;
|
||||||
import eu.eudat.models.DataModel;
|
import eu.eudat.models.DataModel;
|
||||||
import eu.eudat.models.dmp.DataManagementPlan;
|
import eu.eudat.models.dmp.DataManagementPlan;
|
||||||
|
import eu.eudat.models.files.ContentFile;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -39,6 +41,8 @@ public class Project implements DataModel<eu.eudat.entities.Project, Project> {
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
private List<ContentFile> files;
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -152,6 +156,14 @@ public class Project implements DataModel<eu.eudat.entities.Project, Project> {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ContentFile> getFiles() {
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiles(List<ContentFile> files) {
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Project fromDataModel(eu.eudat.entities.Project entity) {
|
public Project fromDataModel(eu.eudat.entities.Project entity) {
|
||||||
this.id = entity.getId();
|
this.id = entity.getId();
|
||||||
|
@ -166,6 +178,7 @@ public class Project implements DataModel<eu.eudat.entities.Project, Project> {
|
||||||
this.created = entity.getCreated();
|
this.created = entity.getCreated();
|
||||||
this.modified = entity.getModified();
|
this.modified = entity.getModified();
|
||||||
this.description = entity.getDescription();
|
this.description = entity.getDescription();
|
||||||
|
this.files = entity.getContent() != null ? Arrays.asList(new ContentFile(entity.getContent().getLabel(), UUID.fromString(entity.getContent().getUri().split(":")[1]), "final", entity.getContent().getExtension())) : Arrays.asList(new ContentFile("default.png", null, null, null));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@ import eu.eudat.entities.Project;
|
||||||
import eu.eudat.entities.UserInfo;
|
import eu.eudat.entities.UserInfo;
|
||||||
import eu.eudat.models.DataModel;
|
import eu.eudat.models.DataModel;
|
||||||
import eu.eudat.models.dmp.DataManagementPlan;
|
import eu.eudat.models.dmp.DataManagementPlan;
|
||||||
|
import eu.eudat.models.files.ContentFile;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -39,6 +41,8 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
private List<ContentFile> files;
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -152,6 +156,14 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ContentFile> getFiles() {
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiles(List<ContentFile> files) {
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectListingModel fromDataModel(eu.eudat.entities.Project entity) {
|
public ProjectListingModel fromDataModel(eu.eudat.entities.Project entity) {
|
||||||
this.id = entity.getId();
|
this.id = entity.getId();
|
||||||
|
@ -166,6 +178,7 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,
|
||||||
this.created = entity.getCreated().toString();
|
this.created = entity.getCreated().toString();
|
||||||
this.modified = entity.getModified().toString();
|
this.modified = entity.getModified().toString();
|
||||||
this.description = entity.getDescription();
|
this.description = entity.getDescription();
|
||||||
|
this.files = entity.getContent() != null ? Arrays.asList(new ContentFile(entity.getContent().getLabel(), UUID.fromString(entity.getContent().getUri().split(":")[1]), "final", entity.getContent().getExtension())) : Arrays.asList(new ContentFile("default.png", null, null, null));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,8 @@ public interface QueryableList<T extends DataEntity> {
|
||||||
|
|
||||||
Subquery<Long> subQueryCount(SinglePredicate<T> predicate, List<SelectionField> fields);
|
Subquery<Long> subQueryCount(SinglePredicate<T> predicate, List<SelectionField> fields);
|
||||||
|
|
||||||
|
<U extends Comparable> QueryableList<T> initSubQuery(Class<U> uClass);
|
||||||
|
|
||||||
<U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass);
|
<U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass);
|
||||||
|
|
||||||
<U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass);
|
<U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass);
|
||||||
|
|
|
@ -28,10 +28,10 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
private Class<T> tClass;
|
private Class<T> tClass;
|
||||||
private Root<T> root;
|
private Root<T> root;
|
||||||
private Root<T> nestedQueryRoot;
|
private Root<T> nestedQueryRoot;
|
||||||
private Subquery<T> subquery;
|
private Subquery subquery;
|
||||||
private List<SinglePredicate<T>> singlePredicates = new LinkedList<>();
|
private List<SinglePredicate<T>> singlePredicates = new LinkedList<>();
|
||||||
private List<NestedQuerySinglePredicate<T>> nestedPredicates = new LinkedList<>();
|
private List<NestedQuerySinglePredicate<T>> nestedPredicates = new LinkedList<>();
|
||||||
|
private boolean distinct = false;
|
||||||
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
|
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
|
||||||
private List<String> fields = new LinkedList<>();
|
private List<String> fields = new LinkedList<>();
|
||||||
private Integer length;
|
private Integer length;
|
||||||
|
@ -114,7 +114,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryableList<T> distinct() {
|
public QueryableList<T> distinct() {
|
||||||
this.query.distinct(true);
|
this.distinct = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,18 +126,22 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
public Long count() {
|
public Long count() {
|
||||||
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
||||||
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
Root<T> root = criteriaQuery.from(tClass);
|
this.root = criteriaQuery.from(tClass);
|
||||||
criteriaQuery.select(criteriaBuilder.count(root));
|
if (distinct) criteriaQuery.select(criteriaBuilder.countDistinct(this.root.get("id")));
|
||||||
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, root, this.nestedPredicates, this.nestedQueryRoot));
|
else criteriaQuery.select(criteriaBuilder.count(this.root));
|
||||||
|
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
|
//if (distinct) criteriaQuery.distinct(true);
|
||||||
return this.manager.createQuery(criteriaQuery).getSingleResult();
|
return this.manager.createQuery(criteriaQuery).getSingleResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Long> countAsync() {
|
public CompletableFuture<Long> countAsync() {
|
||||||
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
||||||
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||||
Root<T> root = criteriaQuery.from(tClass);
|
this.root = criteriaQuery.from(tClass);
|
||||||
criteriaQuery.select(criteriaBuilder.count(root));
|
if (distinct) criteriaQuery.select(criteriaBuilder.countDistinct(this.root.get("id")));
|
||||||
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, root, this.nestedPredicates, this.nestedQueryRoot));
|
else criteriaQuery.select(criteriaBuilder.count(this.root));
|
||||||
|
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
|
//if (distinct) criteriaQuery.distinct(true);
|
||||||
return CompletableFuture.supplyAsync(() -> this.manager.createQuery(criteriaQuery).getSingleResult());
|
return CompletableFuture.supplyAsync(() -> this.manager.createQuery(criteriaQuery).getSingleResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,10 +181,11 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
|
if (distinct) this.query.distinct(true);
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||||
if (this.hint != null && this.hints.contains(hint)) {
|
if (this.hint != null) {
|
||||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||||
if (ids != null && !ids.isEmpty()) typedQuery = queryWithHint(ids);
|
if (ids != null && !ids.isEmpty()) typedQuery = queryWithHint(ids);
|
||||||
}
|
}
|
||||||
|
@ -191,11 +196,12 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||||
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
|
if (distinct) this.query.distinct(true);
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
if (this.hint != null && this.hints.contains(hint)) {
|
if (this.hint != null) {
|
||||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||||
if (ids != null && !ids.isEmpty()) return queryWithHint(ids).getResultList();
|
if (ids != null && !ids.isEmpty()) return queryWithHint(ids).getResultList();
|
||||||
}
|
}
|
||||||
|
@ -310,8 +316,8 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
|
public <U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
|
||||||
Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
//Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
||||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
//this.nestedQueryRoot = subquery.from(this.tClass);
|
||||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
||||||
if (fields.get(0).getType() == FieldSelectionType.FIELD)
|
if (fields.get(0).getType() == FieldSelectionType.FIELD)
|
||||||
subquery.select(this.manager.getCriteriaBuilder().greatest(this.nestedQueryRoot.<U>get(fields.get(0).getField())));
|
subquery.select(this.manager.getCriteriaBuilder().greatest(this.nestedQueryRoot.<U>get(fields.get(0).getField())));
|
||||||
|
@ -320,4 +326,10 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
}
|
}
|
||||||
return subquery;
|
return subquery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <U extends Comparable> QueryableList<T> initSubQuery(Class<U> uClass) {
|
||||||
|
this.subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
||||||
|
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package eu.eudat.services.helpers;
|
||||||
|
|
||||||
|
import eu.eudat.models.files.ContentFile;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/15/2018.
|
||||||
|
*/
|
||||||
|
public interface FileStorageService {
|
||||||
|
List<ContentFile> writeToTempFileSystem(MultipartFile[] multipartFiles) throws IOException;
|
||||||
|
|
||||||
|
ContentFile copyFromTempFileSystem(ContentFile file) throws IOException;
|
||||||
|
|
||||||
|
Resource readFromFilesystem(String filename, String type, String location) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package eu.eudat.services.helpers;
|
||||||
|
|
||||||
|
import eu.eudat.exceptions.files.TempFileNotFoundException;
|
||||||
|
import eu.eudat.models.files.ContentFile;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 3/15/2018.
|
||||||
|
*/
|
||||||
|
@Service("fileStorageService")
|
||||||
|
public class FileStorageServiceImpl implements FileStorageService {
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public FileStorageServiceImpl(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ContentFile> writeToTempFileSystem(MultipartFile[] multipartFiles) throws IOException {
|
||||||
|
List<ContentFile> contentFileList = new LinkedList<>();
|
||||||
|
for (MultipartFile multipartFile : Arrays.asList(multipartFiles)) {
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
Files.copy(multipartFile.getInputStream(), Paths.get(environment.getProperty("files.storage.temp")).resolve(id.toString()));
|
||||||
|
ContentFile contentFile = new ContentFile(multipartFile.getOriginalFilename(), id, "temp", getFileExtension(multipartFile.getOriginalFilename()));
|
||||||
|
contentFileList.add(contentFile);
|
||||||
|
}
|
||||||
|
return contentFileList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentFile copyFromTempFileSystem(ContentFile file) throws IOException, TempFileNotFoundException {
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
if (!Files.exists(Paths.get(environment.getProperty("files.storage.temp") + "/" + file.getId())))
|
||||||
|
throw new TempFileNotFoundException();
|
||||||
|
Files.copy(Paths.get(environment.getProperty("files.storage.temp") + "/" + file.getId()), Paths.get(environment.getProperty("files.storage.final")).resolve(id.toString()));
|
||||||
|
ContentFile contentFile = new ContentFile(file.getFilename(), id, file.getLocation(), file.getType());
|
||||||
|
return contentFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resource readFromFilesystem(String filename, String type, String location) throws IOException {
|
||||||
|
if (location.equals("temp")) {
|
||||||
|
return new UrlResource(Paths.get(environment.getProperty("files.storage.temp") + '/' + filename).toUri());
|
||||||
|
} else {
|
||||||
|
return new UrlResource(Paths.get(environment.getProperty("files.storage.final") + '/' + filename).toUri());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
try {
|
||||||
|
if (!Files.exists(Paths.get(environment.getProperty("files.storage.temp")))) {
|
||||||
|
Files.createDirectory(Paths.get(environment.getProperty("files.storage.temp")));
|
||||||
|
}
|
||||||
|
if (!Files.exists(Paths.get(environment.getProperty("files.storage.final")))) {
|
||||||
|
Files.createDirectory(Paths.get(environment.getProperty("files.storage.final")));
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFileExtension(String fileName) {
|
||||||
|
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0)
|
||||||
|
return fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||||
|
else return "";
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,4 +37,6 @@ public interface DatabaseRepository {
|
||||||
ExternalDatasetDao getExternalDatasetDao();
|
ExternalDatasetDao getExternalDatasetDao();
|
||||||
|
|
||||||
UserDmpDao getUserDmpDao();
|
UserDmpDao getUserDmpDao();
|
||||||
|
|
||||||
|
ContentDao getContentDao();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
||||||
private ExternalDatasetDao externalDatasetDao;
|
private ExternalDatasetDao externalDatasetDao;
|
||||||
private UserRoleDao userRoleDao;
|
private UserRoleDao userRoleDao;
|
||||||
private UserDmpDao userDmpDao;
|
private UserDmpDao userDmpDao;
|
||||||
|
private ContentDao contentDao;
|
||||||
|
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@ -195,4 +196,14 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
||||||
public void setUserDmpDao(UserDmpDao userDmpDao) {
|
public void setUserDmpDao(UserDmpDao userDmpDao) {
|
||||||
this.userDmpDao = userDmpDao;
|
this.userDmpDao = userDmpDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentDao getContentDao() {
|
||||||
|
return this.contentDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setContentDao(ContentDao contentDao) {
|
||||||
|
this.contentDao = contentDao;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.services.operations;
|
||||||
|
|
||||||
import eu.eudat.builders.BuilderFactory;
|
import eu.eudat.builders.BuilderFactory;
|
||||||
import eu.eudat.proxy.fetching.RemoteFetcher;
|
import eu.eudat.proxy.fetching.RemoteFetcher;
|
||||||
|
import eu.eudat.services.helpers.FileStorageService;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,4 +18,6 @@ public interface OperationsContext {
|
||||||
|
|
||||||
RemoteFetcher getRemoteFetcher();
|
RemoteFetcher getRemoteFetcher();
|
||||||
|
|
||||||
|
FileStorageService getFileStorageService();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.services.operations;
|
||||||
|
|
||||||
import eu.eudat.builders.BuilderFactory;
|
import eu.eudat.builders.BuilderFactory;
|
||||||
import eu.eudat.proxy.fetching.RemoteFetcher;
|
import eu.eudat.proxy.fetching.RemoteFetcher;
|
||||||
|
import eu.eudat.services.helpers.FileStorageService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -16,13 +17,16 @@ public class OperationsContextImpl implements OperationsContext {
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
private RemoteFetcher remoteFetcher;
|
private RemoteFetcher remoteFetcher;
|
||||||
private BuilderFactory builderFactory;
|
private BuilderFactory builderFactory;
|
||||||
|
private FileStorageService fileStorageService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcher remoteFetcher, BuilderFactory builderFactory) {
|
public OperationsContextImpl(DatabaseRepository databaseRepository, ApplicationContext applicationContext, RemoteFetcher remoteFetcher
|
||||||
|
, BuilderFactory builderFactory, FileStorageService fileStorageService) {
|
||||||
this.databaseRepository = databaseRepository;
|
this.databaseRepository = databaseRepository;
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.remoteFetcher = remoteFetcher;
|
this.remoteFetcher = remoteFetcher;
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
|
this.fileStorageService = fileStorageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -45,4 +49,8 @@ public class OperationsContextImpl implements OperationsContext {
|
||||||
return builderFactory;
|
return builderFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileStorageService getFileStorageService() {
|
||||||
|
return fileStorageService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,3 +58,5 @@ b2access.externallogin.clientid=eudatdmptool
|
||||||
b2access.externallogin.clientSecret=A3b*1*92
|
b2access.externallogin.clientSecret=A3b*1*92
|
||||||
#################################################################################
|
#################################################################################
|
||||||
pdf.converter.url=http://localhost/
|
pdf.converter.url=http://localhost/
|
||||||
|
files.storage.temp = temp
|
||||||
|
files.storage.final = final
|
Binary file not shown.
After Width: | Height: | Size: 939 B |
Loading…
Reference in New Issue