Merge branch 'ui-redesign' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot into ui-redesign

This commit is contained in:
apapachristou 2020-07-10 10:32:19 +03:00
commit 1a14ee0929
7 changed files with 41 additions and 17 deletions

View File

@ -14,6 +14,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.xml.bind.JAXBException;
import java.util.List;
import java.util.UUID;
@ -41,7 +42,7 @@ public class UserInvitationController extends BaseController {
@Transactional
@RequestMapping(method = RequestMethod.GET, value = {"/exchange/{invitationID}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<UUID>> exchange(@PathVariable UUID invitationID, Principal principal) {
ResponseEntity<ResponseItem<UUID>> exchange(@PathVariable UUID invitationID, Principal principal) throws JAXBException {
UUID dmpId = invitationsManager.assignUserAcceptedInvitation(invitationID, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(dmpId));
}

View File

@ -12,10 +12,11 @@ import eu.eudat.models.data.userinfo.UserInfoInvitationModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -38,6 +39,7 @@ public class InvitationsManager {
for (UserInfo userInfo : alreadySignedInUsersEntities) {
UserDMP userDMP = new UserDMP();
userDMP.setUser(userInfo);
userDMP.setRole(invitation.getRole());
userInfoToUserDmp.add(userDMP);
/*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(principalUser, userInfo)) {
UserAssociation userAssociation = new UserAssociation();
@ -47,7 +49,7 @@ public class InvitationsManager {
}*/
}
DMP dataManagementPlan = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan());
apiContext.getUtilitiesService().getInvitationService().createInvitations(apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao(), apiContext.getUtilitiesService().getMailService(), invitation.getUsers().stream().map(UserInfoInvitationModel::toDataModel).collect(Collectors.toList()), dataManagementPlan, principalUser);
apiContext.getUtilitiesService().getInvitationService().createInvitations(apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao(), apiContext.getUtilitiesService().getMailService(), invitation.getUsers().stream().map(UserInfoInvitationModel::toDataModel).collect(Collectors.toList()), dataManagementPlan, invitation.getRole(), principalUser);
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userInfoToUserDmp, dataManagementPlan);
}
@ -69,7 +71,7 @@ public class InvitationsManager {
return userModels;
}
public UUID assignUserAcceptedInvitation(UUID invitationID, Principal principal) throws UnauthorisedException {
public UUID assignUserAcceptedInvitation(UUID invitationID, Principal principal) throws UnauthorisedException, JAXBException {
eu.eudat.data.entities.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID);
if (invitation == null)
throw new UnauthorisedException("There is no Data Management Plan assigned to this Link");
@ -78,7 +80,14 @@ public class InvitationsManager {
UserDMP userDMP = new UserDMP();
userDMP.setUser(invitedUser);
userDMP.setDmp(invitation.getDmp());
userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue());
JAXBContext context = JAXBContext.newInstance(HashMap.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Map<String, Object> properties = (Map<String, Object>) unmarshaller.unmarshal(new StringReader(invitation.getProperties()));
if (properties.get("role") != null) {
userDMP.setRole((Integer) properties.get("role"));
} else {
userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue());
}
/*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(invitedUser, invitation.getUser())) {
UserAssociation userAssociation = new UserAssociation();
userAssociation.setFirstUser(invitedUser);

View File

@ -16,7 +16,7 @@ public interface InvitationService {
void assignToDmp(DMPDao dmpDao, eu.eudat.data.entities.UserDMP user, DMP dmp);
void createInvitations(InvitationDao invitationDao, MailService mailService, List<eu.eudat.data.entities.UserInfo> users, DMP dmp, eu.eudat.data.entities.UserInfo creator) throws MessagingException;
void createInvitations(InvitationDao invitationDao, MailService mailService, List<eu.eudat.data.entities.UserInfo> users, DMP dmp, Integer role, eu.eudat.data.entities.UserInfo creator) throws MessagingException;
CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService) throws MessagingException;
CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService, Integer role) throws MessagingException;
}

View File

@ -5,6 +5,7 @@ import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.InvitationDao;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Invitation;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.models.data.mail.SimpleMail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,7 +47,7 @@ public class InvitationServiceImpl implements InvitationService {
}
@Override
public void createInvitations(InvitationDao invitationDao, MailService mailService, List<eu.eudat.data.entities.UserInfo> users, DMP dmp, eu.eudat.data.entities.UserInfo creator) throws MessagingException {
public void createInvitations(InvitationDao invitationDao, MailService mailService, List<eu.eudat.data.entities.UserInfo> users, DMP dmp, Integer role, eu.eudat.data.entities.UserInfo creator) throws MessagingException {
for (eu.eudat.data.entities.UserInfo userInfo : users) {
Invitation invitation = new Invitation();
invitation.setDmp(dmp);
@ -54,16 +55,17 @@ public class InvitationServiceImpl implements InvitationService {
invitation.setUser(creator);
invitation.setToken(UUID.randomUUID());
invitation.setAcceptedInvitation(false);
invitation.setProperties("<role>" + role + "</role>");
invitationDao.createOrUpdate(invitation);
sendInvitationAsync(dmp, invitation, userInfo.getName(), mailService);
sendInvitationAsync(dmp, invitation, userInfo.getName(), mailService, role);
}
}
@Override
public CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService) {
public CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService, Integer role) {
return CompletableFuture.runAsync(() -> {
SimpleMail mail = new SimpleMail();
mail.setSubject(createSubject(dmp, mailService.getMailTemplateSubject()));
mail.setSubject(createSubject(dmp, mailService.getMailTemplateSubject(), role));
mail.setContent(createContent(invitation.getId(), dmp, recipient, mailService.getMailTemplateContent("classpath:templates/email/email.html")));
mail.setTo(invitation.getInvitationEmail());
try {
@ -74,8 +76,9 @@ public class InvitationServiceImpl implements InvitationService {
});
}
private String createSubject(DMP dmp, String templateSubject) {
private String createSubject(DMP dmp, String templateSubject, Integer role) {
String subject = templateSubject.replace("{dmpname}", dmp.getLabel());
subject = subject.replace("{dmprole}", UserDMP.UserDMPRoles.fromInteger(role).name());
return subject;
}

View File

@ -9,6 +9,7 @@ import java.util.UUID;
public class Invitation {
private UUID dataManagementPlan;
private List<UserInfoInvitationModel> users;
private Integer role;
public UUID getDataManagementPlan() {
return dataManagementPlan;
@ -25,4 +26,12 @@ public class Invitation {
public void setUsers(List<UserInfoInvitationModel> users) {
this.users = users;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
}

View File

@ -261,7 +261,7 @@
<tr>
<td>
<p>Dear {recipient},</p>
<p>You have been invited to collaborate to Data Management plan {dmpname}.</p>
<p>You have been invited to collaborate to Data Management plan {dmpname} with role {dmprole}.</p>
<p>Click the button to redirect to {dmpname}.</p>
<table border="0" cellpadding="0" cellspacing="0" class="btn btn-primary">

View File

@ -5,11 +5,13 @@ export class DmpInvitation {
public dataManagementPlan: string;
public users = new Array<DmpInvitationUser>();
public role: number;
buildForm(): FormGroup {
const formGroup = new FormBuilder().group({
dataManagementPlan: [this.dataManagementPlan],
users: [this.users]
users: [this.users],
role: [this.role]
});
return formGroup;