From 16aefcd9f43c72c369aae1ba7e54ace153a18bdd Mon Sep 17 00:00:00 2001 From: Jasper Vijverberg Date: Tue, 27 Aug 2019 16:19:58 +0200 Subject: [PATCH] another fix for config path loading and minor update to docs --- README.md | 2 +- .../IfcObjectCollectionBaseService.java | 35 +++++++------------ .../services/IfcToMpgCollectionService.java | 18 +--------- .../MpgCalculationResultsService.java | 16 +-------- 4 files changed, 16 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 6d728a6..0e01088 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ In the BimServer documentation it states how to set up the eclipse client with t ## The NMD Service If you are to run the NMD service locally please clone [this repository](https://github.com/TNOBIM/NMD/) and follow the readme to run it. As this is a private repository you will either need to require access rights , or use an externally hosted NMD service. -In order to connect to a locally hosted NMD service you are required to add a config.xml file (for NMD3.0 tokens and NMD2.2 db location) in the root directory of the NL-MPG-calc repository (= the current repository). An example file with the structure of the xml has been provided in the examples folder of this repository. +In order to connect to a locally hosted NMD service you are required to add a config.xml file (for NMD3.0 tokens and NMD2.2 db location) in the root directory of the NL-MPG-CALC *and* the root directory of the NMD Service repositories. An example file with the structure of the xml has been provided in the examples folder of this repository. Currently we make use of the NMD2.2 connection as the 3.0 version is not ready for full load testing yet. However, the problem with the 2.2 version is that the user needs its own sqlite *.db file hosted locally in the config data folder. However, the disadvantage of the NMD2.2 version is that the interface is only partially implemented and therefore does not return representative values for product cards. This has been intentionally left as 'to do' as we are currently not planning for the 2.2 version to be used in production stages. diff --git a/src/org/opensourcebim/services/IfcObjectCollectionBaseService.java b/src/org/opensourcebim/services/IfcObjectCollectionBaseService.java index a82807b..e8c11ae 100644 --- a/src/org/opensourcebim/services/IfcObjectCollectionBaseService.java +++ b/src/org/opensourcebim/services/IfcObjectCollectionBaseService.java @@ -2,7 +2,6 @@ import java.io.FileNotFoundException; import java.nio.file.Files; -import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; @@ -17,9 +16,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import nl.tno.bim.nmd.config.NmdConfig; -import nl.tno.bim.nmd.config.NmdConfigImpl; -import nl.tno.bim.nmd.services.Nmd2DataService; import nl.tno.bim.nmd.services.Nmd3DataService; public abstract class IfcObjectCollectionBaseService extends BimBotAbstractService { @@ -73,26 +69,21 @@ public void setStore(MpgObjectStore store) { * @return a preconfigured NMDDataResolver * @throws FileNotFoundException */ - protected NmdDataResolver getNmdResolver() throws FileNotFoundException { - NmdConfig config; - if (getPluginContext() == null) { - config = new NmdConfigImpl(); - } else { - - Path pPath = Paths.get(getPluginContext().getRootPath().getParent().toString()); - if (Files.notExists(pPath.resolve("config.xml"))) { - config = new NmdConfigImpl(Paths.get(getPluginContext().getRootPath().toString())); - } else { - config = new NmdConfigImpl(pPath); - } - if (Files.notExists(pPath.resolve("config.xml"))) { - throw new FileNotFoundException("Could not find config file"); - } - } - + protected NmdDataResolver getNmdResolver() { + Path pPath; + if (getPluginContext() == null) { + pPath = Paths.get(System.getProperty("user.dir")); + } else { + pPath = getPluginContext().getRootPath().getParent(); + if (Files.notExists(pPath.resolve("config.xml"))) { + pPath = getPluginContext().getRootPath(); + } + } + NmdDataResolver resolver = new NmdDataResolverImpl(); - resolver.setNmdService(new Nmd3DataService(config)); + resolver.setNmdService(Nmd3DataService.getInstance(pPath)); resolver.setMappingService(new MappingDataServiceRestImpl()); return resolver; } + } diff --git a/src/org/opensourcebim/services/IfcToMpgCollectionService.java b/src/org/opensourcebim/services/IfcToMpgCollectionService.java index 4aa3ae0..4e55708 100644 --- a/src/org/opensourcebim/services/IfcToMpgCollectionService.java +++ b/src/org/opensourcebim/services/IfcToMpgCollectionService.java @@ -1,23 +1,12 @@ package org.opensourcebim.services; -import java.io.FileNotFoundException; -import java.nio.file.Path; -import java.nio.file.Paths; - import org.bimserver.bimbots.BimBotContext; import org.bimserver.bimbots.BimBotsException; import org.bimserver.bimbots.BimBotsInput; import org.bimserver.bimbots.BimBotsOutput; import org.bimserver.plugins.PluginConfiguration; import org.opensourcebim.ifccollection.MpgIfcObjectCollector; -import org.opensourcebim.mapping.MappingDataServiceRestImpl; import org.opensourcebim.mapping.NmdDataResolver; -import org.opensourcebim.mapping.NmdDataResolverImpl; - -import nl.tno.bim.nmd.config.NmdConfigImpl; -import nl.tno.bim.nmd.services.Nmd2DataService; -import nl.tno.bim.nmd.services.Nmd3DataService; -import nl.tno.bim.nmd.services.NmdDataService; public class IfcToMpgCollectionService extends IfcObjectCollectionBaseService { @@ -27,12 +16,7 @@ public BimBotsOutput runBimBot(BimBotsInput input, BimBotContext bimBotContext, // Get properties from ifcModel MpgIfcObjectCollector matParser = new MpgIfcObjectCollector(); - NmdDataResolver resolver; - try { - resolver = getNmdResolver(); - } catch (FileNotFoundException e) { - return this.toBimBotsJsonOutput(e, "bot failed. Config not found"); - } + NmdDataResolver resolver = getNmdResolver(); this.setStore(matParser.collectIfcModelObjects(input, bimBotContext.getContextId())); resolver.setStore(this.getStore()); diff --git a/src/org/opensourcebim/services/MpgCalculationResultsService.java b/src/org/opensourcebim/services/MpgCalculationResultsService.java index 958dba9..c9c1a8f 100644 --- a/src/org/opensourcebim/services/MpgCalculationResultsService.java +++ b/src/org/opensourcebim/services/MpgCalculationResultsService.java @@ -1,23 +1,15 @@ package org.opensourcebim.services; -import java.io.FileNotFoundException; -import java.nio.file.Path; -import java.nio.file.Paths; - import org.bimserver.bimbots.BimBotContext; import org.bimserver.bimbots.BimBotsException; import org.bimserver.bimbots.BimBotsInput; import org.bimserver.bimbots.BimBotsOutput; import org.bimserver.plugins.PluginConfiguration; import org.opensourcebim.ifccollection.MpgIfcObjectCollector; -import org.opensourcebim.mapping.MappingDataServiceRestImpl; import org.opensourcebim.mapping.NmdDataResolver; -import org.opensourcebim.mapping.NmdDataResolverImpl; import org.opensourcebim.mpgcalculation.MpgCalculationResults; import org.opensourcebim.mpgcalculation.MpgCalculator; -import nl.tno.bim.nmd.config.NmdConfigImpl; -import nl.tno.bim.nmd.services.Nmd2DataService; public class MpgCalculationResultsService extends IfcObjectCollectionBaseService { @@ -27,13 +19,7 @@ public BimBotsOutput runBimBot(BimBotsInput input, BimBotContext bimBotContext, // Get properties from ifcModel MpgIfcObjectCollector matParser = new MpgIfcObjectCollector(); - NmdDataResolver resolver; - try { - resolver = getNmdResolver(); - } catch (FileNotFoundException e) { - return this.toBimBotsJsonOutput(e, "bot failed. Config not found"); - } - + NmdDataResolver resolver = getNmdResolver(); this.setStore(matParser.collectIfcModelObjects(input, bimBotContext.getContextId())); resolver.setStore(this.getStore());