From 8cb918f6267e19f844c5626c6231732b7c4259e3 Mon Sep 17 00:00:00 2001
From: jojohoch <joachim.hoch@iqb.hu-berlin.de>
Date: Fri, 11 Aug 2023 10:06:22 +0200
Subject: [PATCH] [player] Add method for checking unit definition version to
 UnitComp.

---
 .../src/app/components/unit/unit.component.ts   | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/projects/player/src/app/components/unit/unit.component.ts b/projects/player/src/app/components/unit/unit.component.ts
index c7f9688c3..36aa01dac 100644
--- a/projects/player/src/app/components/unit/unit.component.ts
+++ b/projects/player/src/app/components/unit/unit.component.ts
@@ -54,16 +54,10 @@ export class UnitComponent implements OnInit {
       try {
         LogService.debug('player: unitDefinition', message.unitDefinition);
         const unitDefinition = JSON.parse(message.unitDefinition as string);
-        if (!VersionManager.hasCompatibleVersion(unitDefinition)) {
-          if (VersionManager.isNewer(unitDefinition)) {
-            throw Error(this.translateService.instant('errorMessage.unitDefinitionIsNewer'));
-          }
-          throw Error(this.translateService.instant('errorMessage.unitDefinitionIsOutdated'));
-        }
+        this.checkUnitdefinitionVersion(unitDefinition);
         const unit: Unit = new Unit(unitDefinition);
         this.pages = unit.pages;
         this.playerConfig = message.playerConfig || {};
-        LogService.info('player: unitStateElementCodes', this.unitStateService.elementCodes);
         this.metaDataService.resourceURL = this.playerConfig.directDownloadUrl;
         this.veronaPostService.sessionID = message.sessionId;
         this.initElementCodes(message, unit);
@@ -89,6 +83,15 @@ export class UnitComponent implements OnInit {
     }
   }
 
+  private checkUnitdefinitionVersion(unitDefinition: Record<string, unknown>): void {
+    if (!VersionManager.hasCompatibleVersion(unitDefinition)) {
+      if (VersionManager.isNewer(unitDefinition)) {
+        throw Error(this.translateService.instant('errorMessage.unitDefinitionIsNewer'));
+      }
+      throw Error(this.translateService.instant('errorMessage.unitDefinitionIsOutdated'));
+    }
+  }
+
   private showErrorDialog(text: string): void {
     this.dialog.open(UnitDefErrorDialogComponent, {
       data: { text: text },
-- 
GitLab