Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • eosc-pillar/ffds/ffds-register-front
1 result
Show changes
Showing
with 510 additions and 405 deletions
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { Router } from '@angular/router';
import { SmartHarvesterUser } from 'src/app/user/model/user';
import { AuthService } from '../services/auth.service';
@Component({
selector: 'app-signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.scss']
})
export class SignupComponent implements OnInit {
isSubmitted = false;
isLoggedIn = false;
isLoginFailed = false;
errorMessage = '';
showPassword = false;
user: SmartHarvesterUser;
formGroup = new FormGroup({
firsName: new FormControl(''),
lastName: new FormControl(''),
email: new FormControl(''),
password: new FormControl(''),
passwordConfirm: new FormControl(''),
});
constructor(private authService: AuthService, private router: Router) { }
ngOnInit(): void {
}
onSubmit(): void {
this.authService.register(this.formGroup).subscribe(
data => {
console.error("Response : ", data)
if (data.statusCode == 'OK') {
this.router.navigateByUrl('/auth/signin');
//this.reloadPage();
}
},
err => {
this.errorMessage = err.error.message;
this.isLoginFailed = true;
}
);
}
reloadPage(): void {
window.location.reload();
}
}
<nb-layout>
<nb-layout-header fixed>
<nb-icon (click)="toggleSidebar()" class="sidebar-toggle" icon="menu-2-outline"></nb-icon>
<a routerLink="/dashboard" routerLinkActive="active">
<img width="80" alt="Angular Logo" src="assets/images/logo.png" />
</a>
<h3 style="width: 100%;text-align: center;"> <strong>{{settingtitle}}</strong></h3>
<!--User badge-->
<nb-user style="white-space: pre;"
name="{{userData.firstName}}"
title="{{userData.lastName}}"
[nbContextMenu]="menuItems"
nbContextMenuTag="my-context-menu"
badgePosition="right">
</nb-user>
<!--<button routerLink="/login" nbContextMenuPlacement="right" outline nbButton>Login</button>-->
</nb-layout-header>
<nb-sidebar responsive start state="compacted">
<!--Menu Items-->
<nb-menu [items]="menuItems" autoCollapse="true"></nb-menu>
</nb-sidebar>
<nb-layout-column>
<app-stats *ngIf="routerUrl === '/dashboard'"></app-stats>
<router-outlet></router-outlet>
</nb-layout-column>
<nb-layout-footer>Contact us</nb-layout-footer>
</nb-layout>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DashboardComponent } from './dashboard.component';
describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DashboardComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationStart, Router } from '@angular/router';
import { NbMenuItem, NbSidebarService } from '@nebular/theme';
import { AuthService } from '../authentication/services/auth.service';
import { TokenStorageService } from '../authentication/services/token-storage.service';
import { SmartHarvesterUser } from '../user/model/user';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
userData: SmartHarvesterUser;
routerUrl: string;
menuItems: NbMenuItem[] = [
{
title: 'Home',
icon: 'home-outline',
link: '/dashboard/',
pathMatch: 'full'
},
{
title: 'Integrate your repository',
icon: 'cube-outline',
children: [
{
title: 'SDT information',
link: '/dashboard/repositoryinfo',
pathMatch: 'full',
icon: 'flash-outline',
},
{
title: 'Technical information',
link: '/dashboard/repository',
pathMatch: 'full',
icon: 'text-outline',
},
{
title: 'Describe access to datasets',
icon: 'clipboard-outline',
link: '/dashboard/publishapi',
pathMatch: 'full'
}
],
},
{
title: 'Search',
icon: 'search-outline',
link: '/dashboard/simplesearch',
pathMatch: 'full'
},
{
title: 'Settings',
icon: 'options-2-outline',
children: [
{
title: 'FFDS settings',
link: '/dashboard/settingfdp',
pathMatch: 'full'
},
{
title: 'SmartHarvester settings',
link: '/dashboard/settingsmartharvester',
pathMatch: 'full'
}
],
},
];
constructor(private readonly sidebarService: NbSidebarService,
private authService: AuthService,
private tokeService: TokenStorageService, private route: Router) { }
ngOnInit(): void {
this.routerUrl = this.route.url;
this.route.events.subscribe(event => {
if (event instanceof NavigationStart) {
this.routerUrl = event.url;
}
});
let loggedIn = this.authService.isLoggedIn;
if (loggedIn) {
this.userData = this.tokeService.getUser();
}
}
toggleSidebar(): boolean {
this.sidebarService.toggle(true);
return false;
}
}
......@@ -3,6 +3,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
import { AppConfiguration } from '../AppConfiguration';
import { FileSaverService } from 'ngx-filesaver';
import { environment } from 'src/environments/environment.prod';
import { DatasetCrudService } from './services/dataset-crud.service';
@Component({
......@@ -20,6 +21,7 @@ export class DatasetsComponent implements OnInit {
private appConfig: AppConfiguration,
private http: HttpClient,
private _FileSaverService: FileSaverService,
private dataSetService: DatasetCrudService
) { }
ngOnInit() {
......@@ -28,70 +30,71 @@ export class DatasetsComponent implements OnInit {
listdatasets() {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "Application/json");
var myInit = { method: 'GET', headers: myHeaders};
myHeaders.append("Content-Type", "Application/json");
var myInit = { method: 'GET', headers: myHeaders };
//appeler smart havester pour récuperer l'api à lancer
// https://data.inrae.fr/api/search?q=*&per_page=10&type=dataset&start=16000&show_entity_ids=true&show_my_data=true
// var myRequest = new Request(this.appConfig.smartapiurl+'harvest/allurls',myInit);
var myRequest = new Request('https://dataverse.ird.fr/api/search?q=*&per_page=100&show_facets=true&show_my_data=true',myInit);
fetch(myRequest, myInit)
.then(response => {
response.json()
.then(data => {
//this.dataresult =data;
this.itemsdatasets = data['data']['items'];
console.log(this.itemsdatasets);
for (var i = 0; i < this.itemsdatasets.length; i++) {
this.createdataset(data['data']['items'][i]);
}
});
});
return null;
}
// var myRequest = new Request(this.appConfig.smartapiurl+'harvest/allurls',myInit);
var myRequest = new Request('https://dataverse.ird.fr/api/search?q=*&per_page=100&show_facets=true&show_my_data=true', myInit);
fetch(myRequest, myInit)
.then(response => {
response.json()
.then(data => {
//this.dataresult =data;
this.itemsdatasets = data['data']['items'];
console.log(this.itemsdatasets);
for (var i = 0; i < this.itemsdatasets.length; i++) {
this.createdataset(data['data']['items'][i]);
}
});
});
return null;
}
createdataset(item: any) {
console.log(item);
let data: string;
let description: string;
description = JSON.stringify(item['description']);
let name: string;
name = JSON.stringify(item['name']);
let url: string;
url = JSON.stringify(item['url']);
data ='\
@prefix dcat: <http://www.w3.org/ns/dcat#>.\n\
@prefix dct: <http://purl.org/dc/terms/>.\n\
@prefix language: <http://id.loc.gov/vocabulary/iso639-1/>.\n\
@prefix s: <'+this.appConfig.fdpurl+'/>.\n\
@prefix c: <'+this.appConfig.fdpurl+'/catalog/>.\n\
\n\
s:new\n\
a dcat:Dataset, dcat:Resource;\n\
dct:description '+ description+ ';\n\
dct:hasVersion "1.0";\n\
dct:isPartOf c:a21f9b06-b7e7-43c0-869d-d81f09053383;\n\
dct:language language:en;\n\
dct:license <http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0>;\n\
dct:title '+ name +';\n\
dcat:keyword '+ url +'.\n'
const httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/turtle',
'Content-Type': 'text/turtle',
'Authorization': 'Bearer '+ environment.token
})
};
return this.http.post(this.appConfig.fdpurl+"/dataset", data, httpOptions ).subscribe( (r)=>{console.log('got r', r)}) ;
let data: string;
let description: string;
description = JSON.stringify(item['description']);
let name: string;
name = JSON.stringify(item['name']);
let url: string;
url = JSON.stringify(item['url']);
data = '\@prefix dcat: <http://www.w3.org/ns/dcat#>.\n\
@prefix dct: <http://purl.org/dc/terms/>.\n\
@prefix language: <http://id.loc.gov/vocabulary/iso639-1/>.\n\
@prefix s: <'+ this.appConfig.fdpurl + '/>.\n\
@prefix c: <'+ this.appConfig.fdpurl + '/catalog/>.\n\
\n\
s:new\n\
a dcat:Dataset, dcat:Resource;\n\
dct:description '+ description + ';\n\
dct:hasVersion "1.0";\n\
dct:isPartOf c:a21f9b06-b7e7-43c0-869d-d81f09053383;\n\
dct:language language:en;\n\
dct:license <http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0>;\n\
dct:title '+ name + ';\n\
dcat:keyword '+ url + '.\n'
/* const httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/turtle',
'Content-Type': 'text/turtle',
'Authorization': 'Bearer '+ environment.token
})
};
return this.http.post(this.appConfig.fdpurl+"/dataset", data, httpOptions ).subscribe( (r)=>{console.log('got r', r)}) ; */
return this.dataSetService.createDataSet(data);
}
......
import { TestBed } from '@angular/core/testing';
import { AuthService } from './auth.service';
import { DatasetCrudService } from './dataset-crud.service';
describe('AuthService', () => {
let service: AuthService;
describe('DatasetCrudService', () => {
let service: DatasetCrudService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AuthService);
service = TestBed.inject(DatasetCrudService);
});
it('should be created', () => {
......
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AppConfiguration } from 'src/app/AppConfiguration';
import { AuthService } from 'src/app/authentication/services/auth.service';
@Injectable({
providedIn: 'root'
})
export class DatasetCrudService {
fds2Token: string
constructor(private http: HttpClient,private appConfig: AppConfiguration, private authService: AuthService) { }
createDataSet(data:string){
this.authService.getF2DSAuthToken().subscribe(data=>{
this.fds2Token = data.token
})
if (this.fds2Token) {
const httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/turtle',
'Content-Type': 'text/turtle',
'Authorization': 'Bearer '+ this.fds2Token
})
};
let resultat = this.http.post(this.appConfig.fdpurl+"/catalog", data, httpOptions ).subscribe( (r)=>{console.log('reponse: ', r)}) ;
if (resultat){
console.log("resultat: " + JSON.stringify(resultat));
return JSON.stringify(resultat);
}
return "The repository has not been published"
}
}
}
<h1 style="text-align:center">AAI EOSC-Pillar</h1>
<nb-card status="info" style="width: 50%;height: auto; margin: auto;" >
<nb-card-header style="text-align: center;">Welcome to the API register</nb-card-header>
<nb-card-body class="example-items-col">
<div class="login" style="text-align: center;">
<h2 class="login-header">Log in</h2>
<form [formGroup]="loginForm" class="login-container" (ngSubmit)="login()">
<p [ngClass]="{ 'has-error': isSubmitted && formControls.email.errors }">
<label class="label" for="email">Email:</label>
<input style="margin: auto;" type="email" nbInput shape="semi-round" placeholder="Email" formControlName="email">
</p>
<div *ngIf="isSubmitted && formControls.email.errors" class="help-block">
<div *ngIf="formControls.email.errors.required">Email is required</div>
</div>
<p [ngClass]="{ 'has-error': isSubmitted && formControls.password.errors }">
<label class="label" for="passord">Password:</label>
<input type="password" nbInput shape="semi-round" placeholder="Password" formControlName="password">
</p>
<div *ngIf="isSubmitted && formControls.password.errors" class="help-block">
<div *ngIf="formControls.password.errors.required">Password is required</div>
</div>
<p>
<input type="submit" nbButton shape="rectangle" status="info" value="Log in" style="width: auto;height: auto;">
</p>
</form>
</div>
</nb-card-body>
</nb-card>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
background: #456;
font-family: 'Open Sans', sans-serif;
}
.has-error input[type="email"],
.has-error input[type="password"] {
border-color: rgb(216, 12, 12);
color: rgb(230, 14, 14);
}
label {
width: auto;
}
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { AuthService } from './services/auth.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
loginForm: FormGroup;
isSubmitted = false;
public isLoggedIn = false;
constructor(private authService: AuthService, private router: Router, private formBuilder: FormBuilder) { }
ngOnInit(): void {
//Create form
this.loginForm = this.formBuilder.group({
email: ['', Validators.required],
password: ['', Validators.required]
});
//Check crendentials
this.isLoggedIn = this.authService.checkCredentials();
}
get formControls() { return this.loginForm.controls; }
login() {
const val = this.loginForm.value;
if (val.email && val.password) {
this.authService.login(val.email, val.password)
.subscribe(
() => {
console.log("User is logged in");
this.router.navigateByUrl('/');
}
);
}
}
}
export interface authObj {
"username": string,
"email": string
}
\ No newline at end of file
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from './auth.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService){}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.authService.isLoggedIn();
}
}
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { shareReplay,catchError } from "rxjs/operators";
import { User } from 'src/app/user/model/user';
import { Cookie } from 'ng2-cookies';
@Injectable({
providedIn: 'root'
})
export class AuthService {
public clientId = 'newClient';
public redirectUri = 'http://localhost:8089/';
constructor(private http: HttpClient) { }
retrieveToken(code) {
let params = new URLSearchParams();
params.append('grant_type','authorization_code');
params.append('client_id', this.clientId);
params.append('client_secret', 'newClientSecret');
params.append('redirect_uri', this.redirectUri);
params.append('code',code);
let headers =
new HttpHeaders({'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'});
this.http.post('http://localhost:8083/auth/smartharvester/protocol/openid-connect/token',
params.toString(), { headers: headers })
.subscribe( data => this.saveToken(data), err => alert('Invalid Credentials'));
}
login(email:string, password:string ) {
return this.http.post<User>('/api/login', {email, password})
.pipe(
// defaults to all values so we set it to just keep and replay last one
shareReplay(1))
}
saveToken(token) {
let expireDate = new Date().getTime() + (1000 * token.expires_in);
Cookie.set("access_token", token.access_token, expireDate);
console.log('Obtained Access token');
window.location.href = 'http://localhost:8089';
}
getResource(resourceUrl) : Observable<any> {
var headers = new HttpHeaders({
'Content-type': 'application/x-www-form-urlencoded; charset=utf-8',
'Authorization': 'Bearer '+ Cookie.get('access_token')});
return this.http.get(resourceUrl, { headers: headers })
.pipe(
catchError(
(error:any) => Observable.throw(error.json().error || 'Server error')
)
);
}
checkCredentials() {
return Cookie.check('access_token');
}
logout() {
let token = Cookie.get('id_token');
Cookie.delete('access_token');
Cookie.delete('id_token');
let logoutURL = "http://localhost:8083/auth/smartharvester/protocol/openid-connect/logout?id_token_hint="
+ token
+ "&post_logout_redirect_uri=" + this.redirectUri;
window.location.href = logoutURL;
}
public isLoggedIn(){
return localStorage.getItem('ACCESS_TOKEN') !== null;
}
}
<h3>AAI EOSC-Pillar (to integrate)</h3>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Login</mat-card-title>
</mat-card-header>
<mat-card-content>
<form class="example-form">
<table class="example-full-width" cellspacing="0">
<tr>
<td>
<mat-form-field class="example-full-width">
<input matInput placeholder="Username" [(ngModel)]="username" name="username" required>
</mat-form-field>
</td>
</tr>
<tr>
<td><mat-form-field class="example-full-width">
<input matInput placeholder="Password" [(ngModel)]="password" type="password" name="password" required>
</mat-form-field></td>
</tr>
<tr>
<td>
<a routerLink="/user" routerLinkActive="active">Register</a>
</td>
</tr>
</table>
</form>
<mat-spinner [style.display]="showSpinner ? 'block' : 'none'"></mat-spinner>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button (click)="login()" color="primary">Login</button>
</mat-card-actions>
</mat-card>
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
constructor(private router: Router) { }
username: string;
password: string;
ngOnInit() {
}
login() : void {
if(this.username == 'admin' && this.password == 'admin'){
this.router.navigate(["/"]);
}else {
alert("Invalid credentials");
}
}
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NbMenuModule,
NbThemeModule,
NbStepperModule,
NbCardModule,
NbSidebarModule,
NbLayoutModule,
NbButtonModule,
NbIconModule,
NbInputModule,
NbContextMenuModule,
NbUserModule,
NbSpinnerModule,
NbAlertModule,
NbCheckboxModule,
NbFormFieldModule
} from '@nebular/theme/';
import { NbEvaIconsModule } from '@nebular/eva-icons';
@NgModule({
declarations: [],
imports: [
CommonModule,
NbLayoutModule,
NbStepperModule,
NbThemeModule.forRoot(),
NbContextMenuModule,
NbButtonModule,
NbMenuModule.forRoot(),
NbIconModule,
NbInputModule,
NbUserModule,
NbSpinnerModule,
NbAlertModule,
NbCheckboxModule,
NbCardModule,
NbFormFieldModule,
NbEvaIconsModule,
NbSidebarModule.forRoot()
],
exports:[
NbCardModule,
NbStepperModule,
NbThemeModule,
NbLayoutModule,
NbContextMenuModule,
NbMenuModule,
NbIconModule,
NbUserModule,
NbSpinnerModule,
NbAlertModule,
NbCheckboxModule,
NbInputModule,
NbButtonModule,
NbFormFieldModule,
NbEvaIconsModule,
NbSidebarModule
]
})
export class NebularModule { }
......@@ -2,10 +2,12 @@ import { Component, OnInit } from '@angular/core';
import { Validators } from '@angular/forms';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { FileSaverService } from 'ngx-filesaver';
import { FormControl} from '@angular/forms';
import { FormGroup} from '@angular/forms';
import { FormControl } from '@angular/forms';
import { FormGroup } from '@angular/forms';
import { AppConfiguration } from '../AppConfiguration';
import { environment } from 'src/environments/environment.prod';
import { AuthService } from '../authentication/services/auth.service';
import { PublishRepositoryService } from './services/publish-repository.service';
@Component({
......@@ -20,118 +22,117 @@ export class RepositoryComponent implements OnInit {
public importFile: File;
public resultat: any;
Form = new FormGroup({
repotype: new FormControl(),
reponame: new FormControl('', Validators.required),
repodescription: new FormControl(),
repourl: new FormControl(),
repoversion: new FormControl(),
repolicence: new FormControl(),
repolanguage: new FormControl(),
filetofill: new FormControl(),
Form = new FormGroup({
repotype: new FormControl(),
reponame: new FormControl('', Validators.required),
repodescription: new FormControl(),
repourl: new FormControl(),
repoversion: new FormControl(),
repolicence: new FormControl(),
repolanguage: new FormControl(),
filetofill: new FormControl(),
});
constructor(
private appConfig: AppConfiguration,
private http: HttpClient,
private _FileSaverService: FileSaverService,
) { }
constructor(private appConfig: AppConfiguration, private http: HttpClient, private authService:AuthService,
private _FileSaverService: FileSaverService,private publishService: PublishRepositoryService) { }
ngOnInit() {
this.authService.getF2DSAuthToken()
}
repositorytoyaml(buttonType) {
if (buttonType == 'submit') {
let data: string;
if (buttonType == 'submit') {
let data: string;
data ='\
data = '\
repository:\n\
type: '+ this.Form.value.repotype +'\n\
title: '+ this.Form.value.reponame +'\n\
description: '+ this.Form.value.repodescription +'\n\
url: '+ this.Form.value.repourl +'\n\
version: '+ this.Form.value.repoversion +' \n\
licence: '+ this.Form.value.repolicence +'\n\
language: '+ this.Form.value.repolanguage +'\n\
type: '+ this.Form.value.repotype + '\n\
title: '+ this.Form.value.reponame + '\n\
description: '+ this.Form.value.repodescription + '\n\
url: '+ this.Form.value.repourl + '\n\
version: '+ this.Form.value.repoversion + ' \n\
licence: '+ this.Form.value.repolicence + '\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();
const fileName = `repository.yaml`;
const fileType = this._FileSaverService.genType(fileName);
const txtBlob = new Blob([data], { type: fileType });
this._FileSaverService.save(txtBlob, fileName);
}
fileReader.onload = (event) => {
text = fileReader.result as string;
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: ''
});
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);
}
fileReader.readAsText(this.importFile);
}
if (buttonType == 'publish') {
if (buttonType == 'publish') {
let data: string;
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\
@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\
dcat:keyword "'+this.Form.value.repotype+'";\n\
dct:isPartOf <'+ this.appConfig.fdpurl + '>;\n\
dcat:keyword "'+ this.Form.value.repotype + '";\n\
dct:title "'+ this.Form.value.reponame + '".\n'
const httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/turtle',
'Content-Type': 'text/turtle',
'Authorization': 'Bearer '+ environment.token
})
};
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)}) ;
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);
return JSON.stringify(this.resultat); */
}
}
}
......
import { TestBed } from '@angular/core/testing';
import { PublishRepositoryService } from './publish-repository.service';
describe('PublishRepositoryService', () => {
let service: PublishRepositoryService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(PublishRepositoryService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AppConfiguration } from 'src/app/AppConfiguration';
import { AuthService } from 'src/app/authentication/services/auth.service';
import { environment } from 'src/environments/environment.prod';
@Injectable({
providedIn: 'root'
})
export class PublishRepositoryService {
fds2Token: string
constructor(private http: HttpClient,private appConfig: AppConfiguration, private authService: AuthService) { }
publishRepository(data:string){
this.authService.getF2DSAuthToken().subscribe(data=>{
this.fds2Token = data.token
})
if (this.fds2Token) {
const httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/turtle',
'Content-Type': 'text/turtle',
'Authorization': 'Bearer '+ this.fds2Token
})
};
let resultat = this.http.post(this.appConfig.fdpurl+"/catalog", data, httpOptions ).subscribe( (r)=>{console.log('reponse: ', r)}) ;
if (resultat){
console.log("resultat: " + JSON.stringify(resultat));
return JSON.stringify(resultat);
}
return "The repository has not been published"
}
}
}