diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/AuthenticationConfigurationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/AuthenticationConfigurationEntity.java index 4ac464433..3990b2c1f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/AuthenticationConfigurationEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/AuthenticationConfigurationEntity.java @@ -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; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/AuthenticationConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/AuthenticationConfigurationBuilder.java index beadcd9f4..77b04d493 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/AuthenticationConfigurationBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/AuthenticationConfigurationBuilder.java @@ -49,6 +49,7 @@ public class AuthenticationConfigurationBuilder extends BaseBuilder 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()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java index b687eb3ea..f3045b42d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java @@ -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; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/AuthenticationConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/AuthenticationConfiguration.java index be7385415..adef7b334 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/AuthenticationConfiguration.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/AuthenticationConfiguration.java @@ -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; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java index 3b09d5ca9..adcdbefa0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java @@ -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()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceTypeController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceTypeController.java index 41eafff10..bd9107bac 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceTypeController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceTypeController.java @@ -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("code", code), + new AbstractMap.SimpleEntry("fields", fieldSet) + )); + + return model; + } + @PostMapping("persist") @Transactional public ReferenceType persist(@MyValidate @RequestBody ReferenceTypePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException { diff --git a/dmp-frontend/src/app/core/model/reference-type/reference-type.ts b/dmp-frontend/src/app/core/model/reference-type/reference-type.ts index 3feaad017..fb4804d96 100644 --- a/dmp-frontend/src/app/core/model/reference-type/reference-type.ts +++ b/dmp-frontend/src/app/core/model/reference-type/reference-type.ts @@ -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; diff --git a/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts b/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts index 8aebac210..831e7bf1a 100644 --- a/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts +++ b/dmp-frontend/src/app/core/services/reference-type/reference-type.service.ts @@ -40,6 +40,15 @@ export class ReferenceTypeService { catchError((error: any) => throwError(error))); } + getSingleWithCode(code: string, reqFields: string[] = []): Observable { + const url = `${this.apiBase}/code/${code}`; + const options = { params: { f: reqFields } }; + + return this.http + .get(url, options).pipe( + catchError((error: any) => throwError(error))); + } + persist(item: ReferenceTypePersist): Observable { 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; + } } \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html index 90eec2012..29c1fdd99 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html @@ -240,8 +240,8 @@ {{'GENERAL.VALIDATION.REQUIRED' | translate}} -
- +
+ {{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}} @@ -278,30 +278,10 @@
- -
{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -321,50 +301,54 @@
-

{{'REFERENCE-TYPE-EDITOR.FIELDS.AUTHENTICATION' | translate}}

-
- - {{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}} - - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'REFERENCE-TYPE-EDITOR.FIELDS.HTTP-METHOD' | translate}} - - - {{enumUtils.toReferenceTypeExternalApiHTTPMethodTypeString(httpMethod)}} - - - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'REFERENCE-TYPE-EDITOR.FIELDS.TOKEN-PATH' | translate}} - - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}} - - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'REFERENCE-TYPE-EDITOR.FIELDS.TYPE' | translate}} - - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - +

{{'REFERENCE-TYPE-EDITOR.FIELDS.AUTHENTICATION' | translate}} + +

+
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.HTTP-METHOD' | translate}} + + + {{enumUtils.toReferenceTypeExternalApiHTTPMethodTypeString(httpMethod)}} + + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.TOKEN-PATH' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.TYPE' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +

{{'REFERENCE-TYPE-EDITOR.FIELDS.QUERIES' | translate}} @@ -439,30 +423,10 @@

-
{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -506,7 +470,7 @@
{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}} - + {{referenceType.code}} @@ -519,7 +483,7 @@ {{'REFERENCE-TYPE-EDITOR.FIELDS.KEY' | translate}} - + {{key}} @@ -570,7 +534,7 @@ {{'REFERENCE-TYPE-EDITOR.FIELDS.TARGET' | translate}} - + {{targetCode}} diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts index cce9f394f..be05146a4 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts @@ -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 = new Map(); propertyCodes: string[] = []; targetPropertyCodes: string[] = []; + targetPropertyCodesMap: Map = new Map(); protected get canDelete(): boolean { return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteReferenceType); @@ -115,24 +115,16 @@ export class ReferenceTypeEditorComponent extends BaseEditor 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,50 +386,55 @@ export class ReferenceTypeEditorComponent extends BaseEditor { 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) - }); - }else{ - source.options.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{ + 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); + } + + }); } // 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 ; } diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts index fb155e84b..34fe57252 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts @@ -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(); + 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`)] }); diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.resolver.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.resolver.ts index 119c0d0d5..eb5f16855 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.resolver.ts @@ -45,6 +45,7 @@ export class ReferenceTypeEditorResolver extends BaseEditorResolver { [nameof(x => x.definition), nameof(x => x.sources), nameof(x => x.requestBody)].join('.'), [nameof(x => x.definition), nameof(x => x.sources), nameof(x => x.filterType)].join('.'), + [nameof(x => x.definition), nameof(x => x.sources), nameof(x => x.auth),nameof(x => x.enabled)].join('.'), [nameof(x => x.definition), nameof(x => x.sources), nameof(x => x.auth),nameof(x => x.authUrl)].join('.'), [nameof(x => x.definition), nameof(x => x.sources), nameof(x => x.auth),nameof(x => x.authMethod)].join('.'), [nameof(x => x.definition), nameof(x => x.sources), nameof(x => x.auth),nameof(x => x.authTokenPath)].join('.'), diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index cafd8167c..ee4b62614 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -1162,13 +1162,13 @@ "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" } }, - "CONFIRM-DELETE-DIALOG": { - "MESSAGE": "Would you like to delete this Reference type?", - "CONFIRM-BUTTON": "Yes, delete", - "CANCEL-BUTTON": "No" - }, "DMP-BLUEPRINT-EDITOR": { "TITLE": { "NEW": "New DMP Blueprint",