login button eudat
This commit is contained in:
commit
c2f5c4123b
|
@ -28,6 +28,8 @@ public class CredentialBuilder extends Builder<Credential> {
|
||||||
|
|
||||||
private Date lastUpdateTime;
|
private Date lastUpdateTime;
|
||||||
|
|
||||||
|
private String externalId;
|
||||||
|
|
||||||
public CredentialBuilder id(UUID id) {
|
public CredentialBuilder id(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
return this;
|
return this;
|
||||||
|
@ -68,6 +70,11 @@ public class CredentialBuilder extends Builder<Credential> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CredentialBuilder externalId(String externalId) {
|
||||||
|
this.externalId = externalId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Credential build() {
|
public Credential build() {
|
||||||
Credential credential = new Credential();
|
Credential credential = new Credential();
|
||||||
credential.setStatus(status);
|
credential.setStatus(status);
|
||||||
|
@ -78,6 +85,7 @@ public class CredentialBuilder extends Builder<Credential> {
|
||||||
credential.setPublicValue(publicValue);
|
credential.setPublicValue(publicValue);
|
||||||
credential.setUserInfo(userInfo);
|
credential.setUserInfo(userInfo);
|
||||||
credential.setId(id);
|
credential.setId(id);
|
||||||
|
credential.setExternalId(externalId);
|
||||||
return credential;
|
return credential;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@ import eu.eudat.models.login.Credentials;
|
||||||
import eu.eudat.models.login.LoginInfo;
|
import eu.eudat.models.login.LoginInfo;
|
||||||
import eu.eudat.models.security.Principal;
|
import eu.eudat.models.security.Principal;
|
||||||
import eu.eudat.security.CustomAuthenticationProvider;
|
import eu.eudat.security.CustomAuthenticationProvider;
|
||||||
|
import eu.eudat.security.validators.b2access.B2AccessTokenValidator;
|
||||||
|
import eu.eudat.security.validators.b2access.helpers.B2AccessRequest;
|
||||||
|
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||||
import eu.eudat.security.validators.twitter.TwitterTokenValidator;
|
import eu.eudat.security.validators.twitter.TwitterTokenValidator;
|
||||||
import eu.eudat.services.AuthenticationService;
|
import eu.eudat.services.AuthenticationService;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
@ -30,11 +33,14 @@ public class Login {
|
||||||
|
|
||||||
private TwitterTokenValidator twitterTokenValidator;
|
private TwitterTokenValidator twitterTokenValidator;
|
||||||
|
|
||||||
|
private B2AccessTokenValidator b2AccessTokenValidator;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService authenticationService, TwitterTokenValidator twitterTokenValidator) {
|
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService authenticationService, TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator) {
|
||||||
this.customAuthenticationProvider = customAuthenticationProvider;
|
this.customAuthenticationProvider = customAuthenticationProvider;
|
||||||
this.authenticationService = authenticationService;
|
this.authenticationService = authenticationService;
|
||||||
this.twitterTokenValidator = twitterTokenValidator;
|
this.twitterTokenValidator = twitterTokenValidator;
|
||||||
|
this.b2AccessTokenValidator = b2AccessTokenValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -76,6 +82,17 @@ public class Login {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = {"/b2AccessRequestToken"}, produces = "application/json", consumes = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem<B2AccessResponseToken>> b2AccessRequestToken(@RequestBody B2AccessRequest b2AccessRequest) {
|
||||||
|
try {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<B2AccessResponseToken>().payload(this.b2AccessTokenValidator.getAccessToken(b2AccessRequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<B2AccessResponseToken>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import eu.eudat.dao.databaselayer.service.DatabaseService;
|
||||||
import eu.eudat.entities.DataEntity;
|
import eu.eudat.entities.DataEntity;
|
||||||
|
|
||||||
|
|
||||||
public class DatabaseAccess<T extends DataEntity<T>> {
|
public class DatabaseAccess<T extends DataEntity> {
|
||||||
private DatabaseService<T> databaseService;
|
private DatabaseService<T> databaseService;
|
||||||
|
|
||||||
public DatabaseService<T> getDatabaseService() {
|
public DatabaseService<T> getDatabaseService() {
|
||||||
|
|
|
@ -2,13 +2,20 @@ package eu.eudat.dao;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.entities.DataEntity;
|
import eu.eudat.entities.DataEntity;
|
||||||
|
import eu.eudat.entities.Dataset;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
|
||||||
public interface DatabaseAccessLayer<T extends DataEntity<T>, I> {
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public interface DatabaseAccessLayer<T extends DataEntity, I> {
|
||||||
T createOrUpdate(T item);
|
T createOrUpdate(T item);
|
||||||
|
|
||||||
|
CompletableFuture<T> createOrUpdateAsync(T item);
|
||||||
|
|
||||||
T find(I id);
|
T find(I id);
|
||||||
|
|
||||||
|
T find(I id, String hint);
|
||||||
|
|
||||||
void delete(T item);
|
void delete(T item);
|
||||||
|
|
||||||
QueryableList<T> asQueryable();
|
QueryableList<T> asQueryable();
|
||||||
|
|
|
@ -13,7 +13,7 @@ import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
|
||||||
@Repository("databaseCtx")
|
@Repository("databaseCtx")
|
||||||
public class DatabaseContext<T extends DataEntity<T>> {
|
public class DatabaseContext<T extends DataEntity> {
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
@ -30,8 +30,8 @@ public class DatabaseContext<T extends DataEntity<T>> {
|
||||||
@Transactional
|
@Transactional
|
||||||
public T createOrUpdate(T item, Class<T> type) {
|
public T createOrUpdate(T item, Class<T> type) {
|
||||||
EntityManager entityManager = this.entityManager;
|
EntityManager entityManager = this.entityManager;
|
||||||
if (item.getKeys()[0] != null) {
|
if (item.getKeys() != null) {
|
||||||
T oldItem = entityManager.find(type, item.getKeys()[0]);
|
T oldItem = entityManager.find(type, item.getKeys());
|
||||||
if (oldItem != null) {
|
if (oldItem != null) {
|
||||||
oldItem.update(item);
|
oldItem.update(item);
|
||||||
entityManager.merge(oldItem);
|
entityManager.merge(oldItem);
|
||||||
|
@ -43,11 +43,6 @@ public class DatabaseContext<T extends DataEntity<T>> {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long count(Class<T> entityClass) {
|
|
||||||
EntityManager entityManager = this.entityManager;
|
|
||||||
return ((Number) entityManager.createQuery("select count(e) from " + entityClass.getSimpleName() + " e").getSingleResult()).longValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(T item) {
|
public void delete(T item) {
|
||||||
this.entityManager.remove(item);
|
this.entityManager.remove(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
@Service("databaseService")
|
@Service("databaseService")
|
||||||
public class DatabaseService<T extends DataEntity<T>> {
|
public class DatabaseService<T extends DataEntity> {
|
||||||
|
|
||||||
private DatabaseContext<T> databaseCtx;
|
private DatabaseContext<T> databaseCtx;
|
||||||
|
|
||||||
|
@ -32,10 +32,6 @@ public class DatabaseService<T extends DataEntity<T>> {
|
||||||
return this.databaseCtx.createOrUpdate(item, tClass);
|
return this.databaseCtx.createOrUpdate(item, tClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long count(Class<T> tClass) {
|
|
||||||
return this.databaseCtx.count(tClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(T item) {
|
public void delete(T item) {
|
||||||
this.databaseCtx.delete(item);
|
this.databaseCtx.delete(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,5 +17,4 @@ public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
||||||
|
|
||||||
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UserInfo principal);
|
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UserInfo principal);
|
||||||
|
|
||||||
Long count();
|
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
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 {
|
||||||
|
@ -78,7 +79,12 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long count() {
|
public CompletableFuture<DMP> createOrUpdateAsync(DMP item) {
|
||||||
return this.getDatabaseService().count(DMP.class);
|
return CompletableFuture.supplyAsync(()->this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DMP find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("dataRepositoryDao")
|
@Component("dataRepositoryDao")
|
||||||
public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implements DataRepositoryDao {
|
public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implements DataRepositoryDao {
|
||||||
|
@ -36,6 +37,16 @@ public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implem
|
||||||
return getDatabaseService().createOrUpdate(item, DataRepository.class);
|
return getDatabaseService().createOrUpdate(item, DataRepository.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<DataRepository> createOrUpdateAsync(DataRepository item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataRepository find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(DataRepository item) {
|
public void delete(DataRepository item) {
|
||||||
this.getDatabaseService().delete(item);
|
this.getDatabaseService().delete(item);
|
||||||
|
|
|
@ -15,9 +15,4 @@ public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
|
||||||
|
|
||||||
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal);
|
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal);
|
||||||
|
|
||||||
CompletableFuture<Dataset> createOrUpdateAsync(Dataset item);
|
|
||||||
|
|
||||||
Dataset find(UUID id, String hint);
|
|
||||||
|
|
||||||
Long count();
|
|
||||||
}
|
}
|
|
@ -61,11 +61,6 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long count() {
|
|
||||||
return this.getDatabaseService().count(Dataset.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Dataset item) {
|
public void delete(Dataset item) {
|
||||||
this.getDatabaseService().delete(item);
|
this.getDatabaseService().delete(item);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("datasetProfileDao")
|
@Component("datasetProfileDao")
|
||||||
public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implements DatasetProfileDao {
|
public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implements DatasetProfileDao {
|
||||||
|
@ -50,4 +51,14 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implem
|
||||||
public QueryableList<DatasetProfile> asQueryable() {
|
public QueryableList<DatasetProfile> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(DatasetProfile.class);
|
return this.getDatabaseService().getQueryable(DatasetProfile.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<DatasetProfile> createOrUpdateAsync(DatasetProfile item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatasetProfile find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@Component("externalDatasetDao")
|
@Component("externalDatasetDao")
|
||||||
|
@ -46,4 +47,14 @@ public class ExternalDatasetDaoImpl extends DatabaseAccess<ExternalDataset> impl
|
||||||
public QueryableList<ExternalDataset> asQueryable() {
|
public QueryableList<ExternalDataset> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(ExternalDataset.class);
|
return this.getDatabaseService().getQueryable(ExternalDataset.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<ExternalDataset> createOrUpdateAsync(ExternalDataset item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExternalDataset find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@Service("invitationDao")
|
@Service("invitationDao")
|
||||||
|
@ -43,4 +44,14 @@ public class InvitationDaoImpl extends DatabaseAccess<Invitation> implements Inv
|
||||||
public QueryableList<Invitation> asQueryable() {
|
public QueryableList<Invitation> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(Invitation.class);
|
return this.getDatabaseService().getQueryable(Invitation.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Invitation> createOrUpdateAsync(Invitation item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Invitation find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("organisationDao")
|
@Component("organisationDao")
|
||||||
public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements OrganisationDao {
|
public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements OrganisationDao {
|
||||||
|
@ -45,4 +46,14 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
|
||||||
public QueryableList<Organisation> asQueryable() {
|
public QueryableList<Organisation> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(Organisation.class);
|
return this.getDatabaseService().getQueryable(Organisation.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Organisation> createOrUpdateAsync(Organisation item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Organisation find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,4 @@ public interface ProjectDao extends DatabaseAccessLayer<Project, UUID> {
|
||||||
|
|
||||||
QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal);
|
QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal);
|
||||||
|
|
||||||
Long count();
|
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("projectDao")
|
@Component("projectDao")
|
||||||
public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDao {
|
public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDao {
|
||||||
|
@ -44,11 +45,6 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
|
||||||
return getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
|
return getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long count() {
|
|
||||||
return this.getDatabaseService().count(Project.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Project item) {
|
public void delete(Project item) {
|
||||||
this.getDatabaseService().delete(item);
|
this.getDatabaseService().delete(item);
|
||||||
|
@ -63,4 +59,14 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
|
||||||
query.where((builder, root) -> builder.equal(root.get("creator"), principal));
|
query.where((builder, root) -> builder.equal(root.get("creator"), principal));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Project> createOrUpdateAsync(Project item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Project find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("registryDao")
|
@Component("registryDao")
|
||||||
public class RegistryDaoImpl extends DatabaseAccess<Registry> implements RegistryDao {
|
public class RegistryDaoImpl extends DatabaseAccess<Registry> implements RegistryDao {
|
||||||
|
@ -45,4 +46,14 @@ public class RegistryDaoImpl extends DatabaseAccess<Registry> implements Registr
|
||||||
public QueryableList<Registry> asQueryable() {
|
public QueryableList<Registry> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(Registry.class);
|
return this.getDatabaseService().getQueryable(Registry.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Registry> createOrUpdateAsync(Registry item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Registry find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("researcherDao")
|
@Component("researcherDao")
|
||||||
public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements ResearcherDao {
|
public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements ResearcherDao {
|
||||||
|
@ -45,4 +46,14 @@ public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements Res
|
||||||
public QueryableList<Researcher> asQueryable() {
|
public QueryableList<Researcher> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(Researcher.class);
|
return this.getDatabaseService().getQueryable(Researcher.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Researcher> createOrUpdateAsync(Researcher item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Researcher find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("serviceDao")
|
@Component("serviceDao")
|
||||||
public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDao {
|
public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDao {
|
||||||
|
@ -45,4 +46,14 @@ public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDa
|
||||||
public QueryableList<Service> asQueryable() {
|
public QueryableList<Service> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(Service.class);
|
return this.getDatabaseService().getQueryable(Service.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Service> createOrUpdateAsync(Service item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Service find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ikalyvas on 2/8/2018.
|
* Created by ikalyvas on 2/8/2018.
|
||||||
|
@ -39,4 +40,14 @@ public class UserDmpDaoImpl extends DatabaseAccess<UserDMP> implements UserDmpDa
|
||||||
public QueryableList<UserDMP> asQueryable() {
|
public QueryableList<UserDMP> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(UserDMP.class);
|
return this.getDatabaseService().getQueryable(UserDMP.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<UserDMP> createOrUpdateAsync(UserDMP item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDMP find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Component("userInfoDao")
|
@Component("userInfoDao")
|
||||||
public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInfoDao {
|
public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInfoDao {
|
||||||
|
@ -49,4 +50,14 @@ public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInf
|
||||||
public QueryableList<UserInfo> asQueryable() {
|
public QueryableList<UserInfo> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(UserInfo.class);
|
return this.getDatabaseService().getQueryable(UserInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<UserInfo> createOrUpdateAsync(UserInfo item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserInfo find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@Component("userRoleDao")
|
@Component("userRoleDao")
|
||||||
|
@ -55,4 +56,14 @@ public class UserRoleDaoImpl extends DatabaseAccess<UserRole> implements UserRol
|
||||||
public QueryableList<UserRole> asQueryable() {
|
public QueryableList<UserRole> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(UserRole.class);
|
return this.getDatabaseService().getQueryable(UserRole.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<UserRole> createOrUpdateAsync(UserRole item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserRole find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@Component("credentialDao")
|
@Component("credentialDao")
|
||||||
|
@ -49,4 +50,14 @@ public class CredentialDaoImpl extends DatabaseAccess<Credential> implements Cre
|
||||||
public QueryableList<Credential> asQueryable() {
|
public QueryableList<Credential> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(Credential.class);
|
return this.getDatabaseService().getQueryable(Credential.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Credential> createOrUpdateAsync(Credential item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Credential find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@Component("userTokenDao")
|
@Component("userTokenDao")
|
||||||
|
@ -37,4 +38,14 @@ public class UserTokenDaoImpl extends DatabaseAccess<UserToken> implements UserT
|
||||||
public QueryableList<UserToken> asQueryable() {
|
public QueryableList<UserToken> asQueryable() {
|
||||||
return this.getDatabaseService().getQueryable(UserToken.class);
|
return this.getDatabaseService().getQueryable(UserToken.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<UserToken> createOrUpdateAsync(UserToken item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserToken find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,12 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Credential\"")
|
@Table(name = "\"Credential\"")
|
||||||
public class Credential implements DataEntity<Credential> {
|
@NamedEntityGraphs({
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "credentialUserInfo",
|
||||||
|
attributeNodes = {@NamedAttributeNode("userInfo")})
|
||||||
|
})
|
||||||
|
public class Credential implements DataEntity<Credential,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
|
@ -31,6 +36,9 @@ public class Credential implements DataEntity<Credential> {
|
||||||
@Column(name = "\"LastUpdateTime\"", nullable = false)
|
@Column(name = "\"LastUpdateTime\"", nullable = false)
|
||||||
private Date lastUpdateTime;
|
private Date lastUpdateTime;
|
||||||
|
|
||||||
|
@Column(name = "\"ExternalId\"", nullable = false)
|
||||||
|
private String externalId;
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +103,14 @@ public class Credential implements DataEntity<Credential> {
|
||||||
this.lastUpdateTime = lastUpdateTime;
|
this.lastUpdateTime = lastUpdateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExternalId() {
|
||||||
|
return externalId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalId(String externalId) {
|
||||||
|
this.externalId = externalId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -119,7 +135,7 @@ public class Credential implements DataEntity<Credential> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.*;
|
||||||
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
|
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
|
||||||
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")})
|
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")})
|
||||||
})
|
})
|
||||||
public class DMP implements Serializable, DataEntity<DMP> {
|
public class DMP implements DataEntity<DMP,UUID> {
|
||||||
|
|
||||||
public enum DMPStatus {
|
public enum DMPStatus {
|
||||||
ACTIVE((short) 0), DELETED((short) 1);
|
ACTIVE((short) 0), DELETED((short) 1);
|
||||||
|
@ -286,8 +286,8 @@ public class DMP implements Serializable, DataEntity<DMP> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DMPOrganisation\"")
|
@Table(name = "\"DMPOrganisation\"")
|
||||||
public class DMPOrganisation implements Serializable {
|
public class DMPOrganisation {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.entities;
|
package eu.eudat.entities;
|
||||||
|
|
||||||
public interface DataEntity<T> {
|
public interface DataEntity<T,K> {
|
||||||
void update(T entity);
|
void update(T entity);
|
||||||
|
|
||||||
Object[] getKeys();
|
K getKeys();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DataRepository\"")
|
@Table(name = "\"DataRepository\"")
|
||||||
public class DataRepository implements Serializable, DataEntity<DataRepository> {
|
public class DataRepository implements Serializable, DataEntity<DataRepository,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -147,7 +147,7 @@ public class DataRepository implements Serializable, DataEntity<DataRepository>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.*;
|
||||||
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("dataRepositories"), @NamedAttributeNode("externalDatasets"), @NamedAttributeNode("registries"),
|
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("dataRepositories"), @NamedAttributeNode("externalDatasets"), @NamedAttributeNode("registries"),
|
||||||
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")})
|
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")})
|
||||||
})
|
})
|
||||||
public class Dataset implements DataEntity<Dataset> {
|
public class Dataset implements DataEntity<Dataset,UUID> {
|
||||||
|
|
||||||
public static Set<String> getHints() {
|
public static Set<String> getHints() {
|
||||||
return hints;
|
return hints;
|
||||||
|
@ -313,7 +313,7 @@ public class Dataset implements DataEntity<Dataset> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetProfile\"")
|
@Table(name = "\"DatasetProfile\"")
|
||||||
public class DatasetProfile implements Serializable, DataEntity<DatasetProfile> {
|
public class DatasetProfile implements DataEntity<DatasetProfile,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -132,7 +132,7 @@ public class DatasetProfile implements Serializable, DataEntity<DatasetProfile>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetProfileRuleset\"")
|
@Table(name = "\"DatasetProfileRuleset\"")
|
||||||
public class DatasetProfileRuleset implements Serializable {
|
public class DatasetProfileRuleset {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetRegistry\"")
|
@Table(name = "\"DatasetRegistry\"")
|
||||||
public class DatasetRegistry implements Serializable {
|
public class DatasetRegistry {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetService\"")
|
@Table(name = "\"DatasetService\"")
|
||||||
public class DatasetService implements Serializable {
|
public class DatasetService {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"ExternalDataset\"")
|
@Table(name = "\"ExternalDataset\"")
|
||||||
public class ExternalDataset implements DataEntity<ExternalDataset> {
|
public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -104,7 +104,7 @@ public class ExternalDataset implements DataEntity<ExternalDataset> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Invitation\"")
|
@Table(name = "\"Invitation\"")
|
||||||
public class Invitation implements DataEntity<Invitation> {
|
public class Invitation implements DataEntity<Invitation,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -100,7 +100,7 @@ public class Invitation implements DataEntity<Invitation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Organisation\"")
|
@Table(name = "\"Organisation\"")
|
||||||
public class Organisation implements Serializable, DataEntity<Organisation> {
|
public class Organisation implements Serializable, DataEntity<Organisation,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -151,7 +151,7 @@ public class Organisation implements Serializable, DataEntity<Organisation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Project\"")
|
@Table(name = "\"Project\"")
|
||||||
public class Project implements DataEntity<Project> {
|
public class Project implements DataEntity<Project,UUID> {
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
|
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
|
||||||
|
@ -248,7 +248,7 @@ public class Project implements DataEntity<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Registry\"")
|
@Table(name = "\"Registry\"")
|
||||||
public class Registry implements DataEntity<Registry> {
|
public class Registry implements DataEntity<Registry,UUID> {
|
||||||
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -149,7 +149,7 @@ public class Registry implements DataEntity<Registry> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Researcher\"")
|
@Table(name = "\"Researcher\"")
|
||||||
public class Researcher implements DataEntity<Researcher> {
|
public class Researcher implements DataEntity<Researcher,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -150,7 +150,7 @@ public class Researcher implements DataEntity<Researcher> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Service\"")
|
@Table(name = "\"Service\"")
|
||||||
public class Service implements DataEntity<Service> {
|
public class Service implements DataEntity<Service, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -150,7 +150,7 @@ public class Service implements DataEntity<Service> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserDMP\"")
|
@Table(name = "\"UserDMP\"")
|
||||||
public class UserDMP implements DataEntity<UserDMP> {
|
public class UserDMP implements DataEntity<UserDMP, UUID> {
|
||||||
|
|
||||||
public enum UserDMPRoles {
|
public enum UserDMPRoles {
|
||||||
OWNER(0), USER(1);
|
OWNER(0), USER(1);
|
||||||
|
@ -90,7 +90,7 @@ public class UserDMP implements DataEntity<UserDMP> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.util.UUID;
|
||||||
name = "userInfo",
|
name = "userInfo",
|
||||||
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")})
|
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")})
|
||||||
})
|
})
|
||||||
public class UserInfo implements DataEntity<UserInfo> {
|
public class UserInfo implements DataEntity<UserInfo, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -173,7 +173,7 @@ public class UserInfo implements DataEntity<UserInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserRole\"")
|
@Table(name = "\"UserRole\"")
|
||||||
public class UserRole implements DataEntity<UserRole> {
|
public class UserRole implements DataEntity<UserRole, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -53,7 +53,7 @@ public class UserRole implements DataEntity<UserRole> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserToken\"")
|
@Table(name = "\"UserToken\"")
|
||||||
public class UserToken implements DataEntity<UserToken> {
|
public class UserToken implements DataEntity<UserToken, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
|
@ -62,7 +62,7 @@ public class UserToken implements DataEntity<UserToken> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.token == null ? null : this.token};
|
return this.token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ public class DashBoardManager {
|
||||||
|
|
||||||
public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) {
|
public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) {
|
||||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||||
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.count());
|
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.asQueryable().count());
|
||||||
statistics.setTotalDataSetCount(datasetRepository.count());
|
statistics.setTotalDataSetCount(datasetRepository.asQueryable().count());
|
||||||
statistics.setTotalProjectCount(projectRepository.count());
|
statistics.setTotalProjectCount(projectRepository.asQueryable().count());
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,9 @@ public class DataManagementPlanManager {
|
||||||
|
|
||||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
|
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
|
||||||
|
|
||||||
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
|
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
|
||||||
List<DataManagementPlanListingModel> datamanagementPlans = resultList.stream().map(item -> new DataManagementPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
|
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
||||||
dataTable.setData(datamanagementPlans);
|
dataTable.setData(resultList);
|
||||||
});
|
});
|
||||||
|
|
||||||
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
||||||
|
@ -62,7 +62,7 @@ public class DataManagementPlanManager {
|
||||||
|
|
||||||
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria) throws IllegalAccessException, InstantiationException {
|
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria) throws IllegalAccessException, InstantiationException {
|
||||||
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria());
|
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria());
|
||||||
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = items.toList().stream().map(item -> new DataManagementPlan().fromDataModel(item)).collect(Collectors.toList());
|
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = items.select(item -> new DataManagementPlan().fromDataModel(item));
|
||||||
return datamanagementPlans;
|
return datamanagementPlans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package eu.eudat.managers;
|
||||||
|
|
||||||
import eu.eudat.builders.entity.UserInfoBuilder;
|
import eu.eudat.builders.entity.UserInfoBuilder;
|
||||||
import eu.eudat.dao.entities.*;
|
import eu.eudat.dao.entities.*;
|
||||||
import eu.eudat.entities.Dataset;
|
|
||||||
import eu.eudat.entities.UserInfo;
|
import eu.eudat.entities.UserInfo;
|
||||||
import eu.eudat.models.HintedModelFactory;
|
import eu.eudat.models.HintedModelFactory;
|
||||||
import eu.eudat.models.criteria.DataRepositoryCriteria;
|
import eu.eudat.models.criteria.DataRepositoryCriteria;
|
||||||
|
@ -24,7 +23,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
|
||||||
public class DatasetManager {
|
public class DatasetManager {
|
||||||
|
@ -36,9 +34,9 @@ public class DatasetManager {
|
||||||
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
|
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
|
||||||
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
||||||
|
|
||||||
CompletableFuture<List<Dataset>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
|
CompletableFuture<List<DatasetListingModel>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).
|
||||||
List<DatasetListingModel> datasets = resultList.stream().map(item -> new DatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
|
selectAsync(item -> new DatasetListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
||||||
dataTable.setData(datasets);
|
dataTable.setData(resultList);
|
||||||
});
|
});
|
||||||
|
|
||||||
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
||||||
|
|
|
@ -19,20 +19,20 @@ public class DatasetProfileManager {
|
||||||
|
|
||||||
public static List<DatasetProfileAutocompleteItem> getWithCriteria(DatasetProfileDao datasetProfileRepository, DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException {
|
public static List<DatasetProfileAutocompleteItem> getWithCriteria(DatasetProfileDao datasetProfileRepository, DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException {
|
||||||
QueryableList<DatasetProfile> items = datasetProfileRepository.getWithCriteria(datasetProfileAutocompleteRequest.getCriteria());
|
QueryableList<DatasetProfile> items = datasetProfileRepository.getWithCriteria(datasetProfileAutocompleteRequest.getCriteria());
|
||||||
List<DatasetProfileAutocompleteItem> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileAutocompleteItem().fromDataModel(item)).collect(Collectors.toList());
|
List<DatasetProfileAutocompleteItem> datasetProfiles = items.select(item -> new DatasetProfileAutocompleteItem().fromDataModel(item));
|
||||||
return datasetProfiles;
|
return datasetProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataTableData<DatasetProfileListingModel> getPaged(ApiContext apiContext, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception {
|
public static DataTableData<DatasetProfileListingModel> getPaged(ApiContext apiContext, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception {
|
||||||
QueryableList<DatasetProfile> items = apiContext.getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
|
QueryableList<DatasetProfile> items = apiContext.getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
|
||||||
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem);
|
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem);
|
||||||
List<DatasetProfileListingModel> datasetProfiles = pagedItems.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
|
List<DatasetProfileListingModel> datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item));
|
||||||
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
|
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DatasetProfileListingModel> getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException {
|
public static List<DatasetProfileListingModel> getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException {
|
||||||
QueryableList<DatasetProfile> items = datasetProfileRepository.getAll();
|
QueryableList<DatasetProfile> items = datasetProfileRepository.getAll();
|
||||||
List<DatasetProfileListingModel> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
|
List<DatasetProfileListingModel> datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item));
|
||||||
return datasetProfiles;
|
return datasetProfiles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class DatasetWizardManager {
|
||||||
UserInfo userInfo = new UserInfo();
|
UserInfo userInfo = new UserInfo();
|
||||||
userInfo.setId(principal.getId());
|
userInfo.setId(principal.getId());
|
||||||
QueryableList<DMP> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest, userInfo);
|
QueryableList<DMP> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest, userInfo);
|
||||||
List<DataManagentPlanListingModel> dataManagementPlans = items.toList().stream().map(item -> new DataManagentPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
|
List<DataManagentPlanListingModel> dataManagementPlans = items.select(item -> new DataManagentPlanListingModel().fromDataModel(item));
|
||||||
return dataManagementPlans;
|
return dataManagementPlans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,14 @@ public class ExternalDatasetManager {
|
||||||
public DataTableData<ExternalDatasetListingModel> getPaged(ApiContext apiContext, ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception {
|
public DataTableData<ExternalDatasetListingModel> getPaged(ApiContext apiContext, ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception {
|
||||||
QueryableList<ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(externalDatasetTableRequest.getCriteria());
|
QueryableList<ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(externalDatasetTableRequest.getCriteria());
|
||||||
QueryableList<ExternalDataset> pagedItems = PaginationManager.applyPaging(items, externalDatasetTableRequest);
|
QueryableList<ExternalDataset> pagedItems = PaginationManager.applyPaging(items, externalDatasetTableRequest);
|
||||||
List<ExternalDatasetListingModel> externalDatasetListingmodels = pagedItems.toList().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
|
List<ExternalDatasetListingModel> externalDatasetListingmodels = pagedItems.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
|
||||||
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build();
|
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExternalDatasetListingModel> getWithExternal(ApiContext apiContext, String query, RemoteFetcher remoteFetcher) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException {
|
public List<ExternalDatasetListingModel> getWithExternal(ApiContext apiContext, String query, RemoteFetcher remoteFetcher) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException {
|
||||||
ExternalDatasetCriteria criteria = apiContext.getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
|
ExternalDatasetCriteria criteria = apiContext.getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
|
||||||
QueryableList<eu.eudat.entities.ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
|
QueryableList<eu.eudat.entities.ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
|
||||||
List<ExternalDatasetListingModel> externalDatasets = items.toList().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
|
List<ExternalDatasetListingModel> externalDatasets = items.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
|
||||||
return externalDatasets;
|
return externalDatasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class InvitationsManager {
|
||||||
|
|
||||||
public static List<UserInfoInvitationModel> getUsers(ApiContext apiContext, UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException {
|
public static List<UserInfoInvitationModel> getUsers(ApiContext apiContext, UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException {
|
||||||
QueryableList<UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria());
|
QueryableList<UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria());
|
||||||
List<UserInfoInvitationModel> userModels = users.toList().stream().map(item -> new UserInfoInvitationModel().fromDataModel(item)).collect(Collectors.toList());
|
List<UserInfoInvitationModel> userModels = users.select(item -> new UserInfoInvitationModel().fromDataModel(item));
|
||||||
return userModels;
|
return userModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,18 +6,21 @@ import eu.eudat.models.helpers.common.Ordering;
|
||||||
import eu.eudat.models.helpers.requests.TableRequest;
|
import eu.eudat.models.helpers.requests.TableRequest;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class PaginationManager {
|
public class PaginationManager {
|
||||||
|
|
||||||
public static <T extends DataEntity<T>> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
public static <T extends DataEntity> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||||
if (tableRequest.getOrderings() != null) applyOrder(items, tableRequest);
|
if (tableRequest.getOrderings() != null) applyOrder(items, tableRequest);
|
||||||
if (tableRequest.getLength() != null) items.take(tableRequest.getLength());
|
if (tableRequest.getLength() != null) items.take(tableRequest.getLength());
|
||||||
if (tableRequest.getOffset() != null) items.skip(tableRequest.getOffset());
|
if (tableRequest.getOffset() != null) items.skip(tableRequest.getOffset());
|
||||||
|
if (tableRequest.getSelection() != null && tableRequest.getSelection().getFields() != null && tableRequest.getSelection().getFields().length > 0)
|
||||||
|
items.withFields(Arrays.asList(tableRequest.getSelection().getFields()));
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends DataEntity<T>> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||||
ColumnOrderings columnOrderings = tableRequest.getOrderings();
|
ColumnOrderings columnOrderings = tableRequest.getOrderings();
|
||||||
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
|
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
|
||||||
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
|
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
|
||||||
|
@ -29,7 +32,7 @@ public class PaginationManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends DataEntity<T>> void applyAscOrder(QueryableList<T> items, Ordering ordering) {
|
private static <T extends DataEntity> void applyAscOrder(QueryableList<T> items, Ordering ordering) {
|
||||||
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
||||||
items.orderBy((builder, root) -> builder.asc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
items.orderBy((builder, root) -> builder.asc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
||||||
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
||||||
|
@ -40,7 +43,7 @@ public class PaginationManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends DataEntity<T>> void applyDescOrder(QueryableList<T> items, Ordering ordering) {
|
private static <T extends DataEntity> void applyDescOrder(QueryableList<T> items, Ordering ordering) {
|
||||||
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
||||||
items.orderBy((builder, root) -> builder.desc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
items.orderBy((builder, root) -> builder.desc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
||||||
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
||||||
|
|
|
@ -32,9 +32,8 @@ public class ProjectManager {
|
||||||
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items, projectTableRequest);
|
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items, projectTableRequest);
|
||||||
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<eu.eudat.models.project.ProjectListingModel>();
|
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<eu.eudat.models.project.ProjectListingModel>();
|
||||||
|
|
||||||
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).toListAsync().whenComplete((results, throwable) -> {
|
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> new ProjectListingModel().fromDataModel(item)).whenComplete((results, throwable) -> {
|
||||||
List<eu.eudat.models.project.ProjectListingModel> projects = results.stream().map(item -> new ProjectListingModel().fromDataModel(item)).collect(Collectors.toList());
|
dataTable.setData(results);
|
||||||
dataTable.setData(projects);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
CompletableFuture countFuture = pagedItems.countAsync().whenComplete((count, throwable) -> dataTable.setTotalCount(count));
|
CompletableFuture countFuture = pagedItems.countAsync().whenComplete((count, throwable) -> dataTable.setTotalCount(count));
|
||||||
|
@ -58,7 +57,7 @@ public class ProjectManager {
|
||||||
|
|
||||||
public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ApiContext apiContext, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
|
public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ApiContext apiContext, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
|
||||||
QueryableList<eu.eudat.entities.Project> items = apiContext.getDatabaseRepository().getProjectDao().getWithCriteria(projectCriteria.getCriteria());
|
QueryableList<eu.eudat.entities.Project> items = apiContext.getDatabaseRepository().getProjectDao().getWithCriteria(projectCriteria.getCriteria());
|
||||||
List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
|
List<eu.eudat.models.project.Project> projects = items.select(item -> new Project().fromDataModel(item));
|
||||||
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
|
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
|
||||||
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||||
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
|
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
|
||||||
|
@ -76,7 +75,7 @@ public class ProjectManager {
|
||||||
|
|
||||||
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
|
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
|
||||||
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
|
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
|
||||||
List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
|
List<eu.eudat.models.project.Project> projects = items.select(item -> new Project().fromDataModel(item));
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class UserManager {
|
||||||
QueryableList<eu.eudat.entities.UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria());
|
QueryableList<eu.eudat.entities.UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria());
|
||||||
QueryableList<eu.eudat.entities.UserInfo> pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem);
|
QueryableList<eu.eudat.entities.UserInfo> pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem);
|
||||||
|
|
||||||
List<UserListingModel> modelUsers = pagedUsers.toList().stream().map(item -> new UserListingModel().fromDataModel(item)).collect(Collectors.toList());
|
List<UserListingModel> modelUsers = pagedUsers.select(item -> new UserListingModel().fromDataModel(item));
|
||||||
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
|
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,20 @@ import eu.eudat.security.validators.TokenValidatorFactoryImpl;
|
||||||
|
|
||||||
public class LoginProviderUser {
|
public class LoginProviderUser {
|
||||||
private String name;
|
private String name;
|
||||||
|
private String id;
|
||||||
private String email;
|
private String email;
|
||||||
private String secret;
|
private String secret;
|
||||||
private boolean isVerified;
|
private boolean isVerified;
|
||||||
private TokenValidatorFactoryImpl.LoginProvider provider;
|
private TokenValidatorFactoryImpl.LoginProvider provider;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,17 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public interface QueryableList<T extends DataEntity<T>> {
|
public interface QueryableList<T extends DataEntity> {
|
||||||
QueryableList<T> where(SinglePredicate<T> predicate);
|
QueryableList<T> where(SinglePredicate<T> predicate);
|
||||||
|
|
||||||
<R> List<R> select(SelectPredicate<T, R> predicate);
|
<R> List<R> select(SelectPredicate<T, R> predicate);
|
||||||
|
|
||||||
|
<R> CompletableFuture<List<R>> selectAsync(SelectPredicate<T, R> predicate);
|
||||||
|
|
||||||
List<T> toList();
|
List<T> toList();
|
||||||
|
|
||||||
|
QueryableList<T> withFields(List<String> fields);
|
||||||
|
|
||||||
CompletableFuture<List<T>> toListAsync();
|
CompletableFuture<List<T>> toListAsync();
|
||||||
|
|
||||||
T getSingle();
|
T getSingle();
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class QueryableHibernateList<T extends DataEntity<T>> implements QueryableList<T> {
|
public class QueryableHibernateList<T extends DataEntity> implements QueryableList<T> {
|
||||||
|
|
||||||
private EntityManager manager;
|
private EntityManager manager;
|
||||||
private CriteriaQuery<T> query;
|
private CriteriaQuery<T> query;
|
||||||
|
@ -33,7 +33,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
private List<NestedQuerySinglePredicate<T>> nestedPredicates = new LinkedList<>();
|
private List<NestedQuerySinglePredicate<T>> nestedPredicates = new LinkedList<>();
|
||||||
|
|
||||||
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
|
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
|
||||||
private List<Selection> fields = new LinkedList<>();
|
private List<String> fields = new LinkedList<>();
|
||||||
private Integer length;
|
private Integer length;
|
||||||
private Integer offset;
|
private Integer offset;
|
||||||
private Set<String> hints;
|
private Set<String> hints;
|
||||||
|
@ -59,6 +59,18 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryableList<T> withFields(List<String> fields) {
|
||||||
|
this.fields = fields;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private QueryableList<T> selectFields() {
|
||||||
|
List<Selection> rootFields = fields.stream().map(field -> root.get(field)).collect(Collectors.toList());
|
||||||
|
this.query.select(this.manager.getCriteriaBuilder().construct(tClass, rootFields.toArray(new Selection[rootFields.size()])));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public QueryableHibernateList<T> setEntity(Class<T> type) {
|
public QueryableHibernateList<T> setEntity(Class<T> type) {
|
||||||
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
|
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
|
||||||
this.query = builder.createQuery(type);
|
this.query = builder.createQuery(type);
|
||||||
|
@ -94,12 +106,11 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
}
|
}
|
||||||
|
|
||||||
public <R> List<R> select(SelectPredicate<T, R> predicate) {
|
public <R> List<R> select(SelectPredicate<T, R> predicate) {
|
||||||
List<T> list = this.toList();
|
return this.toList().stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList());
|
||||||
List<R> newlist = new LinkedList<R>();
|
|
||||||
for (T item : list) {
|
|
||||||
newlist.add(predicate.applySelection(item));
|
|
||||||
}
|
}
|
||||||
return newlist;
|
|
||||||
|
public <R> CompletableFuture<List<R>> selectAsync(SelectPredicate<T, R> predicate) {
|
||||||
|
return this.toListAsync().thenApplyAsync(items -> items.stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryableList<T> distinct() {
|
public QueryableList<T> distinct() {
|
||||||
|
@ -163,14 +174,14 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> toList() {
|
public List<T> toList() {
|
||||||
|
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||||
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||||
if (this.hint != null && this.hints.contains(hint)) {
|
if (this.hint != null && this.hints.contains(hint)) {
|
||||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()[0]).collect(Collectors.toList());
|
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||||
if (ids != null && !ids.isEmpty()) typedQuery = queryWithHint(ids);
|
if (ids != null && !ids.isEmpty()) typedQuery = queryWithHint(ids);
|
||||||
}
|
}
|
||||||
return typedQuery.getResultList();
|
return typedQuery.getResultList();
|
||||||
|
@ -179,12 +190,13 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
public CompletableFuture<List<T>> toListAsync() {
|
public CompletableFuture<List<T>> toListAsync() {
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||||
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
if (this.hint != null && this.hints.contains(hint)) {
|
if (this.hint != null && this.hints.contains(hint)) {
|
||||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()[0]).collect(Collectors.toList());
|
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||||
if (ids != null && !ids.isEmpty()) return queryWithHint(ids).getResultList();
|
if (ids != null && !ids.isEmpty()) return queryWithHint(ids).getResultList();
|
||||||
}
|
}
|
||||||
return typedQuery.getResultList();
|
return typedQuery.getResultList();
|
||||||
|
@ -193,6 +205,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
|
|
||||||
public T getSingle() {
|
public T getSingle() {
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.hint != null)
|
if (this.hint != null)
|
||||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||||
|
@ -201,6 +214,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
|
|
||||||
public CompletableFuture<T> getSingleAsync() {
|
public CompletableFuture<T> getSingleAsync() {
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.hint != null)
|
if (this.hint != null)
|
||||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||||
|
@ -209,7 +223,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
|
|
||||||
public T getSingleOrDefault() {
|
public T getSingleOrDefault() {
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.hint != null)
|
if (this.hint != null)
|
||||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||||
|
@ -221,7 +235,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
|
|
||||||
public CompletableFuture<T> getSingleOrDefaultAsync() {
|
public CompletableFuture<T> getSingleOrDefaultAsync() {
|
||||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||||
|
if (this.fields != null && !this.fields.isEmpty()) this.selectFields();
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if (this.hint != null)
|
if (this.hint != null)
|
||||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||||
|
@ -236,7 +250,6 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
||||||
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(tClass);
|
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(tClass);
|
||||||
Root<T> criteriaRoot = criteriaQuery.from(this.tClass);
|
Root<T> criteriaRoot = criteriaQuery.from(this.tClass);
|
||||||
|
|
||||||
criteriaQuery.where(criteriaRoot.get("id").in(ids));
|
criteriaQuery.where(criteriaRoot.get("id").in(ids));
|
||||||
if (!this.orderings.isEmpty())
|
if (!this.orderings.isEmpty())
|
||||||
criteriaQuery.orderBy(this.generateOrderPredicates(this.orderings, criteriaRoot));
|
criteriaQuery.orderBy(this.generateOrderPredicates(this.orderings, criteriaRoot));
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package eu.eudat.security.customproviders;
|
||||||
|
|
||||||
|
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 2/22/2018.
|
||||||
|
*/
|
||||||
|
public interface B2AccessCustomProvider {
|
||||||
|
B2AccessUser getUser(String accessToken);
|
||||||
|
|
||||||
|
B2AccessResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret);
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package eu.eudat.security.customproviders;
|
||||||
|
|
||||||
|
import com.google.api.client.repackaged.org.apache.commons.codec.binary.Base64;
|
||||||
|
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
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.nio.charset.Charset;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 2/22/2018.
|
||||||
|
*/
|
||||||
|
@Component("b2AccessCustomProvider")
|
||||||
|
public class B2AccessCustomProviderImpl implements B2AccessCustomProvider {
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public B2AccessCustomProviderImpl(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public B2AccessUser 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("b2access.externallogin.user_info_url"), HttpMethod.GET, entity, Map.class).getBody();
|
||||||
|
B2AccessUser b2AccessUser = new B2AccessUser();
|
||||||
|
b2AccessUser.setEmail((String)values.get("email"));
|
||||||
|
b2AccessUser.setId((String)values.get("urn:oid:2.5.4.49"));
|
||||||
|
b2AccessUser.setName((String)values.get("name"));
|
||||||
|
return b2AccessUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public B2AccessResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret) {
|
||||||
|
RestTemplate template = new RestTemplate();
|
||||||
|
HttpHeaders headers = this.createBasicAuthHeaders(clientId, clientSecret);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
map.add("code", code);
|
||||||
|
map.add("grant_type", "authorization_code");
|
||||||
|
map.add("redirect_uri", redirectUri);
|
||||||
|
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);
|
||||||
|
B2AccessResponseToken b2AccessResponseToken = new B2AccessResponseToken();
|
||||||
|
b2AccessResponseToken.setAccessToken((String) values.get("access_token"));
|
||||||
|
return b2AccessResponseToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createBasicAuthHeaders(String username, String password) {
|
||||||
|
return new HttpHeaders() {{
|
||||||
|
String auth = username + ":" + password;
|
||||||
|
byte[] encodedAuth = Base64.encodeBase64(
|
||||||
|
auth.getBytes(Charset.forName("US-ASCII")));
|
||||||
|
String authHeader = "Basic " + new String(encodedAuth);
|
||||||
|
set("Authorization", authHeader);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createBearerAuthHeaders(String accessToken) {
|
||||||
|
return new HttpHeaders() {{
|
||||||
|
String authHeader = "Bearer " + new String(accessToken);
|
||||||
|
set("Authorization", authHeader);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package eu.eudat.security.customproviders;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 2/22/2018.
|
||||||
|
*/
|
||||||
|
public class B2AccessUser {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.security.validators;
|
package eu.eudat.security.validators;
|
||||||
|
|
||||||
|
import eu.eudat.security.validators.b2access.B2AccessTokenValidator;
|
||||||
import eu.eudat.security.validators.facebook.FacebookTokenValidator;
|
import eu.eudat.security.validators.facebook.FacebookTokenValidator;
|
||||||
import eu.eudat.security.validators.google.GoogleTokenValidator;
|
import eu.eudat.security.validators.google.GoogleTokenValidator;
|
||||||
import eu.eudat.security.validators.linkedin.LinkedInTokenValidator;
|
import eu.eudat.security.validators.linkedin.LinkedInTokenValidator;
|
||||||
|
@ -11,7 +12,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((short) 1), FACEBOOK((short) 2), TWITTER((short) 3), LINKEDIN((short) 4), NATIVELOGIN((short) 5);
|
GOOGLE((short) 1), FACEBOOK((short) 2), TWITTER((short) 3), LINKEDIN((short) 4), NATIVELOGIN((short) 5), B2_ACCESS((short) 6);
|
||||||
|
|
||||||
private short value;
|
private short value;
|
||||||
|
|
||||||
|
@ -35,6 +36,8 @@ public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
||||||
return LINKEDIN;
|
return LINKEDIN;
|
||||||
case 5:
|
case 5:
|
||||||
return NATIVELOGIN;
|
return NATIVELOGIN;
|
||||||
|
case 6:
|
||||||
|
return B2_ACCESS;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unsupported LoginProvider");
|
throw new RuntimeException("Unsupported LoginProvider");
|
||||||
}
|
}
|
||||||
|
@ -45,13 +48,16 @@ public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
||||||
private FacebookTokenValidator facebookTokenValidator;
|
private FacebookTokenValidator facebookTokenValidator;
|
||||||
private LinkedInTokenValidator linkedInTokenValidator;
|
private LinkedInTokenValidator linkedInTokenValidator;
|
||||||
private TwitterTokenValidator twitterTokenValidator;
|
private TwitterTokenValidator twitterTokenValidator;
|
||||||
|
private B2AccessTokenValidator b2AccessTokenValidator;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TokenValidatorFactoryImpl(GoogleTokenValidator googleTokenValidator, FacebookTokenValidator facebookTokenValidator, LinkedInTokenValidator linkedInTokenValidator, TwitterTokenValidator twitterTokenValidator) {
|
public TokenValidatorFactoryImpl(GoogleTokenValidator googleTokenValidator, FacebookTokenValidator facebookTokenValidator,
|
||||||
|
LinkedInTokenValidator linkedInTokenValidator, TwitterTokenValidator twitterTokenValidator,B2AccessTokenValidator b2AccessTokenValidator) {
|
||||||
this.googleTokenValidator = googleTokenValidator;
|
this.googleTokenValidator = googleTokenValidator;
|
||||||
this.facebookTokenValidator = facebookTokenValidator;
|
this.facebookTokenValidator = facebookTokenValidator;
|
||||||
this.linkedInTokenValidator = linkedInTokenValidator;
|
this.linkedInTokenValidator = linkedInTokenValidator;
|
||||||
this.twitterTokenValidator = twitterTokenValidator;
|
this.twitterTokenValidator = twitterTokenValidator;
|
||||||
|
this.b2AccessTokenValidator = b2AccessTokenValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenValidator getProvider(LoginProvider provider) {
|
public TokenValidator getProvider(LoginProvider provider) {
|
||||||
|
@ -64,6 +70,8 @@ public class TokenValidatorFactoryImpl implements TokenValidatorFactory {
|
||||||
return this.linkedInTokenValidator;
|
return this.linkedInTokenValidator;
|
||||||
case TWITTER:
|
case TWITTER:
|
||||||
return this.twitterTokenValidator;
|
return this.twitterTokenValidator;
|
||||||
|
case B2_ACCESS:
|
||||||
|
return this.b2AccessTokenValidator;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Login Provider Not Implemented");
|
throw new RuntimeException("Login Provider Not Implemented");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package eu.eudat.security.validators.b2access;
|
||||||
|
|
||||||
|
import eu.eudat.exceptions.security.NonValidTokenException;
|
||||||
|
import eu.eudat.models.login.LoginInfo;
|
||||||
|
import eu.eudat.models.loginprovider.LoginProviderUser;
|
||||||
|
import eu.eudat.models.security.Principal;
|
||||||
|
import eu.eudat.security.customproviders.B2AccessCustomProvider;
|
||||||
|
import eu.eudat.security.customproviders.B2AccessUser;
|
||||||
|
import eu.eudat.security.validators.TokenValidator;
|
||||||
|
import eu.eudat.security.validators.b2access.helpers.B2AccessRequest;
|
||||||
|
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||||
|
import eu.eudat.services.AuthenticationService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 2/22/2018.
|
||||||
|
*/
|
||||||
|
@Component("b2AccessTokenValidator ")
|
||||||
|
public class B2AccessTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
|
private B2AccessCustomProvider b2AccessCustomProvider;
|
||||||
|
private AuthenticationService authenticationService;
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public B2AccessTokenValidator(AuthenticationService authenticationService, Environment environment, B2AccessCustomProvider b2AccessCustomProvider) {
|
||||||
|
this.authenticationService = authenticationService;
|
||||||
|
this.environment = environment;
|
||||||
|
this.b2AccessCustomProvider = b2AccessCustomProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException {
|
||||||
|
B2AccessUser b2AccessUser = this.b2AccessCustomProvider.getUser(credentials.getTicket());
|
||||||
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
|
user.setId(b2AccessUser.getId());
|
||||||
|
user.setEmail(b2AccessUser.getEmail());
|
||||||
|
user.setName(b2AccessUser.getName());
|
||||||
|
user.setProvider(credentials.getProvider());
|
||||||
|
user.setSecret(credentials.getTicket());
|
||||||
|
return this.authenticationService.Touch(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public B2AccessResponseToken getAccessToken(B2AccessRequest b2AccessRequest) {
|
||||||
|
return this.b2AccessCustomProvider.getAccessToken(b2AccessRequest.getCode(), this.environment.getProperty("b2access.externallogin.redirect_uri")
|
||||||
|
, this.environment.getProperty("b2access.externallogin.clientid")
|
||||||
|
, this.environment.getProperty("b2access.externallogin.clientSecret"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package eu.eudat.security.validators.b2access.helpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 2/22/2018.
|
||||||
|
*/
|
||||||
|
public class B2AccessRequest {
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package eu.eudat.security.validators.b2access.helpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ikalyvas on 2/22/2018.
|
||||||
|
*/
|
||||||
|
public class B2AccessResponseToken {
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
public String getAccessToken() {
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,6 +44,7 @@ public class FacebookTokenValidator implements TokenValidator {
|
||||||
if (profile.getEmail() == null)
|
if (profile.getEmail() == null)
|
||||||
throw new UnauthorisedException("Cannot login user.Facebook account did not provide email");
|
throw new UnauthorisedException("Cannot login user.Facebook account did not provide email");
|
||||||
user.setEmail(profile.getEmail());
|
user.setEmail(profile.getEmail());
|
||||||
|
user.setId(profile.getId());
|
||||||
user.setIsVerified(profile.isVerified());
|
user.setIsVerified(profile.isVerified());
|
||||||
user.setName(profile.getName());
|
user.setName(profile.getName());
|
||||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.FACEBOOK);
|
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.FACEBOOK);
|
||||||
|
|
|
@ -47,11 +47,11 @@ public class GoogleTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public eu.eudat.models.security.Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException {
|
public eu.eudat.models.security.Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException {
|
||||||
|
|
||||||
GoogleIdToken idToken = this.verifyUserAndGetUser(credentials.getTicket());
|
GoogleIdToken idToken = this.verifyUserAndGetUser(credentials.getTicket());
|
||||||
Payload payload = idToken.getPayload();
|
Payload payload = idToken.getPayload();
|
||||||
LoginProviderUser user = new LoginProviderUser();
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
user.setSecret(credentials.getTicket());
|
user.setSecret(credentials.getTicket());
|
||||||
|
user.setId( payload.getSubject());
|
||||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.GOOGLE);
|
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.GOOGLE);
|
||||||
user.setName((String) payload.get("name"));
|
user.setName((String) payload.get("name"));
|
||||||
user.setEmail(payload.getEmail());
|
user.setEmail(payload.getEmail());
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class LinkedInTokenValidator implements TokenValidator {
|
||||||
if (linkedInProfile.getEmailAddress() == null)
|
if (linkedInProfile.getEmailAddress() == null)
|
||||||
throw new UnauthorisedException("Cannot login user.LinkedIn account did not provide email");
|
throw new UnauthorisedException("Cannot login user.LinkedIn account did not provide email");
|
||||||
user.setEmail(linkedInProfile.getEmailAddress());
|
user.setEmail(linkedInProfile.getEmailAddress());
|
||||||
|
user.setId(linkedInProfile.getId());
|
||||||
user.setIsVerified(true); //TODO
|
user.setIsVerified(true); //TODO
|
||||||
user.setName(linkedInProfile.getFirstName() + " " + linkedInProfile.getLastName());
|
user.setName(linkedInProfile.getFirstName() + " " + linkedInProfile.getLastName());
|
||||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.LINKEDIN);
|
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.LINKEDIN);
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class TwitterTokenValidator implements TokenValidator {
|
||||||
throw new UnauthorisedException("Cannot login user.Twitter account did not provide email");
|
throw new UnauthorisedException("Cannot login user.Twitter account did not provide email");
|
||||||
user.setEmail((String) values.get("email"));
|
user.setEmail((String) values.get("email"));
|
||||||
user.setIsVerified(true); //TODO
|
user.setIsVerified(true); //TODO
|
||||||
|
user.setId(""+profile.getId());
|
||||||
user.setName(profile.getName());
|
user.setName(profile.getName());
|
||||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.TWITTER);
|
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.TWITTER);
|
||||||
user.setSecret(finalOauthToken.getValue());
|
user.setSecret(finalOauthToken.getValue());
|
||||||
|
|
|
@ -91,12 +91,21 @@ public class AuthenticationService {
|
||||||
public Principal Touch(LoginProviderUser profile) {
|
public Principal Touch(LoginProviderUser profile) {
|
||||||
UserInfoCriteria criteria = new UserInfoCriteria();
|
UserInfoCriteria criteria = new UserInfoCriteria();
|
||||||
criteria.setEmail(profile.getEmail());
|
criteria.setEmail(profile.getEmail());
|
||||||
|
|
||||||
UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.equal(root.get("email"), profile.getEmail())).getSingleOrDefault();
|
UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.equal(root.get("email"), profile.getEmail())).getSingleOrDefault();
|
||||||
|
|
||||||
|
if(userInfo == null){
|
||||||
|
Optional<Credential> optionalCredential = Optional.ofNullable(apiContext.getDatabaseRepository().getCredentialDao()
|
||||||
|
.asQueryable().withHint("credentialUserInfo")
|
||||||
|
.where((builder, root) -> builder.and(builder.equal(root.get("provider"), profile.getProvider().getValue()), builder.equal(root.get("externalId"), profile.getId())))
|
||||||
|
.getSingleOrDefault());
|
||||||
|
userInfo = optionalCredential.map(Credential::getUserInfo).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
final Credential credential = this.apiContext.getBuilderFactory().getBuilder(CredentialBuilder.class)
|
final Credential credential = this.apiContext.getBuilderFactory().getBuilder(CredentialBuilder.class)
|
||||||
.id(UUID.randomUUID()).creationTime(new Date()).status(1)
|
.id(UUID.randomUUID()).creationTime(new Date()).status(1)
|
||||||
.lastUpdateTime(new Date()).provider((int) profile.getProvider().getValue())
|
.lastUpdateTime(new Date()).provider((int) profile.getProvider().getValue())
|
||||||
.secret(profile.getSecret())
|
.secret(profile.getSecret()).externalId(profile.getId())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (userInfo == null) {
|
if (userInfo == null) {
|
||||||
|
|
|
@ -50,3 +50,9 @@ spring.profiles.active=devel
|
||||||
autouser.root.email=root@dmp.com
|
autouser.root.email=root@dmp.com
|
||||||
autouser.root.password=root
|
autouser.root.password=root
|
||||||
autouser.root.username=root
|
autouser.root.username=root
|
||||||
|
#################################################################################
|
||||||
|
b2access.externallogin.user_info_url = https://unity.eudat-aai.fz-juelich.de:443/oauth2/userinfo
|
||||||
|
b2access.externallogin.access_token_url = https://unity.eudat-aai.fz-juelich.de:443/oauth2/token
|
||||||
|
b2access.externallogin.redirect_uri = http://dmp.eudat.org:4200/api/oauth/authorized/b2access
|
||||||
|
b2access.externallogin.clientid = eudatdmptool
|
||||||
|
b2access.externallogin.clientSecret = A3b*1*92
|
|
@ -6,6 +6,7 @@ import { HomepageComponent } from './homepage/homepage.component';
|
||||||
import { AuthGuard } from './guards/auth.guard';
|
import { AuthGuard } from './guards/auth.guard';
|
||||||
import { LoginComponent } from './user-management/login/login.component';
|
import { LoginComponent } from './user-management/login/login.component';
|
||||||
import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
|
import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
|
||||||
|
import { B2AccessLoginComponent } from './user-management/login/b2access/b2access-login.component';
|
||||||
|
|
||||||
const appRoutes: Routes = [
|
const appRoutes: Routes = [
|
||||||
{ path: 'datasets', loadChildren: './datasets/dataset.module#DatasetModule', canActivate: [AuthGuard] },
|
{ path: 'datasets', loadChildren: './datasets/dataset.module#DatasetModule', canActivate: [AuthGuard] },
|
||||||
|
@ -17,7 +18,8 @@ const appRoutes: Routes = [
|
||||||
{ path: "unauthorized", loadChildren: './unauthorized/unauthorized.module#UnauthorizedModule' },
|
{ path: "unauthorized", loadChildren: './unauthorized/unauthorized.module#UnauthorizedModule' },
|
||||||
{ path: "users", loadChildren: './users/users.module#UsersModule' },
|
{ path: "users", loadChildren: './users/users.module#UsersModule' },
|
||||||
{ path: "datasetsProfiles", loadChildren: './datasets-admin-listing/dataset-admin.module#DatasetAdminModule' },
|
{ path: "datasetsProfiles", loadChildren: './datasets-admin-listing/dataset-admin.module#DatasetAdminModule' },
|
||||||
{ path: "welcome", component: WelcomepageComponent }
|
{ path: "welcome", component: WelcomepageComponent },
|
||||||
|
{ path: "api/oauth/authorized/b2access", component: B2AccessLoginComponent }
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
@ -33,6 +33,7 @@ import { DatasetProfileModule } from './dataset-profile-form/dataset-profile.mod
|
||||||
import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
|
import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
|
||||||
import { HelpContentService } from './services/help-content/help-content.service';
|
import { HelpContentService } from './services/help-content/help-content.service';
|
||||||
import { HelpContentComponent } from './help-content/help-content.component';
|
import { HelpContentComponent } from './help-content/help-content.component';
|
||||||
|
import { B2AccessLoginComponent } from './user-management/login/b2access/b2access-login.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -40,7 +41,8 @@ import { HelpContentComponent } from './help-content/help-content.component';
|
||||||
PageNotFoundComponent,
|
PageNotFoundComponent,
|
||||||
HomepageComponent,
|
HomepageComponent,
|
||||||
WelcomepageComponent,
|
WelcomepageComponent,
|
||||||
HelpContentComponent
|
HelpContentComponent,
|
||||||
|
B2AccessLoginComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -53,7 +55,8 @@ import { HelpContentComponent } from './help-content/help-content.component';
|
||||||
LoginOptions.googleOauth,
|
LoginOptions.googleOauth,
|
||||||
LoginOptions.nativeLogin,
|
LoginOptions.nativeLogin,
|
||||||
LoginOptions.linkedInOauth,
|
LoginOptions.linkedInOauth,
|
||||||
LoginOptions.twitterOauth
|
LoginOptions.twitterOauth,
|
||||||
|
LoginOptions.b2Access
|
||||||
],
|
],
|
||||||
facebookConfiguration: { clientId: "110586756143149" },
|
facebookConfiguration: { clientId: "110586756143149" },
|
||||||
googleConfiguration: { clientId: '524432312250-sc9qsmtmbvlv05r44onl6l93ia3k9deo.apps.googleusercontent.com' },
|
googleConfiguration: { clientId: '524432312250-sc9qsmtmbvlv05r44onl6l93ia3k9deo.apps.googleusercontent.com' },
|
||||||
|
@ -64,7 +67,14 @@ import { HelpContentComponent } from './help-content/help-content.component';
|
||||||
accessTokenUri: "https://www.linkedin.com/oauth/v2/accessToken",
|
accessTokenUri: "https://www.linkedin.com/oauth/v2/accessToken",
|
||||||
clientSecret: "2OCO9e3wKylW05Tt"
|
clientSecret: "2OCO9e3wKylW05Tt"
|
||||||
},
|
},
|
||||||
twitterConfiguration: { clientId: "HiR4hQH9HNubKC5iKQy0l4mAZ", oauthUrl: "https://api.twitter.com/oauth/authenticate" }
|
twitterConfiguration: { clientId: "HiR4hQH9HNubKC5iKQy0l4mAZ", oauthUrl: "https://api.twitter.com/oauth/authenticate" },
|
||||||
|
b2accessConfiguration: {
|
||||||
|
clientId: "eudatdmptool",
|
||||||
|
clientSecret: "A3b*1*92",
|
||||||
|
oauthUrl: "https://unity.eudat-aai.fz-juelich.de/oauth2-as/oauth2-authz",
|
||||||
|
redirectUri: "http://dmp.eudat.org:4200/api/oauth/authorized/b2access",
|
||||||
|
accessTokenUri: "https://unity.eudat-aai.fz-juelich.de:443/oauth2/token"
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
HttpModule,
|
HttpModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
|
|
|
@ -2,7 +2,9 @@ export enum LoginProviders {
|
||||||
Google = 1,
|
Google = 1,
|
||||||
Facebook = 2,
|
Facebook = 2,
|
||||||
Twitter = 3,
|
Twitter = 3,
|
||||||
LinkedIn = 4
|
LinkedIn = 4,
|
||||||
|
NativeLogin = 5,
|
||||||
|
B2Accesss = 6
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LoginInfo {
|
export class LoginInfo {
|
||||||
|
|
|
@ -15,9 +15,8 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<ng-template #loginoption>
|
<ng-template #loginoption>
|
||||||
|
<button mat-button [routerLink]=" ['/login'] ">
|
||||||
<span class="login-label">Log in</span>
|
<span class="login-label">Log in</span>
|
||||||
<button mat-icon-button class="navbar-icon" [routerLink]=" ['/login'] ">
|
|
||||||
<mat-icon class="navbar-icon">input</mat-icon>
|
|
||||||
</button>
|
</button>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</mat-toolbar>
|
</mat-toolbar>
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { LoginService } from '../../utilties/login-service';
|
||||||
|
import { Component, OnInit } from '@angular/core'
|
||||||
|
import { Router, ActivatedRoute, Params } from '@angular/router';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'b2access-login',
|
||||||
|
templateUrl: './b2access-login.component.html',
|
||||||
|
})
|
||||||
|
export class B2AccessLoginComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private router: Router,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private loginService: LoginService
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.route.queryParams.subscribe((data: any) => {
|
||||||
|
if (!data["code"]) this.loginService.b2AccessGetAuthCode()
|
||||||
|
else this.loginService.b2AccessLogin(data["code"])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
<i class="fa fa-twitter"></i>
|
<i class="fa fa-twitter"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn btn_red"><span class="iconmedium"></span><a href="#"></a><span></span></div>
|
<button *ngIf="hasB2AccessOauth()" class="mat-icon-button" (click)="b2AccessLogin()" ><span class="iconmedium"></span><span></span></button>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="hasNativeLogin()">
|
<div *ngIf="hasNativeLogin()">
|
||||||
<!-- <p class="tip">Or Be Classical</p> -->
|
<!-- <p class="tip">Or Be Classical</p> -->
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<button mat-button (click)="nativeLogin()">LET'S GO</button>
|
<button mat-button (click)="nativeLogin()">LOGIN</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -45,6 +45,11 @@ export class LoginComponent implements OnInit {
|
||||||
public nativeLogin() {
|
public nativeLogin() {
|
||||||
this.loginService.nativeLogin(this.credential);
|
this.loginService.nativeLogin(this.credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public b2AccessLogin() {
|
||||||
|
return this.loginService.b2AccessInitialiseLogin();
|
||||||
|
}
|
||||||
|
|
||||||
public hasFacebookOauth(): boolean {
|
public hasFacebookOauth(): boolean {
|
||||||
return this.loginService.hasProvider(LoginOptions.facebookOauth);
|
return this.loginService.hasProvider(LoginOptions.facebookOauth);
|
||||||
}
|
}
|
||||||
|
@ -65,4 +70,8 @@ export class LoginComponent implements OnInit {
|
||||||
return this.loginService.hasProvider(LoginOptions.nativeLogin);
|
return this.loginService.hasProvider(LoginOptions.nativeLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public hasB2AccessOauth(): boolean {
|
||||||
|
return this.loginService.hasProvider(LoginOptions.b2Access);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,5 +4,6 @@ export enum LoginOptions{
|
||||||
twitterOauth = 3,
|
twitterOauth = 3,
|
||||||
googleOauth = 4,
|
googleOauth = 4,
|
||||||
nativeLogin = 5,
|
nativeLogin = 5,
|
||||||
all = 6
|
b2Access = 6,
|
||||||
|
all = 7,
|
||||||
}
|
}
|
|
@ -18,3 +18,10 @@ export class LinkedInConfiguration extends LoginProviderConfiguration {
|
||||||
public accessTokenUri: string
|
public accessTokenUri: string
|
||||||
public clientSecret: string
|
public clientSecret: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class B2AccessConfiguration extends LoginProviderConfiguration {
|
||||||
|
public oauthUrl: string
|
||||||
|
public redirectUri: string
|
||||||
|
public accessTokenUri: string
|
||||||
|
public clientSecret: string
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ import {
|
||||||
GoogleLoginConfiguration,
|
GoogleLoginConfiguration,
|
||||||
LinkedInConfiguration,
|
LinkedInConfiguration,
|
||||||
TwitterLoginConfiguration,
|
TwitterLoginConfiguration,
|
||||||
|
B2AccessConfiguration,
|
||||||
} from './LoginProviderConfiguration';
|
} from './LoginProviderConfiguration';
|
||||||
import { LoginOptions } from './LoginOptions';
|
import { LoginOptions } from './LoginOptions';
|
||||||
export class LoginServiceConfiguration {
|
export class LoginServiceConfiguration {
|
||||||
|
@ -11,4 +12,5 @@ export class LoginServiceConfiguration {
|
||||||
public googleConfiguration?: GoogleLoginConfiguration;
|
public googleConfiguration?: GoogleLoginConfiguration;
|
||||||
public twitterConfiguration?: TwitterLoginConfiguration;
|
public twitterConfiguration?: TwitterLoginConfiguration;
|
||||||
public linkedInConfiguration?: LinkedInConfiguration;
|
public linkedInConfiguration?: LinkedInConfiguration;
|
||||||
|
public b2accessConfiguration?: B2AccessConfiguration;
|
||||||
}
|
}
|
|
@ -56,6 +56,7 @@ export class LoginService {
|
||||||
case LoginOptions.googleOauth: return this.hasAllRequiredFieldsConfigured(this.config.googleConfiguration)
|
case LoginOptions.googleOauth: return this.hasAllRequiredFieldsConfigured(this.config.googleConfiguration)
|
||||||
case LoginOptions.linkedInOauth: return this.hasAllRequiredFieldsConfigured(this.config.linkedInConfiguration);
|
case LoginOptions.linkedInOauth: return this.hasAllRequiredFieldsConfigured(this.config.linkedInConfiguration);
|
||||||
case LoginOptions.twitterOauth: return this.hasAllRequiredFieldsConfigured(this.config.twitterConfiguration);
|
case LoginOptions.twitterOauth: return this.hasAllRequiredFieldsConfigured(this.config.twitterConfiguration);
|
||||||
|
case LoginOptions.b2Access: return this.hasAllRequiredFieldsConfigured(this.config.b2accessConfiguration);
|
||||||
case LoginOptions.nativeLogin: return true;
|
case LoginOptions.nativeLogin: return true;
|
||||||
default: throw new Error("Unsupported Provider Type")
|
default: throw new Error("Unsupported Provider Type")
|
||||||
}
|
}
|
||||||
|
@ -169,6 +170,31 @@ export class LoginService {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* B2ACCESS LOG IN
|
||||||
|
*/
|
||||||
|
|
||||||
|
public b2AccessInitialiseLogin() {
|
||||||
|
this.router.navigate(["/api/oauth/authorized/b2access"])
|
||||||
|
}
|
||||||
|
|
||||||
|
public b2AccessGetAuthCode() {
|
||||||
|
window.location.href = this.config.b2accessConfiguration.oauthUrl + "?response_type=code&client_id=" + this.config.b2accessConfiguration.clientId + "&redirect_uri=" + this.config.b2accessConfiguration.redirectUri + "&state=987654321&scope=USER_PROFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
public b2AccessLogin(code: String) {
|
||||||
|
let headers = new HttpHeaders();
|
||||||
|
headers = headers.set('Content-Type', 'application/json');
|
||||||
|
headers = headers.set('Accept', 'application/json');
|
||||||
|
this.httpClient.post(HostConfiguration.Server + "auth/b2AccessRequestToken", { code: code }, { headers: headers })
|
||||||
|
.subscribe((data: any) => {
|
||||||
|
this.authService.login({ ticket: data.payload.accessToken, provider: LoginProviders.B2Accesss, data: null }).subscribe(
|
||||||
|
res => this.onLogInSuccess(res),
|
||||||
|
error => this.onLogInError(error)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NATIVE LOGIN
|
* NATIVE LOGIN
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
Server: 'http://192.168.32.64:8080/api/',
|
Server: 'http://devel-21.local.cite.gr:8080/api/',
|
||||||
App: 'localhost:4200/'
|
App: 'localhost:4200/'
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
<script src="https://apis.google.com/js/platform.js"></script>
|
||||||
|
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||||
|
@ -12,14 +14,14 @@
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
<script src="//connect.facebook.net/en_US/all.js"></script>
|
<script src="//connect.facebook.net/en_US/all.js"></script>
|
||||||
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
|
||||||
<script src="https://apis.google.com/js/platform.js" async defer></script>
|
|
||||||
<script type="text/javascript" src="//platform.linkedin.com/in.js">
|
<script type="text/javascript" src="//platform.linkedin.com/in.js">
|
||||||
api_key: 86bl8vfk77clh9
|
api_key: 86bl8vfk77clh9
|
||||||
</script>
|
</script>
|
||||||
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
|
||||||
|
crossorigin="anonymous">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue