From 30e5ed504a2b2e6f15839aa6c5fe8f32c7816d28 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Fri, 17 May 2024 11:27:33 +0300 Subject: [PATCH 1/4] fix tenant select --- .../service/tenant/TenantService.java | 8 ++-- .../service/tenant/TenantServiceImpl.java | 48 +++++++++++++++++-- .../controllers/PrincipalController.java | 29 +++++------ .../org/opencdmp/models/AccountBuilder.java | 20 ++++---- .../src/main/resources/messages.properties | 4 +- .../core/services/http/principal.service.ts | 5 +- .../login/post-login/post-login.component.ts | 4 +- .../tenant-switch.component.html | 2 +- .../tenant-switch/tenant-switch.component.ts | 11 +++-- .../user-profile/user-profile.component.html | 10 ++-- .../ui/user-profile/user-profile.component.ts | 7 +-- 11 files changed, 96 insertions(+), 52 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantService.java b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantService.java index 8e39ff6a9..24acbc16f 100644 --- a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantService.java +++ b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantService.java @@ -1,18 +1,16 @@ package org.opencdmp.service.tenant; -import org.opencdmp.model.Tenant; -import org.opencdmp.model.persist.TenantPersist; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.exception.MyValidationException; import gr.cite.tools.fieldset.FieldSet; +import org.opencdmp.model.Tenant; +import org.opencdmp.model.persist.TenantPersist; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKey; -import javax.crypto.spec.IvParameterSpec; import javax.management.InvalidApplicationException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; @@ -26,4 +24,6 @@ public interface TenantService { InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; + + List myTenants(FieldSet fieldSet) throws MyForbiddenException; } diff --git a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java index 311f67f5f..67a0205d5 100644 --- a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java @@ -1,8 +1,12 @@ package org.opencdmp.service.tenant; import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; +import gr.cite.commons.web.oidc.principal.MyPrincipal; +import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractor; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.deleter.DeleterFactory; +import gr.cite.tools.data.query.Ordering; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; @@ -14,6 +18,7 @@ import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationProperties; +import org.opencdmp.authorization.ClaimNames; import org.opencdmp.authorization.Permission; import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.scope.tenant.TenantScope; @@ -31,6 +36,7 @@ import org.opencdmp.model.Tenant; import org.opencdmp.model.builder.TenantBuilder; import org.opencdmp.model.deleter.TenantDeleter; import org.opencdmp.model.persist.TenantPersist; +import org.opencdmp.query.TenantQuery; import org.opencdmp.query.UserCredentialQuery; import org.opencdmp.query.UserRoleQuery; import org.opencdmp.service.keycloak.KeycloakService; @@ -48,6 +54,7 @@ import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.time.Instant; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -73,6 +80,8 @@ public class TenantServiceImpl implements TenantService { private final AuthorizationProperties authorizationProperties; private final TenantScope tenantScope; private final QueryFactory queryFactory; + private final CurrentPrincipalResolver currentPrincipalResolver; + private final ClaimExtractor claimExtractor; @Autowired @@ -83,7 +92,7 @@ public class TenantServiceImpl implements TenantService { BuilderFactory builderFactory, ConventionService conventionService, MessageSource messageSource, - ErrorThesaurusProperties errors, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler, KeycloakService keycloakService, AuthorizationProperties authorizationProperties, TenantScope tenantScope, QueryFactory queryFactory) { + ErrorThesaurusProperties errors, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler, KeycloakService keycloakService, AuthorizationProperties authorizationProperties, TenantScope tenantScope, QueryFactory queryFactory, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractor claimExtractor) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -97,6 +106,8 @@ public class TenantServiceImpl implements TenantService { this.authorizationProperties = authorizationProperties; this.tenantScope = tenantScope; this.queryFactory = queryFactory; + this.currentPrincipalResolver = currentPrincipalResolver; + this.claimExtractor = claimExtractor; } @Override @@ -177,8 +188,6 @@ public class TenantServiceImpl implements TenantService { } - - @Override public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { logger.debug("deleting : {}", id); @@ -192,5 +201,38 @@ public class TenantServiceImpl implements TenantService { this.tenantRemovalIntegrationEventHandler.handle(tenantRemovalIntegrationEvent); } + + + @Override + public List myTenants(FieldSet fieldSet) throws MyForbiddenException { + logger.debug("my tenants"); + + MyPrincipal principal = this.currentPrincipalResolver.currentPrincipal(); + List tenants = this.claimExtractor.asStrings(principal, ClaimNames.TenantCodesClaimName); + List models = new ArrayList<>(); + + if (tenants != null && !tenants.isEmpty()) { + if (fieldSet == null || fieldSet.isEmpty()) { + fieldSet = new BaseFieldSet( + Tenant._id, + Tenant._code, + Tenant._name); + } + + TenantQuery query = this.queryFactory.query(TenantQuery.class).codes(tenants).isActive(IsActive.Active); + query.setOrder(new Ordering().addAscending(Tenant._name)); + List data = query.collectAs(fieldSet); + models.addAll(this.builderFactory.builder(TenantBuilder.class).build(fieldSet, data)); + + if (tenants.contains(this.tenantScope.getDefaultTenantCode())){ + Tenant tenant = new Tenant(); + tenant.setCode(this.tenantScope.getDefaultTenantCode()); + tenant.setName(this.messageSource.getMessage("DefaultTenant_Name", new Object[]{}, LocaleContextHolder.getLocale())); + models.addFirst(tenant); + } + } + return models; + } + } diff --git a/backend/web/src/main/java/org/opencdmp/controllers/PrincipalController.java b/backend/web/src/main/java/org/opencdmp/controllers/PrincipalController.java index 01d05740e..30df186aa 100644 --- a/backend/web/src/main/java/org/opencdmp/controllers/PrincipalController.java +++ b/backend/web/src/main/java/org/opencdmp/controllers/PrincipalController.java @@ -1,17 +1,16 @@ package org.opencdmp.controllers; -import org.opencdmp.audit.AuditableAction; -import org.opencdmp.authorization.ClaimNames; -import org.opencdmp.commons.scope.tenant.TenantScope; -import org.opencdmp.models.Account; -import org.opencdmp.models.AccountBuilder; import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; import gr.cite.commons.web.oidc.principal.MyPrincipal; -import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractor; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; +import org.opencdmp.audit.AuditableAction; +import org.opencdmp.model.Tenant; +import org.opencdmp.models.Account; +import org.opencdmp.models.AccountBuilder; +import org.opencdmp.service.tenant.TenantService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -21,27 +20,26 @@ import org.springframework.web.bind.annotation.RestController; import javax.management.InvalidApplicationException; import java.util.List; -import java.util.stream.Collectors; @RestController -@RequestMapping(value = { "/api/principal/" }) +@RequestMapping("/api/principal/") public class PrincipalController { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PrincipalController.class)); private final AuditService auditService; private final CurrentPrincipalResolver currentPrincipalResolver; private final AccountBuilder accountBuilder; - private final ClaimExtractor claimExtractor; + private final TenantService tenantService; @Autowired public PrincipalController( CurrentPrincipalResolver currentPrincipalResolver, AccountBuilder accountBuilder, - AuditService auditService, ClaimExtractor claimExtractor) { + AuditService auditService, TenantService tenantService) { this.currentPrincipalResolver = currentPrincipalResolver; this.accountBuilder = accountBuilder; this.auditService = auditService; - this.claimExtractor = claimExtractor; + this.tenantService = tenantService; } @RequestMapping(path = "me", method = RequestMethod.GET ) @@ -80,16 +78,15 @@ public class PrincipalController { } @GetMapping("my-tenants") - public List myTenants() { + public List myTenants(FieldSet fieldSet) { logger.debug("my-tenants"); - MyPrincipal principal = this.currentPrincipalResolver.currentPrincipal(); - List tenants = this.claimExtractor.asStrings(principal, ClaimNames.TenantCodesClaimName); + List models = this.tenantService.myTenants(fieldSet); this.auditService.track(AuditableAction.Principal_MyTenants); //auditService.trackIdentity(AuditableAction.IdentityTracking_Action); - - return tenants == null ? null : tenants.stream().distinct().collect(Collectors.toList()); + + return models; } } diff --git a/backend/web/src/main/java/org/opencdmp/models/AccountBuilder.java b/backend/web/src/main/java/org/opencdmp/models/AccountBuilder.java index 1376898b4..2bae2acd5 100644 --- a/backend/web/src/main/java/org/opencdmp/models/AccountBuilder.java +++ b/backend/web/src/main/java/org/opencdmp/models/AccountBuilder.java @@ -1,10 +1,5 @@ package org.opencdmp.models; -import org.opencdmp.commons.JsonHandlingService; -import org.opencdmp.commons.scope.user.UserScope; -import org.opencdmp.commons.types.user.AdditionalInfoEntity; -import org.opencdmp.data.TenantEntityManager; -import org.opencdmp.data.UserEntity; import gr.cite.commons.web.authz.configuration.AuthorizationConfiguration; import gr.cite.commons.web.authz.configuration.Permission; import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; @@ -13,6 +8,11 @@ import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractor; import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorKeys; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; +import org.opencdmp.commons.JsonHandlingService; +import org.opencdmp.commons.scope.user.UserScope; +import org.opencdmp.commons.types.user.AdditionalInfoEntity; +import org.opencdmp.data.TenantEntityManager; +import org.opencdmp.data.UserEntity; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -21,7 +21,7 @@ import javax.management.InvalidApplicationException; import java.util.*; @Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class AccountBuilder { private final ClaimExtractor claimExtractor; @@ -91,13 +91,13 @@ public class AccountBuilder { } } if (fields.hasField(Account._roles)) { - List roles = claimExtractor.roles(currentPrincipalResolver.currentPrincipal()); + List roles = this.claimExtractor.roles(this.currentPrincipalResolver.currentPrincipal()); model.setRoles(roles); } if (fields.hasField(Account._permissions)) { - List roles = claimExtractor.roles(currentPrincipalResolver.currentPrincipal()); - Set permissions = authorizationConfiguration.permissionsOfRoles(roles); - for (Map.Entry permissionEntry : authorizationConfiguration.getRawPolicies().entrySet()){ + List roles = this.claimExtractor.roles(this.currentPrincipalResolver.currentPrincipal()); + Set permissions = this.authorizationConfiguration.permissionsOfRoles(roles); + for (Map.Entry permissionEntry : this.authorizationConfiguration.getRawPolicies().entrySet()){ if (permissionEntry.getValue().getAllowAuthenticated()){ permissions.add(permissionEntry.getKey()); } diff --git a/backend/web/src/main/resources/messages.properties b/backend/web/src/main/resources/messages.properties index d590e2ebc..9c04fd2b4 100644 --- a/backend/web/src/main/resources/messages.properties +++ b/backend/web/src/main/resources/messages.properties @@ -27,4 +27,6 @@ Validation.LargerThenEqual= value {0} must be equal or larger than {1} Validation.MissingFields= missing fields: {0} Validation.InvalidDescriptionTemplateMultiplicity= {0} can not be used Validation.InvalidDescriptionTemplateMultiplicityOnDMP= Description Templates has multiplicity errors -Validation_UrlRequired={0} is not valid url \ No newline at end of file +Validation_UrlRequired={0} is not valid url + +DefaultTenant_Name=Default \ No newline at end of file diff --git a/dmp-frontend/src/app/core/services/http/principal.service.ts b/dmp-frontend/src/app/core/services/http/principal.service.ts index fb2d64c65..a5538a027 100644 --- a/dmp-frontend/src/app/core/services/http/principal.service.ts +++ b/dmp-frontend/src/app/core/services/http/principal.service.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; import { map } from 'rxjs/operators'; +import { Tenant } from '@app/core/model/tenant/tenant'; @Injectable() export class PrincipalService { @@ -20,8 +21,8 @@ export class PrincipalService { return this.http.get(url, options); } - public myTenants(options?: Object): Observable> { + public myTenants(options?: Object): Observable> { const url = `${this.apiBase}/my-tenants`; - return this.http.get>(url, options); + return this.http.get>(url, options); } } diff --git a/dmp-frontend/src/app/ui/auth/login/post-login/post-login.component.ts b/dmp-frontend/src/app/ui/auth/login/post-login/post-login.component.ts index 4a0a94b5c..bf72c9cc5 100644 --- a/dmp-frontend/src/app/ui/auth/login/post-login/post-login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/post-login/post-login.component.ts @@ -64,9 +64,9 @@ export class PostLoginComponent extends BaseComponent implements OnInit { this.principalService.myTenants({ params: params }).subscribe(myTenants => { if (myTenants) { if (myTenants.length > 1) { - this.tenants = myTenants.map(function (code) { return { 'code': code }; }); + this.tenants = myTenants; } else if (myTenants.length === 1) { - this.authService.selectedTenant(myTenants[0]); + this.authService.selectedTenant(myTenants[0]?.code); this.loadUser(); } else { this.authService.selectedTenant(null); diff --git a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.html b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.html index 775d85bba..9a36ad797 100644 --- a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.html +++ b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.html @@ -1,5 +1,5 @@
- {{ tenant }} + {{ tenant.name }}
diff --git a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts index 1e053cb95..8c28a854a 100644 --- a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts +++ b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts @@ -1,6 +1,7 @@ import { Component, EventEmitter, OnInit, Output } from "@angular/core"; import { MatButtonToggleChange } from "@angular/material/button-toggle"; import { Router } from "@angular/router"; +import { Tenant } from "@app/core/model/tenant/tenant"; import { AuthService } from "@app/core/services/auth/auth.service"; import { PrincipalService } from "@app/core/services/http/principal.service"; import { BaseComponent } from "@common/base/base.component"; @@ -16,7 +17,7 @@ import { takeUntil } from "rxjs/operators"; styleUrls: ['tenant-switch.component.scss'] }) export class TenantSwitchComponent extends BaseComponent implements OnInit { - tenants: Observable>; + tenants: Observable>; constructor( private router: Router, @@ -26,7 +27,7 @@ export class TenantSwitchComponent extends BaseComponent implements OnInit { ) { super(); } - + get currentTenant(): string { return this.authService.selectedTenant(); } @@ -36,7 +37,7 @@ export class TenantSwitchComponent extends BaseComponent implements OnInit { //this.tenantChange.emit(this.getCurrentLanguage()) } - loadUserTenants(): Observable> { + loadUserTenants(): Observable> { const params = new BaseHttpParams(); params.interceptorContext = { excludedInterceptors: [InterceptorType.TenantHeaderInterceptor] @@ -61,8 +62,8 @@ export class TenantSwitchComponent extends BaseComponent implements OnInit { .subscribe( () => { this.authService.onAuthenticateSuccessReload(); - }, + }, (error) => this.authService.onAuthenticateError(error) ); } -} \ No newline at end of file +} diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile.component.html b/dmp-frontend/src/app/ui/user-profile/user-profile.component.html index 06de05ffd..19f7600a6 100644 --- a/dmp-frontend/src/app/ui/user-profile/user-profile.component.html +++ b/dmp-frontend/src/app/ui/user-profile/user-profile.component.html @@ -15,7 +15,7 @@ Tenant - {{ tenant }} + {{ tenant.name }} @@ -83,9 +83,9 @@ --> @@ -226,7 +226,7 @@ - + diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts index 5179089e0..8b55e5be2 100644 --- a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts +++ b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts @@ -38,6 +38,7 @@ import { ReferenceTypeService } from '@app/core/services/reference-type/referenc import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; import { ReferenceSourceType } from '@app/core/common/enum/reference-source-type'; import { ReferenceType } from '@app/core/model/reference-type/reference-type'; +import { Tenant } from '@app/core/model/tenant/tenant'; @Component({ selector: 'app-user-profile', @@ -61,7 +62,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes errorMessages = []; nestedCount = []; nestedIndex = 0; - tenants: Observable>; + tenants: Observable>; expandedPreferences: boolean = false; organisationsSingleAutoCompleteConfiguration: SingleAutoCompleteConfiguration; @@ -154,7 +155,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes [nameof(x => x.additionalInfo), nameof(x => x.organization), nameof(x => x.reference)].join('.'), [nameof(x => x.additionalInfo), nameof(x => x.organization), nameof(x => x.source)].join('.'), [nameof(x => x.additionalInfo), nameof(x => x.organization), nameof(x => x.sourceType)].join('.'), - [nameof(x => x.additionalInfo), nameof(x => x.organization), nameof(x => x.isActive)].join('.'), + [nameof(x => x.additionalInfo), nameof(x => x.organization), nameof(x => x.isActive)].join('.'), nameof(x => x.additionalInfo.roleOrganization), nameof(x => x.createdAt), nameof(x => x.updatedAt), @@ -438,7 +439,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes } // Switch Tenant - loadUserTenants(): Observable> { + loadUserTenants(): Observable> { const params = new BaseHttpParams(); params.interceptorContext = { excludedInterceptors: [InterceptorType.TenantHeaderInterceptor] From 125fd2c994d376c75c95aeff8ac8a5fd2e7e54e6 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Fri, 17 May 2024 12:02:00 +0300 Subject: [PATCH 2/4] tenant code validation --- .../errorcode/ErrorThesaurusProperties.java | 48 +++++++++++-------- .../service/tenant/TenantServiceImpl.java | 3 ++ .../web/src/main/resources/config/errors.yml | 4 +- .../core/common/enum/respone-error-code.ts | 2 +- dmp-frontend/src/common/base/base-editor.ts | 5 +- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java index ddd3ab82c..780008ce6 100644 --- a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java +++ b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java @@ -8,7 +8,7 @@ public class ErrorThesaurusProperties { private ErrorDescription systemError; public ErrorDescription getSystemError() { - return systemError; + return this.systemError; } public void setSystemError(ErrorDescription systemError) { @@ -18,7 +18,7 @@ public class ErrorThesaurusProperties { private ErrorDescription forbidden; public ErrorDescription getForbidden() { - return forbidden; + return this.forbidden; } public void setForbidden(ErrorDescription forbidden) { @@ -28,7 +28,7 @@ public class ErrorThesaurusProperties { private ErrorDescription hashConflict; public ErrorDescription getHashConflict() { - return hashConflict; + return this.hashConflict; } public void setHashConflict(ErrorDescription hashConflict) { @@ -38,7 +38,7 @@ public class ErrorThesaurusProperties { private ErrorDescription modelValidation; public ErrorDescription getModelValidation() { - return modelValidation; + return this.modelValidation; } public void setModelValidation(ErrorDescription modelValidation) { @@ -48,7 +48,7 @@ public class ErrorThesaurusProperties { private ErrorDescription descriptionTemplateNewVersionConflict; public ErrorDescription getDescriptionTemplateNewVersionConflict() { - return descriptionTemplateNewVersionConflict; + return this.descriptionTemplateNewVersionConflict; } public void setDescriptionTemplateNewVersionConflict(ErrorDescription descriptionTemplateNewVersionConflict) { @@ -58,7 +58,7 @@ public class ErrorThesaurusProperties { private ErrorDescription dmpNewVersionConflict; public ErrorDescription getDmpNewVersionConflict() { - return dmpNewVersionConflict; + return this.dmpNewVersionConflict; } public void setDmpNewVersionConflict(ErrorDescription dmpNewVersionConflict) { @@ -68,7 +68,7 @@ public class ErrorThesaurusProperties { public ErrorDescription dmpBlueprintNewVersionConflict; public ErrorDescription getDmpBlueprintNewVersionConflict() { - return dmpBlueprintNewVersionConflict; + return this.dmpBlueprintNewVersionConflict; } public void setDmpBlueprintNewVersionConflict(ErrorDescription dmpBlueprintNewVersionConflict) { @@ -78,7 +78,7 @@ public class ErrorThesaurusProperties { private ErrorDescription dmpIsFinalized; public ErrorDescription getDmpIsFinalized() { - return dmpIsFinalized; + return this.dmpIsFinalized; } public void setDmpIsFinalized(ErrorDescription dmpIsFinalized) { @@ -88,7 +88,7 @@ public class ErrorThesaurusProperties { private ErrorDescription dmpCanNotChange; public ErrorDescription getDmpCanNotChange() { - return dmpCanNotChange; + return this.dmpCanNotChange; } public void setDmpCanNotChange(ErrorDescription dmpCanNotChange) { @@ -98,7 +98,7 @@ public class ErrorThesaurusProperties { private ErrorDescription dmpDescriptionTemplateCanNotChange; public ErrorDescription getDmpDescriptionTemplateCanNotChange() { - return dmpDescriptionTemplateCanNotChange; + return this.dmpDescriptionTemplateCanNotChange; } public void setDmpDescriptionTemplateCanNotChange(ErrorDescription dmpDescriptionTemplateCanNotChange) { @@ -108,7 +108,7 @@ public class ErrorThesaurusProperties { private ErrorDescription invalidDescriptionTemplate; public ErrorDescription getInvalidDescriptionTemplate() { - return invalidDescriptionTemplate; + return this.invalidDescriptionTemplate; } public void setInvalidDescriptionTemplate(ErrorDescription invalidDescriptionTemplate) { @@ -118,7 +118,7 @@ public class ErrorThesaurusProperties { private ErrorDescription descriptionIsFinalized; public ErrorDescription getDescriptionIsFinalized() { - return descriptionIsFinalized; + return this.descriptionIsFinalized; } public void setDescriptionIsFinalized(ErrorDescription descriptionIsFinalized) { @@ -128,7 +128,7 @@ public class ErrorThesaurusProperties { private ErrorDescription dmpBlueprintHasNoDescriptionTemplates; public ErrorDescription getDmpBlueprintHasNoDescriptionTemplates() { - return dmpBlueprintHasNoDescriptionTemplates; + return this.dmpBlueprintHasNoDescriptionTemplates; } public void setDmpBlueprintHasNoDescriptionTemplates(ErrorDescription dmpBlueprintHasNoDescriptionTemplates) { @@ -138,7 +138,7 @@ public class ErrorThesaurusProperties { private ErrorDescription dmpDescriptionTemplateCanNotRemove; public ErrorDescription getDmpDescriptionTemplateCanNotRemove() { - return dmpDescriptionTemplateCanNotRemove; + return this.dmpDescriptionTemplateCanNotRemove; } public void setDmpDescriptionTemplateCanNotRemove(ErrorDescription dmpDescriptionTemplateCanNotRemove) { @@ -148,7 +148,7 @@ public class ErrorThesaurusProperties { private ErrorDescription missingTenant; public ErrorDescription getMissingTenant() { - return missingTenant; + return this.missingTenant; } public void setMissingTenant(ErrorDescription missingTenant) { @@ -158,7 +158,7 @@ public class ErrorThesaurusProperties { private ErrorDescription tenantNotAllowed; public ErrorDescription getTenantNotAllowed() { - return tenantNotAllowed; + return this.tenantNotAllowed; } public void setTenantNotAllowed(ErrorDescription tenantNotAllowed) { @@ -168,7 +168,7 @@ public class ErrorThesaurusProperties { private ErrorDescription tenantTampering; public ErrorDescription getTenantTampering() { - return tenantTampering; + return this.tenantTampering; } public void setTenantTampering(ErrorDescription tenantTampering) { @@ -178,7 +178,7 @@ public class ErrorThesaurusProperties { private ErrorDescription tenantConfigurationTypeCanNotChange; public ErrorDescription getTenantConfigurationTypeCanNotChange() { - return tenantConfigurationTypeCanNotChange; + return this.tenantConfigurationTypeCanNotChange; } public void setTenantConfigurationTypeCanNotChange(ErrorDescription tenantConfigurationTypeCanNotChange) { @@ -188,10 +188,20 @@ public class ErrorThesaurusProperties { private ErrorDescription multipleTenantConfigurationTypeNotAllowed; public ErrorDescription getMultipleTenantConfigurationTypeNotAllowed() { - return multipleTenantConfigurationTypeNotAllowed; + return this.multipleTenantConfigurationTypeNotAllowed; } public void setMultipleTenantConfigurationTypeNotAllowed(ErrorDescription multipleTenantConfigurationTypeNotAllowed) { this.multipleTenantConfigurationTypeNotAllowed = multipleTenantConfigurationTypeNotAllowed; } + + private ErrorDescription tenantCodeExists; + + public ErrorDescription getTenantCodeExists() { + return this.tenantCodeExists; + } + + public void setTenantCodeExists(ErrorDescription tenantCodeExists) { + this.tenantCodeExists = tenantCodeExists; + } } diff --git a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java index 67a0205d5..e8dba3eed 100644 --- a/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/tenant/TenantServiceImpl.java @@ -141,6 +141,9 @@ public class TenantServiceImpl implements TenantService { else this.entityManager.persist(data); this.entityManager.flush(); + + Long tenantsWithThisCode = this.queryFactory.query(TenantQuery.class).codes(data.getCode()).count(); + if (tenantsWithThisCode > 1) throw new MyValidationException(this.errors.getTenantCodeExists().getCode(), this.errors.getTenantCodeExists().getMessage()); if (!isUpdate) { this.keycloakService.createTenantGroups(data.getCode()); diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index 284314b61..9409cad3c 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -65,4 +65,6 @@ error-thesaurus: multiple-tenant-configuration-type-not-allowed: code: 125 message: Multiple Tenant Configuration Type Not Allowed - + tenant-code-exists: + code: 126 + message: Tenant code exists \ No newline at end of file diff --git a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts index acbf1515a..bf367108d 100644 --- a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts +++ b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts @@ -16,5 +16,5 @@ export enum ResponseErrorCode { TenantTampering = 123, TenantConfigurationTypeCanNotChange = 124, MultipleTenantConfigurationTypeNotAllowed = 125, - + TenantCodeExists = 126, } diff --git a/dmp-frontend/src/common/base/base-editor.ts b/dmp-frontend/src/common/base/base-editor.ts index 17d501e49..d16932a00 100644 --- a/dmp-frontend/src/common/base/base-editor.ts +++ b/dmp-frontend/src/common/base/base-editor.ts @@ -138,7 +138,10 @@ export abstract class BaseEditor Date: Fri, 17 May 2024 12:15:23 +0300 Subject: [PATCH 3/4] Fixed plan overview link on description editor banner --- .../app/ui/description/editor/description-editor.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.component.html b/dmp-frontend/src/app/ui/description/editor/description-editor.component.html index 3ec5ac043..6f52370a1 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.component.html +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.component.html @@ -19,7 +19,7 @@
{{'DESCRIPTION-EDITOR.TO-DMP' | translate}}
: {{ item?.dmp?.label }}
From 8a0d02d02e571a3eeed1c427c2f6459e74c71edd Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Fri, 17 May 2024 12:46:20 +0300 Subject: [PATCH 4/4] Remove not visible fields on persist --- .../persist/DescriptionReferencePersist.java | 17 ++++---- .../PropertyDefinitionPersist.java | 33 ++++++++------- .../DescriptionReferenceDataPersist.java | 7 ++-- .../description/DescriptionServiceImpl.java | 42 +++++++++++-------- 4 files changed, 53 insertions(+), 46 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionReferencePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionReferencePersist.java index fb3eff3e7..6a4633c81 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionReferencePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionReferencePersist.java @@ -1,12 +1,12 @@ package org.opencdmp.model.persist; -import org.opencdmp.commons.validation.BaseValidator; -import org.opencdmp.model.persist.descriptionreference.DescriptionReferenceDataPersist; -import org.opencdmp.model.persist.dmpreference.DmpReferenceDataPersist; import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.specification.Specification; +import org.opencdmp.commons.validation.BaseValidator; import org.opencdmp.convention.ConventionService; import org.opencdmp.errorcode.ErrorThesaurusProperties; +import org.opencdmp.model.persist.descriptionreference.DescriptionReferenceDataPersist; +import org.opencdmp.model.persist.dmpreference.DmpReferenceDataPersist; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; @@ -15,12 +15,11 @@ import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -import java.util.UUID; public class DescriptionReferencePersist { - private ReferencePersist reference = null; + private ReferencePersist reference; public static final String _reference = "reference"; @@ -30,7 +29,7 @@ public class DescriptionReferencePersist { public static final String _data = "data"; public ReferencePersist getReference() { - return reference; + return this.reference; } public void setReference(ReferencePersist reference) { @@ -38,7 +37,7 @@ public class DescriptionReferencePersist { } public DescriptionReferenceDataPersist getData() { - return data; + return this.data; } public void setData(DescriptionReferenceDataPersist data) { @@ -71,7 +70,7 @@ public class DescriptionReferencePersist { return Arrays.asList( this.spec() .must(() -> !this.isNull(item.getReference())) - .failOn(DescriptionReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._reference}, LocaleContextHolder.getLocale())), + .failOn(DescriptionReferencePersist._reference).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._reference}, LocaleContextHolder.getLocale())), this.refSpec() .iff(() -> !this.isNull(item.getReference())) .on(DescriptionReferencePersist._reference) @@ -79,7 +78,7 @@ public class DescriptionReferencePersist { .using(() -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class)), this.spec() .must(() -> !this.isNull(item.getData())) - .failOn(DescriptionReferencePersist._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._data}, LocaleContextHolder.getLocale())), + .failOn(DescriptionReferencePersist._data).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._data}, LocaleContextHolder.getLocale())), this.refSpec() .iff(() -> !this.isNull(item.getData())) .on(DescriptionReferencePersist._data) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/PropertyDefinitionPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/PropertyDefinitionPersist.java index 5791fd959..36c6562c5 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/PropertyDefinitionPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/PropertyDefinitionPersist.java @@ -1,5 +1,7 @@ package org.opencdmp.model.persist.descriptionproperties; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; import org.opencdmp.commons.enums.DescriptionStatus; import org.opencdmp.commons.enums.FieldValidationType; import org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity; @@ -11,15 +13,16 @@ import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.model.persist.validation.StatusAware; import org.opencdmp.service.visibility.VisibilityService; import org.opencdmp.service.visibility.VisibilityServiceImpl; -import gr.cite.tools.validation.ValidatorFactory; -import gr.cite.tools.validation.specification.Specification; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; public class PropertyDefinitionPersist { @@ -29,7 +32,7 @@ public class PropertyDefinitionPersist { private Map fieldSets; public Map getFieldSets() { - return fieldSets; + return this.fieldSets; } public void setFieldSets(Map fieldSets) { @@ -67,21 +70,21 @@ public class PropertyDefinitionPersist { this.spec() .iff(() -> this.status == DescriptionStatus.Finalized) .must(() -> !this.isNull(item.getFieldSets()) && !item.getFieldSets().isEmpty()) - .failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fieldSets}, LocaleContextHolder.getLocale())), + .failOn(PropertyDefinitionPersist._fieldSets).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fieldSets}, LocaleContextHolder.getLocale())), this.spec() .must(() -> this.isListNullOrEmpty(this.getMissingFieldSetEntity(item))) - .failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFieldSets(this.getMissingFieldSetEntity(item))}, LocaleContextHolder.getLocale())), + .failOn(PropertyDefinitionPersist._fieldSets).failWith(this.messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFieldSets(this.getMissingFieldSetEntity(item))}, LocaleContextHolder.getLocale())), this.spec() .must(() -> this.isListNullOrEmpty(this.getMissingFieldsEntity(item))) - .failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFields(this.getMissingFieldsEntity(item))}, LocaleContextHolder.getLocale())), + .failOn(PropertyDefinitionPersist._fieldSets).failWith(this.messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFields(this.getMissingFieldsEntity(item))}, LocaleContextHolder.getLocale())), this.mapSpec() .iff(() -> !this.isNull(item.getFieldSets())) .on(PropertyDefinitionPersist._fieldSets) .over(item.getFieldSets()) .mapKey((k) -> ((String)k)) .using((itm) -> { - FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null; - return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity).withVisibilityService(visibilityService).setStatus(this.status); + FieldSetEntity fieldSetEntity = this.definition != null ? this.definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null; + return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity).withVisibilityService(this.visibilityService).setStatus(this.status); }) ); } @@ -105,8 +108,8 @@ public class PropertyDefinitionPersist { private List getMissingFieldSetEntity(PropertyDefinitionPersist item){ List missingMultipleFieldSets = new ArrayList<>(); - if (definition == null || definition.getAllFieldSets() == null) return missingMultipleFieldSets; - for (FieldSetEntity fieldSet: definition.getAllFieldSets()) { + if (this.definition == null || this.definition.getAllFieldSets() == null) return missingMultipleFieldSets; + for (FieldSetEntity fieldSet: this.definition.getAllFieldSets()) { boolean requiredAtLeastOneFieldSet = fieldSet.getMultiplicity() != null && fieldSet.getHasMultiplicity() && fieldSet.getMultiplicity().getMin() > 0; if (requiredAtLeastOneFieldSet) { @@ -124,8 +127,8 @@ public class PropertyDefinitionPersist { private List getMissingFieldsEntity(PropertyDefinitionPersist item){ List missingFields = new ArrayList<>(); - if (definition == null || definition.getAllFieldSets() == null) return missingFields; - for (FieldSetEntity fieldSet: definition.getAllFieldSets()) { + if (this.definition == null || this.definition.getAllFieldSets() == null) return missingFields; + for (FieldSetEntity fieldSet: this.definition.getAllFieldSets()) { if (fieldSet.getFields() == null) continue; @@ -163,12 +166,12 @@ public class PropertyDefinitionPersist { private String serializeMissingFieldSets (List missingFieldSets){ if (missingFieldSets == null) return ""; - return missingFieldSets.stream().map(x -> x.getId()).collect(Collectors.joining(", ")); + return missingFieldSets.stream().map(FieldSetEntity::getId).collect(Collectors.joining(", ")); } private String serializeMissingFields (List missingFields){ if (missingFields == null) return ""; - return missingFields.stream().map(x -> x.getId()).collect(Collectors.joining(", ")); + return missingFields.stream().map(FieldEntity::getId).collect(Collectors.joining(", ")); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionreference/DescriptionReferenceDataPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionreference/DescriptionReferenceDataPersist.java index 812b6a0e4..c3a23d736 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionreference/DescriptionReferenceDataPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionreference/DescriptionReferenceDataPersist.java @@ -1,9 +1,9 @@ package org.opencdmp.model.persist.descriptionreference; +import gr.cite.tools.validation.specification.Specification; import org.opencdmp.commons.validation.BaseValidator; import org.opencdmp.convention.ConventionService; import org.opencdmp.errorcode.ErrorThesaurusProperties; -import gr.cite.tools.validation.specification.Specification; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; @@ -12,7 +12,6 @@ import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; -import java.util.UUID; public class DescriptionReferenceDataPersist { @@ -21,7 +20,7 @@ public class DescriptionReferenceDataPersist { public static final String _fieldId = "fieldId"; public String getFieldId() { - return fieldId; + return this.fieldId; } public void setFieldId(String fieldId) { @@ -50,7 +49,7 @@ public class DescriptionReferenceDataPersist { return Arrays.asList( this.spec() .must(() -> !this.isNull(item.getFieldId())) - .failOn(DescriptionReferenceDataPersist._fieldId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._fieldId}, LocaleContextHolder.getLocale())) + .failOn(DescriptionReferenceDataPersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._fieldId}, LocaleContextHolder.getLocale())) ); } } diff --git a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java index 742bec78b..e52c2c0ff 100644 --- a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java @@ -66,6 +66,8 @@ import org.opencdmp.service.filetransformer.FileTransformerService; import org.opencdmp.service.responseutils.ResponseUtilsService; import org.opencdmp.service.storage.StorageFileProperties; import org.opencdmp.service.storage.StorageFileService; +import org.opencdmp.service.visibility.VisibilityService; +import org.opencdmp.service.visibility.VisibilityServiceImpl; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; @@ -237,11 +239,12 @@ public class DescriptionServiceImpl implements DescriptionService { this.entityManager.flush(); org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); - Map> fieldToReferenceMap = this.patchAndSaveReferences(this.buildDescriptionReferencePersists(model.getProperties()), data.getId(), definition); + VisibilityService visibilityService = new VisibilityServiceImpl(definition, model.getProperties()); + Map> fieldToReferenceMap = this.patchAndSaveReferences(this.buildDescriptionReferencePersists(visibilityService, model.getProperties()), data.getId(), definition); this.entityManager.flush(); - data.setProperties(this.jsonHandlingService.toJson(this.buildPropertyDefinitionEntity(model.getProperties(), definition, fieldToReferenceMap))); + data.setProperties(this.jsonHandlingService.toJson(this.buildPropertyDefinitionEntity(visibilityService, model.getProperties(), definition, fieldToReferenceMap))); this.entityManager.merge(data); @@ -262,7 +265,7 @@ public class DescriptionServiceImpl implements DescriptionService { return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Description._id), data); } @Override - public void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException, JAXBException { + public void updateDescriptionTemplate(UpdateDescriptionTemplatePersist model) throws InvalidApplicationException, IOException { logger.debug(new MapLogEntry("update description template").And("model", model)); this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(model.getId())), Permission.EditDescription); @@ -399,7 +402,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.eventHandler.handle(event); } - private NotifyIntegrationEvent applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event) { + private void applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event) { switch (status) { case Draft: event.setNotificationType(this.notificationProperties.getDescriptionModifiedType()); @@ -410,7 +413,7 @@ public class DescriptionServiceImpl implements DescriptionService { default: throw new MyApplicationException("Unsupported Description Status."); } - return event; + return; } @Override @@ -460,38 +463,39 @@ public class DescriptionServiceImpl implements DescriptionService { DescriptionPersist.DescriptionPersistValidator validator = this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class); validator.validate(this.buildDescriptionPersist(description)); if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid); - descriptionValidationResults.add(descriptionValidationResult); + + descriptionValidationResults.add(descriptionValidationResult); } return descriptionValidationResults; } - private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(PropertyDefinitionPersist persist, org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity definition, Map> fieldToReferenceMap) throws InvalidApplicationException { + private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(VisibilityService visibilityService, PropertyDefinitionPersist persist, org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity definition, Map> fieldToReferenceMap) throws InvalidApplicationException { PropertyDefinitionEntity data = new PropertyDefinitionEntity(); if (persist == null) return data; if (persist.getFieldSets() != null && !persist.getFieldSets().isEmpty()){ data.setFieldSets(new HashMap<>()); for (String key: persist.getFieldSets().keySet()) { FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null; - data.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetEntity(persist.getFieldSets().get(key), fieldSetEntity, fieldToReferenceMap)); + data.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetEntity(persist.getFieldSets().get(key), fieldSetEntity, fieldToReferenceMap, visibilityService)); } } return data; } - private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist, FieldSetEntity fieldSetEntity, Map> fieldToReferenceMap) throws InvalidApplicationException { + private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist, FieldSetEntity fieldSetEntity, Map> fieldToReferenceMap, VisibilityService visibilityService) throws InvalidApplicationException { PropertyDefinitionFieldSetEntity data = new PropertyDefinitionFieldSetEntity(); if (persist == null) return data; if (!this.conventionService.isListNullOrEmpty(persist.getItems())){ data.setItems(new ArrayList<>()); for (PropertyDefinitionFieldSetItemPersist itemsPersist: persist.getItems()) { - data.getItems().add(this.buildPropertyDefinitionFieldSetItemEntity(itemsPersist, fieldSetEntity, fieldToReferenceMap)); + data.getItems().add(this.buildPropertyDefinitionFieldSetItemEntity(itemsPersist, fieldSetEntity, fieldToReferenceMap, visibilityService)); } } return data; } - private @NotNull PropertyDefinitionFieldSetItemEntity buildPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemPersist persist, FieldSetEntity fieldSetEntity, Map> fieldToReferenceMap) throws InvalidApplicationException { + private @NotNull PropertyDefinitionFieldSetItemEntity buildPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemPersist persist, FieldSetEntity fieldSetEntity, Map> fieldToReferenceMap, VisibilityService visibilityService) throws InvalidApplicationException { PropertyDefinitionFieldSetItemEntity data = new PropertyDefinitionFieldSetItemEntity(); if (persist == null) return data; if (persist.getFields() != null && !persist.getFields().isEmpty()){ @@ -500,16 +504,17 @@ public class DescriptionServiceImpl implements DescriptionService { data.setFields(new HashMap<>()); for (String key: persist.getFields().keySet()) { org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null; - data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap)); + boolean isVisible = fieldEntity != null ? visibilityService.isVisible(fieldEntity.getId(), persist.getOrdinal()) : false; + data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap, isVisible)); } } return data; } - private @NotNull FieldEntity buildFieldEntity(FieldPersist persist, org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity, Map> fieldToReferenceMap) throws InvalidApplicationException { + private @NotNull FieldEntity buildFieldEntity(FieldPersist persist, org.opencdmp.commons.types.descriptiontemplate.FieldEntity fieldEntity, Map> fieldToReferenceMap, boolean isVisible) throws InvalidApplicationException { FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; FieldEntity data = new FieldEntity(); - if (persist == null) return data; + if (persist == null || !isVisible) return data; if (FieldType.isTextType(fieldType)) { if (FieldType.UPLOAD.equals(fieldType)){ @@ -537,7 +542,7 @@ public class DescriptionServiceImpl implements DescriptionService { else if (FieldType.isTextListType(fieldType)) { List ids = new ArrayList<>(); if (FieldType.INTERNAL_ENTRIES_DMPS.equals(fieldType)) { - if (!this.conventionService.isListNullOrEmpty(persist.getTextListValue())) persist.getTextListValue().stream().map(UUID::fromString).toList(); + if (!this.conventionService.isListNullOrEmpty(persist.getTextListValue())) ids = persist.getTextListValue().stream().map(UUID::fromString).toList(); else if (!this.conventionService.isNullOrEmpty(persist.getTextValue())) ids.add(UUID.fromString(persist.getTextValue())); if (!ids.isEmpty()){ @@ -590,7 +595,7 @@ public class DescriptionServiceImpl implements DescriptionService { return data; } - private @NotNull List buildDescriptionReferencePersists(PropertyDefinitionPersist persist){ + private @NotNull List buildDescriptionReferencePersists(VisibilityService visibilityService, PropertyDefinitionPersist persist){ List descriptionReferencePersists = new ArrayList<>(); if (persist.getFieldSets() != null && !persist.getFieldSets().isEmpty()){ for (PropertyDefinitionFieldSetPersist propertyDefinitionFieldSetPersist: persist.getFieldSets().values()) { @@ -599,7 +604,8 @@ public class DescriptionServiceImpl implements DescriptionService { if (definitionFieldSetItemPersist.getFields() != null && !definitionFieldSetItemPersist.getFields().isEmpty()) { for (String key : definitionFieldSetItemPersist.getFields().keySet()) { FieldPersist fieldPersist = definitionFieldSetItemPersist.getFields().get(key); - this.BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists); + boolean isVisible = visibilityService.isVisible(key, definitionFieldSetItemPersist.getOrdinal()); + if (isVisible) this.BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists); } } } @@ -649,7 +655,7 @@ public class DescriptionServiceImpl implements DescriptionService { List updatedCreatedIds = new ArrayList<>(); for (DescriptionReferencePersist model : models) { ReferencePersist referencePersist = model.getReference(); - ReferenceEntity referenceEntity = null; + ReferenceEntity referenceEntity; if (this.conventionService.isValidGuid(referencePersist.getId())){ referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId()); if (referenceEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));