Add updateusers end point for DMP

This commit is contained in:
George Kalampokis 2020-07-07 12:22:45 +03:00
parent 029c246a4b
commit ace12c3140
3 changed files with 31 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.security.Principal;
import eu.eudat.query.DMPQuery;
import eu.eudat.types.ApiMessageCode;
@ -277,6 +278,19 @@ public class DMPs extends BaseController {
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/updateusers/{id}"})
public ResponseEntity<ResponseItem<DMP>> updateUsers(@PathVariable String id, @RequestBody List<UserInfoListingModel> users, Principal principal) {
try {
this.dataManagementPlanManager.updateUsers(UUID.fromString(id), users, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Updated Colaborators for Data Datamanagement Plan."));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to update the users of Data Management Plan."));
}
}
/*
* DOI Generation
* */

View File

@ -867,6 +867,18 @@ public class DataManagementPlanManager {
this.updateIndex(dmp);
}
public void updateUsers(UUID id, List<UserInfoListingModel> users, Principal principal) throws Exception {
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id);
if (!isUserOwnerOfDmp(dmp, principal))
throw new Exception("User does not have the privilege to do this action.");
clearUsers(dmp);
for (UserInfoListingModel userListing : users) {
UserInfo tempUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userListing.getId());
assignUser(dmp, tempUser, UserDMP.UserDMPRoles.fromInteger(userListing.getRole()));
}
}
/*
* Export Data
* */

View File

@ -19,6 +19,7 @@ import { ExploreDmpCriteriaModel } from '../../query/explore-dmp/explore-dmp-cri
import { RequestItem } from '../../query/request-item';
import { BaseHttpService } from '../http/base-http.service';
import { ConfigurationService } from '../configuration/configuration.service';
import { UserInfoListingModel } from '@app/core/model/user/user-info-listing';
@Injectable()
export class DmpService {
@ -96,6 +97,10 @@ export class DmpService {
return this.http.post<DmpModel>(this.actionUrl + 'unfinalize/' + id, { headers: this.headers });
}
updateUsers(id: string, users: UserInfoListingModel[]): Observable<DmpModel> {
return this.http.post<DmpModel>(`${this.actionUrl}updateusers/${id}`, users, {headers: this.headers});
}
getDoi(id: string): Observable<string> {
return this.http.post<string>(this.actionUrl + 'createZenodoDoi/' + id, { headers: this.headers });
}