From 11bb1a3c8c281778635a3b605fc7a5265846983b Mon Sep 17 00:00:00 2001 From: amentis Date: Mon, 6 Nov 2023 15:25:04 +0200 Subject: [PATCH] create Supportive Material query public --- .../censorship/SupportiveMaterialCensor.java | 2 +- .../java/eu/eudat/query/ReferenceQuery.java | 25 +++++----- .../eudat/query/SupportiveMaterialQuery.java | 1 + .../SupportiveMaterialServiceImpl.java | 2 +- .../v2/SupportiveMaterialController.java | 27 +++++----- .../src/main/resources/config/permissions.yml | 22 +++++++++ .../resources/material/about/About_gr.html | 17 ------- .../supportive-material.service.ts | 11 ++--- .../src/app/ui/about/about.component.ts | 6 ++- .../faq/faq-content/faq-content.component.ts | 6 ++- .../glossary-content.component.ts | 6 ++- .../sidebar-footer/terms/terms.component.ts | 6 ++- .../supportive-material-editor.component.ts | 49 ++++++++++--------- .../user-guide-content.component.ts | 6 ++- 14 files changed, 106 insertions(+), 80 deletions(-) delete mode 100644 dmp-backend/web/src/main/resources/material/about/About_gr.html diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/SupportiveMaterialCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/SupportiveMaterialCensor.java index 72d4dcefe..59943a975 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/SupportiveMaterialCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/SupportiveMaterialCensor.java @@ -38,7 +38,7 @@ public class SupportiveMaterialCensor extends BaseCensor { if (fields == null || fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseDmpBlueprint); + this.authService.authorizeForce(Permission.BrowseSupportiveMaterial); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java index c2503d74a..20b86852c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java @@ -6,6 +6,7 @@ import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.ReferenceEntity; +import eu.eudat.model.Reference; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; @@ -213,18 +214,18 @@ public class ReferenceQuery extends QueryBase { @Override protected String fieldNameOf(FieldResolver item) { if (item.match(ReferenceEntity._id)) return ReferenceEntity._id; - else if (item.match(ReferenceEntity._label)) return ReferenceEntity._label; - else if (item.match(ReferenceEntity._description)) return ReferenceEntity._description; - else if (item.match(ReferenceEntity._createdAt)) return ReferenceEntity._createdAt; - else if (item.match(ReferenceEntity._updatedAt)) return ReferenceEntity._updatedAt; - else if (item.match(ReferenceEntity._isActive)) return ReferenceEntity._isActive; - else if (item.match(ReferenceEntity._definition)) return ReferenceEntity._definition; - else if (item.match(ReferenceEntity._abbreviation)) return ReferenceEntity._abbreviation; - else if (item.match(ReferenceEntity._reference)) return ReferenceEntity._reference; - else if (item.match(ReferenceEntity._source)) return ReferenceEntity._source; - else if (item.match(ReferenceEntity._sourceType)) return ReferenceEntity._sourceType; - else if (item.match(ReferenceEntity._type)) return ReferenceEntity._type; - //else if (item.prefix(ReferenceEntity._createdBy)) return ReferenceEntity._createdBy; + else if (item.match(Reference._label)) return ReferenceEntity._label; + else if (item.match(Reference._description)) return ReferenceEntity._description; + else if (item.match(Reference._createdAt)) return ReferenceEntity._createdAt; + else if (item.match(Reference._updatedAt)) return ReferenceEntity._updatedAt; + else if (item.match(Reference._isActive)) return ReferenceEntity._isActive; + else if (item.match(Reference._definition)) return ReferenceEntity._definition; + else if (item.match(Reference._abbreviation)) return ReferenceEntity._abbreviation; + else if (item.match(Reference._reference)) return ReferenceEntity._reference; + else if (item.match(Reference._source)) return ReferenceEntity._source; + else if (item.match(Reference._sourceType)) return ReferenceEntity._sourceType; + else if (item.match(Reference._type)) return ReferenceEntity._type; + //else if (item.prefix(Reference._createdBy)) return ReferenceEntity._createdBy; else return null; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/SupportiveMaterialQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/SupportiveMaterialQuery.java index e818f2fed..5601eb2dc 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/SupportiveMaterialQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/SupportiveMaterialQuery.java @@ -210,6 +210,7 @@ public class SupportiveMaterialQuery extends QueryBase if (item.match(SupportiveMaterial._id)) return SupportiveMaterialEntity._id; else if (item.match(SupportiveMaterial._type)) return SupportiveMaterialEntity._type; else if (item.match(SupportiveMaterial._languageCode)) return SupportiveMaterialEntity._languageCode; + else if (item.match(SupportiveMaterial._payload)) return SupportiveMaterialEntity._payload; else if (item.match(SupportiveMaterial._createdAt)) return SupportiveMaterialEntity._createdAt; else if (item.match(SupportiveMaterial._updatedAt)) return SupportiveMaterialEntity._updatedAt; else if (item.match(SupportiveMaterial._isActive)) return SupportiveMaterialEntity._isActive; diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java index 24aa4481c..a51fef853 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java @@ -133,7 +133,7 @@ public class SupportiveMaterialServiceImpl implements SupportiveMaterialService{ } else { List datas = this.queryFactory.query(SupportiveMaterialQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).languageCodes(model.getLanguageCode()).types(model.getType()).collect(); - if(datas != null){ + if(datas != null && !datas.isEmpty()){ throw new MyApplicationException("Could not create a new Data with same type and lang code !"); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java index 564a18b0f..c0bb8785a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java @@ -112,26 +112,23 @@ public class SupportiveMaterialController { return model; } - @GetMapping("get/{lang}") - public ResponseEntity getMaterial(@PathVariable(name = "lang") String lang, int field) throws IOException { - if( !EnumUtils.isValidEnum(SupportiveMaterialFieldType.class, SupportiveMaterialFieldType.of((short) field).name())){ - return new ResponseEntity<>(HttpStatus.NOT_FOUND); + @PostMapping("public") + public ResponseEntity queryPublic(@RequestBody SupportiveMaterialLookup lookup) throws IOException { + logger.debug("querying {}", SupportiveMaterial.class.getSimpleName()); + + this.censorFactory.censor(SupportiveMaterialCensor.class).censor(lookup.getProject(), null); + + SupportiveMaterialQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); + List datas = query.collectAs(lookup.getProject()); + if (datas.size() == 1){ + return new ResponseEntity<>(datas.get(0).getPayload().getBytes(), HttpStatus.OK); } - try (Stream paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty(SupportiveMaterialFieldType.of((short) field).name().toLowerCase() +".path"))))) { - return this.supportiveMaterialService.getResponseEntity(lang, paths); + try (Stream paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty(lookup.getTypes().stream().toList().get(0).name().toLowerCase() +".path"))))) { + return this.supportiveMaterialService.getResponseEntity(lookup.getLanguageCodes().get(0), paths); } } -// @PostMapping("persist") -// public @ResponseBody -// ResponseEntity> persist(@RequestBody SupportiveMaterialPersist model) throws IOException { -// this.authorizationService.authorizeForce(Permission.AdminRole); -// -// //String fileName = this.environment.getProperty(model.getName()+ ".path"); -// this.supportiveMaterialService.persist(model); -// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Updated").payload("Updated")); -// } @PostMapping("persist") @Transactional diff --git a/dmp-backend/web/src/main/resources/config/permissions.yml b/dmp-backend/web/src/main/resources/config/permissions.yml index 4d4fd6d51..1d2f618c9 100644 --- a/dmp-backend/web/src/main/resources/config/permissions.yml +++ b/dmp-backend/web/src/main/resources/config/permissions.yml @@ -300,6 +300,28 @@ permissions: allowAnonymous: false allowAuthenticated: false + # SupportiveMaterial Permissions + BrowseSupportiveMaterial: + roles: + - Admin + clients: [ ] + allowAnonymous: yes + allowAuthenticated: yes + EditSupportiveMaterial: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + DeleteSupportiveMaterial: + roles: + - Admin + claims: [ ] + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + + # DmpDescriptionTemplate Permissions BrowseDmpDescriptionTemplate: roles: diff --git a/dmp-backend/web/src/main/resources/material/about/About_gr.html b/dmp-backend/web/src/main/resources/material/about/About_gr.html deleted file mode 100644 index c2bfd135c..000000000 --- a/dmp-backend/web/src/main/resources/material/about/About_gr.html +++ /dev/null @@ -1,17 +0,0 @@ -

 

-

- - -

-
-
-
-

Σχετικά με το Argos

-
-
-
-
-

Το ARGOS είναι ένα διαδικτυακό εργαλείο για την υποστήριξη αυτοματοποιημένων διαδικασιών για τη δημιουργία, τη διαχείριση, την κοινή χρήση και τη σύνδεση των DMP με ερευνητικά αντικείμενα στα οποία αντιστοιχούν. Αποτελεί κοινή προσπάθεια του OpenAIRE και της EUDAT να παραδώσουν μια ανοιχτή πλατφόρμα για τον Σχεδιασμό Διαχείρισης Δεδομένων που να αντιμετωπίζει τις βέλτιστες πρακτικές FAIR και Open και να μην προϋποθέτει εμπόδια για τη χρήση και την υιοθέτησή της. Το κάνει εφαρμόζοντας κοινά πρότυπα για μηχανικά ενεργά DMPs, όπως ορίζονται από την παγκόσμια κοινότητα ερευνητικών δεδομένων της RDA και επικοινωνώντας και διαβουλεύοντας τους ερευνητές, τις ερευνητικές κοινότητες και τους χρηματοδότες για να προβληματιστούν καλύτερα για τις ανάγκες τους.

Το ARGOS παρέχει ένα ευέλικτο περιβάλλον και μια εύκολη διεπαφή για την πλοήγηση και χρήση των χρηστών.

-
-
-
\ No newline at end of file diff --git a/dmp-frontend/src/app/core/services/supportive-material/supportive-material.service.ts b/dmp-frontend/src/app/core/services/supportive-material/supportive-material.service.ts index 454b20514..d5f82c30a 100644 --- a/dmp-frontend/src/app/core/services/supportive-material/supportive-material.service.ts +++ b/dmp-frontend/src/app/core/services/supportive-material/supportive-material.service.ts @@ -10,6 +10,7 @@ import { catchError } from "rxjs/operators"; import { Guid } from "@common/types/guid"; import { nameof } from "ts-simple-nameof"; import { IsActive } from "@app/core/common/enum/is-active.enum"; +import { SupportiveMaterialFieldType } from "@app/core/common/enum/supportive-material-field-type"; @Injectable() export class SupportiveMaterialService{ @@ -22,14 +23,10 @@ export class SupportiveMaterialService{ private get apiBase(): string { return `${this.configurationService.server}supportive-material`; } - public getMaterial(lang: string, field: number): Observable> { - return this.http.get(`${this.apiBase}/get/${lang}`, {params: {field}, responseType: 'blob', observe: 'response' }); + queryPublic(q: SupportiveMaterialLookup): Observable> { + return this.http.post>(`${this.apiBase}/public`, q , {responseType: 'blob', observe: 'response' }); } - // public persist(item :SupportiveMaterialPersist): Observable { - // return this.http.post(`${this.apiBase}/persist`, item); - // } - query(q: SupportiveMaterialLookup): Observable> { const url = `${this.apiBase}/query`; return this.http.post>(url, q).pipe(catchError((error: any) => throwError(error))); @@ -63,7 +60,7 @@ export class SupportiveMaterialService{ // LOOKUP - public static DefaultSupportiveMaterialLookup(params?: {}): SupportiveMaterialLookup{ + public static DefaultSupportiveMaterialLookup(): SupportiveMaterialLookup{ const lookup = new SupportiveMaterialLookup(); lookup.project = { diff --git a/dmp-frontend/src/app/ui/about/about.component.ts b/dmp-frontend/src/app/ui/about/about.component.ts index 0325ab24d..e7799089e 100644 --- a/dmp-frontend/src/app/ui/about/about.component.ts +++ b/dmp-frontend/src/app/ui/about/about.component.ts @@ -33,7 +33,11 @@ export class AboutComponent extends BaseComponent implements OnInit { this.translate.onLangChange.subscribe((event: LangChangeEvent) => { this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/about'])); }); - this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.About) + const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup(); + lookup.languageCodes = [this.languageService.getCurrentLanguage()]; + lookup.types = [SupportiveMaterialFieldType.About]; + + this.supportiveMaterialService.queryPublic(lookup) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], { type: 'text/html' }); diff --git a/dmp-frontend/src/app/ui/faq/faq-content/faq-content.component.ts b/dmp-frontend/src/app/ui/faq/faq-content/faq-content.component.ts index d64808040..c5b64e42b 100644 --- a/dmp-frontend/src/app/ui/faq/faq-content/faq-content.component.ts +++ b/dmp-frontend/src/app/ui/faq/faq-content/faq-content.component.ts @@ -28,7 +28,11 @@ export class FaqContentComponent extends BaseComponent implements OnInit { ngOnInit() { this.matomoService.trackPageView('FAQ'); - this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.Faq) + const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup(); + lookup.languageCodes = [this.languageService.getCurrentLanguage()]; + lookup.types = [SupportiveMaterialFieldType.Faq]; + + this.supportiveMaterialService.queryPublic(lookup) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], { type: 'text/html' }); diff --git a/dmp-frontend/src/app/ui/glossary/glossary-content/glossary-content.component.ts b/dmp-frontend/src/app/ui/glossary/glossary-content/glossary-content.component.ts index d1686704d..4e101f9ba 100644 --- a/dmp-frontend/src/app/ui/glossary/glossary-content/glossary-content.component.ts +++ b/dmp-frontend/src/app/ui/glossary/glossary-content/glossary-content.component.ts @@ -36,7 +36,11 @@ export class GlossaryContentComponent extends BaseComponent implements OnInit { this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/glossary'])); }); - this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.Glossary) + const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup(); + lookup.languageCodes = [this.languageService.getCurrentLanguage()]; + lookup.types = [SupportiveMaterialFieldType.Glossary]; + + this.supportiveMaterialService.queryPublic(lookup) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], { type: 'text/html' }); diff --git a/dmp-frontend/src/app/ui/sidebar/sidebar-footer/terms/terms.component.ts b/dmp-frontend/src/app/ui/sidebar/sidebar-footer/terms/terms.component.ts index 23586c4d1..02c540e09 100644 --- a/dmp-frontend/src/app/ui/sidebar/sidebar-footer/terms/terms.component.ts +++ b/dmp-frontend/src/app/ui/sidebar/sidebar-footer/terms/terms.component.ts @@ -33,7 +33,11 @@ export class TermsComponent extends BaseComponent implements OnInit { this.translate.onLangChange.subscribe((event: LangChangeEvent) => { this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/terms-and-conditions'])); }); - this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.TermsOfService) + const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup(); + lookup.languageCodes = [this.languageService.getCurrentLanguage()]; + lookup.types = [SupportiveMaterialFieldType.TermsOfService]; + + this.supportiveMaterialService.queryPublic(lookup) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], { type: 'text/html' }); diff --git a/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.ts b/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.ts index 808a9dfc9..51b405236 100644 --- a/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.ts +++ b/dmp-frontend/src/app/ui/supportive-material-editor/supportive-material-editor.component.ts @@ -15,6 +15,7 @@ import { HttpClient } from '@angular/common/http'; import { SupportiveMaterialService } from '@app/core/services/supportive-material/supportive-material.service'; import { SupportiveMaterialFieldType } from '@app/core/common/enum/supportive-material-field-type'; import { SupportiveMaterialPersist } from '@app/core/model/supportive-material/supportive-material'; +import { Guid } from '@common/types/guid'; interface VisibleMaterialType{ name: string; @@ -71,6 +72,7 @@ export class SupportiveMaterialEditorComponent extends BaseComponent implements selectedMaterial: VisibleMaterialType; selectedLang: VisibleLangType; + materialId: Guid = null; ngOnInit() { this.selectedMaterial = this.visiblesMaterialsTypes.find(x => x.type == SupportiveMaterialFieldType.Faq); @@ -96,12 +98,21 @@ export class SupportiveMaterialEditorComponent extends BaseComponent implements name: [''], html: [''] }); - this.supportiveMaterialService.getMaterial(this.selectedLang.type, this.selectedMaterial.type).pipe(takeUntil(this._destroyed)).subscribe(data => { - const contentDispositionHeader = data.headers.get('Content-Disposition'); - const filename = contentDispositionHeader.split(';')[1].trim().split('=')[1].replace(/"/g, ''); + // this.supportiveMaterialService.getPublic(this.selectedLang.type, this.selectedMaterial.type).pipe(takeUntil(this._destroyed)).subscribe(data => { + // const contentDispositionHeader = data.headers.get('Content-Disposition'); + // const filename = contentDispositionHeader.split(';')[1].trim().split('=')[1].replace(/"/g, ''); - this.formGroup.get('name').patchValue(filename); - this.loadFile(data.body); + // this.formGroup.get('name').patchValue(filename); + // this.loadFile(data.body); + // }); + const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup(); + lookup.types = [this.selectedMaterial.type]; + lookup.languageCodes = [this.selectedLang.type]; + this.supportiveMaterialService.query(lookup).pipe(takeUntil(this._destroyed)).subscribe(data => { + if(data.count == 1){ + this.materialId = data.items[0].id; + this.formGroup.get('html').patchValue(data.items[0].payload); + } }); } @@ -118,30 +129,24 @@ export class SupportiveMaterialEditorComponent extends BaseComponent implements return source; } - loadFile(data: Blob) { - const reader = new FileReader(); - reader.addEventListener('load', () => { - let result = this.parseText(reader.result as string); - //result = result.replace(/class="href" path="/g, 'href="#'); - this.formGroup.get('html').patchValue(result); - }, false); - reader.readAsText(data); - } +// loadFile(data: Blob) { +// const reader = new FileReader(); +// reader.addEventListener('load', () => { +// let result = this.parseText(reader.result as string); +// //result = result.replace(/class="href" path="/g, 'href="#'); +// this.formGroup.get('html').patchValue(result); +// }, false); +// reader.readAsText(data); +// } submit() { let result = this.parseText(this.formGroup.get('html').value); - //result = result.replace(/href="#/g, 'class="href" path="'); this.formGroup.get('html').patchValue(result); - //const item = {name: this.formGroup.value['name'], type: this.selectedMaterial.type ,html: this.formGroup.value['html']} as SupportiveMaterialPersist - const item = {id: null, + const item = {id: this.materialId, type: this.selectedMaterial.type, languageCode: this.selectedLang.type, payload: this.formGroup.value['html']} as SupportiveMaterialPersist; - - // if(item.name.endsWith("_en.html") && this.selectedLang.type != "en" ){ - // item.name = item.name.replace("_en.html", `_${this.selectedLang.type}.html`); - // } - + this.supportiveMaterialService.persist(item).pipe(takeUntil(this._destroyed)) .subscribe( complete => { diff --git a/dmp-frontend/src/app/ui/user-guide/user-guide-content/user-guide-content.component.ts b/dmp-frontend/src/app/ui/user-guide/user-guide-content/user-guide-content.component.ts index fd2f5a08d..6b4f9acf7 100644 --- a/dmp-frontend/src/app/ui/user-guide/user-guide-content/user-guide-content.component.ts +++ b/dmp-frontend/src/app/ui/user-guide/user-guide-content/user-guide-content.component.ts @@ -51,7 +51,11 @@ export class UserGuideContentComponent extends BaseComponent implements OnInit { this.translate.onLangChange.subscribe((event: LangChangeEvent) => { this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/user-guide'])); }); - this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.UserGuide) + const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup(); + lookup.languageCodes = [this.languageService.getCurrentLanguage()]; + lookup.types = [SupportiveMaterialFieldType.UserGuide]; + + this.supportiveMaterialService.queryPublic(lookup) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], { type: 'text/html' });