Fix issue with DMP index not updating after a new user is invited

This commit is contained in:
George Kalampokis 2021-10-27 18:16:44 +03:00
parent 900a377d5f
commit fd26e2a742
3 changed files with 12 additions and 4 deletions

View File

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

View File

@ -1843,7 +1843,7 @@ public class DataManagementPlanManager {
}); });
} }
private void updateIndex(DMP dmp) throws IOException { public void updateIndex(DMP dmp) throws IOException {
DmpMapper mapper = new DmpMapper(apiContext, datasetManager); DmpMapper mapper = new DmpMapper(apiContext, datasetManager);
Dmp elastic = mapper.toElastic(dmp); Dmp elastic = mapper.toElastic(dmp);
apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic); apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic);

View File

@ -17,6 +17,7 @@ import org.springframework.stereotype.Component;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -26,10 +27,12 @@ import java.util.stream.Stream;
public class InvitationsManager { public class InvitationsManager {
private ApiContext apiContext; private ApiContext apiContext;
private DataManagementPlanManager dataManagementPlanManager;
@Autowired @Autowired
public InvitationsManager(ApiContext apiContext) { public InvitationsManager(ApiContext apiContext, DataManagementPlanManager dataManagementPlanManager) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.dataManagementPlanManager = dataManagementPlanManager;
} }
public void inviteUsers(Invitation invitation, Principal principal) throws Exception { public void inviteUsers(Invitation invitation, Principal principal) throws Exception {
@ -79,7 +82,7 @@ public class InvitationsManager {
return userModels; return userModels;
} }
public UUID assignUserAcceptedInvitation(UUID invitationID, Principal principal) throws UnauthorisedException, JAXBException { public UUID assignUserAcceptedInvitation(UUID invitationID, Principal principal) throws UnauthorisedException, JAXBException, IOException {
eu.eudat.data.entities.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID); eu.eudat.data.entities.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID);
if (invitation == null) if (invitation == null)
throw new UnauthorisedException("There is no Data Management Plan assigned to this Link"); throw new UnauthorisedException("There is no Data Management Plan assigned to this Link");
@ -98,6 +101,8 @@ public class InvitationsManager {
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), existingUserDMP, datamanagementPlan); apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), existingUserDMP, datamanagementPlan);
invitation.setAcceptedInvitation(true); invitation.setAcceptedInvitation(true);
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation); apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
dataManagementPlanManager.updateIndex(datamanagementPlan);
return datamanagementPlan.getId(); return datamanagementPlan.getId();
} }
} else { } else {
@ -121,6 +126,8 @@ public class InvitationsManager {
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan); apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan);
invitation.setAcceptedInvitation(true); invitation.setAcceptedInvitation(true);
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation); apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
dataManagementPlanManager.updateIndex(datamanagementPlan);
return datamanagementPlan.getId(); return datamanagementPlan.getId();
} }
return invitation.getDmp().getId(); return invitation.getDmp().getId();