From a2758be8a4f6d99736a2f2291a4547984610c00b Mon Sep 17 00:00:00 2001
From: Charly <maeder@cines.fr>
Date: Thu, 24 Jun 2021 17:33:29 +0200
Subject: [PATCH 1/2] Add button to publish catalog on mongoDB

---
 src/app/repository/repository.component.html  |   8 +-
 src/app/repository/repository.component.ts    | 131 ++++++++----------
 .../services/publish-repository.service.ts    | 101 +++++++-------
 src/app/services/parse-xml.service.ts         |   4 +-
 src/environments/environment.prod.ts          |   2 +-
 5 files changed, 112 insertions(+), 134 deletions(-)

diff --git a/src/app/repository/repository.component.html b/src/app/repository/repository.component.html
index a5a3abd63..41d2c3a7d 100644
--- a/src/app/repository/repository.component.html
+++ b/src/app/repository/repository.component.html
@@ -1,8 +1,8 @@
 
-<form [formGroup]="Form" (ngSubmit)="repositorytoyaml(buttonType)">
+<form [formGroup]="Form">
 
     <label>Upload and fill form width repository description file: </label><br>
-    <input type="file"  id="repofile" name="repofile " class="btn btn-primary" (change)="repositorytoyaml('fill')" ><br>
+    <input type="file"  id="repofile" name="repofile " class="btn btn-primary" (change)="yamlToRepository()" ><br>
     <label>Or describe your repository and save a new file for publishing in the FDP database:</label><br>
 
 
@@ -38,11 +38,11 @@
 
   <div>
     <br>
-    <button type="submit"  (click)="repositorytoyaml('submit')" class="btn btn-primary">Save repository description file</button>
+    <button type="submit"  (click)="repositorytoyaml()" class="btn btn-primary">Save repository description file</button>
   </div>
   <div>
     <br>
-    <button type="submit"  (click)="repositorytoyaml('publish')" class="btn btn-success">Publish catalog description in FDP</button>
+    <button type="submit"  (click)="publishCatalog()" class="btn btn-success">Publish catalog description in FDP</button>
   </div>
 </form>
 
