Skip to content

Commit

Permalink
another fix for config path loading and minor update to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Vijverberg committed Aug 27, 2019
1 parent 014f345 commit 16aefcd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
35 changes: 13 additions & 22 deletions src/org/opensourcebim/services/IfcObjectCollectionBaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

}
18 changes: 1 addition & 17 deletions src/org/opensourcebim/services/IfcToMpgCollectionService.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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());
Expand Down
16 changes: 1 addition & 15 deletions src/org/opensourcebim/services/MpgCalculationResultsService.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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());
Expand Down

0 comments on commit 16aefcd

Please sign in to comment.