This commit is contained in:
Kristian Ntavidi 2021-04-07 19:20:32 +03:00
commit 45227cca10
19 changed files with 237 additions and 159 deletions

View File

@ -1,6 +1,5 @@
package eu.eudat.controllers;
import eu.eudat.data.dao.entities.UserDatasetProfileDao;
import eu.eudat.data.entities.UserDatasetProfile;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
@ -17,7 +16,6 @@ import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import org.springframework.core.env.Environment;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.types.ApiMessageCode;
@ -70,16 +68,7 @@ public class Admin extends BaseController {
userDatasetProfile.setUser(userInfo);
userDatasetProfile.setRole(0);
getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
if (profile.getUsers() != null && !profile.getUsers().isEmpty()) {
profile.getUsers().forEach(userInfoListingModel -> {
UserDatasetProfile userDatasetProfile1 = new UserDatasetProfile();
userDatasetProfile1.setDatasetProfile(datasetProfile);
UserInfo userInfo1 = getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userInfoListingModel.getId());
userDatasetProfile1.setUser(userInfo1);
userDatasetProfile1.setRole(1);
getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile1);
});
}
datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile);
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
}
@ -95,16 +84,7 @@ public class Admin extends BaseController {
datasetprofile.setDescription(modelDefinition.getDescription());
datasetprofile.setLanguage(modelDefinition.getLanguage());
eu.eudat.data.entities.DatasetProfile datasetProfile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
if (profile.getUsers() != null && !profile.getUsers().isEmpty()) {
profile.getUsers().forEach(userInfoListingModel -> {
UserDatasetProfile userDatasetProfile1 = new UserDatasetProfile();
userDatasetProfile1.setDatasetProfile(datasetProfile);
UserInfo userInfo1 = getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userInfoListingModel.getId());
userDatasetProfile1.setUser(userInfo1);
userDatasetProfile1.setRole(1);
getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile1);
});
}
datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE));
}
@ -148,16 +128,7 @@ public class Admin extends BaseController {
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
datasetprofile.setLabel(profile.getLabel() + " new ");
datasetprofile.setLanguage(profile.getLanguage());
if (profile.getUsers() != null && !profile.getUsers().isEmpty()) {
datasetprofile.setUsers(profile.getUsers().stream().map(userDatasetProfile -> {
UserInfoListingModel userInfoListingModel = new UserInfoListingModel();
userInfoListingModel.setId(userDatasetProfile.getUser().getId());
userInfoListingModel.setName(userDatasetProfile.getUser().getName());
userInfoListingModel.setEmail(userDatasetProfile.getUser().getEmail());
userInfoListingModel.setRole(userDatasetProfile.getRole());
return userInfoListingModel;
}).collect(Collectors.toList()));
}
datasetProfileManager.retrieveUsers(profile, datasetprofile);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile));
}

View File

@ -119,6 +119,14 @@ public class Users extends BaseController {
ResponseEntity exportCsv(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
return userManager.exportToCsv(principal);
}
@RequestMapping(method = RequestMethod.POST, value = {"/find"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<UserProfile>> find(@Valid @RequestBody String email) throws Exception {
UserProfile userProfile = userManager.getFromEmail(email);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(userProfile).status(ApiMessageCode.NO_MESSAGE));
}
}

View File

@ -4,6 +4,8 @@ import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.entities.UserDatasetProfile;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException;
@ -72,16 +74,7 @@ public class DatasetProfileManager {
datasetprofile.setDescription(profile.getDescription());
datasetprofile.setLanguage(profile.getLanguage());
datasetprofile.setUsers(new ArrayList<>());
if (profile.getUsers() != null && !profile.getUsers().isEmpty()) {
datasetprofile.getUsers().addAll(profile.getUsers().stream().map(userDatasetProfile -> {
UserInfoListingModel userInfoListingModel = new UserInfoListingModel();
userInfoListingModel.setId(userDatasetProfile.getUser().getId());
userInfoListingModel.setName(userDatasetProfile.getUser().getName());
userInfoListingModel.setEmail(userInfoListingModel.getEmail());
userInfoListingModel.setRole(userInfoListingModel.getRole());
return userInfoListingModel;
}).collect(Collectors.toList()));
}
retrieveUsers(profile, datasetprofile);
return datasetprofile;
}
@ -276,4 +269,34 @@ public class DatasetProfileManager {
throw new DatasetProfileNewVersionException("Version to update not the latest.");
}
}
public void storeDatasetProfileUsers(DatasetProfile entity, eu.eudat.models.data.admin.composite.DatasetProfile model) {
if (model.getUsers() != null && !model.getUsers().isEmpty()) {
model.getUsers().stream().filter(userInfoListingModel -> entity.getUsers().stream().filter(userDatasetProfile -> userDatasetProfile.getUser().getId().equals(userInfoListingModel.getId())).count() == 0).forEach(userInfoListingModel -> {
UserDatasetProfile userDatasetProfile1 = new UserDatasetProfile();
userDatasetProfile1.setDatasetProfile(entity);
UserInfo userInfo1 = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userInfoListingModel.getId());
userDatasetProfile1.setUser(userInfo1);
userDatasetProfile1.setRole(1);
apiContext.getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile1);
});
}
entity.getUsers().stream().filter(userDatasetProfile -> model.getUsers().stream().filter(userInfoListingModel -> userDatasetProfile.getUser().getId().equals(userInfoListingModel.getId())).count() == 0).forEach(userDatasetProfile -> {
userDatasetProfile.setRole(2);
apiContext.getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
});
}
public void retrieveUsers(DatasetProfile entity, eu.eudat.models.data.admin.composite.DatasetProfile model) {
if (entity.getUsers() != null && !entity.getUsers().isEmpty()) {
model.setUsers(entity.getUsers().stream().filter(userDatasetProfile -> userDatasetProfile.getRole() < 2).map(userDatasetProfile -> {
UserInfoListingModel userInfoListingModel = new UserInfoListingModel();
userInfoListingModel.setId(userDatasetProfile.getUser().getId());
userInfoListingModel.setName(userDatasetProfile.getUser().getName());
userInfoListingModel.setEmail(userDatasetProfile.getUser().getEmail());
userInfoListingModel.setRole(userDatasetProfile.getRole());
return userInfoListingModel;
}).collect(Collectors.toList()));
}
}
}

View File

@ -240,4 +240,9 @@ public class UserManager {
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
}
public UserProfile getFromEmail(String email) {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), email)).getSingle();
return new UserProfile().fromDataModel(user);
}
}

View File

@ -1,4 +1,5 @@
import { ValidationType } from "../../../common/enum/validation-type";
import { UserInfoListingModel } from "../../user/user-info-listing";
export interface DatasetProfile {
label: string;
@ -8,6 +9,7 @@ export interface DatasetProfile {
version: number;
description: string;
language: string;
users: UserInfoListingModel[];
}
export interface Page {

View File

@ -53,6 +53,10 @@ export class UserService {
return this.http.post<DataTableData<UserListingModel>>(this.actionUrl + 'getCollaboratorsPaged', JSON.stringify(dataTableRequest), { headers: this.headers });
}
getFromEmail(email: string): Observable<UserListingModel> {
return this.http.post<UserListingModel>(this.actionUrl + 'find', email, {headers: this.headers});
}
public hasDOIToken(): Observable<any> {
const url = this.actionUrl + 'hasDOIToken';
return this.http.get(url, { headers: this.headers });

View File

@ -54,6 +54,7 @@ import {DragulaModule} from 'ng2-dragula';
import {MatBadgeModule} from '@angular/material/badge';
import { DatasetProfileEditorSectionFieldSetComponent } from './editor/components/section-fieldset/dataset-profile-editor-section-fieldset.component';
import { FinalPreviewComponent } from './editor/components/final-preview/final-preview.component';
import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.module';
@NgModule({
imports: [
@ -68,7 +69,8 @@ import { FinalPreviewComponent } from './editor/components/final-preview/final-p
AngularStickyThingsModule,
DragDropModule,
MatBadgeModule,
DragulaModule
DragulaModule,
AutoCompleteModule
],
declarations: [
DatasetProfileListingComponent,

View File

@ -1,4 +1,5 @@
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { UserInfoListingModel } from '@app/core/model/user/user-info-listing';
import { DatasetProfile } from '../../../../core/model/admin/dataset-profile/dataset-profile';
import { BaseFormModel } from '../../../../core/model/base-form-model';
import { PageEditorModel } from '../admin/page-editor-model';
@ -15,6 +16,7 @@ export class DatasetProfileEditorModel extends BaseFormModel {
public version: number;
private description: string;
private language: string;
private users: UserInfoListingModel[] = [];
fromModel(item: DatasetProfile): DatasetProfileEditorModel {
if (item.sections) { this.sections = item.sections.map(x => new SectionEditorModel().fromModel(x)); }
@ -24,6 +26,7 @@ export class DatasetProfileEditorModel extends BaseFormModel {
this.version = item.version;
this.description = item.description;
this.language = item.language;
this.users = item.users;
return this;
}
@ -33,7 +36,8 @@ export class DatasetProfileEditorModel extends BaseFormModel {
description: [{ value: this.description, disabled: (disabled && !skipDisable.includes('DatasetProfileEditorModel.description')) }, [Validators.required]],
language: [{ value: this.language, disabled: (disabled && !skipDisable.includes('DatasetProfileEditorModel.language')) }, [Validators.required]],
status: [{ value: this.status, disabled: (disabled && !skipDisable.includes('DatasetProfileEditorModel.status')) }],
version: [{ value: this.version, disabled: (disabled && !skipDisable.includes('DatasetProfileEditorModel.version')) }]
version: [{ value: this.version, disabled: (disabled && !skipDisable.includes('DatasetProfileEditorModel.version')) }],
users: [{ value: this.users, disabled: (disabled && !skipDisable.includes('DatasetProfileEditorModel.users')) }]
});
const sectionsFormArray = new Array<FormGroup>();

View File

@ -164,6 +164,29 @@
</mat-form-field>
</div>
<div class="col-12">
<!-- <div class="heading">1.3 {{'DMP-EDITOR.FIELDS.LANGUAGE' | translate}}</div> -->
<div class="heading">1.4 {{'DATASET-PROFILE-EDITOR.STEPS.GENERAL-INFO.DATASET-TEMPLATE-USERS'| translate}}</div>
<div class="full-width basic-info-input">
<table class="col-12">
<tr class="row">
<th class="col-4">{{'USERS.LISTING.NAME' | translate}}</th>
<th class="col-4">{{'USERS.LISTING.EMAIL' | translate}}</th>
<th class="col-4"></th>
</tr>
<tr *ngFor="let user of userChipList" class="row">
<td class="col-4">{{user.name}}</td>
<td class="col-4">{{user.email}}</td>
<td class="col-4">
<button mat-raised-button class="delete-btn" (click)="removeUser(user)">delete</button>
</td>
</tr>
</table>
</div>
<input matInput #email class = "col-8" placeholder="{{'DATASET-PROFILE-EDITOR.STEPS.GENERAL-INFO.DATASET-TEMPLATE-USERS'| translate}}">
<button mat-raised-button color="primary" (click)="checkAndAdd(email.value)">Add and Validate</button>
</div>
<!-- <div class="col-12">
<button mat-button class="full-width" (click)="addPage()"
[disabled]="viewOnly">{{'DATASET-PROFILE-EDITOR.ACTIONS.NEXT' | translate}}</button>

View File

@ -228,3 +228,8 @@ $blue-color-light: #5cf7f2;
margin-top: 2em;
margin-bottom: 2em;
}
.delete-btn {
background-color: rgba(255, 0, 0, 0.76);
color: white;
}

View File

@ -45,6 +45,12 @@ import { EditorCustomValidators, EditorCustomValidatorsEnum } from './custom-val
import { CustomErrorValidator } from '@common/forms/validation/custom-validator';
import { STEPPER_ANIMATIONS } from './animations/animations';
import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { DmpInvitationUser } from '@app/core/model/dmp/invitation/dmp-invitation-user';
import { RequestItem } from '@app/core/query/request-item';
import { DmpInvitationUserCriteria } from '@app/core/query/dmp/dmp-invitation-user-criteria';
import { DmpInvitationService } from '@app/core/services/dmp/dmp-invitation.service';
import { UserService } from '@app/core/services/user/user.service';
const skipDisable: any[] = require('../../../../../assets/resources/skipDisable.json');
@ -75,6 +81,8 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
nestedIndex: number = 0;
errorMessages: string[] = [];
tocEntryEnumValues = ToCEntryType;
public userChipList:any[] = [];
displayedColumns: String[] = ['name', 'email', 'button'];
colorizeInvalid:boolean = false;
@ -101,7 +109,8 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
private datasetWizardService: DatasetWizardService,
private visibilityRulesService: VisibilityRulesService,
private fb: FormBuilder,
private sidenavService: SideNavService
private sidenavService: SideNavService,
private userService: UserService
) {
super();
// this.profileID = route.snapshot.params['id'];
@ -248,6 +257,8 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
this.steps = this.stepper.steps;
});
this._initializeToCEntries();
console.log(this.form.get('users').value);
this.userChipList = [...this.form.get('users').value];
}
@ -1824,6 +1835,18 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn
}
checkAndAdd(ev: any) {
this.userService.getFromEmail(ev).pipe(takeUntil(this._destroyed)).subscribe((result) => {
this.userChipList.push(result);
this.form.patchValue({'users': this.userChipList});
});
}
removeUser(user: any) {
this.userChipList.splice(this.userChipList.indexOf(user), 1);
this.form.patchValue({'users': this.userChipList});
}
}
interface InvalidControl{

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",

View File

@ -289,6 +289,7 @@
"DATASET-TEMPLATE-DESCRIPTION-HINT": "A brief description of what the Dataset is about, it's scope and objectives.",
"DATASET-TEMPLATE-LANGUAGE": "Dataset template language",
"DATASET-TEMPLATE-SELECT-LANGUAGE": "Select a language",
"DATASET-TEMPLATE-USERS": "Users",
"DATASET-TEMPLATE-DESCRIPTION-PLACEHOLDER": "Dataset template description",
"UNTITLED": "Untitled",
"QUESTION": "Question",