diff --git a/src/app/repository/repository.component.ts b/src/app/repository/repository.component.ts
index bb17611ec..5c63a94d5 100644
--- a/src/app/repository/repository.component.ts
+++ b/src/app/repository/repository.component.ts
@@ -21,6 +21,7 @@ export class RepositoryComponent implements OnInit {
   public fileName: string;
   public importFile: File;
   public resultat: any;
+  public persistentUrl: string;
 
   Form = new FormGroup({
     repotype: new FormControl(),
@@ -34,19 +35,60 @@ export class RepositoryComponent implements OnInit {
   });
 
 
-  constructor(private appConfig: AppConfiguration, private http: HttpClient, private authService:AuthService, 
-    private _FileSaverService: FileSaverService,private publishService: PublishRepositoryService) { }
+  constructor(
+    private appConfig: AppConfiguration,
+    private authService: AuthService,
+    private _FileSaverService: FileSaverService,
+    private publishService: PublishRepositoryService
+  ) { }
 
   ngOnInit() {
-    this.authService.getF2DSAuthToken()
+    this.authService.getF2DSAuthToken();
+    this.publishService.getPersistentUrl().subscribe({
+      next: (response) => this.persistentUrl = response.persistentUrl
+    });
   }
 
-  repositorytoyaml(buttonType) {
-    if (buttonType == 'submit') {
-      let data: string;
+  yamlToRepository() {
+    const files = (event.target as HTMLInputElement).files;
+    this.importFile = files[0];
 
+    let text = "";
+    let lines = [];
+    let line = "";
+    let map = new Map();
+    let fileReader = new FileReader();
 
-      data = '\
+
+    fileReader.onload = (event) => {
+      text = fileReader.result as string;
+
+      lines = text.split("\n");
+      for (let i = 0; i < lines.length; i++) {
+        line = lines[i].split(": ");
+        map.set(line[0].trim(), line[1]);
+      }
+
+      this.Form.setValue({
+        repotype: map.get('type'),
+        reponame: map.get('title'),
+        repodescription: map.get('description'),
+        repourl: map.get('url'),
+        repoversion: map.get('version'),
+        repolicence: map.get('licence'),
+        repolanguage: map.get('language'),
+        filetofill: ''
+      });
+
+    }
+    fileReader.readAsText(this.importFile);
+  }
+
+  repositorytoyaml() {
+    let data: string;
+
+
+    data = '\
 repository:\n\
   type: '+ this.Form.value.repotype + '\n\
   title: '+ this.Form.value.reponame + '\n\
@@ -57,85 +99,28 @@ repository:\n\
   language: '+ this.Form.value.repolanguage + '\n\
 '
 
-      const fileName = `repository.yaml`;
-      const fileType = this._FileSaverService.genType(fileName);
-      const txtBlob = new Blob([data], { type: fileType });
-
-      this._FileSaverService.save(txtBlob, fileName);
-    }
-
-    if (buttonType == 'fill') {
-      const files = (event.target as HTMLInputElement).files;
-      this.importFile = files[0];
-
-      let text = "";
-      let lines = [];
-      let line = "";
-      let map = new Map();
-      let fileReader = new FileReader();
-
-
-      fileReader.onload = (event) => {
-        text = fileReader.result as string;
-
-        lines = text.split("\n");
-        for (let i = 0; i < lines.length; i++) {
-          line = lines[i].split(": ");
-          map.set(line[0].trim(), line[1]);
-        }
-
-        this.Form.setValue({
-          repotype: map.get('type'),
-          reponame: map.get('title'),
-          repodescription: map.get('description'),
-          repourl: map.get('url'),
-          repoversion: map.get('version'),
-          repolicence: map.get('licence'),
-          repolanguage: map.get('language'),
-          filetofill: ''
-        });
+    const fileName = `repository.yaml`;
+    const fileType = this._FileSaverService.genType(fileName);
+    const txtBlob = new Blob([data], { type: fileType });
 
-      }
-      fileReader.readAsText(this.importFile);
-    }
+    this._FileSaverService.save(txtBlob, fileName);
+  }
 
-    if (buttonType == 'publish') {
 
-      let data: string;
+  publishCatalog() {
+    let data: string;
 
-      data = '\
+    data = '\
 @prefix dcat: <http://www.w3.org/ns/dcat#>.\n\
 @prefix dct: <http://purl.org/dc/terms/>.\n\
 @prefix fdp: <'+ this.appConfig.fdpurl + '/>.\n\nfdp:new \n\
     a dcat:Catalog, dcat:Resource;\n\
     dct:description "'+ this.Form.value.repodescription + '";\n\
     dct:hasVersion "'+ this.Form.value.repoversion + '";\n\
-    dct:isPartOf <'+ this.appConfig.fdpurl + '>;\n\
+    dct:isPartOf <' + this.persistentUrl + '>;\n\
     dcat:keyword "'+ this.Form.value.repotype + '";\n\
     dct:title "'+ this.Form.value.reponame + '".\n'
 
     return this.publishService.publishRepository(data);
-      /* const httpOptions = {
-        headers: new HttpHeaders({
-          'Accept': 'text/turtle',
-          'Content-Type': 'text/turtle',
-          'Authorization': 'Bearer ' + environment.token
-        })
-      };
-
-      this.resultat = this.http
-        .post(this.appConfig.fdpurl + "/catalog", data, httpOptions)
-        .subscribe((r) => { console.log('reponse: ', r) });
-
-      console.log("resultat: " + JSON.stringify(this.resultat));
-
-      return JSON.stringify(this.resultat); */
-
-
-    }
-
-
   }
-
-
 }
diff --git a/src/app/repository/services/publish-repository.service.ts b/src/app/repository/services/publish-repository.service.ts
index c97dd28c3..e00d695ba 100644
--- a/src/app/repository/services/publish-repository.service.ts
+++ b/src/app/repository/services/publish-repository.service.ts
@@ -1,10 +1,12 @@
-import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
+import { HttpClient } from '@angular/common/http';
 import { Injectable } from '@angular/core';
+import { Observable } from 'rxjs';
 import { AppConfiguration } from 'src/app/AppConfiguration';
 import { AuthService } from 'src/app/authentication/services/auth.service';
-import { environment } from 'src/environments/environment.prod';
-
 
+interface PersistentUrlResponse {
+  persistentUrl: string;
+}
 
 
 @Injectable({
@@ -12,65 +14,56 @@ import { environment } from 'src/environments/environment.prod';
 })
 export class PublishRepositoryService {
 
-  fds2Token: string
-  constructor(private http: HttpClient,private appConfig: AppConfiguration, private authService: AuthService) { }
+  constructor(
+    private http: HttpClient,
+    private appConfig: AppConfiguration,
+    private authService: AuthService
+  ) { }
+
+  get smartApiUrl(): string {
+    return 'http://localhost:8080/harvester/api'; // TO-DO
+    //return this.appConfig.smartapiurl + '/harvester/api'
+  }
+
+  publishRepository(data: string) {
 
-  publishRepository(data:string){
+    this.authService.getF2DSAuthToken().subscribe(tokenResponse => {
+      const fds2Token = tokenResponse.token;
+      if (fds2Token) {
 
-    this.authService.getF2DSAuthToken().subscribe(data=>{
-      this.fds2Token = data.token
-    })
-    if (this.fds2Token) {
+        const myHeaders = new Headers();
+        myHeaders.append('Accept', 'text/turtle');
+        myHeaders.append('Content-Type', 'text/turtle');
+        myHeaders.append('Authorization', 'Bearer ' + fds2Token);
+        const myInit = { method: 'POST', body: data, headers: myHeaders };
 
-      var myHeaders = new Headers();
-      myHeaders.append( 'Accept',  'text/turtle');
-      myHeaders.append('Content-Type',  'text/turtle');
-      myHeaders.append('Authorization', 'Bearer '+ this.fds2Token );
-      var myInit = { method: 'POST', body:data, headers: myHeaders };      
+        const myRequest = new Request(this.appConfig.fdpurl + "/catalog", myInit);
 
-      var myRequest = new Request(this.appConfig.fdpurl+"/catalog", myInit);
-      
-      fetch(myRequest, myInit)
-      .then(response => {
-        response.text()
-          .then(data => {
-            console.log('catalog creaetd with fdp / id = ' + data.substring(38,74));
-            /* update user (mongo ) with  ( this.authService.user('data.substring(38,74)') -> smartharvester api userRpositories create/update)
-            catalog: {
-              'cat_id':'qsdqs-qsd-qs-dqs-d-qsd-q',
-              'cat_id': 'data.substring(38,74)'
-            } */
-            
-          });   
-        });
-/*
-      const httpOptions = {
-        headers: new HttpHeaders({
-          'Accept':  'text/turtle',
-          'Content-Type':  'text/turtle',
-          'Authorization': 'Bearer '+ this.fds2Token,
-           observe: 'response',
-           responseType: 'text' 
-        })
-      };
+        fetch(myRequest, myInit)
+          .then(response => {
+            response.text()
+              .then(data => {
+                const catId = data.substring(38, 74);
+                console.log('catalog creaetd with fdp / id = ' + catId);
+                this.addUserCatalog(catId).then((response) => console.log(response));
+              });
+          });
 
-      let resultat = this.http.post(this.appConfig.fdpurl+"/catalog", data, httpOptions ).subscribe( 
-        (r:HttpResponse<any>)=>{
-       console.log(r.headers.get('location'))
-      }, 
-      (error: any) => {
-          console.log(error)
-      });
-      
-      if (resultat){
-        console.log("resultat: " + resultat);
-        return resultat;
+        return "The repository has not been published"
       }
+    });
+  }
+
+  getPersistentUrl(): Observable<PersistentUrlResponse> {
+    return this.http.get<PersistentUrlResponse>(/* // TO-DO : this.appConfig.fdpurl*/ 'http://localhost:8084' + '/configs/bootstrap');
+  }
 
-*/
+  async addUserCatalog(catId: string): Promise<any> {
+    const tokenResponse = await this.authService.getF2DSAuthToken().toPromise();
 
-      return "The repository has not been published"
-    }
+    return this.http.post(this.smartApiUrl + '/user/' + this.appConfig.fdpemail + '/catalogs', catId,
+      { headers: { Authorization: 'Bearer ' + tokenResponse.token } })
+      .toPromise();
   }
 
 }
diff --git a/src/app/services/parse-xml.service.ts b/src/app/services/parse-xml.service.ts
index 5574c5d29..646d95ff0 100644
--- a/src/app/services/parse-xml.service.ts
+++ b/src/app/services/parse-xml.service.ts
@@ -1,5 +1,5 @@
 import { Injectable } from '@angular/core';
-import { BehaviorSubject, Observable } from 'rxjs';
+import { Observable } from 'rxjs';
 import { HttpClient, HttpHeaders } from '@angular/common/http';
 
 @Injectable({
@@ -7,7 +7,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
 })
 export class ParseXmlService {
  
-  blazePath = "https://ffds.eosc-pillar.eu/blazegraph/sparql"
+  blazePath = "https://f2ds.eosc-pillar.eu/blazegraph/sparql"
 
   constructor(private http:HttpClient) { }
   
diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts
index e8fafda56..3d96a7919 100644
--- a/src/environments/environment.prod.ts
+++ b/src/environments/environment.prod.ts
@@ -1,4 +1,4 @@
 export const environment = {
   production: true,
-  apiurl: 'ffds.eosc-pillar.eu',
+  apiurl: 'f2ds.eosc-pillar.eu',
 };
-- 
GitLab


From 7b90e747acfe0474100bd55a1c44684f41c11dd0 Mon Sep 17 00:00:00 2001
From: Charly <maeder@cines.fr>
Date: Fri, 2 Jul 2021 17:52:21 +0200
Subject: [PATCH 2/2] Add url, licence and language in RDF for blazegraph

---
 src/app/repository/repository.component.ts | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/app/repository/repository.component.ts b/src/app/repository/repository.component.ts
index 5c63a94d5..e9c83cc6e 100644
--- a/src/app/repository/repository.component.ts
+++ b/src/app/repository/repository.component.ts
@@ -113,14 +113,20 @@ repository:\n\
     data = '\
 @prefix dcat: <http://www.w3.org/ns/dcat#>.\n\
 @prefix dct: <http://purl.org/dc/terms/>.\n\
+@prefix foaf:  <http://xmlns.com/foaf/0.1/> .\n\
+@prefix lang: <http://id.loc.gov/vocabulary/iso639-1/>. \n\
 @prefix fdp: <'+ this.appConfig.fdpurl + '/>.\n\nfdp:new \n\
     a dcat:Catalog, dcat:Resource;\n\
     dct:description "'+ this.Form.value.repodescription + '";\n\
     dct:hasVersion "'+ this.Form.value.repoversion + '";\n\
     dct:isPartOf <' + this.persistentUrl + '>;\n\
     dcat:keyword "'+ this.Form.value.repotype + '";\n\
-    dct:title "'+ this.Form.value.reponame + '".\n'
+    dct:title "'+ this.Form.value.reponame + '";\n\
+    foaf:homepage <' + this.Form.value.repourl + '>;\n\
+    dct:licence <' + this.Form.value.repolicence + '>;\n\
+    dct:language lang:' + this.Form.value.repolanguage + ' .\n';
 
+    console.log(data);
     return this.publishService.publishRepository(data);
   }
 }
-- 
GitLab