Add support for Dataset Overview
This commit is contained in:
parent
f2fb409900
commit
372c9bb074
|
@ -4,9 +4,12 @@ import eu.eudat.data.entities.Dataset;
|
|||
import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest;
|
||||
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
|
||||
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
|
||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||
import eu.eudat.logic.managers.DatasetManager;
|
||||
import eu.eudat.logic.managers.DatasetWizardManager;
|
||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.dataset.DatasetOverviewModel;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
|
@ -52,6 +55,32 @@ public class Datasets extends BaseController {
|
|||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity getOverviewSingle(@PathVariable String id,@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
|
||||
try {
|
||||
DatasetOverviewModel dataset = this.datasetManager.getOverviewSingle(id, principal, false);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
|
||||
} catch (Exception e) {
|
||||
if (e instanceof UnauthorisedException) {
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ResponseItem<DatasetOverviewModel>().status(ApiMessageCode.ERROR_MESSAGE));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ResponseItem<DatasetOverviewModel>().status(ApiMessageCode.ERROR_MESSAGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/publicOverview/{id}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity getOverviewSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
|
||||
// try {
|
||||
DatasetOverviewModel dataset = this.datasetManager.getOverviewSingle(id, principal, true);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
|
||||
// } catch (Exception ex) {
|
||||
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
|
||||
// }
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/makepublic/{id}"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
|
@ -82,5 +111,13 @@ public class Datasets extends BaseController {
|
|||
this.datasetManager.clearIndex(principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null));
|
||||
}
|
||||
|
||||
@javax.transaction.Transactional
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> delete(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
||||
new DatasetWizardManager().delete(this.getApiContext(), id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequest
|
|||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
import eu.eudat.elastic.repository.DatasetRepository;
|
||||
import eu.eudat.exceptions.security.ForbiddenException;
|
||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||
import eu.eudat.logic.builders.BuilderFactory;
|
||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||
|
@ -32,6 +33,7 @@ import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
|
|||
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
||||
import eu.eudat.logic.utilities.json.JsonSearcher;
|
||||
import eu.eudat.models.HintedModelFactory;
|
||||
import eu.eudat.models.data.dataset.DatasetOverviewModel;
|
||||
import eu.eudat.models.data.datasetImport.DatasetImportField;
|
||||
import eu.eudat.models.data.datasetImport.DatasetImportPagedDatasetProfile;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||
|
@ -39,6 +41,7 @@ import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|||
import eu.eudat.models.data.dmp.AssociatedProfile;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
|
||||
import eu.eudat.models.data.listingmodels.DatasetListingModel;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||
|
@ -325,6 +328,26 @@ public class DatasetManager {
|
|||
}
|
||||
}
|
||||
|
||||
public DatasetOverviewModel getOverviewSingle(String id, Principal principal, boolean isPublic) throws Exception {
|
||||
Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id));
|
||||
if (datasetEntity.getStatus() == Dataset.Status.DELETED.getValue()) {
|
||||
throw new Exception("Dataset is deleted.");
|
||||
}
|
||||
if (!isPublic && principal == null) {
|
||||
throw new UnauthorisedException();
|
||||
} else
|
||||
if (!isPublic && datasetEntity.getDmp().getUsers()
|
||||
.stream().noneMatch(userInfo -> userInfo.getUser().getId() == principal.getId())) {
|
||||
throw new UnauthorisedException();
|
||||
} else if (isPublic && !datasetEntity.getDmp().isPublic()) {
|
||||
throw new ForbiddenException("Selected Dataset is not public");
|
||||
}
|
||||
DatasetOverviewModel dataset = new DatasetOverviewModel();
|
||||
dataset.fromDataModel(datasetEntity);
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) {
|
||||
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile());
|
||||
datasetprofile.setStatus(dataset.getStatus());
|
||||
|
|
|
@ -3,9 +3,7 @@ package eu.eudat.logic.mapper.elastic;
|
|||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
||||
import eu.eudat.elastic.entities.Collaborator;
|
||||
import eu.eudat.elastic.entities.Dataset;
|
||||
import eu.eudat.elastic.entities.Organization;
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
import eu.eudat.logic.managers.DatasetManager;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
|
|
|
@ -3,8 +3,12 @@ package eu.eudat.models.data.dataset;
|
|||
import eu.eudat.data.entities.Dataset;
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
||||
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DatasetOverviewModel implements DataModel<Dataset, DatasetOverviewModel> {
|
||||
|
||||
|
@ -12,6 +16,12 @@ public class DatasetOverviewModel implements DataModel<Dataset, DatasetOverviewM
|
|||
private String label;
|
||||
private short status;
|
||||
private DatasetProfileOverviewModel datasetTemplate;
|
||||
private List<UserInfoListingModel> users;
|
||||
private String dmp;
|
||||
private String grant;
|
||||
private String description;
|
||||
private Boolean isPublic;
|
||||
private Date modified;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
@ -41,12 +51,66 @@ public class DatasetOverviewModel implements DataModel<Dataset, DatasetOverviewM
|
|||
this.datasetTemplate = datasetTemplate;
|
||||
}
|
||||
|
||||
public List<UserInfoListingModel> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(List<UserInfoListingModel> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public String getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
||||
public void setDmp(String dmp) {
|
||||
this.dmp = dmp;
|
||||
}
|
||||
|
||||
public String getGrant() {
|
||||
return grant;
|
||||
}
|
||||
|
||||
public void setGrant(String grant) {
|
||||
this.grant = grant;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Boolean getPublic() {
|
||||
return isPublic;
|
||||
}
|
||||
|
||||
public void setPublic(Boolean aPublic) {
|
||||
isPublic = aPublic;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void setModified(Date modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatasetOverviewModel fromDataModel(Dataset entity) {
|
||||
this.id = entity.getId();
|
||||
this.label = entity.getLabel();
|
||||
this.status = entity.getStatus();
|
||||
this.datasetTemplate = new DatasetProfileOverviewModel().fromDataModel(entity.getProfile());
|
||||
this.users = entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
|
||||
this.dmp = entity.getDmp().getLabel();
|
||||
this.grant = entity.getDmp().getGrant().getLabel();
|
||||
this.description = entity.getDescription();
|
||||
this.isPublic = entity.getDmp().isPublic();
|
||||
this.modified = entity.getModified();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue