commit
f5d266554b
@ -0,0 +1,6 @@
|
||||
package eu.eudat.data.dao.criteria;
|
||||
|
||||
import eu.eudat.data.entities.EmailConfirmation;
|
||||
|
||||
public class EmailConfirmationCriteria extends Criteria<EmailConfirmation>{
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package eu.eudat.data.dao.criteria;
|
||||
|
||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
||||
|
||||
public class LoginConfirmationEmailCriteria extends Criteria<LoginConfirmationEmail>{
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package eu.eudat.data.dao.entities;
|
||||
|
||||
import eu.eudat.data.dao.DatabaseAccessLayer;
|
||||
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
|
||||
import eu.eudat.data.entities.EmailConfirmation;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface EmailConfirmationDao extends DatabaseAccessLayer<EmailConfirmation, UUID> {
|
||||
|
||||
QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria);
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package eu.eudat.data.dao.entities;
|
||||
|
||||
import eu.eudat.data.dao.DatabaseAccess;
|
||||
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
|
||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||
import eu.eudat.data.entities.EmailConfirmation;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service("LoginConfirmationEmailDao")
|
||||
public class EmailConfirmationDaoImpl extends DatabaseAccess<EmailConfirmation> implements EmailConfirmationDao {
|
||||
|
||||
@Autowired
|
||||
public EmailConfirmationDaoImpl(DatabaseService<EmailConfirmation> databaseService) {
|
||||
super(databaseService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailConfirmation createOrUpdate(EmailConfirmation item) {
|
||||
return this.getDatabaseService().createOrUpdate(item, EmailConfirmation.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<EmailConfirmation> createOrUpdateAsync(EmailConfirmation item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailConfirmation find(UUID id) {
|
||||
return this.getDatabaseService().getQueryable(EmailConfirmation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailConfirmation find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(EmailConfirmation item) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryableList<EmailConfirmation> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(EmailConfirmation.class);
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package eu.eudat.data.dao.entities;
|
||||
|
||||
import eu.eudat.data.dao.DatabaseAccessLayer;
|
||||
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
|
||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface LoginConfirmationEmailDao extends DatabaseAccessLayer<LoginConfirmationEmail, UUID> {
|
||||
|
||||
QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria);
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package eu.eudat.data.dao.entities;
|
||||
|
||||
import eu.eudat.data.dao.DatabaseAccess;
|
||||
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
|
||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service("LoginConfirmationEmailDao")
|
||||
public class LoginConfirmationEmailDaoImpl extends DatabaseAccess<LoginConfirmationEmail> implements LoginConfirmationEmailDao {
|
||||
|
||||
@Autowired
|
||||
public LoginConfirmationEmailDaoImpl(DatabaseService<LoginConfirmationEmail> databaseService) {
|
||||
super(databaseService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginConfirmationEmail createOrUpdate(LoginConfirmationEmail item) {
|
||||
return this.getDatabaseService().createOrUpdate(item, LoginConfirmationEmail.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<LoginConfirmationEmail> createOrUpdateAsync(LoginConfirmationEmail item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginConfirmationEmail find(UUID id) {
|
||||
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginConfirmationEmail find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(LoginConfirmationEmail item) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryableList<LoginConfirmationEmail> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package eu.eudat.data.dao.entities;
|
||||
|
||||
import eu.eudat.data.dao.DatabaseAccessLayer;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.data.entities.UserDatasetProfile;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/8/2018.
|
||||
*/
|
||||
public interface UserDatasetProfileDao extends DatabaseAccessLayer<UserDatasetProfile, UUID> {
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package eu.eudat.data.dao.entities;
|
||||
|
||||
import eu.eudat.data.dao.DatabaseAccess;
|
||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.data.entities.UserDatasetProfile;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("userDatasetProfileDao")
|
||||
public class UserDatasetProfileDaoImpl extends DatabaseAccess<UserDatasetProfile> implements UserDatasetProfileDao {
|
||||
|
||||
@Autowired
|
||||
public UserDatasetProfileDaoImpl(DatabaseService<UserDatasetProfile> databaseService) {
|
||||
super(databaseService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDatasetProfile createOrUpdate(UserDatasetProfile item) {
|
||||
return this.getDatabaseService().createOrUpdate(item, UserDatasetProfile.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDatasetProfile find(UUID id) {
|
||||
return this.getDatabaseService().getQueryable(UserDatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(UserDatasetProfile item) {
|
||||
this.getDatabaseService().delete(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryableList<UserDatasetProfile> asQueryable() {
|
||||
return this.getDatabaseService().getQueryable(UserDatasetProfile.class);
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public CompletableFuture<UserDatasetProfile> createOrUpdateAsync(UserDatasetProfile item) {
|
||||
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDatasetProfile find(UUID id, String hint) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package eu.eudat.data.entities;
|
||||
|
||||
import eu.eudat.data.entities.helpers.EntityBinder;
|
||||
import eu.eudat.queryable.queryableentity.DataEntity;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "\"UserDatasetProfile\"")
|
||||
public class UserDatasetProfile implements DataEntity<UserDatasetProfile, UUID> {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "usr")
|
||||
private UserInfo user;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "\"datasetProfile\"")
|
||||
private DatasetProfile datasetProfile;
|
||||
|
||||
@Column(name = "role")
|
||||
private Integer role;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public UserInfo getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(UserInfo user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public DatasetProfile getDatasetProfile() {
|
||||
return datasetProfile;
|
||||
}
|
||||
|
||||
public void setDatasetProfile(DatasetProfile datasetProfile) {
|
||||
this.datasetProfile = datasetProfile;
|
||||
}
|
||||
|
||||
public Integer getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(Integer role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(UserDatasetProfile entity) {
|
||||
this.role = entity.getRole();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getKeys() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDatasetProfile buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
||||
String currentBase = base.isEmpty() ? "" : base + ".";
|
||||
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
||||
import eu.eudat.logic.managers.EmailConfirmationManager;
|
||||
import eu.eudat.logic.managers.MergeEmailConfirmationManager;
|
||||
import eu.eudat.logic.security.CustomAuthenticationProvider;
|
||||
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.models.data.userinfo.UserMergeRequestModel;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "api/emailMergeConfirmation")
|
||||
public class EmailMergeConfirmation {
|
||||
|
||||
private MergeEmailConfirmationManager emailConfirmationManager;
|
||||
|
||||
@Autowired
|
||||
public EmailMergeConfirmation(MergeEmailConfirmationManager emailConfirmationManager) {
|
||||
this.emailConfirmationManager = emailConfirmationManager;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/{emailToken}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem> emailConfirmation(@PathVariable(value = "emailToken") String token) {
|
||||
try {
|
||||
this.emailConfirmationManager.confirmEmail(token);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch
|
||||
(HasConfirmedEmailException | TokenExpiredException ex) {
|
||||
if (ex instanceof TokenExpiredException) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity sendConfirmatioEmail(@RequestBody UserMergeRequestModel requestModel, Principal principal) {
|
||||
try {
|
||||
this.emailConfirmationManager.sendConfirmationEmail(requestModel.getEmail(), principal, requestModel.getUserId(), requestModel.getProvider());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch (Exception ex) {
|
||||
if (ex instanceof HasConfirmedEmailException) {
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.data.entities.Service;
|
||||
import eu.eudat.logic.managers.ServiceManager;
|
||||
import eu.eudat.logic.managers.ValidationManager;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.models.data.services.ServiceModel;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = {"/api"})
|
||||
public class Validation extends BaseController {
|
||||
|
||||
private ValidationManager validationManager;
|
||||
|
||||
@Autowired
|
||||
public Validation(ApiContext apiContext, ValidationManager validationManager) {
|
||||
super(apiContext);
|
||||
this.validationManager = validationManager;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/external/validation"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Boolean>> validate(
|
||||
@RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal
|
||||
) throws HugeResultSet, NoURLFound {
|
||||
Boolean isValid = this.validationManager.validateIdentifier(query, type, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Boolean>().payload(isValid).status(ApiMessageCode.NO_MESSAGE));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,113 @@
|
||||
package eu.eudat.logic.managers;
|
||||
|
||||
import eu.eudat.data.entities.Credential;
|
||||
import eu.eudat.data.entities.EmailConfirmation;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.data.entities.UserToken;
|
||||
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.queryable.jpa.predicates.OrderByPredicate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class MergeEmailConfirmationManager {
|
||||
private static Logger logger = LoggerFactory.getLogger(MergeEmailConfirmationManager.class);
|
||||
private ApiContext apiContext;
|
||||
private DatabaseRepository databaseRepository;
|
||||
|
||||
@Autowired
|
||||
public MergeEmailConfirmationManager(ApiContext apiContext) {
|
||||
this.apiContext = apiContext;
|
||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
|
||||
EmailConfirmation loginConfirmationEmail = apiContext.getOperationsContext()
|
||||
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
||||
|
||||
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
|
||||
throw new TokenExpiredException("Token has expired.");
|
||||
|
||||
UserInfo userToBeMerged = databaseRepository.getUserInfoDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
||||
|
||||
try {
|
||||
Map<String, Object> map = new ObjectMapper().readValue(loginConfirmationEmail.getData(), HashMap.class);
|
||||
UUID otherUserId = UUID.fromString((String) map.get("userId"));
|
||||
UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("id"), otherUserId)).getSingle();
|
||||
|
||||
// Checks if mail is used by another user. If it is, merges the new the old.
|
||||
mergeNewUserToOld(user, userToBeMerged, Integer.valueOf((String) map.get("provider")));
|
||||
expireUserToken(userToBeMerged);
|
||||
loginConfirmationEmail.setIsConfirmed(true);
|
||||
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendConfirmationEmail(String email, Principal principal, UUID userId, Integer provider) throws HasConfirmedEmailException {
|
||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
|
||||
if (user.getEmail() != null && !user.getEmail().equals(email)) {
|
||||
apiContext.getUtilitiesService().getConfirmationEmailService().createMergeConfirmationEmail(
|
||||
databaseRepository.getLoginConfirmationEmailDao(),
|
||||
apiContext.getUtilitiesService().getMailService(),
|
||||
email,
|
||||
userId,
|
||||
principal,
|
||||
provider
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser, Integer provider) {
|
||||
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.and(builder.equal(root.get("userInfo"), oldUser), builder.equal(root.get("provider"), provider))).getSingle();
|
||||
credential.setUserInfo(newUser);
|
||||
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
||||
List<UserDMP> userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList();
|
||||
userDmps.forEach(userDmp -> {
|
||||
userDmp.setUser(newUser);
|
||||
databaseRepository.getUserDmpDao().createOrUpdate(userDmp);
|
||||
});
|
||||
oldUser.setUserStatus((short)1);
|
||||
oldUser.setEmail(null);
|
||||
List<Credential> credentials = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), oldUser)).toList();
|
||||
credentials.forEach(cred -> {
|
||||
if (cred.getId() != credential.getId()) {
|
||||
databaseRepository.getCredentialDao().delete(cred);
|
||||
}
|
||||
});
|
||||
databaseRepository.getUserInfoDao().createOrUpdate(oldUser);
|
||||
}
|
||||
|
||||
private void expireUserToken(UserInfo user) {
|
||||
UserToken userToken = databaseRepository.getUserTokenDao().asQueryable()
|
||||
.where((builder, root) -> builder.equal(root.get("user"), user))
|
||||
.orderBy((builder, root) -> builder.desc(root.get("issuedAt")))
|
||||
.take(1).toList().get(0);
|
||||
userToken.setExpiresAt(new Date());
|
||||
databaseRepository.getUserTokenDao().createOrUpdate(userToken);
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package eu.eudat.logic.managers;
|
||||
|
||||
import io.prometheus.client.Gauge;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.transaction.Transactional;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Component
|
||||
public class MetricsManager {
|
||||
private final static Logger logger = LoggerFactory.getLogger(MetricsManager.class);
|
||||
private static Map<String, Gauge> gauges = Stream.of( new Object[][]{
|
||||
{"argos_managed_dmps", Gauge.build().name("argos_managed_dmps").help("Number of managed DMPs").labelNames("status").register()},
|
||||
|
||||
{"argos_funders", Gauge.build().name("argos_funders").help("Number of registered Funders").register()},
|
||||
{"argos_grants", Gauge.build().name("argos_grants").help("Number of registered Grants").register()},
|
||||
{"argos_projects", Gauge.build().name("argos_projects").help("Number of registered Projects").register()},
|
||||
{"argos_researchers", Gauge.build().name("argos_researchers").help("Number of Colaborators/Researchers").register()},
|
||||
|
||||
{"argos_managed_dataset_descriptions", Gauge.build().name("argos_managed_dataset_descriptions").help("Number of managed Dataset Descriptions").labelNames("status").register()},
|
||||
|
||||
{"argos_dataset_templates", Gauge.build().name("argos_dataset_templates").help("Number of dataset Templates").labelNames("status").register()},
|
||||
|
||||
{"argos_users", Gauge.build().name("argos_users").help("Number of users").labelNames("type").register()},
|
||||
|
||||
{"argos_languages", Gauge.build().name("argos_languages").help("Number of Languages").register()},
|
||||
|
||||
}).collect(Collectors.toMap(data -> (String)data[0], data -> (Gauge) data[1]));
|
||||
|
||||
public static void increaseValue(String name, int amount, String label) {
|
||||
|
||||
if(label != null) {
|
||||
gauges.get(name).labels(label).inc(amount);
|
||||
} else {
|
||||
gauges.get(name).inc(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public static void decreaseValue(String name, int amount, String label) {
|
||||
if(label != null) {
|
||||
gauges.get(name).labels(label).dec(amount);
|
||||
} else {
|
||||
gauges.get(name).dec(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getValue(String name, String label) {
|
||||
if(label != null) {
|
||||
return Double.valueOf(gauges.get(name).labels(label).get()).intValue();
|
||||
} else {
|
||||
return Double.valueOf(gauges.get(name).get()).intValue();
|
||||
}
|
||||
}
|
||||
|
||||
public static void calculateValue(String name, int amount, String label) {
|
||||
Integer orig = getValue(name, label);
|
||||
int diff = orig - amount;
|
||||
if (diff != 0) {
|
||||
if (diff > 0) {
|
||||
decreaseValue(name, diff, label);
|
||||
} else {
|
||||
increaseValue(name, Math.abs(diff), label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final DatasetManager datasetManager;
|
||||
private final DataManagementPlanManager dataManagementPlanManager;
|
||||
private final DatasetProfileManager datasetProfileManager;
|
||||
private final UserManager userManager;
|
||||
private final Environment environment;
|
||||
|
||||
@Autowired
|
||||
public MetricsManager(DatasetManager datasetManager, DataManagementPlanManager dataManagementPlanManager, DatasetProfileManager datasetProfileManager, UserManager userManager, Environment environment) {
|
||||
this.datasetManager = datasetManager;
|
||||
this.dataManagementPlanManager = dataManagementPlanManager;
|
||||
this.datasetProfileManager = datasetProfileManager;
|
||||
this.userManager = userManager;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@Transactional
|
||||
@Scheduled(initialDelay = 1000 * 60 * 60, fixedDelay = 1000 * 60 * 60)
|
||||
public void init() throws IOException {
|
||||
logger.info("Start calculating Metrics");
|
||||
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllDrafts(), "draft");
|
||||
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllFinalized(), "finalized");
|
||||
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllPublished(), "published");
|
||||
calculateValue("argos_managed_dmps", (int) dataManagementPlanManager.countAllDoied(), "doied");
|
||||
|
||||
calculateValue("argos_funders", (int) dataManagementPlanManager.countAllFunders(), null);
|
||||
calculateValue("argos_grants", (int) dataManagementPlanManager.countAllGrants(), null);
|
||||
calculateValue("argos_projects", (int) dataManagementPlanManager.countAllProjects(), null);
|
||||
calculateValue("argos_researchers", (int) dataManagementPlanManager.countAllResearchers(), null);
|
||||
|
||||
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllDraft(), "draft");
|
||||
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllFinalized(), "finalized");
|
||||
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllPublic(), "published");
|
||||
calculateValue("argos_managed_dataset_descriptions", (int) datasetManager.countAllWithDoi(), "doied");
|
||||
|
||||
calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAlldraft(), "total");
|
||||
calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAllFinalized(), "active");
|
||||
calculateValue("argos_dataset_templates", (int) datasetProfileManager.countAllUsed(), "used");
|
||||
|
||||
calculateValue("argos_users", (int) userManager.countActiveUsers().intValue(), "loggedin");
|
||||
calculateValue("argos_users", (int) userManager.countAllUsers().intValue(), "total");
|
||||
|
||||
long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count();
|
||||
calculateValue("argos_languages", (int) files, null);
|
||||
|
||||
logger.info("Metrics calculation Completed");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package eu.eudat.logic.managers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
|
||||
@Component
|
||||
public class ValidationManager {
|
||||
|
||||
private RemoteFetcher remoteFetcher;
|
||||
|
||||
@Autowired
|
||||
public ValidationManager(RemoteFetcher remoteFetcher) {
|
||||
super();
|
||||
this.remoteFetcher = remoteFetcher;
|
||||
}
|
||||
|
||||
public Boolean validateIdentifier(String identifier, String type, Principal principal) throws NoURLFound, HugeResultSet {
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(identifier);
|
||||
Integer count = this.remoteFetcher.findEntries(externalUrlCriteria, type);
|
||||
return principal != null && count > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package eu.eudat.logic.proxy.config.entities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
|
||||
import eu.eudat.logic.proxy.config.FetchStrategy;
|
||||
import eu.eudat.logic.proxy.config.UrlConfiguration;
|
||||
|
||||
public class ValidationUrls {
|
||||
|
||||
List<UrlConfiguration> urls;
|
||||
FetchStrategy fetchMode;
|
||||
|
||||
public List<UrlConfiguration> getUrls() {
|
||||
return urls;
|
||||
}
|
||||
|
||||
@XmlElementWrapper
|
||||
@XmlElement(name = "urlConfig")
|
||||
public void setUrls(List<UrlConfiguration> urls) {
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public FetchStrategy getFetchMode() {
|
||||
return fetchMode;
|
||||
}
|
||||
|
||||
@XmlElement(name = "fetchMode")
|
||||
public void setFetchMode(FetchStrategy fetchMode) {
|
||||
this.fetchMode = fetchMode;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,13 +1,18 @@
|
||||
package eu.eudat.logic.services.utilities;
|
||||
|
||||
import eu.eudat.data.dao.entities.LoginConfirmationEmailDao;
|
||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
||||
import eu.eudat.data.dao.entities.EmailConfirmationDao;
|
||||
import eu.eudat.data.entities.EmailConfirmation;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface ConfirmationEmailService {
|
||||
public void createConfirmationEmail(LoginConfirmationEmailDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId);
|
||||
public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId);
|
||||
|
||||
public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, Principal principal, Integer provider);
|
||||
|
||||
public CompletableFuture sentConfirmationEmail(LoginConfirmationEmail confirmationEmail, MailService mailService);
|
||||
public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService);
|
||||
|
||||
public CompletableFuture sentMergeConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService, String userName);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package eu.eudat.models.data.components.commons.datafield;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ValidationData extends FieldData<ValidationData> {
|
||||
@Override
|
||||
public ValidationData fromData(Object data) {
|
||||
if (data != null) {
|
||||
this.setLabel((String) ((Map<String, Object>) data).get("label"));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toXml(Document doc) {
|
||||
Element root = doc.createElement("data");
|
||||
root.setAttribute("label", this.getLabel());
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationData fromXml(Element item) {
|
||||
this.setLabel(item != null ? item.getAttribute("label") : "");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap(Element item) {
|
||||
HashMap dataMap = new HashMap();
|
||||
dataMap.put("label", item != null ? item.getAttribute("label") : "");
|
||||
return dataMap;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue