DmpBlueprint refactor

This commit is contained in:
Efstratios Giannopoulos 2023-10-24 12:13:05 +03:00
parent dc380cdc01
commit a68668f07e
6 changed files with 150 additions and 66 deletions

View File

@ -1,6 +1,7 @@
package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import org.w3c.dom.Element;
public class ExtraFieldEntity extends FieldEntity {
@ -23,6 +24,7 @@ public class ExtraFieldEntity extends FieldEntity {
@Override
public ExtraFieldEntity fromXmlChild(Element item) {
this.type = DmpBlueprintExtraFieldDataType.of(Short.parseShort(item.getAttribute("type")));
this.setCategory(DmpBlueprintFieldCategory.Extra);
return this;
}
}

View File

@ -1,5 +1,6 @@
package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.types.xml.XmlSerializable;
import org.w3c.dom.Document;

View File

@ -1,5 +1,6 @@
package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
import eu.eudat.commons.types.xml.XmlSerializable;
import org.w3c.dom.Document;
@ -27,6 +28,7 @@ public class SystemFieldEntity extends FieldEntity {
@Override
public SystemFieldEntity fromXmlChild(Element item) {
this.type = DmpBlueprintSystemFieldType.of(Short.parseShort(item.getAttribute("type")));
this.setCategory(DmpBlueprintFieldCategory.System);
return this;
}
}

View File

@ -10,12 +10,17 @@ import { BaseHttpParams } from '@common/http/base-http-params';
import { InterceptorType } from '@common/http/interceptors/interceptor-type';
import { QueryResult } from '@common/model/query-result';
import { Guid } from '@common/types/guid';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { catchError, map } from 'rxjs/operators';
import { ConfigurationService } from '../configuration/configuration.service';
import { BaseHttpV2Service } from '../http/base-http-v2.service';
import { DmpBlueprintCriteria } from '@app/core/query/dmp/dmp-blueprint-criteria';
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { nameof } from 'ts-simple-nameof';
import { FilterService } from '@common/modules/text-filter/filter-service';
import { Observable, throwError } from 'rxjs';
@Injectable()
export class DmpBlueprintService {
@ -23,7 +28,7 @@ export class DmpBlueprintService {
private actionUrl: string;
private headers = new HttpHeaders();
constructor(private http: BaseHttpV2Service, private httpClient: HttpClient, private configurationService: ConfigurationService) {
constructor(private http: BaseHttpV2Service, private httpClient: HttpClient, private configurationService: ConfigurationService, private filterService: FilterService) {
this.actionUrl = configurationService.server + 'dmpprofile/';
}
@ -65,10 +70,6 @@ export class DmpBlueprintService {
return this.http.post<DataTableData<DmpBlueprint>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers });
}
getPagedBlueprint(dataTableRequest: DataTableRequest<DmpBlueprintCriteria>): Observable<DataTableData<DmpBlueprint>> {
return this.http.post<DataTableData<DmpBlueprint>>(this.actionUrl + 'getPagedBlueprint', dataTableRequest, { headers: this.headers });
}
getSingleBlueprint(id: String): Observable<DmpBlueprint> {
return this.http.get<DmpBlueprint>(this.actionUrl + 'getSingleBlueprint/' + id, { headers: this.headers });
}
@ -103,4 +104,44 @@ export class DmpBlueprintService {
externalAutocomplete(lookUpItem: RequestItem<DmpBlueprintExternalAutocompleteCriteria>): Observable<any> {
return this.httpClient.post(this.actionUrl + 'search/autocomplete', lookUpItem);
}
//
// Autocomplete Commons
//
// tslint:disable-next-line: member-ordering
singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup()).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: DmpBlueprint) => item.label,
titleFn: (item: DmpBlueprint) => item.label,
valueAssign: (item: DmpBlueprint) => item.id,
};
// tslint:disable-next-line: member-ordering
multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = {
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup(searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup(null, null, selectedItems)).pipe(map(x => x.items)),
displayFn: (item: DmpBlueprint) => item.label,
titleFn: (item: DmpBlueprint) => item.label,
valueAssign: (item: DmpBlueprint) => item.id,
};
private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): DmpBlueprintLookup {
const lookup: DmpBlueprintLookup = new DmpBlueprintLookup();
lookup.page = { size: 100, offset: 0 };
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }
if (ids && ids.length > 0) { lookup.ids = ids; }
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
nameof<DmpBlueprint>(x => x.id),
nameof<DmpBlueprint>(x => x.label)
]
};
lookup.order = { items: [nameof<DmpBlueprint>(x => x.label)] };
if (like) { lookup.like = this.filterService.transformLike(like); }
return lookup;
}
}

