package eu.eudat.controllers; import eu.eudat.data.query.items.item.userinfo.UserInfoRequestItem; import eu.eudat.logic.managers.InvitationsManager; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.invitation.Invitation; import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.userinfo.UserInfoInvitationModel; 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 javax.xml.bind.JAXBException; import java.util.List; import java.util.UUID; @RequestMapping("api/invite/") @RestController @CrossOrigin public class UserInvitationController extends BaseController { private InvitationsManager invitationsManager; @Autowired public UserInvitationController(ApiContext apiContext, InvitationsManager invitationsManager) { super(apiContext); this.invitationsManager = invitationsManager; } @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/users"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> users(@RequestBody Invitation invitation, Principal principal) throws Exception { this.invitationsManager.inviteUsers(invitation, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Users have beeen invited")); } @Transactional @RequestMapping(method = RequestMethod.GET, value = {"/exchange/{invitationID}"}, produces = "application/json") public @ResponseBody ResponseEntity> exchange(@PathVariable UUID invitationID, Principal principal) throws JAXBException { UUID dmpId = invitationsManager.assignUserAcceptedInvitation(invitationID, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).payload(dmpId)); } @RequestMapping(method = RequestMethod.POST, value = {"/getUsers"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getUsers(Principal principal) throws IllegalAccessException, InstantiationException { List users = invitationsManager.getUsers(principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(users)); } }