Fetching and building users for dmps for public API
This commit is contained in:
parent
0166bf8ece
commit
92956f6598
|
@ -93,7 +93,7 @@ public class Dmp {
|
||||||
|
|
||||||
private List<DmpUser> dmpUsers;
|
private List<DmpUser> dmpUsers;
|
||||||
|
|
||||||
public static final String _dmpUsers = "dmoUsers";
|
public static final String _dmpUsers = "dmpUsers";
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.model.mapper.publicapi;
|
||||||
|
|
||||||
import eu.eudat.model.Dmp;
|
import eu.eudat.model.Dmp;
|
||||||
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
|
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
|
||||||
|
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
@ -16,7 +17,7 @@ public class DmpToPublicApiDmpListingMapper {
|
||||||
model.setVersion(dmp.getVersion());
|
model.setVersion(dmp.getVersion());
|
||||||
model.setGroupId(dmp.getGroupId());
|
model.setGroupId(dmp.getGroupId());
|
||||||
|
|
||||||
// model.set
|
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
|
||||||
|
|
||||||
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
||||||
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.model.mapper.publicapi;
|
||||||
|
|
||||||
import eu.eudat.model.Dmp;
|
import eu.eudat.model.Dmp;
|
||||||
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
|
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
|
||||||
|
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
@ -17,7 +18,7 @@ public class DmpToPublicApiDmpMapper {
|
||||||
model.setVersion(dmp.getVersion());
|
model.setVersion(dmp.getVersion());
|
||||||
model.setGroupId(dmp.getGroupId());
|
model.setGroupId(dmp.getGroupId());
|
||||||
|
|
||||||
|
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
|
||||||
|
|
||||||
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
||||||
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package eu.eudat.model.publicapi.listingmodels;
|
package eu.eudat.model.publicapi.listingmodels;
|
||||||
|
|
||||||
import eu.eudat.data.DmpEntity;
|
import eu.eudat.data.DmpEntity;
|
||||||
import eu.eudat.model.DmpUser;
|
|
||||||
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
|
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
|
||||||
|
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ public class DataManagementPlanPublicListingModel {
|
||||||
private Date modifiedAt;
|
private Date modifiedAt;
|
||||||
private int version;
|
private int version;
|
||||||
private UUID groupId;
|
private UUID groupId;
|
||||||
private List<DmpUser> users;
|
private List<UserInfoPublicModel> users;
|
||||||
private List<ResearcherPublicModel> researchers;
|
private List<ResearcherPublicModel> researchers;
|
||||||
private Date finalizedAt;
|
private Date finalizedAt;
|
||||||
private Date publishedAt;
|
private Date publishedAt;
|
||||||
|
@ -68,10 +68,10 @@ public class DataManagementPlanPublicListingModel {
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DmpUser> getUsers() {
|
public List<UserInfoPublicModel> getUsers() {
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
public void setUsers(List<DmpUser> users) {
|
public void setUsers(List<UserInfoPublicModel> users) {
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package eu.eudat.model.publicapi.listingmodels;
|
package eu.eudat.model.publicapi.listingmodels;
|
||||||
|
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.model.DmpUser;
|
|
||||||
import eu.eudat.model.publicapi.datasetprofile.DatasetProfilePublicModel;
|
import eu.eudat.model.publicapi.datasetprofile.DatasetProfilePublicModel;
|
||||||
|
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -20,7 +20,7 @@ public class DatasetPublicListingModel {
|
||||||
private Date finalizedAt;
|
private Date finalizedAt;
|
||||||
private Date dmpPublishedAt;
|
private Date dmpPublishedAt;
|
||||||
private int version;
|
private int version;
|
||||||
private List<DmpUser> users;
|
private List<UserInfoPublicModel> users;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -106,11 +106,11 @@ public class DatasetPublicListingModel {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DmpUser> getUsers() {
|
public List<UserInfoPublicModel> getUsers() {
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsers(List<DmpUser> users) {
|
public void setUsers(List<UserInfoPublicModel> users) {
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package eu.eudat.model.publicapi.overviewmodels;
|
package eu.eudat.model.publicapi.overviewmodels;
|
||||||
|
|
||||||
import eu.eudat.data.DmpEntity;
|
import eu.eudat.data.DmpEntity;
|
||||||
import eu.eudat.model.DmpUser;
|
|
||||||
import eu.eudat.model.publicapi.associatedprofile.AssociatedProfilePublicModel;
|
import eu.eudat.model.publicapi.associatedprofile.AssociatedProfilePublicModel;
|
||||||
import eu.eudat.model.publicapi.doi.DoiPublicModel;
|
import eu.eudat.model.publicapi.doi.DoiPublicModel;
|
||||||
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
|
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
|
||||||
import eu.eudat.model.publicapi.organisation.OrganizationPublicModel;
|
import eu.eudat.model.publicapi.organisation.OrganizationPublicModel;
|
||||||
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
|
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
|
||||||
|
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -26,7 +26,7 @@ public class DataManagementPlanPublicModel {
|
||||||
private List<DatasetPublicModel> datasets;
|
private List<DatasetPublicModel> datasets;
|
||||||
private List<AssociatedProfilePublicModel> associatedProfiles;
|
private List<AssociatedProfilePublicModel> associatedProfiles;
|
||||||
private List<ResearcherPublicModel> researchers;
|
private List<ResearcherPublicModel> researchers;
|
||||||
private List<DmpUser> users;
|
private List<UserInfoPublicModel> users;
|
||||||
private String description;
|
private String description;
|
||||||
private Date publishedAt;
|
private Date publishedAt;
|
||||||
private List<DoiPublicModel> dois;
|
private List<DoiPublicModel> dois;
|
||||||
|
@ -116,10 +116,10 @@ public class DataManagementPlanPublicModel {
|
||||||
this.associatedProfiles = associatedProfiles;
|
this.associatedProfiles = associatedProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DmpUser> getUsers() {
|
public List<UserInfoPublicModel> getUsers() {
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
public void setUsers(List<DmpUser> users) {
|
public void setUsers(List<UserInfoPublicModel> users) {
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package eu.eudat.model.publicapi.user;
|
||||||
|
|
||||||
|
import eu.eudat.model.DmpUser;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UserInfoPublicModel {
|
||||||
|
private UUID id;
|
||||||
|
private String name;
|
||||||
|
private int role;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
public void setRole(int role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserInfoPublicModel fromDmpUser(DmpUser dmpUser) {
|
||||||
|
UserInfoPublicModel model = new UserInfoPublicModel();
|
||||||
|
model.setId(dmpUser.getUser().getId());
|
||||||
|
model.setName(dmpUser.getUser().getName());
|
||||||
|
model.setRole(dmpUser.getRole().getValue());
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHint() {
|
||||||
|
return "UserInfoListingModel";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,15 @@
|
||||||
package eu.eudat.controllers.publicapi;
|
package eu.eudat.controllers.publicapi;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpAccessType;
|
import eu.eudat.commons.enums.DmpAccessType;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.controllers.BaseController;
|
import eu.eudat.controllers.BaseController;
|
||||||
import eu.eudat.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRequest;
|
import eu.eudat.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRequest;
|
||||||
import eu.eudat.controllers.publicapi.response.DataTableData;
|
import eu.eudat.controllers.publicapi.response.DataTableData;
|
||||||
import eu.eudat.data.DmpEntity;
|
import eu.eudat.data.DmpEntity;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.model.Dmp;
|
import eu.eudat.model.Dmp;
|
||||||
|
import eu.eudat.model.DmpUser;
|
||||||
|
import eu.eudat.model.User;
|
||||||
import eu.eudat.model.builder.DmpBuilder;
|
import eu.eudat.model.builder.DmpBuilder;
|
||||||
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
|
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
|
||||||
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper;
|
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper;
|
||||||
|
@ -88,12 +91,14 @@ public class PublicDmpsDocumentation extends BaseController {
|
||||||
@RequestParam @Parameter(description = PublicApiStaticHelpers.Dmp.getPagedRequestParamDescription, example = "listing") String fieldsGroup
|
@RequestParam @Parameter(description = PublicApiStaticHelpers.Dmp.getPagedRequestParamDescription, example = "listing") String fieldsGroup
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
DmpLookup lookup = getDmpLookup(fieldsGroup, dmpTableRequest);
|
DmpLookup lookup = getDmpLookup(fieldsGroup, dmpTableRequest);
|
||||||
DmpQuery query = lookup.enrich(this.queryFactory).accessTypes(DmpAccessType.Public);
|
DmpQuery query = lookup.enrich(this.queryFactory).accessTypes(DmpAccessType.Public).isActive(IsActive.Active);
|
||||||
|
long count = this.queryFactory.query(DmpQuery.class).accessTypes(DmpAccessType.Public).isActive(IsActive.Active).count();
|
||||||
|
|
||||||
List<DmpEntity> data = query.collectAs(lookup.getProject());
|
List<DmpEntity> data = query.collectAs(lookup.getProject());
|
||||||
List<Dmp> models = this.builderFactory.builder(DmpBuilder.class).build(lookup.getProject(), data);
|
List<Dmp> models = this.builderFactory.builder(DmpBuilder.class).build(lookup.getProject(), data);
|
||||||
DataTableData<DataManagementPlanPublicListingModel> dataTableData = new DataTableData<>();
|
DataTableData<DataManagementPlanPublicListingModel> dataTableData = new DataTableData<>();
|
||||||
dataTableData.setData(models.stream().map(this.dmpToPublicApiDmpListingMapper::toPublicListingModel).toList());
|
dataTableData.setData(models.stream().map(this.dmpToPublicApiDmpListingMapper::toPublicListingModel).toList());
|
||||||
|
dataTableData.setTotalCount(count);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +113,10 @@ public class PublicDmpsDocumentation extends BaseController {
|
||||||
Dmp._description,
|
Dmp._description,
|
||||||
Dmp._version,
|
Dmp._version,
|
||||||
Dmp._groupId,
|
Dmp._groupId,
|
||||||
|
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._id)),
|
||||||
|
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)),
|
||||||
|
String.join(".", Dmp._dmpUsers, DmpUser._role),
|
||||||
|
Dmp._dmpReferences,
|
||||||
Dmp._createdAt,
|
Dmp._createdAt,
|
||||||
Dmp._updatedAt,
|
Dmp._updatedAt,
|
||||||
Dmp._finalizedAt
|
Dmp._finalizedAt
|
||||||
|
@ -145,12 +154,15 @@ public class PublicDmpsDocumentation extends BaseController {
|
||||||
Dmp._description,
|
Dmp._description,
|
||||||
Dmp._version,
|
Dmp._version,
|
||||||
Dmp._groupId,
|
Dmp._groupId,
|
||||||
|
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._id)),
|
||||||
|
String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)),
|
||||||
|
String.join(".", Dmp._dmpUsers, DmpUser._role),
|
||||||
Dmp._createdAt,
|
Dmp._createdAt,
|
||||||
Dmp._updatedAt,
|
Dmp._updatedAt,
|
||||||
Dmp._finalizedAt
|
Dmp._finalizedAt
|
||||||
);
|
);
|
||||||
fieldSet.setFields(fields);
|
fieldSet.setFields(fields);
|
||||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).ids(UUID.fromString(id)).accessTypes(DmpAccessType.Public);
|
DmpQuery query = this.queryFactory.query(DmpQuery.class).ids(UUID.fromString(id)).accessTypes(DmpAccessType.Public).isActive(IsActive.Active);
|
||||||
Dmp model = this.builderFactory.builder(DmpBuilder.class).build(fieldSet, query.firstAs(fieldSet));
|
Dmp model = this.builderFactory.builder(DmpBuilder.class).build(fieldSet, query.firstAs(fieldSet));
|
||||||
if (model == null)
|
if (model == null)
|
||||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
Loading…
Reference in New Issue