Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Efstratios Giannopoulos 2023-11-22 13:32:21 +02:00
commit ac91b62d63
13 changed files with 175 additions and 137 deletions

View File

@ -5,6 +5,7 @@ import jakarta.xml.bind.annotation.XmlElement;
public class AuthenticationConfigurationEntity {
private Boolean enabled;
private String authUrl;
private ReferenceTypeExternalApiHTTPMethodType authMethod;
private String authTokenPath;
@ -15,6 +16,15 @@ public class AuthenticationConfigurationEntity {
return authUrl;
}
public Boolean getEnabled() {
return enabled;
}
@XmlElement(name = "enabled")
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
@XmlElement(name = "authUrl")
public void setAuthUrl(String authUrl) {
this.authUrl = authUrl;

View File

@ -49,6 +49,7 @@ public class AuthenticationConfigurationBuilder extends BaseBuilder<Authenticati
List<AuthenticationConfiguration> models = new ArrayList<>();
for (AuthenticationConfigurationEntity d : data) {
AuthenticationConfiguration m = new AuthenticationConfiguration();
if (fields.hasField(this.asIndexer(AuthenticationConfiguration._enabled))) m.setEnabled(d.getEnabled());
if (fields.hasField(this.asIndexer(AuthenticationConfiguration._authUrl))) m.setAuthUrl(d.getAuthUrl());
if (fields.hasField(this.asIndexer(AuthenticationConfiguration._authMethod))) m.setAuthMethod(d.getAuthMethod());
if (fields.hasField(this.asIndexer(AuthenticationConfiguration._authTokenPath))) m.setAuthTokenPath(d.getAuthTokenPath());

View File

@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotNull;
public class AuthenticationConfigurationPersist {
@NotNull(message = "{validation.empty}")
private Boolean enabled;
@NotNull(message = "{validation.empty}")
private String authUrl;
@ -19,6 +21,14 @@ public class AuthenticationConfigurationPersist {
@NotNull(message = "{validation.empty}")
private String type;
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getAuthUrl() {
return authUrl;
}

View File

@ -4,6 +4,9 @@ import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
public class AuthenticationConfiguration {
public final static String _enabled = "enabled";
private Boolean enabled;
public final static String _authUrl = "authUrl";
private String authUrl;
@ -19,6 +22,14 @@ public class AuthenticationConfiguration {
public final static String _type = "type";
private String type;
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getAuthUrl() {
return authUrl;
}

View File

@ -223,6 +223,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
AuthenticationConfigurationEntity data = new AuthenticationConfigurationEntity();
if (persist == null) return data;
data.setEnabled(persist.getEnabled());
data.setAuthUrl(persist.getAuthUrl());
data.setAuthMethod(persist.getAuthMethod());
data.setAuthRequestBody(persist.getAuthRequestBody());

View File

@ -107,6 +107,25 @@ public class ReferenceTypeController extends BaseController {
return model;
}
@GetMapping("code/{code}")
public ReferenceType get(@PathVariable("code") String code, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + ReferenceType.class.getSimpleName()).And("code", code).And("fields", fieldSet));
this.censorFactory.censor(ReferenceTypeCensor.class).censor(fieldSet, null);
ReferenceTypeQuery query = this.queryFactory.query(ReferenceTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).codes(code);
ReferenceType model = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{code, Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.ReferenceType_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("code", code),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return model;
}
@PostMapping("persist")
@Transactional
public ReferenceType persist(@MyValidate @RequestBody ReferenceTypePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException {

View File

@ -55,6 +55,7 @@ export interface ResultFieldsMappingConfiguration{
}
export interface AuthenticationConfiguration{
enabled: boolean;
authUrl: string;
authMethod: ReferenceTypeExternalApiHTTPMethodType;
authTokenPath: string;
@ -148,6 +149,7 @@ export interface ResultFieldsMappingConfigurationPersist{
}
export interface AuthenticationConfigurationPersist{
enabled: boolean;
authUrl: string;
authMethod: ReferenceTypeExternalApiHTTPMethodType;
authTokenPath: string;

View File

@ -40,6 +40,15 @@ export class ReferenceTypeService {
catchError((error: any) => throwError(error)));
}
getSingleWithCode(code: string, reqFields: string[] = []): Observable<ReferenceType> {
const url = `${this.apiBase}/code/${code}`;
const options = { params: { f: reqFields } };
return this.http
.get<ReferenceType>(url, options).pipe(
catchError((error: any) => throwError(error)));
}
persist(item: ReferenceTypePersist): Observable<ReferenceType> {
const url = `${this.apiBase}/persist`;
@ -111,4 +120,13 @@ export class ReferenceTypeService {
return lookup;
}
///system fields
getSystemFields(fields: string[]): string[]{
fields.push('reference_id');
fields.push('label');
fields.push('description');
return fields;
}
}

View File

@ -240,8 +240,8 @@
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field *ngIf="source.get('httpMethod').value == referenceTypeExternalApiHTTPMethodType.POST" class="w-100">
<div class="col-6" *ngIf="source.get('httpMethod').value == referenceTypeExternalApiHTTPMethodType.POST" >
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}}</mat-label>
<input matInput type="text" name="requestBody" [formControl]="source.get('requestBody')">
<mat-error *ngIf="source.get('requestBody').hasError('required')">
@ -278,30 +278,10 @@
</div>
</mat-card-header>
<mat-card-content>
<!-- <div class="row" *ngIf="fieldMappingIndex < systemFieldsMapping.length">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" [readonly]="true" name="code" [formControl]="field.get('code')"[ngModel]="systemFieldsMapping[fieldMappingIndex]">
<mat-error *ngIf="field.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.RESPONSE-PATH' | translate}}</mat-label>
<input matInput type="text" name="responsePath" [formControl]="field.get('responsePath')">
<mat-error *ngIf="field.get('responsePath').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div> -->
<!-- <div class="row" *ngIf="fieldMappingIndex >= systemFieldsMapping.length"> -->
<div class="row">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<!-- <input matInput type="text" [readonly]="true" name="code" [formControl]="field.get('code')" [ngModel]="formGroup.get('definition').get('fields').value[fieldMappingIndex - systemFieldsMapping.length].code"> -->
<input matInput type="text" [readonly]="field.get('code').disabled" name="code" [formControl]="field.get('code')">
<mat-error *ngIf="field.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -321,7 +301,10 @@
</div>
</div>
<!-- Auth info -->
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.AUTHENTICATION' | translate}}</h3>
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.AUTHENTICATION' | translate}}
<mat-checkbox [formControl]="source.get('auth').get('enabled')"></mat-checkbox>
</h3>
<div class="row" *ngIf="source.get('auth').get('enabled').value == true">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}}</mat-label>
@ -366,6 +349,7 @@
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
<!-- Queries info -->
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.QUERIES' | translate}}
<button mat-button type="button" (click)="addQuery(sourceIndex)" [disabled]="formGroup.disabled">{{'REFERENCE-TYPE-EDITOR.ACTIONS.ADD-QUERY' | translate}}</button>
@ -439,30 +423,10 @@
</div>
</mat-card-header>
<mat-card-content>
<!-- <div class="row" *ngIf="optionsIndex < systemFieldsMapping.length">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" [readonly]="true" name="code" [formControl]="option.get('code')"[ngModel]="systemFieldsMapping[optionsIndex]">
<mat-error *ngIf="option.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput type="text" name="value" [formControl]="option.get('value')">
<mat-error *ngIf="option.get('value').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
<div class="row" *ngIf="optionsIndex >= systemFieldsMapping.length"> -->
<div class="row">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<!-- <input matInput type="text" [readonly]="true" name="code" [formControl]="option.get('code')" [ngModel]="formGroup.get('definition').get('fields').value[optionsIndex - systemFieldsMapping.length].code"> -->
<input matInput type="text" [readonly]="option.get('code').disabled" name="code" [formControl]="option.get('code')">
<mat-error *ngIf="option.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -506,7 +470,7 @@
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<mat-select [value] ="selectedReferenceTypeCode" (selectionChange)="selectedReferenceTypeChanged($event.value)" name="referenceTypeCode" [formControl]="dependency.get('referenceTypeCode')" required>
<mat-select (selectionChange)="selectedReferenceTypeChanged($event.value)" name="referenceTypeCode" [formControl]="dependency.get('referenceTypeCode')" required>
<mat-option *ngFor="let referenceType of referenceTypes" [value]="referenceType.code">
{{referenceType.code}}
</mat-option>
@ -519,7 +483,7 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
<mat-select name = 'key' [formControl]="dependency.get('key')" required>
<mat-option *ngFor="let key of sourceKeys" [value]="key">
<mat-option *ngFor="let key of sourceKeysMap.get(dependency.get('referenceTypeCode').value)" [value]="key">
{{key}}
</mat-option>
</mat-select>
@ -570,7 +534,7 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.TARGET' | translate}}</mat-label>
<mat-select name = 'target' [formControl]="property.get('target')" required>
<mat-option *ngFor="let targetCode of targetPropertyCodes" [value]="targetCode">
<mat-option *ngFor="let targetCode of targetPropertyCodesMap.get(dependency.get('referenceTypeCode').value)" [value]="targetCode">
{{targetCode}}
</mat-option>
</mat-select>

View File

@ -29,7 +29,6 @@ import { DependencyPropertyEditorModel, QueryConfigEditorModel, ReferenceTypeEdi
import { ReferenceFieldDataType } from '@app/core/common/enum/reference-field-data-type';
import { ReferenceTypeSourceType } from '@app/core/common/enum/reference-type-source-type';
import { ReferenceTypeExternalApiHTTPMethodType } from '@app/core/common/enum/reference-type-external-api-http-method-type';
import { ReferenceTypeLookup } from '@app/core/query/reference-type.lookup';
@Component({
@ -50,10 +49,11 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
public referenceFieldDataTypeEnum = this.enumUtils.getEnumValues(ReferenceFieldDataType);
public referenceTypeExternalApiHTTPMethodTypeEnum = this.enumUtils.getEnumValues(ReferenceTypeExternalApiHTTPMethodType);
referenceTypes: ReferenceType[] = null;
selectedReferenceTypeCode: string = null;
sourceKeys: string[] = [];
sourceKeysMap: Map<string, string[]> = new Map<string, string[]>();
propertyCodes: string[] = [];
targetPropertyCodes: string[] = [];
targetPropertyCodesMap: Map<string, string[]> = new Map<string, string[]>();
protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteReferenceType);
@ -115,24 +115,16 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
this.editorModel = data ? new ReferenceTypeEditorModel().fromModel(data) : new ReferenceTypeEditorModel();
this.getReferenceTypes(this.editorModel.id);
this.propertyCodes = this.referenceTypeService.getSystemFields([]);
if(data){
this.editorModel.definition.sources.forEach(source => source.dependencies.forEach(dependency => {
this.selectedReferenceTypeChanged(dependency.referenceTypeCode);
}));
this.editorModel.definition.sources.forEach(source => {
if(source.type == ReferenceTypeSourceType.STATIC){
source.options.forEach(option => {
if(!this.propertyCodes.includes(option.code)){
this.propertyCodes.push(option.code);
}
});
}else{
source.results.fieldsMapping.forEach(fieldMapping => {
if(!this.propertyCodes.includes(fieldMapping.code)){
this.propertyCodes.push(fieldMapping.code);
}
});
this.editorModel.definition.fields.forEach(field => {
if(!this.propertyCodes.includes(field.code)){
this.propertyCodes.push(field.code);
}
});
}
@ -394,35 +386,48 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
this.referenceTypes = response.items as ReferenceType[];
this.referenceTypes.forEach(referenceType =>{
this.sourceKeysMap.set(referenceType.code, []);
this.targetPropertyCodesMap.set(referenceType.code, []);
})
});
}
selectedReferenceTypeChanged(code: string): void{
this.selectedReferenceTypeCode = code;
this.sourceKeys = [];
this.targetPropertyCodes = [];
const lookup = ReferenceTypeService.DefaultReferenceTypeLookup();
lookup.codes = [this.selectedReferenceTypeCode];
this.referenceTypeService.query(lookup)
this.referenceTypeService.getSingleWithCode(code, ReferenceTypeEditorResolver.lookupFields())
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
if(response.count ==1){
const referenceType = response.items[0] as ReferenceType;
.subscribe(data => {
const referenceType = data as ReferenceType;
// source keys
referenceType.definition.sources.forEach(source => {
if(!this.sourceKeys.includes(source.key)) this.sourceKeys.push(source.key)
if(source.type == ReferenceTypeSourceType.API){
source.results.fieldsMapping.forEach(target => {
if(!this.targetPropertyCodes.includes(target.code)) this.targetPropertyCodes.push(target.code)
});
if(this.sourceKeysMap.has(code) && this.sourceKeysMap.get(code).length == 0){
this.sourceKeysMap.set(code, this.sourceKeys);
}
// targetPropertyCodes
let fields = [];
if(referenceType.definition.fields) {
fields = this.referenceTypeService.getSystemFields(referenceType.definition.fields.map(x => x.code));
}else{
source.options.forEach(target => {
if(!this.targetPropertyCodes.includes(target.code)) this.targetPropertyCodes.push(target.code)
});
fields = this.referenceTypeService.getSystemFields(fields);
}
});
fields.forEach(field => {
if(!this.targetPropertyCodes.includes(field)) this.targetPropertyCodes.push(field)
})
if(this.targetPropertyCodesMap.has(code) && this.targetPropertyCodesMap.get(code).length == 0){
this.targetPropertyCodesMap.set(code, this.targetPropertyCodes);
}
});
}
@ -430,14 +435,6 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
// Properties
addProperty(sourceIndex: number, dependencyIndex: number): void{
const optionFormArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray);
for(let i =0; i < optionFormArray.length; i++){
if(!this.propertyCodes.includes(optionFormArray.at(i).get('code').getRawValue())){
this.propertyCodes.push(optionFormArray.at(i).get('code').getRawValue());
}
}
if (((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get('referenceTypeCode').value == null){
return ;
}

View File

@ -442,7 +442,7 @@ export class ResultFieldsMappingConfigurationEditorModel implements ResultFields
}
return this.formBuilder.group({
code: [{ value: "code", disabled: true }, context.getValidation('code').validators],
code: [{ value: this.code, disabled: true }, context.getValidation('code').validators],
responsePath: [{ value: this.responsePath, disabled: disabled }, context.getValidation('responsePath').validators],
});
}
@ -464,6 +464,7 @@ export class ResultFieldsMappingConfigurationEditorModel implements ResultFields
}
export class AuthenticationConfigurationEditorModel implements AuthenticationConfigurationPersist {
public enabled: boolean;
public authUrl: string;
public authMethod: ReferenceTypeExternalApiHTTPMethodType;
public authTokenPath: string;
@ -477,6 +478,7 @@ export class AuthenticationConfigurationEditorModel implements AuthenticationCon
) { }
fromModel(item: AuthenticationConfiguration): AuthenticationConfigurationEditorModel {
this.enabled = item.enabled;
this.authUrl = item.authUrl;
this.authMethod = item.authMethod;
this.authTokenPath = item.authTokenPath;
@ -500,6 +502,7 @@ export class AuthenticationConfigurationEditorModel implements AuthenticationCon
}
return this.formBuilder.group({
enabled: [{ value: this.enabled, disabled: disabled }, context.getValidation('enabled').validators],
authUrl: [{ value: this.authUrl, disabled: disabled }, context.getValidation('authUrl').validators],
authMethod: [{ value: this.authMethod, disabled: disabled }, context.getValidation('authMethod').validators],
authTokenPath: [{ value: this.authTokenPath, disabled: disabled }, context.getValidation('authTokenPath').validators],
@ -516,6 +519,7 @@ export class AuthenticationConfigurationEditorModel implements AuthenticationCon
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'enabled', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}enabled`)] });
baseValidationArray.push({ key: 'authUrl', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}authUrl`)] });
baseValidationArray.push({ key: 'authMethod', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}authMethod`)] });
baseValidationArray.push({ key: 'authTokenPath', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}authTokenPath`)] });

View File

@ -45,6 +45,7 @@ export class ReferenceTypeEditorResolver extends BaseEditorResolver {
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.requestBody)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.filterType)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.auth),nameof<AuthenticationConfiguration>(x => x.enabled)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.auth),nameof<AuthenticationConfiguration>(x => x.authUrl)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.auth),nameof<AuthenticationConfiguration>(x => x.authMethod)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.auth),nameof<AuthenticationConfiguration>(x => x.authTokenPath)].join('.'),

View File

@ -1162,12 +1162,12 @@
"REMOVE-DEPENDENCY": "Remove Dependency",
"ADD-PROPERTY": "Add property",
"REMOVE-PROPERTY": "Remove property"
}
},
"CONFIRM-DELETE-DIALOG": {
"MESSAGE": "Would you like to delete this Reference type?",
"CONFIRM-BUTTON": "Yes, delete",
"CANCEL-BUTTON": "No"
}
},
"DMP-BLUEPRINT-EDITOR": {
"TITLE": {