|
| 1 | +import { ProfileManager } from "@foerderfunke/matching-engine/src/ProfileManager"; |
| 2 | +import resourceService from "@/core/services/resourceService"; |
| 3 | + |
| 4 | +const profileManager = { |
| 5 | + profileManagerInstance: null, |
| 6 | + constructionPromise: null, |
| 7 | + |
| 8 | + async constructProfileManagerOnce() { |
| 9 | + if (this.profileManagerInstance) return this.profileManagerInstance; |
| 10 | + if (this.constructionPromise) return this.constructionPromise; |
| 11 | + |
| 12 | + console.log("Constructing Profile Manager..."); |
| 13 | + this.constructionPromise = (async () => { |
| 14 | + const validationConfig = await resourceService.fetchResourceWithCache( |
| 15 | + "assets/data/requirement-profiles/requirement-profiles.json" |
| 16 | + ); |
| 17 | + |
| 18 | + const datafieldsString = await resourceService.fetchResourceWithCache(validationConfig["datafields"]); |
| 19 | + const datafieldsBielefeldString = await resourceService.fetchResourceWithCache(validationConfig["datafields-bielefeld"]); |
| 20 | + const definitionsString = await resourceService.fetchResourceWithCache(validationConfig["definitions"]); |
| 21 | + const materializationString = await resourceService.fetchResourceWithCache(validationConfig["materialization"]); |
| 22 | + const consistencyString = await resourceService.fetchResourceWithCache(validationConfig["consistency"]); |
| 23 | + |
| 24 | + const profileManager = new ProfileManager(); |
| 25 | + profileManager.addDatafieldsTurtle(datafieldsString) |
| 26 | + profileManager.addDatafieldsTurtle(datafieldsBielefeldString) |
| 27 | + profileManager.addDefinitionsTurtle(definitionsString); |
| 28 | + profileManager.addMaterializationTurtle(materializationString); |
| 29 | + profileManager.addConsistencyTurtle(consistencyString); |
| 30 | + |
| 31 | + this.profileManagerInstance = profileManager; |
| 32 | + console.log("Profile Manager constructed."); |
| 33 | + return profileManager; |
| 34 | + })(); |
| 35 | + |
| 36 | + return this.constructionPromise; |
| 37 | + }, |
| 38 | + |
| 39 | + async initProfileManager(defaultProfileId) { |
| 40 | + const profileManager = await this.constructProfileManagerOnce(); |
| 41 | + await profileManager.init(); |
| 42 | + // let profileIds = JSON.parse(localStorage.getItem('userIds')) || [] |
| 43 | + let existingProfileTurtle = localStorage.getItem(defaultProfileId); |
| 44 | + if (existingProfileTurtle) { |
| 45 | + profileManager.importProfileTurtle(defaultProfileId, existingProfileTurtle); |
| 46 | + } else { |
| 47 | + let profile = profileManager.getProfile(profileManager.newProfile(defaultProfileId)); |
| 48 | + localStorage.setItem(defaultProfileId, await profile.toTurtle()); |
| 49 | + } |
| 50 | + return profileManager; |
| 51 | + }, |
| 52 | +}; |
| 53 | + |
| 54 | +export default profileManager; |
0 commit comments