Merge commit 'c8358f22dd5d108b7f270f97724d6bab1582c2c5'
This commit is contained in:
commit
63ee865dd9
|
@ -11,6 +11,7 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
|
||||||
private List<UUID> grants;
|
private List<UUID> grants;
|
||||||
public List<UUID> datasetProfile;
|
public List<UUID> datasetProfile;
|
||||||
private List<String> dmpOrganisations;
|
private List<String> dmpOrganisations;
|
||||||
|
private Integer role;
|
||||||
|
|
||||||
public GrantStateType getGrantStatus() {
|
public GrantStateType getGrantStatus() {
|
||||||
return grantStatus;
|
return grantStatus;
|
||||||
|
@ -39,4 +40,11 @@ public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
|
||||||
public void setDmpOrganisations(List<String> dmpOrganisations) {
|
public void setDmpOrganisations(List<String> dmpOrganisations) {
|
||||||
this.dmpOrganisations = dmpOrganisations;
|
this.dmpOrganisations = dmpOrganisations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
public void setRole(Integer role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,16 @@ package eu.eudat.data.dao.criteria;
|
||||||
|
|
||||||
import eu.eudat.data.entities.DataRepository;
|
import eu.eudat.data.entities.DataRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DataRepositoryCriteria extends Criteria<DataRepository> {
|
public class DataRepositoryCriteria extends Criteria<DataRepository> {
|
||||||
|
|
||||||
|
private UUID creationUserId;
|
||||||
|
|
||||||
|
public UUID getCreationUserId() {
|
||||||
|
return creationUserId;
|
||||||
|
}
|
||||||
|
public void setCreationUserId(UUID creationUserId) {
|
||||||
|
this.creationUserId = creationUserId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ public class DatasetPublicCriteria extends Criteria<Dataset>{
|
||||||
private List<String> dmpOrganisations;
|
private List<String> dmpOrganisations;
|
||||||
private List<Tag> tags;
|
private List<Tag> tags;
|
||||||
private List<UUID> dmpIds;
|
private List<UUID> dmpIds;
|
||||||
|
private Integer role;
|
||||||
|
|
||||||
public GrantStateType getGrantStatus() {
|
public GrantStateType getGrantStatus() {
|
||||||
return grantStatus;
|
return grantStatus;
|
||||||
|
@ -59,4 +60,11 @@ public class DatasetPublicCriteria extends Criteria<Dataset>{
|
||||||
public void setDmpIds(List<UUID> dmpIds) {
|
public void setDmpIds(List<UUID> dmpIds) {
|
||||||
this.dmpIds = dmpIds;
|
this.dmpIds = dmpIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
public void setRole(Integer role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
package eu.eudat.data.dao.criteria;
|
package eu.eudat.data.dao.criteria;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.data.entities.ExternalDataset;
|
import eu.eudat.data.entities.ExternalDataset;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ExternalDatasetCriteria extends Criteria<ExternalDataset> {
|
public class ExternalDatasetCriteria extends Criteria<ExternalDataset> {
|
||||||
|
private UUID creationUserId;
|
||||||
|
|
||||||
|
public UUID getCreationUserId() {
|
||||||
|
return creationUserId;
|
||||||
|
}
|
||||||
|
public void setCreationUserId(UUID creationUserId) {
|
||||||
|
this.creationUserId = creationUserId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,16 @@ package eu.eudat.data.dao.criteria;
|
||||||
|
|
||||||
import eu.eudat.data.entities.Registry;
|
import eu.eudat.data.entities.Registry;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class RegistryCriteria extends Criteria<Registry> {
|
public class RegistryCriteria extends Criteria<Registry> {
|
||||||
|
|
||||||
|
private UUID creationUserId;
|
||||||
|
|
||||||
|
public UUID getCreationUserId() {
|
||||||
|
return creationUserId;
|
||||||
|
}
|
||||||
|
public void setCreationUserId(UUID creationUserId) {
|
||||||
|
this.creationUserId = creationUserId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,16 @@ package eu.eudat.data.dao.criteria;
|
||||||
|
|
||||||
import eu.eudat.data.entities.Service;
|
import eu.eudat.data.entities.Service;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ServiceCriteria extends Criteria<Service> {
|
public class ServiceCriteria extends Criteria<Service> {
|
||||||
|
|
||||||
|
private UUID creationUserId;
|
||||||
|
|
||||||
|
public UUID getCreationUserId() {
|
||||||
|
return creationUserId;
|
||||||
|
}
|
||||||
|
public void setCreationUserId(UUID creationUserId) {
|
||||||
|
this.creationUserId = creationUserId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import eu.eudat.data.entities.UserDMP;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
||||||
|
@ -16,6 +17,6 @@ public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
||||||
|
|
||||||
QueryableList<DMP> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo);
|
QueryableList<DMP> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo);
|
||||||
|
|
||||||
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principalId);
|
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principalId, List<Integer> roles);
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@ import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
||||||
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
|
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
|
||||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||||
import eu.eudat.data.entities.DMP;
|
import eu.eudat.data.entities.DMP;
|
||||||
import eu.eudat.data.entities.UserDMP;
|
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.queryable.types.FieldSelectionType;
|
import eu.eudat.queryable.types.FieldSelectionType;
|
||||||
|
@ -14,15 +13,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
import javax.persistence.criteria.JoinType;
|
import javax.persistence.criteria.JoinType;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("dMPDao")
|
@Component("dMPDao")
|
||||||
public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DMPDaoImpl(DatabaseService<DMP> databaseService) {
|
public DMPDaoImpl(DatabaseService<DMP> databaseService) {
|
||||||
super(databaseService);
|
super(databaseService);
|
||||||
|
@ -56,13 +56,13 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||||
}
|
}
|
||||||
if (criteria.getIsPublic())
|
if (criteria.getIsPublic())
|
||||||
query.where(((builder, root) -> builder.equal(root.get("isPublic"), true)));
|
query.where(((builder, root) -> builder.equal(root.get("isPublic"), true)));
|
||||||
if (criteria.getRole() != null) {
|
/*if (criteria.getRole() != null) {
|
||||||
if (criteria.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())) {
|
if (criteria.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())) {
|
||||||
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.OWNER.getValue()));
|
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.OWNER.getValue()));
|
||||||
} else if (criteria.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())) {
|
} else if (criteria.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())) {
|
||||||
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.USER.getValue()));
|
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.USER.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty()) {
|
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty()) {
|
||||||
query.where((builder, root) -> root.join("organisations").get("reference").in(criteria.getOrganisations()));
|
query.where((builder, root) -> root.join("organisations").get("reference").in(criteria.getOrganisations()));
|
||||||
}
|
}
|
||||||
|
@ -70,14 +70,22 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||||
query.where((builder, root) -> root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
|
query.where((builder, root) -> root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
|
||||||
}
|
}
|
||||||
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty()) {
|
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty()) {
|
||||||
query.where(((builder, root) -> root.join("associatedDmps", JoinType.LEFT).get("id").in(criteria.getDatasetTemplates())));
|
query.where((builder, root) -> root.join("associatedDmps", JoinType.LEFT).get("id").in(criteria.getDatasetTemplates()));
|
||||||
}
|
}
|
||||||
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()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principal) {
|
public QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principal, List<Integer> roles) {
|
||||||
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user").get("id"), principal));
|
if (roles != null && !roles.isEmpty()) {
|
||||||
|
query.where((builder, root) -> {
|
||||||
|
Join userJoin = root.join("users", JoinType.LEFT);
|
||||||
|
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal), userJoin.get("role").in(roles));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal));
|
||||||
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,11 @@ public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implem
|
||||||
public QueryableList<DataRepository> getWithCriteria(DataRepositoryCriteria criteria) {
|
public QueryableList<DataRepository> getWithCriteria(DataRepositoryCriteria criteria) {
|
||||||
QueryableList<DataRepository> query = this.getDatabaseService().getQueryable(DataRepository.class);
|
QueryableList<DataRepository> query = this.getDatabaseService().getQueryable(DataRepository.class);
|
||||||
if (criteria.getLike() != null)
|
if (criteria.getLike() != null)
|
||||||
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
|
query.where((builder, root) -> builder.or(
|
||||||
|
builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"),
|
||||||
|
builder.equal(builder.upper(root.get("label")), criteria.getLike().toUpperCase())));
|
||||||
|
if (criteria.getCreationUserId() != null)
|
||||||
|
query.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), criteria.getCreationUserId()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package eu.eudat.data.dao.entities;
|
||||||
import eu.eudat.data.dao.DatabaseAccess;
|
import eu.eudat.data.dao.DatabaseAccess;
|
||||||
import eu.eudat.data.dao.criteria.DatasetCriteria;
|
import eu.eudat.data.dao.criteria.DatasetCriteria;
|
||||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||||
import eu.eudat.data.entities.DMP;
|
|
||||||
import eu.eudat.data.entities.Dataset;
|
import eu.eudat.data.entities.Dataset;
|
||||||
|
import eu.eudat.data.entities.UserDMP;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.queryable.types.FieldSelectionType;
|
import eu.eudat.queryable.types.FieldSelectionType;
|
||||||
|
@ -43,8 +43,11 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
||||||
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)));
|
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()));
|
||||||
if (criteria.getRole() != null)
|
if (criteria.getRole() != null) {
|
||||||
query.where((builder, root) -> builder.equal(root.join("dmp").join("users").get("role"), criteria.getRole()));
|
query.where((builder, root) -> builder.equal(root.join("dmp").join("users").get("role"), criteria.getRole()));
|
||||||
|
} else {
|
||||||
|
query.where((builder, root) -> root.join("dmp").join("users").get("role").in(UserDMP.UserDMPRoles.getAllValues()));
|
||||||
|
}
|
||||||
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty())
|
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty())
|
||||||
query.where((builder, root) -> root.join("dmp").join("organisations").get("reference").in(criteria.getOrganisations()));
|
query.where((builder, root) -> root.join("dmp").join("organisations").get("reference").in(criteria.getOrganisations()));
|
||||||
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
|
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
|
||||||
|
@ -52,9 +55,9 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
||||||
if (criteria.getCollaborators() != null && !criteria.getCollaborators().isEmpty())
|
if (criteria.getCollaborators() != null && !criteria.getCollaborators().isEmpty())
|
||||||
query.where((builder, root) -> root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
|
query.where((builder, root) -> root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
|
||||||
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty())
|
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty())
|
||||||
query.where(((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates())));
|
query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates()));
|
||||||
query.where(((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())));
|
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
|
||||||
query.where(((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue())));
|
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +90,7 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
||||||
public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal) {
|
public QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal) {
|
||||||
if (principal.getId() == null) query.where((builder, root) -> builder.equal(root.get("isPublic"), true));
|
if (principal.getId() == null) query.where((builder, root) -> builder.equal(root.get("isPublic"), true));
|
||||||
else {
|
else {
|
||||||
query.where((builder, root) -> builder.or(builder.equal(root.get("dmp").get("creator"), principal), builder.equal(root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId())));
|
query.where((builder, root) -> builder.equal(root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()));
|
||||||
}
|
}
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,11 @@ public class ExternalDatasetDaoImpl extends DatabaseAccess<ExternalDataset> impl
|
||||||
public QueryableList<ExternalDataset> getWithCriteria(ExternalDatasetCriteria criteria) {
|
public QueryableList<ExternalDataset> getWithCriteria(ExternalDatasetCriteria criteria) {
|
||||||
QueryableList<ExternalDataset> query = this.getDatabaseService().getQueryable(ExternalDataset.class);
|
QueryableList<ExternalDataset> query = this.getDatabaseService().getQueryable(ExternalDataset.class);
|
||||||
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
|
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
|
||||||
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"));
|
query.where((builder, root) -> builder.or(
|
||||||
|
builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"),
|
||||||
|
builder.equal(builder.upper(root.get("label")), criteria.getLike().toUpperCase())));
|
||||||
|
if (criteria.getCreationUserId() != null)
|
||||||
|
query.where((builder, root) -> builder.equal(root.join("creationUser").get("id"), criteria.getCreationUserId()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,15 @@ public class FunderDaoImpl extends DatabaseAccess<Funder> implements FunderDao {
|
||||||
builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
|
builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
|
||||||
builder.or(builder.like(builder.upper(root.get("definition")), "%" + criteria.getLike().toUpperCase() + "%"))));
|
builder.or(builder.like(builder.upper(root.get("definition")), "%" + criteria.getLike().toUpperCase() + "%"))));
|
||||||
if (criteria.getReference() != null)
|
if (criteria.getReference() != null)
|
||||||
query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%"));
|
query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), "%" + criteria.getReference().toUpperCase() + "%"));
|
||||||
query.where((builder, root) -> builder.notEqual(root.get("status"), Funder.Status.DELETED.getValue()));
|
query.where((builder, root) -> builder.notEqual(root.get("status"), Funder.Status.DELETED.getValue()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryableList<Funder> getAuthenticated(QueryableList<Funder> query, UserInfo principal) {
|
public QueryableList<Funder> getAuthenticated(QueryableList<Funder> query, UserInfo principal) {
|
||||||
return null;
|
query.where((builder, root) -> builder.equal(root.get("creationUser"), principal));
|
||||||
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,6 +11,7 @@ import eu.eudat.types.grant.GrantStateType;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import schemasMicrosoftComOfficeOffice.LeftDocument;
|
||||||
|
|
||||||
import javax.persistence.criteria.JoinType;
|
import javax.persistence.criteria.JoinType;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -51,6 +52,8 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
|
||||||
}
|
}
|
||||||
if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty())
|
if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty())
|
||||||
query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId())));
|
query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId())));
|
||||||
|
if (criteria.getFunderReference() != null && !criteria.getFunderReference().isEmpty())
|
||||||
|
query.where((builder, root) -> builder.equal(root.join("funder", JoinType.LEFT).get("reference"), criteria.getFunderReference()));
|
||||||
query.where((builder, root) -> builder.notEqual(root.get("status"), Grant.Status.DELETED.getValue()));
|
query.where((builder, root) -> builder.notEqual(root.get("status"), Grant.Status.DELETED.getValue()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,12 @@ public class RegistryDaoImpl extends DatabaseAccess<Registry> implements Registr
|
||||||
public QueryableList<Registry> getWithCriteria(RegistryCriteria criteria) {
|
public QueryableList<Registry> getWithCriteria(RegistryCriteria criteria) {
|
||||||
QueryableList<Registry> query = this.getDatabaseService().getQueryable(Registry.class);
|
QueryableList<Registry> query = this.getDatabaseService().getQueryable(Registry.class);
|
||||||
if (criteria.getLike() != null)
|
if (criteria.getLike() != null)
|
||||||
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
|
if (criteria.getLike() != null)
|
||||||
|
query.where((builder, root) -> builder.or(
|
||||||
|
builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"),
|
||||||
|
builder.equal(builder.upper(root.get("label")), criteria.getLike().toUpperCase())));
|
||||||
|
if (criteria.getCreationUserId() != null)
|
||||||
|
query.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), criteria.getCreationUserId()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,11 @@ public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDa
|
||||||
public QueryableList<Service> getWithCriteria(ServiceCriteria criteria) {
|
public QueryableList<Service> getWithCriteria(ServiceCriteria criteria) {
|
||||||
QueryableList<Service> query = this.getDatabaseService().getQueryable(Service.class);
|
QueryableList<Service> query = this.getDatabaseService().getQueryable(Service.class);
|
||||||
if (criteria.getLike() != null)
|
if (criteria.getLike() != null)
|
||||||
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
|
query.where((builder, root) -> builder.or(
|
||||||
|
builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"),
|
||||||
|
builder.equal(builder.upper(root.get("label")), criteria.getLike().toUpperCase())));
|
||||||
|
if (criteria.getCreationUserId() != null)
|
||||||
|
query.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), criteria.getCreationUserId()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package eu.eudat.data.entities;
|
||||||
|
|
||||||
import eu.eudat.data.entities.helpers.EntityBinder;
|
import eu.eudat.data.entities.helpers.EntityBinder;
|
||||||
import eu.eudat.queryable.queryableentity.DataEntity;
|
import eu.eudat.queryable.queryableentity.DataEntity;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
|
||||||
import org.hibernate.annotations.Type;
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -18,8 +17,6 @@ import java.util.UUID;
|
||||||
public class DataRepository implements Serializable, DataEntity<DataRepository, UUID> {
|
public class DataRepository implements Serializable, DataEntity<DataRepository, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
|
||||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
|
||||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
|
@ -39,11 +36,9 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
|
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
|
||||||
private String definition;
|
private String definition;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "dataRepository", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy = "dataRepository", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private Set<DatasetDataRepository> datasetDataRepositories;
|
private Set<DatasetDataRepository> datasetDataRepositories;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "\"Status\"", nullable = false)
|
@Column(name = "\"Status\"", nullable = false)
|
||||||
private Short status;
|
private Short status;
|
||||||
|
|
||||||
|
@ -53,41 +48,35 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
@Column(name = "\"Modified\"")
|
@Column(name = "\"Modified\"")
|
||||||
private Date modified = new Date();
|
private Date modified = new Date();
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"CreationUser\"", nullable = true)
|
||||||
|
private UserInfo creationUser;
|
||||||
|
|
||||||
|
|
||||||
public Short getStatus() {
|
public Short getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setStatus(Short status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
public void setCreated(Date created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getModified() {
|
public Date getModified() {
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
public void setModified(Date modified) {
|
||||||
this.modified = modified;
|
this.modified = modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public void setId(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +84,6 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +91,6 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
public String getAbbreviation() {
|
public String getAbbreviation() {
|
||||||
return abbreviation;
|
return abbreviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAbbreviation(String abbreviation) {
|
public void setAbbreviation(String abbreviation) {
|
||||||
this.abbreviation = abbreviation;
|
this.abbreviation = abbreviation;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +98,6 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
public String getReference() {
|
public String getReference() {
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReference(String reference) {
|
public void setReference(String reference) {
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +105,6 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUri(String uri) {
|
public void setUri(String uri) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +112,6 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
public String getDefinition() {
|
public String getDefinition() {
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefinition(String definition) {
|
public void setDefinition(String definition) {
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
}
|
}
|
||||||
|
@ -135,11 +119,17 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
|
||||||
public Set<DatasetDataRepository> getDatasetDataRepositories() {
|
public Set<DatasetDataRepository> getDatasetDataRepositories() {
|
||||||
return datasetDataRepositories;
|
return datasetDataRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) {
|
public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) {
|
||||||
this.datasetDataRepositories = datasetDataRepositories;
|
this.datasetDataRepositories = datasetDataRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfo getCreationUser() {
|
||||||
|
return creationUser;
|
||||||
|
}
|
||||||
|
public void setCreationUser(UserInfo creationUser) {
|
||||||
|
this.creationUser = creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(DataRepository entity) {
|
public void update(DataRepository entity) {
|
||||||
|
|
||||||
|
|
|
@ -276,32 +276,25 @@ public class Dataset implements DataEntity<Dataset, UUID> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Dataset entity) {
|
public void update(Dataset entity) {
|
||||||
this.setRegistries(entity.getRegistries());
|
|
||||||
if (this.getDatasetDataRepositories() == null) this.setDatasetDataRepositories(new HashSet<>());
|
|
||||||
if (!this.getDatasetDataRepositories().containsAll(entity.getDatasetDataRepositories())) {
|
|
||||||
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
|
|
||||||
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().map(item -> {
|
|
||||||
item.setDataset(this);
|
|
||||||
return item;
|
|
||||||
}).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
this.setUri(entity.getUri());
|
this.setUri(entity.getUri());
|
||||||
this.setDescription(entity.getDescription());
|
this.setDescription(entity.getDescription());
|
||||||
this.setLabel(entity.getLabel());
|
this.setLabel(entity.getLabel());
|
||||||
this.setProperties(entity.getProperties());
|
this.setProperties(entity.getProperties());
|
||||||
if (this.getDatasetExternalDatasets() == null) this.setDatasetExternalDatasets(new HashSet<>());
|
|
||||||
if (!this.getDatasetExternalDatasets().containsAll(entity.getDatasetExternalDatasets())) {
|
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
|
||||||
|
if (entity.getDatasetDataRepositories() != null)
|
||||||
|
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories());
|
||||||
|
|
||||||
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
|
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
|
||||||
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().map(item -> {
|
if (entity.getDatasetExternalDatasets() != null)
|
||||||
item.setDataset(this);
|
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets());
|
||||||
return item;
|
|
||||||
}).collect(Collectors.toList()));
|
this.setRegistries(entity.getRegistries());
|
||||||
}
|
|
||||||
if (this.getServices() == null) this.setServices(new HashSet<>());
|
|
||||||
if(!this.getServices().containsAll(entity.getServices())) {
|
|
||||||
this.getServices().removeAll(this.getServices());
|
this.getServices().removeAll(this.getServices());
|
||||||
|
if (entity.getServices() != null)
|
||||||
this.getServices().addAll(entity.getServices());
|
this.getServices().addAll(entity.getServices());
|
||||||
}
|
|
||||||
this.setDmp(entity.getDmp());
|
this.setDmp(entity.getDmp());
|
||||||
this.setStatus(entity.getStatus());
|
this.setStatus(entity.getStatus());
|
||||||
this.setProfile(entity.getProfile());
|
this.setProfile(entity.getProfile());
|
||||||
|
|
|
@ -40,10 +40,14 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
@OneToMany(mappedBy = "externalDataset", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy = "externalDataset", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private Set<DatasetExternalDataset> datasets;
|
private Set<DatasetExternalDataset> datasets;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"CreationUser\"", nullable = true)
|
||||||
|
private UserInfo creationUser;
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public void setId(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +55,6 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +62,6 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
public String getAbbreviation() {
|
public String getAbbreviation() {
|
||||||
return abbreviation;
|
return abbreviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAbbreviation(String abbreviation) {
|
public void setAbbreviation(String abbreviation) {
|
||||||
this.abbreviation = abbreviation;
|
this.abbreviation = abbreviation;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +69,6 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
public String getReference() {
|
public String getReference() {
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReference(String reference) {
|
public void setReference(String reference) {
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +76,6 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
public void setCreated(Date created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,6 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
public Date getModified() {
|
public Date getModified() {
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
public void setModified(Date modified) {
|
||||||
this.modified = modified;
|
this.modified = modified;
|
||||||
}
|
}
|
||||||
|
@ -91,16 +90,23 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
public Set<DatasetExternalDataset> getDatasets() {
|
public Set<DatasetExternalDataset> getDatasets() {
|
||||||
return datasets;
|
return datasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDatasets(Set<DatasetExternalDataset> datasets) {
|
public void setDatasets(Set<DatasetExternalDataset> datasets) {
|
||||||
this.datasets = datasets;
|
this.datasets = datasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfo getCreationUser() {
|
||||||
|
return creationUser;
|
||||||
|
}
|
||||||
|
public void setCreationUser(UserInfo creationUser) {
|
||||||
|
this.creationUser = creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(ExternalDataset entity) {
|
public void update(ExternalDataset entity) {
|
||||||
this.label = entity.getLabel();
|
this.label = entity.getLabel();
|
||||||
this.abbreviation = entity.getAbbreviation();
|
this.abbreviation = entity.getAbbreviation();
|
||||||
this.modified = new Date();
|
this.modified = new Date();
|
||||||
|
this.creationUser = entity.getCreationUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -94,6 +94,10 @@ public class Funder implements DataEntity<Funder, UUID> {
|
||||||
@Column(name = "\"Type\"")
|
@Column(name = "\"Type\"")
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"CreationUser\"", nullable = true)
|
||||||
|
private UserInfo creationUser;
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -151,6 +155,13 @@ public class Funder implements DataEntity<Funder, UUID> {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfo getCreationUser() {
|
||||||
|
return creationUser;
|
||||||
|
}
|
||||||
|
public void setCreationUser(UserInfo creationUser) {
|
||||||
|
this.creationUser = creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Funder entity) {
|
public void update(Funder entity) {
|
||||||
this.label = entity.getLabel();
|
this.label = entity.getLabel();
|
||||||
|
@ -160,6 +171,7 @@ public class Funder implements DataEntity<Funder, UUID> {
|
||||||
this.created = entity.getCreated();
|
this.created = entity.getCreated();
|
||||||
this.modified = new Date();
|
this.modified = new Date();
|
||||||
this.type = entity.getType();
|
this.type = entity.getType();
|
||||||
|
this.creationUser = entity.getCreationUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,7 +17,6 @@ import java.util.UUID;
|
||||||
@Table(name = "\"Registry\"")
|
@Table(name = "\"Registry\"")
|
||||||
public class Registry implements DataEntity<Registry, UUID> {
|
public class Registry implements DataEntity<Registry, UUID> {
|
||||||
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
@ -38,7 +37,6 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
|
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
|
||||||
private String definition;
|
private String definition;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.LAZY)
|
@OneToMany(fetch = FetchType.LAZY)
|
||||||
@JoinTable(name = "\"DatasetRegistry\"",
|
@JoinTable(name = "\"DatasetRegistry\"",
|
||||||
joinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")},
|
joinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")},
|
||||||
|
@ -46,11 +44,9 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
)
|
)
|
||||||
private Set<Dataset> datasets;
|
private Set<Dataset> datasets;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "\"Status\"", nullable = false)
|
@Column(name = "\"Status\"", nullable = false)
|
||||||
private Short status;
|
private Short status;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "\"Created\"")
|
@Column(name = "\"Created\"")
|
||||||
@Convert(converter = DateToUTCConverter.class)
|
@Convert(converter = DateToUTCConverter.class)
|
||||||
private Date created = null;
|
private Date created = null;
|
||||||
|
@ -59,32 +55,28 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
@Convert(converter = DateToUTCConverter.class)
|
@Convert(converter = DateToUTCConverter.class)
|
||||||
private Date modified = new Date();
|
private Date modified = new Date();
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"CreationUser\"", nullable = true)
|
||||||
|
private UserInfo creationUser;
|
||||||
|
|
||||||
|
|
||||||
public Short getStatus() {
|
public Short getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setStatus(Short status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
public void setCreated(Date created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getModified() {
|
public Date getModified() {
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
public void setModified(Date modified) {
|
||||||
this.modified = modified;
|
this.modified = modified;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +84,6 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public void setId(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +91,6 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +98,6 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
public String getAbbreviation() {
|
public String getAbbreviation() {
|
||||||
return abbreviation;
|
return abbreviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAbbreviation(String abbreviation) {
|
public void setAbbreviation(String abbreviation) {
|
||||||
this.abbreviation = abbreviation;
|
this.abbreviation = abbreviation;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +105,6 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
public String getReference() {
|
public String getReference() {
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReference(String reference) {
|
public void setReference(String reference) {
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +112,6 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUri(String uri) {
|
public void setUri(String uri) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +119,6 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
public String getDefinition() {
|
public String getDefinition() {
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefinition(String definition) {
|
public void setDefinition(String definition) {
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
}
|
}
|
||||||
|
@ -140,11 +126,16 @@ public class Registry implements DataEntity<Registry, UUID> {
|
||||||
public Set<Dataset> getDatasets() {
|
public Set<Dataset> getDatasets() {
|
||||||
return datasets;
|
return datasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDatasets(Set<Dataset> datasets) {
|
public void setDatasets(Set<Dataset> datasets) {
|
||||||
this.datasets = datasets;
|
this.datasets = datasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfo getCreationUser() {
|
||||||
|
return creationUser;
|
||||||
|
}
|
||||||
|
public void setCreationUser(UserInfo creationUser) {
|
||||||
|
this.creationUser = creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Registry entity) {
|
public void update(Registry entity) {
|
||||||
|
|
|
@ -62,41 +62,34 @@ public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
@Convert(converter = DateToUTCConverter.class)
|
@Convert(converter = DateToUTCConverter.class)
|
||||||
private Date modified = new Date();
|
private Date modified = new Date();
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"CreationUser\"", nullable = true)
|
||||||
|
private UserInfo creationUser;
|
||||||
|
|
||||||
public Short getStatus() {
|
public Short getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setStatus(Short status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
public void setCreated(Date created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getModified() {
|
public Date getModified() {
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
public void setModified(Date modified) {
|
||||||
this.modified = modified;
|
this.modified = modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public void setId(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +97,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +104,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
public String getPrimaryEmail() {
|
public String getPrimaryEmail() {
|
||||||
return primaryEmail;
|
return primaryEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrimaryEmail(String primaryEmail) {
|
public void setPrimaryEmail(String primaryEmail) {
|
||||||
this.primaryEmail = primaryEmail;
|
this.primaryEmail = primaryEmail;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +111,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
public String getReference() {
|
public String getReference() {
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReference(String reference) {
|
public void setReference(String reference) {
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +118,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUri(String uri) {
|
public void setUri(String uri) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +125,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
public String getDefinition() {
|
public String getDefinition() {
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefinition(String definition) {
|
public void setDefinition(String definition) {
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
}
|
}
|
||||||
|
@ -144,11 +132,16 @@ public class Researcher implements DataEntity<Researcher, UUID> {
|
||||||
public Set<DMP> getdMPs() {
|
public Set<DMP> getdMPs() {
|
||||||
return dMPs;
|
return dMPs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setdMPs(Set<DMP> dMPs) {
|
public void setdMPs(Set<DMP> dMPs) {
|
||||||
this.dMPs = dMPs;
|
this.dMPs = dMPs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfo getCreationUser() {
|
||||||
|
return creationUser;
|
||||||
|
}
|
||||||
|
public void setCreationUser(UserInfo creationUser) {
|
||||||
|
this.creationUser = creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Researcher entity) {
|
public void update(Researcher entity) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "\"Label\"")
|
@Column(name = "\"Label\"")
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
|
@ -37,15 +36,12 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false)
|
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false)
|
||||||
private String definition;
|
private String definition;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "service", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy = "service", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private Set<DatasetService> services;
|
private Set<DatasetService> services;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "\"Status\"", nullable = false)
|
@Column(name = "\"Status\"", nullable = false)
|
||||||
private Short status;
|
private Short status;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "\"Created\"")
|
@Column(name = "\"Created\"")
|
||||||
@Convert(converter = DateToUTCConverter.class)
|
@Convert(converter = DateToUTCConverter.class)
|
||||||
private Date created = null;
|
private Date created = null;
|
||||||
|
@ -54,41 +50,35 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
@Convert(converter = DateToUTCConverter.class)
|
@Convert(converter = DateToUTCConverter.class)
|
||||||
private Date modified = new Date();
|
private Date modified = new Date();
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"CreationUser\"", nullable = true)
|
||||||
|
private UserInfo creationUser;
|
||||||
|
|
||||||
|
|
||||||
public Short getStatus() {
|
public Short getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setStatus(Short status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
public void setCreated(Date created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getModified() {
|
public Date getModified() {
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
public void setModified(Date modified) {
|
||||||
this.modified = modified;
|
this.modified = modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public void setId(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +86,6 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +93,6 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
public String getAbbreviation() {
|
public String getAbbreviation() {
|
||||||
return abbreviation;
|
return abbreviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAbbreviation(String abbreviation) {
|
public void setAbbreviation(String abbreviation) {
|
||||||
this.abbreviation = abbreviation;
|
this.abbreviation = abbreviation;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +100,6 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
public String getReference() {
|
public String getReference() {
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReference(String reference) {
|
public void setReference(String reference) {
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +107,6 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUri(String uri) {
|
public void setUri(String uri) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +114,6 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
public String getDefinition() {
|
public String getDefinition() {
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefinition(String definition) {
|
public void setDefinition(String definition) {
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
}
|
}
|
||||||
|
@ -136,11 +121,17 @@ public class Service implements DataEntity<Service, UUID> {
|
||||||
public Set<DatasetService> getServices() {
|
public Set<DatasetService> getServices() {
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServices(Set<DatasetService> services) {
|
public void setServices(Set<DatasetService> services) {
|
||||||
this.services = services;
|
this.services = services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserInfo getCreationUser() {
|
||||||
|
return creationUser;
|
||||||
|
}
|
||||||
|
public void setCreationUser(UserInfo creationUser) {
|
||||||
|
this.creationUser = creationUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Service entity) {
|
public void update(Service entity) {
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import eu.eudat.queryable.queryableentity.DataEntity;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -25,6 +26,14 @@ public class UserDMP implements DataEntity<UserDMP, UUID> {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Integer> getAllValues() {
|
||||||
|
List<Integer> list = new LinkedList<>();
|
||||||
|
for (Enum en : UserDMP.UserDMPRoles.values()) {
|
||||||
|
list.add(((UserDMPRoles) en).value);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public static UserDMPRoles fromInteger(Integer value) {
|
public static UserDMPRoles fromInteger(Integer value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class DatasetPublicTableRequest extends TableQuery<DatasetPublicCriteria,
|
||||||
.where(((builder, root) -> root.get("profile").get("id").in(this.getCriteria().getDatasetProfile())));
|
.where(((builder, root) -> root.get("profile").get("id").in(this.getCriteria().getDatasetProfile())));
|
||||||
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty()) query
|
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty()) query
|
||||||
.where(((builder, root) -> root.join("dmp").join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
|
.where(((builder, root) -> root.join("dmp").join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
|
||||||
|
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManageme
|
||||||
builder.or(builder.greaterThan(root.get("grant").get("enddate"), new Date())
|
builder.or(builder.greaterThan(root.get("grant").get("enddate"), new Date())
|
||||||
, builder.isNull(root.get("grant").get("enddate"))));
|
, builder.isNull(root.get("grant").get("enddate"))));
|
||||||
}
|
}
|
||||||
if (this.getCriteria().datasetProfile != null && !this.getCriteria().datasetProfile.isEmpty()) query
|
if (this.getCriteria().datasetProfile != null && !this.getCriteria().datasetProfile.isEmpty())
|
||||||
.where(((builder, root) -> root.get("profile").get("id").in(this.getCriteria().datasetProfile)));
|
query.where((builder, root) -> root.join("associatedDmps").get("id").in(this.getCriteria().datasetProfile));
|
||||||
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty()) query
|
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty())
|
||||||
.where(((builder, root) -> root.join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
|
query.where(((builder, root) -> root.join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class ResponsesCache {
|
||||||
caches.add(new GuavaCache("services", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
caches.add(new GuavaCache("services", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
||||||
caches.add(new GuavaCache("tags", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
caches.add(new GuavaCache("tags", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
||||||
caches.add(new GuavaCache("researchers", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
caches.add(new GuavaCache("researchers", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
||||||
|
caches.add(new GuavaCache("externalDatasets", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
|
||||||
simpleCacheManager.setCaches(caches);
|
simpleCacheManager.setCaches(caches);
|
||||||
System.out.println("OK");
|
System.out.println("OK");
|
||||||
return simpleCacheManager;
|
return simpleCacheManager;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class DynamicFunderConfigurationProdImpl implements DynamicFunderConfigur
|
||||||
|
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
|
||||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||||
is = new URL("file:///" + this.environment.getProperty("configuration.resources.path") + "FunderConfiguration.xml").openStream();
|
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class DynamicGrantConfigurationProdImpl implements DynamicGrantConfigurat
|
||||||
|
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
|
||||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||||
is = new URL("file:///" + this.environment.getProperty("configuration.resources.path") + "GrantConfiguration.xml").openStream();
|
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class DynamicProjectConfigurationProdImpl implements DynamicProjectConfig
|
||||||
|
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
|
||||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||||
is = new URL("file:///" + this.environment.getProperty("configuration.resources.path") + "ProjectConfiguration.xml").openStream();
|
is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||||
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
this.configuration = (Configuration) jaxbUnmarshaller.unmarshal(is);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
|
@ -7,12 +7,14 @@ import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption;
|
||||||
import eu.eudat.logic.managers.AdminManager;
|
import eu.eudat.logic.managers.AdminManager;
|
||||||
import eu.eudat.logic.managers.DatasetProfileManager;
|
import eu.eudat.logic.managers.DatasetProfileManager;
|
||||||
import eu.eudat.logic.managers.UserManager;
|
import eu.eudat.logic.managers.UserManager;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.admin.composite.DatasetProfile;
|
import eu.eudat.models.data.admin.composite.DatasetProfile;
|
||||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
@ -37,12 +39,14 @@ public class Admin extends BaseController {
|
||||||
|
|
||||||
private DatasetProfileManager datasetProfileManager;
|
private DatasetProfileManager datasetProfileManager;
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager, Logger logger) {
|
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager, Logger logger, ConfigLoader configLoader) {
|
||||||
super(apiContext);
|
super(apiContext);
|
||||||
this.datasetProfileManager = datasetProfileManager;
|
this.datasetProfileManager = datasetProfileManager;
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -90,7 +94,7 @@ public class Admin extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
|
||||||
DataTableData<DatasetProfileListingModel> datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem);
|
DataTableData<DatasetProfileListingModel> datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
|
||||||
}
|
}
|
||||||
|
@ -116,7 +120,7 @@ public class Admin extends BaseController {
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DatasetProfile>> inactivate(@PathVariable String id, Principal principal) {
|
ResponseEntity<ResponseItem<DatasetProfile>> inactivate(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
|
||||||
try {
|
try {
|
||||||
eu.eudat.data.entities.DatasetProfile ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
|
eu.eudat.data.entities.DatasetProfile ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
|
@ -149,4 +153,8 @@ public class Admin extends BaseController {
|
||||||
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
|
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"/getRDACommonStandards"}, produces = "application/json")
|
||||||
|
public ResponseEntity getRDACommonStandards(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<String>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(configLoader.getRdaProperties()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class DMPProfileController extends BaseController {
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMPProfile>> createOrUpdate(@RequestBody DataManagementPlanProfileListingModel dataManagementPlan, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DMPProfile>> createOrUpdate(@RequestBody DataManagementPlanProfileListingModel dataManagementPlan, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
|
||||||
this.dataManagementProfileManager.createOrUpdate(dataManagementPlan, principal);
|
this.dataManagementProfileManager.createOrUpdate(dataManagementPlan, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMPProfile>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMPProfile>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||||
import eu.eudat.logic.managers.DataManagementPlanManager;
|
import eu.eudat.logic.managers.DataManagementPlanManager;
|
||||||
import eu.eudat.logic.managers.DatasetManager;
|
import eu.eudat.logic.managers.DatasetManager;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
@ -59,24 +60,26 @@ public class DMPs extends BaseController {
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
private DataManagementPlanManager dataManagementPlanManager;
|
private DataManagementPlanManager dataManagementPlanManager;
|
||||||
private DatasetManager datasetManager;
|
private DatasetManager datasetManager;
|
||||||
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DMPs(ApiContext apiContext, DynamicGrantConfiguration dynamicGrantConfiguration, Environment environment,
|
public DMPs(ApiContext apiContext, DynamicGrantConfiguration dynamicGrantConfiguration, Environment environment,
|
||||||
DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager) {
|
DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager, ConfigLoader configLoader) {
|
||||||
super(apiContext);
|
super(apiContext);
|
||||||
this.dynamicGrantConfiguration = dynamicGrantConfiguration;
|
this.dynamicGrantConfiguration = dynamicGrantConfiguration;
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
this.dataManagementPlanManager = dataManagementPlanManager;
|
this.dataManagementPlanManager = dataManagementPlanManager;
|
||||||
this.datasetManager = datasetManager;
|
this.datasetManager = datasetManager;
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
/*@Transactional
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
||||||
this.dataManagementPlanManager.unlock(id);
|
this.dataManagementPlanManager.unlock(id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
|
@ -87,10 +90,10 @@ public class DMPs extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"{id}"})
|
@RequestMapping(method = RequestMethod.GET, value = {"{id}"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException, InstantiationException, IOException {
|
ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType,
|
||||||
if (contentType.equals("application/xml") || contentType.equals("application/msword")) { //|| contentType.equals("application/pdf")
|
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, InstantiationException, IOException {
|
||||||
ResponseEntity<byte[]> document = this.dataManagementPlanManager.getDocument(id, contentType);
|
if (contentType.equals("application/xml") || contentType.equals("application/msword")) {
|
||||||
return document;
|
return this.dataManagementPlanManager.getDocument(id, contentType, principal, this.configLoader);
|
||||||
} else {
|
} else {
|
||||||
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicGrantConfiguration);
|
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicGrantConfiguration);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
|
||||||
|
@ -106,8 +109,8 @@ public class DMPs extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"})
|
@RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity getRDAJsonDocument(@PathVariable String id, Principal principal) throws IOException {
|
ResponseEntity getRDAJsonDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IOException {
|
||||||
return this.dataManagementPlanManager.getRDAJsonDocument(id);
|
return this.dataManagementPlanManager.getRDAJsonDocument(id, principal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"})
|
@RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"})
|
||||||
|
@ -186,8 +189,9 @@ public class DMPs extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType,
|
||||||
File file = this.dataManagementPlanManager.getWordDocument(id);
|
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
||||||
|
File file = this.dataManagementPlanManager.getWordDocument(id, principal, configLoader);
|
||||||
String name = file.getName().substring(0, file.getName().length() - 5);
|
String name = file.getName().substring(0, file.getName().length() - 5);
|
||||||
File pdffile = datasetManager.convertToPDF(file, environment, name);
|
File pdffile = datasetManager.convertToPDF(file, environment, name);
|
||||||
InputStream resource = new FileInputStream(pdffile);
|
InputStream resource = new FileInputStream(pdffile);
|
||||||
|
@ -204,9 +208,7 @@ public class DMPs extends BaseController {
|
||||||
resource.close();
|
resource.close();
|
||||||
Files.deleteIfExists(file.toPath());
|
Files.deleteIfExists(file.toPath());
|
||||||
Files.deleteIfExists(pdffile.toPath());
|
Files.deleteIfExists(pdffile.toPath());
|
||||||
return new ResponseEntity<>(content,
|
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
||||||
responseHeaders,
|
|
||||||
HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
|
||||||
|
@ -218,8 +220,10 @@ public class DMPs extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPublicPaged(@RequestBody DataManagmentPlanPublicTableRequest dmpTableRequest, @RequestParam String fieldsGroup) throws Exception {
|
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPublicPaged(@RequestBody DataManagmentPlanPublicTableRequest dmpTableRequest,
|
||||||
DataTableData<DataManagementPlanListingModel> dmp = this.dataManagementPlanManager.getPaged(dmpTableRequest, fieldsGroup);
|
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal,
|
||||||
|
@RequestParam String fieldsGroup) throws Exception {
|
||||||
|
DataTableData<DataManagementPlanListingModel> dmp = this.dataManagementPlanManager.getPublicPaged(dmpTableRequest, fieldsGroup, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dmp));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +266,7 @@ public class DMPs extends BaseController {
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/createZenodoDoi/{id}"})
|
@RequestMapping(method = RequestMethod.POST, value = {"/createZenodoDoi/{id}"})
|
||||||
public ResponseEntity<ResponseItem<String>> createZenodoDoi(@PathVariable String id, Principal principal) {
|
public ResponseEntity<ResponseItem<String>> createZenodoDoi(@PathVariable String id, Principal principal) {
|
||||||
try {
|
try {
|
||||||
String zenodoDOI = this.dataManagementPlanManager.createZenodoDoi(UUID.fromString(id), principal);
|
String zenodoDOI = this.dataManagementPlanManager.createZenodoDoi(UUID.fromString(id), principal, configLoader);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(zenodoDOI));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(zenodoDOI));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -2,12 +2,10 @@ package eu.eudat.controllers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.DataRepository;
|
import eu.eudat.data.entities.DataRepository;
|
||||||
import eu.eudat.logic.managers.DataRepositoryManager;
|
import eu.eudat.logic.managers.DataRepositoryManager;
|
||||||
import eu.eudat.logic.managers.ResearcherManager;
|
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.datarepository.DataRepositoryModel;
|
import eu.eudat.models.data.datarepository.DataRepositoryModel;
|
||||||
import eu.eudat.models.data.dmp.Researcher;
|
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
@ -18,7 +16,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -36,18 +33,18 @@ public class DataRepositories extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<List<Map<String, String>>>> listExternalDataRepositories(
|
ResponseEntity<ResponseItem<List<DataRepositoryModel>>> listExternalDataRepositories(
|
||||||
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
|
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal
|
||||||
) throws HugeResultSet, NoURLFound {
|
) throws HugeResultSet, NoURLFound {
|
||||||
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getRepositories(query, type);
|
List<DataRepositoryModel> dataRepositoryModels = this.dataRepositoryManager.getDataRepositories(query, type, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Map<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(remoteRepos));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataRepositoryModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataRepositoryModels));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataRepository>> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DataRepository>> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception {
|
||||||
DataRepository dataRepository = this.dataRepositoryManager.create(dataRepositoryModel);
|
DataRepository dataRepository = this.dataRepositoryManager.create(dataRepositoryModel, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataRepository>().payload(dataRepository).status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataRepository>().payload(dataRepository).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,18 +39,18 @@ public class DatasetProfileController extends BaseController {
|
||||||
this.datasetProfileManager = datasetProfileManager;
|
this.datasetProfileManager = datasetProfileManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
/* @Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/save/{id}"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/save/{id}"}, consumes = "application/json", produces = "application/json")
|
||||||
public ResponseEntity<Object> updateDataset(@PathVariable String id, @RequestBody PropertiesModel properties) {
|
public ResponseEntity<Object> updateDataset(@PathVariable String id, @RequestBody PropertiesModel properties) {
|
||||||
eu.eudat.data.entities.Dataset dataset = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
|
eu.eudat.data.entities.Dataset dataset = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
|
||||||
Map<String, Object> values = new HashMap();
|
Map<String, Object> values = new HashMap<>();
|
||||||
properties.toMap(values);
|
properties.toMap(values);
|
||||||
JSONObject jobject = new JSONObject(values);
|
JSONObject jobject = new JSONObject(values);
|
||||||
dataset.setProperties(jobject.toString());
|
dataset.setProperties(jobject.toString());
|
||||||
dataset.setStatus((short) properties.getStatus());
|
dataset.setStatus((short) properties.getStatus());
|
||||||
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
|
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(properties);
|
return ResponseEntity.status(HttpStatus.OK).body(properties);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
||||||
|
|
|
@ -1,25 +1,19 @@
|
||||||
package eu.eudat.controllers;
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.DMP;
|
|
||||||
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest;
|
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest;
|
||||||
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
|
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
|
||||||
import eu.eudat.logic.managers.DatasetProfileManager;
|
import eu.eudat.logic.managers.DatasetProfileManager;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem;
|
import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem;
|
||||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.data.security.Principal;
|
|
||||||
import eu.eudat.types.ApiMessageCode;
|
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.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -42,10 +36,10 @@ public class DatasetProfiles extends BaseController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileAutocompleteItems));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileAutocompleteItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/datasetprofiles/getAll"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getAll"}, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<List<DatasetProfileListingModel>>> getAll() throws InstantiationException, IllegalAccessException {
|
ResponseEntity<ResponseItem<List<DatasetProfileListingModel>>> getAll(@RequestBody DatasetProfileTableRequestItem tableRequestItem) throws InstantiationException, IllegalAccessException {
|
||||||
List<DatasetProfileListingModel> datasetProfileTableData = this.datasetProfileManager.getAll();
|
List<DatasetProfileListingModel> datasetProfileTableData = this.datasetProfileManager.getAll(tableRequestItem);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package eu.eudat.controllers;
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
import eu.eudat.data.dao.entities.DatasetDao;
|
|
||||||
import eu.eudat.data.entities.Dataset;
|
import eu.eudat.data.entities.Dataset;
|
||||||
import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest;
|
import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest;
|
||||||
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest;
|
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest;
|
||||||
|
@ -8,6 +7,7 @@ import eu.eudat.exceptions.datasetwizard.DatasetWizardCannotUnlockException;
|
||||||
import eu.eudat.logic.managers.DatasetManager;
|
import eu.eudat.logic.managers.DatasetManager;
|
||||||
import eu.eudat.logic.managers.DatasetWizardManager;
|
import eu.eudat.logic.managers.DatasetWizardManager;
|
||||||
import eu.eudat.logic.managers.UserManager;
|
import eu.eudat.logic.managers.UserManager;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||||
|
@ -48,13 +48,15 @@ public class DatasetWizardController extends BaseController {
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
private DatasetManager datasetManager;
|
private DatasetManager datasetManager;
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DatasetWizardController(ApiContext apiContext, Environment environment, DatasetManager datasetManager, UserManager userManager) {
|
public DatasetWizardController(ApiContext apiContext, Environment environment, DatasetManager datasetManager, UserManager userManager, ConfigLoader configLoader) {
|
||||||
super(apiContext);
|
super(apiContext);
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
this.datasetManager = datasetManager;
|
this.datasetManager = datasetManager;
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/userDmps"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/userDmps"}, produces = "application/json")
|
||||||
|
@ -80,7 +82,7 @@ public class DatasetWizardController extends BaseController {
|
||||||
return this.datasetManager.getDocument(id, visibilityRuleService, contentType);
|
return this.datasetManager.getDocument(id, visibilityRuleService, contentType);
|
||||||
}
|
}
|
||||||
else if (contentType.equals("application/msword")) {
|
else if (contentType.equals("application/msword")) {
|
||||||
File file = datasetManager.getWordDocument(this.environment, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
File file = datasetManager.getWordDocument(this.configLoader, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||||
InputStream resource = new FileInputStream(file);
|
InputStream resource = new FileInputStream(file);
|
||||||
HttpHeaders responseHeaders = new HttpHeaders();
|
HttpHeaders responseHeaders = new HttpHeaders();
|
||||||
responseHeaders.setContentLength(file.length());
|
responseHeaders.setContentLength(file.length());
|
||||||
|
@ -133,7 +135,7 @@ public class DatasetWizardController extends BaseController {
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
||||||
File file = datasetManager.getWordDocument(this.environment, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
File file = datasetManager.getWordDocument(this.configLoader, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
if (fileName.endsWith(".docx")){
|
if (fileName.endsWith(".docx")){
|
||||||
fileName = fileName.substring(0, fileName.length() - 5);
|
fileName = fileName.substring(0, fileName.length() - 5);
|
||||||
|
|
|
@ -46,7 +46,8 @@ public class Datasets extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPublicPaged(@RequestBody DatasetPublicTableRequest datasetTableRequest, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPublicPaged(@RequestBody DatasetPublicTableRequest datasetTableRequest,
|
||||||
|
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
|
||||||
DataTableData<DatasetListingModel> dataTable = this.datasetManager.getPaged(datasetTableRequest, principal);
|
DataTableData<DatasetListingModel> dataTable = this.datasetManager.getPaged(datasetTableRequest, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class ExternalDatasets extends BaseController {
|
||||||
ResponseEntity<ResponseItem<List<ExternalDatasetListingModel>>> getWithExternal(
|
ResponseEntity<ResponseItem<List<ExternalDatasetListingModel>>> getWithExternal(
|
||||||
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal
|
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal
|
||||||
) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException {
|
) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException {
|
||||||
List<ExternalDatasetListingModel> dataTable = externalDatasetManager.getWithExternal(query);
|
List<ExternalDatasetListingModel> dataTable = externalDatasetManager.getWithExternal(query, type, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class ExternalDatasets extends BaseController {
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<ExternalDataset>> create(@RequestBody eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<ExternalDataset>> create(@RequestBody eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception {
|
||||||
ExternalDataset externalDataset = this.externalDatasetManager.create(externalDatasetModel);
|
ExternalDataset externalDataset = this.externalDatasetManager.create(externalDatasetModel, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalDataset>().payload(externalDataset).status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalDataset>().payload(externalDataset).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,21 +60,21 @@ public class Grants extends BaseController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.grant.Grant>().payload(grant).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.grant.Grant>().payload(grant).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
/*@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Grant>> addGrant(@Valid @RequestBody eu.eudat.models.data.grant.Grant grant, Principal principal) throws IOException, ParseException {
|
ResponseEntity<ResponseItem<Grant>> addGrant(@Valid @RequestBody eu.eudat.models.data.grant.Grant grant, Principal principal) throws IOException, ParseException {
|
||||||
this.grantManager.createOrUpdate(grant, principal);
|
this.grantManager.createOrUpdate(grant, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Grant>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Grant>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Transactional
|
/*@Transactional
|
||||||
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Grant>> inactivate(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
|
ResponseEntity<ResponseItem<Grant>> inactivate(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
|
||||||
this.grantManager.inactivate(id);
|
this.grantManager.inactivate(id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Grant>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Grant>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/external"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/external"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
|
|
|
@ -3,10 +3,21 @@ package eu.eudat.controllers;
|
||||||
import eu.eudat.core.logger.Logger;
|
import eu.eudat.core.logger.Logger;
|
||||||
import eu.eudat.exceptions.security.NullEmailException;
|
import eu.eudat.exceptions.security.NullEmailException;
|
||||||
import eu.eudat.logic.managers.UserManager;
|
import eu.eudat.logic.managers.UserManager;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.security.CustomAuthenticationProvider;
|
import eu.eudat.logic.security.CustomAuthenticationProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.models.ConfigurableProvidersModel;
|
||||||
import eu.eudat.logic.security.validators.b2access.B2AccessTokenValidator;
|
import eu.eudat.logic.security.validators.b2access.B2AccessTokenValidator;
|
||||||
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessRequest;
|
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessRequest;
|
||||||
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessResponseToken;
|
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.ConfigurableProviderTokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.helpers.ConfigurableProviderRequest;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.helpers.ConfigurableProviderResponseToken;
|
||||||
|
import eu.eudat.logic.security.validators.linkedin.LinkedInTokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.linkedin.helpers.LinkedInRequest;
|
||||||
|
import eu.eudat.logic.security.validators.linkedin.helpers.LinkedInResponseToken;
|
||||||
|
import eu.eudat.logic.security.validators.openaire.OpenAIRETokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.openaire.helpers.OpenAIRERequest;
|
||||||
|
import eu.eudat.logic.security.validators.openaire.helpers.OpenAIREResponseToken;
|
||||||
import eu.eudat.logic.security.validators.orcid.ORCIDTokenValidator;
|
import eu.eudat.logic.security.validators.orcid.ORCIDTokenValidator;
|
||||||
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDRequest;
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDRequest;
|
||||||
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDResponseToken;
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDResponseToken;
|
||||||
|
@ -37,19 +48,27 @@ public class Login {
|
||||||
private TwitterTokenValidator twitterTokenValidator;
|
private TwitterTokenValidator twitterTokenValidator;
|
||||||
private B2AccessTokenValidator b2AccessTokenValidator;
|
private B2AccessTokenValidator b2AccessTokenValidator;
|
||||||
private ORCIDTokenValidator orcidTokenValidator;
|
private ORCIDTokenValidator orcidTokenValidator;
|
||||||
|
private LinkedInTokenValidator linkedInTokenValidator;
|
||||||
|
private OpenAIRETokenValidator openAIRETokenValidator;
|
||||||
|
private ConfigurableProviderTokenValidator configurableProviderTokenValidator;
|
||||||
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService nonVerifiedUserAuthenticationService,
|
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService nonVerifiedUserAuthenticationService,
|
||||||
TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator, ORCIDTokenValidator orcidTokenValidator,
|
TwitterTokenValidator twitterTokenValidator, LinkedInTokenValidator linkedInTokenValidator, B2AccessTokenValidator b2AccessTokenValidator,
|
||||||
UserManager userManager ,Logger logger) {
|
ORCIDTokenValidator orcidTokenValidator, OpenAIRETokenValidator openAIRETokenValidator, ConfigurableProviderTokenValidator configurableProviderTokenValidator, ConfigLoader configLoader, UserManager userManager, Logger logger) {
|
||||||
this.customAuthenticationProvider = customAuthenticationProvider;
|
this.customAuthenticationProvider = customAuthenticationProvider;
|
||||||
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
this.twitterTokenValidator = twitterTokenValidator;
|
this.twitterTokenValidator = twitterTokenValidator;
|
||||||
|
this.linkedInTokenValidator = linkedInTokenValidator;
|
||||||
this.b2AccessTokenValidator = b2AccessTokenValidator;
|
this.b2AccessTokenValidator = b2AccessTokenValidator;
|
||||||
this.orcidTokenValidator = orcidTokenValidator;
|
this.orcidTokenValidator = orcidTokenValidator;
|
||||||
|
this.openAIRETokenValidator = openAIRETokenValidator;
|
||||||
|
this.configurableProviderTokenValidator = configurableProviderTokenValidator;
|
||||||
|
this.configLoader = configLoader;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
}
|
}
|
||||||
|
@ -76,6 +95,12 @@ public class Login {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OAuthToken>().payload(this.twitterTokenValidator.getRequestToken()).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OAuthToken>().payload(this.twitterTokenValidator.getRequestToken()).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = {"/linkedInRequestToken"}, produces = "application/json", consumes = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem<LinkedInResponseToken>> linkedInRequestToken(@RequestBody LinkedInRequest linkedInRequest) {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<LinkedInResponseToken>().payload(this.linkedInTokenValidator.getAccessToken(linkedInRequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/b2AccessRequestToken"}, produces = "application/json", consumes = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/b2AccessRequestToken"}, produces = "application/json", consumes = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<B2AccessResponseToken>> b2AccessRequestToken(@RequestBody B2AccessRequest b2AccessRequest) {
|
ResponseEntity<ResponseItem<B2AccessResponseToken>> b2AccessRequestToken(@RequestBody B2AccessRequest b2AccessRequest) {
|
||||||
|
@ -88,6 +113,18 @@ public class Login {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ORCIDResponseToken>().payload(this.orcidTokenValidator.getAccessToken(orcidRequest)).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ORCIDResponseToken>().payload(this.orcidTokenValidator.getAccessToken(orcidRequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = {"/openAireRequestToken"}, produces = "application/json", consumes = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem<OpenAIREResponseToken>> openAIRERequestToken(@RequestBody OpenAIRERequest openAIRERequest) {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OpenAIREResponseToken>().payload(this.openAIRETokenValidator.getAccessToken(openAIRERequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = {"/configurableProviderRequestToken"}, produces = "application/json", consumes = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem<ConfigurableProviderResponseToken>> configurableProviderRequestToken(@RequestBody ConfigurableProviderRequest configurableProviderRequest) {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ConfigurableProviderResponseToken>().payload(this.configurableProviderTokenValidator.getAccessToken(configurableProviderRequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) throws NullEmailException {
|
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) throws NullEmailException {
|
||||||
|
@ -103,4 +140,10 @@ public class Login {
|
||||||
this.logger.info(principal, "Logged Out");
|
this.logger.info(principal, "Logged Out");
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"/configurableLogin"}, consumes = "application/json", produces = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem<ConfigurableProvidersModel>> getConfigurableProviders() {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ConfigurableProvidersModel>().payload(new ConfigurableProvidersModel().fromDataModel(configLoader.getConfigurableProviders())).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.controllers;
|
||||||
|
|
||||||
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
|
import eu.eudat.data.query.items.table.organisations.OrganisationsTableRequest;
|
||||||
import eu.eudat.logic.managers.OrganisationsManager;
|
import eu.eudat.logic.managers.OrganisationsManager;
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
@ -38,7 +39,8 @@ public class Organisations extends BaseController {
|
||||||
ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations(
|
ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations(
|
||||||
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
|
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
|
||||||
) throws HugeResultSet, NoURLFound {
|
) throws HugeResultSet, NoURLFound {
|
||||||
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(query, type);
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||||
|
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(externalUrlCriteria, type);
|
||||||
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
|
OrganisationsExternalSourcesModel organisationsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(organisationsExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(organisationsExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,11 @@ public class QuickWizardController extends BaseController {
|
||||||
|
|
||||||
Funder funderEntity;
|
Funder funderEntity;
|
||||||
//Create Funder
|
//Create Funder
|
||||||
if (quickWizard.getFunder().getExistFunder() == null
|
if (quickWizard.getFunder() == null) {
|
||||||
&& quickWizard.getFunder().getLabel() == null) {
|
throw new Exception("Funder is a mandatory entity");
|
||||||
funderEntity = null;
|
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) {
|
||||||
|
// funderEntity = null;
|
||||||
|
throw new Exception("Funder is a mandatory entity");
|
||||||
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
|
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
|
||||||
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
|
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,8 +92,6 @@ public class QuickWizardController extends BaseController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<QuickWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<QuickWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/datasetcreate"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetcreate"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DatasetCreateWizardModel>> addDatasetWizard(@RequestBody DatasetCreateWizardModel datasetCreateWizardModel, Principal principal) throws Exception{
|
ResponseEntity<ResponseItem<DatasetCreateWizardModel>> addDatasetWizard(@RequestBody DatasetCreateWizardModel datasetCreateWizardModel, Principal principal) throws Exception{
|
||||||
|
@ -101,5 +101,4 @@ public class QuickWizardController extends BaseController {
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetCreateWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset added!"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetCreateWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset added!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.data.registries.RegistryModel;
|
import eu.eudat.models.data.registries.RegistryModel;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
import eu.eudat.types.ApiMessageCode;
|
||||||
import org.apache.regexp.RE;
|
|
||||||
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;
|
||||||
|
@ -17,7 +16,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -35,17 +33,17 @@ public class Registries extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/external/registries"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, value = {"/external/registries"}, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<List<Map<String, String>>>> listExternalRegistries(@RequestParam(value = "query", required = false) String query
|
ResponseEntity<ResponseItem<List<RegistryModel>>> listExternalRegistries(@RequestParam(value = "query", required = false) String query
|
||||||
, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound {
|
, @RequestParam(value = "type", required = false) String type, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getRegistries(query, type);
|
List<RegistryModel> registryModels = this.registryManager.getRegistries(query, type, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Map<String, String>>>().payload(remoteRepos).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RegistryModel>>().payload(registryModels).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Registry>> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<Registry>> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception {
|
||||||
Registry registry = this.registryManager.create(registryModel);
|
Registry registry = this.registryManager.create(registryModel, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Registry>().payload(registry).status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Registry>().payload(registry).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class Researchers extends BaseController {
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/getWithExternal"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/getWithExternal"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>> getWithExternal(@RequestBody ResearcherCriteriaRequest researcherCriteriaRequest, Principal principal) throws HugeResultSet, NoURLFound {
|
ResponseEntity<ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>> getWithExternal(@RequestBody ResearcherCriteriaRequest researcherCriteriaRequest, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
List<eu.eudat.models.data.dmp.Researcher> dataTable = this.researcherManager.getCriteriaWithExternal(researcherCriteriaRequest);
|
List<eu.eudat.models.data.dmp.Researcher> dataTable = this.researcherManager.getCriteriaWithExternal(researcherCriteriaRequest, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class Researchers extends BaseController {
|
||||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Researcher>> create(@RequestBody eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<Researcher>> create(@RequestBody eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
|
||||||
this.researcherManager.create(researcher);
|
this.researcherManager.create(researcher, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Researcher>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Researcher>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -34,18 +33,18 @@ public class Services extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/external/services"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, value = {"/external/services"}, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<List<Map<String, String>>>> listExternalServices(
|
ResponseEntity<ResponseItem<List<ServiceModel>>> listExternalServices(
|
||||||
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type
|
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal
|
||||||
) throws HugeResultSet, NoURLFound {
|
) throws HugeResultSet, NoURLFound {
|
||||||
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getServices(query, type);
|
List<ServiceModel> serviceModels = this.serviceManager.getServices(query, type, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Map<String, String>>>().payload(remoteRepos).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ServiceModel>>().payload(serviceModels).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Service>> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<Service>> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception {
|
||||||
Service service = serviceManager.create(serviceModel);
|
Service service = serviceManager.create(serviceModel, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Service>().payload(service).status(ApiMessageCode.SUCCESS_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Service>().payload(service).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.elastic.criteria.TagCriteria;
|
import eu.eudat.elastic.criteria.TagCriteria;
|
||||||
import eu.eudat.elastic.entities.Dataset;
|
import eu.eudat.elastic.entities.Dataset;
|
||||||
import eu.eudat.elastic.repository.Repository;
|
import eu.eudat.elastic.repository.Repository;
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
@ -47,14 +48,10 @@ public class TagController extends BaseController {
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<TagExternalSourcesModel>> listExternalTagModel(
|
ResponseEntity<ResponseItem<TagExternalSourcesModel>> listExternalTagModel(
|
||||||
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException {
|
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound, IOException {
|
||||||
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(query, type);
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||||
|
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(externalUrlCriteria, type);
|
||||||
TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);
|
TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
|
|
||||||
// ObjectMapper mapper = new ObjectMapper();
|
|
||||||
// String fileUrl = this.environment.getProperty("configuration.resources.path") + this.environment.getProperty("dataset.tags.mock");
|
|
||||||
// List<Map<String, String>> data = mapper.readValue(new File(fileUrl), new TypeReference<List<Map<String, String>>>(){});
|
|
||||||
// TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(data);
|
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<TagExternalSourcesModel>().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<TagExternalSourcesModel>().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,17 @@ public final class PrincipalArgumentResolver implements HandlerMethodArgumentRes
|
||||||
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
|
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
|
||||||
String token = nativeWebRequest.getHeader("AuthToken");
|
String token = nativeWebRequest.getHeader("AuthToken");
|
||||||
|
|
||||||
Boolean checkMailNull = ((ServletWebRequest) nativeWebRequest).getRequest().getRequestURI().startsWith("/api/emailConfirmation");
|
boolean checkMailNull = ((ServletWebRequest) nativeWebRequest).getRequest().getRequestURI().startsWith("/api/emailConfirmation");
|
||||||
AuthenticationService authenticationService = checkMailNull ? this.nonVerifiedUserAuthenticationService : this.verifiedUserAuthenticationService;
|
AuthenticationService authenticationService = checkMailNull ? this.nonVerifiedUserAuthenticationService : this.verifiedUserAuthenticationService;
|
||||||
|
|
||||||
Optional<Annotation> claimsAnnotation = Arrays.stream(methodParameter.getParameterAnnotations()).filter(annotation -> annotation.annotationType().equals(ClaimedAuthorities.class)).findAny();
|
Optional<Annotation> claimsAnnotation = Arrays.stream(methodParameter.getParameterAnnotations()).filter(annotation -> annotation.annotationType().equals(ClaimedAuthorities.class)).findAny();
|
||||||
List<Authorities> claimList = claimsAnnotation.map(annotation -> Arrays.asList(((ClaimedAuthorities) annotation).claims())).orElse(Authorities.all());
|
List<Authorities> claimList = claimsAnnotation.map(annotation -> Arrays.asList(((ClaimedAuthorities) annotation).claims())).orElse(Authorities.all());
|
||||||
if (claimList.size() == 1 && claimList.get(0).equals(Authorities.ANONYMOUS))
|
if (claimList.size() == 1 && claimList.get(0).equals(Authorities.ANONYMOUS)) {
|
||||||
return new Principal();
|
return new Principal();
|
||||||
|
} else if (claimList.contains(Authorities.ANONYMOUS) && token == null) {
|
||||||
|
return new Principal();
|
||||||
|
}
|
||||||
|
|
||||||
if (token == null) throw new UnauthorisedException("Authentication Information Is Missing");
|
if (token == null) throw new UnauthorisedException("Authentication Information Is Missing");
|
||||||
UUID authToken;
|
UUID authToken;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import eu.eudat.data.dao.entities.DMPDao;
|
||||||
import eu.eudat.data.dao.entities.DatasetDao;
|
import eu.eudat.data.dao.entities.DatasetDao;
|
||||||
import eu.eudat.data.dao.entities.OrganisationDao;
|
import eu.eudat.data.dao.entities.OrganisationDao;
|
||||||
import eu.eudat.data.dao.entities.GrantDao;
|
import eu.eudat.data.dao.entities.GrantDao;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.*;
|
||||||
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
|
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
@ -40,23 +40,26 @@ public class DashBoardManager {
|
||||||
public DashBoardStatistics getStatistics() {
|
public DashBoardStatistics getStatistics() {
|
||||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||||
|
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
|
||||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
|
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
|
||||||
datasetCriteria.setAllVersions(false);
|
|
||||||
dataManagementPlanCriteria.setAllVersions(false);
|
dataManagementPlanCriteria.setAllVersions(false);
|
||||||
organisationCriteria.setPublic(false);
|
dataManagementPlanCriteria.setIsPublic(true);
|
||||||
|
organisationCriteria.setPublic(true);
|
||||||
|
|
||||||
CompletableFuture dmpFuture = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).countAsync()
|
List<DMP> dmps = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).toList();
|
||||||
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
long numberOfDatasets = 0;
|
||||||
CompletableFuture datasetFuture = databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).countAsync()
|
LinkedList<Grant> grants = new LinkedList<>();
|
||||||
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
for (DMP dmp : dmps) {
|
||||||
CompletableFuture grantFuture = databaseRepository.getGrantDao().asQueryable().countAsync()
|
numberOfDatasets = numberOfDatasets + dmp.getDataset().stream()
|
||||||
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
|
.filter(item -> item.getStatus() == Dataset.Status.FINALISED.getValue()).count();
|
||||||
CompletableFuture organisationFuture = databaseRepository.getOrganisationDao().getWithCriteria(organisationCriteria).countAsync()
|
grants.add(dmp.getGrant());
|
||||||
.whenComplete((organisationStats, throwable) -> statistics.setTotalOrganisationCount(organisationStats));
|
}
|
||||||
|
|
||||||
|
statistics.setTotalDataManagementPlanCount((long) dmps.size());
|
||||||
|
statistics.setTotalDataSetCount(numberOfDatasets);
|
||||||
|
statistics.setTotalGrantCount(grants.stream().distinct().count());
|
||||||
|
statistics.setTotalOrganisationCount(databaseRepository.getOrganisationDao().getWithCriteria(organisationCriteria).count());
|
||||||
|
|
||||||
CompletableFuture.allOf(dmpFuture, datasetFuture, grantFuture, organisationFuture).join();
|
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,9 +76,9 @@ public class DashBoardManager {
|
||||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||||
dataManagementPlanCriteria.setAllVersions(false);
|
dataManagementPlanCriteria.setAllVersions(false);
|
||||||
GrantCriteria grantCriteria = new GrantCriteria();
|
GrantCriteria grantCriteria = new GrantCriteria();
|
||||||
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
|
|
||||||
|
|
||||||
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId()).countAsync()
|
List<Integer> roles = new LinkedList<>();
|
||||||
|
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).countAsync()
|
||||||
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
||||||
CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user).countAsync()
|
CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user).countAsync()
|
||||||
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
||||||
|
@ -102,7 +105,8 @@ public class DashBoardManager {
|
||||||
GrantCriteria grantCriteria = new GrantCriteria();
|
GrantCriteria grantCriteria = new GrantCriteria();
|
||||||
RecentActivityDataBuilder recentActivityDataBuilder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(RecentActivityDataBuilder.class);
|
RecentActivityDataBuilder recentActivityDataBuilder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(RecentActivityDataBuilder.class);
|
||||||
|
|
||||||
CompletableFuture<List<RecentActivityData>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId())
|
List<Integer> roles = new LinkedList<>();
|
||||||
|
CompletableFuture<List<RecentActivityData>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles)
|
||||||
.withHint("dmpRecentActivity")
|
.withHint("dmpRecentActivity")
|
||||||
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||||
.take(numberofactivities)
|
.take(numberofactivities)
|
||||||
|
@ -135,8 +139,9 @@ public class DashBoardManager {
|
||||||
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
||||||
GrantDao grantRepository = databaseRepository.getGrantDao();
|
GrantDao grantRepository = databaseRepository.getGrantDao();
|
||||||
|
|
||||||
|
List<Integer> roles = new LinkedList<>();
|
||||||
List<SearchBarItem> searchBarItems = new LinkedList<>();
|
List<SearchBarItem> searchBarItems = new LinkedList<>();
|
||||||
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId())
|
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId(), roles)
|
||||||
.withHint("dmpRecentActivity")
|
.withHint("dmpRecentActivity")
|
||||||
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
|
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
|
||||||
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||||
|
|
|
@ -16,6 +16,7 @@ import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
@ -39,6 +40,7 @@ import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
|
||||||
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
|
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
|
||||||
import eu.eudat.models.data.listingmodels.DatasetListingModel;
|
import eu.eudat.models.data.listingmodels.DatasetListingModel;
|
||||||
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
|
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
|
||||||
|
import eu.eudat.models.data.rda.RDAExportModel;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||||
|
@ -59,6 +61,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.JoinType;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
@ -92,7 +96,9 @@ public class DataManagementPlanManager {
|
||||||
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception {
|
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception {
|
||||||
UUID principalID = principal.getId();
|
UUID principalID = principal.getId();
|
||||||
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
||||||
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalID);
|
List<Integer> roles = new LinkedList<>();
|
||||||
|
if (dataManagementPlanTableRequest.getCriteria().getRole() != null) roles.add(dataManagementPlanTableRequest.getCriteria().getRole());
|
||||||
|
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalID, roles);
|
||||||
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
|
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
|
||||||
|
|
||||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
|
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
|
||||||
|
@ -115,20 +121,27 @@ public class DataManagementPlanManager {
|
||||||
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
||||||
} else {
|
} else {
|
||||||
itemsFuture = pagedItems
|
itemsFuture = pagedItems
|
||||||
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item))
|
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModelAssociatedProfiles(item))
|
||||||
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture countFuture = authItems.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();
|
||||||
return dataTable;
|
return dataTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup) throws Exception {
|
public DataTableData<DataManagementPlanListingModel> getPublicPaged(DataManagmentPlanPublicTableRequest dataManagementPlanPublicTableRequest, String fieldsGroup, Principal principal) throws Exception {
|
||||||
dataManagementPlanPublicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)));
|
dataManagementPlanPublicTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)));
|
||||||
QueryableList<DMP> items = dataManagementPlanPublicTableRequest.applyCriteria();
|
QueryableList<DMP> items = dataManagementPlanPublicTableRequest.applyCriteria();
|
||||||
|
|
||||||
|
if (principal.getId() != null && dataManagementPlanPublicTableRequest.getCriteria().getRole() != null) {
|
||||||
|
items.where((builder, root) -> {
|
||||||
|
Join userJoin = root.join("users", JoinType.LEFT);
|
||||||
|
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal.getId()), builder.equal(userJoin.get("role"), dataManagementPlanPublicTableRequest.getCriteria().getRole()));
|
||||||
|
});
|
||||||
|
}
|
||||||
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items, dataManagementPlanPublicTableRequest);
|
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items, dataManagementPlanPublicTableRequest);
|
||||||
|
|
||||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
|
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
|
||||||
|
@ -163,44 +176,38 @@ public class DataManagementPlanManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getWordDocument(String id) throws InstantiationException, IllegalAccessException, IOException {
|
public File getWordDocument(String id, Principal principal, ConfigLoader configLoader) throws IOException {
|
||||||
WordBuilder wordBuilder = new WordBuilder();
|
WordBuilder wordBuilder = new WordBuilder();
|
||||||
VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService();
|
VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService();
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||||
String fileUrl = environment.getProperty("configuration.h2020template");
|
XWPFDocument document = configLoader.getDocument();
|
||||||
InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
|
||||||
XWPFDocument document = new XWPFDocument(is);
|
|
||||||
|
|
||||||
eu.eudat.data.entities.DMP dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
eu.eudat.data.entities.DMP dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||||
|
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||||
|
throw new UnauthorisedException();
|
||||||
|
|
||||||
// Space above DMP title.
|
// DMP info on top of the document.
|
||||||
XWPFParagraph parAboveDmpTitle = document.createParagraph();
|
wordBuilder.addParagraphContent("Data Management Plan Information", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||||
XWPFParagraph parAboveDmpTitle1 = document.createParagraph();
|
|
||||||
XWPFParagraph parAboveDmpTitle2 = document.createParagraph();
|
|
||||||
XWPFParagraph parAboveDmpTitle3 = document.createParagraph();
|
|
||||||
|
|
||||||
// DMP title custom style.
|
// DMP title custom style.
|
||||||
//wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO);
|
wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||||
XWPFParagraph dmpLabelParagraph = document.createParagraph();
|
|
||||||
XWPFRun run = dmpLabelParagraph.createRun();
|
|
||||||
run.setText(dmpEntity.getLabel());
|
|
||||||
run.setBold(true);
|
|
||||||
run.setFontSize(20);
|
|
||||||
|
|
||||||
// Space below DMP title.
|
|
||||||
XWPFParagraph parBelowDmpTitle = document.createParagraph();
|
|
||||||
|
|
||||||
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
|
||||||
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
wordBuilder.addParagraphContent("Funder", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
if (dmpEntity.getGrant().getFunder() != null)
|
||||||
|
wordBuilder.addParagraphContent(dmpEntity.getGrant().getFunder().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
|
||||||
|
wordBuilder.addParagraphContent("Grant", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
wordBuilder.addParagraphContent(dmpEntity.getGrant().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
|
||||||
|
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
if (dmpEntity.getOrganisations().size() > 0) {
|
if (dmpEntity.getOrganisations().size() > 0) {
|
||||||
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(x -> x.getLabel()).collect(Collectors.joining(", "))
|
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(Organisation::getLabel).collect(Collectors.joining(", "))
|
||||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
if (dmpEntity.getResearchers().size() > 0) {
|
if (dmpEntity.getResearchers().size() > 0) {
|
||||||
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(x -> x.getLabel()).collect(Collectors.joining(", "))
|
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(Researcher::getLabel).collect(Collectors.joining(", "))
|
||||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,17 +220,23 @@ public class DataManagementPlanManager {
|
||||||
XWPFParagraph parBreakDMP = document.createParagraph();
|
XWPFParagraph parBreakDMP = document.createParagraph();
|
||||||
parBreakDMP.setPageBreak(true);
|
parBreakDMP.setPageBreak(true);
|
||||||
|
|
||||||
wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.TITLE, BigInteger.ZERO);
|
wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||||
dmpEntity.getDataset().stream().forEach(datasetEntity -> {
|
// Space below Datasets.
|
||||||
|
XWPFParagraph parBreakDatasets = document.createParagraph();
|
||||||
|
dmpEntity.getDataset().stream()
|
||||||
|
.filter(item -> item.getStatus() != Dataset.Status.CANCELED.getValue())
|
||||||
|
.filter(item -> item.getStatus() != Dataset.Status.DELETED.getValue())
|
||||||
|
.forEach(datasetEntity -> {
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
if (datasetEntity.getProperties() != null) {
|
if (datasetEntity.getProperties() != null) {
|
||||||
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
|
JSONObject jObject = new JSONObject(datasetEntity.getProperties());
|
||||||
properties = jobject.toMap();
|
properties = jObject.toMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom style for the Dataset title.
|
// Custom style for the Dataset title.
|
||||||
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||||
XWPFParagraph datasetLabelParagraph = document.createParagraph();
|
XWPFParagraph datasetLabelParagraph = document.createParagraph();
|
||||||
|
datasetLabelParagraph.setStyle("Heading2");
|
||||||
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
|
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
|
||||||
runDatasetTitle1.setText("Title: ");
|
runDatasetTitle1.setText("Title: ");
|
||||||
runDatasetTitle1.setBold(true);
|
runDatasetTitle1.setBold(true);
|
||||||
|
@ -235,6 +248,7 @@ public class DataManagementPlanManager {
|
||||||
runDatasetTitle.setFontSize(12);
|
runDatasetTitle.setFontSize(12);
|
||||||
|
|
||||||
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||||
|
datasetTemplateParagraph.setStyle("Heading3");
|
||||||
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||||
runDatasetTemplate1.setText("Template: ");
|
runDatasetTemplate1.setText("Template: ");
|
||||||
runDatasetTemplate1.setBold(true);
|
runDatasetTemplate1.setBold(true);
|
||||||
|
@ -245,8 +259,52 @@ public class DataManagementPlanManager {
|
||||||
runDatasetTemplate.setBold(true);
|
runDatasetTemplate.setBold(true);
|
||||||
runDatasetTemplate.setFontSize(12);
|
runDatasetTemplate.setFontSize(12);
|
||||||
|
|
||||||
|
XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
||||||
|
externalReferencesParagraph.setStyle("Heading3");
|
||||||
|
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
|
||||||
|
externalReferencesRun.setText("External References");
|
||||||
|
externalReferencesRun.setColor("2E75B6");
|
||||||
|
externalReferencesRun.setBold(true);
|
||||||
|
externalReferencesRun.setFontSize(12);
|
||||||
|
|
||||||
|
wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getDatasetDataRepositories().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getDatasetDataRepositories().stream().map(DatasetDataRepository::getDataRepository).map(DataRepository::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
wordBuilder.addParagraphContent("External Datasets", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getDatasetExternalDatasets().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getDatasetExternalDatasets().stream().map(DatasetExternalDataset::getExternalDataset).map(ExternalDataset::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
wordBuilder.addParagraphContent("Registries", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getRegistries().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getRegistries().stream().map(Registry::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
wordBuilder.addParagraphContent("Services", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getServices().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
/*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
|
||||||
|
// Dataset Description custom style.
|
||||||
|
XWPFParagraph datasetDescriptionParagraph = document.createParagraph();
|
||||||
|
datasetDescriptionParagraph.setStyle("Heading3");
|
||||||
|
XWPFRun datasetDescriptionRun = datasetDescriptionParagraph.createRun();
|
||||||
|
datasetDescriptionRun.setText("Dataset Description");
|
||||||
|
datasetDescriptionRun.setColor("2E75B6");
|
||||||
|
datasetDescriptionRun.setBold(true);
|
||||||
|
datasetDescriptionRun.setFontSize(12);
|
||||||
|
|
||||||
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
|
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
|
||||||
visibilityRuleService.setProperties(properties);
|
visibilityRuleService.setProperties(properties);
|
||||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||||
|
@ -258,6 +316,12 @@ public class DataManagementPlanManager {
|
||||||
// Page break at the end of the Dataset.
|
// Page break at the end of the Dataset.
|
||||||
XWPFParagraph parBreakDataset = document.createParagraph();
|
XWPFParagraph parBreakDataset = document.createParagraph();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Removes the top empty headings.
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
document.removeBodyElement(0);
|
||||||
|
}
|
||||||
|
|
||||||
String fileName = dmpEntity.getLabel();
|
String fileName = dmpEntity.getLabel();
|
||||||
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||||
File exportFile = new File(fileName + ".docx");
|
File exportFile = new File(fileName + ".docx");
|
||||||
|
@ -360,7 +424,8 @@ public class DataManagementPlanManager {
|
||||||
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws IllegalAccessException, InstantiationException {
|
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws IllegalAccessException, InstantiationException {
|
||||||
UUID principalID = principal.getId();
|
UUID principalID = principal.getId();
|
||||||
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlan.class));
|
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlan.class));
|
||||||
QueryableList<DMP> authenticatedItems = dmpsRepository.getAuthenticated(items, principalID);
|
List<Integer> roles = new LinkedList<>();
|
||||||
|
QueryableList<DMP> authenticatedItems = dmpsRepository.getAuthenticated(items, principalID, roles);
|
||||||
List<eu.eudat.models.data.dmp.DataManagementPlan> datamanagementPlans = authenticatedItems.select(item -> new DataManagementPlan().fromDataModel(item));
|
List<eu.eudat.models.data.dmp.DataManagementPlan> datamanagementPlans = authenticatedItems.select(item -> new DataManagementPlan().fromDataModel(item));
|
||||||
return datamanagementPlans;
|
return datamanagementPlans;
|
||||||
}
|
}
|
||||||
|
@ -429,7 +494,7 @@ public class DataManagementPlanManager {
|
||||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||||
|
|
||||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user);
|
||||||
createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
|
createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
|
||||||
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
|
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
|
||||||
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) {
|
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) {
|
||||||
|
@ -445,7 +510,7 @@ public class DataManagementPlanManager {
|
||||||
newDmp.setCreated(dmp.getCreated() == null ? new Date() : dmp.getCreated());
|
newDmp.setCreated(dmp.getCreated() == null ? new Date() : dmp.getCreated());
|
||||||
if (newDmp.getUsers()!= null && newDmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
|
if (newDmp.getUsers()!= null && newDmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
|
||||||
.collect(Collectors.toList()).size() == 0) {
|
.collect(Collectors.toList()).size() == 0) {
|
||||||
List<UserDMP> userDMPList = newDmp.getUsers().stream().collect(Collectors.toList());
|
List<UserDMP> userDMPList = new ArrayList<>(newDmp.getUsers());
|
||||||
for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) {
|
for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) {
|
||||||
for (UserDMP userDMP : userDMPList) {
|
for (UserDMP userDMP : userDMPList) {
|
||||||
if (!(userDMP.getUser().getId().equals(userInfoListingModel.getId()))) {
|
if (!(userDMP.getUser().getId().equals(userInfoListingModel.getId()))) {
|
||||||
|
@ -456,7 +521,9 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkIfUserCanEditGrant(newDmp, user);
|
checkIfUserCanEditGrant(newDmp, user);
|
||||||
checkIfGrandHasCreationUser(newDmp, user);
|
assignGrandUserIfInternal(newDmp, user);
|
||||||
|
assignFunderUserIfInternal(newDmp, user);
|
||||||
|
assignProjectUserIfInternal(newDmp, user);
|
||||||
|
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
|
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||||
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||||
|
@ -521,9 +588,9 @@ public class DataManagementPlanManager {
|
||||||
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
|
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
|
||||||
DMP newDmp = dataManagementPlan.toDataModel();
|
DMP newDmp = dataManagementPlan.toDataModel();
|
||||||
|
|
||||||
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
|
|
||||||
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao());
|
|
||||||
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||||
|
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
|
||||||
|
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
|
||||||
|
|
||||||
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
|
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
|
||||||
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
|
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
|
||||||
|
@ -537,7 +604,9 @@ public class DataManagementPlanManager {
|
||||||
newDmp.setId(null);
|
newDmp.setId(null);
|
||||||
|
|
||||||
checkIfUserCanEditGrant(newDmp, user);
|
checkIfUserCanEditGrant(newDmp, user);
|
||||||
checkIfGrandHasCreationUser(newDmp, user);
|
assignGrandUserIfInternal(newDmp, user);
|
||||||
|
assignFunderUserIfInternal(newDmp, user);
|
||||||
|
assignProjectUserIfInternal(newDmp, user);
|
||||||
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
|
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||||
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
|
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
|
||||||
|
|
||||||
|
@ -552,9 +621,10 @@ public class DataManagementPlanManager {
|
||||||
|
|
||||||
public void clone(DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
public void clone(DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||||
DMP newDmp = dataManagementPlan.toDataModel();
|
DMP newDmp = dataManagementPlan.toDataModel();
|
||||||
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
|
|
||||||
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao());
|
|
||||||
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||||
|
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
|
||||||
|
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
|
||||||
|
|
||||||
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
|
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
|
||||||
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
|
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
|
||||||
|
@ -568,7 +638,9 @@ public class DataManagementPlanManager {
|
||||||
newDmp.setId(null);
|
newDmp.setId(null);
|
||||||
|
|
||||||
checkIfUserCanEditGrant(newDmp, user);
|
checkIfUserCanEditGrant(newDmp, user);
|
||||||
checkIfGrandHasCreationUser(newDmp, user);
|
assignGrandUserIfInternal(newDmp, user);
|
||||||
|
assignFunderUserIfInternal(newDmp, user);
|
||||||
|
assignProjectUserIfInternal(newDmp, user);
|
||||||
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
|
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||||
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
|
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
|
||||||
|
|
||||||
|
@ -588,14 +660,17 @@ public class DataManagementPlanManager {
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
|
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) {
|
private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository, UserInfo user) {
|
||||||
if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) {
|
if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) {
|
||||||
for (eu.eudat.data.entities.Researcher researcher : newDmp.getResearchers()) {
|
for (eu.eudat.data.entities.Researcher researcher : newDmp.getResearchers()) {
|
||||||
ResearcherCriteria criteria = new ResearcherCriteria();
|
ResearcherCriteria criteria = new ResearcherCriteria();
|
||||||
criteria.setLike(researcher.getReference());
|
criteria.setLike(researcher.getReference());
|
||||||
List<eu.eudat.data.entities.Researcher> entries = researcherRepository.getWithCriteria(criteria).toList();
|
List<eu.eudat.data.entities.Researcher> entries = researcherRepository.getWithCriteria(criteria).toList();
|
||||||
if (entries != null && !entries.isEmpty()) researcher.setId(entries.get(0).getId());
|
if (entries != null && !entries.isEmpty()) researcher.setId(entries.get(0).getId());
|
||||||
else researcherRepository.createOrUpdate(researcher);
|
else {
|
||||||
|
researcher.setCreationUser(user);
|
||||||
|
researcherRepository.createOrUpdate(researcher);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -634,7 +709,6 @@ public class DataManagementPlanManager {
|
||||||
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).getSingleOrDefault();
|
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).getSingleOrDefault();
|
||||||
if (funderEntity != null) funder.setId(funderEntity.getId());
|
if (funderEntity != null) funder.setId(funderEntity.getId());
|
||||||
else {
|
else {
|
||||||
funder.setType(Funder.FunderType.EXTERNAL.getValue());
|
|
||||||
funderDao.createOrUpdate(funder);
|
funderDao.createOrUpdate(funder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -681,12 +755,24 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIfGrandHasCreationUser(DMP dmp, UserInfo user) {
|
private void assignGrandUserIfInternal(DMP dmp, UserInfo user) {
|
||||||
if (dmp.getGrant().getCreationUser() == null) {
|
if (dmp.getGrant().getCreationUser() == null && dmp.getGrant().getReference().startsWith("dmp:")) {
|
||||||
dmp.getGrant().setCreationUser(user);
|
dmp.getGrant().setCreationUser(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assignFunderUserIfInternal(DMP dmp, UserInfo user) {
|
||||||
|
if (dmp.getGrant().getFunder().getCreationUser() == null && dmp.getGrant().getFunder().getReference().startsWith("dmp:")) {
|
||||||
|
dmp.getGrant().getFunder().setCreationUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assignProjectUserIfInternal(DMP dmp, UserInfo user) {
|
||||||
|
if (dmp.getProject().getCreationUser() == null && dmp.getProject().getReference().startsWith("dmp:")) {
|
||||||
|
dmp.getProject().setCreationUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
|
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
|
||||||
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
|
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
|
||||||
for (Dataset dataset : newDmp.getDataset()) {
|
for (Dataset dataset : newDmp.getDataset()) {
|
||||||
|
@ -747,10 +833,12 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileEnvelope getXmlDocument(String id) throws InstantiationException, IllegalAccessException, IOException {
|
public FileEnvelope getXmlDocument(String id, Principal principal) throws InstantiationException, IllegalAccessException, IOException {
|
||||||
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
|
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
|
||||||
VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService();
|
VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService();
|
||||||
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||||
|
if (!dmp.isPublic() && dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||||
|
throw new UnauthorisedException();
|
||||||
List<Dataset> datasets = dmp.getDataset().stream().collect(Collectors.toList());
|
List<Dataset> datasets = dmp.getDataset().stream().collect(Collectors.toList());
|
||||||
String fileName = dmp.getLabel();
|
String fileName = dmp.getLabel();
|
||||||
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||||
|
@ -856,11 +944,11 @@ public class DataManagementPlanManager {
|
||||||
return fileEnvelope;
|
return fileEnvelope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseEntity<byte[]> getRDAJsonDocument(String id) throws IOException {
|
public ResponseEntity<byte[]> getRDAJsonDocument(String id, Principal principal) throws IOException {
|
||||||
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||||
DmpRDAExportModel dmpExport = new DmpRDAExportModel().fromDataModel(dmp);
|
if (!dmp.isPublic() && dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||||
RDAExportModel rdaExportModel = new RDAExportModel();
|
throw new UnauthorisedException();
|
||||||
rdaExportModel.setDmp(dmpExport);
|
RDAExportModel rdaExportModel = new RDAExportModel().fromDataModel(dmp);
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String fileName = dmp.getLabel();
|
String fileName = dmp.getLabel();
|
||||||
|
@ -886,20 +974,17 @@ public class DataManagementPlanManager {
|
||||||
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseEntity<byte[]> getDocument(String id, String contentType) throws InstantiationException, IllegalAccessException, IOException {
|
public ResponseEntity<byte[]> getDocument(String id, String contentType, Principal principal, ConfigLoader configLoader) throws InstantiationException, IllegalAccessException, IOException {
|
||||||
File file;
|
File file;
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case "application/xml":
|
case "application/xml":
|
||||||
file = getXmlDocument(id).getFile();
|
file = getXmlDocument(id, principal).getFile();
|
||||||
break;
|
break;
|
||||||
case "application/msword":
|
case "application/msword":
|
||||||
file = getWordDocument(id);
|
file = getWordDocument(id, principal, configLoader);
|
||||||
break;
|
break;
|
||||||
/*case "application/pdf":
|
|
||||||
file = getPdfDocument(id);
|
|
||||||
break;*/
|
|
||||||
default:
|
default:
|
||||||
file = getXmlDocument(id).getFile();
|
file = getXmlDocument(id, principal).getFile();
|
||||||
}
|
}
|
||||||
InputStream resource = new FileInputStream(file);
|
InputStream resource = new FileInputStream(file);
|
||||||
HttpHeaders responseHeaders = new HttpHeaders();
|
HttpHeaders responseHeaders = new HttpHeaders();
|
||||||
|
@ -932,8 +1017,8 @@ public class DataManagementPlanManager {
|
||||||
} catch (IOException | JAXBException ex) {
|
} catch (IOException | JAXBException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
// TODO Iterate through the list of dataManagmentPlans.
|
// TODO Iterate through the list of dataManagementPlans.
|
||||||
// Creates new dataManagmentPlan to fill it with the data model that was parsed from the xml.
|
// Creates new dataManagementPlan to fill it with the data model that was parsed from the xml.
|
||||||
// Creates properties.
|
// Creates properties.
|
||||||
DataManagementPlan dm = new DataManagementPlan();
|
DataManagementPlan dm = new DataManagementPlan();
|
||||||
DataManagementPlanProfile dmpProfile = new DataManagementPlanProfile();
|
DataManagementPlanProfile dmpProfile = new DataManagementPlanProfile();
|
||||||
|
@ -1064,7 +1149,7 @@ public class DataManagementPlanManager {
|
||||||
return (dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId()).equals(principal.getId());
|
return (dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId()).equals(principal.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createZenodoDoi(UUID id, Principal principal) throws Exception {
|
public String createZenodoDoi(UUID id, Principal principal, ConfigLoader configLoader) throws Exception {
|
||||||
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id);
|
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id);
|
||||||
if (!isUserOwnerOfDmp(dmp, principal))
|
if (!isUserOwnerOfDmp(dmp, principal))
|
||||||
throw new Exception("User is not authorized to invoke this action");
|
throw new Exception("User is not authorized to invoke this action");
|
||||||
|
@ -1098,7 +1183,7 @@ public class DataManagementPlanManager {
|
||||||
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
LinkedMultiValueMap<String, Object> addFileMap = new LinkedMultiValueMap<>();
|
LinkedMultiValueMap<String, Object> addFileMap = new LinkedMultiValueMap<>();
|
||||||
|
|
||||||
File file = getWordDocument(id.toString());
|
File file = getWordDocument(id.toString(), principal, configLoader);
|
||||||
addFileMap.add("filename", file.getName());
|
addFileMap.add("filename", file.getName());
|
||||||
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||||
addFileMap.add("file", fileSystemResource);
|
addFileMap.add("file", fileSystemResource);
|
||||||
|
|
|
@ -1,12 +1,23 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
|
||||||
import eu.eudat.data.entities.DataRepository;
|
import eu.eudat.data.entities.DataRepository;
|
||||||
import eu.eudat.data.entities.Researcher;
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.datarepository.DataRepositoryModel;
|
import eu.eudat.models.data.datarepository.DataRepositoryModel;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ikalyvas on 9/3/2018.
|
* Created by ikalyvas on 9/3/2018.
|
||||||
*/
|
*/
|
||||||
|
@ -19,8 +30,29 @@ public class DataRepositoryManager {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataRepository create(eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel) throws Exception {
|
public DataRepository create(eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception {
|
||||||
DataRepository dataRepository = dataRepositoryModel.toDataModel();
|
DataRepository dataRepository = dataRepositoryModel.toDataModel();
|
||||||
|
dataRepository.getCreationUser().setId(principal.getId());
|
||||||
return apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository);
|
return apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DataRepositoryModel> getDataRepositories(String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||||
|
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getRepositories(externalUrlCriteria, type);
|
||||||
|
|
||||||
|
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
||||||
|
if (!query.isEmpty()) criteria.setLike(query);
|
||||||
|
criteria.setCreationUserId(principal.getId());
|
||||||
|
|
||||||
|
List<DataRepositoryModel> dataRepositoryModels = new LinkedList<>();
|
||||||
|
if (type.equals("")) {
|
||||||
|
List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
|
||||||
|
dataRepositoryModels = dataRepositoryList.stream().map(item -> new DataRepositoryModel().fromDataModel(item)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
dataRepositoryModels.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, DataRepositoryModel.class)).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
return dataRepositoryModels;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import eu.eudat.elastic.criteria.DatasetCriteria;
|
||||||
import eu.eudat.elastic.repository.DatasetRepository;
|
import eu.eudat.elastic.repository.DatasetRepository;
|
||||||
import eu.eudat.logic.builders.BuilderFactory;
|
import eu.eudat.logic.builders.BuilderFactory;
|
||||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
@ -32,6 +33,8 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
@ -46,6 +49,8 @@ import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
|
import javax.persistence.criteria.Join;
|
||||||
|
import javax.persistence.criteria.JoinType;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
@ -141,6 +146,16 @@ public class DatasetManager {
|
||||||
} else
|
} else
|
||||||
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (principal.getId() != null && datasetTableRequest.getCriteria().getRole() != null) {
|
||||||
|
items.where((builder, root) -> {
|
||||||
|
Join userJoin = root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT);
|
||||||
|
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal.getId()), builder.equal(userJoin.get("role"), datasetTableRequest.getCriteria().getRole()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
String[] strings = new String[1];
|
||||||
|
strings[0] = "-dmp:publishedAt|join|";
|
||||||
|
datasetTableRequest.getOrderings().setFields(strings);
|
||||||
QueryableList<eu.eudat.data.entities.Dataset> pagedItems = PaginationManager.applyPaging(items, datasetTableRequest);
|
QueryableList<eu.eudat.data.entities.Dataset> pagedItems = PaginationManager.applyPaging(items, datasetTableRequest);
|
||||||
DataTableData<DatasetListingModel> dataTable = new DataTableData<>();
|
DataTableData<DatasetListingModel> dataTable = new DataTableData<>();
|
||||||
|
|
||||||
|
@ -223,8 +238,8 @@ public class DatasetManager {
|
||||||
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile());
|
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile());
|
||||||
datasetprofile.setStatus(dataset.getStatus());
|
datasetprofile.setStatus(dataset.getStatus());
|
||||||
if (datasetEntity.getProperties() != null) {
|
if (datasetEntity.getProperties() != null) {
|
||||||
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
|
JSONObject jObject = new JSONObject(datasetEntity.getProperties());
|
||||||
Map<String, Object> properties = jobject.toMap();
|
Map<String, Object> properties = jObject.toMap();
|
||||||
datasetprofile.fromJsonObject(properties);
|
datasetprofile.fromJsonObject(properties);
|
||||||
}
|
}
|
||||||
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
||||||
|
@ -232,25 +247,81 @@ public class DatasetManager {
|
||||||
return pagedDatasetProfile;
|
return pagedDatasetProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getWordDocument(Environment environment, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
|
public File getWordDocument(ConfigLoader configLoader, String id, VisibilityRuleService visibilityRuleService) throws IOException {
|
||||||
WordBuilder wordBuilder = new WordBuilder();
|
WordBuilder wordBuilder = new WordBuilder();
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||||
String fileUrl = environment.getProperty("configuration.h2020template");
|
XWPFDocument document = configLoader.getDocument();
|
||||||
InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
|
||||||
XWPFDocument document = new XWPFDocument(is);
|
|
||||||
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
||||||
wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO);
|
wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||||
|
|
||||||
|
// Space below Dataset title.
|
||||||
|
XWPFParagraph parBreakDataset = document.createParagraph();
|
||||||
|
|
||||||
|
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||||
|
datasetTemplateParagraph.setStyle("Heading2");
|
||||||
|
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||||
|
runDatasetTemplate1.setText("Template: ");
|
||||||
|
runDatasetTemplate1.setBold(true);
|
||||||
|
runDatasetTemplate1.setFontSize(12);
|
||||||
|
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||||
|
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
||||||
|
runDatasetTemplate.setColor("2E75B6");
|
||||||
|
runDatasetTemplate.setBold(true);
|
||||||
|
runDatasetTemplate.setFontSize(12);
|
||||||
|
|
||||||
|
XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
||||||
|
externalReferencesParagraph.setStyle("Heading2");
|
||||||
|
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
|
||||||
|
externalReferencesRun.setText("External References");
|
||||||
|
externalReferencesRun.setColor("2E75B6");
|
||||||
|
externalReferencesRun.setBold(true);
|
||||||
|
externalReferencesRun.setFontSize(12);
|
||||||
|
|
||||||
|
wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getDatasetDataRepositories().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getDatasetDataRepositories().stream().map(DatasetDataRepository::getDataRepository).map(DataRepository::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
wordBuilder.addParagraphContent("External Datasets", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getDatasetExternalDatasets().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getDatasetExternalDatasets().stream().map(DatasetExternalDataset::getExternalDataset).map(ExternalDataset::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
wordBuilder.addParagraphContent("Registries", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getRegistries().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getRegistries().stream().map(Registry::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
wordBuilder.addParagraphContent("Services", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.getServices().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||||
|
}
|
||||||
|
/*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||||
|
if (datasetEntity.().size() > 0) {
|
||||||
|
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||||
|
, document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||||
|
}*/
|
||||||
|
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
if (datasetEntity.getProperties() != null) {
|
if (datasetEntity.getProperties() != null) {
|
||||||
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
|
JSONObject jObject = new JSONObject(datasetEntity.getProperties());
|
||||||
properties = jobject.toMap();
|
properties = jObject.toMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||||
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
||||||
visibilityRuleService.setProperties(properties);
|
visibilityRuleService.setProperties(properties);
|
||||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||||
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
||||||
String label = datasetEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
|
String label = datasetEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||||
File exportFile = new File(label + ".docx");
|
File exportFile = new File(label + ".docx");
|
||||||
|
|
||||||
|
// Removes the top empty headings.
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
document.removeBodyElement(0);
|
||||||
|
}
|
||||||
|
|
||||||
FileOutputStream out = new FileOutputStream(exportFile);
|
FileOutputStream out = new FileOutputStream(exportFile);
|
||||||
document.write(out);
|
document.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
@ -335,10 +406,11 @@ public class DatasetManager {
|
||||||
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||||
dataset.setCreator(userInfo);
|
dataset.setCreator(userInfo);
|
||||||
|
|
||||||
createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), dataset);
|
|
||||||
createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), dataset);
|
createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), dataset);
|
||||||
createServicesIfTheyDontExist(dataset);
|
|
||||||
createExternalDatasetsIfTheyDontExist(dataset);
|
createExternalDatasetsIfTheyDontExist(dataset);
|
||||||
|
createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), dataset);
|
||||||
|
createServicesIfTheyDontExist(dataset);
|
||||||
|
|
||||||
Dataset dataset1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
|
Dataset dataset1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
|
||||||
datasetWizardModel.setId(dataset1.getId());
|
datasetWizardModel.setId(dataset1.getId());
|
||||||
updateTags(apiContext.getOperationsContext().getDatasetRepository(), datasetWizardModel);
|
updateTags(apiContext.getOperationsContext().getDatasetRepository(), datasetWizardModel);
|
||||||
|
@ -402,11 +474,8 @@ public class DatasetManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDataRepositoriesIfTheyDontExist(DataRepositoryDao dataRepositoryDao, eu.eudat.data.entities.Dataset dataset) {
|
private void createDataRepositoriesIfTheyDontExist(DataRepositoryDao dataRepositoryDao, eu.eudat.data.entities.Dataset dataset) {
|
||||||
Set<DatasetDataRepository> datasetDataRepositories = dataset.getDatasetDataRepositories();
|
if (dataset.getDatasetDataRepositories() != null && !dataset.getDatasetDataRepositories().isEmpty()) {
|
||||||
dataset.setDatasetDataRepositories(new HashSet<>());
|
for (eu.eudat.data.entities.DatasetDataRepository datasetDataRepository : dataset.getDatasetDataRepositories()) {
|
||||||
|
|
||||||
if (datasetDataRepositories != null && !datasetDataRepositories.isEmpty()) {
|
|
||||||
for (eu.eudat.data.entities.DatasetDataRepository datasetDataRepository : datasetDataRepositories) {
|
|
||||||
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
||||||
criteria.setLike(datasetDataRepository.getDataRepository().getReference());
|
criteria.setLike(datasetDataRepository.getDataRepository().getReference());
|
||||||
List<eu.eudat.data.entities.DataRepository> entries = dataRepositoryDao.getWithCriteria(criteria).toList();
|
List<eu.eudat.data.entities.DataRepository> entries = dataRepositoryDao.getWithCriteria(criteria).toList();
|
||||||
|
@ -415,8 +484,9 @@ public class DatasetManager {
|
||||||
datasetDataRepository.setDataset(dataset);
|
datasetDataRepository.setDataset(dataset);
|
||||||
dataset.getDatasetDataRepositories().add(datasetDataRepository);
|
dataset.getDatasetDataRepositories().add(datasetDataRepository);
|
||||||
} else {
|
} else {
|
||||||
//datasetDataRepository.getDataRepository().setId(UUID.randomUUID());
|
datasetDataRepository.getDataRepository().setId(UUID.randomUUID());
|
||||||
DataRepository dataRepository = dataRepositoryDao.createOrUpdate(datasetDataRepository.getDataRepository());
|
DataRepository dataRepository = dataRepositoryDao.createOrUpdate(datasetDataRepository.getDataRepository());
|
||||||
|
datasetDataRepository.setDataset(dataset);
|
||||||
datasetDataRepository.setDataRepository(dataRepository);
|
datasetDataRepository.setDataRepository(dataRepository);
|
||||||
dataset.getDatasetDataRepositories().add(datasetDataRepository);
|
dataset.getDatasetDataRepositories().add(datasetDataRepository);
|
||||||
}
|
}
|
||||||
|
@ -425,41 +495,35 @@ public class DatasetManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createServicesIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) {
|
private void createServicesIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) {
|
||||||
Set<DatasetService> services = dataset.getServices();
|
if (dataset.getServices() != null && !dataset.getServices().isEmpty()) {
|
||||||
dataset.setServices(new HashSet<>());
|
for (DatasetService service : dataset.getServices()) {
|
||||||
if (services != null && !services.isEmpty()) {
|
|
||||||
for (eu.eudat.data.entities.DatasetService datasetService : services) {
|
|
||||||
ServiceCriteria criteria = new ServiceCriteria();
|
ServiceCriteria criteria = new ServiceCriteria();
|
||||||
criteria.setLike(datasetService.getService().getLabel());
|
criteria.setLike(service.getService().getReference());
|
||||||
List<eu.eudat.data.entities.Service> entries = databaseRepository.getServiceDao().getWithCriteria(criteria).toList();
|
List<eu.eudat.data.entities.Service> entries = databaseRepository.getServiceDao().getWithCriteria(criteria).toList();
|
||||||
if (entries != null && !entries.isEmpty()) {
|
if (entries != null && !entries.isEmpty()) {
|
||||||
datasetService.getService().setId(entries.get(0).getId());
|
service.setDataset(dataset);
|
||||||
datasetService.setDataset(dataset);
|
service.getService().setCreated(new Date());
|
||||||
dataset.getServices().add(datasetService);
|
service.setService(service.getService());
|
||||||
} else {
|
this.databaseRepository.getServiceDao().createOrUpdate(service.getService());
|
||||||
datasetService.getService().setCreated(new Date());
|
dataset.getServices().add(service);
|
||||||
Service service = databaseRepository.getServiceDao().createOrUpdate(datasetService.getService());
|
|
||||||
datasetService.setService(service);
|
|
||||||
datasetService.setDataset(dataset);
|
|
||||||
dataset.getServices().add(datasetService);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createExternalDatasetsIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) {
|
private void createExternalDatasetsIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) {
|
||||||
Set<DatasetExternalDataset> externalDatasets = dataset.getDatasetExternalDatasets();
|
if (dataset.getDatasetExternalDatasets() != null && !dataset.getDatasetExternalDatasets().isEmpty()) {
|
||||||
dataset.setDatasetExternalDatasets(new HashSet<>());
|
for (eu.eudat.data.entities.DatasetExternalDataset datasetExternalDataset : dataset.getDatasetExternalDatasets()) {
|
||||||
if (externalDatasets != null && !externalDatasets.isEmpty()) {
|
|
||||||
for (eu.eudat.data.entities.DatasetExternalDataset datasetExternalDataset : externalDatasets) {
|
|
||||||
ExternalDatasetCriteria criteria = new ExternalDatasetCriteria();
|
ExternalDatasetCriteria criteria = new ExternalDatasetCriteria();
|
||||||
criteria.setLike(datasetExternalDataset.getExternalDataset().getLabel());
|
criteria.setLike(datasetExternalDataset.getExternalDataset().getReference());
|
||||||
List<eu.eudat.data.entities.ExternalDataset> entries = databaseRepository.getExternalDatasetDao().getWithCriteria(criteria).toList();
|
List<eu.eudat.data.entities.ExternalDataset> entries = databaseRepository.getExternalDatasetDao().getWithCriteria(criteria).toList();
|
||||||
if (entries != null && !entries.isEmpty()) {
|
if (entries != null && !entries.isEmpty()) {
|
||||||
datasetExternalDataset.getExternalDataset().setId(entries.get(0).getId());
|
datasetExternalDataset.getExternalDataset().setId(entries.get(0).getId());
|
||||||
datasetExternalDataset.setDataset(dataset);
|
datasetExternalDataset.setDataset(dataset);
|
||||||
dataset.getDatasetExternalDatasets().add(datasetExternalDataset);
|
dataset.getDatasetExternalDatasets().add(datasetExternalDataset);
|
||||||
} else {
|
} else {
|
||||||
|
datasetExternalDataset.getExternalDataset().setId(UUID.randomUUID());
|
||||||
|
datasetExternalDataset.setDataset(dataset);
|
||||||
ExternalDataset externalDataset = databaseRepository.getExternalDatasetDao().createOrUpdate(datasetExternalDataset.getExternalDataset());
|
ExternalDataset externalDataset = databaseRepository.getExternalDatasetDao().createOrUpdate(datasetExternalDataset.getExternalDataset());
|
||||||
datasetExternalDataset.setExternalDataset(externalDataset);
|
datasetExternalDataset.setExternalDataset(externalDataset);
|
||||||
dataset.getDatasetExternalDatasets().add(datasetExternalDataset);
|
dataset.getDatasetExternalDatasets().add(datasetExternalDataset);
|
||||||
|
|
|
@ -19,10 +19,9 @@ import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem;
|
||||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||||
import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field;
|
import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field;
|
||||||
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
|
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
|
||||||
import eu.eudat.models.data.helpermodels.Tuple;
|
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.security.Principal;
|
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -45,6 +44,7 @@ public class DatasetProfileManager {
|
||||||
|
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
private DatabaseRepository databaseRepository;
|
private DatabaseRepository databaseRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DatasetProfileManager(ApiContext apiContext) {
|
public DatasetProfileManager(ApiContext apiContext) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
|
@ -81,9 +81,8 @@ public class DatasetProfileManager {
|
||||||
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
|
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DatasetProfileListingModel> getAll() throws IllegalAccessException, InstantiationException {
|
public List<DatasetProfileListingModel> getAll(DatasetProfileTableRequestItem tableRequestItem) throws IllegalAccessException, InstantiationException {
|
||||||
DatasetProfileCriteria criteria = new DatasetProfileCriteria();
|
QueryableList<DatasetProfile> items = databaseRepository.getDatasetProfileDao().getWithCriteria(tableRequestItem.getCriteria());
|
||||||
QueryableList<DatasetProfile> items = databaseRepository.getDatasetProfileDao().getWithCriteria(criteria);
|
|
||||||
List<DatasetProfileListingModel> datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item));
|
List<DatasetProfileListingModel> datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item));
|
||||||
return datasetProfiles;
|
return datasetProfiles;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.dao.entities.DatasetDao;
|
import eu.eudat.data.dao.entities.DatasetDao;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||||
|
@ -12,7 +13,6 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
|
@ -39,17 +39,18 @@ public class DocumentManager {
|
||||||
|
|
||||||
private ApiContext context;
|
private ApiContext context;
|
||||||
private DatasetManager datasetManager;
|
private DatasetManager datasetManager;
|
||||||
public DocumentManager(ApiContext context, DatasetManager datasetManager) {
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
|
public DocumentManager(ApiContext context, DatasetManager datasetManager, ConfigLoader configLoader) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.datasetManager = datasetManager;
|
this.datasetManager = datasetManager;
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getWordDocument(Environment environment, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
|
public File getWordDocument(ConfigLoader configLoader, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
|
||||||
WordBuilder wordBuilder = new WordBuilder();
|
WordBuilder wordBuilder = new WordBuilder();
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||||
String fileUrl = environment.getProperty("configuration.h2020template");
|
XWPFDocument document = configLoader.getDocument();
|
||||||
InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
|
||||||
XWPFDocument document = new XWPFDocument(is);
|
|
||||||
eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
if (datasetEntity.getProperties() != null) {
|
if (datasetEntity.getProperties() != null) {
|
||||||
|
|
|
@ -1,50 +1,90 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
|
import eu.eudat.data.entities.Credential;
|
||||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
import eu.eudat.data.entities.LoginConfirmationEmail;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
|
import eu.eudat.data.entities.UserToken;
|
||||||
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||||
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
import eu.eudat.queryable.jpa.predicates.OrderByPredicate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class EmailConfirmationManager {
|
public class EmailConfirmationManager {
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
|
private DatabaseRepository databaseRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public EmailConfirmationManager(ApiContext apiContext) {
|
public EmailConfirmationManager(ApiContext apiContext) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
|
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
|
||||||
LoginConfirmationEmail loginConfirmationEmail = apiContext.getOperationsContext()
|
LoginConfirmationEmail loginConfirmationEmail = apiContext.getOperationsContext()
|
||||||
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
||||||
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
||||||
|
|
||||||
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
|
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
|
||||||
throw new TokenExpiredException("Token has expired.");
|
throw new TokenExpiredException("Token has expired.");
|
||||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable()
|
|
||||||
|
UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
|
||||||
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
||||||
|
|
||||||
if (user.getEmail() != null)
|
if (user.getEmail() != null)
|
||||||
throw new HasConfirmedEmailException("User already has confirmed his Email.");
|
throw new HasConfirmedEmailException("User already has confirmed his Email.");
|
||||||
|
|
||||||
loginConfirmationEmail.setIsConfirmed(true);
|
loginConfirmationEmail.setIsConfirmed(true);
|
||||||
|
|
||||||
|
// Checks if mail is used by another user. If it is, merges the new the old.
|
||||||
|
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
||||||
|
if (oldUser != null) {
|
||||||
|
mergeNewUserToOld(user, oldUser);
|
||||||
|
expireUserToken(user);
|
||||||
|
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
user.setEmail(loginConfirmationEmail.getEmail());
|
user.setEmail(loginConfirmationEmail.getEmail());
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(user);
|
databaseRepository.getUserInfoDao().createOrUpdate(user);
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendConfirmationEmail(String email, Principal principal) throws HasConfirmedEmailException {
|
public void sendConfirmationEmail(String email, Principal principal) throws HasConfirmedEmailException {
|
||||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||||
if (user.getEmail() != null)
|
if (user.getEmail() != null)
|
||||||
throw new HasConfirmedEmailException("User already has confirmed his Email.");
|
throw new HasConfirmedEmailException("User already has confirmed his Email.");
|
||||||
|
|
||||||
apiContext.getUtilitiesService().getConfirmationEmailService().createConfirmationEmail(
|
apiContext.getUtilitiesService().getConfirmationEmailService().createConfirmationEmail(
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getLoginConfirmationEmailDao(),
|
databaseRepository.getLoginConfirmationEmailDao(),
|
||||||
apiContext.getUtilitiesService().getMailService(),
|
apiContext.getUtilitiesService().getMailService(),
|
||||||
email,
|
email,
|
||||||
principal.getId());
|
principal.getId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser) {
|
||||||
|
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), newUser)).getSingle();
|
||||||
|
credential.setUserInfo(oldUser);
|
||||||
|
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expireUserToken(UserInfo user) {
|
||||||
|
UserToken userToken = databaseRepository.getUserTokenDao().asQueryable()
|
||||||
|
.where((builder, root) -> builder.equal(root.get("user"), user))
|
||||||
|
.orderBy((builder, root) -> builder.desc(root.get("issuedAt")))
|
||||||
|
.take(1)
|
||||||
|
.getSingle();
|
||||||
|
userToken.setExpiresAt(new Date());
|
||||||
|
databaseRepository.getUserTokenDao().createOrUpdate(userToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,33 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.logic.builders.model.criteria.ExternalDatasetCriteriaBuilder;
|
import eu.eudat.logic.builders.model.criteria.ExternalDatasetCriteriaBuilder;
|
||||||
import eu.eudat.logic.builders.model.models.DataTableDataBuilder;
|
import eu.eudat.logic.builders.model.models.DataTableDataBuilder;
|
||||||
import eu.eudat.data.dao.entities.ExternalDatasetDao;
|
|
||||||
import eu.eudat.data.entities.ExternalDataset;
|
import eu.eudat.data.entities.ExternalDataset;
|
||||||
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
|
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
import eu.eudat.models.data.external.ExternalDatasetSourcesModel;
|
||||||
|
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||||
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
|
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
|
||||||
import eu.eudat.data.query.items.table.externaldataset.ExternalDatasetTableRequest;
|
import eu.eudat.data.query.items.table.externaldataset.ExternalDatasetTableRequest;
|
||||||
|
import eu.eudat.models.data.externaldataset.ExternalDatasetModel;
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ExternalDatasetManager {
|
public class ExternalDatasetManager {
|
||||||
|
@ -40,10 +49,26 @@ public class ExternalDatasetManager {
|
||||||
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build();
|
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExternalDatasetListingModel> getWithExternal(String query) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException {
|
public List<ExternalDatasetListingModel> getWithExternal(String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
|
// Fetch the local saved external Datasets that belong to the user.
|
||||||
ExternalDatasetCriteria criteria = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
|
ExternalDatasetCriteria criteria = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
|
||||||
|
criteria.setCreationUserId(principal.getId());
|
||||||
QueryableList<eu.eudat.data.entities.ExternalDataset> items = apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
|
QueryableList<eu.eudat.data.entities.ExternalDataset> items = apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
|
||||||
|
|
||||||
|
// Fetch external Datasets from external sources.
|
||||||
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||||
|
List<Map<String, String>> remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type);
|
||||||
|
|
||||||
|
// Parse items from external sources to listing models.
|
||||||
|
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
List<ExternalDatasetListingModel> externalDatasetModels = remoteRepos.stream()
|
||||||
|
.map(item -> mapper.convertValue(item, ExternalDatasetListingModel.class))
|
||||||
|
.collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
|
||||||
|
// Merge fetched and local.
|
||||||
List<ExternalDatasetListingModel> externalDatasets = items.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
|
List<ExternalDatasetListingModel> externalDatasets = items.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
|
||||||
|
externalDatasets.addAll(externalDatasetModels);
|
||||||
|
|
||||||
return externalDatasets;
|
return externalDatasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +79,9 @@ public class ExternalDatasetManager {
|
||||||
return externalDatasetModel;
|
return externalDatasetModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExternalDataset create(eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel) throws Exception {
|
public ExternalDataset create(eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception {
|
||||||
ExternalDataset externalDataset = externalDatasetModel.toDataModel();
|
ExternalDataset externalDataset = externalDatasetModel.toDataModel();
|
||||||
|
externalDataset.getCreationUser().setId(principal.getId());
|
||||||
return apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().createOrUpdate(externalDataset);
|
return apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().createOrUpdate(externalDataset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@ package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
|
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
|
||||||
import eu.eudat.logic.builders.model.models.FunderBuilder;
|
import eu.eudat.logic.builders.model.models.FunderBuilder;
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||||
import eu.eudat.models.data.external.FundersExternalSourcesModel;
|
import eu.eudat.models.data.external.FundersExternalSourcesModel;
|
||||||
import eu.eudat.models.data.funder.Funder;
|
import eu.eudat.models.data.funder.Funder;
|
||||||
|
@ -16,16 +18,19 @@ import org.springframework.stereotype.Component;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class FunderManager {
|
public class FunderManager {
|
||||||
|
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
private RemoteFetcher remoteFetcher;
|
private RemoteFetcher remoteFetcher;
|
||||||
|
private ListHelper listHelper;
|
||||||
|
|
||||||
public FunderManager(ApiContext apiContext, RemoteFetcher remoteFetcher) {
|
public FunderManager(ApiContext apiContext, RemoteFetcher remoteFetcher, ListHelper listHelper) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.remoteFetcher = remoteFetcher;
|
this.remoteFetcher = remoteFetcher;
|
||||||
|
this.listHelper = listHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Funder> getCriteriaWithExternal(FunderCriteriaRequest funderCriteria, Principal principal) throws HugeResultSet, NoURLFound {
|
public List<Funder> getCriteriaWithExternal(FunderCriteriaRequest funderCriteria, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
|
@ -33,20 +38,26 @@ public class FunderManager {
|
||||||
userInfo.setId(principal.getId());
|
userInfo.setId(principal.getId());
|
||||||
funderCriteria.getCriteria().setReference("dmp:");
|
funderCriteria.getCriteria().setReference("dmp:");
|
||||||
QueryableList<eu.eudat.data.entities.Funder> items = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria.getCriteria());
|
QueryableList<eu.eudat.data.entities.Funder> items = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria.getCriteria());
|
||||||
//QueryableList<eu.eudat.data.entities.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);
|
QueryableList<eu.eudat.data.entities.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);
|
||||||
List<Funder> funders = items.select(item -> new eu.eudat.models.data.funder.Funder().fromDataModel(item));
|
List<Funder> funders = authItems.select(item -> new eu.eudat.models.data.funder.Funder().fromDataModel(item));
|
||||||
List<Map<String, String>> remoteRepos = remoteFetcher.getFunders(funderCriteria.getCriteria().getLike());
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(funderCriteria.getCriteria().getLike());
|
||||||
|
List<Map<String, String>> remoteRepos = remoteFetcher.getFunders(externalUrlCriteria);
|
||||||
FundersExternalSourcesModel fundersExternalSourcesModel = new FundersExternalSourcesModel().fromExternalItem(remoteRepos);
|
FundersExternalSourcesModel fundersExternalSourcesModel = new FundersExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
for (ExternalSourcesItemModel externalListingItem : fundersExternalSourcesModel) {
|
for (ExternalSourcesItemModel externalListingItem : fundersExternalSourcesModel) {
|
||||||
eu.eudat.models.data.funder.Funder funder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(FunderBuilder.class)
|
eu.eudat.models.data.funder.Funder funder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(FunderBuilder.class)
|
||||||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||||
.status(eu.eudat.data.entities.Funder.Status.fromInteger(0))
|
.status(eu.eudat.data.entities.Funder.Status.fromInteger(0))
|
||||||
.source(externalListingItem.getTag())
|
|
||||||
.build();
|
.build();
|
||||||
|
if (externalListingItem.getSource() != null) {
|
||||||
|
funder.setSource(externalListingItem.getSource());
|
||||||
|
} else {
|
||||||
|
funder.setSource(externalListingItem.getTag());
|
||||||
|
}
|
||||||
|
|
||||||
funders.add(funder);
|
funders.add(funder);
|
||||||
}
|
}
|
||||||
funders.sort(Comparator.comparing(Funder::getLabel));
|
funders.sort(Comparator.comparing(Funder::getLabel));
|
||||||
|
funders = funders.stream().filter(listHelper.distinctByKey(Funder::getLabel)).collect(Collectors.toList());
|
||||||
return funders;
|
return funders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,14 @@ import eu.eudat.data.dao.criteria.FunderCriteria;
|
||||||
import eu.eudat.data.entities.Funder;
|
import eu.eudat.data.entities.Funder;
|
||||||
import eu.eudat.data.query.items.table.grant.GrantTableRequest;
|
import eu.eudat.data.query.items.table.grant.GrantTableRequest;
|
||||||
import eu.eudat.exceptions.grant.GrantWithDMPsDeleteException;
|
import eu.eudat.exceptions.grant.GrantWithDMPsDeleteException;
|
||||||
import eu.eudat.logic.builders.entity.ContentBuilder;
|
|
||||||
import eu.eudat.logic.builders.model.models.GrantBuilder;
|
import eu.eudat.logic.builders.model.models.GrantBuilder;
|
||||||
import eu.eudat.data.dao.entities.GrantDao;
|
import eu.eudat.data.dao.entities.GrantDao;
|
||||||
import eu.eudat.data.entities.Content;
|
|
||||||
import eu.eudat.data.entities.DMP;
|
import eu.eudat.data.entities.DMP;
|
||||||
import eu.eudat.exceptions.files.TempFileNotFoundException;
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||||
import eu.eudat.models.data.external.GrantsExternalSourcesModel;
|
import eu.eudat.models.data.external.GrantsExternalSourcesModel;
|
||||||
import eu.eudat.models.data.files.ContentFile;
|
|
||||||
import eu.eudat.models.data.grant.Grant;
|
import eu.eudat.models.data.grant.Grant;
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.data.query.items.item.grant.GrantCriteriaRequest;
|
import eu.eudat.data.query.items.item.grant.GrantCriteriaRequest;
|
||||||
|
@ -27,13 +25,12 @@ import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.helpers.FileStorageService;
|
import eu.eudat.logic.services.helpers.FileStorageService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
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;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class GrantManager {
|
public class GrantManager {
|
||||||
|
@ -42,12 +39,14 @@ public class GrantManager {
|
||||||
private DatabaseRepository databaseRepository;
|
private DatabaseRepository databaseRepository;
|
||||||
private FileStorageService fileStorageService;
|
private FileStorageService fileStorageService;
|
||||||
private RemoteFetcher remoteFetcher;
|
private RemoteFetcher remoteFetcher;
|
||||||
|
private ListHelper listHelper;
|
||||||
|
|
||||||
public GrantManager(ApiContext apiContext) {
|
public GrantManager(ApiContext apiContext, ListHelper listHelper) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
this.fileStorageService = apiContext.getOperationsContext().getFileStorageService();
|
this.fileStorageService = apiContext.getOperationsContext().getFileStorageService();
|
||||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||||
|
this.listHelper = listHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTableData<eu.eudat.models.data.grant.GrantListingModel> getPaged(GrantTableRequest grantTableRequest, Principal principal, String fieldsGroup) throws Exception {
|
public DataTableData<eu.eudat.models.data.grant.GrantListingModel> getPaged(GrantTableRequest grantTableRequest, Principal principal, String fieldsGroup) throws Exception {
|
||||||
|
@ -99,15 +98,15 @@ public class GrantManager {
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public eu.eudat.data.entities.Grant inactivate(String id) throws InstantiationException, IllegalAccessException {
|
/*public eu.eudat.data.entities.Grant inactivate(String id) throws InstantiationException, IllegalAccessException {
|
||||||
GrantDao grantRepository = databaseRepository.getGrantDao();
|
GrantDao grantRepository = databaseRepository.getGrantDao();
|
||||||
eu.eudat.data.entities.Grant grant = grantRepository.find(UUID.fromString(id));
|
eu.eudat.data.entities.Grant grant = grantRepository.find(UUID.fromString(id));
|
||||||
grant.setStatus(eu.eudat.data.entities.Grant.Status.DELETED.getValue());
|
grant.setStatus(eu.eudat.data.entities.Grant.Status.DELETED.getValue());
|
||||||
grant = grantRepository.createOrUpdate(grant);
|
grant = grantRepository.createOrUpdate(grant);
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public List<eu.eudat.models.data.grant.Grant> getCriteriaWithExternal(GrantCriteriaRequest grantCriteria, Principal principal) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
|
public List<eu.eudat.models.data.grant.Grant> getCriteriaWithExternal(GrantCriteriaRequest grantCriteria, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo();
|
eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo();
|
||||||
userInfo.setId(principal.getId());
|
userInfo.setId(principal.getId());
|
||||||
if (grantCriteria.getCriteria().getFunderReference() != null && !grantCriteria.getCriteria().getFunderReference().trim().isEmpty()) {
|
if (grantCriteria.getCriteria().getFunderReference() != null && !grantCriteria.getCriteria().getFunderReference().trim().isEmpty()) {
|
||||||
|
@ -122,7 +121,11 @@ public class GrantManager {
|
||||||
QueryableList<eu.eudat.data.entities.Grant> items = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(grantCriteria.getCriteria());
|
QueryableList<eu.eudat.data.entities.Grant> items = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(grantCriteria.getCriteria());
|
||||||
QueryableList<eu.eudat.data.entities.Grant> authItems = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getAuthenticated(items, userInfo);
|
QueryableList<eu.eudat.data.entities.Grant> authItems = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getAuthenticated(items, userInfo);
|
||||||
List<eu.eudat.models.data.grant.Grant> grants = authItems.select(item -> new Grant().fromDataModel(item));
|
List<eu.eudat.models.data.grant.Grant> grants = authItems.select(item -> new Grant().fromDataModel(item));
|
||||||
List<Map<String, String>> remoteRepos = remoteFetcher.getGrants(grantCriteria.getCriteria().getLike());
|
|
||||||
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(grantCriteria.getCriteria().getLike());
|
||||||
|
if (grantCriteria.getCriteria().getFunderReference() != null) externalUrlCriteria.setFunderId(grantCriteria.getCriteria().getFunderReference());
|
||||||
|
List<Map<String, String>> remoteRepos = remoteFetcher.getGrants(externalUrlCriteria);
|
||||||
|
|
||||||
GrantsExternalSourcesModel grantsExternalSourcesModel = new GrantsExternalSourcesModel().fromExternalItem(remoteRepos);
|
GrantsExternalSourcesModel grantsExternalSourcesModel = new GrantsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
for (ExternalSourcesItemModel externalListingItem : grantsExternalSourcesModel) {
|
for (ExternalSourcesItemModel externalListingItem : grantsExternalSourcesModel) {
|
||||||
eu.eudat.models.data.grant.Grant grant = apiContext.getOperationsContext().getBuilderFactory().getBuilder(GrantBuilder.class)
|
eu.eudat.models.data.grant.Grant grant = apiContext.getOperationsContext().getBuilderFactory().getBuilder(GrantBuilder.class)
|
||||||
|
@ -135,6 +138,7 @@ public class GrantManager {
|
||||||
grants.add(grant);
|
grants.add(grant);
|
||||||
}
|
}
|
||||||
grants.sort(Comparator.comparing(Grant::getLabel));
|
grants.sort(Comparator.comparing(Grant::getLabel));
|
||||||
|
grants = grants.stream().filter(listHelper.distinctByKey(Grant::getLabel)).collect(Collectors.toList());
|
||||||
return grants;
|
return grants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +150,7 @@ public class GrantManager {
|
||||||
return grants;
|
return grants;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createOrUpdate(eu.eudat.models.data.grant.Grant grant, Principal principal) throws ParseException, IOException {
|
/*public void createOrUpdate(eu.eudat.models.data.grant.Grant grant, Principal principal) throws ParseException, IOException {
|
||||||
eu.eudat.data.entities.Grant grantEntity = grant.toDataModel();
|
eu.eudat.data.entities.Grant grantEntity = grant.toDataModel();
|
||||||
if (grant.getFiles() != null) {
|
if (grant.getFiles() != null) {
|
||||||
for (ContentFile file : grant.getFiles()) {
|
for (ContentFile file : grant.getFiles()) {
|
||||||
|
@ -167,7 +171,7 @@ public class GrantManager {
|
||||||
grantEntity.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue());
|
grantEntity.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue());
|
||||||
grantEntity.setCreationUser(databaseRepository.getUserInfoDao().find(principal.getId()));
|
grantEntity.setCreationUser(databaseRepository.getUserInfoDao().find(principal.getId()));
|
||||||
databaseRepository.getGrantDao().createOrUpdate(grantEntity);
|
databaseRepository.getGrantDao().createOrUpdate(grantEntity);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void delete(UUID uuid) {
|
public void delete(UUID uuid) {
|
||||||
eu.eudat.data.entities.Grant oldGrant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(uuid);
|
eu.eudat.data.entities.Grant oldGrant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(uuid);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
|
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||||
import eu.eudat.models.data.external.ProjectsExternalSourcesModel;
|
import eu.eudat.models.data.external.ProjectsExternalSourcesModel;
|
||||||
import eu.eudat.models.data.project.Project;
|
import eu.eudat.models.data.project.Project;
|
||||||
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
|
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
|
||||||
|
@ -16,16 +18,19 @@ import org.springframework.stereotype.Component;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ProjectManager {
|
public class ProjectManager {
|
||||||
|
|
||||||
private ApiContext apiContext;
|
private ApiContext apiContext;
|
||||||
private RemoteFetcher remoteFetcher;
|
private RemoteFetcher remoteFetcher;
|
||||||
|
private ListHelper listHelper;
|
||||||
|
|
||||||
public ProjectManager(ApiContext apiContext) {
|
public ProjectManager(ApiContext apiContext, ListHelper listHelper) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||||
|
this.listHelper = listHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Project> getCriteriaWithExternal(ProjectCriteriaRequest projectCriteria, Principal principal) throws HugeResultSet, NoURLFound {
|
public List<Project> getCriteriaWithExternal(ProjectCriteriaRequest projectCriteria, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
|
@ -35,7 +40,8 @@ public class ProjectManager {
|
||||||
QueryableList<eu.eudat.data.entities.Project> items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(projectCriteria.getCriteria());
|
QueryableList<eu.eudat.data.entities.Project> items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(projectCriteria.getCriteria());
|
||||||
QueryableList<eu.eudat.data.entities.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo);
|
QueryableList<eu.eudat.data.entities.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo);
|
||||||
List<Project> projects = authItems.select(item -> new Project().fromDataModel(item));
|
List<Project> projects = authItems.select(item -> new Project().fromDataModel(item));
|
||||||
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(projectCriteria.getCriteria().getLike());
|
||||||
|
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(externalUrlCriteria);
|
||||||
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
|
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
|
||||||
eu.eudat.models.data.project.Project project = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ProjectBuilder.class)
|
eu.eudat.models.data.project.Project project = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ProjectBuilder.class)
|
||||||
|
@ -48,6 +54,7 @@ public class ProjectManager {
|
||||||
projects.add(project);
|
projects.add(project);
|
||||||
}
|
}
|
||||||
projects.sort(Comparator.comparing(Project::getLabel));
|
projects.sort(Comparator.comparing(Project::getLabel));
|
||||||
|
projects = projects.stream().filter(listHelper.distinctByKey(Project::getLabel)).collect(Collectors.toList());
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.DataRepository;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import eu.eudat.data.dao.criteria.RegistryCriteria;
|
||||||
import eu.eudat.data.entities.Registry;
|
import eu.eudat.data.entities.Registry;
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.datarepository.DataRepositoryModel;
|
|
||||||
import eu.eudat.models.data.registries.RegistryModel;
|
import eu.eudat.models.data.registries.RegistryModel;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class RegistryManager {
|
public class RegistryManager {
|
||||||
|
|
||||||
|
@ -18,8 +28,30 @@ public class RegistryManager {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Registry create(RegistryModel registryModel) throws Exception {
|
public Registry create(RegistryModel registryModel, Principal principal) throws Exception {
|
||||||
|
if (registryModel.getLabel() == null || registryModel.getAbbreviation() == null || registryModel.getUri() == null) {
|
||||||
|
throw new Exception("Missing mandatory entity.");
|
||||||
|
}
|
||||||
Registry registry = registryModel.toDataModel();
|
Registry registry = registryModel.toDataModel();
|
||||||
|
registry.getCreationUser().setId(principal.getId());
|
||||||
return apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry);
|
return apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RegistryModel> getRegistries(String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||||
|
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getRegistries(externalUrlCriteria, type);
|
||||||
|
|
||||||
|
RegistryCriteria criteria = new RegistryCriteria();
|
||||||
|
if (!query.isEmpty()) criteria.setLike(query);
|
||||||
|
criteria.setCreationUserId(principal.getId());
|
||||||
|
List<RegistryModel> registryModels = new LinkedList<>();
|
||||||
|
if (type.equals("")) {
|
||||||
|
List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
|
||||||
|
registryModels = registryList.stream().map(item -> new RegistryModel().fromDataModel(item)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
registryModels.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, RegistryModel.class)).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
return registryModels;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,14 @@ package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.logic.builders.model.models.ResearcherBuilder;
|
import eu.eudat.logic.builders.model.models.ResearcherBuilder;
|
||||||
import eu.eudat.data.entities.Researcher;
|
import eu.eudat.data.entities.Researcher;
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||||
import eu.eudat.models.data.external.ResearchersExternalSourcesModel;
|
import eu.eudat.models.data.external.ResearchersExternalSourcesModel;
|
||||||
import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest;
|
import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -15,6 +17,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,16 +35,19 @@ public class ResearcherManager {
|
||||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Researcher create(eu.eudat.models.data.researcher.Researcher researcher) throws Exception {
|
public Researcher create(eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
|
||||||
Researcher researcherEntity = researcher.toDataModel();
|
Researcher researcherEntity = researcher.toDataModel();
|
||||||
|
researcherEntity.setCreationUser(apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()));
|
||||||
return apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().createOrUpdate(researcherEntity);
|
return apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().createOrUpdate(researcherEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<eu.eudat.models.data.dmp.Researcher> getCriteriaWithExternal(ResearcherCriteriaRequest researcherCriteriaRequest) throws HugeResultSet, NoURLFound {
|
public List<eu.eudat.models.data.dmp.Researcher> getCriteriaWithExternal(ResearcherCriteriaRequest researcherCriteriaRequest, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
|
|
||||||
QueryableList<eu.eudat.data.entities.Researcher> items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria());
|
QueryableList<eu.eudat.data.entities.Researcher> items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria());
|
||||||
|
items.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId()));
|
||||||
List<eu.eudat.models.data.dmp.Researcher> researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item));
|
List<eu.eudat.models.data.dmp.Researcher> researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item));
|
||||||
List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(researcherCriteriaRequest.getCriteria().getName(),null);
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(researcherCriteriaRequest.getCriteria().getName());
|
||||||
|
List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(externalUrlCriteria,null);
|
||||||
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
|
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
for (ExternalSourcesItemModel externalListingItem : researchersExternalSourcesModel) {
|
for (ExternalSourcesItemModel externalListingItem : researchersExternalSourcesModel) {
|
||||||
eu.eudat.models.data.dmp.Researcher researcher = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ResearcherBuilder.class)
|
eu.eudat.models.data.dmp.Researcher researcher = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ResearcherBuilder.class)
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.Registry;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import eu.eudat.data.dao.criteria.ServiceCriteria;
|
||||||
import eu.eudat.data.entities.Service;
|
import eu.eudat.data.entities.Service;
|
||||||
|
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||||
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.models.data.registries.RegistryModel;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.models.data.services.ServiceModel;
|
import eu.eudat.models.data.services.ServiceModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
import java.util.LinkedList;
|
||||||
* Created by ikalyvas on 9/3/2018.
|
import java.util.List;
|
||||||
*/
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ServiceManager {
|
public class ServiceManager {
|
||||||
|
|
||||||
|
@ -21,8 +28,27 @@ public class ServiceManager {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Service create(ServiceModel serviceModel) throws Exception {
|
public Service create(ServiceModel serviceModel, Principal principal) throws Exception {
|
||||||
Service service = serviceModel.toDataModel();
|
Service service = serviceModel.toDataModel();
|
||||||
|
service.getCreationUser().setId(principal.getId());
|
||||||
return apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service);
|
return apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ServiceModel> getServices(String query, String type, Principal principal) throws HugeResultSet, NoURLFound {
|
||||||
|
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||||
|
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().getServices(externalUrlCriteria, type);
|
||||||
|
|
||||||
|
ServiceCriteria criteria = new ServiceCriteria();
|
||||||
|
if (!query.isEmpty()) criteria.setLike(query);
|
||||||
|
criteria.setCreationUserId(principal.getId());
|
||||||
|
List<ServiceModel> serviceModels = new LinkedList<>();
|
||||||
|
if (type.equals("")) {
|
||||||
|
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
|
||||||
|
serviceModels = serviceList.stream().map(item -> new ServiceModel().fromDataModel(item)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
serviceModels.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ServiceModel.class)).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
return serviceModels;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,7 @@ import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -66,7 +63,8 @@ public class UserManager {
|
||||||
public UserProfile getSingle(UUID userId) throws Exception {
|
public UserProfile getSingle(UUID userId) throws Exception {
|
||||||
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
||||||
UserProfile profile = new UserProfile().fromDataModel(user);
|
UserProfile profile = new UserProfile().fromDataModel(user);
|
||||||
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable(), userId).take(5).toList();
|
List<Integer> roles = new LinkedList<>();
|
||||||
|
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable(), userId, roles).take(5).toList();
|
||||||
profile.setAssociatedDmps(dmps.stream().map(x -> new DataManagementPlan().fromDataModel(x)).collect(Collectors.toList()));
|
profile.setAssociatedDmps(dmps.stream().map(x -> new DataManagementPlan().fromDataModel(x)).collect(Collectors.toList()));
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class DataFieldsUrlConfiguration {
|
||||||
private String uri;
|
private String uri;
|
||||||
private String description;
|
private String description;
|
||||||
private String source;
|
private String source;
|
||||||
|
private String count;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -57,4 +58,13 @@ public class DataFieldsUrlConfiguration {
|
||||||
public void setSource(String source) {
|
public void setSource(String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "count")
|
||||||
|
public void setCount(String count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package eu.eudat.logic.proxy.config;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
|
||||||
|
public class DataSearchConfiguration {
|
||||||
|
private String type;
|
||||||
|
private String queryParam;
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
@XmlElement(name = "type")
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQueryParam() {
|
||||||
|
return queryParam;
|
||||||
|
}
|
||||||
|
@XmlElement(name = "queryparam")
|
||||||
|
public void setQueryParam(String queryParam) {
|
||||||
|
this.queryParam = queryParam;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package eu.eudat.logic.proxy.config;
|
||||||
|
|
||||||
|
public class ExternalUrlCriteria {
|
||||||
|
private String like;
|
||||||
|
private String page;
|
||||||
|
private String pageSize;
|
||||||
|
private String funderId;
|
||||||
|
|
||||||
|
public String getLike() {
|
||||||
|
return like;
|
||||||
|
}
|
||||||
|
public void setLike(String like) {
|
||||||
|
this.like = like;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPage() {
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
public void setPage(String page) {
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
public void setPageSize(String pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFunderId() {
|
||||||
|
return funderId;
|
||||||
|
}
|
||||||
|
public void setFunderId(String funderId) {
|
||||||
|
this.funderId = funderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExternalUrlCriteria(String like) {
|
||||||
|
this.like = like;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExternalUrlCriteria() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,11 +12,13 @@ public class UrlConfiguration {
|
||||||
private DataUrlConfiguration data;
|
private DataUrlConfiguration data;
|
||||||
private String type;
|
private String type;
|
||||||
private String paginationPath;
|
private String paginationPath;
|
||||||
|
private String contentType;
|
||||||
|
private String funderQuery;
|
||||||
|
private String firstpage;
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "key")
|
@XmlElement(name = "key")
|
||||||
public void setKey(String key) {
|
public void setKey(String key) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
@ -25,7 +27,6 @@ public class UrlConfiguration {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "label")
|
@XmlElement(name = "label")
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
|
@ -34,7 +35,6 @@ public class UrlConfiguration {
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "url")
|
@XmlElement(name = "url")
|
||||||
public void setUrl(String url) {
|
public void setUrl(String url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -43,7 +43,6 @@ public class UrlConfiguration {
|
||||||
public Integer getOrdinal() {
|
public Integer getOrdinal() {
|
||||||
return ordinal;
|
return ordinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "ordinal")
|
@XmlElement(name = "ordinal")
|
||||||
public void setOrdinal(Integer ordinal) {
|
public void setOrdinal(Integer ordinal) {
|
||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
|
@ -52,7 +51,6 @@ public class UrlConfiguration {
|
||||||
public DataUrlConfiguration getData() {
|
public DataUrlConfiguration getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "data")
|
@XmlElement(name = "data")
|
||||||
public void setData(DataUrlConfiguration data) {
|
public void setData(DataUrlConfiguration data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
@ -61,7 +59,6 @@ public class UrlConfiguration {
|
||||||
public String getPaginationPath() {
|
public String getPaginationPath() {
|
||||||
return paginationPath;
|
return paginationPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "paginationpath")
|
@XmlElement(name = "paginationpath")
|
||||||
public void setPaginationPath(String paginationPath) {
|
public void setPaginationPath(String paginationPath) {
|
||||||
this.paginationPath = paginationPath;
|
this.paginationPath = paginationPath;
|
||||||
|
@ -70,9 +67,32 @@ public class UrlConfiguration {
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "type")
|
@XmlElement(name = "type")
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getContentType() {
|
||||||
|
return contentType;
|
||||||
|
}
|
||||||
|
@XmlElement(name = "contenttype")
|
||||||
|
public void setContentType(String contentType) {
|
||||||
|
this.contentType = contentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFunderQuery() {
|
||||||
|
return funderQuery;
|
||||||
|
}
|
||||||
|
@XmlElement(name = "funderQuery")
|
||||||
|
public void setFunderQuery(String funderQuery) {
|
||||||
|
this.funderQuery = funderQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstpage() {
|
||||||
|
return firstpage;
|
||||||
|
}
|
||||||
|
@XmlElement(name = "firstPage")
|
||||||
|
public void setFirstpage(String firstpage) {
|
||||||
|
this.firstpage = firstpage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package eu.eudat.logic.proxy.config.configloaders;
|
package eu.eudat.logic.proxy.config.configloaders;
|
||||||
|
|
||||||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 2/9/2018.
|
|
||||||
*/
|
|
||||||
public interface ConfigLoader {
|
public interface ConfigLoader {
|
||||||
ExternalUrls getExternalUrls();
|
ExternalUrls getExternalUrls();
|
||||||
|
List<String> getRdaProperties();
|
||||||
|
XWPFDocument getDocument();
|
||||||
|
ConfigurableProviders getConfigurableProviders();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package eu.eudat.logic.proxy.config.configloaders;
|
package eu.eudat.logic.proxy.config.configloaders;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
@ -8,15 +12,22 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service("configLoader")
|
@Service("configLoader")
|
||||||
@Profile("devel")
|
@Profile("devel")
|
||||||
public class DevelConfigLoader implements ConfigLoader {
|
public class DevelConfigLoader implements ConfigLoader {
|
||||||
|
|
||||||
private ExternalUrls externalUrls;
|
private ExternalUrls externalUrls;
|
||||||
|
private List<String> rdaProperties;
|
||||||
|
private XWPFDocument document;
|
||||||
|
private ConfigurableProviders configurableProviders;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
@ -31,9 +42,8 @@ public class DevelConfigLoader implements ConfigLoader {
|
||||||
|
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
||||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||||
is = new URL("file:///"+current+"/web/src/main/resources/ExternalUrls.xml").openStream();
|
is = new URL("file:///" + current + fileUrl).openStream();
|
||||||
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
|
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
System.out.println("Cannot find in folder" + current);
|
System.out.println("Cannot find in folder" + current);
|
||||||
|
@ -44,13 +54,85 @@ public class DevelConfigLoader implements ConfigLoader {
|
||||||
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setRdaProperties() {
|
||||||
|
String filePath = environment.getProperty("configuration.rda");
|
||||||
|
String current = null;
|
||||||
|
BufferedReader reader;
|
||||||
|
List<String> rdaList = new LinkedList<>();
|
||||||
|
try {
|
||||||
|
current = new java.io.File(".").getCanonicalPath();
|
||||||
|
reader = new BufferedReader(new FileReader(current + filePath));
|
||||||
|
String line = reader.readLine();
|
||||||
|
while (line != null) {
|
||||||
|
rdaList.add(line);
|
||||||
|
line = reader.readLine();
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
rdaProperties = rdaList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDocument() {
|
||||||
|
String filePath = environment.getProperty("configuration.h2020template");
|
||||||
|
String current = null;
|
||||||
|
InputStream is = null;
|
||||||
|
try {
|
||||||
|
current = new java.io.File(".").getCanonicalPath();
|
||||||
|
is = new URL("file:///" + current + filePath).openStream();
|
||||||
|
this.document = new XWPFDocument(is);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (is != null) is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Warning: Could not close a stream after reading from file: " + filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigurableProviders() {
|
||||||
|
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
||||||
|
String current = null;
|
||||||
|
InputStream is = null;
|
||||||
|
try {
|
||||||
|
current = new java.io.File(".").getCanonicalPath();
|
||||||
|
is = new URL("file:///" + current + filePath).openStream();
|
||||||
|
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (is != null) is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Warning: Could not close a stream after reading from file: " + filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ExternalUrls getExternalUrls() {
|
public ExternalUrls getExternalUrls() {
|
||||||
this.setExternalUrls();
|
this.setExternalUrls();
|
||||||
return externalUrls;
|
return externalUrls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getRdaProperties() {
|
||||||
|
this.setRdaProperties();
|
||||||
|
return rdaProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XWPFDocument getDocument() {
|
||||||
|
this.setDocument();
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurableProviders getConfigurableProviders() {
|
||||||
|
this.setConfigurableProviders();
|
||||||
|
return configurableProviders;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package eu.eudat.logic.proxy.config.configloaders;
|
package eu.eudat.logic.proxy.config.configloaders;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
@ -8,19 +11,23 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 2/9/2018.
|
|
||||||
*/
|
|
||||||
@Service("configLoader")
|
@Service("configLoader")
|
||||||
@Profile({ "production", "staging" })
|
@Profile({ "production", "staging" })
|
||||||
public class ProductionConfigLoader implements ConfigLoader {
|
public class ProductionConfigLoader implements ConfigLoader {
|
||||||
|
|
||||||
private ExternalUrls externalUrls;
|
private ExternalUrls externalUrls;
|
||||||
|
private List<String> rdaProperties;
|
||||||
|
private XWPFDocument document;
|
||||||
|
private ConfigurableProviders configurableProviders;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
@ -48,13 +55,69 @@ public class ProductionConfigLoader implements ConfigLoader {
|
||||||
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setRdaProperties() {
|
||||||
|
String filePath = environment.getProperty("configuration.rda");
|
||||||
|
BufferedReader reader;
|
||||||
|
List<String> rdaList = new LinkedList<>();
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new FileReader(filePath));
|
||||||
|
String line = reader.readLine();
|
||||||
|
while (line != null) {
|
||||||
|
rdaList.add(line);
|
||||||
|
line = reader.readLine();
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
rdaProperties = rdaList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDocument() {
|
||||||
|
String filePath = environment.getProperty("configuration.h2020template");
|
||||||
|
String current = null;
|
||||||
|
try {
|
||||||
|
current = new java.io.File(".").getCanonicalPath();
|
||||||
|
InputStream is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
||||||
|
this.document = new XWPFDocument(is);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigurableProviders() {
|
||||||
|
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
||||||
|
String current = null;
|
||||||
|
try {
|
||||||
|
current = new java.io.File(".").getCanonicalPath();
|
||||||
|
InputStream is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
this.configurableProviders = objectMapper.readValue(is, ConfigurableProviders.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ExternalUrls getExternalUrls() {
|
public ExternalUrls getExternalUrls() {
|
||||||
this.setExternalUrls();
|
this.setExternalUrls();
|
||||||
return externalUrls;
|
return externalUrls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getRdaProperties() {
|
||||||
|
this.setRdaProperties();
|
||||||
|
return rdaProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XWPFDocument getDocument() {
|
||||||
|
this.setDocument();
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurableProviders getConfigurableProviders() {
|
||||||
|
this.setConfigurableProviders();
|
||||||
|
return configurableProviders;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,22 +4,22 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.jayway.jsonpath.DocumentContext;
|
import com.jayway.jsonpath.DocumentContext;
|
||||||
import com.jayway.jsonpath.JsonPath;
|
import com.jayway.jsonpath.JsonPath;
|
||||||
import eu.eudat.logic.proxy.config.DataUrlConfiguration;
|
import eu.eudat.logic.proxy.config.*;
|
||||||
import eu.eudat.logic.proxy.config.FetchStrategy;
|
|
||||||
import eu.eudat.logic.proxy.config.UrlConfiguration;
|
|
||||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -28,165 +28,200 @@ public class RemoteFetcher {
|
||||||
|
|
||||||
private ConfigLoader configLoader;
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
@Value("${configuration.resources.path}")
|
|
||||||
private String resourcesPath;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public RemoteFetcher(ConfigLoader configLoader) {
|
public RemoteFetcher(ConfigLoader configLoader) {
|
||||||
this.configLoader = configLoader;
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("repositories")
|
@Cacheable("repositories")
|
||||||
public List<Map<String, String>> getRepositories(String query, String key) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getRepositories(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs =
|
List<UrlConfiguration> urlConfigs =
|
||||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRepositories().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRepositories().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||||
: configLoader.getExternalUrls().getRepositories().getUrls();
|
: configLoader.getExternalUrls().getRepositories().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getRepositories().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getRepositories().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("grants")
|
@Cacheable("grants")
|
||||||
public List<Map<String, String>> getGrants(String query) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getGrants(ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getGrants().getUrls();
|
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getGrants().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getGrants().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getGrants().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("projects")
|
@Cacheable("projects")
|
||||||
public List<Map<String, String>> getProjects(String query) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getProjects(ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getProjects().getUrls();
|
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getProjects().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getProjects().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getProjects().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("funders")
|
@Cacheable("funders")
|
||||||
public List<Map<String, String>> getFunders(String query) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getFunders(ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getFunders().getUrls();
|
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getFunders().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getProjects().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getFunders().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("organisations")
|
@Cacheable("organisations")
|
||||||
public List<Map<String, String>> getOrganisations(String query, String key) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getOrganisations(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs =
|
List<UrlConfiguration> urlConfigs =
|
||||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getOrganisations().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getOrganisations().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||||
: configLoader.getExternalUrls().getOrganisations().getUrls();
|
: configLoader.getExternalUrls().getOrganisations().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getOrganisations().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getOrganisations().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("registries")
|
@Cacheable("registries")
|
||||||
public List<Map<String, String>> getRegistries(String query, String key) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getRegistries(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs =
|
List<UrlConfiguration> urlConfigs =
|
||||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRegistries().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRegistries().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||||
: configLoader.getExternalUrls().getRegistries().getUrls();
|
: configLoader.getExternalUrls().getRegistries().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getRegistries().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getRegistries().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("services")
|
@Cacheable("services")
|
||||||
public List<Map<String, String>> getServices(String query, String key) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getServices(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs =
|
List<UrlConfiguration> urlConfigs =
|
||||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getServices().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getServices().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||||
: configLoader.getExternalUrls().getServices().getUrls();
|
: configLoader.getExternalUrls().getServices().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getServices().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getServices().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("researchers")
|
@Cacheable("researchers")
|
||||||
public List<Map<String, String>> getResearchers(String query, String key) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getResearchers(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs =
|
List<UrlConfiguration> urlConfigs =
|
||||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getResearchers().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getResearchers().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||||
: configLoader.getExternalUrls().getResearchers().getUrls();
|
: configLoader.getExternalUrls().getResearchers().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getResearchers().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getResearchers().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("tags")
|
@Cacheable("tags")
|
||||||
public List<Map<String, String>> getTags(String query, String key) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getTags(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs =
|
List<UrlConfiguration> urlConfigs =
|
||||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getTags().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getTags().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||||
: configLoader.getExternalUrls().getTags().getUrls();
|
: configLoader.getExternalUrls().getTags().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getTags().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getTags().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable("datasets")
|
@Cacheable("externalDatasets")
|
||||||
public List<Map<String, String>> getDatasets(String query, String key) throws NoURLFound, HugeResultSet {
|
public List<Map<String, String>> getDatasets(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||||
List<UrlConfiguration> urlConfigs =
|
List<UrlConfiguration> urlConfigs =
|
||||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getDatasets().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getDatasets().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||||
: configLoader.getExternalUrls().getDatasets().getUrls();
|
: configLoader.getExternalUrls().getDatasets().getUrls();
|
||||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getDatasets().getFetchMode();
|
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getDatasets().getFetchMode();
|
||||||
return getAll(urlConfigs, fetchStrategy, query);
|
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<Map<String, String>> getAll(List<UrlConfiguration> urlConfigs, FetchStrategy fetchStrategy, String query) throws NoURLFound, HugeResultSet {
|
private List<Map<String, String>> getAll(List<UrlConfiguration> urlConfigs, FetchStrategy fetchStrategy, ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
|
||||||
|
|
||||||
if (urlConfigs == null || urlConfigs.isEmpty())
|
if (urlConfigs == null || urlConfigs.isEmpty())
|
||||||
throw new NoURLFound("No Repository urls found in configuration");
|
throw new NoURLFound("No Repository urls found in configuration");
|
||||||
|
|
||||||
Collections.sort(urlConfigs, Comparator.comparing(UrlConfiguration::getOrdinal));
|
urlConfigs.sort(Comparator.comparing(UrlConfiguration::getOrdinal));
|
||||||
List<Map<String, String>> results = new LinkedList<>();
|
List<Map<String, String>> results = new LinkedList<>();
|
||||||
for (UrlConfiguration urlConfig : urlConfigs) {
|
for (UrlConfiguration urlConfig : urlConfigs) {
|
||||||
|
ifFunderQueryExist(urlConfig, externalUrlCriteria);
|
||||||
if (urlConfig.getType() == null || urlConfig.getType().equals("External")) {
|
if (urlConfig.getType() == null || urlConfig.getType().equals("External")) {
|
||||||
results.addAll(getAllResultsFromUrl(urlConfig.getUrl(), fetchStrategy, urlConfig.getData(), urlConfig.getPaginationPath(), query, urlConfig.getLabel()));
|
results.addAll(getAllResultsFromUrl(urlConfig.getUrl(), fetchStrategy, urlConfig.getData(), urlConfig.getPaginationPath(), externalUrlCriteria, urlConfig.getLabel(), urlConfig.getContentType(), urlConfig.getFirstpage()));
|
||||||
}
|
} else if (urlConfig.getType() != null && urlConfig.getType().equals("Internal")) {
|
||||||
else if (urlConfig.getType() != null && urlConfig.getType().equals("Internal")) {
|
results.addAll(getAllResultsFromMockUpJson(urlConfig.getUrl(), externalUrlCriteria.getLike()));
|
||||||
results.addAll(getAllResultsFromMockUpJson(urlConfig.getUrl(), query));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ifFunderQueryExist(UrlConfiguration urlConfiguration, ExternalUrlCriteria externalUrlCriteria) {
|
||||||
|
if (urlConfiguration.getFunderQuery() != null) {
|
||||||
|
if (externalUrlCriteria.getFunderId() != null && urlConfiguration.getFunderQuery().startsWith("dmp:")) {
|
||||||
|
urlConfiguration.setUrl(urlConfiguration.getUrl().replace("{funderQuery}", urlConfiguration.getFunderQuery()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
urlConfiguration.setUrl(urlConfiguration.getUrl().replace("{funderQuery}", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<Map<String, String>> getAllResultsFromUrl(String path, FetchStrategy fetchStrategy, final DataUrlConfiguration jsonDataPath, final String jsonPaginationPath, String query, String key) throws HugeResultSet {
|
private String replaceCriteriaOnUrl(String path, ExternalUrlCriteria externalUrlCriteria, String firstPage) {
|
||||||
Set<Integer> pages = new HashSet<Integer>();
|
String completedPath = path;
|
||||||
|
if (externalUrlCriteria.getLike() != null) {
|
||||||
|
if (path.contains("openaire") && externalUrlCriteria.getLike().equals(""))
|
||||||
|
completedPath = completedPath.replaceAll("\\{like}", "*");
|
||||||
|
else
|
||||||
|
completedPath = completedPath.replaceAll("\\{like}", externalUrlCriteria.getLike());
|
||||||
|
} else {
|
||||||
|
completedPath = completedPath.replace("{like}", "");
|
||||||
|
}
|
||||||
|
if (externalUrlCriteria.getFunderId() != null) {
|
||||||
|
String funderId = externalUrlCriteria.getFunderId();
|
||||||
|
try {
|
||||||
|
funderId = URLEncoder.encode(externalUrlCriteria.getFunderId(), "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
completedPath = completedPath.replace("{funderId}", funderId);
|
||||||
|
}
|
||||||
|
if (externalUrlCriteria.getPage() != null) {
|
||||||
|
completedPath = completedPath.replace("{page}", externalUrlCriteria.getPage());
|
||||||
|
} else {
|
||||||
|
if (firstPage != null) {
|
||||||
|
completedPath = completedPath.replace("{page}", firstPage);
|
||||||
|
} else {
|
||||||
|
completedPath = completedPath.replace("{page}", "1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (externalUrlCriteria.getPageSize() != null) {
|
||||||
|
completedPath = completedPath.replace("{pageSize}", externalUrlCriteria.getPageSize());
|
||||||
|
} else {
|
||||||
|
completedPath = completedPath.replace("{pageSize}", "10");
|
||||||
|
}
|
||||||
|
return completedPath;
|
||||||
|
}
|
||||||
|
|
||||||
final String searchQuery = (query != null) && !query.isEmpty() ? "&search=" + query : "";
|
private List<Map<String, String>> getAllResultsFromUrl(String path, FetchStrategy fetchStrategy, final DataUrlConfiguration jsonDataPath, final String jsonPaginationPath, ExternalUrlCriteria externalUrlCriteria, String key, String contentType, String firstPage) throws HugeResultSet {
|
||||||
|
Set<Integer> pages = new HashSet<>();
|
||||||
|
|
||||||
Results results = getResultsFromUrl(path + "?page=1" + searchQuery, jsonDataPath, jsonPaginationPath);
|
String replacedPath = replaceCriteriaOnUrl(path, externalUrlCriteria, firstPage);
|
||||||
|
|
||||||
|
Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType);
|
||||||
if (fetchStrategy == FetchStrategy.FIRST)
|
if (fetchStrategy == FetchStrategy.FIRST)
|
||||||
return results == null ? new LinkedList<>() : results.getResults().stream().map(x -> {
|
return results == null ? new LinkedList<>() : results.getResults().stream().peek(x -> x.put("tag", key)).collect(Collectors.toList());
|
||||||
x.put("tag", key);
|
|
||||||
return x;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set
|
if (results != null && results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set
|
||||||
for (int i = 2; i <= results.getPagination().get("pages"); i++)
|
for (int i = 2; i <= results.getPagination().get("pages"); i++)
|
||||||
pages.add(i);
|
pages.add(i);
|
||||||
|
|
||||||
Long maxResults = configLoader.getExternalUrls().getMaxresults();
|
Long maxResults = configLoader.getExternalUrls().getMaxresults();
|
||||||
if ((maxResults > 0) && (results.getPagination().get("count") > maxResults))
|
if ((maxResults > 0 && results != null) && (results.getPagination().get("count") > maxResults))
|
||||||
throw new HugeResultSet("The submitted search query " + query + " is about to return " + results.getPagination().get("count") + " results... Please submit a more detailed search query");
|
throw new HugeResultSet("The submitted search query " + externalUrlCriteria.getLike() + " is about to return " + results.getPagination().get("count") + " results... Please submit a more detailed search query");
|
||||||
|
|
||||||
Optional<Results> optionalResults = pages.parallelStream()
|
Optional<Results> optionalResults = pages.parallelStream()
|
||||||
.map(page -> getResultsFromUrl(path + "?page=" + page + searchQuery, jsonDataPath, jsonPaginationPath))
|
.map(page -> getResultsFromUrl(path + "&page=" + page, jsonDataPath, jsonPaginationPath, contentType))
|
||||||
.reduce((result1, result2) -> {
|
.reduce((result1, result2) -> {
|
||||||
result1.getResults().addAll(result2.getResults());
|
result1.getResults().addAll(result2.getResults());
|
||||||
return result1;
|
return result1;
|
||||||
});
|
});
|
||||||
Results remainingResults = optionalResults.isPresent() ? optionalResults.get() : new Results();
|
Results remainingResults = optionalResults.orElseGet(Results::new);
|
||||||
|
|
||||||
remainingResults.getResults().addAll(results.getResults());
|
remainingResults.getResults().addAll(results.getResults());
|
||||||
|
|
||||||
return remainingResults.getResults().stream().map(x -> {
|
return remainingResults.getResults().stream().peek(x -> x.put("tag", key)).collect(Collectors.toList());
|
||||||
x.put("tag", key);
|
|
||||||
return x;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Results getResultsFromUrl(String urlString, DataUrlConfiguration jsonDataPath, String jsonPaginationPath) {
|
private Results getResultsFromUrl(String urlString, DataUrlConfiguration jsonDataPath, String jsonPaginationPath, String contentType) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
URL url = new URL(urlString);
|
URL url = new URL(urlString.replace(" ", "%20"));
|
||||||
|
|
||||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
con.setRequestProperty("Accept", "application/vnd.api+json; charset=utf-8");
|
con.setRequestProperty("Accept", contentType);
|
||||||
|
|
||||||
int responseCode = con.getResponseCode();
|
int responseCode = con.getResponseCode();
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||||
|
@ -198,9 +233,13 @@ public class RemoteFetcher {
|
||||||
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName() + "," + jsonDataPath.getFieldsUrlConfiguration().getDescription()
|
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName() + "," + jsonDataPath.getFieldsUrlConfiguration().getDescription()
|
||||||
+ "," + jsonDataPath.getFieldsUrlConfiguration().getUri() + "," + jsonDataPath.getFieldsUrlConfiguration().getId()
|
+ "," + jsonDataPath.getFieldsUrlConfiguration().getUri() + "," + jsonDataPath.getFieldsUrlConfiguration().getId()
|
||||||
+ "," + jsonDataPath.getFieldsUrlConfiguration().getSource() + "]"),
|
+ "," + jsonDataPath.getFieldsUrlConfiguration().getSource() + "]"),
|
||||||
jsonContext.read(jsonPaginationPath));
|
new HashMap<>(1, 1));
|
||||||
}
|
} else if (jsonDataPath.getFieldsUrlConfiguration().getCount() != null) { // parsing services.openaire.eu
|
||||||
else {
|
results = new Results(jsonContext.read(jsonDataPath.getPath()
|
||||||
|
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName()
|
||||||
|
+ "," + jsonDataPath.getFieldsUrlConfiguration().getId() + "]"),
|
||||||
|
new HashMap<>(1, 1));
|
||||||
|
} else {
|
||||||
results = new Results(jsonContext.read(jsonDataPath.getPath()
|
results = new Results(jsonContext.read(jsonDataPath.getPath()
|
||||||
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName() + "," + jsonDataPath.getFieldsUrlConfiguration().getDescription()
|
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName() + "," + jsonDataPath.getFieldsUrlConfiguration().getDescription()
|
||||||
+ "," + jsonDataPath.getFieldsUrlConfiguration().getUri() + "," + jsonDataPath.getFieldsUrlConfiguration().getId() + "]"),
|
+ "," + jsonDataPath.getFieldsUrlConfiguration().getUri() + "," + jsonDataPath.getFieldsUrlConfiguration().getId() + "]"),
|
||||||
|
@ -226,9 +265,9 @@ public class RemoteFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Map<String, String>> getAllResultsFromMockUpJson(String path, String query) {
|
private List<Map<String, String>> getAllResultsFromMockUpJson(String path, String query) {
|
||||||
String filePath = this.resourcesPath + path;
|
|
||||||
List<Map<String, String>> internalResults;
|
List<Map<String, String>> internalResults;
|
||||||
try {
|
try {
|
||||||
|
String filePath = Paths.get(path).toUri().toURL().toString();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, Object>>>(){});
|
internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, Object>>>(){});
|
||||||
searchListMap(internalResults, query);
|
searchListMap(internalResults, query);
|
||||||
|
@ -254,11 +293,12 @@ public class RemoteFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String transformKey(DataUrlConfiguration dataUrlConfiguration, String key) {
|
private String transformKey(DataUrlConfiguration dataUrlConfiguration, String key) {
|
||||||
if (key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getId().replace("'",""))) return "pid";
|
if (dataUrlConfiguration.getFieldsUrlConfiguration().getId() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getId().replace("'",""))) return "pid";
|
||||||
if (key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getDescription().replace("'",""))) return "description";
|
if (dataUrlConfiguration.getFieldsUrlConfiguration().getDescription() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getDescription().replace("'",""))) return "description";
|
||||||
if (key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getUri().replace("'",""))) return "uri";
|
if (dataUrlConfiguration.getFieldsUrlConfiguration().getUri() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getUri().replace("'",""))) return "uri";
|
||||||
if (key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getName().replace("'",""))) return "name";
|
if (dataUrlConfiguration.getFieldsUrlConfiguration().getName() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getName().replace("'",""))) return "name";
|
||||||
if (key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getSource().replace("'",""))) return "source";
|
if (dataUrlConfiguration.getFieldsUrlConfiguration().getSource() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getSource().replace("'",""))) return "source";
|
||||||
|
if (dataUrlConfiguration.getFieldsUrlConfiguration().getCount() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getCount().replace("'",""))) return "count";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,6 @@ import org.springframework.web.client.RestTemplate;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 2/22/2018.
|
|
||||||
*/
|
|
||||||
@Component("b2AccessCustomProvider")
|
@Component("b2AccessCustomProvider")
|
||||||
public class B2AccessCustomProviderImpl implements B2AccessCustomProvider {
|
public class B2AccessCustomProviderImpl implements B2AccessCustomProvider {
|
||||||
|
|
||||||
|
@ -54,7 +51,6 @@ public class B2AccessCustomProviderImpl implements B2AccessCustomProvider {
|
||||||
map.add("redirect_uri", redirectUri);
|
map.add("redirect_uri", redirectUri);
|
||||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
|
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> values = template.postForObject(this.environment.getProperty("b2access.externallogin.access_token_url"), request, Map.class);
|
Map<String, Object> values = template.postForObject(this.environment.getProperty("b2access.externallogin.access_token_url"), request, Map.class);
|
||||||
B2AccessResponseToken b2AccessResponseToken = new B2AccessResponseToken();
|
B2AccessResponseToken b2AccessResponseToken = new B2AccessResponseToken();
|
||||||
b2AccessResponseToken.setAccessToken((String) values.get("access_token"));
|
b2AccessResponseToken.setAccessToken((String) values.get("access_token"));
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviderUserSettings;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.helpers.ConfigurableProviderResponseToken;
|
||||||
|
|
||||||
|
public interface ConfigurableProviderCustomProvider {
|
||||||
|
|
||||||
|
ConfigurableProviderResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret, String accessTokenUrl, String grantType, String access_token, String expires_in);
|
||||||
|
|
||||||
|
ConfigurableProviderUser getUser(String accessToken, ConfigurableProviderUserSettings user);
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviderUserSettings;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.helpers.ConfigurableProviderResponseToken;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component("configurableProviderCustomProvider")
|
||||||
|
public class ConfigurableProviderCustomProviderImpl implements ConfigurableProviderCustomProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigurableProviderResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret, String accessTokenUrl,
|
||||||
|
String grantType, String access_token, String expires_in) {
|
||||||
|
RestTemplate template = new RestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
|
||||||
|
map.add("grant_type", grantType);
|
||||||
|
map.add("code", code);
|
||||||
|
map.add("redirect_uri", redirectUri);
|
||||||
|
map.add("client_id", clientId);
|
||||||
|
map.add("client_secret", clientSecret);
|
||||||
|
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
|
||||||
|
|
||||||
|
Map<String, Object> values = template.postForObject(accessTokenUrl, request, Map.class);
|
||||||
|
ConfigurableProviderResponseToken responseToken = new ConfigurableProviderResponseToken();
|
||||||
|
responseToken.setAccessToken((String) values.get(access_token));
|
||||||
|
if (expires_in != null && !expires_in.isEmpty()) {
|
||||||
|
responseToken.setExpiresIn((Integer) values.get(expires_in));
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigurableProviderUser getUser(String accessToken, ConfigurableProviderUserSettings user) {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
HttpHeaders headers = this.createBearerAuthHeaders(accessToken);
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
Map<String, Object> values = restTemplate.exchange(user.getUser_info_url(), HttpMethod.GET, entity, Map.class).getBody();
|
||||||
|
return new ConfigurableProviderUser().getConfigurableProviderUser(values, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createBearerAuthHeaders(String accessToken) {
|
||||||
|
return new HttpHeaders() {{
|
||||||
|
String authHeader = "Bearer " + accessToken;
|
||||||
|
set("Authorization", authHeader);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviderUserSettings;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ConfigurableProviderUser {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurableProviderUser getConfigurableProviderUser(Map data, ConfigurableProviderUserSettings user) {
|
||||||
|
if (user.getId() != null && !user.getId().isEmpty())
|
||||||
|
this.id = (String) data.get(user.getId());
|
||||||
|
if (user.getName() != null && !user.getName().isEmpty())
|
||||||
|
this.name = (String) data.get(user.getName());
|
||||||
|
if (user.getEmail() != null && !user.getEmail().isEmpty())
|
||||||
|
this.email = (String) data.get(user.getEmail());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider.entities;
|
||||||
|
|
||||||
|
public class ConfigurableProvider {
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
private String configurableLoginId;
|
||||||
|
private String name;
|
||||||
|
private String clientId;
|
||||||
|
private String clientSecret;
|
||||||
|
private String redirect_uri;
|
||||||
|
private String access_token_url;
|
||||||
|
private String grant_type;
|
||||||
|
private ConfigurableProviderToken token;
|
||||||
|
private ConfigurableProviderUserSettings user;
|
||||||
|
private String oauthUrl;
|
||||||
|
private String scope;
|
||||||
|
private String state;
|
||||||
|
|
||||||
|
public boolean getEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConfigurableLoginId() {
|
||||||
|
return configurableLoginId;
|
||||||
|
}
|
||||||
|
public void setConfigurableLoginId(String configurableLoginId) {
|
||||||
|
this.configurableLoginId = configurableLoginId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientId() {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
public void setClientId(String clientId) {
|
||||||
|
this.clientId = clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientSecret() {
|
||||||
|
return clientSecret;
|
||||||
|
}
|
||||||
|
public void setClientSecret(String clientSecret) {
|
||||||
|
this.clientSecret = clientSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRedirect_uri() {
|
||||||
|
return redirect_uri;
|
||||||
|
}
|
||||||
|
public void setRedirect_uri(String redirect_uri) {
|
||||||
|
this.redirect_uri = redirect_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccess_token_url() {
|
||||||
|
return access_token_url;
|
||||||
|
}
|
||||||
|
public void setAccess_token_url(String access_token_url) {
|
||||||
|
this.access_token_url = access_token_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrant_type() {
|
||||||
|
return grant_type;
|
||||||
|
}
|
||||||
|
public void setGrant_type(String grant_type) {
|
||||||
|
this.grant_type = grant_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurableProviderToken getToken() {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
public void setToken(ConfigurableProviderToken token) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurableProviderUserSettings getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
public void setUser(ConfigurableProviderUserSettings user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOauthUrl() {
|
||||||
|
return oauthUrl;
|
||||||
|
}
|
||||||
|
public void setOauthUrl(String oauthUrl) {
|
||||||
|
this.oauthUrl = oauthUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
public void setScope(String scope) {
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
public void setState(String state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider.entities;
|
||||||
|
|
||||||
|
public class ConfigurableProviderToken {
|
||||||
|
private String access_token;
|
||||||
|
private String expires_in;
|
||||||
|
|
||||||
|
public String getAccess_token() {
|
||||||
|
return access_token;
|
||||||
|
}
|
||||||
|
public void setAccess_token(String access_token) {
|
||||||
|
this.access_token = access_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpires_in() {
|
||||||
|
return expires_in;
|
||||||
|
}
|
||||||
|
public void setExpires_in(String expires_in) {
|
||||||
|
this.expires_in = expires_in;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider.entities;
|
||||||
|
|
||||||
|
public class ConfigurableProviderUserSettings {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
private String user_info_url;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser_info_url() {
|
||||||
|
return user_info_url;
|
||||||
|
}
|
||||||
|
public void setUser_info_url(String user_info_url) {
|
||||||
|
this.user_info_url = user_info_url;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider.entities;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ConfigurableProviders {
|
||||||
|
private List<ConfigurableProvider> providers = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<ConfigurableProvider> getProviders() {
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
|
public void setProviders(List<ConfigurableProvider> providers) {
|
||||||
|
this.providers = providers;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider.models;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProvider;
|
||||||
|
|
||||||
|
public class ConfigurableProviderModel {
|
||||||
|
|
||||||
|
private String configurableLoginId;
|
||||||
|
private String name;
|
||||||
|
private String clientId;
|
||||||
|
private String redirect_uri;
|
||||||
|
private String oauthUrl;
|
||||||
|
private String scope;
|
||||||
|
private String state;
|
||||||
|
|
||||||
|
public String getConfigurableLoginId() {
|
||||||
|
return configurableLoginId;
|
||||||
|
}
|
||||||
|
public void setConfigurableLoginId(String configurableLoginId) {
|
||||||
|
this.configurableLoginId = configurableLoginId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientId() {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
public void setClientId(String clientId) {
|
||||||
|
this.clientId = clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRedirect_uri() {
|
||||||
|
return redirect_uri;
|
||||||
|
}
|
||||||
|
public void setRedirect_uri(String redirect_uri) {
|
||||||
|
this.redirect_uri = redirect_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOauthUrl() {
|
||||||
|
return oauthUrl;
|
||||||
|
}
|
||||||
|
public void setOauthUrl(String oauthUrl) {
|
||||||
|
this.oauthUrl = oauthUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
public void setScope(String scope) {
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
public void setState(String state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurableProviderModel fromDataModel(ConfigurableProvider entity) {
|
||||||
|
ConfigurableProviderModel model = new ConfigurableProviderModel();
|
||||||
|
model.setConfigurableLoginId(entity.getConfigurableLoginId());
|
||||||
|
model.setName(entity.getName());
|
||||||
|
model.setClientId(entity.getClientId());
|
||||||
|
model.setRedirect_uri(entity.getRedirect_uri());
|
||||||
|
model.setOauthUrl(entity.getOauthUrl());
|
||||||
|
model.setScope(entity.getScope());
|
||||||
|
model.setState(entity.getState());
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ConfigurableProvider.models;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ConfigurableProvidersModel {
|
||||||
|
private List<ConfigurableProviderModel> providers;
|
||||||
|
|
||||||
|
public List<ConfigurableProviderModel> getProviders() {
|
||||||
|
return providers;
|
||||||
|
}
|
||||||
|
public void setProviders(List<ConfigurableProviderModel> providers) {
|
||||||
|
this.providers = providers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurableProvidersModel fromDataModel(ConfigurableProviders entity) {
|
||||||
|
ConfigurableProvidersModel model = new ConfigurableProvidersModel();
|
||||||
|
List<ConfigurableProviderModel> providerModelList = new LinkedList<>();
|
||||||
|
if (entity != null) {
|
||||||
|
for (ConfigurableProvider entityProvider : entity.getProviders()) {
|
||||||
|
if (entityProvider.getEnabled())
|
||||||
|
providerModelList.add(new ConfigurableProviderModel().fromDataModel(entityProvider));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.setProviders(providerModelList);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.LinkedIn;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.validators.linkedin.helpers.LinkedInResponseToken;
|
||||||
|
|
||||||
|
public interface LinkedInCustomProvider {
|
||||||
|
|
||||||
|
LinkedInUser getUser(String accessToken);
|
||||||
|
|
||||||
|
LinkedInResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret);
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.LinkedIn;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.validators.linkedin.helpers.LinkedInResponseToken;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component("LinkedInCustomProvider")
|
||||||
|
public class LinkedInCustomProviderImpl implements LinkedInCustomProvider {
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
public LinkedInCustomProviderImpl(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedInUser getUser(String accessToken) {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
HttpHeaders headers = this.createBearerAuthHeaders(accessToken);
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
Map profileValues = restTemplate.exchange(this.environment.getProperty("linkedin.login.user_info_url"), HttpMethod.GET, entity, Map.class).getBody();
|
||||||
|
Map emailValues = restTemplate.exchange(this.environment.getProperty("linkedin.login.user_email"), HttpMethod.GET, entity, Map.class).getBody();
|
||||||
|
LinkedInUser linkedInUser = new LinkedInUser();
|
||||||
|
linkedInUser.setEmail((String)emailValues.get("email"));
|
||||||
|
linkedInUser.setName((String)profileValues.get("localizedFirstName"));
|
||||||
|
linkedInUser.setId((String)profileValues.get("id"));
|
||||||
|
return linkedInUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedInResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret) {
|
||||||
|
RestTemplate template = new RestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
|
||||||
|
map.add("grant_type", "authorization_code");
|
||||||
|
map.add("code", code);
|
||||||
|
map.add("redirect_uri", redirectUri);
|
||||||
|
map.add("client_id", clientId);
|
||||||
|
map.add("client_secret", clientSecret);
|
||||||
|
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
|
||||||
|
|
||||||
|
Map<String, Object> values = template.postForObject(this.environment.getProperty("linkedin.login.access_token_url"), request, Map.class);
|
||||||
|
LinkedInResponseToken linkedInResponseToken = new LinkedInResponseToken();
|
||||||
|
linkedInResponseToken.setAccessToken((String) values.get("access_token"));
|
||||||
|
linkedInResponseToken.setExpiresIn((Integer) values.get("expires_in"));
|
||||||
|
|
||||||
|
return linkedInResponseToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createBearerAuthHeaders(String accessToken) {
|
||||||
|
return new HttpHeaders() {{
|
||||||
|
String authHeader = "Bearer " + new String(accessToken);
|
||||||
|
set("Authorization", authHeader);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.LinkedIn;
|
||||||
|
|
||||||
|
public class LinkedInUser {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.OpenAIRE;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.validators.openaire.helpers.OpenAIREResponseToken;
|
||||||
|
|
||||||
|
public interface OpenAIRECustomProvider {
|
||||||
|
|
||||||
|
OpenAIREResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret);
|
||||||
|
|
||||||
|
OpenAIREUser getUser(String accessToken);
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.OpenAIRE;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.validators.openaire.helpers.OpenAIREResponseToken;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component("openAIRECustomProvider")
|
||||||
|
public class OpenAIRECustomProviderImpl implements OpenAIRECustomProvider {
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
public OpenAIRECustomProviderImpl(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenAIREUser getUser(String accessToken) {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
HttpHeaders headers = this.createBearerAuthHeaders(accessToken);
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
Map<String, Object> values = restTemplate.exchange(this.environment.getProperty("openaire.login.user_info_url"), HttpMethod.GET, entity, Map.class).getBody();
|
||||||
|
return new OpenAIREUser().getOpenAIREUser(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenAIREResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret) {
|
||||||
|
RestTemplate template = new RestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
|
||||||
|
map.add("grant_type", "authorization_code");
|
||||||
|
map.add("code", code);
|
||||||
|
map.add("redirect_uri", redirectUri);
|
||||||
|
map.add("client_id", clientId);
|
||||||
|
map.add("client_secret", clientSecret);
|
||||||
|
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
|
||||||
|
|
||||||
|
Map<String, Object> values = template.postForObject(this.environment.getProperty("openaire.login.access_token_url"), request, Map.class);
|
||||||
|
OpenAIREResponseToken openAIREResponseToken = new OpenAIREResponseToken();
|
||||||
|
openAIREResponseToken.setAccessToken((String) values.get("access_token"));
|
||||||
|
openAIREResponseToken.setExpiresIn((Integer) values.get("expires_in"));
|
||||||
|
|
||||||
|
return openAIREResponseToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createBearerAuthHeaders(String accessToken) {
|
||||||
|
return new HttpHeaders() {{
|
||||||
|
String authHeader = "Bearer " + accessToken;
|
||||||
|
set("Authorization", authHeader);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.OpenAIRE;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class OpenAIREUser {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenAIREUser getOpenAIREUser(Object data) {
|
||||||
|
this.id = (String) ((Map) data).get("sub");
|
||||||
|
this.name = (String) ((Map) data).get("name");
|
||||||
|
this.email = (String) ((Map) data).get("email");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,19 @@
|
||||||
package eu.eudat.logic.security.validators;
|
package eu.eudat.logic.security.validators;
|
||||||
|
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.logic.security.customproviders.B2Access.B2AccessCustomProvider;
|
import eu.eudat.logic.security.customproviders.B2Access.B2AccessCustomProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.ConfigurableProviderCustomProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.LinkedIn.LinkedInCustomProvider;
|
||||||
import eu.eudat.logic.security.customproviders.ORCID.ORCIDCustomProvider;
|
import eu.eudat.logic.security.customproviders.ORCID.ORCIDCustomProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.OpenAIRE.OpenAIRECustomProvider;
|
||||||
import eu.eudat.logic.security.validators.b2access.B2AccessTokenValidator;
|
import eu.eudat.logic.security.validators.b2access.B2AccessTokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.ConfigurableProviderTokenValidator;
|
||||||
import eu.eudat.logic.security.validators.facebook.FacebookTokenValidator;
|
import eu.eudat.logic.security.validators.facebook.FacebookTokenValidator;
|
||||||
import eu.eudat.logic.security.validators.google.GoogleTokenValidator;
|
import eu.eudat.logic.security.validators.google.GoogleTokenValidator;
|
||||||
import eu.eudat.logic.security.validators.linkedin.LinkedInTokenValidator;
|
import eu.eudat.logic.security.validators.linkedin.LinkedInTokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.openaire.OpenAIRETokenValidator;
|
||||||
import eu.eudat.logic.security.validators.orcid.ORCIDTokenValidator;
|
import eu.eudat.logic.security.validators.orcid.ORCIDTokenValidator;
|
||||||
import eu.eudat.logic.security.validators.twitter.TwitterTokenValidator;
|
import eu.eudat.logic.security.validators.twitter.TwitterTokenValidator;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
@ -18,7 +23,7 @@ import org.springframework.stereotype.Service;
|
||||||
@Service("tokenValidatorFactory")
|
@Service("tokenValidatorFactory")
|
||||||
public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
||||||
public enum LoginProvider {
|
public enum LoginProvider {
|
||||||
GOOGLE(1), FACEBOOK(2), TWITTER(3), LINKEDIN(4), NATIVELOGIN(5), B2_ACCESS(6), ORCID(7);
|
GOOGLE(1), FACEBOOK(2), TWITTER(3), LINKEDIN(4), NATIVELOGIN(5), B2_ACCESS(6), ORCID(7), OPENAIRE(8), CONFIGURABLE(9);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
|
@ -46,41 +51,58 @@ public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
||||||
return B2_ACCESS;
|
return B2_ACCESS;
|
||||||
case 7:
|
case 7:
|
||||||
return ORCID;
|
return ORCID;
|
||||||
|
case 8:
|
||||||
|
return OPENAIRE;
|
||||||
|
case 9:
|
||||||
|
return CONFIGURABLE;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unsupported LoginProvider");
|
throw new RuntimeException("Unsupported LoginProvider");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiContext apiContext;
|
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
private AuthenticationService nonVerifiedUserAuthenticationService;
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
private B2AccessCustomProvider b2AccessCustomProvider;
|
private B2AccessCustomProvider b2AccessCustomProvider;
|
||||||
private ORCIDCustomProvider orcidCustomProvider;
|
private ORCIDCustomProvider orcidCustomProvider;
|
||||||
|
private LinkedInCustomProvider linkedInCustomProvider;
|
||||||
|
private OpenAIRECustomProvider openAIRECustomProvider;
|
||||||
|
private ConfigurableProviderCustomProvider configurableProviderCustomProvider;
|
||||||
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TokenValidatorFactoryImpl(ApiContext apiContext, Environment environment, AuthenticationService nonVerifiedUserAuthenticationService, B2AccessCustomProvider b2AccessCustomProvider, ORCIDCustomProvider orcidCustomProvider) {
|
public TokenValidatorFactoryImpl(
|
||||||
this.apiContext = apiContext;
|
Environment environment,
|
||||||
|
AuthenticationService nonVerifiedUserAuthenticationService, B2AccessCustomProvider b2AccessCustomProvider,
|
||||||
|
ORCIDCustomProvider orcidCustomProvider, LinkedInCustomProvider linkedInCustomProvider, OpenAIRECustomProvider openAIRECustomProvider, ConfigurableProviderCustomProvider configurableProviderCustomProvider, ConfigLoader configLoader) {
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
this.b2AccessCustomProvider = b2AccessCustomProvider;
|
this.b2AccessCustomProvider = b2AccessCustomProvider;
|
||||||
this.orcidCustomProvider = orcidCustomProvider;
|
this.orcidCustomProvider = orcidCustomProvider;
|
||||||
|
this.linkedInCustomProvider = linkedInCustomProvider;
|
||||||
|
this.openAIRECustomProvider = openAIRECustomProvider;
|
||||||
|
this.configurableProviderCustomProvider = configurableProviderCustomProvider;
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenValidator getProvider(LoginProvider provider) {
|
public TokenValidator getProvider(LoginProvider provider) {
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
case GOOGLE:
|
case GOOGLE:
|
||||||
return new GoogleTokenValidator(this.apiContext, this.environment, this.nonVerifiedUserAuthenticationService);
|
return new GoogleTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService);
|
||||||
case FACEBOOK:
|
case FACEBOOK:
|
||||||
return new FacebookTokenValidator(this.apiContext, this.environment, this.nonVerifiedUserAuthenticationService);
|
return new FacebookTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService);
|
||||||
case LINKEDIN:
|
case LINKEDIN:
|
||||||
return new LinkedInTokenValidator(this.apiContext, this.environment, this.nonVerifiedUserAuthenticationService);
|
return new LinkedInTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, linkedInCustomProvider);
|
||||||
case TWITTER:
|
case TWITTER:
|
||||||
return new TwitterTokenValidator(this.apiContext, this.environment, this.nonVerifiedUserAuthenticationService);
|
return new TwitterTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService);
|
||||||
case B2_ACCESS:
|
case B2_ACCESS:
|
||||||
return new B2AccessTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.b2AccessCustomProvider);
|
return new B2AccessTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.b2AccessCustomProvider);
|
||||||
case ORCID:
|
case ORCID:
|
||||||
return new ORCIDTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.orcidCustomProvider, this.apiContext);
|
return new ORCIDTokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.orcidCustomProvider);
|
||||||
|
case OPENAIRE:
|
||||||
|
return new OpenAIRETokenValidator(this.environment, this.nonVerifiedUserAuthenticationService, this.openAIRECustomProvider);
|
||||||
|
case CONFIGURABLE:
|
||||||
|
return new ConfigurableProviderTokenValidator(this.configurableProviderCustomProvider, this.nonVerifiedUserAuthenticationService, this.configLoader);
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Login Provider Not Implemented");
|
throw new RuntimeException("Login Provider Not Implemented");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,6 @@ import org.springframework.stereotype.Component;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ikalyvas on 2/22/2018.
|
|
||||||
*/
|
|
||||||
@Component("b2AccessTokenValidator ")
|
@Component("b2AccessTokenValidator ")
|
||||||
public class B2AccessTokenValidator implements TokenValidator {
|
public class B2AccessTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package eu.eudat.logic.security.validators.configurableProvider;
|
||||||
|
|
||||||
|
import eu.eudat.exceptions.security.NullEmailException;
|
||||||
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.ConfigurableProviderCustomProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.ConfigurableProviderUser;
|
||||||
|
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProvider;
|
||||||
|
import eu.eudat.logic.security.validators.TokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.helpers.ConfigurableProviderRequest;
|
||||||
|
import eu.eudat.logic.security.validators.configurableProvider.helpers.ConfigurableProviderResponseToken;
|
||||||
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
|
import eu.eudat.models.data.login.LoginInfo;
|
||||||
|
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component("configurableProviderTokenValidator")
|
||||||
|
public class ConfigurableProviderTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
|
private ConfigurableProviderCustomProvider configurableProvider;
|
||||||
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
|
private ConfigLoader configLoader;
|
||||||
|
|
||||||
|
public ConfigurableProviderTokenValidator(ConfigurableProviderCustomProvider configurableProvider, AuthenticationService nonVerifiedUserAuthenticationService, ConfigLoader configLoader) {
|
||||||
|
this.configurableProvider = configurableProvider;
|
||||||
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
|
this.configLoader = configLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurableProviderResponseToken getAccessToken(ConfigurableProviderRequest configurableProviderRequest) {
|
||||||
|
ConfigurableProvider provider = getConfigurableProviderFromId(configurableProviderRequest.getConfigurableLoginId());
|
||||||
|
return this.configurableProvider.getAccessToken(configurableProviderRequest.getCode(),
|
||||||
|
provider.getRedirect_uri(), provider.getClientId(), provider.getClientSecret(),
|
||||||
|
provider.getAccess_token_url(), provider.getGrant_type(), provider.getToken().getAccess_token(), provider.getToken().getExpires_in());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Principal validateToken(LoginInfo credentials) throws NullEmailException {
|
||||||
|
String configurableLoginId = ((Map) credentials.getData()).get("configurableLoginId").toString();
|
||||||
|
ConfigurableProvider configurableProvider = getConfigurableProviderFromId(configurableLoginId);
|
||||||
|
ConfigurableProviderUser configurableUser = this.configurableProvider.getUser(credentials.getTicket(), configurableProvider.getUser());
|
||||||
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
|
user.setId(configurableUser.getId());
|
||||||
|
user.setEmail(configurableUser.getEmail());
|
||||||
|
user.setName(configurableUser.getName());
|
||||||
|
user.setProvider(credentials.getProvider());
|
||||||
|
user.setSecret(credentials.getTicket());
|
||||||
|
|
||||||
|
return this.nonVerifiedUserAuthenticationService.Touch(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConfigurableProvider getConfigurableProviderFromId(String configurableId) {
|
||||||
|
return this.configLoader.getConfigurableProviders().getProviders().stream()
|
||||||
|
.filter(prov -> prov.getConfigurableLoginId().equals(configurableId))
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
.get(0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package eu.eudat.logic.security.validators.configurableProvider.helpers;
|
||||||
|
|
||||||
|
public class ConfigurableProviderRequest {
|
||||||
|
private String code;
|
||||||
|
private String configurableLoginId;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConfigurableLoginId() {
|
||||||
|
return configurableLoginId;
|
||||||
|
}
|
||||||
|
public void setConfigurableLoginId(String configurableLoginId) {
|
||||||
|
this.configurableLoginId = configurableLoginId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package eu.eudat.logic.security.validators.configurableProvider.helpers;
|
||||||
|
|
||||||
|
public class ConfigurableProviderResponseToken {
|
||||||
|
private String accessToken;
|
||||||
|
private Integer expiresIn;
|
||||||
|
|
||||||
|
public String getAccessToken() {
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getExpiresIn() {
|
||||||
|
return expiresIn;
|
||||||
|
}
|
||||||
|
public void setExpiresIn(Integer expiresIn) {
|
||||||
|
this.expiresIn = expiresIn;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ package eu.eudat.logic.security.validators.facebook;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.security.validators.TokenValidator;
|
import eu.eudat.logic.security.validators.TokenValidator;
|
||||||
import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl;
|
import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
import eu.eudat.models.data.login.LoginInfo;
|
import eu.eudat.models.data.login.LoginInfo;
|
||||||
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||||
|
@ -22,17 +21,13 @@ import java.util.Map;
|
||||||
@Component("facebookTokenValidator")
|
@Component("facebookTokenValidator")
|
||||||
public class FacebookTokenValidator implements TokenValidator {
|
public class FacebookTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
private Environment environment;
|
|
||||||
private ApiContext apiContext;
|
|
||||||
private AuthenticationService nonVerifiedUserAuthenticationService;
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
private FacebookServiceProvider facebookServiceProvider;
|
private FacebookServiceProvider facebookServiceProvider;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public FacebookTokenValidator(ApiContext apiContext, Environment environment, AuthenticationService nonVerifiedUserAuthenticationService) {
|
public FacebookTokenValidator(Environment environment, AuthenticationService nonVerifiedUserAuthenticationService) {
|
||||||
this.environment = environment;
|
|
||||||
this.apiContext = apiContext;
|
|
||||||
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
this.facebookServiceProvider = new FacebookServiceProvider(this.environment.getProperty("facebook.login.clientId"), this.environment.getProperty("facebook.login.clientSecret"), this.environment.getProperty("facebook.login.namespace"));
|
this.facebookServiceProvider = new FacebookServiceProvider(environment.getProperty("facebook.login.clientId"), environment.getProperty("facebook.login.clientSecret"), environment.getProperty("facebook.login.namespace"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,8 +51,7 @@ public class FacebookTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
private User getFacebookUser(String accessToken) {
|
private User getFacebookUser(String accessToken) {
|
||||||
String[] fields = {"id", "email", "first_name", "last_name", "name", "verified", "picture"};
|
String[] fields = {"id", "email", "first_name", "last_name", "name", "verified", "picture"};
|
||||||
User profile = this.facebookServiceProvider.getApi(accessToken).fetchObject("me", User.class, fields);
|
return this.facebookServiceProvider.getApi(accessToken).fetchObject("me", User.class, fields);
|
||||||
return profile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Date addADay(Date date) {
|
private Date addADay(Date date) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.google.api.client.http.javanet.NetHttpTransport;
|
||||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||||
import eu.eudat.logic.security.validators.TokenValidator;
|
import eu.eudat.logic.security.validators.TokenValidator;
|
||||||
import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl;
|
import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
import eu.eudat.models.data.login.LoginInfo;
|
import eu.eudat.models.data.login.LoginInfo;
|
||||||
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||||
|
@ -24,24 +23,19 @@ import java.util.Collections;
|
||||||
public class GoogleTokenValidator implements TokenValidator {
|
public class GoogleTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
private static final HttpTransport transport = new NetHttpTransport();
|
private static final HttpTransport transport = new NetHttpTransport();
|
||||||
private ApiContext apiContext;
|
|
||||||
private AuthenticationService nonVerifiedUserAuthenticationService;
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
private GoogleIdTokenVerifier verifier;
|
private GoogleIdTokenVerifier verifier;
|
||||||
private Environment environment;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public GoogleTokenValidator(ApiContext apiContext, Environment environment, AuthenticationService nonVerifiedUserAuthenticationService) {
|
public GoogleTokenValidator(Environment environment, AuthenticationService nonVerifiedUserAuthenticationService) {
|
||||||
this.apiContext = apiContext;
|
|
||||||
this.environment = environment;
|
|
||||||
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
verifier = new GoogleIdTokenVerifier.Builder(transport, JacksonFactory.getDefaultInstance())
|
verifier = new GoogleIdTokenVerifier.Builder(transport, JacksonFactory.getDefaultInstance())
|
||||||
.setAudience(Collections.singletonList(this.environment.getProperty("google.login.clientId")))
|
.setAudience(Collections.singletonList(environment.getProperty("google.login.clientId")))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GoogleIdToken verifyUserAndGetUser(String idTokenString) throws IOException, GeneralSecurityException {
|
private GoogleIdToken verifyUserAndGetUser(String idTokenString) throws IOException, GeneralSecurityException {
|
||||||
GoogleIdToken idToken = verifier.verify(idTokenString);
|
return verifier.verify(idTokenString);
|
||||||
return idToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,5 +52,4 @@ public class GoogleTokenValidator implements TokenValidator {
|
||||||
user.setIsVerified(payload.getEmailVerified());
|
user.setIsVerified(payload.getEmailVerified());
|
||||||
return this.nonVerifiedUserAuthenticationService.Touch(user);
|
return this.nonVerifiedUserAuthenticationService.Touch(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
package eu.eudat.logic.security.validators.linkedin;
|
package eu.eudat.logic.security.validators.linkedin;
|
||||||
|
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
|
import eu.eudat.logic.security.customproviders.LinkedIn.LinkedInCustomProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.LinkedIn.LinkedInUser;
|
||||||
import eu.eudat.logic.security.validators.TokenValidator;
|
import eu.eudat.logic.security.validators.TokenValidator;
|
||||||
import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl;
|
import eu.eudat.logic.security.validators.linkedin.helpers.LinkedInRequest;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.security.validators.linkedin.helpers.LinkedInResponseToken;
|
||||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
import eu.eudat.models.data.login.LoginInfo;
|
import eu.eudat.models.data.login.LoginInfo;
|
||||||
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.social.linkedin.api.LinkedIn;
|
|
||||||
import org.springframework.social.linkedin.api.LinkedInProfile;
|
|
||||||
import org.springframework.social.linkedin.connect.LinkedInServiceProvider;
|
|
||||||
import org.springframework.social.oauth2.AccessGrant;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,21 +19,19 @@ import org.springframework.stereotype.Component;
|
||||||
public class LinkedInTokenValidator implements TokenValidator {
|
public class LinkedInTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
private ApiContext apiContext;
|
|
||||||
private AuthenticationService nonVerifiedUserAuthenticationService;
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
private LinkedInServiceProvider linkedInServiceProvider;
|
private LinkedInCustomProvider linkedInCustomProvider;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public LinkedInTokenValidator(ApiContext apiContext, Environment environment, AuthenticationService nonVerifiedUserAuthenticationService) {
|
public LinkedInTokenValidator(Environment environment, AuthenticationService nonVerifiedUserAuthenticationService, LinkedInCustomProvider linkedInCustomProvider) {
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
this.apiContext = apiContext;
|
|
||||||
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
this.linkedInServiceProvider = new LinkedInServiceProvider(this.environment.getProperty("linkedin.login.clientId"), this.environment.getProperty("linkedin.login.clientSecret"));
|
this.linkedInCustomProvider = linkedInCustomProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Principal validateToken(LoginInfo credentials) {
|
public Principal validateToken(LoginInfo credentials) {
|
||||||
AccessGrant accessGrant = this.linkedInServiceProvider.getOAuthOperations().exchangeForAccess(credentials.getTicket(), this.environment.getProperty("linkedin.login.redirect_uri"), null);
|
/*AccessGrant accessGrant = this.linkedInServiceProvider.getOAuthOperations().exchangeForAccess(credentials.getTicket(), this.environment.getProperty("linkedin.login.redirect_uri"), null);
|
||||||
LinkedIn linkedInService = this.linkedInServiceProvider.getApi(accessGrant.getAccessToken());
|
LinkedIn linkedInService = this.linkedInServiceProvider.getApi(accessGrant.getAccessToken());
|
||||||
LinkedInProfile linkedInProfile = linkedInService.profileOperations().getUserProfile();
|
LinkedInProfile linkedInProfile = linkedInService.profileOperations().getUserProfile();
|
||||||
LoginProviderUser user = new LoginProviderUser();
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
|
@ -48,7 +44,24 @@ public class LinkedInTokenValidator implements TokenValidator {
|
||||||
user.setAvatarUrl(linkedInProfile.getProfilePictureUrl());
|
user.setAvatarUrl(linkedInProfile.getProfilePictureUrl());
|
||||||
user.setName(linkedInProfile.getFirstName() + " " + linkedInProfile.getLastName());
|
user.setName(linkedInProfile.getFirstName() + " " + linkedInProfile.getLastName());
|
||||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.LINKEDIN);
|
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.LINKEDIN);
|
||||||
user.setSecret(accessGrant.getAccessToken());
|
user.setSecret(accessGrant.getAccessToken());*/
|
||||||
|
|
||||||
|
LinkedInUser linkedInUser = this.linkedInCustomProvider.getUser(credentials.getTicket());
|
||||||
|
if (linkedInUser.getEmail() == null)
|
||||||
|
throw new UnauthorisedException("Cannot login user.LinkedIn account did not provide email");
|
||||||
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
|
user.setId(linkedInUser.getId());
|
||||||
|
user.setName(linkedInUser.getName());
|
||||||
|
user.setEmail(linkedInUser.getEmail());
|
||||||
|
user.setProvider(credentials.getProvider());
|
||||||
|
user.setSecret(credentials.getTicket());
|
||||||
|
|
||||||
return this.nonVerifiedUserAuthenticationService.Touch(user);
|
return this.nonVerifiedUserAuthenticationService.Touch(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinkedInResponseToken getAccessToken(LinkedInRequest linkedInRequest) {
|
||||||
|
return this.linkedInCustomProvider.getAccessToken(
|
||||||
|
linkedInRequest.getCode(), this.environment.getProperty("linkedin.login.redirect_uri"),
|
||||||
|
this.environment.getProperty("linkedin.login.clientId"), this.environment.getProperty("linkedin.login.clientSecret"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package eu.eudat.logic.security.validators.linkedin.helpers;
|
||||||
|
|
||||||
|
public class LinkedInRequest {
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package eu.eudat.logic.security.validators.linkedin.helpers;
|
||||||
|
|
||||||
|
public class LinkedInResponseToken {
|
||||||
|
|
||||||
|
private String accessToken;
|
||||||
|
private Integer expiresIn;
|
||||||
|
|
||||||
|
public String getAccessToken() {
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getExpiresIn() {
|
||||||
|
return expiresIn;
|
||||||
|
}
|
||||||
|
public void setExpiresIn(Integer expiresIn) {
|
||||||
|
this.expiresIn = expiresIn;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package eu.eudat.logic.security.validators.openaire;
|
||||||
|
|
||||||
|
import eu.eudat.exceptions.security.NonValidTokenException;
|
||||||
|
import eu.eudat.exceptions.security.NullEmailException;
|
||||||
|
import eu.eudat.logic.security.customproviders.OpenAIRE.OpenAIRECustomProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.OpenAIRE.OpenAIREUser;
|
||||||
|
import eu.eudat.logic.security.validators.TokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.openaire.helpers.OpenAIRERequest;
|
||||||
|
import eu.eudat.logic.security.validators.openaire.helpers.OpenAIREResponseToken;
|
||||||
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
|
import eu.eudat.models.data.login.LoginInfo;
|
||||||
|
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
@Component("openAIRETokenValidator")
|
||||||
|
public class OpenAIRETokenValidator implements TokenValidator {
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
|
private OpenAIRECustomProvider openAIRECustomProvider;
|
||||||
|
|
||||||
|
public OpenAIRETokenValidator(Environment environment, AuthenticationService nonVerifiedUserAuthenticationService, OpenAIRECustomProvider openAIRECustomProvider) {
|
||||||
|
this.environment = environment;
|
||||||
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
|
this.openAIRECustomProvider = openAIRECustomProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenAIREResponseToken getAccessToken(OpenAIRERequest openAIRERequest) {
|
||||||
|
return this.openAIRECustomProvider.getAccessToken(
|
||||||
|
openAIRERequest.getCode(), this.environment.getProperty("openaire.login.redirect_uri"),
|
||||||
|
this.environment.getProperty("openaire.login.client_id"), this.environment.getProperty("openaire.login.client_secret")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException, NullEmailException {
|
||||||
|
OpenAIREUser openAIREUser = this.openAIRECustomProvider.getUser(credentials.getTicket());
|
||||||
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
|
user.setId(openAIREUser.getId());
|
||||||
|
user.setEmail(openAIREUser.getEmail());
|
||||||
|
user.setName(openAIREUser.getName());
|
||||||
|
user.setProvider(credentials.getProvider());
|
||||||
|
user.setSecret(credentials.getTicket());
|
||||||
|
|
||||||
|
return this.nonVerifiedUserAuthenticationService.Touch(user);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package eu.eudat.logic.security.validators.openaire.helpers;
|
||||||
|
|
||||||
|
public class OpenAIRERequest {
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package eu.eudat.logic.security.validators.openaire.helpers;
|
||||||
|
|
||||||
|
public class OpenAIREResponseToken {
|
||||||
|
private String accessToken;
|
||||||
|
private Integer expiresIn;
|
||||||
|
|
||||||
|
public String getAccessToken() {
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getExpiresIn() {
|
||||||
|
return expiresIn;
|
||||||
|
}
|
||||||
|
public void setExpiresIn(Integer expiresIn) {
|
||||||
|
this.expiresIn = expiresIn;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,6 @@ import eu.eudat.logic.security.customproviders.ORCID.ORCIDUser;
|
||||||
import eu.eudat.logic.security.validators.TokenValidator;
|
import eu.eudat.logic.security.validators.TokenValidator;
|
||||||
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDRequest;
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDRequest;
|
||||||
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDResponseToken;
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDResponseToken;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
import eu.eudat.models.data.login.LoginInfo;
|
import eu.eudat.models.data.login.LoginInfo;
|
||||||
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||||
|
@ -25,14 +24,12 @@ public class ORCIDTokenValidator implements TokenValidator {
|
||||||
private ORCIDCustomProvider orcidCustomProvider;
|
private ORCIDCustomProvider orcidCustomProvider;
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
private AuthenticationService nonVerifiedUserAuthenticationService;
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
private ApiContext apiContext;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ORCIDTokenValidator(Environment environment, AuthenticationService nonVerifiedUserAuthenticationService, ORCIDCustomProvider orcidCustomProvider, ApiContext apiContext) {
|
public ORCIDTokenValidator(Environment environment, AuthenticationService nonVerifiedUserAuthenticationService, ORCIDCustomProvider orcidCustomProvider) {
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
this.orcidCustomProvider = orcidCustomProvider;
|
this.orcidCustomProvider = orcidCustomProvider;
|
||||||
this.apiContext = apiContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue