Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add configurable modelling tool url #1726

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:Suppress("ktlint:no-wildcard-imports")

package de.thm.ii.fbs.controller.v2

import de.thm.ii.fbs.model.v2.misc.Integration
import de.thm.ii.fbs.services.v2.misc.IntegrationService
import de.thm.ii.fbs.utils.v2.exceptions.NotFoundException
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping(path = ["/api/v2/integrations"])
class IntegrationController(
private val integrationService: IntegrationService
) {

@GetMapping()
@ResponseBody
fun index(): Map<String, Integration> = integrationService.getAll()

@GetMapping("/{name}")
@ResponseBody
fun get(@PathVariable("name") name: String): Integration = integrationService.get(name) ?: throw NotFoundException()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.thm.ii.fbs.model.v2.misc

data class Integration(val url: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.thm.ii.fbs.services.v2.misc

import de.thm.ii.fbs.model.v2.misc.Integration
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.env.Environment
import org.springframework.stereotype.Service

@Service
class IntegrationService(
@Autowired
private val env: Environment
) {
private val cleanRegex = Regex("[^A-Za-z ]")

fun getAll(): Map<String, Integration> =
(this.env.getProperty("integrations.names", List::class.java) as List<String>).mapNotNull { name -> get(name).let { if (it != null) name to it else null } }.toMap()

fun get(integrationName: String): Integration? =
this.env.getProperty("integrations." + cleanName(integrationName) + ".url").let { if (it !== null) Integration(it) else null }

private fun cleanName(input: String): String = cleanRegex.replace(input, "")
}
12 changes: 12 additions & 0 deletions modules/fbs-core/api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ services:
ids:
salt: ${ID_SALT:feedbacksystem_id_salt}
length: ${ID_LENGTH:8}
integrations:
names: [modelling, feedbackApp, eat, kanban, sciCheck]
modelling:
url: ${MODELLING_URL:https://fbs-modelling.mni.thm.de/}
feedbackApp:
url: ${FEEDBACK_APP_URL:/feedbackApp/}
eat:
url: ${EAT_URL:/eat/}
kanban:
url: ${KANBAN_URL:/kanban/}
sciCheck:
url: ${SCI_CHECK_URL:/scicheck/}
spring:
main:
allow-bean-definition-overriding: true
Expand Down
3 changes: 3 additions & 0 deletions modules/fbs-core/web/src/app/model/Integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Integration {
url: string;
}
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<iframe [src]="getURL()" title="FBS-Modellierung" frameBorder="0"></iframe>
<iframe
[src]="safeUrl | async"
title="FBS-Modellierung"
frameBorder="0"
></iframe>
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
import { Component, OnInit } from "@angular/core";
import { AuthService } from "src/app/service/auth.service";
import { TitlebarService } from "src/app/service/titlebar.service";
import { DomSanitizer, SafeResourceUrl } from "@angular/platform-browser";
import { IntegrationService } from "../../service/integration.service";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";

@Component({
selector: "app-fbs-modelling",
Expand All @@ -10,24 +13,28 @@ import { DomSanitizer, SafeResourceUrl } from "@angular/platform-browser";
})
export class FbsModellingComponent implements OnInit {
token: string;
safeUrl: SafeResourceUrl;
safeUrl: Observable<SafeResourceUrl>;

constructor(
private titlebar: TitlebarService,
private auth: AuthService,
private sanitizer: DomSanitizer,
private cdr: ChangeDetectorRef
private integrationService: IntegrationService
) {
this.token = this.auth.loadToken();
}
ngOnInit() {
this.titlebar.emitTitle("FBS Modellierung");
this.getURL();
}

getURL(): SafeResourceUrl {
const url = `https://fbs-modelling.mni.thm.de/#/login?jsessionid=${this.token}&iframe=true`;
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url);
this.cdr.detach(); // stops iframe from reloading
return this.safeUrl;
getURL() {
this.safeUrl = this.integrationService.getIntegration("modelling").pipe(
map(({ url }) => {
return this.sanitizer.bypassSecurityTrustResourceUrl(
`${url}#/login?jsessionid=${this.token}&iframe=true`
);
})
);
}
}
19 changes: 19 additions & 0 deletions modules/fbs-core/web/src/app/service/integration.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";
import { Integration } from "../model/Integration";

@Injectable({
providedIn: "root",
})
export class IntegrationService {
constructor(private http: HttpClient) {}

getIntegration(name: string): Observable<Integration> {
return this.http.get<Integration>("/api/v2/integrations/" + name);
}

getAllIntegrations(): Observable<Record<string, Integration>> {
return this.http.get<Record<string, Integration>>("/api/v2/integrations");
}
}