View File

@ -104,7 +104,7 @@
<div class="heading2">0.3 Blueprint of DMP *</div>
<mat-form-field>
<mat-label>Select blueprint</mat-label>
<app-single-auto-complete [required]="false" [formControl]="formGroup.get('profile')" placeholder="Select blueprint" [configuration]="dmpBlueprintAutoCompleteConfiguration">
<app-single-auto-complete [required]="false" [formControl]="formGroup.get('profile')" placeholder="Select blueprint" [configuration]="dmpBlueprintService.singleAutocompleteConfiguration">
</app-single-auto-complete>
</mat-form-field>
</div>

View File

@ -54,9 +54,10 @@ import { ExtraPropertiesFormModel } from '../editor/general-tab/extra-properties
import { FunderFormModel } from '../editor/grant-tab/funder-form-model';
import { GrantTabModel } from '../editor/grant-tab/grant-tab-model';
import { ProjectFormModel } from '../editor/grant-tab/project-form-model';
import { DmpBlueprintDefinition } from '@app/core/model/dmp-blueprint/dmp-blueprint';
import { DescriptionTemplatesInSection, DmpBlueprint, DmpBlueprintDefinition, DmpBlueprintDefinitionSection, FieldInSection } from '@app/core/model/dmp-blueprint/dmp-blueprint';
import { DmpBlueprintExtraFieldDataType } from '@app/core/common/enum/dmp-blueprint-extra-field-data-type';
import { DmpBlueprintSystemFieldType } from '@app/core/common/enum/dmp-blueprint-system-field-type';
import { nameof } from 'ts-simple-nameof';
interface Visible {
value: boolean;
@ -129,7 +130,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
readonly defaultBlueprintId = '86635178-36a6-484f-9057-a934e4eeecd5';
readonly defaultBlueprintId: Guid = Guid.parse('86635178-36a6-484f-9057-a934e4eeecd5');
constructor(
private dmpBlueprintService: DmpBlueprintService,
@ -179,15 +180,13 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpBlueprintService.getSingleBlueprint(this.formGroup.get('profile').value)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.selectedDmpBlueprintDefinition = result.definition;
this.getSingle(Guid.parse(this.formGroup.get('profile').value), data => {
this.selectedDmpBlueprintDefinition = data.definition;
this.checkForGrant();
this.checkForFunder();
this.checkForProject();
this.buildExtraFields();
this.formGroup.get('profile').setValue(result);
this.formGroup.get('profile').setValue(data);
this.maxStep = this.selectedDmpBlueprintDefinition.sections.length;
this.step = 1;
this.addProfiles(this.dmp.profiles);
@ -252,15 +251,13 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpBlueprintService.getSingleBlueprint(this.formGroup.get('profile').value)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.selectedDmpBlueprintDefinition = result.definition;
this.getSingle(Guid.parse(this.formGroup.get('profile').value), data => {
this.selectedDmpBlueprintDefinition = data.definition;
this.checkForGrant();
this.checkForFunder();
this.checkForProject();
this.buildExtraFields();
this.formGroup.get('profile').setValue(result);
this.formGroup.get('profile').setValue(data);
this.maxStep = this.selectedDmpBlueprintDefinition.sections.length;
this.step = 1;
this.addProfiles();
@ -434,11 +431,9 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
}
selectDefaultBlueprint() {
this.dmpBlueprintService.getSingleBlueprint(this.defaultBlueprintId)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.selectedDmpBlueprintDefinition = result.definition;
this.formGroup.get('profile').setValue(result);
this.getSingle(this.defaultBlueprintId, data => {
this.selectedDmpBlueprintDefinition = data.definition;
this.formGroup.get('profile').setValue(data.id);
this.maxStep = this.selectedDmpBlueprintDefinition.sections.length;
this.nextStep();
});
@ -834,18 +829,61 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
return this.dmpService.searchDmpBlueprints(request);
}
private getSingle(blueprintId: Guid, successFunction) {
this.dmpBlueprintService.getSingle(blueprintId, [
nameof<DmpBlueprint>(x => x.id),
nameof<DmpBlueprint>(x => x.label),
nameof<DmpBlueprint>(x => x.status),
nameof<DmpBlueprint>(x => x.description),
nameof<DmpBlueprint>(x => x.status),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.description)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.ordinal)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.hasTemplates)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.category)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.dataType)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.systemFieldType)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.placeholder)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.description)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.required)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.ordinal)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.descriptionTemplateId)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.minMultiplicity)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.maxMultiplicity)].join('.'),
nameof<DmpBlueprint>(x => x.createdAt),
nameof<DmpBlueprint>(x => x.hash),
nameof<DmpBlueprint>(x => x.isActive)
]
)
.pipe(map(data => data as DmpBlueprint), takeUntil(this._destroyed))
.subscribe(
data => successFunction(data),
error => this.onCallbackError(error)
);
}
registerFormEventsForDmpBlueprint(): void {
this.formGroup.get('profile').valueChanges
.pipe(
takeUntil(this._destroyed))
.subscribe(Option => {
if (Option instanceof Object) {
this.selectedDmpBlueprintDefinition = Option.definition;
.subscribe(blueprintIdString => {
const blueprintId = Guid.parse(blueprintIdString);
if (blueprintId) {
this.getSingle(blueprintId, data => {
this.selectedDmpBlueprintDefinition = data.definition;
this.checkForGrant();
this.checkForFunder();
this.checkForProject();
this.buildExtraFields();
this.addProfiles();
});
}
else {
this.selectedDmpBlueprintDefinition = null;
@ -964,21 +1002,21 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
}
dmpBlueprintAutoCompleteConfiguration: SingleAutoCompleteConfiguration = {
filterFn: this.dmpBlueprintSearch.bind(this),
initialItems: (extraData) => this.dmpBlueprintSearch(''),
displayFn: (item) => item['label'],
titleFn: (item) => item['label']
};
// dmpBlueprintAutoCompleteConfiguration: SingleAutoCompleteConfiguration = {
// filterFn: this.dmpBlueprintSearch.bind(this),
// initialItems: (extraData) => this.dmpBlueprintSearch(''),
// displayFn: (item) => item['label'],
// titleFn: (item) => item['label']
// };
dmpBlueprintSearch(query: string) {
let fields: Array<string> = new Array();
var request = new DataTableRequest<DmpBlueprintCriteria>(0, 20, { fields: fields });
request.criteria = new DmpBlueprintCriteria();
request.criteria.like = query;
request.criteria.status = DmpBlueprintStatus.Finalized;
return this.dmpBlueprintService.getPagedBlueprint(request).pipe(map(x => x.data));
}
// dmpBlueprintSearch(query: string) {
// let fields: Array<string> = new Array();
// var request = new DataTableRequest<DmpBlueprintCriteria>(0, 20, { fields: fields });
// request.criteria = new DmpBlueprintCriteria();
// request.criteria.like = query;
// request.criteria.status = DmpBlueprintStatus.Finalized;
// return this.dmpBlueprintService.getPagedBlueprint(request).pipe(map(x => x.data));
// }
getLanguageInfos(): LanguageInfo[] {
return this.languageInfoService.getLanguageInfoValues();